From 47561a74c212470c9a81db262298ff5fd7fdd954 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 19 Sep 2024 14:50:30 +0700 Subject: [PATCH 01/16] add config pepe meme --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/constant.ts | 6 +++++- packages/oraidex-common/src/network.ts | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index e8f1b588..67356047 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.8", + "version": "1.1.9", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/constant.ts b/packages/oraidex-common/src/constant.ts index cacdd8c0..494419ae 100644 --- a/packages/oraidex-common/src/constant.ts +++ b/packages/oraidex-common/src/constant.ts @@ -53,6 +53,8 @@ export const USDT_BSC_CONTRACT = "0x55d398326f99059fF775485246999027B3197955"; export const WRAP_BNB_CONTRACT = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"; export const KWT_BSC_CONTRACT = "0x257a8d1E03D17B8535a182301f15290F11674b53"; export const MILKY_BSC_CONTRACT = "0x6fE3d0F096FC932A905accd1EB1783F6e4cEc717"; +export const PEPE_BSC_CONTRACT = "0x25d887Ce7a35172C62FeBFD67a1856F20FaEbB00"; +export const CAT_BSC_CONTRACT = "0x6894CDe390a3f51155ea41Ed24a33A4827d3063D"; // tron contracts export const USDT_TRON_CONTRACT = "0xa614f803B6FD780986A42c78Ec9c7f77e6DeD13C"; export const WRAP_TRON_TRX_CONTRACT = "0x891cdb91d149f23B1a45D9c5Ca78a88d0cB44C18"; @@ -67,7 +69,7 @@ export const KWT_DENOM = ORAI_BRIDGE_EVM_DENOM_PREFIX + KWT_BSC_CONTRACT; export const MILKY_DENOM = ORAI_BRIDGE_EVM_DENOM_PREFIX + MILKY_BSC_CONTRACT; export const USDT_ETH_CONTRACT = "0xdAC17F958D2ee523a2206206994597C13D831ec7"; export const ORAIX_ETH_CONTRACT = "0x2d869aE129e308F94Cc47E66eaefb448CEe0d03e"; - +export const PEPE_ETH_CONTRACT = "0x6982508145454Ce325dDbE47a25d4ec3d2311933"; // config for relayer export const ATOM_ORAICHAIN_CHANNELS = "channel-301 channel-15"; // export const ATOM_ORAICHAIN_CHANNELS="channel-642 channel-124" @@ -95,6 +97,8 @@ export const INJECTIVE_ORAICHAIN_DENOM = "ibc/49D820DFDE9F885D7081725A58202ABA2F export const ORAIIBC_INJECTIVE_DENOM = "ibc/C20C0A822BD22B2CEF0D067400FCCFB6FAEEE9E91D360B4E0725BD522302D565"; export const TON_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/ton"; +export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/pepe"; +export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/cat"; // config for oraichain token export const AIRI_CONTRACT = "orai10ldgzued6zjp0mkqwsv2mux3ml50l97c74x8sg"; diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index 0d84c000..90b4de9f 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -113,7 +113,9 @@ export type CoinGeckoId = | "neutaro" | "och" | "celestia" - | "the-open-network"; + | "the-open-network" + | "pepe" + | "simon-s-cat"; export type NetworkType = "cosmos" | "evm"; export interface NetworkConfig { From ebc5dad4f75e07d82fae8ce2a25c0f1e54979f88 Mon Sep 17 00:00:00 2001 From: trung2891 Date: Thu, 19 Sep 2024 15:18:51 +0700 Subject: [PATCH 02/16] chore: register pepe & cat in bridge --- packages/oraidex-common/src/network.ts | 78 +++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index 90b4de9f..bc2227eb 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -54,7 +54,12 @@ import { ORAIDEX_BID_POOL_CONTRACT, ORAIX_ETH_CONTRACT, MIXED_ROUTER, - AMM_V3_CONTRACT + AMM_V3_CONTRACT, + PEPE_ORAICHAIN_DENOM, + CAT_ORAICHAIN_DENOM, + PEPE_ETH_CONTRACT, + PEPE_BSC_CONTRACT, + CAT_BSC_CONTRACT } from "./constant"; import { listOsmosisToken } from "./alpha-network"; @@ -504,6 +509,22 @@ export const oraichainNetwork: CustomChainInfo = { coinDecimals: 9, coinGeckoId: "the-open-network", coinImageUrl: "https://assets.coingecko.com/coins/images/17980/standard/ton_symbol.png?1696517498" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: PEPE_ORAICHAIN_DENOM, + coinDecimals: 18, + coinGeckoId: "pepe", + bridgeTo: ["0x01", "0x38"], + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "CAT", + coinMinimalDenom: CAT_ORAICHAIN_DENOM, + coinDecimals: 18, + bridgeTo: ["0x38"], + coinGeckoId: "simon-s-cat", + coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } ] }; @@ -639,6 +660,33 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "oraidex", prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX, coinImageUrl: "https://i.ibb.co/VmMJtf7/oraix.png" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX + PEPE_ETH_CONTRACT, + bridgeNetworkIdentifier: "0x01", + coinDecimals: 18, + coinGeckoId: "pepe", + prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX, + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: ORAI_BRIDGE_EVM_DENOM_PREFIX + PEPE_BSC_CONTRACT, + bridgeNetworkIdentifier: "0x38", + coinDecimals: 18, + coinGeckoId: "pepe", + prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX, + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "CAT", + coinMinimalDenom: ORAI_BRIDGE_EVM_DENOM_PREFIX + CAT_BSC_CONTRACT, + bridgeNetworkIdentifier: "0x38", + coinDecimals: 18, + coinGeckoId: "simon-s-cat", + prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX, + coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } ], txExplorer: { @@ -936,6 +984,16 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "oraidex", prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX, coinImageUrl: "https://i.ibb.co/VmMJtf7/oraix.png" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: "erc20_pepe", + contractAddress: PEPE_ETH_CONTRACT, + coinDecimals: 18, + bridgeTo: ["Oraichain"], + coinGeckoId: "pepe", + prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX, + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" } ], txExplorer: { @@ -1057,6 +1115,24 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "binancecoin", bridgeTo: ["Oraichain"], coinImageUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/1839.png" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: "bep20_pepe", + contractAddress: PEPE_BSC_CONTRACT, + coinDecimals: 18, + coinGeckoId: "pepe", + bridgeTo: ["Oraichain"], + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "CAT", + coinMinimalDenom: "bep20_cat", + contractAddress: CAT_BSC_CONTRACT, + coinDecimals: 18, + coinGeckoId: "simon-s-cat", + bridgeTo: ["Oraichain"], + coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } ], txExplorer: { From 4d523eb24050a221dbe19048c62e69ab63678ce8 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 19 Sep 2024 16:33:58 +0700 Subject: [PATCH 03/16] add pepe cat --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/helper.ts | 21 ++++- packages/oraidex-common/src/network.ts | 77 ++++++++++++++++++- packages/universal-swap/package.json | 2 +- packages/universal-swap/src/handler.ts | 17 ++-- .../universal-demos/from-oraichain-to-evm.ts | 56 ++++++++++++++ 6 files changed, 157 insertions(+), 18 deletions(-) create mode 100644 packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index 67356047..46418ef6 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.9", + "version": "1.1.10", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/helper.ts b/packages/oraidex-common/src/helper.ts index 554bb3b5..9e7baa93 100644 --- a/packages/oraidex-common/src/helper.ts +++ b/packages/oraidex-common/src/helper.ts @@ -252,10 +252,23 @@ export const getTokenOnSpecificChainId = ( return flattenTokens.find((t) => t.coinGeckoId === coingeckoId && t.chainId === chainId); }; -export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, decimals?: number) => { - return oraichainTokens.find( - (token) => token.coinGeckoId === coingeckoId && token.decimals === (decimals || CW20_DECIMALS) - ); +/** + * This function get token on oraichain from coingeckoId + * @param coingeckoId - coingeckoId of tokenInOraichain + * @param isNative - isNative token + * @returns token on oraichain + */ + +export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => { + const filterOraichainToken = oraichainTokens.filter((orai) => orai.coinGeckoId === coingeckoId); + if (!filterOraichainToken.length) throw new Error("Cannot find token on Oraichain!"); + + if (filterOraichainToken.length === 1) return filterOraichainToken[0]; + + const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms)); + if (!oraichainToken) throw new Error("Cannot find token isNative on Oraichain!"); + + return oraichainToken; }; export const parseTokenInfoRawDenom = (tokenInfo: TokenItemType) => { diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index 90b4de9f..7fe1801b 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -54,7 +54,12 @@ import { ORAIDEX_BID_POOL_CONTRACT, ORAIX_ETH_CONTRACT, MIXED_ROUTER, - AMM_V3_CONTRACT + AMM_V3_CONTRACT, + PEPE_BSC_CONTRACT, + PEPE_ORAICHAIN_DENOM, + CAT_ORAICHAIN_DENOM, + PEPE_ETH_CONTRACT, + CAT_BSC_CONTRACT } from "./constant"; import { listOsmosisToken } from "./alpha-network"; @@ -319,6 +324,22 @@ export const oraichainNetwork: CustomChainInfo = { }, currencies: [ OraiToken, + { + coinDenom: "PEPE", + coinGeckoId: "pepe", + coinMinimalDenom: PEPE_ORAICHAIN_DENOM, + bridgeTo: ["0x38", "0x01"], + coinDecimals: 18, + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "CAT", + coinMinimalDenom: CAT_ORAICHAIN_DENOM, + coinDecimals: 18, + bridgeTo: ["0x38"], + coinGeckoId: "simon-s-cat", + coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" + }, { coinDenom: "ATOM", coinGeckoId: "cosmos", @@ -639,6 +660,33 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "oraidex", prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX, coinImageUrl: "https://i.ibb.co/VmMJtf7/oraix.png" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: ORAI_BRIDGE_EVM_DENOM_PREFIX + PEPE_BSC_CONTRACT, + bridgeNetworkIdentifier: "0x38", + coinDecimals: 18, + coinGeckoId: "pepe", + prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX, + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX + PEPE_ETH_CONTRACT, + bridgeNetworkIdentifier: "0x01", + coinDecimals: 18, + coinGeckoId: "pepe", + prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX, + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "CAT", + coinMinimalDenom: ORAI_BRIDGE_EVM_DENOM_PREFIX + CAT_BSC_CONTRACT, + bridgeNetworkIdentifier: "0x38", + coinDecimals: 18, + prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX, + coinGeckoId: "simon-s-cat", + coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } ], txExplorer: { @@ -971,6 +1019,15 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "tron", prefixToken: ORAI_BRIDGE_EVM_TRON_DENOM_PREFIX, coinImageUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/1958.png" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: "pepe", + contractAddress: PEPE_ETH_CONTRACT, + coinDecimals: 18, + coinGeckoId: "pepe", + bridgeTo: ["Oraichain"], + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" } ], bip44: { @@ -1057,6 +1114,24 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "binancecoin", bridgeTo: ["Oraichain"], coinImageUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/1839.png" + }, + { + coinDenom: "PEPE", + coinMinimalDenom: "pepe", + contractAddress: PEPE_BSC_CONTRACT, + coinDecimals: 18, + coinGeckoId: "pepe", + bridgeTo: ["Oraichain"], + coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" + }, + { + coinDenom: "CAT", + coinMinimalDenom: "cat", + contractAddress: CAT_BSC_CONTRACT, + coinDecimals: 18, + coinGeckoId: "simon-s-cat", + bridgeTo: ["Oraichain"], + coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } ], txExplorer: { diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index 9a9eb3c3..7839975f 100644 --- a/packages/universal-swap/package.json +++ b/packages/universal-swap/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-universal-swap", - "version": "1.1.5", + "version": "1.1.5-beta.1", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index 79521440..4e6b5085 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -71,8 +71,8 @@ export class UniversalSwapHandler { private readonly currentTimestamp = Date.now() ) {} - private getTokenOnOraichain(coinGeckoId: CoinGeckoId, decimals?: number): TokenItemType { - const fromTokenOnOrai = getTokenOnOraichain(coinGeckoId, decimals); + private getTokenOnOraichain(coinGeckoId: CoinGeckoId, isNative?: boolean): TokenItemType { + const fromTokenOnOrai = getTokenOnOraichain(coinGeckoId, isNative); if (!fromTokenOnOrai) throw generateError(`Could not find token ${coinGeckoId} on Oraichain. Could not swap`); return fromTokenOnOrai; } @@ -137,10 +137,7 @@ export class UniversalSwapHandler { let toTokenInOrai = this.getTokenOnOraichain(toCoinGeckoId); const isSpecialChain = ["kawaii_6886-1", "injective-1"].includes(toChainId); const isSpecialCoingecko = ["kawaii-islands", "milky-token", "injective-protocol"].includes(toCoinGeckoId); - if (isSpecialChain && isSpecialCoingecko) { - const IBC_DECIMALS = 18; - toTokenInOrai = this.getTokenOnOraichain(toCoinGeckoId, IBC_DECIMALS); - } + if (isSpecialChain && isSpecialCoingecko) toTokenInOrai = this.getTokenOnOraichain(toCoinGeckoId, true); let msgTransfer: EncodeObject[]; // if ibc info source has wasm in it, it means we need to transfer IBC using IBC wasm contract, not normal ibc transfer @@ -280,7 +277,7 @@ export class UniversalSwapHandler { let getEncodedExecuteMsgs = []; if (["kawaii-islands", "milky-token"].includes(originalToToken.coinGeckoId)) { const IBC_DECIMALS = 18; - const toTokenInOrai = this.getTokenOnOraichain(originalToToken.coinGeckoId, IBC_DECIMALS); + const toTokenInOrai = this.getTokenOnOraichain(originalToToken.coinGeckoId, true); const evmToken = tokenMap[toTokenInOrai.denom]; const evmAmount = coin(toAmount(this.swapData.fromAmount, evmToken.decimals).toString(), evmToken.denom); const msgConvertReverses = UniversalSwapHelper.generateConvertCw20Erc20Message( @@ -1250,8 +1247,7 @@ export class UniversalSwapHandler { generateMsgsSmartRouterSwap(route: Routes, isLastRoute: boolean) { let contractAddr: string = network.mixer_router; const { originalFromToken, fromAmount, affiliates, userSlippage } = this.swapData; - let decimals = originalFromToken.denom === TON_ORAICHAIN_DENOM ? originalFromToken.decimals : undefined; - const fromTokenOnOrai = this.getTokenOnOraichain(originalFromToken.coinGeckoId, decimals); + 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) { @@ -1280,8 +1276,7 @@ export class UniversalSwapHandler { let contractAddr: string = network.mixer_router; const { originalFromToken, originalToToken, fromAmount, affiliates, userSlippage } = this.swapData; // since we're swapping on Oraichain, we need to get from token on Oraichain - let decimals = originalFromToken.denom === TON_ORAICHAIN_DENOM ? originalFromToken.decimals : undefined; - const fromTokenOnOrai = this.getTokenOnOraichain(originalFromToken.coinGeckoId, decimals); + const fromTokenOnOrai = this.getTokenOnOraichain(originalFromToken.coinGeckoId); const toTokenInOrai = this.getTokenOnOraichain(originalToToken.coinGeckoId); try { const _fromAmount = toAmount(fromAmount, fromTokenOnOrai.decimals).toString(); diff --git a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts new file mode 100644 index 00000000..ae1cc9b2 --- /dev/null +++ b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts @@ -0,0 +1,56 @@ +import "dotenv/config"; +import { CosmosWalletImpl } from "./offline-wallet"; +import { UniversalSwapHandler } from "../handler"; +import { flattenTokens, generateError, toAmount } from "@oraichain/oraidex-common"; +import { UniversalSwapHelper } from "../helper"; + +const oraichainToEvm = async () => { + console.log({ abc: "11111" }); + + const chainId = "Oraichain"; + const wallet = new CosmosWalletImpl(process.env.MNEMONIC); + + const sender = await wallet.getKeplrAddr(chainId); + const fromAmount = 100; + let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe"); + + let originalToToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe"); + + if (!originalFromToken) throw generateError("Could not find original from token"); + if (!originalToToken) throw generateError("Could not find original to token"); + + const smartRoutes = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ + fromInfo: originalFromToken, + toInfo: originalToToken, + amount: toAmount(fromAmount, originalToToken.decimals).toString() + }); + + console.log("expected amount: ", smartRoutes.returnAmount); + const universalHandler = new UniversalSwapHandler( + { + originalFromToken, + originalToToken, + sender: { cosmos: sender }, + relayerFee: { + relayerAmount: "0", + relayerDecimals: 6 + }, + simulatePrice: "1", + fromAmount, + simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(), + userSlippage: 0.01 + }, + { cosmosWallet: wallet, swapOptions: {} } + ); + + try { + const result = await universalHandler.processUniversalSwap(); + console.log("result: ", result); + } catch (error) { + console.log("error: ", error); + } +}; + +(() => { + return oraichainToEvm(); +})(); From 396650865ce0d868af00a33ad2ef049ee3b6578a Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 19 Sep 2024 17:38:00 +0700 Subject: [PATCH 04/16] remove duplicat token pepe cat in oraichain --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/network.ts | 25 ---------------- .../universal-demos/from-oraichain-to-evm.ts | 29 +++++++++++-------- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index 46418ef6..25fd0825 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.10", + "version": "1.1.11", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index badcea9e..dea95c5b 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -525,22 +525,6 @@ export const oraichainNetwork: CustomChainInfo = { coinDecimals: 9, coinGeckoId: "the-open-network", coinImageUrl: "https://assets.coingecko.com/coins/images/17980/standard/ton_symbol.png?1696517498" - }, - { - coinDenom: "PEPE", - coinMinimalDenom: PEPE_ORAICHAIN_DENOM, - coinDecimals: 18, - coinGeckoId: "pepe", - bridgeTo: ["0x01", "0x38"], - coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" - }, - { - coinDenom: "CAT", - coinMinimalDenom: CAT_ORAICHAIN_DENOM, - coinDecimals: 18, - bridgeTo: ["0x38"], - coinGeckoId: "simon-s-cat", - coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } ] }; @@ -1045,15 +1029,6 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "tron", prefixToken: ORAI_BRIDGE_EVM_TRON_DENOM_PREFIX, coinImageUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/1958.png" - }, - { - coinDenom: "PEPE", - coinMinimalDenom: "pepe", - contractAddress: PEPE_ETH_CONTRACT, - coinDecimals: 18, - coinGeckoId: "pepe", - bridgeTo: ["Oraichain"], - coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" } ], bip44: { diff --git a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts index ae1cc9b2..76fdf915 100644 --- a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts +++ b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts @@ -11,34 +11,39 @@ const oraichainToEvm = async () => { const wallet = new CosmosWalletImpl(process.env.MNEMONIC); const sender = await wallet.getKeplrAddr(chainId); - const fromAmount = 100; - let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe"); + const fromAmount = 10000; + let originalToToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe"); - let originalToToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe"); + let originalFromToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe"); if (!originalFromToken) throw generateError("Could not find original from token"); if (!originalToToken) throw generateError("Could not find original to token"); - const smartRoutes = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ - fromInfo: originalFromToken, - toInfo: originalToToken, - amount: toAmount(fromAmount, originalToToken.decimals).toString() + console.log({ + originalToToken, + originalFromToken }); - console.log("expected amount: ", smartRoutes.returnAmount); + // const smartRoutes = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ + // fromInfo: originalFromToken, + // toInfo: originalToToken, + // amount: toAmount(fromAmount, originalToToken.decimals).toString() + // }); + + // console.log("expected amount: ", smartRoutes.returnAmount); const universalHandler = new UniversalSwapHandler( { originalFromToken, originalToToken, - sender: { cosmos: sender }, + sender: { cosmos: sender, evm: "0x8c7E0A841269a01c0Ab389Ce8Fb3Cf150A94E797" }, relayerFee: { - relayerAmount: "0", + relayerAmount: "100000", relayerDecimals: 6 }, - simulatePrice: "1", + simulatePrice: "10000000", fromAmount, simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(), - userSlippage: 0.01 + userSlippage: 1 }, { cosmosWallet: wallet, swapOptions: {} } ); From 365915fe92e965207be71c9c02cc02b254fe5502 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 19 Sep 2024 17:57:20 +0700 Subject: [PATCH 05/16] add config option check balance ibc --- packages/universal-swap/src/handler.ts | 39 +++++++++++++++----------- packages/universal-swap/src/types.ts | 1 + 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index 4e6b5085..b378ac12 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -950,15 +950,18 @@ export class UniversalSwapHandler { default: throw generateError(`Universal swap type ${universalSwapType} is wrong. Should not call this function!`); } - const ibcInfo = this.getIbcInfo("Oraichain", originalToToken.chainId); - await UniversalSwapHelper.checkBalanceChannelIbc( - ibcInfo, - originalFromToken, - originalToToken, - simulateAmount, - client, - this.getCwIcs20ContractAddr() - ); + + if (!this.config?.swapOptions?.isCheckBalanceIbc) { + const ibcInfo = this.getIbcInfo("Oraichain", originalToToken.chainId); + await UniversalSwapHelper.checkBalanceChannelIbc( + ibcInfo, + originalFromToken, + originalToToken, + simulateAmount, + client, + this.getCwIcs20ContractAddr() + ); + } // handle sign and broadcast transactions return client.signAndBroadcast(sender.cosmos, encodedObjects, "auto"); @@ -1027,14 +1030,16 @@ export class UniversalSwapHandler { return this.evmSwap(evmSwapData); } - await UniversalSwapHelper.checkBalanceIBCOraichain( - originalToToken, - originalFromToken, - fromAmount, - simulateAmount, - client, - this.getCwIcs20ContractAddr() - ); + if (!this.config?.swapOptions?.isCheckBalanceIbc) { + await UniversalSwapHelper.checkBalanceIBCOraichain( + originalToToken, + originalFromToken, + fromAmount, + simulateAmount, + client, + this.getCwIcs20ContractAddr() + ); + } const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router); const isSufficient = await UniversalSwapHelper.checkFeeRelayer({ diff --git a/packages/universal-swap/src/types.ts b/packages/universal-swap/src/types.ts index d234c5e7..3b15930e 100644 --- a/packages/universal-swap/src/types.ts +++ b/packages/universal-swap/src/types.ts @@ -89,6 +89,7 @@ export interface SwapOptions { isSourceReceiverTest?: boolean; isAlphaSmartRouter?: boolean; isIbcWasm?: boolean; + isCheckBalanceIbc?: boolean; } export enum Type { From 4af2400361258c990796878208ce8b851410d47b Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Thu, 19 Sep 2024 21:58:43 +0700 Subject: [PATCH 06/16] add pepe with cat --- packages/universal-swap/package.json | 2 +- packages/universal-swap/src/handler.ts | 55 ++++++++++--------- .../universal-demos/from-oraichain-to-evm.ts | 9 ++- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index 7839975f..96fc3523 100644 --- a/packages/universal-swap/package.json +++ b/packages/universal-swap/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-universal-swap", - "version": "1.1.5-beta.1", + "version": "1.1.5-beta.3", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index b378ac12..a2786576 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -934,17 +934,20 @@ export class UniversalSwapHandler { break; case "oraichain-to-evm": const { evm: metamaskAddress, tron: tronAddress } = this.swapData.sender; - const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router); - const isSufficient = await UniversalSwapHelper.checkFeeRelayer({ - originalFromToken: this.swapData.originalFromToken, - fromAmount: this.swapData.fromAmount, - relayerFee: this.swapData.relayerFee, - routerClient - }); - if (!isSufficient) - throw generateError( - `Your swap amount ${this.swapData.fromAmount} cannot cover the fees for this transaction. Please try again with a higher swap amount` - ); + if (!this.config?.swapOptions?.isCheckBalanceIbc) { + const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router); + const isSufficient = await UniversalSwapHelper.checkFeeRelayer({ + originalFromToken: this.swapData.originalFromToken, + fromAmount: this.swapData.fromAmount, + relayerFee: this.swapData.relayerFee, + routerClient + }); + if (!isSufficient) + throw generateError( + `Your swap amount ${this.swapData.fromAmount} cannot cover the fees for this transaction. Please try again with a higher swap amount` + ); + } + encodedObjects = await this.combineMsgEvm(metamaskAddress, tronAddress); break; default: @@ -1009,9 +1012,9 @@ export class UniversalSwapHandler { simulatePrice: simulatePrice }; // has to switch network to the correct chain id on evm since users can swap between network tokens - if (!this.config.evmWallet.isTron(originalFromToken.chainId)) - await this.config.evmWallet.switchNetwork(originalFromToken.chainId); - if (UniversalSwapHelper.isEvmSwappable(swappableData)) return this.evmSwap(evmSwapData); + // if (!this.config.evmWallet.isTron(originalFromToken.chainId)) + // await this.config.evmWallet.switchNetwork(originalFromToken.chainId); + // if (UniversalSwapHelper.isEvmSwappable(swappableData)) return this.evmSwap(evmSwapData); const toTokenSameFromChainId = getTokenOnSpecificChainId(originalToToken.coinGeckoId, originalFromToken.chainId); if (toTokenSameFromChainId) { @@ -1039,19 +1042,19 @@ export class UniversalSwapHandler { client, this.getCwIcs20ContractAddr() ); - } - const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router); - const isSufficient = await UniversalSwapHelper.checkFeeRelayer({ - originalFromToken, - fromAmount, - relayerFee, - routerClient - }); - if (!isSufficient) - throw generateError( - `Your swap amount ${fromAmount} cannot cover the fees for this transaction. Please try again with a higher swap amount` - ); + const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router); + const isSufficient = await UniversalSwapHelper.checkFeeRelayer({ + originalFromToken, + fromAmount, + relayerFee, + routerClient + }); + if (!isSufficient) + throw generateError( + `Your swap amount ${fromAmount} cannot cover the fees for this transaction. Please try again with a higher swap amount` + ); + } return this.transferEvmToIBC(swapRoute); } diff --git a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts index 76fdf915..0e0f3c9b 100644 --- a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts +++ b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts @@ -45,7 +45,14 @@ const oraichainToEvm = async () => { simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(), userSlippage: 1 }, - { cosmosWallet: wallet, swapOptions: {} } + { + cosmosWallet: wallet, + swapOptions: { + isAlphaSmartRouter: true, + isIbcWasm: true, + isCheckBalanceIbc: true + } + } ); try { From d6972f1bebe9a3101d99cd068dc52bb523a5fff7 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 20 Sep 2024 14:52:32 +0700 Subject: [PATCH 07/16] fix getTokenOnOraichain --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/helper.ts | 5 +---- .../universal-demos/from-oraichain-to-evm.ts | 19 ++++++------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index 25fd0825..bb3e0b33 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.11", + "version": "1.1.12", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/helper.ts b/packages/oraidex-common/src/helper.ts index 9e7baa93..9729c5df 100644 --- a/packages/oraidex-common/src/helper.ts +++ b/packages/oraidex-common/src/helper.ts @@ -261,13 +261,10 @@ export const getTokenOnSpecificChainId = ( export const getTokenOnOraichain = (coingeckoId: CoinGeckoId, isNative?: boolean) => { const filterOraichainToken = oraichainTokens.filter((orai) => orai.coinGeckoId === coingeckoId); - if (!filterOraichainToken.length) throw new Error("Cannot find token on Oraichain!"); - + if (!filterOraichainToken.length) return undefined; if (filterOraichainToken.length === 1) return filterOraichainToken[0]; const oraichainToken = filterOraichainToken.find((token) => (isNative ? !token.evmDenoms : token.evmDenoms)); - if (!oraichainToken) throw new Error("Cannot find token isNative on Oraichain!"); - return oraichainToken; }; diff --git a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts index 0e0f3c9b..08920391 100644 --- a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts +++ b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts @@ -5,25 +5,18 @@ import { flattenTokens, generateError, toAmount } from "@oraichain/oraidex-commo import { UniversalSwapHelper } from "../helper"; const oraichainToEvm = async () => { - console.log({ abc: "11111" }); - const chainId = "Oraichain"; const wallet = new CosmosWalletImpl(process.env.MNEMONIC); const sender = await wallet.getKeplrAddr(chainId); - const fromAmount = 10000; - let originalToToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe"); + const fromAmount = 1000; + let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe"); - let originalFromToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe"); + let originalToToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe"); if (!originalFromToken) throw generateError("Could not find original from token"); if (!originalToToken) throw generateError("Could not find original to token"); - console.log({ - originalToToken, - originalFromToken - }); - // const smartRoutes = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ // fromInfo: originalFromToken, // toInfo: originalToToken, @@ -40,7 +33,7 @@ const oraichainToEvm = async () => { relayerAmount: "100000", relayerDecimals: 6 }, - simulatePrice: "10000000", + simulatePrice: toAmount(1, originalToToken.decimals).toString(), fromAmount, simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(), userSlippage: 1 @@ -48,8 +41,8 @@ const oraichainToEvm = async () => { { cosmosWallet: wallet, swapOptions: { - isAlphaSmartRouter: true, - isIbcWasm: true, + isAlphaSmartRouter: false, + isIbcWasm: false, isCheckBalanceIbc: true } } From d62e07ab8faffb428b47dd72c7af372b119764ef Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 23 Sep 2024 11:57:35 +0700 Subject: [PATCH 08/16] feat add pepe cat --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/constant.ts | 7 +++++-- packages/oraidex-common/src/network.ts | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index bb3e0b33..f3efc4dc 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.12", + "version": "1.1.13", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/constant.ts b/packages/oraidex-common/src/constant.ts index 494419ae..819d0542 100644 --- a/packages/oraidex-common/src/constant.ts +++ b/packages/oraidex-common/src/constant.ts @@ -97,8 +97,11 @@ export const INJECTIVE_ORAICHAIN_DENOM = "ibc/49D820DFDE9F885D7081725A58202ABA2F export const ORAIIBC_INJECTIVE_DENOM = "ibc/C20C0A822BD22B2CEF0D067400FCCFB6FAEEE9E91D360B4E0725BD522302D565"; export const TON_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/ton"; -export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/pepe"; -export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/cat"; +// export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/pepe"; +// export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/cat"; + +export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extCAT"; +export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extPEPE"; // config for oraichain token export const AIRI_CONTRACT = "orai10ldgzued6zjp0mkqwsv2mux3ml50l97c74x8sg"; diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index dea95c5b..320ff723 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -329,13 +329,13 @@ export const oraichainNetwork: CustomChainInfo = { coinGeckoId: "pepe", coinMinimalDenom: PEPE_ORAICHAIN_DENOM, bridgeTo: ["0x38", "0x01"], - coinDecimals: 18, + coinDecimals: 6, coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" }, { coinDenom: "CAT", coinMinimalDenom: CAT_ORAICHAIN_DENOM, - coinDecimals: 18, + coinDecimals: 6, bridgeTo: ["0x38"], coinGeckoId: "simon-s-cat", coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" From 2e02a833304384acc8026a61fcd236a64d1dd2f1 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 23 Sep 2024 11:59:49 +0700 Subject: [PATCH 09/16] feat add pepe cat version common 1.1.14 --- packages/oraidex-common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index f3efc4dc..f9754510 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.13", + "version": "1.1.14", "main": "build/index.js", "files": [ "build/" From 4b46a6e8eab8292b91de1be9a3c832529c397834 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 23 Sep 2024 14:26:45 +0700 Subject: [PATCH 10/16] pumb common 1.1.15 --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/constant.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index f9754510..797f18af 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.14", + "version": "1.1.15", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/constant.ts b/packages/oraidex-common/src/constant.ts index 819d0542..6227f0ff 100644 --- a/packages/oraidex-common/src/constant.ts +++ b/packages/oraidex-common/src/constant.ts @@ -100,8 +100,8 @@ export const TON_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3q // export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/pepe"; // export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/cat"; -export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extCAT"; -export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extPEPE"; +export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extPEPE"; +export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extCAT"; // config for oraichain token export const AIRI_CONTRACT = "orai10ldgzued6zjp0mkqwsv2mux3ml50l97c74x8sg"; From e8ca9beb64b78b6f3e4c304e260cd0616df39577 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 23 Sep 2024 17:43:40 +0700 Subject: [PATCH 11/16] fix simulate relayer fee --- packages/universal-swap/package.json | 2 +- packages/universal-swap/src/handler.ts | 20 ++++++++++++++----- .../universal-demos/from-oraichain-to-evm.ts | 20 ++++++++++--------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index 96fc3523..294351cd 100644 --- a/packages/universal-swap/package.json +++ b/packages/universal-swap/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-universal-swap", - "version": "1.1.5-beta.3", + "version": "1.1.6", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index a2786576..7269d3f3 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -1224,11 +1224,21 @@ export class UniversalSwapHandler { ); if (!!subRelayerFee) { const routerClient = new OraiswapRouterQueryClient(client, network.mixer_router); - const { amount } = await UniversalSwapHelper.simulateSwap({ - fromInfo: this.getTokenOnOraichain("oraichain-token"), - toInfo: this.getTokenOnOraichain(originalToToken.coinGeckoId), - amount: subRelayerFee, - routerClient + const { amount } = await UniversalSwapHelper.handleSimulateSwap({ + originalFromInfo: this.getTokenOnOraichain("oraichain-token"), + originalToInfo: this.getTokenOnOraichain(originalToToken.coinGeckoId), + originalAmount: toDisplay(subRelayerFee), + routerClient: routerClient, + routerOption: { + useAlphaSmartRoute: true, + useIbcWasm: true + }, + routerConfig: { + url: "https://osor.oraidex.io", + path: "/smart-router/alpha-router", + protocols: ["Oraidex", "OraidexV3"], + dontAllowSwapAfter: ["Oraidex", "OraidexV3"] + } }); if (amount) subRelayerFee = amount; } diff --git a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts index 08920391..f7922cf5 100644 --- a/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts +++ b/packages/universal-swap/src/universal-demos/from-oraichain-to-evm.ts @@ -9,11 +9,13 @@ const oraichainToEvm = async () => { const wallet = new CosmosWalletImpl(process.env.MNEMONIC); const sender = await wallet.getKeplrAddr(chainId); - const fromAmount = 1000; + const fromAmount = 100; let originalFromToken = flattenTokens.find((t) => t.chainId === chainId && t.coinGeckoId === "pepe"); let originalToToken = flattenTokens.find((t) => t.chainId === "0x38" && t.coinGeckoId === "pepe"); + console.log({ originalFromToken, originalToToken }); + if (!originalFromToken) throw generateError("Could not find original from token"); if (!originalToToken) throw generateError("Could not find original to token"); @@ -29,20 +31,20 @@ const oraichainToEvm = async () => { originalFromToken, originalToToken, sender: { cosmos: sender, evm: "0x8c7E0A841269a01c0Ab389Ce8Fb3Cf150A94E797" }, - relayerFee: { - relayerAmount: "100000", - relayerDecimals: 6 - }, - simulatePrice: toAmount(1, originalToToken.decimals).toString(), + // relayerFee: { + // relayerAmount: "100000", + // relayerDecimals: 6 + // }, + simulatePrice: toAmount(1, originalFromToken.decimals).toString(), fromAmount, - simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(), + simulateAmount: toAmount(fromAmount, originalFromToken.decimals).toString(), userSlippage: 1 }, { cosmosWallet: wallet, swapOptions: { - isAlphaSmartRouter: false, - isIbcWasm: false, + isAlphaSmartRouter: true, + isIbcWasm: true, isCheckBalanceIbc: true } } From 764e2a136b72a229b05b8a9dfaac9cae37ab6df5 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 23 Sep 2024 22:53:31 +0700 Subject: [PATCH 12/16] refactor simulate and params isAlphaSmartRoute --- packages/universal-swap/src/handler.ts | 2 - packages/universal-swap/src/helper.ts | 82 +++++++++++--------------- packages/universal-swap/src/types.ts | 19 +----- 3 files changed, 38 insertions(+), 65 deletions(-) diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index 7269d3f3..9a2ea928 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -1190,9 +1190,7 @@ export class UniversalSwapHandler { obridgeAddress ); - // version alpha smart router oraiDEX pool + osmosis pool if ( - swapOptions?.isAlphaSmartRouter && this.swapData?.alphaSmartRoutes?.routes?.length && ["oraichain-to-oraichain", "oraichain-to-cosmos", "cosmos-to-others"].includes(universalSwapType) && !swapOptions?.isIbcWasm diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index 4b6a9db3..d2a76228 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -60,7 +60,6 @@ import { SimulateResponse, SmartRouteSwapOperations, SmartRouterResponse, - SmartRouterResponseAPI, SwapDirection, SwapOptions, SwapRoute, @@ -466,6 +465,9 @@ export class UniversalSwapHelper { return routeData; }; + /** + * @deprecated. Use UniversalSwapHelper.generateMsgsSmartRouterV2withV3 + */ static generateSwapRoute = (offerAsset: AssetInfo, askAsset: AssetInfo, swapRoute: AssetInfo[]) => { const swaps = []; if (swapRoute.length === 0) { @@ -500,7 +502,9 @@ export class UniversalSwapHelper { return swaps; }; - // generate messages + /** + * @deprecated. Use UniversalSwapHelper.generateMsgsSmartRouterV2withV3 + */ static generateSwapOperationMsgs = (offerInfo: AssetInfo, askInfo: AssetInfo): SwapOperation[] => { const pairExist = PAIRS.some((pair) => { const assetInfos = pair.asset_infos; @@ -534,7 +538,7 @@ export class UniversalSwapHelper { askChainId: string, offerAmount: string, routerConfig: RouterConfigSmartRoute - ): Promise => { + ): Promise => { const { axios } = await getAxios(routerConfig.url); const data = { sourceAsset: parseAssetInfo(offerInfo), @@ -548,7 +552,7 @@ export class UniversalSwapHelper { } }; const res: { - data: SmartRouterResponseAPI; + data: SmartRouterResponse; } = await axios.post(routerConfig.path, data); return { swapAmount: res.data.swapAmount, @@ -566,7 +570,7 @@ export class UniversalSwapHelper { routerConfig: RouterConfigSmartRoute = { url: "https://osor.oraidex.io", path: "/smart-router", - protocols: ["Oraidex", "OraidexV3", "Osmosis"], + protocols: ["Oraidex", "OraidexV3"], dontAllowSwapAfter: ["Oraidex", "OraidexV3"] } ): Promise => { @@ -738,51 +742,37 @@ export class UniversalSwapHelper { return { amount, displayAmount }; } - let amount; - let routes; - let decimals = 6; - if (query?.routerOption?.useAlphaSmartRoute) { - const fromInfo = query?.routerOption?.useIbcWasm - ? getTokenOnOraichain(query.originalFromInfo.coinGeckoId) - : query.originalFromInfo; - const toInfo = query?.routerOption?.useIbcWasm - ? getTokenOnOraichain(query.originalToInfo.coinGeckoId) - : query.originalToInfo; - - if (!fromInfo || !toInfo) - throw new Error(`Cannot find token on Oraichain for token ${fromInfo.coinGeckoId} and ${toInfo.coinGeckoId}`); - - const simulateRes: SmartRouterResponse = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ - fromInfo, - toInfo, - amount: toAmount(query.originalAmount, fromInfo.decimals).toString(), - routerConfig: query.routerConfig - }); + const routerConfigDefault = { + url: query?.routerConfig?.url ?? "https://osor.oraidex.io", + path: query?.routerConfig?.path ?? "/smart-router", + protocols: query?.routerConfig?.protocols ?? ["Oraidex", "OraidexV3"], + dontAllowSwapAfter: query?.routerConfig?.dontAllowSwapAfter ?? ["Oraidex", "OraidexV3"] + }; - routes = simulateRes; - amount = simulateRes.returnAmount; - decimals = toInfo.decimals; - } 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, - toInfo, - amount: toAmount(query.originalAmount, fromInfo.decimals).toString(), - routerClient: query.routerClient - }) - ).amount; - decimals = toInfo.decimals; + let fromInfo = getTokenOnOraichain(query.originalFromInfo.coinGeckoId); + let toInfo = getTokenOnOraichain(query.originalToInfo.coinGeckoId); + + if (!query?.routerOption?.useIbcWasm) { + fromInfo = query.originalFromInfo; + toInfo = query.originalToInfo; } + + if (!fromInfo || !toInfo) + throw new Error(`Cannot find token on Oraichain for token ${fromInfo.coinGeckoId} and ${toInfo.coinGeckoId}`); + + const simulateRes: SmartRouterResponse = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ + fromInfo, + toInfo, + amount: toAmount(query.originalAmount, fromInfo.decimals).toString(), + routerConfig: routerConfigDefault + }); + + const amount = simulateRes.returnAmount; + const routes = simulateRes; return { amount, - displayAmount: toDisplay(amount, decimals), - routes: routes ?? {} + displayAmount: toDisplay(amount, toInfo.decimals), + routes }; }; diff --git a/packages/universal-swap/src/types.ts b/packages/universal-swap/src/types.ts index 3b15930e..4aa41da3 100644 --- a/packages/universal-swap/src/types.ts +++ b/packages/universal-swap/src/types.ts @@ -18,7 +18,7 @@ export enum SwapDirection { export interface SimulateResponse { amount: Uint128; displayAmount: number; - routes?: SmartRouteSwapAPIOperations; + routes?: SmartRouterResponse; routeSwapOps?: SmartRouteSwapOperations[]; } @@ -125,22 +125,7 @@ export type SmartRouteSwapOperations = { export type SmartRouterResponse = { swapAmount: string; returnAmount: string; - routes: (SmartRouteSwapAPIOperations | Route)[]; -}; - -export type SmartRouteSwapAPIOperations = { - swapAmount: string; - returnAmount: string; - paths: { - poolId: string; - tokenOut: string; - }[]; -}; - -export type SmartRouterResponseAPI = { - swapAmount: string; - returnAmount: string; - routes: SmartRouteSwapAPIOperations[]; + routes: Route[]; }; export type ConvertType = Convert | ConvertReverse; From 0e26ded8b39d95bcf904faba67a6e4bdb15ae4d5 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Tue, 24 Sep 2024 15:19:05 +0700 Subject: [PATCH 13/16] change name common pepe cat --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/constant.ts | 8 +++----- packages/oraidex-common/src/network.ts | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index 797f18af..63b71a93 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.15", + "version": "1.1.16", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/constant.ts b/packages/oraidex-common/src/constant.ts index 6227f0ff..11bb2cda 100644 --- a/packages/oraidex-common/src/constant.ts +++ b/packages/oraidex-common/src/constant.ts @@ -97,11 +97,9 @@ export const INJECTIVE_ORAICHAIN_DENOM = "ibc/49D820DFDE9F885D7081725A58202ABA2F export const ORAIIBC_INJECTIVE_DENOM = "ibc/C20C0A822BD22B2CEF0D067400FCCFB6FAEEE9E91D360B4E0725BD522302D565"; export const TON_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/ton"; -// export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/pepe"; -// export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/cat"; - -export const PEPE_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extPEPE"; -export const CAT_ORAICHAIN_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extCAT"; +export const PEPE_ORAICHAIN_EXT_DENOM = + "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extPEPE"; +export const CAT_ORAICHAIN_EXT_DENOM = "factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/extCAT"; // config for oraichain token export const AIRI_CONTRACT = "orai10ldgzued6zjp0mkqwsv2mux3ml50l97c74x8sg"; diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index 320ff723..4db2524a 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -55,8 +55,8 @@ import { ORAIX_ETH_CONTRACT, MIXED_ROUTER, AMM_V3_CONTRACT, - PEPE_ORAICHAIN_DENOM, - CAT_ORAICHAIN_DENOM, + PEPE_ORAICHAIN_EXT_DENOM as PEPE_ORAICHAIN_DENOM, + CAT_ORAICHAIN_EXT_DENOM as CAT_ORAICHAIN_DENOM, PEPE_ETH_CONTRACT, PEPE_BSC_CONTRACT, CAT_BSC_CONTRACT From 0808598f0cabb8cf79b0b962fe09b4b86435f907 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Tue, 24 Sep 2024 16:24:56 +0700 Subject: [PATCH 14/16] fix params sourceReceiverTest --- packages/universal-swap/src/helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index d2a76228..dcae3a16 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -327,7 +327,7 @@ export class UniversalSwapHelper { const source = UniversalSwapHelper.getSourceReceiver( sourceReceiver, fromToken.contractAddress, - swapOption.isSourceReceiverTest + swapOption?.isSourceReceiverTest ); let { swapRoute, universalSwapType, isSmartRouter } = UniversalSwapHelper.getRoute( From d4105d702851c40ca393c4fe07f1239c8a4820b5 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Tue, 24 Sep 2024 17:10:53 +0700 Subject: [PATCH 15/16] hide token cat --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/network.ts | 52 +++++++++++++------------- packages/universal-swap/src/helper.ts | 4 +- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index 63b71a93..2494ce0a 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.1.16", + "version": "1.1.17", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index 4db2524a..d0c5e2be 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -332,14 +332,14 @@ export const oraichainNetwork: CustomChainInfo = { coinDecimals: 6, coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" }, - { - coinDenom: "CAT", - coinMinimalDenom: CAT_ORAICHAIN_DENOM, - coinDecimals: 6, - bridgeTo: ["0x38"], - coinGeckoId: "simon-s-cat", - coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" - }, + // { + // coinDenom: "CAT", + // coinMinimalDenom: CAT_ORAICHAIN_DENOM, + // coinDecimals: 6, + // bridgeTo: ["0x38"], + // coinGeckoId: "simon-s-cat", + // coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" + // }, { coinDenom: "ATOM", coinGeckoId: "cosmos", @@ -678,16 +678,16 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "pepe", prefixToken: ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX, coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" - }, - { - coinDenom: "CAT", - coinMinimalDenom: ORAI_BRIDGE_EVM_DENOM_PREFIX + CAT_BSC_CONTRACT, - bridgeNetworkIdentifier: "0x38", - coinDecimals: 18, - prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX, - coinGeckoId: "simon-s-cat", - coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } + // { + // coinDenom: "CAT", + // coinMinimalDenom: ORAI_BRIDGE_EVM_DENOM_PREFIX + CAT_BSC_CONTRACT, + // bridgeNetworkIdentifier: "0x38", + // coinDecimals: 18, + // prefixToken: ORAI_BRIDGE_EVM_DENOM_PREFIX, + // coinGeckoId: "simon-s-cat", + // coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" + // } ], txExplorer: { name: "OraiBridge Scan", @@ -1124,16 +1124,16 @@ export const chainInfos: CustomChainInfo[] = [ coinGeckoId: "pepe", bridgeTo: ["Oraichain"], coinImageUrl: "https://assets.coingecko.com/coins/images/29850/standard/pepe-token.jpeg?1696528776" - }, - { - coinDenom: "CAT", - coinMinimalDenom: "bep20_cat", - contractAddress: CAT_BSC_CONTRACT, - coinDecimals: 18, - coinGeckoId: "simon-s-cat", - bridgeTo: ["Oraichain"], - coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" } + // { + // coinDenom: "CAT", + // coinMinimalDenom: "bep20_cat", + // contractAddress: CAT_BSC_CONTRACT, + // coinDecimals: 18, + // coinGeckoId: "simon-s-cat", + // bridgeTo: ["Oraichain"], + // coinImageUrl: "https://assets.coingecko.com/coins/images/39765/standard/Simon's_Cat_Logo.png?1724017505" + // } ], txExplorer: { name: "Bsc Scan", diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index dcae3a16..23a09e5e 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -590,7 +590,9 @@ export class UniversalSwapHelper { }; }; - // simulate swap functions + /** + * @deprecated. Use UniversalSwapHelper.handleSimulateSwap + */ static simulateSwap = async (query: { fromInfo: TokenItemType; toInfo: TokenItemType; From e1fab51f5a838a9a0c260558dcf24371f6837b20 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Tue, 24 Sep 2024 17:50:27 +0700 Subject: [PATCH 16/16] hide comment --- packages/universal-swap/src/handler.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index 9a2ea928..4186c074 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -1012,9 +1012,9 @@ export class UniversalSwapHandler { simulatePrice: simulatePrice }; // has to switch network to the correct chain id on evm since users can swap between network tokens - // if (!this.config.evmWallet.isTron(originalFromToken.chainId)) - // await this.config.evmWallet.switchNetwork(originalFromToken.chainId); - // if (UniversalSwapHelper.isEvmSwappable(swappableData)) return this.evmSwap(evmSwapData); + if (!this.config.evmWallet.isTron(originalFromToken.chainId)) + await this.config.evmWallet.switchNetwork(originalFromToken.chainId); + if (UniversalSwapHelper.isEvmSwappable(swappableData)) return this.evmSwap(evmSwapData); const toTokenSameFromChainId = getTokenOnSpecificChainId(originalToToken.coinGeckoId, originalFromToken.chainId); if (toTokenSameFromChainId) {