-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from oraichain/fix/check-balance-ibc
[Review] - Fix Check Balance IBC Universal-Swap
- Loading branch information
Showing
5 changed files
with
141 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/universal-swap/src/universal-demos/from-cosmos-to-evm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import "dotenv/config"; | ||
import { CosmosWalletImpl } from "./offline-wallet"; | ||
import { UniversalSwapHandler } from "../handler"; | ||
import { | ||
ORAI_ETH_CONTRACT, | ||
cosmosTokens, | ||
flattenTokens, | ||
generateError, | ||
toAmount, | ||
USDT_CONTRACT | ||
} from "@oraichain/oraidex-common"; | ||
|
||
const oraichainToEvm = async (chainId: "Oraichain") => { | ||
const wallet = new CosmosWalletImpl(process.env.MNEMONIC); | ||
|
||
const sender = await wallet.getKeplrAddr(chainId); | ||
const fromAmount = 90; | ||
let originalFromToken = cosmosTokens.find( | ||
(t) => t.chainId === chainId && t.contractAddress && t.contractAddress === USDT_CONTRACT | ||
); | ||
|
||
let originalToToken = flattenTokens.find( | ||
(t) => t.chainId === "0x01" && t.contractAddress && t.contractAddress === ORAI_ETH_CONTRACT | ||
); | ||
const evmAddress = "0xf2846a1E4dAFaeA38C1660a618277d67605bd2B5"; | ||
if (!originalFromToken) throw generateError("Could not find original from token"); | ||
if (!originalToToken) throw generateError("Could not find original to token"); | ||
const universalHandler = new UniversalSwapHandler( | ||
{ | ||
originalFromToken, | ||
originalToToken, | ||
sender: { cosmos: sender, evm: evmAddress }, | ||
relayerFee: { | ||
relayerAmount: "1000000", | ||
relayerDecimals: 6 | ||
}, | ||
fromAmount, | ||
simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString() | ||
}, | ||
{ cosmosWallet: wallet, ibcInfoTestMode: false } | ||
); | ||
|
||
try { | ||
const result = await universalHandler.processUniversalSwap(); | ||
console.log("result: ", result); | ||
} catch (error) { | ||
console.log("error: ", error); | ||
} | ||
}; | ||
|
||
(() => { | ||
return oraichainToEvm("Oraichain"); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters