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

Feat/zapper 2 #331

Merged
merged 67 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
342e78c
done basic zap in zap out
vuonghuuhung Aug 29, 2024
85dfe38
Merge branch 'main' into feat/zap-consumer
vuonghuuhung Aug 29, 2024
a3410b6
remove unused code
vuonghuuhung Aug 30, 2024
c68db19
remove unused code
vuonghuuhung Aug 30, 2024
fe3cdb7
Merge branch 'main' into feat/zap-consumer
vuonghuuhung Aug 30, 2024
1fe8372
test beta version
vuonghuuhung Aug 30, 2024
56299f3
pump beta
vuonghuuhung Aug 30, 2024
02bcbee
pump beta: fix logic zap in
vuonghuuhung Aug 31, 2024
f331f44
add beta zap with contract
vuonghuuhung Sep 9, 2024
5091880
fix bug build
vuonghuuhung Sep 9, 2024
85f3045
fix: yarn.lock
vuonghuuhung Sep 9, 2024
e2a2b2e
fix: workflow
vuonghuuhung Sep 9, 2024
aaf67b1
fix: init null variable
vuonghuuhung Sep 9, 2024
acb3c9b
fix: init null variable
vuonghuuhung Sep 9, 2024
c634d10
fix: add config to smart route
vuonghuuhung Sep 9, 2024
31b2306
fix: zap out null value
vuonghuuhung Sep 9, 2024
c693a52
add return amount simulate
vuonghuuhung Sep 9, 2024
bcb2d05
new zap engine
vuonghuuhung Sep 12, 2024
68d1e1a
fix build zapper
vuonghuuhung Sep 12, 2024
dfbcde6
done test flow zap in
vuonghuuhung Sep 12, 2024
f38d717
fix null value
vuonghuuhung Sep 12, 2024
5882001
fix min liquidity
vuonghuuhung Sep 12, 2024
197d6af
fix min liquidity
vuonghuuhung Sep 12, 2024
2494759
add price impact
vuonghuuhung Sep 13, 2024
cf902d3
add fns to handler
vuonghuuhung Sep 13, 2024
db0a16e
revert old version
vuonghuuhung Sep 13, 2024
9421414
revert old version
vuonghuuhung Sep 13, 2024
e9a483a
merge main
vuonghuuhung Sep 13, 2024
450c8e5
change workflows
vuonghuuhung Sep 13, 2024
6949d28
change workflows
vuonghuuhung Sep 13, 2024
dc6ad07
pump sdk
vuonghuuhung Sep 13, 2024
8e134db
add time calculation
vuonghuuhung Sep 16, 2024
7b93d0a
add time calculation
vuonghuuhung Sep 16, 2024
a1180c4
add try catch to zap in
vuonghuuhung Sep 16, 2024
62e2544
pump
vuonghuuhung Sep 16, 2024
537d17c
optimize with promise all
vuonghuuhung Sep 16, 2024
884a589
fix: gen route msg
vuonghuuhung Sep 16, 2024
43d05c3
fix: gen route msg
vuonghuuhung Sep 16, 2024
5a6eda5
update packages version
vuonghuuhung Sep 17, 2024
0f333ea
rm yarn lock
vuonghuuhung Sep 17, 2024
84be2d8
rm yarn lock
vuonghuuhung Sep 17, 2024
68af563
rm yarn lock
vuonghuuhung Sep 17, 2024
e61170b
test zap-out
vuonghuuhung Sep 17, 2024
6b9eca2
pump test zap out
vuonghuuhung Sep 17, 2024
4c074d5
pump test zap out
vuonghuuhung Sep 17, 2024
a1f92e2
pump test zap out
vuonghuuhung Sep 17, 2024
677c539
pump test zap out
vuonghuuhung Sep 17, 2024
9f8e476
pump test zap out
vuonghuuhung Sep 17, 2024
d435cb0
fix min liquidity
vuonghuuhung Sep 17, 2024
ad9674d
refactor
vuonghuuhung Sep 18, 2024
83f0435
refactor
vuonghuuhung Sep 18, 2024
a2ce6fd
refactor
vuonghuuhung Sep 18, 2024
b7e26be
refactor
vuonghuuhung Sep 18, 2024
cf19d58
refactor
vuonghuuhung Sep 18, 2024
bb5a66e
fix type liquidity tick
vuonghuuhung Sep 18, 2024
4339361
remove yarn
vuonghuuhung Sep 18, 2024
07aba3a
fix type liquidity tick
vuonghuuhung Sep 18, 2024
b041c5f
fix type liquidity tick
vuonghuuhung Sep 18, 2024
f626938
fix type liquidity tick
vuonghuuhung Sep 18, 2024
06f9e17
test
vuonghuuhung Sep 18, 2024
38ddddc
fix: update name workflow
vuonghuuhung Sep 18, 2024
f876dd5
fix: update yarn lock
vuonghuuhung Sep 18, 2024
8eb7267
chore: update yarn lock
vuonghuuhung Sep 18, 2024
26af1bb
chore: yarn install
trungbach Sep 18, 2024
e2803b4
chore: type
trungbach Sep 18, 2024
4b10b58
ci: update workflow
trungbach Sep 18, 2024
78f7a1b
chore: add zap contract to common
vuonghuuhung Sep 18, 2024
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
67 changes: 67 additions & 0 deletions .github/workflows/publish_oraiswap_v3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# name: publish_package_oraiswap_v3

