Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NTRN-163] add dex stargate tests #251

Merged
merged 8 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"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",
"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",
Expand All @@ -31,6 +31,8 @@
"test:tge:investors_vesting_vault": "jest -b src/testcases/parallel/tge.investors_vesting_vault",
"test:voting_registry": "jest -b src/testcases/parallel/voting_registry",
"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",
"gen:proto": "bash ./gen-proto.sh",
"lint": "eslint ./src",
"fmt": "eslint ./src --fix"
},
Expand All @@ -41,7 +43,7 @@
"@cosmos-client/core": "^0.47.4",
"@cosmos-client/cosmwasm": "^0.40.3",
"@cosmos-client/ibc": "^1.2.1",
"@neutron-org/neutronjsplus": "0.1.0",
"@neutron-org/neutronjsplus": "^0.2.0",
"@types/lodash": "^4.14.182",
"@types/long": "^4.0.2",
"axios": "^0.27.2",
Expand All @@ -50,8 +52,8 @@
"date-fns": "^2.16.1",
"express": "^4.18.2",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"jest-extended": "^4.0.2",
"jest-junit": "^16.0.0",
"lodash": "^4.17.21",
"long": "^5.2.1",
"merkletreejs": "^0.3.9",
Expand Down Expand Up @@ -87,4 +89,4 @@
"engines": {
"node": ">=16.0 <17"
}
}
}
182 changes: 182 additions & 0 deletions src/helpers/dex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
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<Int64>
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<Int64>
};

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<Uint64>
};

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;
};
Loading