Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/update route #366

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/universal-swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-universal-swap",
"version": "1.1.20",
"version": "1.1.21",
"main": "build/index.js",
"files": [
"build/"
Expand Down
4 changes: 2 additions & 2 deletions packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ export class UniversalSwapHelper {
/**
* useAlphaIbcWasm case:
* evm -> oraichain -> osmosis -> inj/tia
* tia/inj -> osmosis -> oraichain -> evm
*/
if (swapOption.isAlphaIbcWasm) {
if (swapOption.isAlphaIbcWasm && !fromToken.cosmosBased) {
if (!alphaSmartRoute) throw generateError(`Missing router with alpha ibc wasm!`);
const routes = alphaSmartRoute.routes;
const alphaRoutes = routes[0];
Expand All @@ -468,6 +467,7 @@ export class UniversalSwapHelper {
});

if (addresses?.recipientAddress) receiverAddresses[toToken.chainId] = addresses?.recipientAddress;

const { memo } = generateMemoSwap(
{
...alphaRoutes,
Expand Down
83 changes: 22 additions & 61 deletions packages/universal-swap/src/universal-demos/alpha-smart-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,35 @@ import { UniversalSwapHandler } from "../handler";
import { cosmosTokens, flattenTokens, generateError, getTokenOnOraichain, toAmount } from "@oraichain/oraidex-common";

const router = {
swapAmount: "10000000",
returnAmount: "633497",
swapAmount: "1000000",
returnAmount: "339961000000000000",
routes: [
{
swapAmount: "10000000",
returnAmount: "633497",
swapAmount: "1000000",
returnAmount: "339961000000000000",
paths: [
{
chainId: "0x01",
tokenIn: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
tokenInAmount: "10000000",
tokenOut: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh",
tokenOutAmount: "3868034",
tokenOutChainId: "Oraichain",
chainId: "Oraichain",
tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh",
tokenInAmount: "1000000",
tokenOut: "0x55d398326f99059fF775485246999027B3197955",
tokenOutAmount: "339961000000000000",
tokenOutChainId: "0x38",
actions: [
{
type: "Bridge",
protocol: "Bridge",
tokenIn: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
tokenInAmount: "10000000",
tokenOut: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh",
tokenOutAmount: "3868034",
tokenOutChainId: "Oraichain",
tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh",
tokenInAmount: "1000000",
tokenOut: "0x55d398326f99059fF775485246999027B3197955",
tokenOutAmount: "339961000000000000",
tokenOutChainId: "0x38",
bridgeInfo: {
port: "transfer",
channel: "channel-1"
port: "wasm.orai195269awwnt5m6c843q6w7hp8rt0k7syfu9de4h0wz384slshuzps8y7ccm",
channel: "channel-29"
}
}
]
},
{
chainId: "Oraichain",
tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh",
tokenInAmount: "3868034",
tokenOut: "orai",
tokenOutAmount: "633497",
tokenOutChainId: "Oraichain",
actions: [
{
type: "Swap",
protocol: "OraidexV3",
tokenIn: "orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh",
tokenInAmount: "3868034",
tokenOut: "orai10g6frpysmdgw5tdqke47als6f97aqmr8s3cljsvjce4n5enjftcqtamzsd",
tokenOutAmount: "63",
swapInfo: [
{
poolId:
"orai10g6frpysmdgw5tdqke47als6f97aqmr8s3cljsvjce4n5enjftcqtamzsd-orai12hzjxfh77wl572gdzct2fxv2arxcwh6gykc7qh-3000000000-100",
tokenOut: "orai10g6frpysmdgw5tdqke47als6f97aqmr8s3cljsvjce4n5enjftcqtamzsd"
}
]
},
{
type: "Swap",
protocol: "Oraidex",
tokenIn: "orai10g6frpysmdgw5tdqke47als6f97aqmr8s3cljsvjce4n5enjftcqtamzsd",
tokenInAmount: "63",
tokenOut: "orai",
tokenOutAmount: "633497",
swapInfo: [
{
poolId: "orai1fv5kwdv4z0gvp75ht378x8cg2j7prlywa0g35qmctez9q8u4xryspn6lrd",
tokenOut: "orai"
}
]
}
]
}
]
}
Expand All @@ -81,10 +42,10 @@ const router = {
const alphaSwapToOraichain = async () => {
const wallet = new CosmosWalletImpl(process.env.MNEMONIC);
const sender = await wallet.getKeplrAddr("Oraichain");
const fromAmount = 10;
const fromAmount = 1;
console.log("sender: ", sender);
const originalFromToken = flattenTokens.find((t) => t.coinGeckoId === "tether" && t.chainId === "0x01");
const originalToToken = flattenTokens.find((t) => t.coinGeckoId === "oraichain-token" && t.chainId === "Oraichain");
const originalFromToken = flattenTokens.find((t) => t.coinGeckoId === "tether" && t.chainId === "Oraichain");
const originalToToken = flattenTokens.find((t) => t.coinGeckoId === "tether" && t.chainId === "0x38");

if (!originalToToken) throw generateError("Could not find original to token");
if (!originalFromToken) throw generateError("Could not find original from token");
Expand All @@ -103,8 +64,8 @@ const alphaSwapToOraichain = async () => {
// recipientAddress: "orai1hvr9d72r5um9lvt0rpkd4r75vrsqtw6yujhqs2",
// recipientAddress: "osmo12zyu8w93h0q2lcnt50g3fn0w3yqnhy4fh4twhr",
// recipientAddress: "inj133lq4pqjdxspcz4n388glv70z59ffeuh3ktnaj",
simulatePrice: "162461",
simulateAmount: toAmount(fromAmount, originalToToken.decimals).toString(),
simulatePrice: "1000000",
simulateAmount: router.returnAmount,
alphaSmartRoutes: router
},
{
Expand Down
Loading