From 58bbb6a05f614444ed9e57367559e9f972cce152 Mon Sep 17 00:00:00 2001 From: Michael Feng Date: Thu, 9 Nov 2023 08:03:41 -0800 Subject: [PATCH] (fix) remove injective chain and exchange connectors --- docs/swagger/definitions.yml | 56 +- jest.config.js | 2 - package.json | 5 +- src/chains/algorand/algorand.validators.ts | 9 +- src/chains/chain.controller.ts | 10 +- src/chains/chain.routes.ts | 2 +- src/chains/injective/injective.config.ts | 35 - src/chains/injective/injective.controllers.ts | 54 - src/chains/injective/injective.mappers.ts | 66 - src/chains/injective/injective.message.ts | 279 -- src/chains/injective/injective.requests.ts | 49 - src/chains/injective/injective.ts | 543 --- src/chains/injective/injective.validators.ts | 71 - src/chains/kujira/kujira.ts | 2 +- src/connectors/connectors.routes.ts | 21 - .../injective/injective.clob.config.ts | 27 - src/connectors/injective/injective.ts | 250 -- .../injective_perpetual/injective.perp.ts | 585 ---- src/network/network.controllers.ts | 6 - src/services/common-interfaces.ts | 9 + src/services/connection-manager.ts | 15 - src/services/wallet/wallet.controllers.ts | 16 - src/services/wallet/wallet.validators.ts | 8 +- src/templates/injective.yml | 14 - src/templates/root.yml | 4 - .../injective/injective.message.test.ts | 222 -- .../chains/injective/injective.routes.test.ts | 304 -- .../injective/injective.validator.test.ts | 121 - test-bronze/clob/clob.routes.test.ts | 1782 +++++----- .../injective.perp.test.ts | 30 - test-helpers/curl/curl.sh | 86 - .../curl/requests/add_injective_key.json | 6 - .../curl/requests/injective_balances.json | 5 - .../curl/requests/injective_batch_create.json | 22 - .../curl/requests/injective_batch_delete.json | 16 - .../curl/requests/injective_delete_order.json | 8 - .../requests/injective_perp_batch_create.json | 24 - .../requests/injective_perp_batch_delete.json | 16 - .../requests/injective_perp_delete_order.json | 8 - .../requests/injective_perp_funding_info.json | 6 - .../injective_perp_funding_payments.json | 7 - .../injective_perp_last_trade_price.json | 6 - .../requests/injective_perp_order_trades.json | 8 - .../requests/injective_perp_positions.json | 7 - .../requests/injective_perp_post_order.json | 12 - .../curl/requests/injective_poll.json | 5 - .../curl/requests/injective_post_order.json | 11 - .../requests/injective_post_perp_order.json | 12 - .../requests/injective_transfer_to_bank.json | 9 - .../requests/injective_transfer_to_sub.json | 9 - yarn.lock | 2924 ++--------------- 51 files changed, 1217 insertions(+), 6587 deletions(-) delete mode 100644 src/chains/injective/injective.config.ts delete mode 100644 src/chains/injective/injective.controllers.ts delete mode 100644 src/chains/injective/injective.mappers.ts delete mode 100644 src/chains/injective/injective.message.ts delete mode 100644 src/chains/injective/injective.requests.ts delete mode 100644 src/chains/injective/injective.ts delete mode 100644 src/chains/injective/injective.validators.ts delete mode 100644 src/connectors/injective/injective.clob.config.ts delete mode 100644 src/connectors/injective/injective.ts delete mode 100644 src/connectors/injective_perpetual/injective.perp.ts delete mode 100644 src/templates/injective.yml delete mode 100644 test-bronze/chains/injective/injective.message.test.ts delete mode 100644 test-bronze/chains/injective/injective.routes.test.ts delete mode 100644 test-bronze/chains/injective/injective.validator.test.ts delete mode 100644 test-bronze/connectors/injective_perpetual/injective.perp.test.ts delete mode 100644 test-helpers/curl/requests/add_injective_key.json delete mode 100644 test-helpers/curl/requests/injective_balances.json delete mode 100644 test-helpers/curl/requests/injective_batch_create.json delete mode 100644 test-helpers/curl/requests/injective_batch_delete.json delete mode 100644 test-helpers/curl/requests/injective_delete_order.json delete mode 100644 test-helpers/curl/requests/injective_perp_batch_create.json delete mode 100644 test-helpers/curl/requests/injective_perp_batch_delete.json delete mode 100644 test-helpers/curl/requests/injective_perp_delete_order.json delete mode 100644 test-helpers/curl/requests/injective_perp_funding_info.json delete mode 100644 test-helpers/curl/requests/injective_perp_funding_payments.json delete mode 100644 test-helpers/curl/requests/injective_perp_last_trade_price.json delete mode 100644 test-helpers/curl/requests/injective_perp_order_trades.json delete mode 100644 test-helpers/curl/requests/injective_perp_positions.json delete mode 100644 test-helpers/curl/requests/injective_perp_post_order.json delete mode 100644 test-helpers/curl/requests/injective_poll.json delete mode 100644 test-helpers/curl/requests/injective_post_order.json delete mode 100644 test-helpers/curl/requests/injective_post_perp_order.json delete mode 100644 test-helpers/curl/requests/injective_transfer_to_bank.json delete mode 100644 test-helpers/curl/requests/injective_transfer_to_sub.json diff --git a/docs/swagger/definitions.yml b/docs/swagger/definitions.yml index 7c231e9813..f1c1207dcd 100644 --- a/docs/swagger/definitions.yml +++ b/docs/swagger/definitions.yml @@ -1445,13 +1445,13 @@ definitions: example: 'AAVE-USDT' chain: type: 'string' - example: 'injective' + example: 'dexalot' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' ClobMarketResponse: type: 'object' @@ -1483,16 +1483,16 @@ definitions: properties: market: type: 'string' - example: 'AAVE-USDT' + example: 'AVAX-USDC' chain: type: 'string' - example: 'injective' + example: 'dexalot' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' ClobTickerResponse: type: 'object' @@ -1525,16 +1525,16 @@ definitions: properties: market: type: 'string' - example: 'AAVE-USDT' + example: 'AVAX-USDC' chain: type: 'string' - example: 'injective' + example: 'dexalot' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' isDerivative: type: 'boolean' example: false @@ -1571,19 +1571,19 @@ definitions: properties: market: type: 'string' - example: 'AAVE-USDT' + example: 'AVAX-USDC' orderId: type: 'string' example: 'Buy-21342453' chain: type: 'string' - example: 'injective' + example: 'dexalot' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' address: type: 'string' example: '0x...' @@ -1624,16 +1624,16 @@ definitions: properties: market: type: 'string' - example: 'AAVE-USDT' + example: 'AVAX-USDC' chain: type: 'string' - example: 'injective' + example: 'dexalot' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' address: type: 'string' example: '0x...' @@ -1683,16 +1683,16 @@ definitions: properties: market: type: 'string' - example: 'AAVE-USDT' + example: 'AVAX-USDT' chain: type: 'string' - example: 'injective' + example: 'dexalot' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' address: type: 'string' example: '0x...' @@ -1734,7 +1734,7 @@ definitions: example: '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0' chain: type: 'string' - example: 'injective' + example: 'ethereum' network: type: 'string' example: 'mainnet' @@ -1786,7 +1786,7 @@ definitions: example: '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0' chain: type: 'string' - example: 'injective' + example: 'ethereum' network: type: 'string' example: 'mainnet' @@ -1877,7 +1877,7 @@ definitions: properties: chain: type: 'string' - example: 'injective' + example: 'dexalot' network: type: 'string' example: 'mainnet' @@ -1912,13 +1912,13 @@ definitions: example: 'Buy-21342453' chain: type: 'string' - example: 'injective' + example: 'ethereum' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' address: type: 'string' example: '0x...' @@ -1940,13 +1940,13 @@ definitions: example: 'Buy-21342453' chain: type: 'string' - example: 'injective' + example: 'ethereum' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' address: type: 'string' example: '0x...' @@ -1985,13 +1985,13 @@ definitions: example: 'INJ-USDT' chain: type: 'string' - example: 'injective' + example: 'ethereum' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' PerpClobFundingInfoResponse: type: 'object' @@ -2051,13 +2051,13 @@ definitions: properties: chain: type: 'string' - example: 'injective' + example: 'ethereum' network: type: 'string' example: 'mainnet' connector: type: 'string' - example: 'injective' + example: 'dexalot' address: type: 'string' example: '0x...' diff --git a/jest.config.js b/jest.config.js index d3ad4fc182..dbd4b77a3a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,7 +15,6 @@ module.exports = { 'src/chains/avalanche/avalanche.ts', 'src/chains/avalanche/pangolin/pangolin.ts', 'src/chains/cosmos/cosmos.ts', - 'src/chains/injective/injective.ts', 'src/chains/near/near.ts', 'src/chains/near/near.base.ts', 'src/connectors/uniswap/uniswap.config.ts', @@ -23,7 +22,6 @@ module.exports = { 'src/connectors/uniswap/uniswap.lp.helper.ts', 'src/connectors/openocean/openocean.ts', 'src/connectors/pangolin/pangolin.ts', - 'src/chains/injective/injective.mappers.ts', 'src/connectors/quickswap/quickswap.ts', 'src/connectors/sushiswap/sushiswap.ts', 'src/connectors/traderjoe/traderjoe.ts', diff --git a/package.json b/package.json index 97cf34c8ef..bfc663e12d 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,10 @@ "@ethersproject/networks": "5.7.0", "@ethersproject/providers": "5.7.0", "@ethersproject/solidity": "5.7.0", + "@injectivelabs/sdk-ts": "^1.10.58", "@harmony-js/core": "^0.1.57", "@harmony-js/utils": "^0.1.56", "@improbable-eng/grpc-web": "^0.13.0", - "@injectivelabs/networks": "^1.10.8", - "@injectivelabs/sdk-ts": "^1.10.58", - "@injectivelabs/ts-types": "^1.0.29", - "@injectivelabs/wallet-ts": "^1.10.63", "@pancakeswap/sdk": "^2.4.5", "@pangolindex/sdk": "^1.1.0", "@perp/sdk-curie": "^1.16.0", diff --git a/src/chains/algorand/algorand.validators.ts b/src/chains/algorand/algorand.validators.ts index cdd353314b..cc71bf41aa 100644 --- a/src/chains/algorand/algorand.validators.ts +++ b/src/chains/algorand/algorand.validators.ts @@ -10,9 +10,16 @@ import { invalidAddressError, validateNetwork, } from '../ethereum/ethereum.validators'; -import { validateTxHash } from '../injective/injective.validators'; import { invalidChainError } from '../near/near.validators'; +const invalidTxHashError: string = 'The txHash param must be a string.'; + +const validateTxHash: Validator = mkValidator( + 'txHash', + invalidTxHashError, + (val) => typeof val === 'string' +); + const validateAlgorandChain: Validator = mkValidator( 'chain', invalidChainError, diff --git a/src/chains/chain.controller.ts b/src/chains/chain.controller.ts index 58f8f4d8b7..59cd6ef925 100644 --- a/src/chains/chain.controller.ts +++ b/src/chains/chain.controller.ts @@ -1,6 +1,12 @@ import { latency } from '../services/base'; import { Chain } from '../services/common-interfaces'; + +import { + TransferRequest, + TransferResponse, +} from '../services/common-interfaces'; + import { BalanceRequest, BalanceResponse, @@ -19,10 +25,6 @@ import { CancelRequest, CancelResponse, } from './chain.requests'; -import { - TransferRequest, - TransferResponse, -} from './injective/injective.requests'; export async function poll( chain: Chain, diff --git a/src/chains/chain.routes.ts b/src/chains/chain.routes.ts index 9ec5f85501..cbc13bf922 100644 --- a/src/chains/chain.routes.ts +++ b/src/chains/chain.routes.ts @@ -52,7 +52,7 @@ import { import { TransferRequest, TransferResponse, -} from './injective/injective.requests'; +} from '../services/common-interfaces'; import { validateTezosNonceRequest } from './tezos/tezos.validators'; export const validatePollRequest: RequestValidator = mkRequestValidator([ diff --git a/src/chains/injective/injective.config.ts b/src/chains/injective/injective.config.ts deleted file mode 100644 index cbacefddbc..0000000000 --- a/src/chains/injective/injective.config.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ConfigManagerV2 } from '../../services/config-manager-v2'; -import { getNetworkFromString } from './injective.mappers'; -import { getNetworkEndpoints } from '@injectivelabs/networks'; - -export interface NetworkConfig { - name: string; - nodeURL: string; - chainId: string; - maxLRUCacheInstances: number; -} - -export interface Config { - network: NetworkConfig; - nativeCurrencySymbol: string; -} - -export function getInjectiveConfig(networkName: string): Config { - networkName = ['mainnet', 'mainnetLB'].includes(networkName) - ? 'mainnet' - : 'testnet'; - const network = getNetworkFromString(networkName); - return { - network: { - name: networkName, - chainId: ConfigManagerV2.getInstance().get( - 'injective.networks.' + networkName + '.chainId' - ), - nodeURL: network ? getNetworkEndpoints(network).indexer : '', - maxLRUCacheInstances: 10, - }, - nativeCurrencySymbol: ConfigManagerV2.getInstance().get( - 'injective.nativeCurrencySymbol' - ), - }; -} diff --git a/src/chains/injective/injective.controllers.ts b/src/chains/injective/injective.controllers.ts deleted file mode 100644 index 158f6fa21c..0000000000 --- a/src/chains/injective/injective.controllers.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Injective } from './injective'; -import { - BalancesRequest, - BalancesResponse, - PollRequest, - PollResponse, - TransferRequest, - TransferResponse, -} from './injective.requests'; -import { - validateBalanceRequest, - validatePollRequest, - validateTransferRequest, -} from './injective.validators'; - -export class InjectiveController { - static async currentBlockNumber(injective: Injective): Promise { - return injective.currentBlockNumber(); - } - - static async transfer( - injective: Injective, - req: TransferRequest - ): Promise { - validateTransferRequest(req); - - if (req.from.length > req.to.length) { - const wallet = await injective.getWallet(req.from); - return injective.transferToBankAccount(wallet, req.amount, req.token); - } else { - const wallet = await injective.getWallet(req.to); - return injective.transferToSubAccount(wallet, req.amount, req.token); - } - } - - static async balances( - injective: Injective, - req: BalancesRequest - ): Promise { - validateBalanceRequest(req); - - const wallet = await injective.getWallet(req.address); - return injective.balances(wallet); - } - - static async poll( - injective: Injective, - req: PollRequest - ): Promise { - validatePollRequest(req); - - return injective.poll(req.txHash); - } -} diff --git a/src/chains/injective/injective.mappers.ts b/src/chains/injective/injective.mappers.ts deleted file mode 100644 index 659a33771f..0000000000 --- a/src/chains/injective/injective.mappers.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { Network } from '@injectivelabs/networks'; -import { ChainId } from '@injectivelabs/ts-types'; - -export function getChainIdFromString(chainId: string): ChainId | null { - if (['mainnet', 'mainnetLB'].includes(chainId)) { - return ChainId.Mainnet; - } else if (['testnet', 'testnetK8s'].includes(chainId)) { - return ChainId.Testnet; - } else if (chainId === 'devnet') { - return ChainId.Devnet; - } else { - return null; - } -} - -export function chainIdToInt(chainId: ChainId): number { - if (chainId === ChainId.Mainnet) { - return 1; - } else if (chainId === ChainId.Testnet) { - return 2; - } else if (chainId === ChainId.Devnet) { - return 3; - } else { - throw `Unrecognized chain ID ${chainId}.`; - } -} - -export function getNetworkFromString(network: string): Network | null { - if (['mainnet', 'mainnetLB'].includes(network)) { - return Network.MainnetLB; - } else if (network === 'staging') { - return Network.Staging; - } else if (network === 'public') { - return Network.Public; - } else if (['testnet', 'testnetK8s'].includes(network)) { - return Network.TestnetK8s; - } else if (network === 'devnet1') { - return Network.Devnet1; - } else if (network === 'devnet') { - return Network.Devnet; - } else if (network === 'local') { - return Network.Local; - } else { - return null; - } -} - -export function networkToString(network: Network): string { - if ([Network.MainnetLB, Network.Mainnet].includes(network)) { - return 'mainnet'; - } else if (network === Network.Staging) { - return 'staging'; - } else if (network === Network.Public) { - return 'public'; - } else if ([Network.TestnetK8s, Network.Testnet].includes(network)) { - return 'testnet'; - } else if (network === Network.Devnet1) { - return 'devnet1'; - } else if (network === Network.Devnet) { - return 'devnet'; - } else if (network === Network.Local) { - return 'local'; - } else { - throw `Unrecognized network ${network}.`; - } -} diff --git a/src/chains/injective/injective.message.ts b/src/chains/injective/injective.message.ts deleted file mode 100644 index 9927c72ea3..0000000000 --- a/src/chains/injective/injective.message.ts +++ /dev/null @@ -1,279 +0,0 @@ -import { BigNumberInBase, DEFAULT_STD_FEE } from '@injectivelabs/utils'; -import { - PrivateKey, - Msgs, - createTransaction, - getEthereumSignerAddress, - getInjectiveSignerAddress, - BroadcastMode, - TxRestClient, - TxClient, - TxRaw, -} from '@injectivelabs/sdk-ts'; -import { EthereumChainId } from '@injectivelabs/ts-types'; -import { - getNetworkEndpoints, - getNetworkInfo, - Network, - NetworkEndpoints, -} from '@injectivelabs/networks'; -import { Injective } from './injective'; -import LRUCache from 'lru-cache'; -import { getInjectiveConfig } from './injective.config'; -import { networkToString } from './injective.mappers'; -import { AccountDetails } from '@injectivelabs/sdk-ts/dist/cjs/types/auth'; - -interface MsgBroadcasterTxOptions { - msgs: Msgs | Msgs[]; - injectiveAddress: string; - ethereumAddress?: string; - memo?: string; - feePrice?: string; - feeDenom?: string; - gasLimit?: number; - sequence?: number; -} - -interface MsgBroadcasterOptionsLocal { - network: Network; - - /** - * Only used if we want to override the default - * endpoints taken from the network param - */ - endpoints?: { - indexer: string; - grpc: string; - rest: string; - }; - privateKey: string; - ethereumChainId?: EthereumChainId; -} - -/** - * This class is used to broadcast transactions - * using a privateKey as a signer - * for the transactions and broadcasting - * the transactions directly to the node - * - * Mainly used for working in a Node Environment - */ -export class MsgBroadcasterLocal { - private _chain: Injective; - - public endpoints: NetworkEndpoints; - - public chainId: string; - - private _privateKey: PrivateKey; - - private _accountDetails: LRUCache; - - private _localSequence: number; - - private _isBlocked: boolean; - - private _txQueue: MsgBroadcasterTxOptions[]; - - private static _instances: LRUCache; - - constructor(options: MsgBroadcasterOptionsLocal) { - const networkInfo = getNetworkInfo(options.network); - const endpoints = getNetworkEndpoints(options.network); - - this.chainId = networkInfo.chainId; - this.endpoints = { ...endpoints, ...(endpoints || {}) }; - this._chain = Injective.getInstance(options.network); - this._privateKey = PrivateKey.fromHex(options.privateKey); - const config = getInjectiveConfig(networkToString(options.network)); - this._accountDetails = new LRUCache({ - max: config.network.maxLRUCacheInstances, - }); - this._localSequence = 0; - this._isBlocked = false; - this._txQueue = []; - } - - public static getInstance( - options: MsgBroadcasterOptionsLocal - ): MsgBroadcasterLocal { - if (MsgBroadcasterLocal._instances === undefined) { - const config = getInjectiveConfig(networkToString(options.network)); - MsgBroadcasterLocal._instances = new LRUCache< - string, - MsgBroadcasterLocal - >({ - max: config.network.maxLRUCacheInstances, - }); - } - const instanceKey = options.network + options.privateKey; - if (!MsgBroadcasterLocal._instances.has(instanceKey)) { - MsgBroadcasterLocal._instances.set( - instanceKey, - new MsgBroadcasterLocal(options) - ); - } - - return MsgBroadcasterLocal._instances.get( - instanceKey - ) as MsgBroadcasterLocal; - } - - isNextTx(tx: MsgBroadcasterTxOptions): boolean { - return !this._isBlocked && tx === this._txQueue[0]; - } - - async sleep(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms)); - } - - /** - * Broadcasting the transaction using the client - * - * @param transaction - * @returns {string} transaction hash - */ - async broadcast( - transaction: MsgBroadcasterTxOptions - ): Promise<{ txHash: string }> { - let txResponse: { - data: any; - }; - const tx = { - msgs: Array.isArray(transaction.msgs) - ? transaction.msgs - : [transaction.msgs], - ethereumAddress: getEthereumSignerAddress(transaction.injectiveAddress), - injectiveAddress: getInjectiveSignerAddress(transaction.injectiveAddress), - sequence: this._localSequence++, - } as MsgBroadcasterTxOptions; - this._txQueue.push(tx); - - try { - while (!this.isNextTx(tx)) { - await this.sleep(10); // sleep - } - this._isBlocked = true; - - /** Account Details **/ - const accountDetails = await this.getAccountDetails(transaction); - - /** Block Details */ - const timeoutHeight = new BigNumberInBase( - this._chain.currentBlock === 0 - ? await this._chain.currentBlockNumber() - : this._chain.currentBlock - ).plus(120); - - /** Prepare the Transaction * */ - const currentNonce = await this._chain.nonceManager.getNextNonce( - transaction.injectiveAddress - ); - txResponse = await this.createAndSend( - tx, - timeoutHeight, - accountDetails, - currentNonce - ); - if ( - txResponse.data.tx_response.code === 32 && - txResponse.data.tx_response.raw_log.startsWith( - 'account sequence mismatch, expected ', - 0 - ) - ) { - const expectedSequence = Number( - txResponse.data.tx_response.raw_log - .split('account sequence mismatch, expected ')[1] - .split(',')[0] - ); - await this._chain.nonceManager.overridePendingNonce( - transaction.injectiveAddress, - expectedSequence - ); - txResponse = await this.createAndSend( - tx, - timeoutHeight, - accountDetails, - expectedSequence - ); - } else if (txResponse.data.tx_response.code === 0) { - await this._chain.nonceManager.commitNonce( - transaction.injectiveAddress, - currentNonce - ); - } else { - throw new Error(txResponse.data.tx_response.raw_log); - } - } finally { - this._txQueue.shift(); - this._isBlocked = false; - } - - return { - txHash: - txResponse.data.tx_response.code === 0 - ? txResponse.data.tx_response.txhash - : '', - }; - } - - async createAndSend( - tx: MsgBroadcasterTxOptions, - timeoutHeight: BigNumberInBase, - accountDetails: AccountDetails, - sequence: number - ): Promise<{ data: any }> { - const { signBytes, txRaw } = createTransaction({ - memo: '', - fee: DEFAULT_STD_FEE, - message: tx.msgs as Msgs[], - timeoutHeight: timeoutHeight.toNumber(), - pubKey: this._privateKey.toPublicKey().toBase64(), - sequence: sequence, - accountNumber: accountDetails.accountNumber, - chainId: this.chainId, - }); - - /** Sign transaction */ - const signature = await this._privateKey.sign(Buffer.from(signBytes)); - - /** Append Signatures */ - txRaw.signatures = [signature]; - - /** Broadcast transaction */ - const txResponse = await this.broadcastUsingInjective( - txRaw, - BroadcastMode.Sync - ); - return txResponse as { data: any }; - } - - private async broadcastUsingInjective( - txRaw: TxRaw, - mode: BroadcastMode - ): Promise { - return await new TxRestClient(this.endpoints.rest).httpClient.post< - URLSearchParams | any, - { data: any } - >('cosmos/tx/v1beta1/txs', { - tx_bytes: TxClient.encode(txRaw), - mode, - }); - } - - private async getAccountDetails( - transaction: MsgBroadcasterTxOptions - ): Promise { - if (!this._accountDetails.has(transaction.injectiveAddress)) { - this._accountDetails.set( - transaction.injectiveAddress, - await this._chain.getOnChainAccount(transaction.injectiveAddress) - ); - } - const accountDetails = this._accountDetails.get( - transaction.injectiveAddress - ) as AccountDetails; - return accountDetails; - } -} diff --git a/src/chains/injective/injective.requests.ts b/src/chains/injective/injective.requests.ts deleted file mode 100644 index f0bd0be1b2..0000000000 --- a/src/chains/injective/injective.requests.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { NetworkSelectionRequest } from '../../services/common-interfaces'; - -export interface BalancesRequest extends NetworkSelectionRequest { - address: string; // the EVM address of a private key -} - -export interface PollRequest extends NetworkSelectionRequest { - txHash: string; -} - -export type PollResponse = { - blockNumber: number; - hash: string; - gasWanted: number; - gasLimit: number; - gasUsed: number; - sequences: Array; -}; - -export type SubaccountBalanceSub = { - token: string; - totalBalance: string; - availableBalance: string; -}; - -export type SubaccountBalancesWithId = { - subaccountId: string; - balances: Array; -}; - -export type BankBalance = { - token: string; - amount: string; -}; - -export type BalancesResponse = { - injectiveAddress: string; - balances: Array; - subaccounts: Array; -}; - -export interface TransferRequest extends NetworkSelectionRequest { - to: string; - from: string; - amount: string; - token: string; -} - -export type TransferResponse = string; diff --git a/src/chains/injective/injective.ts b/src/chains/injective/injective.ts deleted file mode 100644 index bfc9873002..0000000000 --- a/src/chains/injective/injective.ts +++ /dev/null @@ -1,543 +0,0 @@ -import { - HttpException, - AMOUNT_NOT_SUPPORTED_ERROR_CODE, - AMOUNT_NOT_SUPPORTED_ERROR_MESSAGE, - TOKEN_NOT_SUPPORTED_ERROR_CODE, - TOKEN_NOT_SUPPORTED_ERROR_MESSAGE, -} from '../../services/error-handler'; -import { - chainIdToInt, - getChainIdFromString, - getNetworkFromString, - networkToString, -} from './injective.mappers'; -import { ReferenceCountingCloseable } from '../../services/refcounting-closeable'; -import { BigNumber } from 'ethers'; -import { - bigNumberWithDecimalToStr, - floatStringWithDecimalToBigNumber, -} from '../../services/base'; -import { logger } from '../../services/logger'; -import { Wallet as EthereumWallet } from 'ethers'; -import { walletPath } from '../../services/base'; -import fse from 'fs-extra'; -import { ConfigManagerCertPassphrase } from '../../services/config-manager-cert-passphrase'; -import { ChainId } from '@injectivelabs/ts-types'; -import { - BaseAccount, - MsgDeposit, - MsgWithdraw, - ChainRestAuthApi, - ChainRestBankApi, - IndexerGrpcAccountApi, - IndexerGrpcSpotApi, - PrivateKey, - SubaccountBalance, - TxRestClient, - ChainRestTendermintApi, -} from '@injectivelabs/sdk-ts'; -import { Network, getNetworkEndpoints } from '@injectivelabs/networks'; -import { getInjectiveConfig } from './injective.config'; -import { - BankBalance, - BalancesResponse, - SubaccountBalanceSub, - SubaccountBalancesWithId, -} from './injective.requests'; -import { - ConfigManagerV2, - resolveDBPath, -} from '../../services/config-manager-v2'; -import { MsgBroadcasterLocal } from './injective.message'; -import LRUCache from 'lru-cache'; -import { TokenInfo } from '../../services/base'; -import { EVMNonceManager } from '../ethereum/evm.nonce'; -import { AccountDetails } from '@injectivelabs/sdk-ts/dist/cjs/types/auth'; -import { InjectiveController } from './injective.controllers'; - -export interface InjectiveWallet { - ethereumAddress: string; - injectiveAddress: string; - privateKey: string; - subaccountId: string; -} - -export class Injective { - private static _instances: LRUCache; - private _ready: boolean = false; - private _initialized: Promise = Promise.resolve(false); - - private _network: Network; - private _chainId: ChainId; - private _chainName: string = 'injective'; - private _endpoints; - private _denomToToken: Record = {}; // the addresses are prefixed with things like peggy, ibc, etc. They come from the injective api. - - private _symbolToToken: Record = {}; - private _spotApi: IndexerGrpcSpotApi; - private _indexerGrpcAccountApi: IndexerGrpcAccountApi; - private _chainRestTendermintApi: ChainRestTendermintApi; - private _chainRestAuthApi: ChainRestAuthApi; - private _chainRestBankApi: ChainRestBankApi; - - private readonly _refCountingHandle: string; - private readonly _nonceManager: EVMNonceManager; - - public gasPrice = 500000000; - public nativeTokenSymbol = 'INJ'; - public currentBlock = 0; - public maxCacheSize: number; - private _blockUpdateIntervalID: number | undefined; - private _walletMap: LRUCache; - public controller: typeof InjectiveController; - - private constructor(network: Network, chainId: ChainId) { - this._network = network; - this._chainId = chainId; - this._endpoints = getNetworkEndpoints(this._network); - logger.info(`Injective endpoints: ${JSON.stringify(this._endpoints)}`); - this._spotApi = new IndexerGrpcSpotApi(this._endpoints.indexer); - this._indexerGrpcAccountApi = new IndexerGrpcAccountApi( - this._endpoints.indexer - ); - this._chainRestTendermintApi = new ChainRestTendermintApi( - this._endpoints.rest - ); - this._chainRestAuthApi = new ChainRestAuthApi(this._endpoints.rest); - this._chainRestBankApi = new ChainRestBankApi(this._endpoints.rest); - - this._refCountingHandle = ReferenceCountingCloseable.createHandle(); - this._nonceManager = new EVMNonceManager( - 'injective', - chainIdToInt(this._chainId), - resolveDBPath( - ConfigManagerV2.getInstance().get('server.transactionDbPath') - ), - 3600000, - 3600000 - ); - const config = getInjectiveConfig(networkToString(network)); - this.maxCacheSize = config.network.maxLRUCacheInstances; - this._nonceManager.declareOwnership(this._refCountingHandle); - this._walletMap = new LRUCache({ - max: this.maxCacheSize, - }); - this.controller = InjectiveController; - } - - public static getInstance(networkStr: string): Injective { - const config = getInjectiveConfig(networkStr); - if (Injective._instances === undefined) { - Injective._instances = new LRUCache({ - max: config.network.maxLRUCacheInstances, - }); - } - - if (!Injective._instances.has(config.network.name)) { - const network = getNetworkFromString(config.network.name); - const chainId = getChainIdFromString(config.network.chainId); - if (network !== null && chainId !== null) { - Injective._instances.set( - config.network.name, - new Injective(network, chainId) - ); - } else { - throw new Error( - `Injective.getInstance received an unexpected network: ${network}.` - ); - } - } - - return Injective._instances.get(config.network.name) as Injective; - } - - public async init(): Promise { - await this._initialized; // Wait for any previous init() calls to complete - if (!this.ready()) { - // If we're not ready, this._initialized will be a Promise that resolves after init() completes - this._initialized = (async () => { - try { - // initialize nonce manager - await this._nonceManager.init( - async (address: string) => await this.getTransactionCount(address) - ); - // start updating block number - this._blockUpdateIntervalID = setInterval(async () => { - await this.updateCurrentBlockNumber(); - }, 2000) as unknown as number; - - // get tokens - const rawMarkets = await this._spotApi.fetchMarkets(); - for (const market of rawMarkets) { - if (market.baseToken) { - const token = { - address: '', - chainId: chainIdToInt(this._chainId), - name: market.baseToken.name, - decimals: market.baseToken.decimals, - symbol: market.baseToken.symbol, - denom: market.baseDenom, - }; - this._symbolToToken[market.baseToken.symbol] = token; - this._denomToToken[market.baseDenom] = token; - } - - if (market.quoteToken) { - const token = { - address: '', - chainId: chainIdToInt(this._chainId), - name: market.quoteToken.name, - decimals: market.quoteToken.decimals, - symbol: market.quoteToken.symbol, - denom: market.quoteDenom, - }; - this._symbolToToken[market.quoteToken.symbol] = token; - this._denomToToken[market.quoteDenom] = token; - } - } - return true; - } catch (e) { - logger.error(`Failed to initialize ${this.chainName} chain: ${e}`); - return false; - } - })(); - this._ready = await this._initialized; // Wait for the initialization to complete - } - return; - } - - public get chainRestTendermintApi(): ChainRestTendermintApi { - return this._chainRestTendermintApi; - } - - public get chainRestBankApi(): ChainRestBankApi { - return this._chainRestBankApi; - } - - public ready(): boolean { - return this._ready; - } - - public get network(): string { - return this._network; - } - - public get chainId(): ChainId { - return this._chainId; - } - - public get chainName(): string { - return this._chainName; - } - - public get endpoints() { - return this._endpoints; - } - - public get nonceManager() { - return this._nonceManager; - } - - public get storedTokenList(): Array { - return Object.values(this._symbolToToken); - } - - public static getConnectedInstances(): { [name: string]: Injective } { - const connectedInstances: { [name: string]: Injective } = {}; - if (this._instances !== undefined) { - const keys = Array.from(this._instances.keys()); - for (const instance of keys) { - if (instance !== undefined) { - connectedInstances[instance] = this._instances.get( - instance - ) as Injective; - } - } - } - return connectedInstances; - } - - public broadcaster(privateKey: string) { - return MsgBroadcasterLocal.getInstance({ - network: this._network, - privateKey, - }); - } - - public async currentBlockNumber(): Promise { - return Number( - (await this._chainRestTendermintApi.fetchLatestBlock()).header.height - ); - } - - public async updateCurrentBlockNumber() { - this.currentBlock = await this.currentBlockNumber(); - } - - public async poll(txHash: string): Promise { - return await new TxRestClient(this.endpoints.rest).fetchTx(txHash); - } - - private getPrivateKeyFromHex(privateKey: string): PrivateKey { - return PrivateKey.fromHex(privateKey); - } - - public getWalletFromPrivateKey(privateKey: string): EthereumWallet { - return new EthereumWallet(privateKey); - } - - public encrypt(privateKey: string, password: string): Promise { - const wallet = this.getWalletFromPrivateKey(privateKey); - return wallet.encrypt(password); - } - - private async decrypt( - encryptedPrivateKey: string, - password: string - ): Promise { - return EthereumWallet.fromEncryptedJson(encryptedPrivateKey, password); - } - - // getWallet by subsaccountid - public async getWallet(address: string): Promise { - if (!this._walletMap.has(address)) { - this._walletMap.set(address, await this.loadWallet(address)); - } - return this._walletMap.get(address) as InjectiveWallet; - } - - private async loadWallet(address: string): Promise { - const path = `${walletPath}/${this._chainName}`; - - const encryptedPrivateKey: string = await fse.readFile( - `${path}/${address}.json`, - 'utf8' - ); - - const passphrase = ConfigManagerCertPassphrase.readPassphrase(); - if (!passphrase) { - throw new Error('missing passphrase'); - } - const ethereumWallet = await this.decrypt(encryptedPrivateKey, passphrase); - const privateKey = this.getPrivateKeyFromHex(ethereumWallet.privateKey); - const ethereumAddress = privateKey.toHex(); - - return { - privateKey: ethereumWallet.privateKey, - injectiveAddress: privateKey.toBech32(), - ethereumAddress, - subaccountId: address, - }; - } - - public async transferToSubAccount( - wallet: InjectiveWallet, - amount: string, // string encoded float, this needs to be resolved as an integer string - tokenSymbol: string // the token symbol, this needs to be resolved as the denom - ): Promise { - const denom = this.getTokenForSymbol(tokenSymbol); - - if (denom && denom.denom) { - const correctAmount = floatStringWithDecimalToBigNumber( - amount, - denom.decimals - ); - if (correctAmount === null) { - throw new HttpException( - 500, - AMOUNT_NOT_SUPPORTED_ERROR_MESSAGE, - AMOUNT_NOT_SUPPORTED_ERROR_CODE - ); - } - const amountPair = { - amount: correctAmount.toString(), - denom: denom.denom, - }; - const msg = MsgDeposit.fromJSON({ - amount: amountPair, - subaccountId: wallet.subaccountId, - injectiveAddress: wallet.injectiveAddress, - }); - - const response = await this.broadcaster(wallet.privateKey).broadcast({ - msgs: msg, - injectiveAddress: wallet.injectiveAddress, - }); - return response.txHash; - } else { - throw new HttpException( - 500, - TOKEN_NOT_SUPPORTED_ERROR_MESSAGE, - TOKEN_NOT_SUPPORTED_ERROR_CODE - ); - } - } - - public async transferToBankAccount( - wallet: InjectiveWallet, - amount: string, // string encoded float, this needs to be resolved as an integer string - tokenSymbol: string // the token symbol, this needs to be resolved as the denom - ): Promise { - const denom = this.getTokenForSymbol(tokenSymbol); - - if (denom && denom.denom) { - const correctAmount = floatStringWithDecimalToBigNumber( - amount, - denom.decimals - ); - if (correctAmount === null) { - throw new HttpException( - 500, - AMOUNT_NOT_SUPPORTED_ERROR_MESSAGE, - AMOUNT_NOT_SUPPORTED_ERROR_CODE - ); - } - - const amountPair = { - amount: correctAmount.toString(), - denom: denom.denom, - }; - const msg = MsgWithdraw.fromJSON({ - amount: amountPair, - subaccountId: wallet.subaccountId, - injectiveAddress: wallet.injectiveAddress, - }); - - const response = await this.broadcaster(wallet.privateKey).broadcast({ - msgs: msg, - injectiveAddress: wallet.injectiveAddress, - }); - return response.txHash; - } else { - throw new HttpException( - 500, - TOKEN_NOT_SUPPORTED_ERROR_MESSAGE, - TOKEN_NOT_SUPPORTED_ERROR_CODE - ); - } - } - - public getTokenForSymbol(symbol: string): TokenInfo | null { - return this._symbolToToken[symbol] ? this._symbolToToken[symbol] : null; - } - - async getTokenByDenom(denom: string): Promise { - if (this._denomToToken[denom] !== undefined) { - return this._denomToToken[denom]; - } else { - logger.error(`Injective did not recognize the token denom: ${denom}`); - return; - } - } - - public async balances(wallet: InjectiveWallet): Promise { - const bankBalancesRaw = await this._chainRestBankApi.fetchBalances( - wallet.injectiveAddress - ); - const bankBalances: Array = []; - for (const bankBalance of bankBalancesRaw.balances) { - const token = await this.getTokenByDenom(bankBalance.denom); - if (token !== undefined) { - bankBalances.push({ - token: token.symbol, - amount: bigNumberWithDecimalToStr( - BigNumber.from(bankBalance.amount), - token.decimals - ), - }); - } - } - - const subaccountIds = - await this._indexerGrpcAccountApi.fetchSubaccountsList( - wallet.injectiveAddress - ); - - const promises: Array>> = []; - for (const subaccountId of subaccountIds) { - promises.push( - this._indexerGrpcAccountApi.fetchSubaccountBalancesList(subaccountId) - ); - } - - const subaccountData = await Promise.all(promises); - - const subaccounts: Array = []; - for (const subaccountBalances of subaccountData) { - if (subaccountBalances.length > 0) { - const balances: Array = []; - for (const subaccountBalance of subaccountBalances) { - if (subaccountBalance.deposit) { - const token = await this.getTokenByDenom(subaccountBalance.denom); - if (token !== undefined) { - const balance: SubaccountBalanceSub = { - token: token.symbol, - - totalBalance: bigNumberWithDecimalToStr( - BigNumber.from( - subaccountBalance.deposit.totalBalance.split('.')[0] - ), - token.decimals - ), - availableBalance: bigNumberWithDecimalToStr( - BigNumber.from( - subaccountBalance.deposit.availableBalance.split('.')[0] - ), - token.decimals - ), - }; - balances.push(balance); - } - } - } - const subaccount = { - subaccountId: subaccountBalances[0].subaccountId, - balances, - }; - - subaccounts.push(subaccount); - } - } - - return { - balances: bankBalances, - injectiveAddress: wallet.injectiveAddress, - subaccounts: subaccounts, - }; - } - - public async getTransactionCount(injectiveAddress: string): Promise { - const accountDetailsResponse = await this._chainRestAuthApi.fetchAccount( - injectiveAddress - ); - const baseAccount = BaseAccount.fromRestApi(accountDetailsResponse); - const accountDetails = baseAccount.toAccountDetails(); - - return accountDetails.sequence; - } - - public async getOnChainAccount( - injectiveAddress: string - ): Promise { - return BaseAccount.fromRestApi( - await this._chainRestAuthApi.fetchAccount(injectiveAddress) - ).toAccountDetails(); - } - - // returns the current block number - async getCurrentBlockNumber(): Promise { - return await this.currentBlockNumber(); - } - - public async close() { - const instance = Injective._instances.get(this._network); - if (instance !== undefined) { - if (instance._blockUpdateIntervalID !== undefined) { - clearInterval(instance._blockUpdateIntervalID as number); - } - Injective._instances.delete(this._network); - } - - await this._nonceManager.close(this._refCountingHandle); - } -} diff --git a/src/chains/injective/injective.validators.ts b/src/chains/injective/injective.validators.ts deleted file mode 100644 index be6139aaba..0000000000 --- a/src/chains/injective/injective.validators.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { - isFloatString, - invalidAmountError, - mkValidator, - Validator, - mkRequestValidator, - RequestValidator, -} from '../../services/validators'; -import { validateNetwork } from '../ethereum/ethereum.validators'; - -export const invalidTxHashError: string = 'The txHash param must be a string.'; - -export const invalidTokenError: string = 'The token param must be a string.'; - -export const validateTxHash: Validator = mkValidator( - 'txHash', - invalidTxHashError, - (val) => typeof val === 'string' -); - -export const invalidAddressError: string = - 'The address param must be a non-empty string.'; - -// given a request, look for a key called address that is an Ethereum wallet -export const validateAddress: Validator = mkValidator( - 'address', - invalidAddressError, - (val) => typeof val === 'string' -); - -export const validateFrom: Validator = mkValidator( - 'from', - invalidAddressError, - (val) => typeof val === 'string' -); - -export const validateTo: Validator = mkValidator( - 'to', - invalidAddressError, - (val) => typeof val === 'string' -); - -export const validateBalanceRequest: RequestValidator = mkRequestValidator([ - validateNetwork, - validateAddress, -]); - -export const validatePollRequest: RequestValidator = mkRequestValidator([ - validateNetwork, - validateTxHash, -]); - -export const validateAmount: Validator = mkValidator( - 'amount', - invalidAmountError, - (val) => typeof val === 'string' && isFloatString(val) -); - -export const validateToken: Validator = mkValidator( - 'token', - invalidTokenError, - (val) => typeof val === 'string' -); - -export const validateTransferRequest = mkRequestValidator([ - validateNetwork, - validateFrom, - validateTo, - validateAmount, - validateToken, -]); diff --git a/src/chains/kujira/kujira.ts b/src/chains/kujira/kujira.ts index 021828698a..81a44558c7 100644 --- a/src/chains/kujira/kujira.ts +++ b/src/chains/kujira/kujira.ts @@ -25,7 +25,7 @@ import { import { TransferRequest, TransferResponse, -} from '../injective/injective.requests'; +} from '../../services/common-interfaces'; import { BigNumber } from 'bignumber.js'; export class Kujira { diff --git a/src/connectors/connectors.routes.ts b/src/connectors/connectors.routes.ts index 67e752419d..ad4d13c9de 100644 --- a/src/connectors/connectors.routes.ts +++ b/src/connectors/connectors.routes.ts @@ -13,7 +13,6 @@ import { UniswapConfig } from './uniswap/uniswap.config'; import { VVSConfig } from './vvs/vvs.config'; import { RefConfig } from './ref/ref.config'; import { PancakeSwapConfig } from './pancakeswap/pancakeswap.config'; -import { InjectiveCLOBConfig } from './injective/injective.clob.config'; import { XsswapConfig } from './xsswap/xsswap.config'; import { ConnectorsResponse } from './connectors.request'; import { DexalotCLOBConfig } from './dexalot/dexalot.clob.config'; @@ -105,26 +104,6 @@ export namespace ConnectorsRoutes { chain_type: PancakeSwapConfig.config.chainType, available_networks: PancakeSwapConfig.config.availableNetworks, }, - { - name: 'injective', - trading_type: InjectiveCLOBConfig.config.tradingTypes('spot'), - chain_type: InjectiveCLOBConfig.config.chainType, - available_networks: InjectiveCLOBConfig.config.availableNetworks, - additional_add_wallet_prompts: { - accountId: - 'Enter your injective sub account id wallet key (input 0 if unsure) >>> ', - }, - }, - { - name: 'injective_perpetual', - trading_type: InjectiveCLOBConfig.config.tradingTypes('perp'), - chain_type: InjectiveCLOBConfig.config.chainType, - available_networks: InjectiveCLOBConfig.config.availableNetworks, - additional_add_wallet_prompts: { - accountId: - 'Enter your injective sub account id wallet key (input 0 if unsure) >>> ', - }, - }, { name: 'xswap', trading_type: XsswapConfig.config.tradingTypes, diff --git a/src/connectors/injective/injective.clob.config.ts b/src/connectors/injective/injective.clob.config.ts deleted file mode 100644 index aaed5efad2..0000000000 --- a/src/connectors/injective/injective.clob.config.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { AvailableNetworks } from '../../services/config-manager-types'; -import { ConfigManagerV2 } from '../../services/config-manager-v2'; - -export namespace InjectiveCLOBConfig { - export interface NetworkConfig { - gasLimitEstimate: number; - tradingTypes: (type: string) => Array; - chainType: string; - availableNetworks: Array; - } - - export const config: NetworkConfig = { - gasLimitEstimate: ConfigManagerV2.getInstance().get( - `injective.gasLimitEstimate` - ), - tradingTypes: (type: string) => { - return type === 'spot' ? ['CLOB_SPOT'] : ['CLOB_PERP']; - }, - chainType: 'INJECTIVE', - availableNetworks: [ - { - chain: 'injective', - networks: ['mainnet', 'testnet'], - }, - ], - }; -} diff --git a/src/connectors/injective/injective.ts b/src/connectors/injective/injective.ts deleted file mode 100644 index 6685d75052..0000000000 --- a/src/connectors/injective/injective.ts +++ /dev/null @@ -1,250 +0,0 @@ -import { - MsgBatchUpdateOrders, - IndexerGrpcSpotApi, - Orderbook, - SpotOrderHistory, - GrpcOrderType, - spotPriceToChainPriceToFixed, - spotQuantityToChainQuantityToFixed, -} from '@injectivelabs/sdk-ts'; -import { - ClobMarketsRequest, - ClobOrderbookRequest, - ClobTickerRequest, - ClobGetOrderRequest, - ClobPostOrderRequest, - ClobDeleteOrderRequest, - CLOBMarkets, - ClobGetOrderResponse, - ClobBatchUpdateRequest, - CreateOrderParam, - ClobDeleteOrderRequestExtract, -} from '../../clob/clob.requests'; -import { - CLOBish, - NetworkSelectionRequest, -} from '../../services/common-interfaces'; -import { InjectiveCLOBConfig } from './injective.clob.config'; -import { Injective } from '../../chains/injective/injective'; -import LRUCache from 'lru-cache'; -import { getInjectiveConfig } from '../../chains/injective/injective.config'; - -export class InjectiveCLOB implements CLOBish { - private static _instances: LRUCache; - private _chain; - public conf; - public spotApi: IndexerGrpcSpotApi; - private _ready: boolean = false; - public parsedMarkets: CLOBMarkets = {}; - - private constructor(_chain: string, network: string) { - this._chain = Injective.getInstance(network); - this.conf = InjectiveCLOBConfig.config; - this.spotApi = new IndexerGrpcSpotApi(this._chain.endpoints.indexer); - } - - public static getInstance(chain: string, network: string): InjectiveCLOB { - if (InjectiveCLOB._instances === undefined) { - const config = getInjectiveConfig(network); - InjectiveCLOB._instances = new LRUCache({ - max: config.network.maxLRUCacheInstances, - }); - } - const instanceKey = chain + network; - if (!InjectiveCLOB._instances.has(instanceKey)) { - InjectiveCLOB._instances.set( - instanceKey, - new InjectiveCLOB(chain, network) - ); - } - - return InjectiveCLOB._instances.get(instanceKey) as InjectiveCLOB; - } - - public async loadMarkets() { - const rawMarkets = await this.spotApi.fetchMarkets(); - for (const market of rawMarkets) { - this.parsedMarkets[market.ticker.replace('/', '-')] = market; - } - } - - public async init() { - if (!this._chain.ready() || Object.keys(this.parsedMarkets).length === 0) { - await this._chain.init(); - await this.loadMarkets(); - this._ready = true; - } - } - - public ready(): boolean { - return this._ready; - } - - public async markets( - req: ClobMarketsRequest - ): Promise<{ markets: CLOBMarkets }> { - if (req.market && req.market.split('-').length === 2) { - const resp: CLOBMarkets = {}; - resp[req.market] = this.parsedMarkets[req.market]; - return { markets: resp }; - } - return { markets: this.parsedMarkets }; - } - - public async orderBook(req: ClobOrderbookRequest): Promise { - return await this.spotApi.fetchOrderbookV2( - this.parsedMarkets[req.market].marketId - ); - } - - public async ticker( - req: ClobTickerRequest - ): Promise<{ markets: CLOBMarkets }> { - return await this.markets(req); - } - - public async orders( - req: ClobGetOrderRequest - ): Promise<{ orders: ClobGetOrderResponse['orders'] }> { - if (!req.market) return { orders: [] }; - const marketId = this.parsedMarkets[req.market].marketId; - const orders: SpotOrderHistory[] = ( - await this.spotApi.fetchOrderHistory({ - subaccountId: req.address, - marketId, - }) - ).orderHistory; - - return { orders } as ClobGetOrderResponse; - } - - public async postOrder( - req: ClobPostOrderRequest - ): Promise<{ txHash: string }> { - return await this.orderUpdate(req); - } - - public async deleteOrder( - req: ClobDeleteOrderRequest - ): Promise<{ txHash: string }> { - return this.orderUpdate(req); - } - - public async batchOrders( - req: ClobBatchUpdateRequest - ): Promise<{ txHash: string }> { - return this.orderUpdate(req); - } - - public async orderUpdate( - req: ClobDeleteOrderRequest | ClobPostOrderRequest | ClobBatchUpdateRequest - ): Promise<{ txHash: string }> { - const wallet = await this._chain.getWallet(req.address); - const privateKey: string = wallet.privateKey; - const injectiveAddress: string = wallet.injectiveAddress; - let spotOrdersToCreate: CreateOrderParam[] = []; - let spotOrdersToCancel: ClobDeleteOrderRequestExtract[] = []; - if ('createOrderParams' in req) - spotOrdersToCreate = spotOrdersToCreate.concat( - req.createOrderParams as CreateOrderParam[] - ); - if ('price' in req) - spotOrdersToCreate.push({ - price: req.price, - amount: req.amount, - orderType: req.orderType, - side: req.side, - market: req.market, - }); - if ('cancelOrderParams' in req) - spotOrdersToCancel = spotOrdersToCancel.concat( - req.cancelOrderParams as ClobDeleteOrderRequestExtract[] - ); - if ('orderId' in req) - spotOrdersToCancel.push({ orderId: req.orderId, market: req.market }); - - const msg = MsgBatchUpdateOrders.fromJSON({ - subaccountId: req.address, - injectiveAddress, - spotOrdersToCreate: this.buildPostOrder( - spotOrdersToCreate, - injectiveAddress - ), - spotOrdersToCancel: this.buildDeleteOrder( - spotOrdersToCancel, - req.address - ), - }); - - const { txHash } = await this._chain.broadcaster(privateKey).broadcast({ - msgs: msg, - injectiveAddress, - }); - return { txHash }; - } - - public buildPostOrder( - orderParams: CreateOrderParam[], - injectiveAddress: string - ): { - orderType: GrpcOrderType; - price: string; - quantity: string; - marketId: any; - feeRecipient: string; - }[] { - const spotOrdersToCreate = []; - for (const order of orderParams) { - const market = this.parsedMarkets[order.market]; - let orderType: GrpcOrderType = order.side === 'BUY' ? 1 : 2; - orderType = - order.orderType === 'LIMIT_MAKER' - ? ((orderType + 6) as GrpcOrderType) // i.e. BUY_LIMIT, SELL_LIMIE are 7, 8 respectively - : orderType; - spotOrdersToCreate.push({ - orderType, - price: spotPriceToChainPriceToFixed({ - value: order.price, - baseDecimals: market.baseToken?.decimals, - quoteDecimals: market.quoteToken?.decimals, - }), - quantity: spotQuantityToChainQuantityToFixed({ - value: order.amount, - baseDecimals: market.baseToken?.decimals, - }), - marketId: market.marketId, - feeRecipient: injectiveAddress, - }); - } - return spotOrdersToCreate; - } - - public buildDeleteOrder( - orders: ClobDeleteOrderRequestExtract[], - injectiveAddress: string - ): { marketId: any; subaccountId: string; orderHash: string }[] { - const spotOrdersToCancel = []; - for (const order of orders) { - spotOrdersToCancel.push({ - marketId: this.parsedMarkets[order.market].marketId, - subaccountId: injectiveAddress, - orderHash: order.orderId, - }); - } - return spotOrdersToCancel; - } - - public estimateGas(_req: NetworkSelectionRequest): { - gasPrice: number; - gasPriceToken: string; - gasLimit: number; - gasCost: number; - } { - return { - gasPrice: this._chain.gasPrice, - gasPriceToken: this._chain.nativeTokenSymbol, - gasLimit: this.conf.gasLimitEstimate, - gasCost: this._chain.gasPrice * this.conf.gasLimitEstimate, - }; - } -} diff --git a/src/connectors/injective_perpetual/injective.perp.ts b/src/connectors/injective_perpetual/injective.perp.ts deleted file mode 100644 index e6ea8b88ed..0000000000 --- a/src/connectors/injective_perpetual/injective.perp.ts +++ /dev/null @@ -1,585 +0,0 @@ -import { - DerivativeOrderHistory, - derivativePriceToChainPriceToFixed, - derivativeQuantityToChainQuantityToFixed, - DerivativeTrade, - FundingPayment, - GrpcOrderType, - IndexerGrpcDerivativesApi, - IndexerGrpcOracleApi, - MsgBatchUpdateOrders, - Orderbook, - PerpetualMarket, - Position, - TradeDirection, -} from '@injectivelabs/sdk-ts'; -import { BigNumber, utils } from 'ethers'; -import LRUCache from 'lru-cache'; -import { OrderSide } from '@injectivelabs/networks/node_modules/@injectivelabs/ts-types/dist/cjs/trade'; -import { Injective } from '../../chains/injective/injective'; -import { getInjectiveConfig } from '../../chains/injective/injective.config'; -import { - FundingInfo, - PerpClobDeleteOrderRequest, - PerpClobFundingInfoRequest, - PerpClobFundingPaymentsRequest, - PerpClobGetOrderRequest, - PerpClobGetTradesRequest, - PerpClobMarketRequest, - PerpClobMarkets, - PerpClobOrderbookRequest, - PerpClobPositionRequest, - PerpClobPostOrderRequest, - PerpClobTickerRequest, - PerpClobGetLastTradePriceRequest, - PerpClobBatchUpdateRequest, - ClobDeleteOrderRequestExtract, - CreatePerpOrderParam, -} from '../../clob/clob.requests'; -import { NetworkSelectionRequest } from '../../services/common-interfaces'; -import { InjectiveCLOBConfig } from '../injective/injective.clob.config'; - -function enumFromStringValue( - enm: { [s: string]: T }, - value: string -): T | undefined { - return (Object.values(enm) as unknown as string[]).includes(value) - ? (value as unknown as T) - : undefined; -} - -export class InjectiveClobPerp { - private static _instances: LRUCache; - private _chain; - public conf; - public derivativeApi: IndexerGrpcDerivativesApi; - public oracleApi: IndexerGrpcOracleApi; - private _ready: boolean = false; - public parsedMarkets: PerpClobMarkets = {}; - - private constructor(_chain: string, network: string) { - this._chain = Injective.getInstance(network); - this.conf = InjectiveCLOBConfig.config; - this.derivativeApi = new IndexerGrpcDerivativesApi( - this._chain.endpoints.indexer - ); - this.oracleApi = new IndexerGrpcOracleApi(this._chain.endpoints.indexer); - } - - public static getInstance(chain: string, network: string): InjectiveClobPerp { - if (InjectiveClobPerp._instances === undefined) { - const config = getInjectiveConfig(network); - InjectiveClobPerp._instances = new LRUCache({ - max: config.network.maxLRUCacheInstances, - }); - } - const instanceKey = chain + network; - if (!InjectiveClobPerp._instances.has(instanceKey)) { - InjectiveClobPerp._instances.set( - instanceKey, - new InjectiveClobPerp(chain, network) - ); - } - - return InjectiveClobPerp._instances.get(instanceKey) as InjectiveClobPerp; - } - - public async loadMarkets() { - const derivativeMarkets = await this.derivativeApi.fetchMarkets(); - for (const market of derivativeMarkets) { - const key = market.ticker.replace('/', '-').replace(' PERP', ''); - this.parsedMarkets[key] = market; - } - } - - public async init() { - if (!this._chain.ready() || Object.keys(this.parsedMarkets).length === 0) { - await this._chain.init(); - await this.loadMarkets(); - this._ready = true; - } - } - - public ready(): boolean { - return this._ready; - } - - public async markets( - req: PerpClobMarketRequest - ): Promise<{ markets: PerpClobMarkets }> { - if (req.market && req.market.split('-').length === 2) { - const resp: PerpClobMarkets = {}; - - resp[req.market] = this.parsedMarkets[req.market]; - return { markets: resp }; - } - return { markets: this.parsedMarkets }; - } - - public async orderBook(req: PerpClobOrderbookRequest): Promise { - return await this.derivativeApi.fetchOrderbookV2( - this.parsedMarkets[req.market].marketId - ); - } - - public async ticker( - req: PerpClobTickerRequest - ): Promise<{ markets: PerpClobMarkets }> { - return await this.markets(req); - } - - public async lastTradePrice( - req: PerpClobGetLastTradePriceRequest - ): Promise { - const marketInfo = this.parsedMarkets[req.market]; - const marketId = marketInfo.marketId; - const oracleScaleFactor = parseFloat(`1e-${marketInfo.oracleScaleFactor}`); - const pagination = { - skip: 0, - limit: 1, - key: '', - }; - const result = await this.derivativeApi.fetchTrades({ - marketId, - pagination, - }); - - let price = null; - if (result.trades.length > 0) { - price = ( - parseFloat(result.trades[0].executionPrice) * oracleScaleFactor - ).toString(); - } - - return price; - } - - public async trades( - req: PerpClobGetTradesRequest - ): Promise> { - const marketId = this.parsedMarkets[req.market].marketId; - - const firstPage = await this.derivativeApi.fetchTrades({ - marketId, - subaccountId: req.address, - }); - - let targetTrade = undefined; - - let skip = 0; - const pagination = { - skip, - limit: 100, - key: '', - }; - - const trades = firstPage.trades; - if (req.orderId !== undefined) { - for (const trade of trades) { - if (trade.orderHash === req.orderId) { - targetTrade = trade; - break; - } - } - } - - const total = firstPage.pagination.total; - if (total > 100) { - skip = skip + 99; - while (trades.length < total) { - pagination.skip = skip; - const page = await this.derivativeApi.fetchTrades({ - marketId, - subaccountId: req.address, - }); - - skip = skip + 100; - trades.concat(page.trades); - } - } - - if (req.orderId !== undefined) { - return targetTrade ? [targetTrade] : []; - } else { - return trades; - } - } - - public async orders( - req: PerpClobGetOrderRequest - ): Promise> { - const marketId = this.parsedMarkets[req.market].marketId; - const orderTypes = []; - if (req.orderTypes) { - for (const orderTypeString of req.orderTypes.split(',')) { - const orderType = enumFromStringValue(OrderSide, orderTypeString); - if (orderType !== undefined) { - orderTypes.push(orderType); - } - } - } - let direction = undefined; - if (req.direction) { - direction = enumFromStringValue(TradeDirection, req.direction); - } - - let targetOrder = undefined; - - let skip = 0; - let limit = 100; - if (req.limit) { - limit = req.limit; - } - const pagination = { - skip, - limit, - key: '', - }; - - const firstPage = await this.derivativeApi.fetchOrderHistory({ - subaccountId: req.address, - marketId, - direction, - orderTypes, - pagination, - }); - - const orders = firstPage.orderHistory; - if (req.orderId !== undefined) { - for (const order of orders) { - if (order.orderHash === req.orderId) { - targetOrder = order; - break; - } - } - } - - const total = firstPage.pagination.total; - if (total > 100 && limit >= 100) { - skip = skip + 99; - while (orders.length < total) { - pagination.skip = skip; - const page = await this.derivativeApi.fetchOrderHistory({ - subaccountId: req.address, - marketId, - direction, - orderTypes, - pagination, - }); - if (req.orderId !== undefined) { - for (const order of page.orderHistory) { - if (order.orderHash === req.orderId) { - targetOrder = order; - break; - } - } - } - - skip = skip + 100; - orders.concat(page.orderHistory); - } - } - - if (req.orderId !== undefined) { - return targetOrder ? [targetOrder] : []; - } else { - return orders; - } - } - - public static calculateMargin( - price: string, - quantity: string, - decimals: number, - leverage: number - ): BigNumber { - // margin = (price * quantity) / leverage - const priceBig = utils.parseUnits(price, decimals); - const quantityBig = utils.parseUnits(quantity, decimals); - const leverageBig = utils.parseUnits(leverage.toString(), decimals); - const decimalsBig = BigNumber.from(10).pow(decimals); - - const numerator = priceBig.mul(quantityBig).mul(decimalsBig); - const denominator = leverageBig.mul(decimalsBig); - - return numerator.div(denominator); - } - - public async postOrder( - req: PerpClobPostOrderRequest - ): Promise<{ txHash: string }> { - return await this.orderUpdate(req); - } - - public async deleteOrder( - req: PerpClobDeleteOrderRequest - ): Promise<{ txHash: string }> { - return this.orderUpdate(req); - } - - public async batchPerpOrders( - req: PerpClobBatchUpdateRequest - ): Promise<{ txHash: string }> { - return this.orderUpdate(req); - } - - public estimateGas(_req: NetworkSelectionRequest): { - gasPrice: number; - gasPriceToken: string; - gasLimit: number; - gasCost: number; - } { - return { - gasPrice: this._chain.gasPrice, - gasPriceToken: this._chain.nativeTokenSymbol, - gasLimit: this.conf.gasLimitEstimate, - gasCost: this._chain.gasPrice * this.conf.gasLimitEstimate, - }; - } - - private _getNextHourUnixTimestamp(): number { - // Returns the next hour unix timestamp in seconds. - const now = Date.now() * 1e-3; - return (now - (now % 3600) + 3600) * 1e3; - } - - public async fundingInfo( - req: PerpClobFundingInfoRequest - ): Promise { - // Ensures that the latest Derivative Market Info is loaded. - await this.loadMarkets(); - - const marketInfo = this.parsedMarkets[req.market]; - const marketId = marketInfo.marketId; - const [baseSymbol, quoteSymbol] = req.market.split('-'); - const oracleType = marketInfo.oracleType; - const oracleScaleFactor = parseFloat(`1e-${marketInfo.oracleScaleFactor}`); - const nextFundingTimestamp = - marketInfo.perpetualMarketInfo?.nextFundingTimestamp || - this._getNextHourUnixTimestamp(); - - const fundingRateResp = await this.derivativeApi.fetchFundingRates({ - marketId, - }); - const tradesResp = await this.derivativeApi.fetchTrades({ - marketId, - }); - const oraclePriceResp = await this.oracleApi.fetchOraclePrice({ - baseSymbol, - quoteSymbol, - oracleType, - }); - - const indexPrice = ( - parseFloat(tradesResp.trades[0].executionPrice) * oracleScaleFactor - ).toString(); - const fundingRate: string = fundingRateResp.fundingRates[0].rate; - const markPrice = oraclePriceResp.price; - - return { - marketId, - indexPrice, - markPrice, - fundingRate, - nextFundingTimestamp: nextFundingTimestamp * 1e3, - }; - } - - public async fundingPayments( - req: PerpClobFundingPaymentsRequest - ): Promise> { - let skip = 0; - const marketId = this.parsedMarkets[req.market].marketId; - const pagination = { - skip, - limit: 100, - key: '', - }; - - const firstPage = await this.derivativeApi.fetchFundingPayments({ - marketId, - subaccountId: req.address, - pagination, - }); - - const fundingPayments = firstPage.fundingPayments; - - const total = firstPage.pagination.total; - if (total > 100) { - skip = skip + 99; - while (fundingPayments.length < total) { - pagination.skip = skip; - const page = await this.derivativeApi.fetchFundingPayments({ - marketId, - subaccountId: req.address, - pagination, - }); - skip = skip + 100; - fundingPayments.concat(page.fundingPayments); - } - } - - return fundingPayments; - } - - public async positions( - req: PerpClobPositionRequest - ): Promise> { - const marketIds = []; - for (const market of req.markets) { - marketIds.push(this.parsedMarkets[market].marketId); - } - - let skip = 0; - const pagination = { - skip, - limit: 100, - key: '', - }; - - const firstPage = await this.derivativeApi.fetchPositions({ - marketIds, - subaccountId: req.address, - pagination, - }); - - const positions = firstPage.positions; - - const total = firstPage.pagination.total; - if (total > 100) { - skip = skip + 99; - while (positions.length < total) { - pagination.skip = skip; - const page = await this.derivativeApi.fetchPositions({ - marketIds, - subaccountId: req.address, - pagination, - }); - skip = skip + 100; - positions.concat(page.positions); - } - } - - return positions; - } - - public buildPostOrder( - orderParams: CreatePerpOrderParam[], - injectiveAddress: string - ): { - orderType: GrpcOrderType; - price: string; - quantity: string; - marketId: any; - feeRecipient: string; - margin: string; - }[] { - const derivativeOrdersToCreate = []; - for (const order of orderParams) { - const market = this.parsedMarkets[order.market]; - const [base, quote] = order.market.split('-'); - let orderType: GrpcOrderType = order.side === 'BUY' ? 1 : 2; - orderType = - order.orderType === 'LIMIT_MAKER' - ? ((orderType + 6) as GrpcOrderType) // i.e. BUY_LIMIT, SELL_LIMIT are 7, 8 respectively - : orderType; - - const price = derivativePriceToChainPriceToFixed({ - value: order.price, - quoteDecimals: this._chain.getTokenForSymbol(quote)?.decimals, - }); - const quantity = derivativeQuantityToChainQuantityToFixed({ - value: order.amount, - }); - const baseToken = this._chain.getTokenForSymbol(base); - const decimalForMargin = baseToken ? baseToken.decimals : 18; - - derivativeOrdersToCreate.push({ - orderType, - price, - quantity, - marketId: market.marketId, - feeRecipient: injectiveAddress, - margin: utils.formatUnits( - InjectiveClobPerp.calculateMargin( - price, - quantity, - decimalForMargin, - order.leverage - ), - decimalForMargin - ), - }); - } - return derivativeOrdersToCreate; - } - - public buildDeleteOrder( - orders: ClobDeleteOrderRequestExtract[], - injectiveAddress: string - ): { marketId: any; subaccountId: string; orderHash: string }[] { - const derivativeOrdersToCancel = []; - for (const order of orders) { - derivativeOrdersToCancel.push({ - marketId: this.parsedMarkets[order.market].marketId, - subaccountId: injectiveAddress, - orderHash: order.orderId, - }); - } - return derivativeOrdersToCancel; - } - - public async orderUpdate( - req: - | PerpClobDeleteOrderRequest - | PerpClobPostOrderRequest - | PerpClobBatchUpdateRequest - ): Promise<{ txHash: string }> { - const wallet = await this._chain.getWallet(req.address); - const privateKey: string = wallet.privateKey; - const injectiveAddress: string = wallet.injectiveAddress; - let derivativeOrdersToCreate: CreatePerpOrderParam[] = []; - let derivativeOrdersToCancel: ClobDeleteOrderRequestExtract[] = []; - if ('createOrderParams' in req) - derivativeOrdersToCreate = derivativeOrdersToCreate.concat( - req.createOrderParams as CreatePerpOrderParam[] - ); - if ('price' in req) - derivativeOrdersToCreate.push({ - price: req.price, - amount: req.amount, - orderType: req.orderType, - side: req.side, - market: req.market, - leverage: req.leverage, - }); - if ('cancelOrderParams' in req) - derivativeOrdersToCancel = derivativeOrdersToCancel.concat( - req.cancelOrderParams as ClobDeleteOrderRequestExtract[] - ); - if ('orderId' in req) - derivativeOrdersToCancel.push({ - orderId: req.orderId, - market: req.market, - }); - - const msg = MsgBatchUpdateOrders.fromJSON({ - subaccountId: req.address, - injectiveAddress, - derivativeOrdersToCreate: this.buildPostOrder( - derivativeOrdersToCreate, - injectiveAddress - ), - derivativeOrdersToCancel: this.buildDeleteOrder( - derivativeOrdersToCancel, - req.address - ), - }); - - const { txHash } = await this._chain.broadcaster(privateKey).broadcast({ - msgs: msg, - injectiveAddress, - }); - return { txHash }; - } -} diff --git a/src/network/network.controllers.ts b/src/network/network.controllers.ts index 8fe6926c44..d1ca7b234d 100644 --- a/src/network/network.controllers.ts +++ b/src/network/network.controllers.ts @@ -4,7 +4,6 @@ import { BinanceSmartChain } from '../chains/binance-smart-chain/binance-smart-c import { Ethereum } from '../chains/ethereum/ethereum'; import { Harmony } from '../chains/harmony/harmony'; import { Polygon } from '../chains/polygon/polygon'; -import { Injective } from '../chains/injective/injective'; import { Xdc } from '../chains/xdc/xdc'; import { Tezos } from '../chains/tezos/tezos'; import { Kujira } from '../chains/kujira/kujira'; @@ -94,11 +93,6 @@ export async function getStatus( bscConnections ? Object.values(bscConnections) : [] ); - const injectiveConnections = Injective.getConnectedInstances(); - connections = connections.concat( - injectiveConnections ? Object.values(injectiveConnections) : [] - ); - const tezosConnections = Tezos.getConnectedInstances(); connections = connections.concat( tezosConnections ? Object.values(tezosConnections) : [] diff --git a/src/services/common-interfaces.ts b/src/services/common-interfaces.ts index 96f7efaef4..96e469bc10 100644 --- a/src/services/common-interfaces.ts +++ b/src/services/common-interfaces.ts @@ -774,3 +774,12 @@ export interface CustomTransactionResponse gasLimit: string; value: string; } + +export interface TransferRequest extends NetworkSelectionRequest { + to: string; + from: string; + amount: string; + token: string; +} + +export type TransferResponse = string; diff --git a/src/services/connection-manager.ts b/src/services/connection-manager.ts index 0228de6e17..18f6d87c31 100644 --- a/src/services/connection-manager.ts +++ b/src/services/connection-manager.ts @@ -15,9 +15,6 @@ import { PancakeSwap } from '../connectors/pancakeswap/pancakeswap'; import { Uniswap } from '../connectors/uniswap/uniswap'; import { UniswapLP } from '../connectors/uniswap/uniswap.lp'; import { VVSConnector } from '../connectors/vvs/vvs'; -import { InjectiveCLOB } from '../connectors/injective/injective'; -import { InjectiveClobPerp } from '../connectors/injective_perpetual/injective.perp'; -import { Injective } from '../chains/injective/injective'; import { CLOBish, Ethereumish, @@ -48,7 +45,6 @@ export type ChainUnion = | Cosmos | Ethereumish | Nearish - | Injective | Xdcish | Tezosish | Kujira; @@ -63,8 +59,6 @@ export type Chain = T extends Algorand ? Nearish : T extends Xdcish ? Xdcish - : T extends Injective - ? Injective : T extends Tezosish ? Tezosish : T extends KujiraCLOB @@ -126,8 +120,6 @@ export async function getChainInstance( connection = BinanceSmartChain.getInstance(network); } else if (chain === 'xdc') { connection = Xdc.getInstance(network); - } else if (chain === 'injective') { - connection = Injective.getInstance(network); } else if (chain === 'tezos') { connection = Tezos.getInstance(network); } else if (chain === 'kujira') { @@ -145,7 +137,6 @@ export type ConnectorUnion = | Perpish | RefAMMish | CLOBish - | InjectiveClobPerp | Tinyman | Plenty | Curve @@ -161,8 +152,6 @@ export type Connector = T extends Uniswapish ? RefAMMish : T extends CLOBish ? CLOBish - : T extends InjectiveClobPerp - ? InjectiveClobPerp : T extends Tinyman ? Tinyman : T extends Plenty @@ -209,12 +198,8 @@ export async function getConnector( connectorInstance = PancakeSwap.getInstance(chain, network); } else if (connector === 'sushiswap') { connectorInstance = Sushiswap.getInstance(chain, network); - } else if (chain === 'injective' && connector === 'injective_perpetual') { - connectorInstance = InjectiveClobPerp.getInstance(chain, network); } else if (chain === 'xdc' && connector === 'xsswap') { connectorInstance = Xsswap.getInstance(chain, network); - } else if (chain === 'injective' && connector === 'injective') { - connectorInstance = InjectiveCLOB.getInstance(chain, network); } else if (chain === 'avalanche' && connector === 'dexalot') { connectorInstance = DexalotCLOB.getInstance(network); } else if (chain == 'algorand' && connector == 'tinyman') { diff --git a/src/services/wallet/wallet.controllers.ts b/src/services/wallet/wallet.controllers.ts index 3974a504f0..1877f24503 100644 --- a/src/services/wallet/wallet.controllers.ts +++ b/src/services/wallet/wallet.controllers.ts @@ -1,7 +1,6 @@ import fse from 'fs-extra'; import { Xdc } from '../../chains/xdc/xdc'; import { Cosmos } from '../../chains/cosmos/cosmos'; -import { Injective } from '../../chains/injective/injective'; import { Tezos } from '../../chains/tezos/tezos'; import { Kujira } from '../../chains/kujira/kujira'; @@ -120,21 +119,6 @@ export async function addWallet( ) ).accountId; encryptedPrivateKey = connection.encrypt(req.privateKey, passphrase); - } else if (connection instanceof Injective) { - const ethereumAddress = connection.getWalletFromPrivateKey( - req.privateKey - ).address; - const subaccountId = req.accountId; - if (subaccountId !== undefined) { - address = ethereumAddress + subaccountId.toString(16).padStart(24, '0'); - - encryptedPrivateKey = await connection.encrypt( - req.privateKey, - passphrase - ); - } else { - throw new Error('Injective wallet requires a subaccount id'); - } } else if (connection instanceof Tezos) { const tezosWallet = await connection.getWalletFromPrivateKey( req.privateKey diff --git a/src/services/wallet/wallet.validators.ts b/src/services/wallet/wallet.validators.ts index 4ae01ff548..489d71a940 100644 --- a/src/services/wallet/wallet.validators.ts +++ b/src/services/wallet/wallet.validators.ts @@ -114,11 +114,6 @@ export const validatePrivateKey: Validator = mkSelectingValidator( invalidEthPrivateKeyError, (val) => typeof val === 'string' && isEthPrivateKey(val) ), - injective: mkValidator( - 'privateKey', - invalidEthPrivateKeyError, - (val) => typeof val === 'string' && isEthPrivateKey(val) - ), xdc: mkValidator( 'privateKey', invalidEthPrivateKeyError, @@ -138,7 +133,7 @@ export const validatePrivateKey: Validator = mkSelectingValidator( ); export const invalidChainError: string = - 'chain must be "ethereum", "avalanche", "near", "harmony", "cosmos", "binance-smart-chain", "injective", or "kujira"'; + 'chain must be "ethereum", "avalanche", "near", "harmony", "cosmos", "binance-smart-chain", "kujira"'; export const invalidNetworkError: string = 'expected a string for the network key'; @@ -165,7 +160,6 @@ export const validateChain: Validator = mkValidator( val === 'cronos' || val === 'cosmos' || val === 'binance-smart-chain' || - val === 'injective' || val === 'tezos' || val === 'kujira') ); diff --git a/src/templates/injective.yml b/src/templates/injective.yml deleted file mode 100644 index 52647eaa37..0000000000 --- a/src/templates/injective.yml +++ /dev/null @@ -1,14 +0,0 @@ -networks: - mainnet: - chainId: mainnet - nodeURL: https://tm.injective.network - testnet: - chainId: testnet - nodeURL: https://k8s.testnet.tm.injective.network - devnet: - chainId: devnet - nodeURL: https://devnet.tm.injective.dev - -nativeCurrencySymbol: INJ -gasLimitEstimate: 500000 - diff --git a/src/templates/root.yml b/src/templates/root.yml index 5654cf1c85..2dc4d913c5 100644 --- a/src/templates/root.yml +++ b/src/templates/root.yml @@ -92,10 +92,6 @@ configurations: configurationPath: pancakeswap.yml schemaPath: pangolin-schema.json - $namespace injective: - configurationPath: injective.yml - schemaPath: injective-schema.json - $namespace xdc: configurationPath: xdc.yml schemaPath: ethereum-schema.json diff --git a/test-bronze/chains/injective/injective.message.test.ts b/test-bronze/chains/injective/injective.message.test.ts deleted file mode 100644 index 32849ce1b3..0000000000 --- a/test-bronze/chains/injective/injective.message.test.ts +++ /dev/null @@ -1,222 +0,0 @@ -import { MsgBroadcasterLocal } from '../../../src/chains/injective/injective.message'; -import { Network } from '@injectivelabs/networks'; -import { patch, unpatch } from '../../../test/services/patch'; -import { - MsgBid, - PrivateKey, - TxClientBroadcastOptions, - TxRaw, -} from '@injectivelabs/sdk-ts'; -import { Injective } from '../../../src/chains/injective/injective'; -import { patchEVMNonceManager } from '../../../test/evm.nonce.mock'; -import { AccountDetails } from '@injectivelabs/sdk-ts/dist/cjs/types/auth'; - -const TX_HASH = - 'CC6BF44223B4BD05396F83D55A0ABC0F16CE80836C0E34B08F4558CF72944299'; // noqa: mock -const PRIVATE_KEY = 'somePrivateKey'; -const TRANSACTION_RESPONSES_QUEUE: { data: any }[] = []; -let injChain: Injective; -let msgBroadcastLocal: MsgBroadcasterLocal; - -beforeAll(async () => { - injChain = Injective.getInstance('mainnet'); - patchEVMNonceManager(injChain.nonceManager); - patchCurrentBlockNumber(); - await injChain.init(); - patchPrivateKey(); - msgBroadcastLocal = injChain.broadcaster(PRIVATE_KEY); -}); - -beforeEach(() => { - patchEVMNonceManager(injChain.nonceManager); - patchCurrentBlockNumber(); -}); - -afterEach(() => { - unpatch(); -}); - -afterAll(async () => { - await injChain.close(); -}); - -const patchCurrentBlockNumber = (withError: boolean = false) => { - patch(injChain.chainRestTendermintApi, 'fetchLatestBlock', () => { - return withError ? {} : { header: { height: 100 } }; - }); -}; - -const patchPrivateKey = (publicKey: string | undefined = undefined) => { - const privateKeyMock = { - toPublicKey() { - return { - toBase64(): string { - return publicKey ? publicKey : 'somePublicKey'; - }, - }; - }, - async sign(messageBytes: Buffer): Promise { - return messageBytes; - }, - }; - patch(PrivateKey, 'fromHex', (_: string) => { - return privateKeyMock; - }); -}; - -const patchGetOnChainAccount = () => { - patch( - injChain, - 'getOnChainAccount', - async (injectiveAddress: string): Promise => { - return (async () => { - return { - address: injectiveAddress, - pubKey: { type: 'someType', key: 'someKey' }, - accountNumber: 0, - sequence: 0, - }; - })(); - } - ); -}; - -const patchBroadcastUsingInjective = () => { - patch( - msgBroadcastLocal, - 'broadcastUsingInjective', - async (_: TxRaw, __?: TxClientBroadcastOptions): Promise<{ data: any }> => { - return TRANSACTION_RESPONSES_QUEUE.shift() as { data: any }; - } - ); -}; - -const queueTransactionResponse = (txResponse: { data: any }) => { - TRANSACTION_RESPONSES_QUEUE.push(txResponse); -}; - -// const patchHttpClient = () => { -// patch(HttpClient, '') -// } - -describe('Test that the getInstance function', () => { - it('creates a single new instance of the broadcaster per network and private key', () => { - const firstPrivateKey = 'somePrivateKey'; - const firstInstance = MsgBroadcasterLocal.getInstance({ - network: Network.Mainnet, - privateKey: firstPrivateKey, - }); - - expect(firstInstance).toBeDefined(); - - const secondInstance = MsgBroadcasterLocal.getInstance({ - network: Network.Mainnet, - privateKey: firstPrivateKey, - }); - - expect(firstInstance === secondInstance).toBeTruthy(); // same reference - - const thirdInstance = MsgBroadcasterLocal.getInstance({ - network: Network.Mainnet, - privateKey: 'anotherPrivateKey', - }); - - expect(firstInstance === thirdInstance).toBeFalsy(); - }); -}); - -describe('That the broadcast function', () => { - it('broadcasts a transaction successfully', async () => { - patchGetOnChainAccount(); - patchBroadcastUsingInjective(); - queueTransactionResponse({ - data: { tx_response: { code: 0, txhash: TX_HASH } }, - }); - - const instance = MsgBroadcasterLocal.getInstance({ - network: Network.Mainnet, - privateKey: PRIVATE_KEY, - }); - const { txHash } = await instance.broadcast({ - msgs: MsgBid.fromJSON({ - round: 10, - injectiveAddress: 'someAddress', - amount: { - amount: '1', - denom: 'someDenom', - }, - }), - injectiveAddress: 'someAddress', - }); - - expect(txHash).toEqual(TX_HASH); - expect(TRANSACTION_RESPONSES_QUEUE.length === 0).toBeTruthy(); - }); - - it('retries broadcasting after failure due to sequence mismatch', async () => { - patchGetOnChainAccount(); - patchBroadcastUsingInjective(); - queueTransactionResponse({ - data: { - tx_response: { - code: 32, - raw_log: 'account sequence mismatch, expected 2, got x', - }, - }, - }); - queueTransactionResponse({ - data: { tx_response: { code: 0, txhash: TX_HASH } }, - }); - const instance = MsgBroadcasterLocal.getInstance({ - network: Network.Mainnet, - privateKey: PRIVATE_KEY, - }); - const { txHash } = await instance.broadcast({ - msgs: MsgBid.fromJSON({ - round: 10, - injectiveAddress: 'someAddress', - amount: { - amount: '1', - denom: 'someDenom', - }, - }), - injectiveAddress: 'someAddress', - }); - - expect(txHash).toEqual(TX_HASH); - expect(TRANSACTION_RESPONSES_QUEUE.length === 0).toBeTruthy(); - }); - - it('broadcaster throws error when issues unrelated to sequence arise', async () => { - patchGetOnChainAccount(); - patchBroadcastUsingInjective(); - queueTransactionResponse({ - data: { - tx_response: { - code: 5, - raw_log: - '10148642834638inj is smaller than 200000000000000inj: insufficient funds: insufficient funds', - }, - }, - }); - const instance = MsgBroadcasterLocal.getInstance({ - network: Network.Mainnet, - privateKey: PRIVATE_KEY, - }); - await expect(async () => { - await instance.broadcast({ - msgs: MsgBid.fromJSON({ - round: 10, - injectiveAddress: 'someAddress', - amount: { - amount: '1', - denom: 'someDenom', - }, - }), - injectiveAddress: 'someAddress', - }); - }).rejects.toThrow( - '10148642834638inj is smaller than 200000000000000inj: insufficient funds: insufficient funds' - ); - }); -}); diff --git a/test-bronze/chains/injective/injective.routes.test.ts b/test-bronze/chains/injective/injective.routes.test.ts deleted file mode 100644 index 1c7258c7ac..0000000000 --- a/test-bronze/chains/injective/injective.routes.test.ts +++ /dev/null @@ -1,304 +0,0 @@ -import request from 'supertest'; -import { Injective } from '../../../src/chains/injective/injective'; -import { patch, unpatch } from '../../../test/services/patch'; -import { gatewayApp } from '../../../src/app'; -import { patchEVMNonceManager } from '../../../test/evm.nonce.mock'; - -const TX_HASH = - 'CC6BF44223B4BD05396F83D55A0ABC0F16CE80836C0E34B08F4558CF72944299'; // noqa: mock -let injChain: Injective; - -beforeAll(async () => { - injChain = Injective.getInstance('mainnet'); - patchEVMNonceManager(injChain.nonceManager); - patchCurrentBlockNumber(); - await injChain.init(); -}); - -beforeEach(() => { - patchEVMNonceManager(injChain.nonceManager); - patchCurrentBlockNumber(); -}); - -afterEach(() => { - unpatch(); -}); - -afterAll(async () => { - await injChain.close(); -}); - -const patchGetNonce = () => { - patch(injChain.nonceManager, 'getNonce', () => 2); -}; - -const patchCommitNonce = () => { - patch(injChain.nonceManager, 'commitNonce', () => 3); -}; - -const patchMsgBroadcaster = () => { - patch(injChain, 'broadcaster', () => { - return { - broadcast() { - return { - txHash: TX_HASH, - }; - }, - }; - }); -}; - -const patchGetWallet = () => { - patch(injChain, 'getWallet', () => { - return { - privateKey: - '82683695dee0dc43536d4adf397b0dbff33e3f56adf036860e2002e57d6d5a3f', // noqa: mock - injectiveAddress: 'inj1ycfk9k7pmqmst2craxteyd2k3xj93xuw2x0vgp', - ethereumAddress: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5', - }; - }); -}; - -const patchCurrentBlockNumber = (withError: boolean = false) => { - patch(injChain.chainRestTendermintApi, 'fetchLatestBlock', () => { - return withError ? {} : { header: { height: 100 } }; - }); -}; - -const patchBalances = () => { - patch(injChain.chainRestBankApi, 'fetchBalances', () => { - return { balances: [{ denom: 'INJ', amount: '1' }] }; - }); -}; - -const patchGetTokenByDenom = () => { - patch(injChain, 'getTokenByDenom', (symbol: string) => { - let result; - switch (symbol) { - case 'INJ': - result = { - address: '0xd0A1E359811322d97991E03f863a0C30C2cFFFFF', - chainId: 1, - name: 'INJ', - decimals: 1, - symbol: 'INJ', - denom: 'INJ', - }; - break; - case 'DAI': - result = { - chainId: 1, - name: 'DAI', - symbol: 'DAI', - address: '0xd0A1E359811322d97991E03f863a0C30C2cFFFFF', - decimals: 18, - }; - break; - } - return result; - }); -}; - -const patchFetchTransaction = () => { - const default_tx = { - id: '', - blockNumber: 4747419, - blockTimestamp: '2022-05-03 15:38:17.443 +0000 UTC', - hash: '0xd7a1c7ee985f807bf6bc06de728810fd52d85141549af0540486faf5e7de0d1d', // noqa: mock - code: 0, - data: 'CiMKIS9pbmplY3RpdmUuYXVjdGlvbi52MWJldGExLk1zZ0JpZA==', - info: '', - gasWanted: 400000, - gasUsed: 99411, - gasFee: { - amountList: [ - { - denom: 'inj', - amount: '200000000000000', - }, - ], - gasLimit: 400000, - payer: 'inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r', - granter: '', - }, - codespace: '', - eventsList: [], - txType: 'injective', - messages: - '[{"type":"/injective.auction.v1beta1.MsgBid","value":{"bid_amount":{"amount":"1000000000000000000","denom":"inj"},"round":"15130","sender":"inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"}}]', - signatures: [ - { - pubkey: 'injvalcons1hkhdaj2a2clmq5jq6mspsggqs32vynpkflpeux', - address: 'inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r', - sequence: 1120, - signature: - 'jUkld9DBYu8DgwWr+OCMfbcIww5wtxrY4jrpXGL7GHY1nE415fKRZhWhfVV8P4Wx5OQWnZjYnfUSIKQq0m3QgQ==', - }, - ], - memo: '', - }; - patch(injChain, 'poll', () => { - return default_tx; - }); -}; - -describe('GET /injective/block/current', () => { - it('should return 200 with correct params', async () => { - patchCurrentBlockNumber(); - await request(gatewayApp) - .get(`/injective/block/current`) - .query({ - chain: 'injective', - network: 'mainnet', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body).toEqual(100)); - }); - - it('should return 503 when network is not ready', async () => { - patchCurrentBlockNumber(true); - await request(gatewayApp) - .get(`/injective/block/current`) - .query({ - chain: 'injective', - network: 'mainnet', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(503); - }); - - it('should return 503 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/injective/block/current`) - .query({ - chain: 123, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(503); - }); -}); - -describe('POST /injective/transfer/to/bank', () => { - it('should return 200 with proper request params', async () => { - patchGetWallet(); - patchCommitNonce(); - patchGetNonce(); - patchMsgBroadcaster(); - patchCurrentBlockNumber(); - await request(gatewayApp) - .post(`/injective/transfer/to/bank`) - .send({ - chain: 'injective', - network: 'mainnet', - address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5', - subaccountId: '000000000000000000000000', - amount: '100', - token: 'INJ', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body).toEqual(TX_HASH)); - }); - - it('should return 404 when parameters are invalid/incomplete', async () => { - await request(gatewayApp) - .post(`/injective/transfer/to/bank`) - .send({ - chain: 'injective', - network: 'mainnet', - }) - .expect(404); - }); -}); - -describe('POST /injective/transfer/to/sub', () => { - it('should return 200 with correct parameters', async () => { - patchGetWallet(); - patchCommitNonce(); - patchGetNonce(); - patchMsgBroadcaster(); - - await request(gatewayApp) - .post(`/injective/transfer/to/sub`) - .send({ - chain: 'injective', - network: 'mainnet', - address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5', - subaccountId: '000000000000000000000000', - amount: '100', - token: 'INJ', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body).toEqual(TX_HASH)); - }); - - it('should return 404 when parameters are invalid/incomplete', async () => { - await request(gatewayApp) - .post(`/injective/transfer/to/sub`) - .send({ - chain: 'injective', - network: 'mainnet', - }) - .expect(404); - }); -}); - -describe('POST /injective/balances', () => { - it('should return 200 with correct parameters', async () => { - patchGetWallet(); - patchGetTokenByDenom(); - patchBalances(); - patchCurrentBlockNumber(); - - await request(gatewayApp) - .post(`/injective/balances`) - .send({ - chain: 'injective', - network: 'mainnet', - address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200); - //.expect((res) => expect(res.body.nonce).toBe(3)); - }); - - it('should return 404 when parameters are invalid/incomplete', async () => { - await request(gatewayApp) - .post(`/injective/balances`) - .send({ - chain: 'injective', - network: 'mainnet', - }) - .expect(404); - }); -}); - -describe('POST /injective/poll', () => { - it('should return 200 with correct parameters', async () => { - patchFetchTransaction(); - const res = await request(gatewayApp).post('/injective/poll').send({ - chain: 'injective', - network: 'mainnet', - txHash: - '0x2faeb1aa55f96c1db55f643a8cf19b0f76bf091d0b7d1b068d2e829414576362', // noqa: mock - }); - expect(res.statusCode).toEqual(200); - }); - - it('should get unknown error with invalid txHash', async () => { - const res = await request(gatewayApp).post('/injective/poll').send({ - chain: 'injective', - network: 'mainnet', - txHash: 123, - }); - expect(res.statusCode).toEqual(404); - }); -}); diff --git a/test-bronze/chains/injective/injective.validator.test.ts b/test-bronze/chains/injective/injective.validator.test.ts deleted file mode 100644 index e854d359a7..0000000000 --- a/test-bronze/chains/injective/injective.validator.test.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { - validateTxHash, - validateAddress, - validateAmount, - validateToken, - invalidAddressError, - invalidTxHashError, - invalidTokenError, -} from '../../../src/chains/injective/injective.validators'; - -import { - invalidAmountError, - missingParameter, -} from '../../../src/services/validators'; - -import 'jest-extended'; - -describe('validateTxHash', () => { - it('valid when req.txHash is a txHash', () => { - expect( - validateTxHash({ - txHash: - '92EE240C1C31E50AAA7E3C00A6280A4BE52E65B5A8A4C1B4A6FEF9E170B14D0F', // noqa: mock - }) - ).toEqual([]); - }); - - it('return error when req.txHash does not exist', () => { - expect( - validateTxHash({ - hello: 'world', - }) - ).toEqual([missingParameter('txHash')]); - }); - - it('return error when req.txHash is invalid', () => { - expect( - validateTxHash({ - txHash: 123, - }) - ).toEqual([invalidTxHashError]); - }); -}); - -describe('validateAddress', () => { - it('valid when req.address is a address', () => { - expect( - validateAddress({ - address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5', - }) - ).toEqual([]); - }); - - it('return error when req.address does not exist', () => { - expect( - validateAddress({ - hello: 'world', - }) - ).toEqual([missingParameter('address')]); - }); - - it('return error when req.address is invalid', () => { - expect( - validateAddress({ - address: 123, - }) - ).toEqual([invalidAddressError]); - }); -}); - -describe('validateAmount', () => { - it('valid when req.amount is an amount', () => { - expect( - validateAmount({ - amount: '0.2', - }) - ).toEqual([]); - }); - - it('return error when req.amount does not exist', () => { - expect( - validateAmount({ - hello: 'world', - }) - ).toEqual([missingParameter('amount')]); - }); - - it('return error when req.amount is invalid', () => { - expect( - validateAmount({ - amount: 'world', - }) - ).toEqual([invalidAmountError]); - }); -}); - -describe('validateToken', () => { - it('valid when req.token is a token', () => { - expect( - validateToken({ - token: 'INJ', - }) - ).toEqual([]); - }); - - it('return error when req.token does not exist', () => { - expect( - validateToken({ - hello: 'world', - }) - ).toEqual([missingParameter('token')]); - }); - - it('return error when req.token is invalid', () => { - expect( - validateToken({ - token: 123, - }) - ).toEqual([invalidTokenError]); - }); -}); diff --git a/test-bronze/clob/clob.routes.test.ts b/test-bronze/clob/clob.routes.test.ts index ef7999c92e..ab614f3fb6 100644 --- a/test-bronze/clob/clob.routes.test.ts +++ b/test-bronze/clob/clob.routes.test.ts @@ -1,894 +1,894 @@ import request from 'supertest'; import { patch, unpatch } from '../../test/services/patch'; import { gatewayApp } from '../../src/app'; -import { Injective } from '../../src/chains/injective/injective'; -import { InjectiveCLOB } from '../../src/connectors/injective/injective'; -import { InjectiveClobPerp } from '../../src/connectors/injective_perpetual/injective.perp'; - -let inj: Injective; -let injCLOB: InjectiveCLOB; -let injClobPerp: InjectiveClobPerp; - -const TX_HASH = - 'CC6BF44223B4BD05396F83D55A0ABC0F16CE80836C0E34B08F4558CF72944299'; // noqa: mock -const MARKET = 'INJ-USDT'; - -const SPOT_MARKETS = [ - { - marketId: - '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0', // noqa: mock - marketStatus: 'active', - ticker: 'INJ/USDT', - baseDenom: 'inj', - quoteDenom: 'peggy0xdAC17F958D2ee523a2206206994597C13D831ec7', - quoteToken: { - name: 'Tether', - address: '0xdAC17F958D2ee523a2206206994597C13D831ec7', - symbol: 'USDT', - logo: 'https://static.alchemyapi.io/images/assets/825.png', - decimals: 6, - updatedAt: 1669849325905, - coinGeckoId: '', - }, - baseToken: { - name: 'Injective Protocol', - address: '0xe28b3B32B6c345A34Ff64674606124Dd5Aceca30', - symbol: 'INJ', - logo: 'https://static.alchemyapi.io/images/assets/7226.png', - decimals: 18, - updatedAt: 1659191789475, - coinGeckoId: '', - }, - makerFeeRate: '-0.0001', - takerFeeRate: '0.001', - serviceProviderFee: '0.4', - minPriceTickSize: 1e-15, - minQuantityTickSize: 1000000000000000, - }, -]; -const DERIVATIVE_MARKETS = [ - { - oracleBase: 'INJ', - oracleQuote: 'USDT', - oracleType: 'bandibc', - oracleScaleFactor: 6, - initialMarginRatio: '0.195', - maintenanceMarginRatio: '0.095', - isPerpetual: true, - marketId: - '0x9b9980167ecc3645ff1a5517886652d94a0825e54a77d2057cbbe3ebee015963', - marketStatus: 'active', - ticker: 'INJ/USDT PERP', - quoteDenom: 'peggy0xdAC17F958D2ee523a2206206994597C13D831ec7', - quoteToken: { - name: 'Tether', - address: '0xdAC17F958D2ee523a2206206994597C13D831ec7', - symbol: 'USDT', - logo: 'https://static.alchemyapi.io/images/assets/825.png', - decimals: 6, - updatedAt: 1677706712778, - coinGeckoId: '', - }, - makerFeeRate: '-0.0001', - takerFeeRate: '0.001', - serviceProviderFee: '0.4', - minPriceTickSize: 1000, - minQuantityTickSize: 0.001, - perpetualMarketInfo: { - hourlyFundingRateCap: '0.0000625', - hourlyInterestRate: '0.00000416666', - nextFundingTimestamp: 1678186800, - fundingInterval: 3600, - }, - perpetualMarketFunding: { - cumulativeFunding: '1161622.340224922505695088', - cumulativePrice: '3.308427930614979416', - lastTimestamp: 1678185153, - }, - }, -]; - -const FUNDING_RATES = [ - { - marketId: - '0x1c79dac019f73e4060494ab1b4fcba734350656d6fc4d474f6a238c13c6f9ced', - rate: '0.000122', - timestamp: 1654246801786, - }, -]; - -const FUNDING_PAYMENTS = [ - { - marketId: - '0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce', - subaccountId: - '0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000', - amount: '-4895705.795221', - timestamp: 1654246801786, - }, -]; - -const POSITIONS = [ - { - ticker: 'BTC/USDT PERP', - marketId: - '0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce', - subaccountId: - '0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000', - direction: 'short', - quantity: '1.6321', - entryPrice: '40673269578.764267860566718788', - margin: '65479686044.860453741141489314', - liquidationPrice: '76945874187.425265', - markPrice: '40128736026.4094317665', - aggregateReduceOnlyQuantity: '0', - }, -]; - -const ORDER_BOOK = { - sells: [ - ['12', '1'], - ['11', '0.3'], - ], - buys: [ - ['10', '1'], - ['9', '0.3'], - ], -}; - -const TRADES = { - trades: [ - { - executionPrice: '1.0123', - }, - ], - pagination: { to: 0, from: 0, total: 1 }, -}; - -const ORDERS = { - orderHistory: [ - { - orderHash: - '0xf6f81a37796bd06a797484467302e4d6f72832409545e2e01feb86dd8b22e4b2', // noqa: mock - marketId: - '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0', // noqa: mock - active: false, - subaccountId: - '0x261362dbc1d83705ab03e99792355689a4589b8e000000000000000000000000', // noqa: mock - executionType: 'limit', - orderType: 'sell', - price: '0.000000000002', - triggerPrice: '0', - quantity: '2000000000000000000', - filledQuantity: '0', - state: 'canceled', - createdAt: 1669850499821, - updatedAt: 1669853807685, - direction: 'sell', - }, - { - orderHash: - '0x751a0fcfa52562d0cfe842d21673ebcb654a3774739654800388b1037bc267bc', // noqa: mock - marketId: - '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0', // noqa: mock - active: true, - subaccountId: - '0x261362dbc1d83705ab03e99792355689a4589b8e000000000000000000000000', // noqa: mock - executionType: 'limit', - orderType: 'sell', - price: '0.000000000002', - triggerPrice: '0', - quantity: '2000000000000000000', - filledQuantity: '0', - state: 'booked', - createdAt: 1669850223538, - updatedAt: 1669850223538, - direction: 'sell', - }, - ], - pagination: { to: 0, from: 0, total: 2 }, -}; - -const GAS_PRICES = { - gasPrice: '500000000', - gasPriceToken: 'Token', - gasLimit: '1000', - gasCost: '100', -}; - -const INVALID_REQUEST = { - chain: 'unknown', - network: 'mainnet', -}; - -beforeAll(async () => { - inj = Injective.getInstance('mainnet'); - patchCurrentBlockNumber(); - inj.init(); - injCLOB = InjectiveCLOB.getInstance('injective', 'mainnet'); - injClobPerp = InjectiveClobPerp.getInstance('injective', 'mainnet'); - patchMarkets(); - await injCLOB.init(); - await injClobPerp.init(); -}); - -// eslint-disable-next-line @typescript-eslint/no-empty-function -beforeEach(() => { - patchCurrentBlockNumber(); -}); - -afterEach(() => { - unpatch(); -}); - -afterAll(async () => { - await inj.close(); -}); - -const patchCurrentBlockNumber = (withError: boolean = false) => { - patch(inj.chainRestTendermintApi, 'fetchLatestBlock', () => { - return withError ? {} : { header: { height: 100 } }; - }); -}; - -const patchMarkets = () => { - patch(injCLOB.spotApi, 'fetchMarkets', () => { - return SPOT_MARKETS; - }); - patch(injClobPerp.derivativeApi, 'fetchMarkets', () => { - return DERIVATIVE_MARKETS; - }); -}; - -const patchOrderBook = () => { - patch(injCLOB.spotApi, 'fetchOrderbookV2', () => { - return ORDER_BOOK; - }); - patch(injClobPerp.derivativeApi, 'fetchOrderbookV2', () => { - return ORDER_BOOK; - }); -}; - -const patchTrades = () => { - patch(injClobPerp.derivativeApi, 'fetchTrades', () => { - return TRADES; - }); -}; - -const patchFundingRates = () => { - patch(injClobPerp.derivativeApi, 'fetchFundingRates', () => { - return { - fundingRates: FUNDING_RATES, - pagination: { to: 0, from: 0, total: 1 }, - }; - }); -}; - -const patchOraclePrice = () => { - patch(injClobPerp.oracleApi, 'fetchOraclePrice', () => { - return { - price: '1.234', - }; - }); -}; - -const patchFundingPayments = () => { - patch(injClobPerp.derivativeApi, 'fetchFundingPayments', () => { - return { - fundingPayments: FUNDING_PAYMENTS, - pagination: { to: 0, from: 0, total: 1 }, - }; - }); -}; - -const patchPositions = () => { - patch(injClobPerp.derivativeApi, 'fetchPositions', () => { - return { - positions: POSITIONS, - pagination: { to: 0, from: 0, total: 1 }, - }; - }); -}; - -const patchGetWallet = () => { - patch(inj, 'getWallet', () => { - return { - privateKey: - 'b5959390c834283a11ad71f3668fee9784853f1422e921a7015c275c98c95c08', // noqa: mock - injectiveAddress: 'inj1ycfk9k7pmqmst2craxteyd2k3xj93xuw2x0vgp', - }; - }); -}; - -const patchMsgBroadcaster = () => { - patch(inj, 'broadcaster', () => { - return { - broadcast() { - return { - txHash: TX_HASH, - }; - }, - }; - }); -}; - -const patchOrders = () => { - patch(injCLOB.spotApi, 'fetchOrderHistory', () => { - return ORDERS; - }); - patch(injClobPerp.derivativeApi, 'fetchOrderHistory', () => { - return ORDERS; - }); -}; - -const patchGasPrices = () => { - patch(injCLOB, 'estimateGas', () => { - return GAS_PRICES; - }); - patch(injClobPerp, 'estimateGas', () => { - return GAS_PRICES; - }); -}; - -describe('GET /clob/markets', () => { - it('should return 200 with proper request', async () => { - patchMarkets(); - await request(gatewayApp) - .get(`/clob/markets`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.markets).toEqual(injCLOB.parsedMarkets)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/markets`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/orderBook', () => { - it('should return 200 with proper request', async () => { - patchOrderBook(); - await request(gatewayApp) - .get(`/clob/orderBook`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - market: MARKET, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.buys).toEqual(ORDER_BOOK.buys)) - .expect((res) => expect(res.body.sells).toEqual(ORDER_BOOK.sells)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/orderBook`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/ticker', () => { - it('should return 200 with proper request', async () => { - patchMarkets(); - await request(gatewayApp) - .get(`/clob/ticker`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.markets).toEqual(injCLOB.parsedMarkets)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/ticker`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/orders', () => { - it('should return 200 with proper request', async () => { - patchOrders(); - await request(gatewayApp) - .get(`/clob/orders`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - market: MARKET, - orderId: '0x...', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.orders).toEqual(ORDERS.orderHistory)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/orders`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('POST /clob/orders', () => { - it('should return 200 with proper request', async () => { - patchGetWallet(); - patchMsgBroadcaster(); - await request(gatewayApp) - .post(`/clob/orders`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - market: MARKET, - price: '10000.12', - amount: '0.12', - side: 'BUY', - orderType: 'LIMIT', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .post(`/clob/orders`) - .send(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('DELETE /clob/orders', () => { - it('should return 200 with proper request', async () => { - patchGetWallet(); - patchMsgBroadcaster(); - await request(gatewayApp) - .delete(`/clob/orders`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - market: MARKET, - orderId: '0x...', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .delete(`/clob/orders`) - .send(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('POST /clob/batchOrders', () => { - it('should return 200 with proper request to create batch orders', async () => { - patchGetWallet(); - patchMsgBroadcaster(); - await request(gatewayApp) - .post(`/clob/batchOrders`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - createOrderParams: [ - { - price: '2', - amount: '0.10', - side: 'SELL', - orderType: 'LIMIT', - market: MARKET, - }, - { - price: '3', - amount: '0.10', - side: 'SELL', - market: MARKET, - }, - ], - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); - }); - - it('should return 200 with proper request to delete batch orders', async () => { - patchGetWallet(); - patchMsgBroadcaster(); - await request(gatewayApp) - .post(`/clob/batchOrders`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - market: MARKET, - cancelOrderIds: [ - '0x73af517124c3f564d1d70e38ad5200dfc7101d04986c14df410042e00932d4bf', // noqa: mock - '0x8ce222ca5da95aaffd87b3d38a307f25d6e2c09e70a0cb8599bc6c8a0851fda3', // noqa: mock - ], - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .post(`/clob/batchOrders`) - .send(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/estimateGas', () => { - it('should return 200 with proper request', async () => { - patchGasPrices(); - await request(gatewayApp) - .get(`/clob/estimateGas`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.gasPrice).toEqual(GAS_PRICES.gasPrice)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/estimateGas`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -// perp stuff - -describe('POST /clob/perp/positions', () => { - it('should return 200 with proper request', async () => { - patchPositions(); - await request(gatewayApp) - .post(`/clob/perp/positions`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - markets: [MARKET], - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.positions).toEqual(POSITIONS)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .post(`/clob/perp/positions`) - .send(INVALID_REQUEST) - .set('Accept', 'application/json') - .expect(404); - }); -}); - -describe('POST /clob/perp/funding/info', () => { - it('should return 200 with proper request', async () => { - patchMarkets(); - patchFundingRates(); - patchTrades(); - patchOraclePrice(); - await request(gatewayApp) - .post(`/clob/perp/funding/info`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - market: MARKET, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.fundingInfo.markPrice).toEqual('1.234')); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .post(`/clob/perp/funding/info`) - .send(INVALID_REQUEST) - .set('Accept', 'application/json') - .expect(404); - }); -}); - -describe('POST /clob/perp/funding/payments', () => { - it('should return 200 with proper request', async () => { - patchFundingPayments(); - await request(gatewayApp) - .post(`/clob/perp/funding/payments`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - market: MARKET, - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => - expect(res.body.fundingPayments).toEqual(FUNDING_PAYMENTS) - ); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .post(`/clob/perp/funding/payments`) - .send(INVALID_REQUEST) - .set('Accept', 'application/json') - .expect(404); - }); -}); - -describe('GET /clob/perp/markets', () => { - it('should return 200 with proper request', async () => { - patchMarkets(); - await request(gatewayApp) - .get(`/clob/perp/markets`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => - expect(res.body.markets).toEqual(injClobPerp.parsedMarkets) - ); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/perp/markets`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/perp/orderBook', () => { - it('should return 200 with proper request', async () => { - patchOrderBook(); - await request(gatewayApp) - .get(`/clob/perp/orderBook`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - market: MARKET, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.buys).toEqual(ORDER_BOOK.buys)) - .expect((res) => expect(res.body.sells).toEqual(ORDER_BOOK.sells)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/perp/orderBook`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/perp/ticker', () => { - it('should return 200 with proper request', async () => { - patchMarkets(); - await request(gatewayApp) - .get(`/clob/perp/ticker`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => - expect(res.body.markets).toEqual(injClobPerp.parsedMarkets) - ); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/perp/ticker`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/perp/orders', () => { - it('should return 200 with proper request', async () => { - patchOrders(); - await request(gatewayApp) - .get(`/clob/perp/orders`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - market: MARKET, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.orders).toEqual(ORDERS.orderHistory)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/perp/orders`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('POST /clob/perp/orders', () => { - it('should return 200 with proper request', async () => { - patchGetWallet(); - patchMsgBroadcaster(); - await request(gatewayApp) - .post(`/clob/perp/orders`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - market: MARKET, - price: '10000.12', - amount: '0.12', - side: 'BUY', - orderType: 'LIMIT', - leverage: 20.0, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .post(`/clob/perp/orders`) - .send(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('DELETE /clob/perp/orders', () => { - it('should return 200 with proper request', async () => { - patchGetWallet(); - patchMsgBroadcaster(); - await request(gatewayApp) - .delete(`/clob/perp/orders`) - .send({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - address: - '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock - market: MARKET, - orderId: '0x...', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .delete(`/clob/perp/orders`) - .send(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/perp/estimateGas', () => { - it('should return 200 with proper request', async () => { - patchGasPrices(); - await request(gatewayApp) - .get(`/clob/perp/estimateGas`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => expect(res.body.gasPrice).toEqual(GAS_PRICES.gasPrice)); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/perp/estimateGas`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); - -describe('GET /clob/perp/lastTradePrice', () => { - it('should return 200 with proper request', async () => { - patchTrades(); - await request(gatewayApp) - .get(`/clob/perp/lastTradePrice`) - .query({ - chain: 'injective', - network: 'mainnet', - connector: 'injective_perpetual', - market: MARKET, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200) - .expect((res) => - expect(res.body.lastTradePrice).toEqual( - ( - parseFloat(TRADES.trades[0].executionPrice) * parseFloat(`1e-6`) - ).toString() - ) - ); - }); - - it('should return 404 when parameters are invalid', async () => { - await request(gatewayApp) - .get(`/clob/perp/lastTradePrice`) - .query(INVALID_REQUEST) - .expect(404); - }); -}); +// import { Injective } from '../../src/chains/injective/injective'; +// import { InjectiveCLOB } from '../../src/connectors/injective/injective'; +// import { InjectiveClobPerp } from '../../src/connectors/injective_perpetual/injective.perp'; + +// let inj: Injective; +// let injCLOB: InjectiveCLOB; +// let injClobPerp: InjectiveClobPerp; + +// const TX_HASH = +// 'CC6BF44223B4BD05396F83D55A0ABC0F16CE80836C0E34B08F4558CF72944299'; // noqa: mock +// const MARKET = 'INJ-USDT'; + +// const SPOT_MARKETS = [ +// { +// marketId: +// '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0', // noqa: mock +// marketStatus: 'active', +// ticker: 'INJ/USDT', +// baseDenom: 'inj', +// quoteDenom: 'peggy0xdAC17F958D2ee523a2206206994597C13D831ec7', +// quoteToken: { +// name: 'Tether', +// address: '0xdAC17F958D2ee523a2206206994597C13D831ec7', +// symbol: 'USDT', +// logo: 'https://static.alchemyapi.io/images/assets/825.png', +// decimals: 6, +// updatedAt: 1669849325905, +// coinGeckoId: '', +// }, +// baseToken: { +// name: 'Injective Protocol', +// address: '0xe28b3B32B6c345A34Ff64674606124Dd5Aceca30', +// symbol: 'INJ', +// logo: 'https://static.alchemyapi.io/images/assets/7226.png', +// decimals: 18, +// updatedAt: 1659191789475, +// coinGeckoId: '', +// }, +// makerFeeRate: '-0.0001', +// takerFeeRate: '0.001', +// serviceProviderFee: '0.4', +// minPriceTickSize: 1e-15, +// minQuantityTickSize: 1000000000000000, +// }, +// ]; +// const DERIVATIVE_MARKETS = [ +// { +// oracleBase: 'INJ', +// oracleQuote: 'USDT', +// oracleType: 'bandibc', +// oracleScaleFactor: 6, +// initialMarginRatio: '0.195', +// maintenanceMarginRatio: '0.095', +// isPerpetual: true, +// marketId: +// '0x9b9980167ecc3645ff1a5517886652d94a0825e54a77d2057cbbe3ebee015963', +// marketStatus: 'active', +// ticker: 'INJ/USDT PERP', +// quoteDenom: 'peggy0xdAC17F958D2ee523a2206206994597C13D831ec7', +// quoteToken: { +// name: 'Tether', +// address: '0xdAC17F958D2ee523a2206206994597C13D831ec7', +// symbol: 'USDT', +// logo: 'https://static.alchemyapi.io/images/assets/825.png', +// decimals: 6, +// updatedAt: 1677706712778, +// coinGeckoId: '', +// }, +// makerFeeRate: '-0.0001', +// takerFeeRate: '0.001', +// serviceProviderFee: '0.4', +// minPriceTickSize: 1000, +// minQuantityTickSize: 0.001, +// perpetualMarketInfo: { +// hourlyFundingRateCap: '0.0000625', +// hourlyInterestRate: '0.00000416666', +// nextFundingTimestamp: 1678186800, +// fundingInterval: 3600, +// }, +// perpetualMarketFunding: { +// cumulativeFunding: '1161622.340224922505695088', +// cumulativePrice: '3.308427930614979416', +// lastTimestamp: 1678185153, +// }, +// }, +// ]; + +// const FUNDING_RATES = [ +// { +// marketId: +// '0x1c79dac019f73e4060494ab1b4fcba734350656d6fc4d474f6a238c13c6f9ced', +// rate: '0.000122', +// timestamp: 1654246801786, +// }, +// ]; + +// const FUNDING_PAYMENTS = [ +// { +// marketId: +// '0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce', +// subaccountId: +// '0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000', +// amount: '-4895705.795221', +// timestamp: 1654246801786, +// }, +// ]; + +// const POSITIONS = [ +// { +// ticker: 'BTC/USDT PERP', +// marketId: +// '0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce', +// subaccountId: +// '0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000', +// direction: 'short', +// quantity: '1.6321', +// entryPrice: '40673269578.764267860566718788', +// margin: '65479686044.860453741141489314', +// liquidationPrice: '76945874187.425265', +// markPrice: '40128736026.4094317665', +// aggregateReduceOnlyQuantity: '0', +// }, +// ]; + +// const ORDER_BOOK = { +// sells: [ +// ['12', '1'], +// ['11', '0.3'], +// ], +// buys: [ +// ['10', '1'], +// ['9', '0.3'], +// ], +// }; + +// const TRADES = { +// trades: [ +// { +// executionPrice: '1.0123', +// }, +// ], +// pagination: { to: 0, from: 0, total: 1 }, +// }; + +// const ORDERS = { +// orderHistory: [ +// { +// orderHash: +// '0xf6f81a37796bd06a797484467302e4d6f72832409545e2e01feb86dd8b22e4b2', // noqa: mock +// marketId: +// '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0', // noqa: mock +// active: false, +// subaccountId: +// '0x261362dbc1d83705ab03e99792355689a4589b8e000000000000000000000000', // noqa: mock +// executionType: 'limit', +// orderType: 'sell', +// price: '0.000000000002', +// triggerPrice: '0', +// quantity: '2000000000000000000', +// filledQuantity: '0', +// state: 'canceled', +// createdAt: 1669850499821, +// updatedAt: 1669853807685, +// direction: 'sell', +// }, +// { +// orderHash: +// '0x751a0fcfa52562d0cfe842d21673ebcb654a3774739654800388b1037bc267bc', // noqa: mock +// marketId: +// '0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0', // noqa: mock +// active: true, +// subaccountId: +// '0x261362dbc1d83705ab03e99792355689a4589b8e000000000000000000000000', // noqa: mock +// executionType: 'limit', +// orderType: 'sell', +// price: '0.000000000002', +// triggerPrice: '0', +// quantity: '2000000000000000000', +// filledQuantity: '0', +// state: 'booked', +// createdAt: 1669850223538, +// updatedAt: 1669850223538, +// direction: 'sell', +// }, +// ], +// pagination: { to: 0, from: 0, total: 2 }, +// }; + +// const GAS_PRICES = { +// gasPrice: '500000000', +// gasPriceToken: 'Token', +// gasLimit: '1000', +// gasCost: '100', +// }; + +// const INVALID_REQUEST = { +// chain: 'unknown', +// network: 'mainnet', +// }; + +// beforeAll(async () => { +// inj = Injective.getInstance('mainnet'); +// patchCurrentBlockNumber(); +// inj.init(); +// injCLOB = InjectiveCLOB.getInstance('injective', 'mainnet'); +// injClobPerp = InjectiveClobPerp.getInstance('injective', 'mainnet'); +// patchMarkets(); +// await injCLOB.init(); +// await injClobPerp.init(); +// }); + +// // eslint-disable-next-line @typescript-eslint/no-empty-function +// beforeEach(() => { +// patchCurrentBlockNumber(); +// }); + +// afterEach(() => { +// unpatch(); +// }); + +// afterAll(async () => { +// await inj.close(); +// }); + +// const patchCurrentBlockNumber = (withError: boolean = false) => { +// patch(inj.chainRestTendermintApi, 'fetchLatestBlock', () => { +// return withError ? {} : { header: { height: 100 } }; +// }); +// }; + +// const patchMarkets = () => { +// patch(injCLOB.spotApi, 'fetchMarkets', () => { +// return SPOT_MARKETS; +// }); +// patch(injClobPerp.derivativeApi, 'fetchMarkets', () => { +// return DERIVATIVE_MARKETS; +// }); +// }; + +// const patchOrderBook = () => { +// patch(injCLOB.spotApi, 'fetchOrderbookV2', () => { +// return ORDER_BOOK; +// }); +// patch(injClobPerp.derivativeApi, 'fetchOrderbookV2', () => { +// return ORDER_BOOK; +// }); +// }; + +// const patchTrades = () => { +// patch(injClobPerp.derivativeApi, 'fetchTrades', () => { +// return TRADES; +// }); +// }; + +// const patchFundingRates = () => { +// patch(injClobPerp.derivativeApi, 'fetchFundingRates', () => { +// return { +// fundingRates: FUNDING_RATES, +// pagination: { to: 0, from: 0, total: 1 }, +// }; +// }); +// }; + +// const patchOraclePrice = () => { +// patch(injClobPerp.oracleApi, 'fetchOraclePrice', () => { +// return { +// price: '1.234', +// }; +// }); +// }; + +// const patchFundingPayments = () => { +// patch(injClobPerp.derivativeApi, 'fetchFundingPayments', () => { +// return { +// fundingPayments: FUNDING_PAYMENTS, +// pagination: { to: 0, from: 0, total: 1 }, +// }; +// }); +// }; + +// const patchPositions = () => { +// patch(injClobPerp.derivativeApi, 'fetchPositions', () => { +// return { +// positions: POSITIONS, +// pagination: { to: 0, from: 0, total: 1 }, +// }; +// }); +// }; + +// const patchGetWallet = () => { +// patch(inj, 'getWallet', () => { +// return { +// privateKey: +// 'b5959390c834283a11ad71f3668fee9784853f1422e921a7015c275c98c95c08', // noqa: mock +// injectiveAddress: 'inj1ycfk9k7pmqmst2craxteyd2k3xj93xuw2x0vgp', +// }; +// }); +// }; + +// const patchMsgBroadcaster = () => { +// patch(inj, 'broadcaster', () => { +// return { +// broadcast() { +// return { +// txHash: TX_HASH, +// }; +// }, +// }; +// }); +// }; + +// const patchOrders = () => { +// patch(injCLOB.spotApi, 'fetchOrderHistory', () => { +// return ORDERS; +// }); +// patch(injClobPerp.derivativeApi, 'fetchOrderHistory', () => { +// return ORDERS; +// }); +// }; + +// const patchGasPrices = () => { +// patch(injCLOB, 'estimateGas', () => { +// return GAS_PRICES; +// }); +// patch(injClobPerp, 'estimateGas', () => { +// return GAS_PRICES; +// }); +// }; + +// describe('GET /clob/markets', () => { +// it('should return 200 with proper request', async () => { +// patchMarkets(); +// await request(gatewayApp) +// .get(`/clob/markets`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.markets).toEqual(injCLOB.parsedMarkets)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/markets`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/orderBook', () => { +// it('should return 200 with proper request', async () => { +// patchOrderBook(); +// await request(gatewayApp) +// .get(`/clob/orderBook`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// market: MARKET, +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.buys).toEqual(ORDER_BOOK.buys)) +// .expect((res) => expect(res.body.sells).toEqual(ORDER_BOOK.sells)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/orderBook`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/ticker', () => { +// it('should return 200 with proper request', async () => { +// patchMarkets(); +// await request(gatewayApp) +// .get(`/clob/ticker`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.markets).toEqual(injCLOB.parsedMarkets)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/ticker`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/orders', () => { +// it('should return 200 with proper request', async () => { +// patchOrders(); +// await request(gatewayApp) +// .get(`/clob/orders`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// market: MARKET, +// orderId: '0x...', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.orders).toEqual(ORDERS.orderHistory)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/orders`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('POST /clob/orders', () => { +// it('should return 200 with proper request', async () => { +// patchGetWallet(); +// patchMsgBroadcaster(); +// await request(gatewayApp) +// .post(`/clob/orders`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// market: MARKET, +// price: '10000.12', +// amount: '0.12', +// side: 'BUY', +// orderType: 'LIMIT', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .post(`/clob/orders`) +// .send(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('DELETE /clob/orders', () => { +// it('should return 200 with proper request', async () => { +// patchGetWallet(); +// patchMsgBroadcaster(); +// await request(gatewayApp) +// .delete(`/clob/orders`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// market: MARKET, +// orderId: '0x...', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .delete(`/clob/orders`) +// .send(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('POST /clob/batchOrders', () => { +// it('should return 200 with proper request to create batch orders', async () => { +// patchGetWallet(); +// patchMsgBroadcaster(); +// await request(gatewayApp) +// .post(`/clob/batchOrders`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// createOrderParams: [ +// { +// price: '2', +// amount: '0.10', +// side: 'SELL', +// orderType: 'LIMIT', +// market: MARKET, +// }, +// { +// price: '3', +// amount: '0.10', +// side: 'SELL', +// market: MARKET, +// }, +// ], +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); +// }); + +// it('should return 200 with proper request to delete batch orders', async () => { +// patchGetWallet(); +// patchMsgBroadcaster(); +// await request(gatewayApp) +// .post(`/clob/batchOrders`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// market: MARKET, +// cancelOrderIds: [ +// '0x73af517124c3f564d1d70e38ad5200dfc7101d04986c14df410042e00932d4bf', // noqa: mock +// '0x8ce222ca5da95aaffd87b3d38a307f25d6e2c09e70a0cb8599bc6c8a0851fda3', // noqa: mock +// ], +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .post(`/clob/batchOrders`) +// .send(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/estimateGas', () => { +// it('should return 200 with proper request', async () => { +// patchGasPrices(); +// await request(gatewayApp) +// .get(`/clob/estimateGas`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.gasPrice).toEqual(GAS_PRICES.gasPrice)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/estimateGas`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// // perp stuff + +// describe('POST /clob/perp/positions', () => { +// it('should return 200 with proper request', async () => { +// patchPositions(); +// await request(gatewayApp) +// .post(`/clob/perp/positions`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// markets: [MARKET], +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.positions).toEqual(POSITIONS)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .post(`/clob/perp/positions`) +// .send(INVALID_REQUEST) +// .set('Accept', 'application/json') +// .expect(404); +// }); +// }); + +// describe('POST /clob/perp/funding/info', () => { +// it('should return 200 with proper request', async () => { +// patchMarkets(); +// patchFundingRates(); +// patchTrades(); +// patchOraclePrice(); +// await request(gatewayApp) +// .post(`/clob/perp/funding/info`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// market: MARKET, +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.fundingInfo.markPrice).toEqual('1.234')); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .post(`/clob/perp/funding/info`) +// .send(INVALID_REQUEST) +// .set('Accept', 'application/json') +// .expect(404); +// }); +// }); + +// describe('POST /clob/perp/funding/payments', () => { +// it('should return 200 with proper request', async () => { +// patchFundingPayments(); +// await request(gatewayApp) +// .post(`/clob/perp/funding/payments`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// market: MARKET, +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => +// expect(res.body.fundingPayments).toEqual(FUNDING_PAYMENTS) +// ); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .post(`/clob/perp/funding/payments`) +// .send(INVALID_REQUEST) +// .set('Accept', 'application/json') +// .expect(404); +// }); +// }); + +// describe('GET /clob/perp/markets', () => { +// it('should return 200 with proper request', async () => { +// patchMarkets(); +// await request(gatewayApp) +// .get(`/clob/perp/markets`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => +// expect(res.body.markets).toEqual(injClobPerp.parsedMarkets) +// ); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/perp/markets`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/perp/orderBook', () => { +// it('should return 200 with proper request', async () => { +// patchOrderBook(); +// await request(gatewayApp) +// .get(`/clob/perp/orderBook`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// market: MARKET, +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.buys).toEqual(ORDER_BOOK.buys)) +// .expect((res) => expect(res.body.sells).toEqual(ORDER_BOOK.sells)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/perp/orderBook`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/perp/ticker', () => { +// it('should return 200 with proper request', async () => { +// patchMarkets(); +// await request(gatewayApp) +// .get(`/clob/perp/ticker`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => +// expect(res.body.markets).toEqual(injClobPerp.parsedMarkets) +// ); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/perp/ticker`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/perp/orders', () => { +// it('should return 200 with proper request', async () => { +// patchOrders(); +// await request(gatewayApp) +// .get(`/clob/perp/orders`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// market: MARKET, +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.orders).toEqual(ORDERS.orderHistory)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/perp/orders`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('POST /clob/perp/orders', () => { +// it('should return 200 with proper request', async () => { +// patchGetWallet(); +// patchMsgBroadcaster(); +// await request(gatewayApp) +// .post(`/clob/perp/orders`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// market: MARKET, +// price: '10000.12', +// amount: '0.12', +// side: 'BUY', +// orderType: 'LIMIT', +// leverage: 20.0, +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .post(`/clob/perp/orders`) +// .send(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('DELETE /clob/perp/orders', () => { +// it('should return 200 with proper request', async () => { +// patchGetWallet(); +// patchMsgBroadcaster(); +// await request(gatewayApp) +// .delete(`/clob/perp/orders`) +// .send({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// address: +// '0x261362dBC1D83705AB03e99792355689A4589b8E000000000000000000000000', // noqa: mock +// market: MARKET, +// orderId: '0x...', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.txHash).toEqual(TX_HASH)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .delete(`/clob/perp/orders`) +// .send(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/perp/estimateGas', () => { +// it('should return 200 with proper request', async () => { +// patchGasPrices(); +// await request(gatewayApp) +// .get(`/clob/perp/estimateGas`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => expect(res.body.gasPrice).toEqual(GAS_PRICES.gasPrice)); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/perp/estimateGas`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); + +// describe('GET /clob/perp/lastTradePrice', () => { +// it('should return 200 with proper request', async () => { +// patchTrades(); +// await request(gatewayApp) +// .get(`/clob/perp/lastTradePrice`) +// .query({ +// chain: 'injective', +// network: 'mainnet', +// connector: 'injective_perpetual', +// market: MARKET, +// }) +// .set('Accept', 'application/json') +// .expect('Content-Type', /json/) +// .expect(200) +// .expect((res) => +// expect(res.body.lastTradePrice).toEqual( +// ( +// parseFloat(TRADES.trades[0].executionPrice) * parseFloat(`1e-6`) +// ).toString() +// ) +// ); +// }); + +// it('should return 404 when parameters are invalid', async () => { +// await request(gatewayApp) +// .get(`/clob/perp/lastTradePrice`) +// .query(INVALID_REQUEST) +// .expect(404); +// }); +// }); diff --git a/test-bronze/connectors/injective_perpetual/injective.perp.test.ts b/test-bronze/connectors/injective_perpetual/injective.perp.test.ts deleted file mode 100644 index 3d23bb14d8..0000000000 --- a/test-bronze/connectors/injective_perpetual/injective.perp.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { utils } from 'ethers'; -import { InjectiveClobPerp } from '../../../src/connectors/injective_perpetual/injective.perp'; - -// const margin = calculateMargin('1.234', '567.89', 4, 100); -describe('calculateMargin', () => { - it('100x leverage, 4 decimals', () => { - const result = utils.formatUnits( - InjectiveClobPerp.calculateMargin('1.234', '567.89', 4, 100), - 4 - ); - expect(result).toEqual('7.0077'); - }); - - it('100x leverage, 18 decimals', () => { - const result = utils.formatUnits( - InjectiveClobPerp.calculateMargin('1.234', '567.89', 18, 100), - 18 - ); - expect(result).toEqual('7.0077626'); - }); - - // EUR/USD 1 = 1.06 - it('20x leverage, 2 decimals', () => { - const result = utils.formatUnits( - InjectiveClobPerp.calculateMargin('1.06', '500', 2, 20), - 2 - ); - expect(result).toEqual('26.5'); - }); -}); diff --git a/test-helpers/curl/curl.sh b/test-helpers/curl/curl.sh index e59d1fa459..b2bbab5842 100644 --- a/test-helpers/curl/curl.sh +++ b/test-helpers/curl/curl.sh @@ -5,9 +5,7 @@ # export AVALANCHE_ADDRESS='' # export NEAR_ADDRESS='=0.6.0: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" @@ -14688,14 +12525,6 @@ saxes@^5.0.1: dependencies: xmlchars "^2.2.0" -scheduler@^0.19.1: - version "0.19.1" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196" - integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - scheduler@^0.23.0: version "0.23.0" resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe" @@ -14730,11 +12559,6 @@ scryptsy@2.1.0, scryptsy@^2.1.0: resolved "https://registry.yarnpkg.com/scryptsy/-/scryptsy-2.1.0.tgz#8d1e8d0c025b58fdd25b6fa9a0dc905ee8faa790" integrity sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w== -sdp@^2.12.0, sdp@^2.6.0: - version "2.12.0" - resolved "https://registry.yarnpkg.com/sdp/-/sdp-2.12.0.tgz#338a106af7560c86e4523f858349680350d53b22" - integrity sha512-jhXqQAQVM+8Xj5EjJGVweuEzgtGWb3tmEEpl3CLP3cStInSbVHSg0QWOGQzNq8pSID4JkpeV2mPqlMDLrm0/Vw== - secp256k1@3.7.1: version "3.7.1" resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-3.7.1.tgz#12e473e0e9a7c2f2d4d4818e722ad0e14cc1e2f1" @@ -14749,7 +12573,7 @@ secp256k1@3.7.1: nan "^2.14.0" safe-buffer "^5.1.2" -secp256k1@4.0.3, secp256k1@^4.0.0, secp256k1@^4.0.1, secp256k1@^4.0.3: +secp256k1@4.0.3, secp256k1@^4.0.1, secp256k1@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.3.tgz#c4559ecd1b8d3c1827ed2d1b94190d69ce267303" integrity sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA== @@ -14958,7 +12782,7 @@ shelljs@^0.8.5: interpret "^1.0.0" rechoir "^0.6.2" -shx@^0.3.2, shx@^0.3.3: +shx@^0.3.2: version "0.3.4" resolved "https://registry.yarnpkg.com/shx/-/shx-0.3.4.tgz#74289230b4b663979167f94e1935901406e40f02" integrity sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g== @@ -15032,11 +12856,6 @@ slice-ansi@^4.0.0: astral-regex "^2.0.0" is-fullwidth-code-point "^3.0.0" -smart-buffer@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae" - integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg== - snake-case@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-2.1.0.tgz#41bdb1b73f30ec66a04d4e2cad1b76387d4d6d9f" @@ -15091,41 +12910,6 @@ snapdragon@^0.8.1: source-map-resolve "^0.5.0" use "^3.1.0" -socket.io-client@^4.6.1: - version "4.6.1" - resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-4.6.1.tgz#80d97d5eb0feca448a0fb6d69a7b222d3d547eab" - integrity sha512-5UswCV6hpaRsNg5kkEHVcbBIXEYoVbMQaHJBXJCyEQ+CiFPV1NIOY0XOFWG4XR4GZcB8Kn6AsRs/9cy9TbqVMQ== - dependencies: - "@socket.io/component-emitter" "~3.1.0" - debug "~4.3.2" - engine.io-client "~6.4.0" - socket.io-parser "~4.2.1" - -socket.io-parser@~4.2.1: - version "4.2.2" - resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-4.2.2.tgz#1dd384019e25b7a3d374877f492ab34f2ad0d206" - integrity sha512-DJtziuKypFkMMHCm2uIshOYC7QaylbtzQwiMYDuCKy3OPkjLzu4B2vAhTlqipRHHzrI0NJeBAizTK7X+6m1jVw== - dependencies: - "@socket.io/component-emitter" "~3.1.0" - debug "~4.3.1" - -socks-proxy-agent@6.1.1: - version "6.1.1" - resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-6.1.1.tgz#e664e8f1aaf4e1fb3df945f09e3d94f911137f87" - integrity sha512-t8J0kG3csjA4g6FTbsMOWws+7R7vuRC8aQ/wy3/1OWmsgwA68zs/+cExQ0koSitUDXqhufF/YJr9wtNMZHw5Ew== - dependencies: - agent-base "^6.0.2" - debug "^4.3.1" - socks "^2.6.1" - -socks@^2.6.1: - version "2.7.1" - resolved "https://registry.yarnpkg.com/socks/-/socks-2.7.1.tgz#d8e651247178fde79c0663043e07240196857d55" - integrity sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ== - dependencies: - ip "^2.0.0" - smart-buffer "^4.2.0" - solc@0.7.3: version "0.7.3" resolved "https://registry.yarnpkg.com/solc/-/solc-0.7.3.tgz#04646961bd867a744f63d2b4e3c0701ffdc7d78a" @@ -15141,13 +12925,6 @@ solc@0.7.3: semver "^5.5.0" tmp "0.0.33" -sonic-boom@^2.2.1: - version "2.8.0" - resolved "https://registry.yarnpkg.com/sonic-boom/-/sonic-boom-2.8.0.tgz#c1def62a77425090e6ad7516aad8eb402e047611" - integrity sha512-kuonw1YOYYNOve5iHdSahXPOK49GqwA+LZhI6Wz/l0rP57iKyXXIHaRagOBHAPmGwJC6od2Z9zgvZ5loSgMlVg== - dependencies: - atomic-sleep "^1.0.0" - source-map-resolve@^0.5.0: version "0.5.3" resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a" @@ -15192,11 +12969,6 @@ spark-md5@3.0.2: resolved "https://registry.yarnpkg.com/spark-md5/-/spark-md5-3.0.2.tgz#7952c4a30784347abcee73268e473b9c0167e3fc" integrity sha512-wcFzz9cDfbuqe0FZzfi2or1sgyIrsDwmPwfZC4hiNidPdPINjeUwNfv5kldczoEAcjl9Y1L3SM7Uz2PUEQzxQw== -split-on-first@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f" - integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw== - split-string@^3.0.1, split-string@^3.0.2: version "3.1.0" resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" @@ -15204,11 +12976,6 @@ split-string@^3.0.1, split-string@^3.0.2: dependencies: extend-shallow "^3.0.0" -split2@^4.0.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/split2/-/split2-4.1.0.tgz#101907a24370f85bb782f08adaabe4e281ecf809" - integrity sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ== - sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" @@ -15290,19 +13057,6 @@ stream-blackhole@^1.0.3: resolved "https://registry.yarnpkg.com/stream-blackhole/-/stream-blackhole-1.0.3.tgz#6fc2e2c2e9d9fde6be8c68d3db88de09802e4d63" integrity sha512-7NWl3dkmCd12mPkEwTbBPGxwvxj7L4O9DTjJudn02Fmk9K+RuPaDF8zeGo3kmjbsffU5E1aGpZ1dTR9AaRg6AQ== -stream-browserify@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f" - integrity sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA== - dependencies: - inherits "~2.0.4" - readable-stream "^3.5.0" - -stream-shift@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d" - integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ== - streamsearch@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" @@ -15313,11 +13067,6 @@ strict-uri-encode@^1.0.0: resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713" integrity sha512-R3f198pcvnB+5IpnBlRkphuE9n46WyVl8I39W/ZUTZLz4nqSP/oLYUrcnJrw462Ds8he4YKMov2efsTIw1BDGQ== -strict-uri-encode@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546" - integrity sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ== - string-length@^4.0.1: version "4.0.2" resolved "https://registry.yarnpkg.com/string-length/-/string-length-4.0.2.tgz#a8a8dc7bd5c1a82b9b3c8b87e125f66871b6e57a" @@ -15343,15 +13092,6 @@ string-width@^2.0.0, string-width@^2.1.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" -string-width@^3.0.0, string-width@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" - integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== - dependencies: - emoji-regex "^7.0.1" - is-fullwidth-code-point "^2.0.0" - strip-ansi "^5.1.0" - string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" @@ -15421,7 +13161,7 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" -strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: +strip-ansi@^5.0.0: version "5.2.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== @@ -15474,11 +13214,6 @@ strip-json-comments@3.1.1, strip-json-comments@^3.1.0, strip-json-comments@^3.1. resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== -sturdy-websocket@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/sturdy-websocket/-/sturdy-websocket-0.2.1.tgz#20a58fd53372ef96eaa08f3c61c91a10b07c7c05" - integrity sha512-NnzSOEKyv4I83qbuKw9ROtJrrT6Z/Xt7I0HiP/e6H6GnpeTDvzwGIGeJ8slai+VwODSHQDooW2CAilJwT9SpRg== - sublevel-pouchdb@7.3.1: version "7.3.1" resolved "https://registry.yarnpkg.com/sublevel-pouchdb/-/sublevel-pouchdb-7.3.1.tgz#c1cc03af45081345c7c82821d6dcaa74564ae2ef" @@ -15720,13 +13455,6 @@ text-table@^0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw== -thread-stream@^0.15.1: - version "0.15.2" - resolved "https://registry.yarnpkg.com/thread-stream/-/thread-stream-0.15.2.tgz#fb95ad87d2f1e28f07116eb23d85aba3bc0425f4" - integrity sha512-UkEhKIg2pD+fjkHQKyJO3yoIvAP3N6RlNFt2dUhcS1FGvCD1cQa1M/PGknCLFIyZdtJOWQjejp7bdNqmN7zwdA== - dependencies: - real-require "^0.1.0" - throat@^6.0.1: version "6.0.2" resolved "https://registry.yarnpkg.com/throat/-/throat-6.0.2.tgz#51a3fbb5e11ae72e2cf74861ed5c8020f89f29fe" @@ -15740,7 +13468,7 @@ through2@3.0.2: inherits "^2.0.4" readable-stream "2 || 3" -through2@^2.0.1, through2@^2.0.3: +through2@^2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd" integrity sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ== @@ -15768,17 +13496,6 @@ tiny-invariant@^1.1.0: resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.1.tgz#8560808c916ef02ecfd55e66090df23a4b7aa642" integrity sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw== -tiny-secp256k1@^1.1.3, tiny-secp256k1@^1.1.6: - version "1.1.6" - resolved "https://registry.yarnpkg.com/tiny-secp256k1/-/tiny-secp256k1-1.1.6.tgz#7e224d2bee8ab8283f284e40e6b4acb74ffe047c" - integrity sha512-FmqJZGduTyvsr2cF3375fqGHUovSwDi/QytexX1Se4BPuPZpTE5Ftp5fg+EFSuEf3lhZqgCRjEG3ydUQ/aNiwA== - dependencies: - bindings "^1.3.0" - bn.js "^4.11.8" - create-hmac "^1.1.7" - elliptic "^6.4.0" - nan "^2.13.2" - tiny-typed-emitter@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz#b3b027fdd389ff81a152c8e847ee2f5be9fad7b5" @@ -15861,11 +13578,6 @@ toformat@^2.0.0: resolved "https://registry.yarnpkg.com/toformat/-/toformat-2.0.0.tgz#7a043fd2dfbe9021a4e36e508835ba32056739d8" integrity sha512-03SWBVop6nU8bpyZCx7SodpYznbZF5R4ljwNLBcTQzKOD9xuihRo/psX58llS1BMFhhAI08H3luot5GoXJz2pQ== -toggle-selection@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32" - integrity sha512-BiZS+C1OS8g/q2RRbJmy59xpyghNBqrr6k5L/uKBGRsTfxmu3ffiRnd8mlGPUVayg8pvfi5urfnu8TU7DVOkLQ== - toidentifier@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" @@ -15969,7 +13681,7 @@ ts-jest@^27.0.5: semver "7.x" yargs-parser "20.x" -ts-node@^10.0.0, ts-node@^10.9.1: +ts-node@^10.0.0: version "10.9.1" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw== @@ -15998,12 +13710,12 @@ tsconfig-paths@^3.14.1: minimist "^1.2.6" strip-bom "^3.0.0" -tslib@1.14.1, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.8.1, tslib@^1.9.3: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@2.5.0, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.0: +tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.0: version "2.5.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== @@ -16032,7 +13744,7 @@ tunnel-agent@^0.6.0: dependencies: safe-buffer "^5.0.1" -tweetnacl-util@^0.15.0, tweetnacl-util@^0.15.1: +tweetnacl-util@^0.15.1: version "0.15.1" resolved "https://registry.yarnpkg.com/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz#b80fcdb5c97bcc508be18c44a4be50f022eea00b" integrity sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw== @@ -16061,7 +13773,7 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5: +type-detect@4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== @@ -16135,11 +13847,6 @@ typedarray-to-buffer@^4.0.0: resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-4.0.0.tgz#cdd2933c61dd3f5f02eda5d012d441f95bfeb50a" integrity sha512-6dOYeZfS3O9RtRD1caom0sMxgK59b27+IwoNy8RDPsmslSGOyU+mpTamlaIW7aNKi90ZQZ9DFaZL3YRoiSCULQ== -typeforce@^1.11.5, typeforce@^1.18.0: - version "1.18.0" - resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc" - integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g== - typescript-compare@^0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/typescript-compare/-/typescript-compare-0.0.2.tgz#7ee40a400a406c2ea0a7e551efd3309021d5f425" @@ -16159,7 +13866,7 @@ typescript-tuple@^2.2.1: dependencies: typescript-compare "^0.0.2" -typescript@^4.3.2, typescript@^4.6.2: +typescript@^4.3.2: version "4.9.5" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== @@ -16169,13 +13876,6 @@ u3@^0.1.1: resolved "https://registry.yarnpkg.com/u3/-/u3-0.1.1.tgz#5f52044f42ee76cd8de33148829e14528494b73b" integrity sha512-+J5D5ir763y+Am/QY6hXNRlwljIeRMZMGs0cT6qqZVVzzT3X3nFPXVyPOFRMOR4kupB0T8JnCdpWdp6Q/iXn3w== -uint8arrays@^3.0.0, uint8arrays@^3.1.0: - version "3.1.1" - resolved "https://registry.yarnpkg.com/uint8arrays/-/uint8arrays-3.1.1.tgz#2d8762acce159ccd9936057572dade9459f65ae0" - integrity sha512-+QJa8QRnbdXVpHYjLoTpJIdCTiw9Ir62nocClWuXIq2JIh4Uta0cQsTSpFL678p2CN8B+XSApwcU+pQEqVpKWg== - dependencies: - multiformats "^9.4.2" - ultron@~1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.1.tgz#9fe1536a10a664a65266a1e3ccf85fd36302bc9c" @@ -16246,11 +13946,6 @@ universalify@^2.0.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== -unload@^2.4.1: - version "2.4.1" - resolved "https://registry.yarnpkg.com/unload/-/unload-2.4.1.tgz#b0c5b7fb44e17fcbf50dcb8fb53929c59dd226a5" - integrity sha512-IViSAm8Z3sRBYA+9wc0fLQmU9Nrxb16rcDmIiR6Y9LJSZzI7QY5QsDhqPpKOjAn0O9/kfK1TfNEMMAGPTIraPw== - unorm@^1.3.3: version "1.6.0" resolved "https://registry.yarnpkg.com/unorm/-/unorm-1.6.0.tgz#029b289661fba714f1a9af439eb51d9b16c205af" @@ -16367,7 +14062,7 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== -util@^0.12.0, util@^0.12.5: +util@^0.12.5: version "0.12.5" resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA== @@ -16378,11 +14073,6 @@ util@^0.12.0, util@^0.12.5: is-typed-array "^1.1.3" which-typed-array "^1.1.2" -utility-types@^3.10.0: - version "3.10.0" - resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.10.0.tgz#ea4148f9a741015f05ed74fd615e1d20e6bed82b" - integrity sha512-O11mqxmi7wMKCo6HKFt5AhO4BwY3VV68YU07tgxfz8zJTIxr4BpsezN49Ffwy9j3ZpwwJp4fkRwjRzq3uWE6Rg== - utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" @@ -16447,13 +14137,6 @@ varint@^5.0.0: resolved "https://registry.yarnpkg.com/varint/-/varint-5.0.2.tgz#5b47f8a947eb668b848e034dcfa87d0ff8a7f7a4" integrity sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow== -varuint-bitcoin@^1.1.2: - version "1.1.2" - resolved "https://registry.yarnpkg.com/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz#e76c138249d06138b480d4c5b40ef53693e24e92" - integrity sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw== - dependencies: - safe-buffer "^5.1.1" - vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" @@ -16527,13 +14210,6 @@ walker@^1.0.7: dependencies: makeerror "1.0.12" -warning@^4.0.3: - version "4.0.3" - resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3" - integrity sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w== - dependencies: - loose-envify "^1.0.0" - web3-bzz@1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/web3-bzz/-/web3-bzz-1.2.1.tgz#c3bd1e8f0c02a13cd6d4e3c3e9e1713f144f6f0d" @@ -16995,15 +14671,7 @@ webidl-conversions@^6.1.0: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514" integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w== -webrtc-adapter@^7.2.1: - version "7.7.1" - resolved "https://registry.yarnpkg.com/webrtc-adapter/-/webrtc-adapter-7.7.1.tgz#b2c227a6144983b35057df67bd984a7d4bfd17f1" - integrity sha512-TbrbBmiQBL9n0/5bvDdORc6ZfRY/Z7JnEj+EYOD1ghseZdpJ+nF2yx14k3LgQKc7JZnG7HAcL+zHnY25So9d7A== - dependencies: - rtcpeerconnection-shim "^1.2.15" - sdp "^2.12.0" - -websocket@^1.0.28, websocket@^1.0.32, websocket@^1.0.34: +websocket@^1.0.28, websocket@^1.0.32: version "1.0.34" resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.34.tgz#2bdc2602c08bf2c82253b730655c0ef7dcab3111" integrity sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ== @@ -17101,13 +14769,6 @@ which@^2.0.1: dependencies: isexe "^2.0.0" -wif@^2.0.6: - version "2.0.6" - resolved "https://registry.yarnpkg.com/wif/-/wif-2.0.6.tgz#08d3f52056c66679299726fade0d432ae74b4704" - integrity sha512-HIanZn1zmduSF+BQhkE+YXIbEiH0xPr1012QbFEGB0xsKqJii0/SqJjyn8dFv6y36kOznMgMB+LGcbZTJ1xACQ== - dependencies: - bs58check "<3.0.0" - winston-daily-rotate-file@^4.5.5: version "4.7.1" resolved "https://registry.yarnpkg.com/winston-daily-rotate-file/-/winston-daily-rotate-file-4.7.1.tgz#f60a643af87f8867f23170d8cd87dbe3603a625f" @@ -17162,15 +14823,6 @@ wrap-ansi@^2.0.0: string-width "^1.0.1" strip-ansi "^3.0.1" -wrap-ansi@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09" - integrity sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q== - dependencies: - ansi-styles "^3.2.0" - string-width "^3.0.0" - strip-ansi "^5.0.0" - wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" @@ -17207,11 +14859,6 @@ ws@7.4.6: resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c" integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A== -ws@7.5.9, ws@^7, ws@^7.2.0, ws@^7.4.0, ws@^7.4.5, ws@^7.4.6, ws@^7.5.1: - version "7.5.9" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" - integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== - ws@8.12.0: version "8.12.0" resolved "https://registry.yarnpkg.com/ws/-/ws-8.12.0.tgz#485074cc392689da78e1828a9ff23585e06cddd8" @@ -17226,16 +14873,16 @@ ws@^3.0.0: safe-buffer "~5.1.0" ultron "~1.1.0" +ws@^7, ws@^7.2.0, ws@^7.4.5, ws@^7.4.6: + version "7.5.9" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" + integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== + ws@^8.5.0: version "8.13.0" resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== -ws@~8.11.0: - version "8.11.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.11.0.tgz#6a0d36b8edfd9f96d8b25683db2f8d7de6e8e143" - integrity sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg== - xhr-request-promise@^0.1.2: version "0.1.3" resolved "https://registry.yarnpkg.com/xhr-request-promise/-/xhr-request-promise-0.1.3.tgz#2d5f4b16d8c6c893be97f1a62b0ed4cf3ca5f96c" @@ -17309,11 +14956,6 @@ xmlchars@^2.2.0: resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb" integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw== -xmlhttprequest-ssl@~2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz#91360c86b914e67f44dce769180027c0da618c67" - integrity sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A== - xmlhttprequest@1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" @@ -17353,7 +14995,7 @@ xtend@^4.0.0, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1: resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== -"y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0: +"y18n@^3.2.1 || ^4.0.0": version "4.0.3" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.3.tgz#b5f259c82cd6e336921efd7bfd8bf560de9eeedf" integrity sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ== @@ -17396,14 +15038,6 @@ yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^13.1.2: - version "13.1.2" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38" - integrity sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg== - dependencies: - camelcase "^5.0.0" - decamelize "^1.2.0" - yargs-unparser@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb" @@ -17445,22 +15079,6 @@ yargs@^12.0.2: y18n "^3.2.1 || ^4.0.0" yargs-parser "^11.1.1" -yargs@^13.2.4: - version "13.3.2" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd" - integrity sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw== - dependencies: - cliui "^5.0.0" - find-up "^3.0.0" - get-caller-file "^2.0.1" - require-directory "^2.1.1" - require-main-filename "^2.0.0" - set-blocking "^2.0.0" - string-width "^3.0.0" - which-module "^2.0.0" - y18n "^4.0.0" - yargs-parser "^13.1.2" - yarn@^1.22.17, yarn@^1.22.19: version "1.22.19" resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.19.tgz#4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"