# # Controls when the action will run.
# on:
# # Triggers the workflow on push or pull request events but only for the main branch
# push:
# branches: [feat/zapper-2]

# # Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:

# # A workflow run is made up of one or more jobs that can run sequentially or in parallel
# jobs:
# build:
# runs-on: ubuntu-20.04
# strategy:
# matrix:
# node-version: ["18"]
# steps:
# - name: Cancel Previous Runs
# uses: styfle/cancel-workflow-action@0.8.0
# with:
# access_token: ${{ github.token }}
# - uses: actions/checkout@v2
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v2
# with:
# node-version: ${{ matrix.node-version }}
# - name: Get yarn cache directory path
# id: yarn-cache-dir-path
# run: echo "::set-output name=dir::$(yarn cache dir)"
# - uses: actions/cache@v4
# id: yarn-cache
# with:
# path: |
# ${{ steps.yarn-cache-dir-path.outputs.dir }}
# ./node_modules/
# key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-yarn-
# - name: Install Dependencies
# run: yarn
# - name: Build
# run: yarn build
# - name: Authenticate with private NPM package
# run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
# - name: Publish Oraiswap v3
# id: publish-oraiswap-v3
# continue-on-error: true
# run: yarn deploy:beta packages/oraiswap-v3
# env:
# CI: false
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# - name: Publish Contract SDK
# id: publish-oraidex-contracts-sdk
# continue-on-error: true
# run: yarn deploy:beta packages/contracts-sdk
# env:
# CI: false
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# - name: Publish Contract Build
# id: publish-oraidex-contracts-build
# continue-on-error: true
# run: yarn deploy:beta packages/contracts-build
# env:
# CI: false
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ cache/
packages/contract-state-simulate/public/
coverage

.nx/cache
.nx/cache
.nx/workspace-data

.yarn
5 changes: 5 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


yarn-path ".yarn/releases/yarn-1.22.22.cjs"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"husky": "^9.0.11",
"jest": "^29.7.0",
"lerna": "^8.1.2",
"nx": "18.1.2",
"nx": "19.7.3",
"patch-package": "^8.0.0",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
Expand Down
Binary file added packages/contracts-build/data/zapper.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/contracts-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-contracts-build",
"version": "1.0.36",
"version": "1.0.37",
"main": "build/index.js",
"license": "MIT",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts-build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type ContractName =
| "oraiswap-router"
| "oraiswap-staking"
| "oraidex-listing-contract"
| "oraiswap-v3";
| "oraiswap-v3"
| "zapper";

