Skip to content

Commit

Permalink
fix response func handleSimulateSwap
Browse files Browse the repository at this point in the history
  • Loading branch information
haunv3 committed Apr 25, 2024
1 parent 1c2de82 commit e394946
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 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.73",
"version": "1.0.74",
"main": "build/index.js",
"files": [
"build/"
Expand Down
40 changes: 23 additions & 17 deletions packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,25 +653,31 @@ export class UniversalSwapHelper {
throw new Error(
`Cannot find token on Oraichain for token ${query.originalFromInfo.coinGeckoId} and ${query.originalToInfo.coinGeckoId}`
);
const amount = query.useSmartRoute
? (
await UniversalSwapHelper.simulateSwapUsingSmartRoute({
fromInfo,
toInfo,
amount: toAmount(query.originalAmount, fromInfo.decimals).toString()
})
).returnAmount
: (
await UniversalSwapHelper.simulateSwap({
fromInfo,
toInfo,
amount: toAmount(query.originalAmount, fromInfo.decimals).toString(),
routerClient: query.routerClient
})
).amount;
let amount;
let routes = [];
if (query.useSmartRoute) {
const { returnAmount, routes: routesSwap }: SmartRouterResponse =
await UniversalSwapHelper.simulateSwapUsingSmartRoute({
fromInfo,
toInfo,
amount: toAmount(query.originalAmount, fromInfo.decimals).toString()
});
routes = routesSwap;
amount = returnAmount;
} else {
amount = (
await UniversalSwapHelper.simulateSwap({
fromInfo,
toInfo,
amount: toAmount(query.originalAmount, fromInfo.decimals).toString(),
routerClient: query.routerClient
})
).amount;
}
return {
amount,
displayAmount: toDisplay(amount, getTokenOnOraichain(toInfo.coinGeckoId)?.decimals)
displayAmount: toDisplay(amount, getTokenOnOraichain(toInfo.coinGeckoId)?.decimals),
routes
};
};

Expand Down
1 change: 1 addition & 0 deletions packages/universal-swap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum SwapDirection {
export interface SimulateResponse {
amount: Uint128;
displayAmount: number;
routes?: SmartRouteSwapOperations[];
}

export interface SwapData {
Expand Down

0 comments on commit e394946

Please sign in to comment.