From d0585adff861fddccc08d14564ba7613ab00cf53 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 24 May 2024 13:45:45 +0700 Subject: [PATCH 1/4] update logic build msg smart router --- packages/universal-swap/package.json | 2 +- packages/universal-swap/src/handler.ts | 350 ++++++------- packages/universal-swap/src/types.ts | 29 +- .../src/universal-demos/alpha-smart-router.ts | 404 +++++++++++++++ .../src/universal-demos/apha-smart-router.ts | 459 ------------------ 5 files changed, 617 insertions(+), 627 deletions(-) create mode 100644 packages/universal-swap/src/universal-demos/alpha-smart-router.ts delete mode 100644 packages/universal-swap/src/universal-demos/apha-smart-router.ts diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index 405aa0a6..8ad99609 100644 --- a/packages/universal-swap/package.json +++ b/packages/universal-swap/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-universal-swap", - "version": "1.0.84", + "version": "1.0.85", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index e56ee3ac..80becd43 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -48,6 +48,8 @@ import { UniversalSwapHelper } from "./helper"; import { ConvertReverse, ConvertType, + Route, + Routes, SmartRouteSwapOperations, SwapAndAction, Type, @@ -298,9 +300,8 @@ export class UniversalSwapHandler { return [...msgExecuteSwap, ...msgExecuteTransfer]; } - // TODO: need refactor smart router osmosis // TODO: need check func getAddress - private getAddress = (prefix, address, coinType = 118) => { + private getAddress = (prefix: string, address: string, coinType: number = 118) => { const approve = { 118: address }; @@ -308,96 +309,133 @@ export class UniversalSwapHandler { return toBech32(prefix, data); }; - private createSwapAndAction = ({ action, path, route, receiver, userSlippage }) => { - const getPrefix = (chainId) => - cosmosChains.find((cosmos) => cosmos.chainId === chainId).bech32Config.bech32PrefixAccAddr; - const prefixRecover = getPrefix(path.chainId); - const prefixReceiver = getPrefix(path.tokenOutChainId); - - const swap_and_action: SwapAndAction = { - user_swap: {}, - min_asset: {}, - timeout_timestamp: Number(calculateTimeoutTimestamp(3600)), - post_swap_action: { - ibc_transfer: { - ibc_info: { - source_channel: action.bridgeInfo.channel, - receiver: this.getAddress(prefixReceiver, receiver), - memo: "", - recover_address: this.getAddress(prefixRecover, receiver) - } - } - }, - affiliates: [] - }; - - const pathOsmosis = route.paths.find((r) => r.chainId === "osmosis-1"); - if (pathOsmosis) { - const swapAction = pathOsmosis.actions.find((act) => act.type === "Swap"); - if (swapAction) { - const operations = swapAction.swapInfo.map((info, index) => { - const denom_in = index === 0 ? swapAction.tokenIn : swapAction.swapInfo[index - 1].tokenOut; - return { - pool: info.poolId, - denom_in, - denom_out: info.tokenOut - }; - }); - - const minimumReceive = Math.trunc( - new BigDecimal(swapAction.tokenOutAmount).mul((100 - this.swapData.userSlippage) / 100).toNumber() - ).toString(); + private getReceiverIBCHooks = (chainId: string, receiver?: string) => { + if (chainId === "osmosis-1") return OSMOSIS_ROUTER_CONTRACT; + return receiver; + }; - Object.assign(swap_and_action, { - user_swap: { - swap_exact_asset_in: { - swap_venue_name: "osmosis-poolmanager", - operations - } - }, - min_asset: { - native: { - denom: swapAction.tokenOut, - amount: minimumReceive - } - }, - slippage: userSlippage - }); - } + private getSwapAndAction(route: Routes, isOnlySwap: boolean) { + const { prefixReceiver } = this.getPrefixCosmos(route); + let post_swap_action = {}; + if (isOnlySwap) { + post_swap_action = { + transfer: { + // TODO: need check address + to_address: this.getAddress(prefixReceiver, this.swapData.sender.cosmos) + } + }; } + const operations = route.swapInfo.map((info, index) => { + const denom_in = index === 0 ? route.tokenIn : route.swapInfo[index - 1].tokenOut; + return { + pool: info.poolId, + denom_in, + denom_out: info.tokenOut + }; + }); - return { + const minimumReceive = Math.trunc( + new BigDecimal(route.tokenOutAmount).mul((100 - this.swapData.userSlippage) / 100).toNumber() + ).toString(); + + const msgActionSwap = { wasm: { - contract: this.getReceiverIBCHooks(path.chainId), + // TODO: need check address + contract: this.getReceiverIBCHooks(route.chainId), msg: { - swap_and_action + swap_and_action: { + user_swap: { + swap_exact_asset_in: { + swap_venue_name: "osmosis-poolmanager", + operations + } + }, + min_asset: { + native: { + denom: route.tokenOut, + amount: minimumReceive + } + }, + timeout_timestamp: Number(calculateTimeoutTimestamp(3600)), + post_swap_action, + affiliates: [] + } } } }; - }; + return { msgActionSwap }; + } - private createForwardObject = ({ action, path, receiver }) => { - const prefixReceiver = cosmosChains.find((cosmos) => cosmos.chainId === path.tokenOutChainId).bech32Config - .bech32PrefixAccAddr; + private getIbcTransferInfo(route: Routes) { + const { prefixRecover, prefixReceiver } = this.getPrefixCosmos(route); + const msgTransferInfo = { + ibc_transfer: { + ibc_info: { + source_channel: route.bridgeInfo.channel, + // TODO: need check address + receiver: this.getAddress(prefixReceiver, this.swapData.sender.cosmos), + memo: "", + // TODO: need check address + recover_address: this.getAddress(prefixRecover, this.swapData.sender.cosmos) + } + } + }; + return { msgTransferInfo }; + } + + private createForwardObject = (route: Routes) => { + const { prefixReceiver } = this.getPrefixCosmos(route); return { - forward: { - receiver: this.getReceiverIBCHooks(path.tokenOutChainId, this.getAddress(prefixReceiver, receiver)), - port: action.bridgeInfo.port, - channel: action.bridgeInfo.channel, - timeout: 0, - retries: 2 + msgForwardObject: { + forward: { + // TODO: need check address + receiver: this.getReceiverIBCHooks( + route.tokenOutChainId, + this.getAddress(prefixReceiver, this.swapData.sender.cosmos) + ), + port: route.bridgeInfo.port, + channel: route.bridgeInfo.channel, + timeout: 0, + retries: 2 + } } }; }; - private getReceiverIBCHooks = (chainId, receiver?: string) => { - if (chainId === "osmosis-1") return OSMOSIS_ROUTER_CONTRACT; - return receiver; + private getPrefixCosmos = (route: Routes) => { + const getPrefix = (chainId: string) => + cosmosChains.find((cosmos) => cosmos.chainId === chainId).bech32Config.bech32PrefixAccAddr; + const prefixRecover = getPrefix(route.chainId); + const prefixReceiver = getPrefix(route.tokenOutChainId ?? route.chainId); + return { prefixRecover, prefixReceiver }; }; + private getMsgTransfer = (route: Routes) => { + const { prefixReceiver, prefixRecover } = this.getPrefixCosmos(route); + return { + sourcePort: route.bridgeInfo.port, + sourceChannel: route.bridgeInfo.channel, + // TODO: need check address + receiver: this.getReceiverIBCHooks( + route.tokenOutChainId, + this.getAddress(prefixReceiver, this.swapData.sender.cosmos) + ), + token: { + amount: route.tokenInAmount, + denom: route.tokenIn + }, + // TODO: need check address + sender: this.getAddress(prefixRecover, this.swapData.sender.cosmos), + memo: "", + timeoutTimestamp: Number(calculateTimeoutTimestamp(3600)) + }; + }; + + // TODO: need refactor smart router osmosis async alphaSmartRouterSwap() { const { cosmos } = this.swapData.sender; - const { alphaSmartRoutes, userSlippage, originalFromToken } = this.swapData; + const { alphaSmartRoutes, originalFromToken } = this.swapData; + const { client } = await this.config.cosmosWallet.getCosmWasmClient( { chainId: originalFromToken.chainId as CosmosChainId, @@ -409,62 +447,41 @@ export class UniversalSwapHandler { ); let messages = []; - let transfers = []; - - alphaSmartRoutes.routes.forEach((route, index) => { - let msgTransfer; - let pathMemo = ""; - - route.paths.forEach((path) => { - if ( - path.chainId === "Oraichain" && - // path.actions.length == 1 && - path.actions.some((pathAction) => pathAction.type === "Swap") - ) { - messages.push(...this.generateMsgsSmartRouterSwap(index)); + let msgTransfers = []; + let pathMemo = ""; + + const { routesFlatten } = this.flattenSmartRouters(alphaSmartRoutes.routes); + + routesFlatten.forEach((route: Routes, index: number, routes: Routes[]) => { + if (route.chainId === "Oraichain" && route.type === "Swap") { + // swap in oraichain + messages.push(...this.generateMsgsSmartRouterSwap(route)); + } else { + if (!msgTransfers[route.path]) { + // initial msgTransfer + msgTransfers[route.path] = this.getMsgTransfer(route); + pathMemo = "memo"; } else { - path.actions.forEach((action) => { - const prefix = cosmosChains.find((cosmos) => cosmos.chainId === path.tokenOutChainId).bech32Config - .bech32PrefixAccAddr; - if (action.type === "Bridge") { - if (!msgTransfer) { - msgTransfer = { - sourcePort: action.bridgeInfo.port, - sourceChannel: action.bridgeInfo.channel, - receiver: this.getReceiverIBCHooks(path.tokenOutChainId, this.getAddress(prefix, cosmos)), - token: coin(action.tokenInAmount, action.tokenIn), - sender: cosmos, - memo: "", - timeoutTimestamp: Number(calculateTimeoutTimestamp(3600)) - }; - pathMemo = "memo"; - } else { - let forwardObject = {}; - if (path.chainId === "osmosis-1" && path.actions.length > 1) { - forwardObject = this.createSwapAndAction({ action, path, route, receiver: cosmos, userSlippage }); - } else { - forwardObject = this.createForwardObject({ - action, - path, - receiver: cosmos - }); - } - - this.updateNestedProperty(msgTransfer, pathMemo, forwardObject); - pathMemo += - path.chainId === "osmosis-1" && path.actions.length > 1 - ? ".wasm.msg.swap_and_action.post_swap_action.ibc_transfer.ibc_info.memo" - : ".forward.next"; - } + if (route.chainId === "osmosis-1") { + if (route.type === "Swap") { + const { msgActionSwap } = this.getSwapAndAction(route, index + 1 === routes.length); + this.updateNestedProperty(msgTransfers[route.path], pathMemo, msgActionSwap); + pathMemo += ".wasm.msg.swap_and_action.post_swap_action"; + } else if (index > 0 && routes[index - 1].chainId === route.chainId) { + const { msgTransferInfo } = this.getIbcTransferInfo(route); + this.updateNestedProperty(msgTransfers[route.path], pathMemo, msgTransferInfo); + pathMemo += ".ibc_transfer.ibc_info.memo"; } - }); + } else { + const { msgForwardObject } = this.createForwardObject(route); + this.updateNestedProperty(msgTransfers[route.path], pathMemo, msgForwardObject); + pathMemo += ".forward.next"; + } } - }); - - if (msgTransfer) transfers.push(msgTransfer); + } }); - const transferStringifyMemo = transfers.map((transfer) => { + const transferStringifyMemo = msgTransfers.map((transfer) => { this.stringifyMemos(transfer); return { typeUrl: "/ibc.applications.transfer.v1.MsgTransfer", @@ -476,6 +493,19 @@ export class UniversalSwapHandler { return client.signAndBroadcast(this.swapData.sender.cosmos, [...msgExecuteSwap, ...transferStringifyMemo], "auto"); } + private flattenSmartRouters(routers: Route[]) { + const routesFlatten = routers.flatMap((router, i) => + router.paths.flatMap((path) => + path.actions.map((action) => ({ + ...action, + path: i, + chainId: path.chainId + })) + ) + ); + return { routesFlatten }; + } + private updateNestedProperty = (obj, key, value) => { const keys = key.split("."); keys.slice(0, -1).reduce((current, k) => { @@ -923,44 +953,40 @@ export class UniversalSwapHandler { return this.transferAndSwap(swapRoute); } - generateMsgsSmartRouterSwap(index) { - if (this.swapData.alphaSmartRoutes) { - let contractAddr: string = network.router; - const { originalFromToken, fromAmount } = this.swapData; - const fromTokenOnOrai = this.getTokenOnOraichain(originalFromToken.coinGeckoId); - const _fromAmount = toAmount(fromAmount, fromTokenOnOrai.decimals).toString(); - const isValidSlippage = this.swapData.userSlippage || this.swapData.userSlippage === 0; - if (!this.swapData.simulatePrice || !isValidSlippage) { - throw generateError( - "Could not calculate the minimum receive value because there is no simulate price or user slippage" - ); - } - const to = this.swapData.recipientAddress; - const { info: offerInfo } = parseTokenInfo(fromTokenOnOrai, _fromAmount); - const alphaSmartRoutesSwap = this.swapData.alphaSmartRoutes.routes[index].paths[0]; - const swapInOraichain = alphaSmartRoutesSwap.actions.filter((act) => act.type === "Swap"); - const routes = swapInOraichain.map((route) => { - let ops = []; - let currTokenIn = offerInfo; - for (let path of route.swapInfo) { - let tokenOut = parseAssetInfoFromContractAddrOrDenom(path.tokenOut); - ops.push({ - orai_swap: { - offer_asset_info: currTokenIn, - ask_asset_info: tokenOut - } - }); - currTokenIn = tokenOut; - } - return { - swapAmount: route.tokenInAmount, - returnAmount: route.tokenOutAmount, - swapOps: ops - }; - }); - const msgs: ExecuteInstruction[] = this.buildSwapMsgsFromSmartRoute(routes, fromTokenOnOrai, to, contractAddr); - return msgs; + generateMsgsSmartRouterSwap(route: Routes) { + let contractAddr: string = network.router; + const { originalFromToken, fromAmount } = this.swapData; + const fromTokenOnOrai = this.getTokenOnOraichain(originalFromToken.coinGeckoId); + const _fromAmount = toAmount(fromAmount, fromTokenOnOrai.decimals).toString(); + const isValidSlippage = this.swapData.userSlippage || this.swapData.userSlippage === 0; + if (!this.swapData.simulatePrice || !isValidSlippage) { + throw generateError( + "Could not calculate the minimum receive value because there is no simulate price or user slippage" + ); } + const to = this.swapData.recipientAddress; + const { info: offerInfo } = parseTokenInfo(fromTokenOnOrai, _fromAmount); + const routes = [route].map((route) => { + let ops = []; + let currTokenIn = offerInfo; + for (let path of route.swapInfo) { + let tokenOut = parseAssetInfoFromContractAddrOrDenom(path.tokenOut); + ops.push({ + orai_swap: { + offer_asset_info: currTokenIn, + ask_asset_info: tokenOut + } + }); + currTokenIn = tokenOut; + } + return { + swapAmount: route.tokenInAmount, + returnAmount: route.tokenOutAmount, + swapOps: ops + }; + }); + const msgs: ExecuteInstruction[] = this.buildSwapMsgsFromSmartRoute(routes, fromTokenOnOrai, to, contractAddr); + return msgs; } generateMsgsSwap() { diff --git a/packages/universal-swap/src/types.ts b/packages/universal-swap/src/types.ts index 0128d703..69404b9a 100644 --- a/packages/universal-swap/src/types.ts +++ b/packages/universal-swap/src/types.ts @@ -52,7 +52,7 @@ export interface UniversalSwapData { readonly amounts?: AmountDetails; readonly recipientAddress?: string; // recipient address from client, if user want to send to another address readonly smartRoutes?: SmartRouteSwapOperations[]; - readonly alphaSmartRoutes?: Router; + readonly alphaSmartRoutes?: RouterResponse; } /** @@ -167,16 +167,19 @@ export interface IbcInfo { } export interface PostSwapAction { - ibc_transfer: { + ibc_transfer?: { ibc_info: IbcInfo; }; + transfer?: { + to_address: string; + }; } export interface SwapAndAction { user_swap: UserSwap; min_asset: MinAsset; timeout_timestamp: number | string; - post_swap_action?: PostSwapAction; + post_swap_action: PostSwapAction; affiliates: any[]; } @@ -200,13 +203,13 @@ export interface Forward { next: NextWasm; } -interface Router { +export interface RouterResponse { swapAmount: string; returnAmount: string; routes: Route[]; } -interface Route { +export interface Route { swapAmount: string; returnAmount: string; paths: Path[]; @@ -241,3 +244,19 @@ interface BridgeInfo { port: string; channel: string; } +interface RouteBase { + path: number; + chainId: string; + type: string; + tokenIn: string; + tokenInAmount: string; + tokenOut: string; + tokenOutAmount: string; +} + +export interface Routes extends RouteBase { + type: "Bridge" | "Swap"; + tokenOutChainId?: string; + bridgeInfo?: BridgeInfo; + swapInfo?: SwapInfo[]; +} diff --git a/packages/universal-swap/src/universal-demos/alpha-smart-router.ts b/packages/universal-swap/src/universal-demos/alpha-smart-router.ts new file mode 100644 index 00000000..7064a060 --- /dev/null +++ b/packages/universal-swap/src/universal-demos/alpha-smart-router.ts @@ -0,0 +1,404 @@ +import "dotenv/config"; +import { CosmosWalletImpl } from "./offline-wallet"; +import { UniversalSwapHandler } from "../handler"; +import { cosmosTokens, generateError, getTokenOnOraichain, toAmount } from "@oraichain/oraidex-common"; + +const router = { + swapAmount: "100000", + returnAmount: "978854", + routes: [ + { + swapAmount: "100000", + returnAmount: "978854", + paths: [ + { + chainId: "cosmoshub-4", + tokenIn: "uatom", + tokenInAmount: "100000", + tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", + tokenOutAmount: "100000", + tokenOutChainId: "osmosis-1", + actions: [ + { + type: "Bridge", + tokenIn: "uatom", + tokenInAmount: "100000", + tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", + tokenOutAmount: "100000", + tokenOutChainId: "osmosis-1", + bridgeInfo: { + port: "transfer", + channel: "channel-141" + } + } + ] + }, + { + chainId: "osmosis-1", + tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", + tokenInAmount: "100000", + tokenOut: "uosmo", + tokenOutAmount: "978854", + tokenOutChainId: "osmosis-1", + actions: [ + { + type: "Swap", + tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", + tokenInAmount: "100000", + tokenOut: "uosmo", + tokenOutAmount: "978854", + swapInfo: [ + { + poolId: "1135", + tokenOut: "uosmo" + } + ] + } + ] + } + ] + } + ] +}; + +// const router = { +// swapAmount: "10000000", +// returnAmount: "86063044", +// routes: [ +// { +// swapAmount: "10000000", +// returnAmount: "86063044", +// paths: [ +// { +// chainId: "Oraichain", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "10000000", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "86063044", +// tokenOutChainId: "Oraichain", +// actions: [ +// { +// type: "Swap", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "10000000", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "86063044", +// swapInfo: [ +// { +// poolId: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs", +// tokenOut: "orai" +// }, +// { +// poolId: "orai1m6q5k5nr2eh8q0rdrf57wr7phk7uvlpg7mwfv5", +// tokenOut: "orai1lus0f0rhx8s03gdllx2n6vhkmf0536dv57wfge" +// }, +// { +// poolId: "orai1n4edv5h86rawzrvhy8lmrmnnmmherxnhuwqnk3yuvt0wgclh75usyn3md6", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd" +// } +// ] +// } +// ] +// } +// ] +// } +// ] +// }; + +// const router = { +// swapAmount: "1000000000", +// returnAmount: "8518615211", +// routes: [ +// { +// swapAmount: "500000000", +// returnAmount: "4259030486", +// paths: [ +// { +// chainId: "Oraichain", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "500000000", +// tokenOut: "uatom", +// tokenOutAmount: "500000000", +// tokenOutChainId: "cosmoshub-4", +// actions: [ +// { +// type: "Bridge", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "500000000", +// tokenOut: "uatom", +// tokenOutAmount: "500000000", +// tokenOutChainId: "cosmoshub-4", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-15" +// } +// } +// ] +// }, +// { +// chainId: "cosmoshub-4", +// tokenIn: "uatom", +// tokenInAmount: "500000000", +// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenOutAmount: "500000000", +// tokenOutChainId: "osmosis-1", +// actions: [ +// { +// type: "Bridge", +// tokenIn: "uatom", +// tokenInAmount: "500000000", +// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenOutAmount: "500000000", +// tokenOutChainId: "osmosis-1", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-141" +// } +// } +// ] +// }, +// { +// chainId: "osmosis-1", +// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenInAmount: "500000000", +// tokenOut: "uusdc", +// tokenOutAmount: "4267957444", +// tokenOutChainId: "noble-1", +// actions: [ +// { +// type: "Swap", +// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenInAmount: "500000000", +// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", +// tokenOutAmount: "4272229674", +// swapInfo: [ +// { +// poolId: "1282", +// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4" +// } +// ] +// }, +// { +// type: "Bridge", +// tokenIn: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", +// tokenInAmount: "4272229674", +// tokenOut: "uusdc", +// tokenOutAmount: "4267957444", +// tokenOutChainId: "noble-1", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-750" +// } +// } +// ] +// }, +// { +// chainId: "noble-1", +// tokenIn: "uusdc", +// tokenInAmount: "4267957444", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "4259030486", +// tokenOutChainId: "Oraichain", +// actions: [ +// { +// type: "Bridge", +// tokenIn: "uusdc", +// tokenInAmount: "4267957444", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "4259030486", +// tokenOutChainId: "Oraichain", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-34" +// } +// } +// ] +// } +// ] +// }, +// { +// swapAmount: "400000000", +// returnAmount: "3402135656", +// paths: [ +// { +// chainId: "Oraichain", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "400000000", +// tokenOut: "uatom", +// tokenOutAmount: "400000000", +// tokenOutChainId: "cosmoshub-4", +// actions: [ +// { +// type: "Bridge", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "400000000", +// tokenOut: "uatom", +// tokenOutAmount: "400000000", +// tokenOutChainId: "cosmoshub-4", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-15" +// } +// } +// ] +// }, +// { +// chainId: "cosmoshub-4", +// tokenIn: "uatom", +// tokenInAmount: "400000000", +// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenOutAmount: "400000000", +// tokenOutChainId: "osmosis-1", +// actions: [ +// { +// type: "Bridge", +// tokenIn: "uatom", +// tokenInAmount: "400000000", +// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenOutAmount: "400000000", +// tokenOutChainId: "osmosis-1", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-141" +// } +// } +// ] +// }, +// { +// chainId: "osmosis-1", +// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenInAmount: "400000000", +// tokenOut: "uusdc", +// tokenOutAmount: "3410204861", +// tokenOutChainId: "noble-1", +// actions: [ +// { +// type: "Swap", +// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", +// tokenInAmount: "400000000", +// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", +// tokenOutAmount: "3413618480", +// swapInfo: [ +// { +// poolId: "1251", +// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4" +// } +// ] +// }, +// { +// type: "Bridge", +// tokenIn: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", +// tokenInAmount: "3413618480", +// tokenOut: "uusdc", +// tokenOutAmount: "3410204861", +// tokenOutChainId: "noble-1", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-750" +// } +// } +// ] +// }, +// { +// chainId: "noble-1", +// tokenIn: "uusdc", +// tokenInAmount: "3410204861", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "3402135656", +// tokenOutChainId: "Oraichain", +// actions: [ +// { +// type: "Bridge", +// tokenIn: "uusdc", +// tokenInAmount: "3410204861", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "3402135656", +// tokenOutChainId: "Oraichain", +// bridgeInfo: { +// port: "transfer", +// channel: "channel-34" +// } +// } +// ] +// } +// ] +// }, +// { +// swapAmount: "100000000", +// returnAmount: "857449069", +// paths: [ +// { +// chainId: "Oraichain", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "100000000", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "857449069", +// tokenOutChainId: "Oraichain", +// actions: [ +// { +// type: "Swap", +// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", +// tokenInAmount: "100000000", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", +// tokenOutAmount: "857449069", +// swapInfo: [ +// { +// poolId: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs", +// tokenOut: "orai" +// }, +// { +// poolId: "orai1m6q5k5nr2eh8q0rdrf57wr7phk7uvlpg7mwfv5", +// tokenOut: "orai1lus0f0rhx8s03gdllx2n6vhkmf0536dv57wfge" +// }, +// { +// poolId: "orai1n4edv5h86rawzrvhy8lmrmnnmmherxnhuwqnk3yuvt0wgclh75usyn3md6", +// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd" +// } +// ] +// } +// ] +// } +// ] +// } +// ] +// }; + +const alphaSwapToOraichain = async () => { + const wallet = new CosmosWalletImpl(process.env.MNEMONIC); + const sender = await wallet.getKeplrAddr("cosmoshub-4"); + const fromAmount = 0.1; + console.log("sender: ", sender); + const originalFromToken = cosmosTokens.find((t) => t.coinGeckoId === "cosmos" && t.chainId === "cosmoshub-4"); + + const originalToToken = cosmosTokens.find((t) => t.coinGeckoId === "osmosis" && t.chainId === "osmosis-1"); + // const originalFromToken = getTokenOnOraichain("cosmos"); + // const originalToToken = getTokenOnOraichain("usd-coin"); + + if (!originalToToken) throw generateError("Could not find original to token"); + if (!originalFromToken) throw generateError("Could not find original from token"); + + const universalHandler = new UniversalSwapHandler( + { + originalFromToken, + originalToToken, + sender: { cosmos: sender }, + fromAmount, + userSlippage: 100, + simulatePrice: "9834300", + simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(), + alphaSmartRoutes: router + }, + { cosmosWallet: wallet, swapOptions: { isAlphaSmartRouter: true } } + ); + + try { + const result = await universalHandler.processUniversalSwap(); + console.log("result: ", result); + } catch (error) { + console.trace("error: ", error); + } +}; + +(() => { + alphaSwapToOraichain(); +})(); diff --git a/packages/universal-swap/src/universal-demos/apha-smart-router.ts b/packages/universal-swap/src/universal-demos/apha-smart-router.ts deleted file mode 100644 index f4cf114e..00000000 --- a/packages/universal-swap/src/universal-demos/apha-smart-router.ts +++ /dev/null @@ -1,459 +0,0 @@ -import "dotenv/config"; -import { CosmosWalletImpl } from "./offline-wallet"; -import { UniversalSwapHandler } from "../handler"; -import { generateError, getTokenOnOraichain, toAmount } from "@oraichain/oraidex-common"; - -// ORAICHAIN -> ORAICHAIN -// ORAICHAIN -> COSMOS -// COSMOS -> COSMOS -// COSMOS -> ORAICHAIN - -// const router = { -// swapAmount: "10", -// returnAmount: "147", -// routes: [ -// { -// swapAmount: "10", -// returnAmount: "147", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "orai", -// tokenInAmount: "10", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "147", -// tokenOutChainId: "Oraichain", -// actions: [ -// { -// type: "Swap", -// tokenIn: "orai", -// tokenInAmount: "10", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "147", -// swapInfo: [ -// { -// poolId: "orai19ttg0j7w5kr83js32tmwnwxxdq9rkmw4m3d7mn2j2hkpugwwa4tszwsnkg", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd" -// } -// ] -// } -// ] -// } -// ] -// } -// ] -// }; - -// { -// "sourceAsset":"orai", -// "sourceChainId": "Oraichain", -// "destAsset": "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// "destChainId":"Oraichain", -// "offerAmount": "10" -// } - -// const router = { -// swapAmount: "100", -// returnAmount: "1464", -// routes: [ -// { -// swapAmount: "90", -// returnAmount: "1318", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "orai", -// tokenInAmount: "90", -// tokenOut: "uatom", -// tokenOutAmount: "160", -// tokenOutChainId: "cosmoshub-4", -// actions: [ -// { -// type: "Swap", -// tokenIn: "orai", -// tokenInAmount: "90", -// tokenOut: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenOutAmount: "160", -// swapInfo: [ -// { -// poolId: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs", -// tokenOut: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78" -// } -// ] -// }, -// { -// type: "Bridge", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "160", -// tokenOut: "uatom", -// tokenOutAmount: "160", -// tokenOutChainId: "cosmoshub-4", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-15" -// } -// } -// ] -// }, -// { -// chainId: "cosmoshub-4", -// tokenIn: "uatom", -// tokenInAmount: "160", -// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenOutAmount: "160", -// tokenOutChainId: "osmosis-1", -// actions: [ -// { -// type: "Bridge", -// tokenIn: "uatom", -// tokenInAmount: "160", -// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenOutAmount: "160", -// tokenOutChainId: "osmosis-1", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-141" -// } -// } -// ] -// }, - -// //---- -// // { -// // chainId: "cosmoshub-4", -// // tokenIn: "uatom", -// // tokenInAmount: "160", -// // // tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// // tokenOut: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// // tokenOutAmount: "160", -// // // tokenOutChainId: "osmosis-1", -// // tokenOutChainId: "Oraichain", -// // actions: [ -// // { -// // type: "Bridge", -// // tokenIn: "uatom", -// // tokenInAmount: "160", -// // // tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// // tokenOut: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// // tokenOutAmount: "160", -// // // tokenOutChainId: "osmosis-1", -// // tokenOutChainId: "Oraichain", -// // bridgeInfo: { -// // port: "transfer", -// // // channel: "channel-141" -// // channel: "channel-301" -// // } -// // } -// // ] -// // } -// //----- - -// { -// chainId: "osmosis-1", -// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenInAmount: "160", -// tokenOut: "uusdc", -// tokenOutAmount: "1320", -// tokenOutChainId: "noble-1", -// actions: [ -// { -// type: "Swap", -// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenInAmount: "160", -// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", -// tokenOutAmount: "1322", -// swapInfo: [ -// { -// poolId: "1135", -// tokenOut: "uosmo" -// }, -// { -// poolId: "1464", -// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4" -// } -// ] -// }, -// { -// type: "Bridge", -// tokenIn: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", -// tokenInAmount: "1322", -// tokenOut: "uusdc", -// tokenOutAmount: "1320", -// tokenOutChainId: "noble-1", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-750" -// } -// } -// ] -// } -// // { -// // chainId: "noble-1", -// // tokenIn: "uusdc", -// // tokenInAmount: "1320", -// // tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// // tokenOutAmount: "1318", -// // tokenOutChainId: "Oraichain", -// // actions: [ -// // { -// // type: "Bridge", -// // tokenIn: "uusdc", -// // tokenInAmount: "1320", -// // tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// // tokenOutAmount: "1318", -// // tokenOutChainId: "Oraichain", -// // bridgeInfo: { -// // port: "transfer", -// // channel: "channel-147" -// // } -// // } -// // ] -// // } - -// // { -// // chainId: "noble-1", -// // tokenIn: "uusdc", -// // tokenInAmount: "1320", -// // tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// // tokenOutAmount: "1318", -// // tokenOutChainId: "Oraichain", -// // actions: [ -// // { -// // type: "Bridge", -// // tokenIn: "uusdc", -// // tokenInAmount: "1320", -// // tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// // tokenOutAmount: "1318", -// // tokenOutChainId: "Oraichain", -// // bridgeInfo: { -// // port: "transfer", -// // channel: "channel-147" -// // } -// // } -// // ] -// // } -// ] -// }, -// { -// swapAmount: "10", -// returnAmount: "146", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "orai", -// tokenInAmount: "10", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "146", -// tokenOutChainId: "Oraichain", -// actions: [ -// { -// type: "Swap", -// tokenIn: "orai", -// tokenInAmount: "10", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "146", -// swapInfo: [ -// { -// poolId: "orai19ttg0j7w5kr83js32tmwnwxxdq9rkmw4m3d7mn2j2hkpugwwa4tszwsnkg", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd" -// } -// ] -// } -// ] -// } -// ] -// } -// ] -// }; - -// const router = { -// swapAmount: "100000", -// returnAmount: "880721", -// routes: [ -// { -// swapAmount: "100000", -// returnAmount: "880721", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "ibc/a2e2eec9057a4a1c2c0a6a4c78b0239118df5f278830f50b4a6bdd7a66506b78", -// tokenInAmount: "100000", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "880721", -// tokenOutChainId: "Oraichain", -// actions: [ -// { -// type: "Swap", -// tokenIn: "ibc/a2e2eec9057a4a1c2c0a6a4c78b0239118df5f278830f50b4a6bdd7a66506b78", -// tokenInAmount: "100000", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "880721", -// swapInfo: [ -// { -// poolId: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs", -// tokenOut: "orai" -// }, -// { -// poolId: "orai19ttg0j7w5kr83js32tmwnwxxdq9rkmw4m3d7mn2j2hkpugwwa4tszwsnkg", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd" -// } -// ] -// } -// ] -// } -// ] -// } -// ] -// }; - -const router = { - swapAmount: "10000", - returnAmount: "88913", - routes: [ - { - swapAmount: "10000", - returnAmount: "88913", - paths: [ - { - chainId: "Oraichain", - tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", - tokenInAmount: "10000", - tokenOut: "uatom", - tokenOutAmount: "10000", - tokenOutChainId: "cosmoshub-4", - actions: [ - { - type: "Bridge", - tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", - tokenInAmount: "10000", - tokenOut: "uatom", - tokenOutAmount: "10000", - tokenOutChainId: "cosmoshub-4", - bridgeInfo: { - port: "transfer", - channel: "channel-15" - } - } - ] - }, - { - chainId: "cosmoshub-4", - tokenIn: "uatom", - tokenInAmount: "10000", - tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - tokenOutAmount: "10000", - tokenOutChainId: "osmosis-1", - actions: [ - { - type: "Bridge", - tokenIn: "uatom", - tokenInAmount: "10000", - tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - tokenOutAmount: "10000", - tokenOutChainId: "osmosis-1", - bridgeInfo: { - port: "transfer", - channel: "channel-141" - } - } - ] - }, - { - chainId: "osmosis-1", - tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - tokenInAmount: "10000", - tokenOut: "uusdc", - tokenOutAmount: "89003", - tokenOutChainId: "noble-1", - actions: [ - { - type: "Swap", - tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - tokenInAmount: "10000", - tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - tokenOutAmount: "89093", - swapInfo: [ - { - poolId: "1282", - tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4" - } - ] - }, - { - type: "Bridge", - tokenIn: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - tokenInAmount: "89093", - tokenOut: "uusdc", - tokenOutAmount: "89003", - tokenOutChainId: "noble-1", - bridgeInfo: { - port: "transfer", - channel: "channel-750" - } - } - ] - } - // { - // chainId: "noble-1", - // tokenIn: "uusdc", - // tokenInAmount: "89003", - // tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", - // tokenOutAmount: "88913", - // tokenOutChainId: "Oraichain", - // actions: [ - // { - // type: "Bridge", - // tokenIn: "uusdc", - // tokenInAmount: "89003", - // tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", - // tokenOutAmount: "88913", - // tokenOutChainId: "Oraichain", - // bridgeInfo: { - // port: "transfer", - // channel: "channel-147" - // } - // } - // ] - // } - ] - } - ] -}; - -const alphaSwapToOraichain = async () => { - const wallet = new CosmosWalletImpl(process.env.MNEMONIC); - const sender = await wallet.getKeplrAddr("Oraichain"); - const fromAmount = 0.01; - console.log("sender: ", sender); - // const originalFromToken = cosmosTokens.find((t) => t.coinGeckoId === "oraichain-token" && t.chainId === "Oraichain"); - const originalFromToken = getTokenOnOraichain("cosmos"); - const originalToToken = getTokenOnOraichain("usd-coin"); - - if (!originalToToken) throw generateError("Could not find original to token"); - if (!originalFromToken) throw generateError("Could not find original from token"); - - const universalHandler = new UniversalSwapHandler( - { - originalFromToken, - originalToToken, - sender: { cosmos: sender }, - fromAmount, - userSlippage: 1, - simulatePrice: "16604436", - simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(), - alphaSmartRoutes: router - }, - { cosmosWallet: wallet, swapOptions: { isAlphaSmartRouter: true } } - ); - - try { - const result = await universalHandler.processUniversalSwap(); - console.log("result: ", result); - } catch (error) { - console.trace("error: ", error); - } -}; - -(() => { - alphaSwapToOraichain(); -})(); From d5d0295a43ef263ce6c9a4b0dc792ce61cae29f0 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 24 May 2024 16:57:52 +0700 Subject: [PATCH 2/4] fix logic smart router --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/network.ts | 4 +- packages/universal-swap/src/handler.ts | 145 +++++++++++++++++-------- packages/universal-swap/src/types.ts | 3 +- 4 files changed, 101 insertions(+), 53 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index f82f5d35..3d572d71 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.0.87", + "version": "1.0.88", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index 4e79d83a..53dfb216 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -748,8 +748,8 @@ export const chainInfos: CustomChainInfo[] = [ beta: true }, { - rpc: "https://rpc.cosmos.directory/cosmoshub", - rest: "https://rest.cosmos.directory/cosmoshub", + rpc: "https://cosmos-rpc.publicnode.com:443", + rest: "https://cosmos-rest.publicnode.com", chainId: "cosmoshub-4", chainName: "Cosmos Hub", networkType: "cosmos", diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index 80becd43..f208b24f 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -301,9 +301,10 @@ export class UniversalSwapHandler { } // TODO: need check func getAddress - private getAddress = (prefix: string, address: string, coinType: number = 118) => { + private getAddress = (prefix: string, { address60, address118 }, coinType: number = 118) => { const approve = { - 118: address + 118: address118, + 60: address60 }; const { data } = fromBech32(approve[coinType]); return toBech32(prefix, data); @@ -314,14 +315,17 @@ export class UniversalSwapHandler { return receiver; }; - private getSwapAndAction(route: Routes, isOnlySwap: boolean) { - const { prefixReceiver } = this.getPrefixCosmos(route); + private getSwapAndAction(route: Routes, { oraiAddress, injAddress }, isOnlySwap: boolean) { + const { prefixReceiver, chainInfoReceiver } = this.getPrefixCosmos(route); let post_swap_action = {}; if (isOnlySwap) { post_swap_action = { transfer: { - // TODO: need check address - to_address: this.getAddress(prefixReceiver, this.swapData.sender.cosmos) + to_address: this.getAddress( + prefixReceiver, + { address60: injAddress, address118: oraiAddress }, + chainInfoReceiver.bip44.coinType + ) } }; } @@ -366,32 +370,42 @@ export class UniversalSwapHandler { return { msgActionSwap }; } - private getIbcTransferInfo(route: Routes) { - const { prefixRecover, prefixReceiver } = this.getPrefixCosmos(route); + private getIbcTransferInfo(route: Routes, { oraiAddress, injAddress }) { + const { prefixRecover, prefixReceiver, chainInfoReceiver, chainInfoRecover } = this.getPrefixCosmos(route); const msgTransferInfo = { ibc_transfer: { ibc_info: { source_channel: route.bridgeInfo.channel, - // TODO: need check address - receiver: this.getAddress(prefixReceiver, this.swapData.sender.cosmos), + receiver: this.getAddress( + prefixReceiver, + { address60: injAddress, address118: oraiAddress }, + chainInfoReceiver.bip44.coinType + ), memo: "", - // TODO: need check address - recover_address: this.getAddress(prefixRecover, this.swapData.sender.cosmos) + recover_address: this.getAddress( + prefixRecover, + { address60: injAddress, address118: oraiAddress }, + chainInfoRecover.bip44.coinType + ) } } }; return { msgTransferInfo }; } - private createForwardObject = (route: Routes) => { - const { prefixReceiver } = this.getPrefixCosmos(route); + private createForwardObject = (route: Routes, { oraiAddress, injAddress }) => { + const { prefixReceiver, chainInfoReceiver } = this.getPrefixCosmos(route); return { msgForwardObject: { forward: { // TODO: need check address receiver: this.getReceiverIBCHooks( route.tokenOutChainId, - this.getAddress(prefixReceiver, this.swapData.sender.cosmos) + this.getAddress( + prefixReceiver, + { address60: injAddress, address118: oraiAddress }, + chainInfoReceiver.bip44.coinType + ) ), port: route.bridgeInfo.port, channel: route.bridgeInfo.channel, @@ -403,83 +417,118 @@ export class UniversalSwapHandler { }; private getPrefixCosmos = (route: Routes) => { - const getPrefix = (chainId: string) => - cosmosChains.find((cosmos) => cosmos.chainId === chainId).bech32Config.bech32PrefixAccAddr; - const prefixRecover = getPrefix(route.chainId); - const prefixReceiver = getPrefix(route.tokenOutChainId ?? route.chainId); - return { prefixRecover, prefixReceiver }; + const getPrefix = (chainId: string) => { + const chainInfo = cosmosChains.find((cosmos) => cosmos.chainId === chainId); + return { + chainInfo, + prefix: chainInfo.bech32Config.bech32PrefixAccAddr + }; + }; + const { prefix: prefixRecover, chainInfo: chainInfoRecover } = getPrefix(route.chainId); + const { prefix: prefixReceiver, chainInfo: chainInfoReceiver } = getPrefix(route.tokenOutChainId ?? route.chainId); + return { prefixRecover, prefixReceiver, chainInfoRecover, chainInfoReceiver }; }; - private getMsgTransfer = (route: Routes) => { - const { prefixReceiver, prefixRecover } = this.getPrefixCosmos(route); + private getMsgTransfer = (route: Routes, { oraiAddress, injAddress }) => { + const { prefixReceiver, prefixRecover, chainInfoRecover, chainInfoReceiver } = this.getPrefixCosmos(route); return { sourcePort: route.bridgeInfo.port, sourceChannel: route.bridgeInfo.channel, - // TODO: need check address receiver: this.getReceiverIBCHooks( route.tokenOutChainId, - this.getAddress(prefixReceiver, this.swapData.sender.cosmos) + this.getAddress( + prefixReceiver, + { address60: injAddress, address118: oraiAddress }, + chainInfoReceiver.bip44.coinType + ) ), token: { amount: route.tokenInAmount, denom: route.tokenIn }, - // TODO: need check address - sender: this.getAddress(prefixRecover, this.swapData.sender.cosmos), + sender: this.getAddress( + prefixRecover, + { address60: injAddress, address118: oraiAddress }, + chainInfoRecover.bip44.coinType + ), memo: "", timeoutTimestamp: Number(calculateTimeoutTimestamp(3600)) }; }; - // TODO: need refactor smart router osmosis - async alphaSmartRouterSwap() { - const { cosmos } = this.swapData.sender; - const { alphaSmartRoutes, originalFromToken } = this.swapData; - - const { client } = await this.config.cosmosWallet.getCosmWasmClient( - { - chainId: originalFromToken.chainId as CosmosChainId, - rpc: originalFromToken.rpc - }, - { - gasPrice: this.getGasPriceFromToken() - } - ); - + getMessagesAndMsgTransfers = (routeFlatten: Routes[], { oraiAddress, injAddress }) => { let messages = []; let msgTransfers = []; let pathMemo = ""; - const { routesFlatten } = this.flattenSmartRouters(alphaSmartRoutes.routes); - - routesFlatten.forEach((route: Routes, index: number, routes: Routes[]) => { + routeFlatten.forEach((route: Routes, index: number, routes: Routes[]) => { if (route.chainId === "Oraichain" && route.type === "Swap") { // swap in oraichain messages.push(...this.generateMsgsSmartRouterSwap(route)); } else { if (!msgTransfers[route.path]) { // initial msgTransfer - msgTransfers[route.path] = this.getMsgTransfer(route); + msgTransfers[route.path] = this.getMsgTransfer(route, { oraiAddress, injAddress }); pathMemo = "memo"; } else { if (route.chainId === "osmosis-1") { if (route.type === "Swap") { - const { msgActionSwap } = this.getSwapAndAction(route, index + 1 === routes.length); + const { msgActionSwap } = this.getSwapAndAction( + route, + { oraiAddress, injAddress }, + index + 1 === routes.length + ); this.updateNestedProperty(msgTransfers[route.path], pathMemo, msgActionSwap); pathMemo += ".wasm.msg.swap_and_action.post_swap_action"; } else if (index > 0 && routes[index - 1].chainId === route.chainId) { - const { msgTransferInfo } = this.getIbcTransferInfo(route); + const { msgTransferInfo } = this.getIbcTransferInfo(route, { oraiAddress, injAddress }); this.updateNestedProperty(msgTransfers[route.path], pathMemo, msgTransferInfo); pathMemo += ".ibc_transfer.ibc_info.memo"; } } else { - const { msgForwardObject } = this.createForwardObject(route); + const { msgForwardObject } = this.createForwardObject(route, { oraiAddress, injAddress }); this.updateNestedProperty(msgTransfers[route.path], pathMemo, msgForwardObject); pathMemo += ".forward.next"; } } } }); + return { messages, msgTransfers }; + }; + + // TODO: need refactor smart router osmosis + async alphaSmartRouterSwap() { + const { cosmos } = this.swapData.sender; + const { alphaSmartRoutes, originalFromToken } = this.swapData; + + const { client } = await this.config.cosmosWallet.getCosmWasmClient( + { + chainId: originalFromToken.chainId as CosmosChainId, + // rpc: originalFromToken.rpc + rpc: "https://cosmos-rpc.publicnode.com:443" + }, + { + gasPrice: this.getGasPriceFromToken() + } + ); + + const { routesFlatten } = this.flattenSmartRouters(alphaSmartRoutes.routes); + + const [oraiAddress, injAddress] = await Promise.all([ + this.config.cosmosWallet.getKeplrAddr("Oraichain"), + this.config.cosmosWallet.getKeplrAddr("injective-1") + ]); + + if (!oraiAddress || !injAddress) { + throw generateError( + `There is a mismatch address between ${oraiAddress} and ${injAddress}. Should not using smart router swap!` + ); + } + + const { messages, msgTransfers } = await this.getMessagesAndMsgTransfers(routesFlatten, { + oraiAddress, + injAddress + }); const transferStringifyMemo = msgTransfers.map((transfer) => { this.stringifyMemos(transfer); diff --git a/packages/universal-swap/src/types.ts b/packages/universal-swap/src/types.ts index 69404b9a..c228f100 100644 --- a/packages/universal-swap/src/types.ts +++ b/packages/universal-swap/src/types.ts @@ -247,7 +247,7 @@ interface BridgeInfo { interface RouteBase { path: number; chainId: string; - type: string; + type: "Bridge" | "Swap" | string; tokenIn: string; tokenInAmount: string; tokenOut: string; @@ -255,7 +255,6 @@ interface RouteBase { } export interface Routes extends RouteBase { - type: "Bridge" | "Swap"; tokenOutChainId?: string; bridgeInfo?: BridgeInfo; swapInfo?: SwapInfo[]; From 89a2867c834a92351d00393b21e1e209b8f2d6df Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 24 May 2024 16:59:08 +0700 Subject: [PATCH 3/4] fix logic smart router --- .../src/universal-demos/alpha-smart-router.ts | 305 ------------------ 1 file changed, 305 deletions(-) diff --git a/packages/universal-swap/src/universal-demos/alpha-smart-router.ts b/packages/universal-swap/src/universal-demos/alpha-smart-router.ts index 7064a060..04e25671 100644 --- a/packages/universal-swap/src/universal-demos/alpha-smart-router.ts +++ b/packages/universal-swap/src/universal-demos/alpha-smart-router.ts @@ -61,318 +61,13 @@ const router = { ] }; -// const router = { -// swapAmount: "10000000", -// returnAmount: "86063044", -// routes: [ -// { -// swapAmount: "10000000", -// returnAmount: "86063044", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "10000000", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "86063044", -// tokenOutChainId: "Oraichain", -// actions: [ -// { -// type: "Swap", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "10000000", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "86063044", -// swapInfo: [ -// { -// poolId: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs", -// tokenOut: "orai" -// }, -// { -// poolId: "orai1m6q5k5nr2eh8q0rdrf57wr7phk7uvlpg7mwfv5", -// tokenOut: "orai1lus0f0rhx8s03gdllx2n6vhkmf0536dv57wfge" -// }, -// { -// poolId: "orai1n4edv5h86rawzrvhy8lmrmnnmmherxnhuwqnk3yuvt0wgclh75usyn3md6", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd" -// } -// ] -// } -// ] -// } -// ] -// } -// ] -// }; - -// const router = { -// swapAmount: "1000000000", -// returnAmount: "8518615211", -// routes: [ -// { -// swapAmount: "500000000", -// returnAmount: "4259030486", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "500000000", -// tokenOut: "uatom", -// tokenOutAmount: "500000000", -// tokenOutChainId: "cosmoshub-4", -// actions: [ -// { -// type: "Bridge", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "500000000", -// tokenOut: "uatom", -// tokenOutAmount: "500000000", -// tokenOutChainId: "cosmoshub-4", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-15" -// } -// } -// ] -// }, -// { -// chainId: "cosmoshub-4", -// tokenIn: "uatom", -// tokenInAmount: "500000000", -// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenOutAmount: "500000000", -// tokenOutChainId: "osmosis-1", -// actions: [ -// { -// type: "Bridge", -// tokenIn: "uatom", -// tokenInAmount: "500000000", -// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenOutAmount: "500000000", -// tokenOutChainId: "osmosis-1", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-141" -// } -// } -// ] -// }, -// { -// chainId: "osmosis-1", -// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenInAmount: "500000000", -// tokenOut: "uusdc", -// tokenOutAmount: "4267957444", -// tokenOutChainId: "noble-1", -// actions: [ -// { -// type: "Swap", -// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenInAmount: "500000000", -// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", -// tokenOutAmount: "4272229674", -// swapInfo: [ -// { -// poolId: "1282", -// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4" -// } -// ] -// }, -// { -// type: "Bridge", -// tokenIn: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", -// tokenInAmount: "4272229674", -// tokenOut: "uusdc", -// tokenOutAmount: "4267957444", -// tokenOutChainId: "noble-1", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-750" -// } -// } -// ] -// }, -// { -// chainId: "noble-1", -// tokenIn: "uusdc", -// tokenInAmount: "4267957444", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "4259030486", -// tokenOutChainId: "Oraichain", -// actions: [ -// { -// type: "Bridge", -// tokenIn: "uusdc", -// tokenInAmount: "4267957444", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "4259030486", -// tokenOutChainId: "Oraichain", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-34" -// } -// } -// ] -// } -// ] -// }, -// { -// swapAmount: "400000000", -// returnAmount: "3402135656", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "400000000", -// tokenOut: "uatom", -// tokenOutAmount: "400000000", -// tokenOutChainId: "cosmoshub-4", -// actions: [ -// { -// type: "Bridge", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "400000000", -// tokenOut: "uatom", -// tokenOutAmount: "400000000", -// tokenOutChainId: "cosmoshub-4", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-15" -// } -// } -// ] -// }, -// { -// chainId: "cosmoshub-4", -// tokenIn: "uatom", -// tokenInAmount: "400000000", -// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenOutAmount: "400000000", -// tokenOutChainId: "osmosis-1", -// actions: [ -// { -// type: "Bridge", -// tokenIn: "uatom", -// tokenInAmount: "400000000", -// tokenOut: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenOutAmount: "400000000", -// tokenOutChainId: "osmosis-1", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-141" -// } -// } -// ] -// }, -// { -// chainId: "osmosis-1", -// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenInAmount: "400000000", -// tokenOut: "uusdc", -// tokenOutAmount: "3410204861", -// tokenOutChainId: "noble-1", -// actions: [ -// { -// type: "Swap", -// tokenIn: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", -// tokenInAmount: "400000000", -// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", -// tokenOutAmount: "3413618480", -// swapInfo: [ -// { -// poolId: "1251", -// tokenOut: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4" -// } -// ] -// }, -// { -// type: "Bridge", -// tokenIn: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", -// tokenInAmount: "3413618480", -// tokenOut: "uusdc", -// tokenOutAmount: "3410204861", -// tokenOutChainId: "noble-1", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-750" -// } -// } -// ] -// }, -// { -// chainId: "noble-1", -// tokenIn: "uusdc", -// tokenInAmount: "3410204861", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "3402135656", -// tokenOutChainId: "Oraichain", -// actions: [ -// { -// type: "Bridge", -// tokenIn: "uusdc", -// tokenInAmount: "3410204861", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "3402135656", -// tokenOutChainId: "Oraichain", -// bridgeInfo: { -// port: "transfer", -// channel: "channel-34" -// } -// } -// ] -// } -// ] -// }, -// { -// swapAmount: "100000000", -// returnAmount: "857449069", -// paths: [ -// { -// chainId: "Oraichain", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "100000000", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "857449069", -// tokenOutChainId: "Oraichain", -// actions: [ -// { -// type: "Swap", -// tokenIn: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", -// tokenInAmount: "100000000", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd", -// tokenOutAmount: "857449069", -// swapInfo: [ -// { -// poolId: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs", -// tokenOut: "orai" -// }, -// { -// poolId: "orai1m6q5k5nr2eh8q0rdrf57wr7phk7uvlpg7mwfv5", -// tokenOut: "orai1lus0f0rhx8s03gdllx2n6vhkmf0536dv57wfge" -// }, -// { -// poolId: "orai1n4edv5h86rawzrvhy8lmrmnnmmherxnhuwqnk3yuvt0wgclh75usyn3md6", -// tokenOut: "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd" -// } -// ] -// } -// ] -// } -// ] -// } -// ] -// }; - const alphaSwapToOraichain = async () => { const wallet = new CosmosWalletImpl(process.env.MNEMONIC); const sender = await wallet.getKeplrAddr("cosmoshub-4"); const fromAmount = 0.1; console.log("sender: ", sender); const originalFromToken = cosmosTokens.find((t) => t.coinGeckoId === "cosmos" && t.chainId === "cosmoshub-4"); - const originalToToken = cosmosTokens.find((t) => t.coinGeckoId === "osmosis" && t.chainId === "osmosis-1"); - // const originalFromToken = getTokenOnOraichain("cosmos"); - // const originalToToken = getTokenOnOraichain("usd-coin"); if (!originalToToken) throw generateError("Could not find original to token"); if (!originalFromToken) throw generateError("Could not find original from token"); From 713d19a9e0411f55e3eb6c94ec3febbe8e7718ff Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 24 May 2024 17:06:07 +0700 Subject: [PATCH 4/4] update create rpc client --- packages/universal-swap/src/handler.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index f208b24f..ad007811 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -504,8 +504,7 @@ export class UniversalSwapHandler { const { client } = await this.config.cosmosWallet.getCosmWasmClient( { chainId: originalFromToken.chainId as CosmosChainId, - // rpc: originalFromToken.rpc - rpc: "https://cosmos-rpc.publicnode.com:443" + rpc: originalFromToken.rpc }, { gasPrice: this.getGasPriceFromToken()