diff --git a/package.json b/package.json index d09c53b1..f5ea7b83 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "yarn test:parallel && yarn test:run_in_band", "test:parallel": "jest -b src/testcases/parallel", - "test:run_in_band": "yarn test:tge:auction && yarn test:tge:airdrop && yarn test:tge:credits && yarn test:interchaintx && yarn test:interchain_kv_query && yarn test:interchain_tx_query_plain && yarn test:tokenomics && yarn test:reserve && yarn test:ibc_hooks && yarn test:float && yarn test:parameters && yarn test:dex_stargate && yarn test:globalfee && yarn test:pob", + "test:run_in_band": "yarn test:tge:auction && yarn test:tge:airdrop && yarn test:tge:credits && yarn test:interchaintx && yarn test:interchain_kv_query && yarn test:interchain_tx_query_plain && yarn test:tokenomics && yarn test:reserve && yarn test:ibc_hooks && yarn test:float && yarn test:parameters && yarn test:dex_stargate && yarn test:globalfee && yarn test:dex_bindings && yarn test:pob", "test:simple": "jest -b src/testcases/parallel/simple", "test:stargate_queries": "jest -b src/testcases/parallel/stargate_queries", "test:interchaintx": "jest -b src/testcases/run_in_band/interchaintx", @@ -33,9 +33,11 @@ "test:float": "NO_WAIT_CHANNEL1=1 NO_WAIT_HTTP2=1 NO_WAIT_CHANNEL2=1 NO_WAIT_DELAY=1 jest -b src/testcases/run_in_band/float", "test:dex_stargate": "NO_WAIT_CHANNEL1=1 NO_WAIT_HTTP2=1 NO_WAIT_CHANNEL2=1 NO_WAIT_DELAY=1 jest -b src/testcases/run_in_band/dex_stargate", "test:pob": "NO_WAIT_CHANNEL1=1 NO_WAIT_HTTP2=1 NO_WAIT_CHANNEL2=1 NO_WAIT_DELAY=1 jest -b src/testcases/run_in_band/pob", + "test:dex_bindings": "NO_WAIT_CHANNEL1=1 NO_WAIT_HTTP2=1 NO_WAIT_CHANNEL2=1 NO_WAIT_DELAY=1 jest -b src/testcases/run_in_band/dex_bindings", "gen:proto": "bash ./gen-proto.sh", "lint": "eslint ./src", - "fmt": "eslint ./src --fix" + "fmt": "eslint ./src --fix", + "postinstall": "[ -d './node_modules/@neutron-org/neutronjsplus/dist' ] || tsc -p ./node_modules/@neutron-org/neutronjsplus/tsconfig.json" }, "author": "Neutron", "license": "Apache-2.0", @@ -44,9 +46,9 @@ "@cosmos-client/core": "^0.47.4", "@cosmos-client/cosmwasm": "^0.40.3", "@cosmos-client/ibc": "^1.2.1", - "@neutron-org/neutronjsplus": "0.3.1", + "@neutron-org/neutronjsplus": "^0.3.2", "@types/lodash": "^4.14.182", - "@types/long": "^4.0.2", + "@types/long": "^5.0.0", "axios": "^0.27.2", "babel-jest": "^29.3.1", "commander": "^10.0.0", @@ -76,7 +78,7 @@ "regenerator-runtime": "^0.13.9", "ts-node": "^9.1.1", "tslint": "^5.20.1", - "typescript": "^4.1.3" + "typescript": "^5.1.6" }, "lint-staged": { "./**/src/**/*.{ts,tsx}": [ diff --git a/src/helpers/dex.ts b/src/helpers/dex.ts deleted file mode 100644 index aad1fb42..00000000 --- a/src/helpers/dex.ts +++ /dev/null @@ -1,182 +0,0 @@ -import { cosmos } from '../generated/ibc/proto'; - -// DEX queries - -export type ParamsResponse = { - params: Params; -}; - -export type LimitOrderTrancheUserResponse = { - limit_order_tranche_user?: LimitOrderTrancheUser; -}; - -export type AllLimitOrderTrancheUserResponse = { - limit_order_tranche_user: LimitOrderTrancheUser[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -export type AllUserLimitOrdersResponse = { - limit_orders: LimitOrderTrancheUser[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -export type LimitOrderTrancheResponse = { - limit_order_tranche?: LimitOrderTranche; -}; - -export type AllLimitOrderTrancheResponse = { - limit_order_tranche: LimitOrderTranche[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -export type AllUserDepositsResponse = { - deposits: DepositRecord[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -export type AllTickLiquidityResponse = { - tick_liquidity: TickLiquidity[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -export type InactiveLimitOrderTrancheResponse = { - inactive_limit_order_tranche: LimitOrderTranche; -}; - -export type AllInactiveLimitOrderTrancheResponse = { - inactive_limit_order_tranche: LimitOrderTranche[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -export type AllPoolReservesResponse = { - pool_reserves: PoolReserves[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -export type PoolReservesResponse = { - pool_reserves: PoolReserves; -}; - -export type EstimateMultiHopSwapResponse = { - coin_out: cosmos.base.v1beta1.Coin; -}; - -export type EstimatePlaceLimitOrderResponse = { - // Total amount of coin used for the limit order - // You can derive makerLimitInCoin using the equation: totalInCoin = swapInCoin + makerLimitInCoin - total_in_coin: cosmos.base.v1beta1.Coin; - // Total amount of the token in that was immediately swapped for swapOutCoin - swap_in_coin: cosmos.base.v1beta1.Coin; - // Total amount of coin received from the taker portion of the limit order - // This is the amount of coin immediately available in the users account after executing the - // limit order. It does not include any future proceeds from the maker portion which will have withdrawn in the future - swap_out_coin: cosmos.base.v1beta1.Coin; -}; - -export type PoolResponse = { - pool: Pool; -}; - -export type PoolMetadataResponse = { - pool_metadata: PoolMetadata; -}; - -export type AllPoolMetadataResponse = { - pool_metadata: PoolMetadata[]; - pagination?: cosmos.base.query.v1beta1.PageResponse; -}; - -// types - -export enum LimitOrderType { - GoodTilCanceled = 0, - FillOrKill = 1, - ImmediateOrCancel = 2, - JustInTime = 3, - GoodTilTime = 4, -} - -export type MultiHopRoute = { - hops: string[]; -}; - -export type LimitOrderTrancheUser = { - trade_pair_id: TradePairID; - tick_index_taker_to_maker: string; // Int64 - tranche_key: string; - address: string; - shares_owned: string; // Int128 - shares_withdrawn: string; // Int128 - shares_cancelled: string; // Int128 - order_type: LimitOrderType; -}; - -export type TradePairID = { - maker_denom: string; - taker_denom: string; -}; - -export type Params = { - fee_tiers: string[]; // Uint64 - max_true_taker_spread: string; // PrecDec -}; - -export type LimitOrderTranche = { - key: LimitOrderTrancheKey; - reserves_maker_denom: string; // Int128 - reserves_taker_denom: string; // Int128 - total_maker_denom: string; // Int128 - total_taker_denom: string; // Int128 - expiration_time?: string; // Option - price_taker_to_maker: string; // PrecDec -}; - -export type LimitOrderTrancheKey = { - trade_pair_id: TradePairID; - tick_index_taker_to_maker: string; // Int64 - tranche_key: string; -}; - -export type DepositRecord = { - pair_id: PairID; - shares_owned: string; // Int128 - center_tick_index: string; // Int64 - lower_tick_index: string; // Int64 - ipper_tick_index: string; // Int64 - fee?: string; // Option -}; - -export type PairID = { - token0: string; - token1: string; -}; - -export type TickLiquidity = - | { pool_reserves: PoolReserves } - | { limit_order_tranche: LimitOrderTranche }; - -export type PoolReserves = { - key: PoolReservesKey; - reserves_maker_denom: string; // Int128 - price_taker_to_maker: string; // PrecDec - price_opposite_taker_to_maker: string; // PrecDec -}; - -export type PoolReservesKey = { - trade_pair_id: TradePairID; - tick_index_taker_to_maker: string; // Int64 - fee?: string; // Option -}; - -export type Pool = { - id: string; // Uint64 - lower_tick0: PoolReserves; - lower_tick1: PoolReserves; -}; - -export type PoolMetadata = { - id: string; // Uint64 - tick: string; // Int64 - fee: string; // Uint64 - pair_id: PairID; -}; diff --git a/src/testcases/run_in_band/dex_bindings.test.ts b/src/testcases/run_in_band/dex_bindings.test.ts new file mode 100644 index 00000000..33755794 --- /dev/null +++ b/src/testcases/run_in_band/dex_bindings.test.ts @@ -0,0 +1,683 @@ +import { + CosmosWrapper, + getEventAttribute, + getEventAttributesFromTx, + NEUTRON_DENOM, + WalletWrapper, +} from '@neutron-org/neutronjsplus/dist/cosmos'; +import { TestStateLocalCosmosTestNet } from '@neutron-org/neutronjsplus'; +import { NeutronContract, CodeId } from '@neutron-org/neutronjsplus/dist/types'; +import { + AllInactiveLimitOrderTrancheResponse, + AllLimitOrderTrancheResponse, + AllLimitOrderTrancheUserResponse, + AllPoolMetadataResponse, + AllPoolReservesResponse, + AllTickLiquidityResponse, + AllUserDepositsResponse, + AllUserLimitOrdersResponse, + EstimatePlaceLimitOrderResponse, + InactiveLimitOrderTrancheResponse, + LimitOrderTrancheResponse, + LimitOrderTrancheUserResponse, + LimitOrderType, + ParamsResponse, + PoolMetadataResponse, + PoolReservesResponse, + PoolResponse, +} from '@neutron-org/neutronjsplus/dist/dex_bindings'; +import { + msgCreateDenom, + msgMintDenom, +} from '@neutron-org/neutronjsplus/dist/tokenfactory'; + +const config = require('../../config.json'); + +describe('Neutron / dex module bindings', () => { + let testState: TestStateLocalCosmosTestNet; + let neutronChain: CosmosWrapper; + let neutronAccount: WalletWrapper; + let contractAddress: string; + let trancheKeyToWithdraw: string; + let trancheKeyToQuery: string; + + beforeAll(async () => { + testState = new TestStateLocalCosmosTestNet(config); + await testState.init(); + neutronChain = new CosmosWrapper( + testState.sdk1, + testState.blockWaiter1, + NEUTRON_DENOM, + ); + neutronAccount = new WalletWrapper( + neutronChain, + testState.wallets.neutron.demo1, + ); + }); + + describe('Instantiate dex binding contract', () => { + let codeId: CodeId; + test('store contract', async () => { + codeId = await neutronAccount.storeWasm(NeutronContract.DEX_DEV); + expect(codeId).toBeGreaterThan(0); + }); + test('instantiate contract', async () => { + contractAddress = ( + await neutronAccount.instantiateContract(codeId, '{}', 'dex_dev') + )[0]._contract_address; + console.log(contractAddress); + + await neutronAccount.msgSend(contractAddress, { + amount: '100000000', + denom: 'untrn', + }); + await neutronAccount.msgSend(contractAddress, { + amount: '100000000', + denom: 'uibcusdc', + }); + }); + }); + + describe('DEX messages', () => { + describe('Deposit', () => { + test('Invalid pair', async () => { + await expect( + neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + deposit: { + receiver: contractAddress, + token_a: 'untrn', + token_b: 'untrn', + amounts_a: ['100'], // uint128 + amounts_b: ['100'], // uint128 + tick_indexes_a_to_b: [1], // i64 + fees: [0], // u64 + options: [ + { + disable_swap: true, + }, + ], + }, + }), + ), + ).rejects.toThrowError( + /failed to execute \*types.MsgDeposit: untrn<>untrn: Invalid token pair/, + ); + }); + test('Valid pair', async () => { + // pool denom - 'neutron/pool/0' + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + deposit: { + receiver: contractAddress, + token_a: 'untrn', + token_b: 'uibcusdc', + amounts_a: ['100'], // uint128 + amounts_b: ['100'], // uint128 + tick_indexes_a_to_b: [1], // i64 + fees: [0], // u64 + options: [ + { + disable_swap: true, + }, + ], + }, + }), + ); + expect(res.code).toEqual(0); + }); + }); + describe('Withdrawal', () => { + test('valid', async () => { + // pool denom - 'neutron/pool/0' + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + withdrawal: { + receiver: contractAddress, + token_a: 'untrn', + token_b: 'uibcusdc', + shares_to_remove: ['10'], // uint128 + tick_indexes_a_to_b: [1], // i64 + fees: [0], // u64 + }, + }), + ); + expect(res.code).toEqual(0); + }); + }); + describe('LimitOrder', () => { + // enum LimitOrderType{ + // GOOD_TIL_CANCELLED = 0; + // FILL_OR_KILL = 1; + // IMMEDIATE_OR_CANCEL = 2; + // JUST_IN_TIME = 3; + // GOOD_TIL_TIME = 4; + // } + test('GOOD_TIL_CANCELLED', async () => { + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + order_type: LimitOrderType.GoodTilCancelled, + }, + }), + ); + expect(res.code).toEqual(0); + }); + test('FILL_OR_KILL', async () => { + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + order_type: LimitOrderType.FillOrKill, + max_amount_out: '100', + }, + }), + ); + expect(res.code).toEqual(0); + }); + test('IMMEDIATE_OR_CANCEL', async () => { + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + order_type: LimitOrderType.ImmediateOrCancel, + max_amount_out: '100', + }, + }), + ); + expect(res.code).toEqual(0); + }); + test('JUST_IN_TIME', async () => { + let res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + order_type: LimitOrderType.JustInTime, + }, + }), + ); + expect(res.code).toEqual(0); + trancheKeyToWithdraw = getEventAttributesFromTx( + { tx_response: res }, + 'TickUpdate', + ['TrancheKey'], + )[0]['TrancheKey']; + res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 2, + amount_in: '10', + order_type: LimitOrderType.JustInTime, + }, + }), + ); + expect(res.code).toEqual(0); + trancheKeyToQuery = getEventAttributesFromTx( + { tx_response: res }, + 'TickUpdate', + ['TrancheKey'], + )[0]['TrancheKey']; + }); + test('GOOD_TIL_TIME', async () => { + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + expiration_time: Math.ceil(Date.now() / 1000) + 1000, + order_type: LimitOrderType.GoodTilTime, + }, + }), + ); + expect(res.code).toEqual(0); + }); + test('GOOD_TIL_TIME expired', async () => { + await expect( + neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + expiration_time: 1, + order_type: LimitOrderType.GoodTilTime, + }, + }), + ), + ).rejects.toThrowError( + /Limit order expiration time must be greater than current block time/, + ); + }); + test('unknown order type', async () => { + await expect( + neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + place_limit_order: { + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + expiration_time: 1, + order_type: 'unknown', + }, + }), + ), + ).rejects.toThrowError( + /unknown variant `unknown`, expected one of `GOOD_TIL_CANCELLED`, `FILL_OR_KILL`, `IMMEDIATE_OR_CANCEL`, `JUST_IN_TIME`, `GOOD_TIL_TIME`/, + ); + }); + }); + describe('Withdraw filled lo', () => { + console.log(trancheKeyToWithdraw); + test('Withdraw', async () => { + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + withdraw_filled_limit_order: { + tranche_key: trancheKeyToWithdraw, + }, + }), + ); + expect(res.code).toEqual(0); + }); + }); + describe('cancel lo', () => { + console.log(trancheKeyToWithdraw); + test('cancel failed', async () => { + await expect( + neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + cancel_limit_order: { + tranche_key: trancheKeyToWithdraw, + }, + }), + ), + ).rejects.toThrowError( + /No active limit found. It does not exist or has already been filled/, + ); + }); + }); + + describe('MultiHopSwap', () => { + const denoms: any[] = []; + test('successfull multihops', async () => { + const numberDenoms = 10; + for (let i = 0; i < numberDenoms; i++) { + const data = await msgCreateDenom( + neutronAccount, + neutronAccount.wallet.address.toString(), + String(i), + ); + + const newTokenDenom = getEventAttribute( + (data as any).events, + 'create_denom', + 'new_token_denom', + ); + + await msgMintDenom( + neutronAccount, + neutronAccount.wallet.address.toString(), + { + denom: newTokenDenom, + amount: '1000000', + }, + ); + await neutronAccount.msgSend(contractAddress, { + amount: '1000000', + denom: newTokenDenom, + }); + denoms.push({ + denom: newTokenDenom, + balance: 1000000, + }); + } + for (let i = 0; i < numberDenoms - 1; i++) { + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + deposit: { + receiver: contractAddress, + token_a: denoms[i].denom, + token_b: denoms[i + 1].denom, + amounts_a: ['1000'], // uint128 + amounts_b: ['1000'], // uint128 + tick_indexes_a_to_b: [5], // i64 + fees: [0], // u64 + options: [ + { + disable_swap: true, + }, + ], + }, + }), + ); + expect(res.code).toEqual(0); + } + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + multi_hop_swap: { + receiver: contractAddress, + routes: [ + { + hops: [ + denoms[0].denom, + denoms[1].denom, + denoms[2].denom, + denoms[3].denom, + denoms[4].denom, + denoms[5].denom, + denoms[6].denom, + denoms[7].denom, + denoms[8].denom, + denoms[9].denom, + ], + }, + ], + amount_in: '100', + exit_limit_price: '0.1', + pick_best_route: true, + }, + }), + ); + expect(res.code).toEqual(0); + console.log(res); + }); + + test('no route found', async () => { + await expect( + neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + multi_hop_swap: { + receiver: contractAddress, + routes: [ + { + hops: [denoms[0].denom, denoms[9].denom], + }, + ], + amount_in: '100', + exit_limit_price: '0.1', + pick_best_route: true, + }, + }), + ), + ).rejects.toThrowError( + /All multihop routes failed limitPrice check or had insufficient liquidity/, + ); + }); + }); + }); + describe('DEX queries', () => { + test('ParamsQuery', async () => { + await neutronAccount.chain.queryContract( + contractAddress, + { + params: {}, + }, + ); + }); + test('LimitOrderTrancheUserQuery', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + limit_order_tranche_user: { + address: contractAddress, + tranche_key: trancheKeyToWithdraw, + }, + }, + ); + expect(res.limit_order_tranche_user).toBeDefined(); + }); + test('LimitOrderTrancheUserAllQuery', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + limit_order_tranche_user_all: {}, + }, + ); + expect(res.limit_order_tranche_user.length).toBeGreaterThan(0); + }); + test('LimitOrderTrancheUserAllByAddressQuery', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + limit_order_tranche_user_all_by_address: { + address: contractAddress, + }, + }, + ); + expect(res.limit_orders.length).toBeGreaterThan(0); + }); + test('LimitOrderTrancheQuery', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + limit_order_tranche: { + pair_id: 'uibcusdc<>untrn', + tick_index: -2, + token_in: 'untrn', + tranche_key: trancheKeyToQuery, + }, + }, + ); + expect(res.limit_order_tranche).toBeDefined(); + }); + test('invalid LimitOrderTrancheQuery', async () => { + await expect( + neutronAccount.chain.queryContract( + contractAddress, + { + limit_order_tranche: { + pair_id: 'untrn<>notadenom', + tick_index: 1, + token_in: 'untrn', + tranche_key: trancheKeyToWithdraw, + }, + }, + ), + ).rejects.toThrowError(); + }); + test('AllLimitOrderTranche', async () => { + // const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + limit_order_tranche_all: { + pair_id: 'uibcusdc<>untrn', + token_in: 'untrn', + }, + }, + ); + // TODO: add tranche for tests + // expect(res.limit_order_tranche.length).toBeGreaterThan(0); + }); + test('AllUserDeposits', async () => { + const resp = + await neutronAccount.chain.queryContract( + contractAddress, + { + user_deposit_all: { + address: contractAddress, + include_pool_data: true, + }, + }, + ); + console.log(resp); + expect(Number(resp.deposits[0].total_shares)).toBeGreaterThan(0); + expect(Number(resp.deposits[0].pool!.id)).toEqual(0); + + const respNoPoolData = + await neutronAccount.chain.queryContract( + contractAddress, + { + user_deposit_all: { + address: contractAddress, + include_pool_data: false, + }, + }, + ); + expect(respNoPoolData.deposits[0].total_shares).toBeNull(); + expect(respNoPoolData.deposits[0].pool).toBeNull(); + }); + test('AllTickLiquidity', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + tick_liquidity_all: { + pair_id: 'uibcusdc<>untrn', + token_in: 'untrn', + }, + }, + ); + expect(res.tick_liquidity.length).toBeGreaterThan(0); + }); + test('InactiveLimitOrderTranche', async () => { + await neutronAccount.chain.queryContract( + contractAddress, + { + inactive_limit_order_tranche: { + pair_id: 'uibcusdc<>untrn', + tick_index: -2, + token_in: 'untrn', + tranche_key: trancheKeyToQuery, + }, + }, + ); + }); + test('AllInactiveLimitOrderTranche', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + inactive_limit_order_tranche_all: {}, + }, + ); + expect(res.inactive_limit_order_tranche.length).toBeGreaterThan(0); + }); + test('AllPoolReserves', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + pool_reserves_all: { + pair_id: 'uibcusdc<>untrn', + token_in: 'untrn', + }, + }, + ); + expect(res.pool_reserves.length).toBeGreaterThan(0); + }); + test('PoolReserves', async () => { + await neutronAccount.chain.queryContract( + contractAddress, + { + pool_reserves: { + pair_id: 'uibcusdc<>untrn', + tick_index: -1, + token_in: 'untrn', + fee: 0, + }, + }, + ); + }); + test.skip('EstimateMultiHopSwap', async () => { + // TODO + // await neutronAccount.chain.queryContract( + // contractAddress, + // { + // params: {}, + // }, + // ); + }); + test('EstimatePlaceLimitOrder', async () => { + await neutronAccount.chain.queryContract( + contractAddress, + { + estimate_place_limit_order: { + creator: contractAddress, + receiver: contractAddress, + token_in: 'untrn', + token_out: 'uibcusdc', + tick_index_in_to_out: 1, + amount_in: '10', + expiration_time: Math.ceil(Date.now() / 1000) + 1000, + order_type: LimitOrderType.GoodTilTime, + }, + }, + ); + }); + test('Pool', async () => { + await neutronAccount.chain.queryContract(contractAddress, { + pool: { pair_id: 'uibcusdc<>untrn', tick_index: -1, fee: 0 }, + }); + }); + test('PoolByID', async () => { + await neutronAccount.chain.queryContract(contractAddress, { + pool_by_id: { pool_id: 0 }, + }); + }); + test('PoolMetadata', async () => { + await neutronAccount.chain.queryContract( + contractAddress, + { + pool_metadata: { id: 0 }, + }, + ); + }); + test('AllPoolMetadata', async () => { + const res = + await neutronAccount.chain.queryContract( + contractAddress, + { + pool_metadata_all: {}, + }, + ); + expect(res.pool_metadata.length).toBeGreaterThan(0); + }); + }); +}); diff --git a/src/testcases/run_in_band/dex_stargate.test.ts b/src/testcases/run_in_band/dex_stargate.test.ts index 8851f923..d46c9011 100644 --- a/src/testcases/run_in_band/dex_stargate.test.ts +++ b/src/testcases/run_in_band/dex_stargate.test.ts @@ -435,12 +435,32 @@ describe('Neutron / dex module (stargate contract)', () => { // expect(res.limit_order_tranche.length).toBeGreaterThan(0); }); test('AllUserDeposits', async () => { - await neutronAccount.chain.queryContract( - contractAddress, - { - all_user_deposits: { address: contractAddress }, - }, - ); + const resp = + await neutronAccount.chain.queryContract( + contractAddress, + { + all_user_deposits: { + address: contractAddress, + include_pool_data: true, + }, + }, + ); + console.log(resp); + expect(Number(resp.deposits[0].total_shares)).toBeGreaterThan(0); + expect(Number(resp.deposits[0].pool!.id)).toEqual(0); + + const respNoPoolData = + await neutronAccount.chain.queryContract( + contractAddress, + { + all_user_deposits: { + address: contractAddress, + include_pool_data: false, + }, + }, + ); + expect(respNoPoolData.deposits[0].total_shares).toBeNull(); + expect(respNoPoolData.deposits[0].pool).toBeNull(); }); test('AllTickLiquidity', async () => { const res = diff --git a/yarn.lock b/yarn.lock index 12816811..74754cd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1564,10 +1564,10 @@ resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-5.50.0.tgz#29c6419e8379d496ab6d0426eadf3c4d100cd186" integrity sha512-swKHYCOZUGyVt4ge0u8a7AwNcA//h4nx5wIi0sruGye1IJ5Cva0GyK9L2/WdX+kWVTKp92ZiEo1df31lrWGPgA== -"@neutron-org/neutronjsplus@0.3.1": - version "0.3.1" - resolved "https://registry.yarnpkg.com/@neutron-org/neutronjsplus/-/neutronjsplus-0.3.1.tgz#56670b48ab25c634d019720694e50d37ba733af1" - integrity sha512-O7Q4Qvqwmj6bY2rCUTXPPdKg8MmqtD/4IugWIeDoCNQN1i75qBAxJhxXZ6tILdDicQZlwXdoP9usqwvKxMRYdA== +"@neutron-org/neutronjsplus@^0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@neutron-org/neutronjsplus/-/neutronjsplus-0.3.2.tgz#e17ff14469fcfa5fdc31beb64d72b5b0bc374bf6" + integrity sha512-Tidybr9e4z8CzhaDc7Btl2PRtwC4453gG81rJHBrGb76Ts38gTFA+hGeKhzoGDaTJFgSYIonDyUjCe9UC//v1w== dependencies: "@bufbuild/protobuf" "^1.4.2" "@cosmos-client/core" "^0.47.4" @@ -1826,11 +1826,18 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.202.tgz#f09dbd2fb082d507178b2f2a5c7e74bd72ff98f8" integrity sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ== -"@types/long@^4.0.1", "@types/long@^4.0.2": +"@types/long@^4.0.1": version "4.0.2" resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.2.tgz#b74129719fc8d11c01868010082d483b7545591a" integrity sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA== +"@types/long@^5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@types/long/-/long-5.0.0.tgz#daaa7b7f74c919c946ff74889d5ca2afe363b2cd" + integrity sha512-eQs9RsucA/LNjnMoJvWG/nXa7Pot/RbBzilF/QRIU/xRl+0ApxrSUFsV5lmf01SvSlqMzJ7Zwxe440wmz2SJGA== + dependencies: + long "*" + "@types/mime@*": version "3.0.4" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.4.tgz#2198ac274de6017b44d941e00261d5bc6a0e0a45" @@ -4172,16 +4179,16 @@ log-update@^4.0.0: slice-ansi "^4.0.0" wrap-ansi "^6.2.0" +long@*, long@^5.2.1: + version "5.2.3" + resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1" + integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q== + long@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== -long@^5.2.1: - version "5.2.3" - resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1" - integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q== - lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" @@ -5326,10 +5333,10 @@ typeforce@^1.11.5: resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc" integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g== -typescript@^4.1.3: - version "4.9.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" - integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== +typescript@^5.1.6: + version "5.3.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" + integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== typescript@~4.4: version "4.4.4"