Skip to content

Commit

Permalink
Merge pull request #274 from oraichain/feat/smart-router-osmosis-pool
Browse files Browse the repository at this point in the history
Pumb version 1.0.88 universal swap
  • Loading branch information
haunv3 authored May 28, 2024
2 parents 0edb7d2 + 403a83c commit a144f7b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 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.87",
"version": "1.0.88",
"main": "build/index.js",
"files": [
"build/"
Expand Down
23 changes: 11 additions & 12 deletions packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,29 +682,28 @@ export class UniversalSwapHelper {
console.log("amount, display amount: ", { amount, displayAmount });
return { amount, displayAmount };
}
const fromInfo = getTokenOnOraichain(query.originalFromInfo.coinGeckoId);
const toInfo = getTokenOnOraichain(query.originalToInfo.coinGeckoId);
if (!fromInfo || !toInfo)
throw new Error(
`Cannot find token on Oraichain for token ${query.originalFromInfo.coinGeckoId} and ${query.originalToInfo.coinGeckoId}`
);

let amount;
let routes = [];
let routeSwapOps;
if (query?.routerOption?.useSmartRoute || query?.routerOption?.useAlphaSmartRoute) {
const fromTokenInfo = query.routerOption.useAlphaSmartRoute ? query.originalFromInfo : fromInfo;
const toTokenInfo = query.routerOption.useAlphaSmartRoute ? query.originalToInfo : toInfo;
const simulateRes: SmartRouterResponse = await UniversalSwapHelper.simulateSwapUsingSmartRoute({
fromInfo: fromTokenInfo,
toInfo: toTokenInfo,
amount: toAmount(query.originalAmount, fromInfo.decimals).toString(),
fromInfo: query.originalFromInfo,
toInfo: query.originalToInfo,
amount: toAmount(query.originalAmount, query.originalFromInfo.decimals).toString(),
urlRouter: query.urlRouter,
useAlphaSmartRoute: query?.routerOption?.useAlphaSmartRoute
});
routes = simulateRes?.routesSwap;
amount = simulateRes.returnAmount;
routeSwapOps = simulateRes?.routes;
} else {
const fromInfo = getTokenOnOraichain(query.originalFromInfo.coinGeckoId);
const toInfo = getTokenOnOraichain(query.originalToInfo.coinGeckoId);
if (!fromInfo || !toInfo)
throw new Error(
`Cannot find token on Oraichain for token ${query.originalFromInfo.coinGeckoId} and ${query.originalToInfo.coinGeckoId}`
);
amount = (
await UniversalSwapHelper.simulateSwap({
fromInfo,
Expand All @@ -716,7 +715,7 @@ export class UniversalSwapHelper {
}
return {
amount,
displayAmount: toDisplay(amount, getTokenOnOraichain(toInfo.coinGeckoId)?.decimals),
displayAmount: toDisplay(amount, getTokenOnOraichain(query.originalToInfo.coinGeckoId)?.decimals),
routes,
routeSwapOps
};
Expand Down
52 changes: 24 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3485,6 +3485,27 @@
resolved "https://registry.yarnpkg.com/@oraichain/immutable/-/immutable-4.3.9.tgz#ff8d5a7b39b5b01f3f72a902cffbfea32ccb20c3"
integrity sha512-INpHnhL970OCkR7I71Kssb2aLl2l4Y/x8W6FlyRO0KmC8GHjxc/hlNB1t44BiI7lkOYmcWMRQoC8dwParsp1RQ==

"@oraichain/oraidex-common@latest":
version "1.0.88"
resolved "https://registry.yarnpkg.com/@oraichain/oraidex-common/-/oraidex-common-1.0.88.tgz#74f01707400a09431e75efbfe9a8f7d7fedd6f80"
integrity sha512-G50ZpAc9w73r4hUnRchv051nEBjP/wv30/cVTMK1r8uUuiojrbzoiVGntXEAQeTdVrctxM6eCYlcUI+7ecDtYg==
dependencies:
"@cosmjs/amino" "0.31.3"
"@cosmjs/cosmwasm-stargate" "0.31.3"
"@cosmjs/crypto" "0.31.3"
"@cosmjs/proto-signing" "0.31.3"
"@cosmjs/stargate" "0.31.3"
"@cosmjs/tendermint-rpc" "0.31.3"
"@ethersproject/providers" "^5.0.10"
"@injectivelabs/sdk-ts" "1.12.1"
"@keplr-wallet/types" "^0.11.38"
"@oraichain/oraidex-contracts-sdk" latest
axios "0.26.1"
axios-extensions "3.1.3"
bignumber.js "^9.1.2"
cosmjs-types "0.8.0"
ethers "^5.0.15"

"@oraichain/oraidex-contracts-sdk@latest":
version "1.0.44"
resolved "https://registry.yarnpkg.com/@oraichain/oraidex-contracts-sdk/-/oraidex-contracts-sdk-1.0.44.tgz#9ff41ec388dd92ba112c2eef545d11fd6e18c684"
Expand Down Expand Up @@ -15308,16 +15329,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -15382,14 +15394,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -16678,7 +16683,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -16696,15 +16701,6 @@ wrap-ansi@^6.0.1:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit a144f7b

Please sign in to comment.