Skip to content

Commit

Permalink
Merge pull request #331 from oraichain/feat/zapper-2
Browse files Browse the repository at this point in the history
Feat/zapper 2
  • Loading branch information
vuonghuuhung authored Sep 18, 2024
2 parents 98774d1 + 78f7a1b commit 87032d5
Show file tree
Hide file tree
Showing 27 changed files with 1,743 additions and 155 deletions.
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/[email protected]
# 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/[email protected].
* 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: {};
};
export interface MigrateMsg {}
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

0 comments on commit 87032d5

Please sign in to comment.