const contractDir = path.join(__dirname, "..", "data");

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-contracts-sdk",
"version": "1.0.51",
"version": "1.0.52",
"main": "build/index.js",
"files": [
"build/",
Expand Down
166 changes: 166 additions & 0 deletions packages/contracts-sdk/src/Zapper.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* This file was automatically generated by @oraichain/ts-codegen@0.35.9.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @oraichain/ts-codegen generate command to regenerate this file.
*/

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import {Addr, InstantiateMsg, ExecuteMsg, Uint128, AssetInfo, Liquidity, Percentage, SwapOperation, AssetInfo2, Decimal, Asset, PoolKey, FeeTier, Route, QueryMsg, MigrateMsg, Config, ProtocolFee} from "./Zapper.types";
export interface ZapperReadOnlyInterface {
contractAddress: string;
config: () => Promise<Config>;
protocolFee: () => Promise<ProtocolFee>;
}
export class ZapperQueryClient implements ZapperReadOnlyInterface {
client: CosmWasmClient;
contractAddress: string;

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
this.config = this.config.bind(this);
this.protocolFee = this.protocolFee.bind(this);
}

config = async (): Promise<Config> => {
return this.client.queryContractSmart(this.contractAddress, {
config: {}
});
};
protocolFee = async (): Promise<ProtocolFee> => {
return this.client.queryContractSmart(this.contractAddress, {
protocol_fee: {}
});
};
}
export interface ZapperInterface extends ZapperReadOnlyInterface {
contractAddress: string;
sender: string;
updateConfig: ({
admin,
dexV3,
mixedRouter
}: {
admin?: Addr;
dexV3?: Addr;
mixedRouter?: Addr;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
zapInLiquidity: ({
assetIn,
minimumLiquidity,
poolKey,
routes,
tickLowerIndex,
tickUpperIndex
}: {
assetIn: Asset;
minimumLiquidity?: Liquidity;
poolKey: PoolKey;
routes: Route[];
tickLowerIndex: number;
tickUpperIndex: number;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
zapOutLiquidity: ({
positionIndex,
routes
}: {
positionIndex: number;
routes: Route[];
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
registerProtocolFee: ({
feeReceiver,
percent
}: {
feeReceiver: Addr;
percent: Decimal;
}, _fee?: number | StdFee | "auto", _memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}
export class ZapperClient extends ZapperQueryClient implements ZapperInterface {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;

constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
super(client, contractAddress);
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
this.updateConfig = this.updateConfig.bind(this);
this.zapInLiquidity = this.zapInLiquidity.bind(this);
this.zapOutLiquidity = this.zapOutLiquidity.bind(this);
this.registerProtocolFee = this.registerProtocolFee.bind(this);
}

updateConfig = async ({
admin,
dexV3,
mixedRouter
}: {
admin?: Addr;
dexV3?: Addr;
mixedRouter?: Addr;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_config: {
admin,
dex_v3: dexV3,
mixed_router: mixedRouter
}
}, _fee, _memo, _funds);
};
zapInLiquidity = async ({
assetIn,
minimumLiquidity,
poolKey,
routes,
tickLowerIndex,
tickUpperIndex
}: {
assetIn: Asset;
minimumLiquidity?: Liquidity;
poolKey: PoolKey;
routes: Route[];
tickLowerIndex: number;
tickUpperIndex: number;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
zap_in_liquidity: {
asset_in: assetIn,
minimum_liquidity: minimumLiquidity,
pool_key: poolKey,
routes,
tick_lower_index: tickLowerIndex,
tick_upper_index: tickUpperIndex
}
}, _fee, _memo, _funds);
};
zapOutLiquidity = async ({
positionIndex,
routes
}: {
positionIndex: number;
routes: Route[];
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
zap_out_liquidity: {
position_index: positionIndex,
routes
}
}, _fee, _memo, _funds);
};
registerProtocolFee = async ({
feeReceiver,
percent
}: {
feeReceiver: Addr;
percent: Decimal;
}, _fee: number | StdFee | "auto" = "auto", _memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
register_protocol_fee: {
fee_receiver: feeReceiver,
percent
}
}, _fee, _memo, _funds);
};
}
99 changes: 99 additions & 0 deletions packages/contracts-sdk/src/Zapper.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
export type Addr = string;
export interface InstantiateMsg {
admin: Addr;
dex_v3: Addr;
mixed_router: Addr;
}
export type ExecuteMsg = {
update_config: {
admin?: Addr | null;
dex_v3?: Addr | null;
mixed_router?: Addr | null;
};
} | {
zap_in_liquidity: {
asset_in: Asset;
minimum_liquidity?: Liquidity | null;
pool_key: PoolKey;
routes: Route[];
tick_lower_index: number;
tick_upper_index: number;
};
} | {
zap_out_liquidity: {
position_index: number;
routes: Route[];
};
} | {
register_protocol_fee: {
fee_receiver: Addr;
percent: Decimal;
};
};
export type Uint128 = string;
export type AssetInfo = {
token: {
contract_addr: Addr;
};
} | {
native_token: {
denom: string;
};
};
export type Liquidity = string;
export type Percentage = number;
export type SwapOperation = {
orai_swap: {
ask_asset_info: AssetInfo2;
offer_asset_info: AssetInfo2;
};
} | {
swap_v3: {
pool_key: PoolKey;
x_to_y: boolean;
};
};
export type AssetInfo2 = {
token: {
contract_addr: Addr;
};
} | {
native_token: {
denom: string;
};
};
export type Decimal = string;
export interface Asset {
amount: Uint128;
info: AssetInfo;
}
export interface PoolKey {
fee_tier: FeeTier;
token_x: string;
token_y: string;
}
export interface FeeTier {
fee: Percentage;
tick_spacing: number;
}
export interface Route {
minimum_receive?: Uint128 | null;
offer_amount: Uint128;
operations: SwapOperation[];
token_in: string;
}
export type QueryMsg = {
config: {};
} | {
protocol_fee: {};
};
Comment on lines +85 to +89
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the type definition to explicitly define the shape of the query messages.

Using {} as a type is not recommended because it means "any non-nullable value" and does not provide type safety. Consider updating the type definition to explicitly define the shape of the query messages.

For example:

-export type QueryMsg = {
-  config: {};
-} | {
-  protocol_fee: {};
-};
+export type QueryMsg = {
+  config: {
+    // Define the shape of the config query message
+  };
+} | {
+  protocol_fee: {
+    // Define the shape of the protocol_fee query message
+  };
+};

Committable suggestion was skipped due to low confidence.

Tools
Biome

[error] 86-86: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 88-88: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

export interface MigrateMsg {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a type alias instead of an empty interface.

An empty interface is equivalent to {}, which means "any non-nullable value" and does not provide type safety. Consider using a type alias instead.

For example:

-export interface MigrateMsg {}
+export type MigrateMsg = Record<string, never>;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export interface MigrateMsg {}
export type MigrateMsg = Record<string, never>;
Tools
Biome

[error] 90-90: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

export interface Config {
admin: Addr;
dex_v3: Addr;
mixed_router: Addr;
}
export interface ProtocolFee {
fee_receiver: Addr;
percent: Decimal;
}
2 changes: 2 additions & 0 deletions packages/contracts-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ export * as OraiswapV3Types from "./OraiswapV3.types";
export * from "./OraiswapV3.client";
export * as OraiswapMixedRouterTypes from "./OraiswapMixedRouter.types";
export * from "./OraiswapMixedRouter.client";
export * as ZapperTypes from "./Zapper.types";
export * from "./Zapper.client";
export * from "./types";
Loading
Loading