Skip to content

Commit

Permalink
done test flow zap in
Browse files Browse the repository at this point in the history
  • Loading branch information
vuonghuuhung committed Sep 12, 2024
1 parent 68d1e1a commit dfbcde6
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 76 deletions.
2 changes: 1 addition & 1 deletion packages/oraiswap-v3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraiswap-v3",
"version": "0.1.6-beta.10",
"version": "0.1.6-beta.11",
"main": "build/index.js",
"files": [
"build/"
Expand Down
2 changes: 1 addition & 1 deletion packages/oraiswap-v3/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RouteNotFoundError extends Error {
export class RouteNotFoundError extends Error {
constructor(route: string) {
super(`Route not found: ${route}`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/oraiswap-v3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./types";
export * from "./helpers";
export * from "./handler";
export * from "./zap-consumer";
export * from "./error";
export * from "./wasm/oraiswap_v3_wasm";
45 changes: 28 additions & 17 deletions packages/oraiswap-v3/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ async function main() {
];
const tokenIn = oraichainTokens.find((t) => extractAddress(t) === USDT_CONTRACT);

// const zapper = new ZapConsumer({
// routerApi: "https://osor.oraidex.io/smart-router/alpha-router",
// client: await CosmWasmClient.connect("https://rpc.orai.io"),
// dexV3Address: AMM_V3_CONTRACT,
// multicallAddress: MULTICALL_CONTRACT,
// devitation: 0.05,
// smartRouteConfig: {
// swapOptions: {
// protocols: ["OraidexV3"],
// maxSplits: 1
// }
// }
// });
const zapper = new ZapConsumer({
routerApi: "https://osor.oraidex.io/smart-router/alpha-router",
client: await CosmWasmClient.connect("https://rpc.orai.io"),
dexV3Address: AMM_V3_CONTRACT,
multicallAddress: MULTICALL_CONTRACT,
devitation: 0.05,
smartRouteConfig: {
swapOptions: {
protocols: ["OraidexV3"],
maxSplits: 1
}
},
});

// const handler = zapper.handler;

Expand All @@ -58,14 +58,25 @@ async function main() {

// const liquidityTick = await zapper.getAllLiquidityTicks(parsePoolKey(poolList[0]), tickMap2);
// console.log({ liquidityTick });
const tickSpacing = parsePoolKey(poolList[0]).fee_tier.tick_spacing;
const currentTick = (await zapper.handler.getPool(parsePoolKey(poolList[0]))).pool.current_tick_index;

// const res = await zapper.processZapOutPositionLiquidity({
// owner: "orai1hvr9d72r5um9lvt0rpkd4r75vrsqtw6yujhqs2",
// tokenId: 1858,
// tokenOut: tokenIn as TokenItemType
// const res = await zapper.processZapInPositionLiquidity({
// poolKey: parsePoolKey(poolList[0]),
// tokenIn: tokenIn as TokenItemType,
// amountIn: "10000000",
// lowerTick: currentTick - tickSpacing * 3,
// upperTick: currentTick - tickSpacing * 1
// });
// console.log({ res });

const res = await zapper.processZapOutPositionLiquidity({
owner: "orai1hvr9d72r5um9lvt0rpkd4r75vrsqtw6yujhqs2",
tokenId: 1902,
tokenOut: tokenIn as TokenItemType
});
console.log({ res });

// for (const poolKey of poolList) {
// const poolKeyParsed = parsePoolKey(poolKey);
// const pool = await handler.getPool(poolKeyParsed);
Expand Down
9 changes: 6 additions & 3 deletions packages/oraiswap-v3/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export type ZapConfig = {
client: CosmWasmClient;
dexV3Address: string;
multicallAddress: string;
zapper: string;
devitation: number;
smartRouteConfig: SmartRouteConfig;
};
Expand Down Expand Up @@ -262,7 +261,6 @@ export type ZapInLiquidityResponse = {
currentTick: number;

swapFee: number;
zapFee: bigint;
result: ZapInResult;
};

Expand All @@ -272,6 +270,8 @@ export type ZapOutLiquidityResponse = {
operationFromX?: SwapOperation[];
operationFromY?: SwapOperation[];
positionIndex: number;
routes: Route[];
swapFee: number;
amountToX: bigint;
amountToY: bigint;
zapOutResult: ZapOutResult;
Expand All @@ -297,5 +297,8 @@ export enum ZapInResult {
export enum ZapOutResult {
// Error
NoRouteFound = "No route found to zap",
SomethingWentWrong = "Something went wrong"
SomethingWentWrong = "Something went wrong",

// Success
Success = "Zap out successfully"
}
Loading

0 comments on commit dfbcde6

Please sign in to comment.