Skip to content

Commit

Permalink
Merge pull request #179 from oraichain/fix/orderbook-dex-pair-types
Browse files Browse the repository at this point in the history
fix: latest oraidex pair & orderbook reward receiver logic
  • Loading branch information
ducphamle2 authored Feb 23, 2024
2 parents 9b23bf3 + dc26e4b commit daa0856
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"scripts": {
"postinstall": "patch-package",
"test": "jest",
"test": "yarn build && jest",
"docs": "typedoc --entryPointStrategy expand --name 'Oraidex SDK' --readme none --tsconfig packages/contracts-sdk/tsconfig.json packages/contracts-sdk/src",
"clean": "lerna clean --yes && lerna exec -- rimraf build/ dist/ cache/",
"build": "lerna run build --concurrency 1",
Expand Down
Binary file modified packages/contracts-build/data/oraiswap_factory.wasm
Binary file not shown.
Binary file modified packages/contracts-build/data/oraiswap_limit_order.wasm
Binary file not shown.
Binary file modified packages/contracts-build/data/oraiswap_oracle.wasm
Binary file not shown.
Binary file modified packages/contracts-build/data/oraiswap_pair.wasm
Binary file not shown.
Binary file modified packages/contracts-build/data/oraiswap_router.wasm
Binary file not shown.
Binary file modified packages/contracts-build/data/oraiswap_staking.wasm
Binary file not shown.
19 changes: 18 additions & 1 deletion packages/contracts-sdk/src/OraiswapLimitOrder.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import {Addr, Uint128, Binary, AssetInfo, Decimal, Cw20ReceiveMsg, Asset} from "./types";
import {Uint128, Binary, Addr, AssetInfo, Decimal, Cw20ReceiveMsg, Asset} from "./types";
import {InstantiateMsg, ExecuteMsg, OrderDirection, QueryMsg, OrderFilter, MigrateMsg, ContractInfoResponse, LastOrderIdResponse, OrderStatus, OrderResponse, OrderBookResponse, OrderBookMatchableResponse, OrderBooksResponse, OrdersResponse, BaseAmountResponse, TickResponse, TicksResponse} from "./OraiswapLimitOrder.types";
export interface OraiswapLimitOrderReadOnlyInterface {
contractAddress: string;
Expand Down Expand Up @@ -302,6 +302,11 @@ export interface OraiswapLimitOrderInterface extends OraiswapLimitOrderReadOnlyI
commissionRate?: string;
rewardAddress?: Addr;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
updateOperator: ({
operator
}: {
operator?: string;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
createOrderBookPair: ({
baseCoinInfo,
minQuoteCoinAmount,
Expand Down Expand Up @@ -380,6 +385,7 @@ export class OraiswapLimitOrderClient extends OraiswapLimitOrderQueryClient impl
this.receive = this.receive.bind(this);
this.updateAdmin = this.updateAdmin.bind(this);
this.updateConfig = this.updateConfig.bind(this);
this.updateOperator = this.updateOperator.bind(this);
this.createOrderBookPair = this.createOrderBookPair.bind(this);
this.updateOrderbookPair = this.updateOrderbookPair.bind(this);
this.submitOrder = this.submitOrder.bind(this);
Expand Down Expand Up @@ -432,6 +438,17 @@ export class OraiswapLimitOrderClient extends OraiswapLimitOrderQueryClient impl
}
}, _fee, _memo, _funds);
};
updateOperator = async ({
operator
}: {
operator?: string;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_operator: {
operator
}
}, _fee, _memo, _funds);
};
createOrderBookPair = async ({
baseCoinInfo,
minQuoteCoinAmount,
Expand Down
12 changes: 9 additions & 3 deletions packages/contracts-sdk/src/OraiswapLimitOrder.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Addr, Uint128, Binary, AssetInfo, Decimal, Cw20ReceiveMsg, Asset} from "./types";
import {Uint128, Binary, Addr, AssetInfo, Decimal, Cw20ReceiveMsg, Asset} from "./types";
export interface InstantiateMsg {
admin?: Addr | null;
admin?: string | null;
commission_rate?: string | null;
name?: string | null;
reward_address?: Addr | null;
operator?: string | null;
reward_address: string;
version?: string | null;
}
export type ExecuteMsg = {
Expand All @@ -17,6 +18,10 @@ export type ExecuteMsg = {
commission_rate?: string | null;
reward_address?: Addr | null;
};
} | {
update_operator: {
operator?: string | null;
};
} | {
create_order_book_pair: {
base_coin_info: AssetInfo;
Expand Down Expand Up @@ -132,6 +137,7 @@ export interface ContractInfoResponse {
admin: Addr;
commission_rate: string;
name: string;
operator?: Addr | null;
reward_address: Addr;
version: string;
}
Expand Down
79 changes: 77 additions & 2 deletions packages/contracts-sdk/src/OraiswapPair.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import {AssetInfo, Addr, Uint128, Binary, Decimal, Cw20ReceiveMsg, Asset, PairInfo} from "./types";
import {InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg, PairResponse, PoolResponse, ReverseSimulationResponse, SimulationResponse} from "./OraiswapPair.types";
import {Addr, AssetInfo, Uint128, Binary, Decimal, Cw20ReceiveMsg, Asset, PairInfo} from "./types";
import {InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg, String, PairResponse, PoolResponse, ReverseSimulationResponse, SimulationResponse, Boolean} from "./OraiswapPair.types";
export interface OraiswapPairReadOnlyInterface {
contractAddress: string;
pair: () => Promise<PairResponse>;
Expand All @@ -22,6 +22,12 @@ export interface OraiswapPairReadOnlyInterface {
}: {
askAsset: Asset;
}) => Promise<ReverseSimulationResponse>;
traderIsWhitelisted: ({
trader
}: {
trader: Addr;
}) => Promise<Boolean>;
admin: () => Promise<String>;
}
export class OraiswapPairQueryClient implements OraiswapPairReadOnlyInterface {
client: CosmWasmClient;
Expand All @@ -34,6 +40,8 @@ export class OraiswapPairQueryClient implements OraiswapPairReadOnlyInterface {
this.pool = this.pool.bind(this);
this.simulation = this.simulation.bind(this);
this.reverseSimulation = this.reverseSimulation.bind(this);
this.traderIsWhitelisted = this.traderIsWhitelisted.bind(this);
this.admin = this.admin.bind(this);
}

pair = async (): Promise<PairResponse> => {
Expand Down Expand Up @@ -68,6 +76,22 @@ export class OraiswapPairQueryClient implements OraiswapPairReadOnlyInterface {
}
});
};
traderIsWhitelisted = async ({
trader
}: {
trader: Addr;
}): Promise<Boolean> => {
return this.client.queryContractSmart(this.contractAddress, {
trader_is_whitelisted: {
trader
}
});
};
admin = async (): Promise<String> => {
return this.client.queryContractSmart(this.contractAddress, {
admin: {}
});
};
}
export interface OraiswapPairInterface extends OraiswapPairReadOnlyInterface {
contractAddress: string;
Expand Down Expand Up @@ -101,6 +125,21 @@ export interface OraiswapPairInterface extends OraiswapPairReadOnlyInterface {
offerAsset: Asset;
to?: Addr;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
enableWhitelist: ({
status
}: {
status: boolean;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
registerTrader: ({
traders
}: {
traders: Addr[];
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
deregisterTrader: ({
traders
}: {
traders: Addr[];
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}
export class OraiswapPairClient extends OraiswapPairQueryClient implements OraiswapPairInterface {
client: SigningCosmWasmClient;
Expand All @@ -115,6 +154,9 @@ export class OraiswapPairClient extends OraiswapPairQueryClient implements Orais
this.receive = this.receive.bind(this);
this.provideLiquidity = this.provideLiquidity.bind(this);
this.swap = this.swap.bind(this);
this.enableWhitelist = this.enableWhitelist.bind(this);
this.registerTrader = this.registerTrader.bind(this);
this.deregisterTrader = this.deregisterTrader.bind(this);
}

receive = async ({
Expand Down Expand Up @@ -171,4 +213,37 @@ export class OraiswapPairClient extends OraiswapPairQueryClient implements Orais
}
}, _fee, _memo, _funds);
};
enableWhitelist = async ({
status
}: {
status: boolean;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
enable_whitelist: {
status
}
}, _fee, _memo, _funds);
};
registerTrader = async ({
traders
}: {
traders: Addr[];
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
register_trader: {
traders
}
}, _fee, _memo, _funds);
};
deregisterTrader = async ({
traders
}: {
traders: Addr[];
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
deregister_trader: {
traders
}
}, _fee, _memo, _funds);
};
}
29 changes: 26 additions & 3 deletions packages/contracts-sdk/src/OraiswapPair.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {AssetInfo, Addr, Uint128, Binary, Decimal, Cw20ReceiveMsg, Asset, PairInfo} from "./types";
import {Addr, AssetInfo, Uint128, Binary, Decimal, Cw20ReceiveMsg, Asset, PairInfo} from "./types";
export interface InstantiateMsg {
admin?: Addr | null;
asset_infos: [AssetInfo, AssetInfo];
commission_rate?: string | null;
oracle_addr: Addr;
Expand All @@ -20,6 +21,18 @@ export type ExecuteMsg = {
offer_asset: Asset;
to?: Addr | null;
};
} | {
enable_whitelist: {
status: boolean;
};
} | {
register_trader: {
traders: Addr[];
};
} | {
deregister_trader: {
traders: Addr[];
};
};
export type QueryMsg = {
pair: {};
Expand All @@ -33,8 +46,17 @@ export type QueryMsg = {
reverse_simulation: {
ask_asset: Asset;
};
} | {
trader_is_whitelisted: {
trader: Addr;
};
} | {
admin: {};
};
export interface MigrateMsg {}
export interface MigrateMsg {
admin?: string | null;
}
export type String = string;
export interface PairResponse {
info: PairInfo;
}
Expand All @@ -51,4 +73,5 @@ export interface SimulationResponse {
commission_amount: Uint128;
return_amount: Uint128;
spread_amount: Uint128;
}
}
export type Boolean = boolean;
5 changes: 5 additions & 0 deletions packages/contracts-sdk/src/OraiswapRouter.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ export interface OraiswapRouterInterface extends OraiswapRouterReadOnlyInterface
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
executeSwapOperation: ({
operation,
sender,
to
}: {
operation: SwapOperation;
sender: Addr;
to?: Addr;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
assertMinimumReceive: ({
Expand Down Expand Up @@ -142,14 +144,17 @@ export class OraiswapRouterClient extends OraiswapRouterQueryClient implements O
};
executeSwapOperation = async ({
operation,
sender,
to
}: {
operation: SwapOperation;
sender: Addr;
to?: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
execute_swap_operation: {
operation,
sender,
to
}
}, _fee, _memo, _funds);
Expand Down
1 change: 1 addition & 0 deletions packages/contracts-sdk/src/OraiswapRouter.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ExecuteMsg = {
} | {
execute_swap_operation: {
operation: SwapOperation;
sender: Addr;
to?: Addr | null;
};
} | {
Expand Down

0 comments on commit daa0856

Please sign in to comment.