diff --git a/packages/universal-swap/tests/msg/oraichain-msg.spec.ts b/packages/universal-swap/tests/msg/oraichain-msg.spec.ts index 4b3dfaae..f5d63e2b 100644 --- a/packages/universal-swap/tests/msg/oraichain-msg.spec.ts +++ b/packages/universal-swap/tests/msg/oraichain-msg.spec.ts @@ -3,6 +3,7 @@ import { BridgeMsgInfo, OraichainMsg } from "../../src/msg"; import { calculateTimeoutTimestamp, generateError, IBC_TRANSFER_TIMEOUT } from "@oraichain/oraidex-common"; import { Action } from "@oraichain/osor-api-contracts-sdk/src/EntryPoint.types"; import { OsmosisMsg } from "../../build/msg"; +import { Memo } from "../../src/proto/universal_swap_memo"; describe("test build oraichain msg", () => { const validPath = { @@ -115,75 +116,106 @@ describe("test build oraichain msg", () => { } }); - // it("Valid path with swap + bridge", () => { - // const nextMemo = "{}"; - // let osmosis = new OsmosisMsg(validPath, "1", receiver, currentAddress, nextMemo); + it("Valid path with swap + ibc bridge", () => { + const nextMemo = "{}"; + let oraichainMsg = new OraichainMsg(validPath, "1", receiver, currentAddress, nextMemo); - // let [swapOps, bridgeInfo] = osmosis.getSwapAndBridgeInfo(); - // expect(bridgeInfo).toEqual({ - // amount: "217432", - // sourceChannel: "channel-0", - // sourcePort: "transfer", - // memo: nextMemo, - // receiver: receiver, - // timeout: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), - // fromToken: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - // toToken: "uatom", - // fromChain: "osmosis-1", - // toChain: "cosmoshub-4" - // }); - // expect(swapOps).toEqual([ - // { - // denom_in: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - // denom_out: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - // pool: "1282" - // } - // ]); + let [swapOps, bridgeInfo] = oraichainMsg.getSwapAndBridgeInfo(); + expect(bridgeInfo).toEqual({ + amount: "1359212", + sourceChannel: "channel-15", + sourcePort: "transfer", + memo: "{}", + receiver: receiver, + timeout: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), + fromToken: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", + toToken: "uatom", + fromChain: "Oraichain", + toChain: "cosmoshub-4" + }); + expect(swapOps).toEqual([ + { + denom_in: "orai", + denom_out: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", + pool: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs" + } + ]); - // let memoAsMiddleware = osmosis.genMemoAsMiddleware(); - // expect(memoAsMiddleware).toEqual({ - // receiver: osmosis.ENTRY_POINT_CONTRACT, - // memo: JSON.stringify({ - // wasm: { - // contract: osmosis.ENTRY_POINT_CONTRACT, - // msg: { - // swap_and_action: { - // user_swap: { - // swap_exact_asset_in: { - // swap_venue_name: osmosis.SWAP_VENUE_NAME, - // operations: [ - // { - // denom_in: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - // denom_out: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", - // pool: "1282" - // } - // ] - // } - // }, - // min_asset: { - // native: { amount: "1", denom: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2" } - // }, - // timeout_timestamp: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), - // post_swap_action: { - // ibc_transfer: { - // ibc_info: { - // source_channel: "channel-0", - // receiver: receiver, - // memo: "{}", - // recover_address: currentAddress - // } - // } - // }, - // affiliates: [] - // } - // } - // } - // }) - // }); + let memoAsMiddleware = oraichainMsg.genMemoAsMiddleware(); + expect(memoAsMiddleware).toEqual({ + receiver: oraichainMsg.ENTRY_POINT_CONTRACT, + memo: JSON.stringify({ + wasm: { + contract: oraichainMsg.ENTRY_POINT_CONTRACT, + msg: { + swap_and_action: { + user_swap: { + swap_exact_asset_in: { + swap_venue_name: oraichainMsg.SWAP_VENUE_NAME, + operations: [ + { + denom_in: "orai", + denom_out: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78", + pool: "orai1jf74ry4m0jcy9emsaudkhe7vte9l8qy8enakvs" + } + ] + } + }, + min_asset: { + native: { amount: "1", denom: "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78" } + }, + timeout_timestamp: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), + post_swap_action: { + ibc_transfer: { + ibc_info: { + source_channel: "channel-15", + receiver: receiver, + memo: "{}", + recover_address: currentAddress + } + } + }, + affiliates: [] + } + } + } + }) + }); - // let executeMsg = osmosis.genExecuteMsg(); - // expect(executeMsg.typeUrl).toEqual("/cosmwasm.wasm.v1.MsgExecuteContract"); - // }); + let executeMsg = oraichainMsg.genExecuteMsg(); + expect(executeMsg.typeUrl).toEqual("/cosmwasm.wasm.v1.MsgExecuteContract"); + + let memoForIbcWasm = oraichainMsg.genMemoForIbcWasm(); + expect(memoForIbcWasm).toEqual({ + receiver: currentAddress, + memo: Buffer.from( + Memo.encode({ + userSwap: { + swapVenueName: oraichainMsg.SWAP_VENUE_NAME, + swapExactAssetIn: { + operations: swapOps.map((operation) => ({ + poolId: operation.pool, + denomIn: operation.denom_in, + denomOut: operation.denom_out + })) + } + }, + minimumReceive: "1", + timeoutTimestamp: +calculateTimeoutTimestamp(IBC_TRANSFER_TIMEOUT), + postSwapAction: { + ibcTransferMsg: { + sourceChannel: bridgeInfo.sourceChannel, + sourcePort: bridgeInfo.sourcePort, + receiver: bridgeInfo.receiver, + memo: bridgeInfo.memo, + recoverAddress: currentAddress + } + }, + recoveryAddr: currentAddress + }).finish() + ).toString("base64") + }); + }); // it("Valid path with bridge only", () => { // const nextMemo = "{}";