Skip to content

Commit

Permalink
Merge pull request #251 from oraichain/feat/smart-router
Browse files Browse the repository at this point in the history
Feat/smart router
  • Loading branch information
haunv3 authored Apr 26, 2024
2 parents da3b68d + 0ec2032 commit 06345d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/universal-swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-universal-swap",
"version": "1.0.74",
"version": "1.0.75",
"main": "build/index.js",
"files": [
"build/"
Expand Down
18 changes: 9 additions & 9 deletions packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,15 @@ export class UniversalSwapHelper {
askChainId: string,
offerAmount: string
): Promise<SmartRouterResponse> => {
const { returnAmount, routes } = await UniversalSwapHelper.querySmartRoute(
const { returnAmount, routes: routesSwap } = await UniversalSwapHelper.querySmartRoute(
offerInfo,
offerChainId,
askInfo,
askChainId,
offerAmount
);

const routesSwap = routes.map((route) => {
const routes = routesSwap.map((route) => {
let ops = [];
let currTokenIn = offerInfo;
for (let path of route.paths) {
Expand All @@ -503,7 +503,8 @@ export class UniversalSwapHelper {
return {
swapAmount: offerAmount,
returnAmount,
routes: routesSwap
routes,
routesSwap
};
};

Expand Down Expand Up @@ -656,12 +657,11 @@ export class UniversalSwapHelper {
let amount;
let routes = [];
if (query.useSmartRoute) {
const { returnAmount, routes: routesSwap }: SmartRouterResponse =
await UniversalSwapHelper.simulateSwapUsingSmartRoute({
fromInfo,
toInfo,
amount: toAmount(query.originalAmount, fromInfo.decimals).toString()
});
const { returnAmount, routesSwap }: SmartRouterResponse = await UniversalSwapHelper.simulateSwapUsingSmartRoute({
fromInfo,
toInfo,
amount: toAmount(query.originalAmount, fromInfo.decimals).toString()
});
routes = routesSwap;
amount = returnAmount;
} else {
Expand Down
21 changes: 12 additions & 9 deletions packages/universal-swap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum SwapDirection {
export interface SimulateResponse {
amount: Uint128;
displayAmount: number;
routes?: SmartRouteSwapOperations[];
routes?: SmartRouteSwapAPIOperations[];
}

export interface SwapData {
Expand Down Expand Up @@ -116,19 +116,22 @@ export type SmartRouterResponse = {
swapAmount: string;
returnAmount: string;
routes: SmartRouteSwapOperations[];
routesSwap?: SmartRouteSwapAPIOperations[];
};

export type SmartRouterResponseAPI = {
export type SmartRouteSwapAPIOperations = {
swapAmount: string;
returnAmount: string;
routes: {
swapAmount: string;
returnAmount: string;
paths: {
poolId: string;
tokenOut: string;
}[];
paths: {
poolId: string;
tokenOut: string;
}[];
};

export type SmartRouterResponseAPI = {
swapAmount: string;
returnAmount: string;
routes: SmartRouteSwapAPIOperations[];
};

export type ConvertType = Convert | ConvertReverse;

0 comments on commit 06345d8

Please sign in to comment.