UNPKG

@quantara/sdk

Version:

JavaScript/TypeScript SDK for interacting with Quantara Protocol on Neura Testnet

78 lines (77 loc) 2.99 kB
import { createPublicClient, createWalletClient, http } from "viem"; import { BATCH_CONFIGS } from "./configs/batch"; import { getViemChain } from "./configs/chains"; import { Accounts } from "./modules/accounts/accounts"; import { Markets } from "./modules/markets/markets"; import { Oracle } from "./modules/oracle"; import { Orders } from "./modules/orders/orders"; import { Positions } from "./modules/positions/positions"; import { Tokens } from "./modules/tokens/tokens"; import { Trades } from "./modules/trades/trades"; import { Utils } from "./modules/utils/utils"; import { callContract } from "./utils/callContract"; import { MAX_TIMEOUT, Multicall } from "./utils/multicall"; export class QuantaraSdk { constructor(config) { this.config = config; this.markets = new Markets(this); this.tokens = new Tokens(this); this.positions = new Positions(this); this.orders = new Orders(this); this.trades = new Trades(this); this.accounts = new Accounts(this); this.utils = new Utils(this); this.oracle = new Oracle(this); this.publicClient = config.publicClient ?? createPublicClient({ transport: http(this.config.rpcUrl, { // retries works strangely in viem, so we disable them retryCount: 0, retryDelay: 10000000, batch: BATCH_CONFIGS[this.config.chainId].http, timeout: MAX_TIMEOUT, }), pollingInterval: undefined, batch: BATCH_CONFIGS[this.config.chainId].client, chain: getViemChain(this.config.chainId), }); this.walletClient = config.walletClient ?? createWalletClient({ account: config.account, chain: getViemChain(config.chainId), transport: http(config.rpcUrl, { retryCount: 0, retryDelay: 10000000, batch: BATCH_CONFIGS[config.chainId].http, timeout: MAX_TIMEOUT, }), }); } setAccount(account) { this.config.account = account; } async executeMulticall(request) { const multicall = await Multicall.getInstance(this); return multicall?.call(request, MAX_TIMEOUT); } async callContract(address, abi, method, params, opts) { return callContract(this, address, abi, method, params, opts); } get chainId() { return this.config.chainId; } get chain() { return getViemChain(this.chainId); } get account() { return this.config.account; } } // Export all types and utilities export * from "./types"; export * from "./configs"; export * from "./utils"; export * from "./abis"; export * from "./prebuilt";