Skip to content

Commit

Permalink
Merge pull request #344 from oraichain/fix/minimum-receive-ibc-wasm
Browse files Browse the repository at this point in the history
Fix/minimum receive ibc wasm
  • Loading branch information
haunv3 authored Oct 3, 2024
2 parents c8e6eb5 + 287e1c5 commit fd9dc2b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
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.11",
"version": "1.1.12",
"main": "build/index.js",
"files": [
"build/"
Expand Down
7 changes: 2 additions & 5 deletions packages/universal-swap/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,13 +1207,10 @@ export class UniversalSwapHandler {
}

async caculateMinimumReceive() {
const { relayerFee, fromAmount, originalToToken, bridgeFee = 1, userSlippage = 0 } = this.swapData;
const { relayerFee, simulateAmount, originalToToken, bridgeFee = 1, userSlippage = 0 } = this.swapData;
const { cosmosWallet } = this.config;
const convertSimulateAmount = toAmount(
fromAmount,
this.getTokenOnOraichain(originalToToken.coinGeckoId)?.decimals ?? 6
).toString();

const convertSimulateAmount = simulateAmount;
let subRelayerFee = relayerFee?.relayerAmount || "0";

if (originalToToken.coinGeckoId !== "oraichain-token") {
Expand Down
14 changes: 14 additions & 0 deletions packages/universal-swap/src/universal-demos/decode-memo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Memo } from "../proto/universal_swap_memo";

(() => {
const memo =
"Co0BCgdvcmFpZGV4GoEBCn8KBzEwMDAwMDASdAo/b3JhaS1vcmFpMTJoemp4Zmg3N3dsNTcyZ2R6Y3QyZnh2MmFyeGN3aDZneWtjN3FoLTMwMDAwMDAwMDAtMTAwEitvcmFpMTJoemp4Zmg3N3dsNTcyZ2R6Y3QyZnh2MmFyeGN3aDZneWtjN3FoGgRvcmFpEgY4ODAwMDAYgJDwj+nYgP0XIi8iLQorb3JhaTFodnI5ZDcycjV1bTlsdnQwcnBrZDRyNzV2cnNxdHc2eXVqaHFzMiorb3JhaTFodnI5ZDcycjV1bTlsdnQwcnBrZDRyNzV2cnNxdHc2eXVqaHFzMg==";
const uint8Array = Buffer.from(memo, "base64");
const encodedMemo = Memo.decode(uint8Array);
console.dir(
{
encodedMemo
},
{ depth: null }
);
})();
22 changes: 15 additions & 7 deletions packages/universal-swap/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1842,31 +1842,39 @@ describe("test universal swap handler functions", () => {
expect(msgTransfers).toEqual(expectResultMsgTransfer);
});

it.each<[any, number, string, number, string]>([
it.each<[string, any, any, number, string, number, string]>([
[
flattenTokens.find((t) => t.coinGeckoId === "oraichain-token" && t.chainId === "Oraichain"),
"from-orai-bnb-to-orai-oraichain",
flattenTokens.find((t) => t.coinGeckoId === "oraichain-token" && t.chainId === "0x38"), // 18
flattenTokens.find((t) => t.coinGeckoId === "oraichain-token" && t.chainId === "Oraichain"), // 6
1,
(1e5).toString(),
0.1,
"889000"
],
[
flattenTokens.find((t) => t.coinGeckoId === "oraichain-token" && t.chainId === "0x01"),
"from-orai-bnb-to-orai-oraichain",
flattenTokens.find((t) => t.coinGeckoId === "oraichain-token" && t.chainId === "0x38"), // 18
flattenTokens.find((t) => t.coinGeckoId === "tether" && t.chainId === "Oraichain"), // 6
1,
(1e6).toString(),
(1e5).toString(),
0.1,
"0"
"389000"
]
])(
"test-caculate-minimum-receive-ibc-wasm",
async (originalToToken, fromAmount, relayerFee, bridgeFee, expectResult) => {
async (_name, originalFromToken, originalToToken, fromAmount, relayerFee, bridgeFee, expectResult) => {
const isHandleSimulateSwap = vi.spyOn(UniversalSwapHelper, "handleSimulateSwap");
isHandleSimulateSwap.mockReturnValue(new Promise((resolve) => resolve({ amount: "600000", displayAmount: 0.6 })));

const universalSwap = new FakeUniversalSwapHandler({
...universalSwapData,
userSlippage: 1,
bridgeFee,
fromAmount,
originalToToken,
simulateAmount,
originalFromToken,
simulateAmount: (fromAmount * 1e6).toString(),
relayerFee: {
relayerAmount: relayerFee,
relayerDecimals: 6
Expand Down

0 comments on commit fd9dc2b

Please sign in to comment.