From e7e50fd6492018f8e212e8b9e52100627bb80c89 Mon Sep 17 00:00:00 2001 From: Jeff Huang Date: Thu, 15 Aug 2024 17:31:00 +0800 Subject: [PATCH] fix: disable native and stable coins in Stargate V2, add cake between bnb and polygon zkevm --- .changeset/yellow-pianos-wink.md | 5 + .env.bnb | 2 + src/logics/stargate-v2/abis/OFTWrapper.json | 361 +++++++ src/logics/stargate-v2/configs.ts | 678 +++++++------ .../stargate-v2/contracts/OFTWrapper.ts | 951 ++++++++++++++++++ .../factories/OFTWrapper__factory.ts | 880 ++++++++++++++++ .../stargate-v2/contracts/factories/index.ts | 1 + src/logics/stargate-v2/contracts/index.ts | 2 + .../stargate-v2/logic.swap-token.test.ts | 74 +- src/logics/stargate-v2/logic.swap-token.ts | 213 ++-- src/logics/stargate-v2/tokens/data/bnb.json | 9 + .../stargate-v2/tokens/data/mainnet.json | 7 + .../stargate-v2/tokens/data/polygonZkevm.json | 9 + src/logics/stargate-v2/tokens/index.ts | 10 + .../logics/stargate-v2/swap-token-bnb.test.ts | 85 ++ ...est.ts => swap-token-mainnet.test.ts.bkup} | 0 .../swap-token-polygonZkevm.test.ts | 91 ++ 17 files changed, 2958 insertions(+), 420 deletions(-) create mode 100644 .changeset/yellow-pianos-wink.md create mode 100644 .env.bnb create mode 100644 src/logics/stargate-v2/abis/OFTWrapper.json create mode 100644 src/logics/stargate-v2/contracts/OFTWrapper.ts create mode 100644 src/logics/stargate-v2/contracts/factories/OFTWrapper__factory.ts create mode 100644 src/logics/stargate-v2/tokens/data/bnb.json create mode 100644 src/logics/stargate-v2/tokens/data/polygonZkevm.json create mode 100644 test/logics/stargate-v2/swap-token-bnb.test.ts rename test/logics/stargate-v2/{swap-token.test.ts => swap-token-mainnet.test.ts.bkup} (100%) create mode 100644 test/logics/stargate-v2/swap-token-polygonZkevm.test.ts diff --git a/.changeset/yellow-pianos-wink.md b/.changeset/yellow-pianos-wink.md new file mode 100644 index 00000000..1e7efc48 --- /dev/null +++ b/.changeset/yellow-pianos-wink.md @@ -0,0 +1,5 @@ +--- +'@protocolink/logics': patch +--- + +disable native and stable coins in Stargate V2, add cake between bnb and polygon zkevm diff --git a/.env.bnb b/.env.bnb new file mode 100644 index 00000000..ccc44adb --- /dev/null +++ b/.env.bnb @@ -0,0 +1,2 @@ +CHAIN_ID=56 +HTTP_RPC_URL=https://bsc-dataseed.binance.org diff --git a/src/logics/stargate-v2/abis/OFTWrapper.json b/src/logics/stargate-v2/abis/OFTWrapper.json new file mode 100644 index 00000000..6b46e121 --- /dev/null +++ b/src/logics/stargate-v2/abis/OFTWrapper.json @@ -0,0 +1,361 @@ +[ + { + "inputs": [{ "internalType": "uint256", "name": "_defaultBps", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "oft", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "WrapperFeeWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes2", "name": "partnerId", "type": "bytes2" }, + { "indexed": false, "internalType": "address", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "wrapperFee", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "callerFee", "type": "uint256" } + ], + "name": "WrapperFees", + "type": "event" + }, + { + "inputs": [], + "name": "BPS_DENOMINATOR", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_UINT", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "defaultBps", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_oft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes", "name": "_toAddress", "type": "bytes" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "bool", "name": "_useZro", "type": "bool" }, + { "internalType": "bytes", "name": "_adapterParams", "type": "bytes" }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "estimateSendFee", + "outputs": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "zroFee", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_oft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes32", "name": "_toAddress", "type": "bytes32" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "bool", "name": "_useZro", "type": "bool" }, + { "internalType": "bytes", "name": "_adapterParams", "type": "bytes" }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "estimateSendFeeV2", + "outputs": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "zroFee", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_token", "type": "address" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "uint256", "name": "_callerBps", "type": "uint256" } + ], + "name": "getAmountAndFees", + "outputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "wrapperFee", "type": "uint256" }, + { "internalType": "uint256", "name": "callerFee", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "oftBps", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "_oft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes", "name": "_toAddress", "type": "bytes" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "uint256", "name": "_minAmount", "type": "uint256" }, + { "internalType": "address payable", "name": "_refundAddress", "type": "address" }, + { "internalType": "address", "name": "_zroPaymentAddress", "type": "address" }, + { "internalType": "bytes", "name": "_adapterParams", "type": "bytes" }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "sendOFT", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_oft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes32", "name": "_toAddress", "type": "bytes32" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "uint256", "name": "_minAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address payable", "name": "refundAddress", "type": "address" }, + { "internalType": "address", "name": "zroPaymentAddress", "type": "address" }, + { "internalType": "bytes", "name": "adapterParams", "type": "bytes" } + ], + "internalType": "struct ICommonOFT.LzCallParams", + "name": "_callParams", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "sendOFTFeeV2", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_oft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes32", "name": "_toAddress", "type": "bytes32" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "uint256", "name": "_minAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address payable", "name": "refundAddress", "type": "address" }, + { "internalType": "address", "name": "zroPaymentAddress", "type": "address" }, + { "internalType": "bytes", "name": "adapterParams", "type": "bytes" } + ], + "internalType": "struct ICommonOFT.LzCallParams", + "name": "_callParams", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "sendOFTV2", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_proxyOft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes", "name": "_toAddress", "type": "bytes" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "uint256", "name": "_minAmount", "type": "uint256" }, + { "internalType": "address payable", "name": "_refundAddress", "type": "address" }, + { "internalType": "address", "name": "_zroPaymentAddress", "type": "address" }, + { "internalType": "bytes", "name": "_adapterParams", "type": "bytes" }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "sendProxyOFT", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_proxyOft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes32", "name": "_toAddress", "type": "bytes32" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "uint256", "name": "_minAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address payable", "name": "refundAddress", "type": "address" }, + { "internalType": "address", "name": "zroPaymentAddress", "type": "address" }, + { "internalType": "bytes", "name": "adapterParams", "type": "bytes" } + ], + "internalType": "struct ICommonOFT.LzCallParams", + "name": "_callParams", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "sendProxyOFTFeeV2", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_proxyOft", "type": "address" }, + { "internalType": "uint16", "name": "_dstChainId", "type": "uint16" }, + { "internalType": "bytes32", "name": "_toAddress", "type": "bytes32" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" }, + { "internalType": "uint256", "name": "_minAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address payable", "name": "refundAddress", "type": "address" }, + { "internalType": "address", "name": "zroPaymentAddress", "type": "address" }, + { "internalType": "bytes", "name": "adapterParams", "type": "bytes" } + ], + "internalType": "struct ICommonOFT.LzCallParams", + "name": "_callParams", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "callerBps", "type": "uint256" }, + { "internalType": "address", "name": "caller", "type": "address" }, + { "internalType": "bytes2", "name": "partnerId", "type": "bytes2" } + ], + "internalType": "struct IOFTWrapper.FeeObj", + "name": "_feeObj", + "type": "tuple" + } + ], + "name": "sendProxyOFTV2", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_defaultBps", "type": "uint256" }], + "name": "setDefaultBps", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_token", "type": "address" }, + { "internalType": "uint256", "name": "_bps", "type": "uint256" } + ], + "name": "setOFTBps", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_oft", "type": "address" }, + { "internalType": "address", "name": "_to", "type": "address" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "withdrawFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/logics/stargate-v2/configs.ts b/src/logics/stargate-v2/configs.ts index 50923ca8..ad999f28 100644 --- a/src/logics/stargate-v2/configs.ts +++ b/src/logics/stargate-v2/configs.ts @@ -1,7 +1,13 @@ +import { bnbTokens, mainnetTokens, metisTokens, polygonZkevmTokens } from './tokens'; import * as common from '@protocolink/common'; -import { mainnetTokens, metisTokens } from './tokens'; + +export enum StargateChainId { + BNB = 102, + POLYGON_ZKEVM = 158, +} export enum EndpointId { + OFT = 0, ETHEREUM = 30101, BNB = 30102, AVALANCHE = 30106, @@ -14,6 +20,7 @@ export enum EndpointId { } export enum PoolId { + OFT = 0, USDC = 1, USDT = 2, ETH = 13, @@ -24,6 +31,7 @@ export interface Pool { id: number; token: common.Token; address: string; + proxyOFT?: string; destinations: { chainId: number; endpointId: number }[]; } @@ -32,352 +40,360 @@ export interface PoolConfig extends Pool { } export interface Config { + id: number; eid: number; chainId: number; pools: Pool[]; } export const configs: Config[] = [ + // { + // eid: EndpointId.ETHEREUM, + // chainId: common.ChainId.mainnet, + // pools: [ + // // { + // // id: PoolId.ETH, + // // token: common.mainnetTokens.ETH, + // // address: '0x77b2043768d28E9C9aB44E1aBfC95944bcE57931', + // // destinations: [ + // // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // // ], + // // }, + // // { + // // id: PoolId.USDC, + // // token: common.mainnetTokens.USDC, + // // address: '0xc026395860Db2d07ee33e05fE50ed7bD583189C7', + // // destinations: [ + // // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // // ], + // // }, + // // { + // // id: PoolId.USDT, + // // token: common.mainnetTokens.USDT, + // // address: '0x933597a323Eb81cAe705C5bC29985172fd5A3973', + // // destinations: [ + // // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // // { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + // // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // // ], + // // }, + // // { + // // id: PoolId.METIS, + // // token: mainnetTokens.Metis, + // // address: '0xcDafB1b2dB43f366E48e6F614b8DCCBFeeFEEcD3', + // // destinations: [{ chainId: common.ChainId.metis, endpointId: EndpointId.METIS }], + // // }, + // ], + // }, { - eid: EndpointId.ETHEREUM, - chainId: common.ChainId.mainnet, - pools: [ - { - id: PoolId.ETH, - token: common.mainnetTokens.ETH, - address: '0x77b2043768d28E9C9aB44E1aBfC95944bcE57931', - destinations: [ - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - ], - }, - { - id: PoolId.USDC, - token: common.mainnetTokens.USDC, - address: '0xc026395860Db2d07ee33e05fE50ed7bD583189C7', - destinations: [ - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - { - id: PoolId.USDT, - token: common.mainnetTokens.USDT, - address: '0x933597a323Eb81cAe705C5bC29985172fd5A3973', - destinations: [ - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - { - id: PoolId.METIS, - token: mainnetTokens.Metis, - address: '0xcDafB1b2dB43f366E48e6F614b8DCCBFeeFEEcD3', - destinations: [{ chainId: common.ChainId.metis, endpointId: EndpointId.METIS }], - }, - ], - }, - { + id: StargateChainId.BNB, eid: EndpointId.BNB, chainId: common.ChainId.bnb, pools: [ { - id: PoolId.USDT, - token: common.bnbTokens.USDT, - address: '0x138EB30f73BC423c6455C53df6D89CB01d9eBc63', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], + id: PoolId.OFT, + token: bnbTokens.CAKE, + address: '0x86355F02119bdBC28ED6A4D5E0cA327Ca7730fFF', // OFTWrapper + proxyOFT: '0xb274202daBA6AE180c665B4fbE59857b7c3a8091', + destinations: [{ chainId: common.ChainId.polygonZkevm, endpointId: EndpointId.OFT }], }, ], }, + // { + // eid: EndpointId.AVALANCHE, + // chainId: common.ChainId.avalanche, + // pools: [ + // { + // id: PoolId.USDC, + // token: common.avalancheTokens.USDC, + // address: '0x5634c4a5FEd09819E3c46D86A965Dd9447d86e47', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // ], + // }, + // { + // id: PoolId.USDT, + // token: common.avalancheTokens.USDt, + // address: '0x12dC9256Acc9895B076f6638D628382881e62CeE', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // ], + // }, + // ], + // }, + // { + // eid: EndpointId.POLYGON, + // chainId: common.ChainId.polygon, + // pools: [ + // { + // id: PoolId.USDC, + // token: common.polygonTokens.USDC, + // address: '0x9Aa02D4Fae7F58b8E8f34c66E756cC734DAc7fe4', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // { + // id: PoolId.USDT, + // token: common.polygonTokens.USDT, + // address: '0xd47b03ee6d86Cf251ee7860FB2ACf9f91B9fD4d7', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // ], + // }, { - eid: EndpointId.AVALANCHE, - chainId: common.ChainId.avalanche, + id: StargateChainId.POLYGON_ZKEVM, + eid: EndpointId.OFT, + chainId: common.ChainId.polygonZkevm, pools: [ { - id: PoolId.USDC, - token: common.avalancheTokens.USDC, - address: '0x5634c4a5FEd09819E3c46D86A965Dd9447d86e47', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - ], - }, - { - id: PoolId.USDT, - token: common.avalancheTokens.USDt, - address: '0x12dC9256Acc9895B076f6638D628382881e62CeE', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - ], - }, - ], - }, - { - eid: EndpointId.POLYGON, - chainId: common.ChainId.polygon, - pools: [ - { - id: PoolId.USDC, - token: common.polygonTokens.USDC, - address: '0x9Aa02D4Fae7F58b8E8f34c66E756cC734DAc7fe4', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - { - id: PoolId.USDT, - token: common.polygonTokens.USDT, - address: '0xd47b03ee6d86Cf251ee7860FB2ACf9f91B9fD4d7', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - ], - }, - { - eid: EndpointId.ARBITRUM, - chainId: common.ChainId.arbitrum, - pools: [ - { - id: PoolId.ETH, - token: common.arbitrumTokens.ETH, - address: '0xA45B5130f36CDcA45667738e2a258AB09f4A5f7F', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - ], - }, - { - id: PoolId.USDC, - token: common.arbitrumTokens.USDC, - address: '0xe8CDF27AcD73a434D661C84887215F7598e7d0d3', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - { - id: PoolId.USDT, - token: common.arbitrumTokens.USDT, - address: '0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - ], - }, - { - eid: EndpointId.OPTIMISM, - chainId: common.ChainId.optimism, - pools: [ - { - id: PoolId.ETH, - token: common.optimismTokens.ETH, - address: '0xe8CDF27AcD73a434D661C84887215F7598e7d0d3', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - ], - }, - { - id: PoolId.USDC, - token: common.optimismTokens.USDC, - address: '0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - { - id: PoolId.USDT, - token: common.optimismTokens.USDT, - address: '0x19cFCE47eD54a88614648DC3f19A5980097007dD', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - ], - }, - { - eid: EndpointId.METIS, - chainId: common.ChainId.metis, - pools: [ - { - id: PoolId.METIS, - token: metisTokens.Metis, - address: '0xD9050e7043102a0391F81462a3916326F86331F0', - destinations: [{ chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }], - }, - { - id: PoolId.ETH, - token: common.metisTokens.WETH, - address: '0x36ed193dc7160D3858EC250e69D12B03Ca087D08', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - ], - }, - { - id: PoolId.USDT, - token: common.metisTokens['m.USDT'], - address: '0x4dCBFC0249e8d5032F89D6461218a9D2eFff5125', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - ], - }, - { - eid: EndpointId.BASE, - chainId: common.ChainId.base, - pools: [ - { - id: PoolId.ETH, - token: common.baseTokens.ETH, - address: '0xdc181Bd607330aeeBEF6ea62e03e5e1Fb4B6F7C7', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - ], - }, - { - id: PoolId.USDC, - token: common.baseTokens.USDC, - address: '0x27a16dc786820B16E5c9028b75B99F6f604b5d26', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - ], - }, - { - eid: EndpointId.IOTA, - chainId: common.ChainId.iota, - pools: [ - { - id: PoolId.ETH, - token: common.iotaTokens.WETH, - address: '0x9c2dc7377717603eB92b2655c5f2E7997a4945BD', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - ], - }, - { - id: PoolId.USDC, - token: common.iotaTokens['USDC.e'], - address: '0x8e8539e4CcD69123c623a106773F2b0cbbc58746', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], - }, - { - id: PoolId.USDT, - token: common.iotaTokens.USDT, - address: '0x77C71633C34C3784ede189d74223122422492a0f', - destinations: [ - { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, - { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, - { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, - { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, - { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, - { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, - { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, - ], + id: PoolId.OFT, + token: polygonZkevmTokens.CAKE, + address: '0x86355F02119bdBC28ED6A4D5E0cA327Ca7730fFF', // OFTWrapper + destinations: [{ chainId: common.ChainId.bnb, endpointId: EndpointId.OFT }], }, ], }, + // { + // eid: EndpointId.ARBITRUM, + // chainId: common.ChainId.arbitrum, + // pools: [ + // { + // id: PoolId.ETH, + // token: common.arbitrumTokens.ETH, + // address: '0xA45B5130f36CDcA45667738e2a258AB09f4A5f7F', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // ], + // }, + // { + // id: PoolId.USDC, + // token: common.arbitrumTokens.USDC, + // address: '0xe8CDF27AcD73a434D661C84887215F7598e7d0d3', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // { + // id: PoolId.USDT, + // token: common.arbitrumTokens.USDT, + // address: '0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // ], + // }, + // { + // eid: EndpointId.OPTIMISM, + // chainId: common.ChainId.optimism, + // pools: [ + // { + // id: PoolId.ETH, + // token: common.optimismTokens.ETH, + // address: '0xe8CDF27AcD73a434D661C84887215F7598e7d0d3', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // ], + // }, + // { + // id: PoolId.USDC, + // token: common.optimismTokens.USDC, + // address: '0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // { + // id: PoolId.USDT, + // token: common.optimismTokens.USDT, + // address: '0x19cFCE47eD54a88614648DC3f19A5980097007dD', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // ], + // }, + // { + // eid: EndpointId.METIS, + // chainId: common.ChainId.metis, + // pools: [ + // { + // id: PoolId.METIS, + // token: metisTokens.Metis, + // address: '0xD9050e7043102a0391F81462a3916326F86331F0', + // destinations: [{ chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }], + // }, + // { + // id: PoolId.ETH, + // token: common.metisTokens.WETH, + // address: '0x36ed193dc7160D3858EC250e69D12B03Ca087D08', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // ], + // }, + // { + // id: PoolId.USDT, + // token: common.metisTokens['m.USDT'], + // address: '0x4dCBFC0249e8d5032F89D6461218a9D2eFff5125', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // ], + // }, + // { + // eid: EndpointId.BASE, + // chainId: common.ChainId.base, + // pools: [ + // { + // id: PoolId.ETH, + // token: common.baseTokens.ETH, + // address: '0xdc181Bd607330aeeBEF6ea62e03e5e1Fb4B6F7C7', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // ], + // }, + // { + // id: PoolId.USDC, + // token: common.baseTokens.USDC, + // address: '0x27a16dc786820B16E5c9028b75B99F6f604b5d26', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // ], + // }, + // { + // eid: EndpointId.IOTA, + // chainId: common.ChainId.iota, + // pools: [ + // { + // id: PoolId.ETH, + // token: common.iotaTokens.WETH, + // address: '0x9c2dc7377717603eB92b2655c5f2E7997a4945BD', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // ], + // }, + // { + // id: PoolId.USDC, + // token: common.iotaTokens['USDC.e'], + // address: '0x8e8539e4CcD69123c623a106773F2b0cbbc58746', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // { + // id: PoolId.USDT, + // token: common.iotaTokens.USDT, + // address: '0x77C71633C34C3784ede189d74223122422492a0f', + // destinations: [ + // { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + // { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + // { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + // { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + // { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + // { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + // { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + // ], + // }, + // ], + // }, ]; export const [supportedChainIds, configMap, tokensMap, poolConfigMapById, poolConfigMapByToken] = configs.reduce( @@ -408,6 +424,10 @@ export function getMarkets(chainId: number) { return configMap[chainId].pools; } +export function getStargateChainId(chainId: number) { + return configMap[chainId].id; +} + export function getEndpointId(chainId: number) { return configMap[chainId].eid; } @@ -420,6 +440,10 @@ export function getTokenByPoolId(chainId: number, poolId: number) { return poolConfigMapById[chainId][poolId].token; } +export function getPoolConfigByTokenAddress(chainId: number, tokenAddress: string) { + return poolConfigMapByToken[chainId][tokenAddress]; +} + export function getPoolByTokenAddress(chainId: number, tokenAddress: string) { return poolConfigMapByToken[chainId][tokenAddress].address; } diff --git a/src/logics/stargate-v2/contracts/OFTWrapper.ts b/src/logics/stargate-v2/contracts/OFTWrapper.ts new file mode 100644 index 00000000..bf81e0d9 --- /dev/null +++ b/src/logics/stargate-v2/contracts/OFTWrapper.ts @@ -0,0 +1,951 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PayableOverrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result, EventFragment } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from './common'; + +export declare namespace IOFTWrapper { + export type FeeObjStruct = { + callerBps: BigNumberish; + caller: string; + partnerId: BytesLike; + }; + + export type FeeObjStructOutput = [BigNumber, string, string] & { + callerBps: BigNumber; + caller: string; + partnerId: string; + }; +} + +export declare namespace ICommonOFT { + export type LzCallParamsStruct = { + refundAddress: string; + zroPaymentAddress: string; + adapterParams: BytesLike; + }; + + export type LzCallParamsStructOutput = [string, string, string] & { + refundAddress: string; + zroPaymentAddress: string; + adapterParams: string; + }; +} + +export interface OFTWrapperInterface extends utils.Interface { + functions: { + 'BPS_DENOMINATOR()': FunctionFragment; + 'MAX_UINT()': FunctionFragment; + 'defaultBps()': FunctionFragment; + 'estimateSendFee(address,uint16,bytes,uint256,bool,bytes,(uint256,address,bytes2))': FunctionFragment; + 'estimateSendFeeV2(address,uint16,bytes32,uint256,bool,bytes,(uint256,address,bytes2))': FunctionFragment; + 'getAmountAndFees(address,uint256,uint256)': FunctionFragment; + 'oftBps(address)': FunctionFragment; + 'owner()': FunctionFragment; + 'renounceOwnership()': FunctionFragment; + 'sendOFT(address,uint16,bytes,uint256,uint256,address,address,bytes,(uint256,address,bytes2))': FunctionFragment; + 'sendOFTFeeV2(address,uint16,bytes32,uint256,uint256,(address,address,bytes),(uint256,address,bytes2))': FunctionFragment; + 'sendOFTV2(address,uint16,bytes32,uint256,uint256,(address,address,bytes),(uint256,address,bytes2))': FunctionFragment; + 'sendProxyOFT(address,uint16,bytes,uint256,uint256,address,address,bytes,(uint256,address,bytes2))': FunctionFragment; + 'sendProxyOFTFeeV2(address,uint16,bytes32,uint256,uint256,(address,address,bytes),(uint256,address,bytes2))': FunctionFragment; + 'sendProxyOFTV2(address,uint16,bytes32,uint256,uint256,(address,address,bytes),(uint256,address,bytes2))': FunctionFragment; + 'setDefaultBps(uint256)': FunctionFragment; + 'setOFTBps(address,uint256)': FunctionFragment; + 'transferOwnership(address)': FunctionFragment; + 'withdrawFees(address,address,uint256)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'BPS_DENOMINATOR' + | 'MAX_UINT' + | 'defaultBps' + | 'estimateSendFee' + | 'estimateSendFeeV2' + | 'getAmountAndFees' + | 'oftBps' + | 'owner' + | 'renounceOwnership' + | 'sendOFT' + | 'sendOFTFeeV2' + | 'sendOFTV2' + | 'sendProxyOFT' + | 'sendProxyOFTFeeV2' + | 'sendProxyOFTV2' + | 'setDefaultBps' + | 'setOFTBps' + | 'transferOwnership' + | 'withdrawFees' + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'BPS_DENOMINATOR', values?: undefined): string; + encodeFunctionData(functionFragment: 'MAX_UINT', values?: undefined): string; + encodeFunctionData(functionFragment: 'defaultBps', values?: undefined): string; + encodeFunctionData( + functionFragment: 'estimateSendFee', + values: [string, BigNumberish, BytesLike, BigNumberish, boolean, BytesLike, IOFTWrapper.FeeObjStruct] + ): string; + encodeFunctionData( + functionFragment: 'estimateSendFeeV2', + values: [string, BigNumberish, BytesLike, BigNumberish, boolean, BytesLike, IOFTWrapper.FeeObjStruct] + ): string; + encodeFunctionData(functionFragment: 'getAmountAndFees', values: [string, BigNumberish, BigNumberish]): string; + encodeFunctionData(functionFragment: 'oftBps', values: [string]): string; + encodeFunctionData(functionFragment: 'owner', values?: undefined): string; + encodeFunctionData(functionFragment: 'renounceOwnership', values?: undefined): string; + encodeFunctionData( + functionFragment: 'sendOFT', + values: [ + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + string, + string, + BytesLike, + IOFTWrapper.FeeObjStruct + ] + ): string; + encodeFunctionData( + functionFragment: 'sendOFTFeeV2', + values: [ + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + ICommonOFT.LzCallParamsStruct, + IOFTWrapper.FeeObjStruct + ] + ): string; + encodeFunctionData( + functionFragment: 'sendOFTV2', + values: [ + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + ICommonOFT.LzCallParamsStruct, + IOFTWrapper.FeeObjStruct + ] + ): string; + encodeFunctionData( + functionFragment: 'sendProxyOFT', + values: [ + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + string, + string, + BytesLike, + IOFTWrapper.FeeObjStruct + ] + ): string; + encodeFunctionData( + functionFragment: 'sendProxyOFTFeeV2', + values: [ + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + ICommonOFT.LzCallParamsStruct, + IOFTWrapper.FeeObjStruct + ] + ): string; + encodeFunctionData( + functionFragment: 'sendProxyOFTV2', + values: [ + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + ICommonOFT.LzCallParamsStruct, + IOFTWrapper.FeeObjStruct + ] + ): string; + encodeFunctionData(functionFragment: 'setDefaultBps', values: [BigNumberish]): string; + encodeFunctionData(functionFragment: 'setOFTBps', values: [string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'transferOwnership', values: [string]): string; + encodeFunctionData(functionFragment: 'withdrawFees', values: [string, string, BigNumberish]): string; + + decodeFunctionResult(functionFragment: 'BPS_DENOMINATOR', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'MAX_UINT', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'defaultBps', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'estimateSendFee', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'estimateSendFeeV2', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getAmountAndFees', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'oftBps', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'owner', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'renounceOwnership', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendOFT', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendOFTFeeV2', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendOFTV2', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendProxyOFT', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendProxyOFTFeeV2', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendProxyOFTV2', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setDefaultBps', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setOFTBps', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'transferOwnership', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdrawFees', data: BytesLike): Result; + + events: { + 'OwnershipTransferred(address,address)': EventFragment; + 'WrapperFeeWithdrawn(address,address,uint256)': EventFragment; + 'WrapperFees(bytes2,address,uint256,uint256)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'OwnershipTransferred'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'WrapperFeeWithdrawn'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'WrapperFees'): EventFragment; +} + +export interface OwnershipTransferredEventObject { + previousOwner: string; + newOwner: string; +} +export type OwnershipTransferredEvent = TypedEvent<[string, string], OwnershipTransferredEventObject>; + +export type OwnershipTransferredEventFilter = TypedEventFilter; + +export interface WrapperFeeWithdrawnEventObject { + oft: string; + to: string; + amount: BigNumber; +} +export type WrapperFeeWithdrawnEvent = TypedEvent<[string, string, BigNumber], WrapperFeeWithdrawnEventObject>; + +export type WrapperFeeWithdrawnEventFilter = TypedEventFilter; + +export interface WrapperFeesEventObject { + partnerId: string; + token: string; + wrapperFee: BigNumber; + callerFee: BigNumber; +} +export type WrapperFeesEvent = TypedEvent<[string, string, BigNumber, BigNumber], WrapperFeesEventObject>; + +export type WrapperFeesEventFilter = TypedEventFilter; + +export interface OFTWrapper extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: OFTWrapperInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + BPS_DENOMINATOR(overrides?: CallOverrides): Promise<[BigNumber]>; + + MAX_UINT(overrides?: CallOverrides): Promise<[BigNumber]>; + + defaultBps(overrides?: CallOverrides): Promise<[BigNumber]>; + + estimateSendFee( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { nativeFee: BigNumber; zroFee: BigNumber }>; + + estimateSendFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { nativeFee: BigNumber; zroFee: BigNumber }>; + + getAmountAndFees( + _token: string, + _amount: BigNumberish, + _callerBps: BigNumberish, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + amount: BigNumber; + wrapperFee: BigNumber; + callerFee: BigNumber; + } + >; + + oftBps(arg0: string, overrides?: CallOverrides): Promise<[BigNumber]>; + + owner(overrides?: CallOverrides): Promise<[string]>; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + sendOFT( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFT( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTFeeV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setDefaultBps(_defaultBps: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + setOFTBps( + _token: string, + _bps: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + withdrawFees( + _oft: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + }; + + BPS_DENOMINATOR(overrides?: CallOverrides): Promise; + + MAX_UINT(overrides?: CallOverrides): Promise; + + defaultBps(overrides?: CallOverrides): Promise; + + estimateSendFee( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { nativeFee: BigNumber; zroFee: BigNumber }>; + + estimateSendFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { nativeFee: BigNumber; zroFee: BigNumber }>; + + getAmountAndFees( + _token: string, + _amount: BigNumberish, + _callerBps: BigNumberish, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + amount: BigNumber; + wrapperFee: BigNumber; + callerFee: BigNumber; + } + >; + + oftBps(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + sendOFT( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFT( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTFeeV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setDefaultBps(_defaultBps: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + setOFTBps( + _token: string, + _bps: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + withdrawFees( + _oft: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + callStatic: { + BPS_DENOMINATOR(overrides?: CallOverrides): Promise; + + MAX_UINT(overrides?: CallOverrides): Promise; + + defaultBps(overrides?: CallOverrides): Promise; + + estimateSendFee( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { nativeFee: BigNumber; zroFee: BigNumber }>; + + estimateSendFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise<[BigNumber, BigNumber] & { nativeFee: BigNumber; zroFee: BigNumber }>; + + getAmountAndFees( + _token: string, + _amount: BigNumberish, + _callerBps: BigNumberish, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + amount: BigNumber; + wrapperFee: BigNumber; + callerFee: BigNumber; + } + >; + + oftBps(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: CallOverrides): Promise; + + sendOFT( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + sendOFTFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + sendOFTV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + sendProxyOFT( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + sendProxyOFTFeeV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + sendProxyOFTV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + setDefaultBps(_defaultBps: BigNumberish, overrides?: CallOverrides): Promise; + + setOFTBps(_token: string, _bps: BigNumberish, overrides?: CallOverrides): Promise; + + transferOwnership(newOwner: string, overrides?: CallOverrides): Promise; + + withdrawFees(_oft: string, _to: string, _amount: BigNumberish, overrides?: CallOverrides): Promise; + }; + + filters: { + 'OwnershipTransferred(address,address)'( + previousOwner?: string | null, + newOwner?: string | null + ): OwnershipTransferredEventFilter; + OwnershipTransferred(previousOwner?: string | null, newOwner?: string | null): OwnershipTransferredEventFilter; + + 'WrapperFeeWithdrawn(address,address,uint256)'( + oft?: string | null, + to?: null, + amount?: null + ): WrapperFeeWithdrawnEventFilter; + WrapperFeeWithdrawn(oft?: string | null, to?: null, amount?: null): WrapperFeeWithdrawnEventFilter; + + 'WrapperFees(bytes2,address,uint256,uint256)'( + partnerId?: BytesLike | null, + token?: null, + wrapperFee?: null, + callerFee?: null + ): WrapperFeesEventFilter; + WrapperFees( + partnerId?: BytesLike | null, + token?: null, + wrapperFee?: null, + callerFee?: null + ): WrapperFeesEventFilter; + }; + + estimateGas: { + BPS_DENOMINATOR(overrides?: CallOverrides): Promise; + + MAX_UINT(overrides?: CallOverrides): Promise; + + defaultBps(overrides?: CallOverrides): Promise; + + estimateSendFee( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + estimateSendFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + getAmountAndFees( + _token: string, + _amount: BigNumberish, + _callerBps: BigNumberish, + overrides?: CallOverrides + ): Promise; + + oftBps(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + sendOFT( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFT( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTFeeV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setDefaultBps(_defaultBps: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + setOFTBps(_token: string, _bps: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + withdrawFees( + _oft: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + }; + + populateTransaction: { + BPS_DENOMINATOR(overrides?: CallOverrides): Promise; + + MAX_UINT(overrides?: CallOverrides): Promise; + + defaultBps(overrides?: CallOverrides): Promise; + + estimateSendFee( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + estimateSendFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _useZro: boolean, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: CallOverrides + ): Promise; + + getAmountAndFees( + _token: string, + _amount: BigNumberish, + _callerBps: BigNumberish, + overrides?: CallOverrides + ): Promise; + + oftBps(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + sendOFT( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTFeeV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendOFTV2( + _oft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFT( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _refundAddress: string, + _zroPaymentAddress: string, + _adapterParams: BytesLike, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTFeeV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendProxyOFTV2( + _proxyOft: string, + _dstChainId: BigNumberish, + _toAddress: BytesLike, + _amount: BigNumberish, + _minAmount: BigNumberish, + _callParams: ICommonOFT.LzCallParamsStruct, + _feeObj: IOFTWrapper.FeeObjStruct, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setDefaultBps(_defaultBps: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + setOFTBps( + _token: string, + _bps: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + withdrawFees( + _oft: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + }; +} diff --git a/src/logics/stargate-v2/contracts/factories/OFTWrapper__factory.ts b/src/logics/stargate-v2/contracts/factories/OFTWrapper__factory.ts new file mode 100644 index 00000000..190ac636 --- /dev/null +++ b/src/logics/stargate-v2/contracts/factories/OFTWrapper__factory.ts @@ -0,0 +1,880 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { OFTWrapper, OFTWrapperInterface } from '../OFTWrapper'; + +const _abi = [ + { + inputs: [ + { + internalType: 'uint256', + name: '_defaultBps', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'oft', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'WrapperFeeWithdrawn', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + { + indexed: false, + internalType: 'address', + name: 'token', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'wrapperFee', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'callerFee', + type: 'uint256', + }, + ], + name: 'WrapperFees', + type: 'event', + }, + { + inputs: [], + name: 'BPS_DENOMINATOR', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'MAX_UINT', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'defaultBps', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_oft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes', + name: '_toAddress', + type: 'bytes', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'bool', + name: '_useZro', + type: 'bool', + }, + { + internalType: 'bytes', + name: '_adapterParams', + type: 'bytes', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'estimateSendFee', + outputs: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'zroFee', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_oft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes32', + name: '_toAddress', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'bool', + name: '_useZro', + type: 'bool', + }, + { + internalType: 'bytes', + name: '_adapterParams', + type: 'bytes', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'estimateSendFeeV2', + outputs: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'zroFee', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_token', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_callerBps', + type: 'uint256', + }, + ], + name: 'getAmountAndFees', + outputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'wrapperFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'callerFee', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'oftBps', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_oft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes', + name: '_toAddress', + type: 'bytes', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_minAmount', + type: 'uint256', + }, + { + internalType: 'address payable', + name: '_refundAddress', + type: 'address', + }, + { + internalType: 'address', + name: '_zroPaymentAddress', + type: 'address', + }, + { + internalType: 'bytes', + name: '_adapterParams', + type: 'bytes', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'sendOFT', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_oft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes32', + name: '_toAddress', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_minAmount', + type: 'uint256', + }, + { + components: [ + { + internalType: 'address payable', + name: 'refundAddress', + type: 'address', + }, + { + internalType: 'address', + name: 'zroPaymentAddress', + type: 'address', + }, + { + internalType: 'bytes', + name: 'adapterParams', + type: 'bytes', + }, + ], + internalType: 'struct ICommonOFT.LzCallParams', + name: '_callParams', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'sendOFTFeeV2', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_oft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes32', + name: '_toAddress', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_minAmount', + type: 'uint256', + }, + { + components: [ + { + internalType: 'address payable', + name: 'refundAddress', + type: 'address', + }, + { + internalType: 'address', + name: 'zroPaymentAddress', + type: 'address', + }, + { + internalType: 'bytes', + name: 'adapterParams', + type: 'bytes', + }, + ], + internalType: 'struct ICommonOFT.LzCallParams', + name: '_callParams', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'sendOFTV2', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_proxyOft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes', + name: '_toAddress', + type: 'bytes', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_minAmount', + type: 'uint256', + }, + { + internalType: 'address payable', + name: '_refundAddress', + type: 'address', + }, + { + internalType: 'address', + name: '_zroPaymentAddress', + type: 'address', + }, + { + internalType: 'bytes', + name: '_adapterParams', + type: 'bytes', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'sendProxyOFT', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_proxyOft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes32', + name: '_toAddress', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_minAmount', + type: 'uint256', + }, + { + components: [ + { + internalType: 'address payable', + name: 'refundAddress', + type: 'address', + }, + { + internalType: 'address', + name: 'zroPaymentAddress', + type: 'address', + }, + { + internalType: 'bytes', + name: 'adapterParams', + type: 'bytes', + }, + ], + internalType: 'struct ICommonOFT.LzCallParams', + name: '_callParams', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'sendProxyOFTFeeV2', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_proxyOft', + type: 'address', + }, + { + internalType: 'uint16', + name: '_dstChainId', + type: 'uint16', + }, + { + internalType: 'bytes32', + name: '_toAddress', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_minAmount', + type: 'uint256', + }, + { + components: [ + { + internalType: 'address payable', + name: 'refundAddress', + type: 'address', + }, + { + internalType: 'address', + name: 'zroPaymentAddress', + type: 'address', + }, + { + internalType: 'bytes', + name: 'adapterParams', + type: 'bytes', + }, + ], + internalType: 'struct ICommonOFT.LzCallParams', + name: '_callParams', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'callerBps', + type: 'uint256', + }, + { + internalType: 'address', + name: 'caller', + type: 'address', + }, + { + internalType: 'bytes2', + name: 'partnerId', + type: 'bytes2', + }, + ], + internalType: 'struct IOFTWrapper.FeeObj', + name: '_feeObj', + type: 'tuple', + }, + ], + name: 'sendProxyOFTV2', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_defaultBps', + type: 'uint256', + }, + ], + name: 'setDefaultBps', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_token', + type: 'address', + }, + { + internalType: 'uint256', + name: '_bps', + type: 'uint256', + }, + ], + name: 'setOFTBps', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_oft', + type: 'address', + }, + { + internalType: 'address', + name: '_to', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'withdrawFees', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as const; + +export class OFTWrapper__factory { + static readonly abi = _abi; + static createInterface(): OFTWrapperInterface { + return new utils.Interface(_abi) as OFTWrapperInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): OFTWrapper { + return new Contract(address, _abi, signerOrProvider) as OFTWrapper; + } +} diff --git a/src/logics/stargate-v2/contracts/factories/index.ts b/src/logics/stargate-v2/contracts/factories/index.ts index 45dfa0f2..fcbc13c1 100644 --- a/src/logics/stargate-v2/contracts/factories/index.ts +++ b/src/logics/stargate-v2/contracts/factories/index.ts @@ -1,4 +1,5 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ +export { OFTWrapper__factory } from './OFTWrapper__factory'; export { StargatePool__factory } from './StargatePool__factory'; diff --git a/src/logics/stargate-v2/contracts/index.ts b/src/logics/stargate-v2/contracts/index.ts index 9755f0b5..150ff9e4 100644 --- a/src/logics/stargate-v2/contracts/index.ts +++ b/src/logics/stargate-v2/contracts/index.ts @@ -1,6 +1,8 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ +export type { OFTWrapper } from './OFTWrapper'; export type { StargatePool } from './StargatePool'; export * as factories from './factories'; +export { OFTWrapper__factory } from './factories/OFTWrapper__factory'; export { StargatePool__factory } from './factories/StargatePool__factory'; diff --git a/src/logics/stargate-v2/logic.swap-token.test.ts b/src/logics/stargate-v2/logic.swap-token.test.ts index 3ab12b04..0a2a0608 100644 --- a/src/logics/stargate-v2/logic.swap-token.test.ts +++ b/src/logics/stargate-v2/logic.swap-token.test.ts @@ -1,11 +1,12 @@ import { LogicTestCase } from 'test/types'; -import { StargatePool__factory } from './contracts'; +import { OFTWrapper__factory, StargatePool__factory } from './contracts'; import { SwapTokenLogic, SwapTokenLogicFields, SwapTokenLogicOptions } from './logic.swap-token'; +import { bnbTokens, polygonZkevmTokens } from './tokens'; import * as common from '@protocolink/common'; import { constants, utils } from 'ethers'; import * as core from '@protocolink/core'; import { expect } from 'chai'; -import { getPoolByTokenAddress } from './configs'; +import { getPoolConfigByTokenAddress } from './configs'; describe('StargateV2 SwapTokenLogic', function () { context('Test getTokenList', async function () { @@ -19,62 +20,93 @@ describe('StargateV2 SwapTokenLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.mainnet; - const logic = new SwapTokenLogic(chainId); - const stgIface = StargatePool__factory.createInterface(); + const stgIface = OFTWrapper__factory.createInterface(); const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; const testCases: LogicTestCase[] = [ { fields: { - input: new common.TokenAmount(common.mainnetTokens.ETH, '1'), - output: new common.TokenAmount(common.optimismTokens.ETH, '1'), + input: new common.TokenAmount(bnbTokens.CAKE, '1'), + output: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), receiver: account, fee: '0', - lzTokenFee: '0', }, options: { account }, }, { fields: { - input: new common.TokenAmount(common.mainnetTokens.USDC, '1'), - output: new common.TokenAmount(common.optimismTokens.USDC, '1'), + input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), + output: new common.TokenAmount(bnbTokens.CAKE, '1'), receiver: account, - fee: '0.01', - lzTokenFee: '0.01', + fee: '0.1', }, options: { account }, }, { fields: { - input: new common.TokenAmount(common.mainnetTokens.USDC, '1'), - output: new common.TokenAmount(common.optimismTokens.USDC, '1'), + input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), + output: new common.TokenAmount(bnbTokens.CAKE, '1'), receiver: account, - fee: '0.01', - lzTokenFee: '0.01', + fee: '0.1', balanceBps: 5000, }, options: { account }, }, + // { + // fields: { + // input: new common.TokenAmount(common.mainnetTokens.ETH, '1'), + // output: new common.TokenAmount(common.optimismTokens.ETH, '1'), + // receiver: account, + // fee: '0', + // lzTokenFee: '0', + // }, + // options: { account }, + // }, + // { + // fields: { + // input: new common.TokenAmount(common.mainnetTokens.USDC, '1'), + // output: new common.TokenAmount(common.optimismTokens.USDC, '1'), + // receiver: account, + // fee: '0.01', + // lzTokenFee: '0.01', + // }, + // options: { account }, + // }, + // { + // fields: { + // input: new common.TokenAmount(common.mainnetTokens.USDC, '1'), + // output: new common.TokenAmount(common.optimismTokens.USDC, '1'), + // receiver: account, + // fee: '0.01', + // lzTokenFee: '0.01', + // balanceBps: 5000, + // }, + // options: { account }, + // }, ]; testCases.forEach(({ fields, options }) => { it(`${fields.input.token.symbol} to ${fields.output.token.symbol}`, async function () { + const logic = new SwapTokenLogic(fields.input.token.chainId); const routerLogic = await logic.build(fields, options); const sig = routerLogic.data.substring(0, 10); const { input, balanceBps, fee } = fields; - const poolAddress = getPoolByTokenAddress(chainId, input.token.address); + const pool = getPoolConfigByTokenAddress(input.token.chainId, input.token.address); - expect(routerLogic.to).to.eq(poolAddress); - expect(sig).to.eq(stgIface.getSighash('sendToken')); + expect(routerLogic.to).to.eq(pool.address); + if (pool.proxyOFT) { + expect(sig).to.eq(stgIface.getSighash('sendProxyOFTFeeV2')); + } else { + expect(sig).to.eq(stgIface.getSighash('sendOFTFeeV2')); + } expect(routerLogic.inputs[0].token).to.eq(input.token.elasticAddress); - expect(routerLogic.inputs[1].token).to.eq(common.mainnetTokens.ETH.elasticAddress); + expect(routerLogic.inputs[1].token).to.eq(common.getNativeToken(input.token.chainId).elasticAddress); expect(routerLogic.inputs[1].amountOrOffset).to.eq(common.toSmallUnit(fee, common.mainnetTokens.ETH.decimals)); expect(utils.isBytesLike(routerLogic.data)).to.be.true; if (balanceBps) { expect(routerLogic.inputs[0].balanceBps).to.eq(balanceBps); - expect(routerLogic.inputs[0].amountOrOffset).to.eq(common.getParamOffset(2)); + expect(routerLogic.inputs[0].amountOrOffset).to.eq(common.getParamOffset(3)); } else { expect(routerLogic.inputs[0].balanceBps).to.eq(core.BPS_NOT_USED); expect(routerLogic.inputs[0].amountOrOffset).eq(input.amountWei); diff --git a/src/logics/stargate-v2/logic.swap-token.ts b/src/logics/stargate-v2/logic.swap-token.ts index a9b53794..56f953fc 100644 --- a/src/logics/stargate-v2/logic.swap-token.ts +++ b/src/logics/stargate-v2/logic.swap-token.ts @@ -1,16 +1,16 @@ -import { StargatePool__factory } from './contracts'; -import * as common from '@protocolink/common'; -import * as core from '@protocolink/core'; +import { BigNumber, constants, utils } from 'ethers'; +import { OFTWrapper__factory } from './contracts'; import { + PoolId, getDestChainIds, getDestToken, - getEndpointId, getMarkets, - getPoolByTokenAddress, + getPoolConfigByTokenAddress, + getStargateChainId, supportedChainIds, } from './configs'; -import { getNativeToken } from '@protocolink/common'; -import { utils } from 'ethers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; export type SwapTokenLogicTokenList = { srcToken: common.Token; @@ -24,7 +24,7 @@ export type SwapTokenLogicParams = core.TokenToTokenExactInParams<{ export type SwapTokenLogicFields = core.TokenToTokenExactInFields<{ receiver: string; fee: string; - lzTokenFee: string; + // lzTokenFee: string; }>; export type SwapTokenLogicOptions = Pick; @@ -60,84 +60,154 @@ export class SwapTokenLogic extends core.Logic implements core.LogicBuilderInter public async quote(params: SwapTokenLogicParams) { const { input, tokenOut, receiver } = params; - - // check if tokenOut is legit - const destToken = getDestToken(input.token, tokenOut.chainId); - if (!tokenOut.is(destToken)) { - return { - input, - output: new common.TokenAmount(tokenOut), - fee: '0', - lzTokenFee: '0', - receiver, + const pool = getPoolConfigByTokenAddress(input.token.chainId, input.token.address); + + let output = new common.TokenAmount(tokenOut); + let fee = BigNumber.from('0'); + if (pool.id === PoolId.OFT) { + const oftWrapper = OFTWrapper__factory.connect(pool.address, this.provider); + const oft = pool.proxyOFT ? pool.proxyOFT : input.token.address; + const destChainId = getStargateChainId(tokenOut.chainId); + const srcAmount = input.amountWei; + const adapterParameters = utils.solidityPack(['uint16', 'uint256'], [1, 200000]); + const feeObj = { + callerBps: 0, + caller: constants.AddressZero, + partnerId: utils.hexZeroPad(utils.solidityPack(['bytes'], [0]), 2), }; - } - - const dstEid = getEndpointId(tokenOut.chainId); - const to = utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32); - const poolAddress = getPoolByTokenAddress(this.chainId, input.token.address); - const amountLD = input.amountWei; - const sendParam = { - dstEid, - to, - amountLD, - minAmountLD: amountLD, - extraOptions: utils.solidityPack(['string'], ['']), - composeMsg: utils.solidityPack(['string'], ['']), - oftCmd: utils.solidityPack(['string'], ['']), - }; - - const stargate = StargatePool__factory.connect(poolAddress, this.provider); - const [, , receipt] = await stargate.quoteOFT(sendParam); - sendParam.minAmountLD = receipt.amountReceivedLD; - - const messagingFee = await stargate.quoteSend(sendParam, false); - const fee = messagingFee.nativeFee; - const lzTokenFee = messagingFee.lzTokenFee; - - const output = new common.TokenAmount(tokenOut).setWei(receipt.amountReceivedLD); + [fee] = await oftWrapper.estimateSendFeeV2( + oft, + destChainId, + utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32), + input.amountWei, + false, + adapterParameters, + feeObj + ); + + const [amount] = await oftWrapper.getAmountAndFees(oft, srcAmount, feeObj.callerBps); + output = output.setWei(amount); + } + // } else { + + // // check if tokenOut is legit + // const destToken = getDestToken(input.token, tokenOut.chainId); + // if (!tokenOut.is(destToken)) { + // return { + // input, + // output: new common.TokenAmount(tokenOut), + // fee: '0', + // lzTokenFee: '0', + // receiver, + // }; + // } + + // const dstEid = getEndpointId(tokenOut.chainId); + // const to = utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32); + // const poolAddress = getPoolByTokenAddress(this.chainId, input.token.address); + // const amountLD = input.amountWei; + // const sendParam = { + // dstEid, + // to, + // amountLD, + // minAmountLD: amountLD, + // extraOptions: utils.solidityPack(['string'], ['']), + // composeMsg: utils.solidityPack(['string'], ['']), + // oftCmd: utils.solidityPack(['string'], ['']), + // }; + + // const stargate = StargatePool__factory.connect(poolAddress, this.provider); + // const [, , receipt] = await stargate.quoteOFT(sendParam); + // sendParam.minAmountLD = receipt.amountReceivedLD; + + // const messagingFee = await stargate.quoteSend(sendParam, false); + // const fee = common.toBigUnit(messagingFee.nativeFee, getNativeToken(this.chainId).decimals), + // const lzTokenFee = common.toBigUnit(messagingFee.lzTokenFee, getNativeToken(this.chainId).decimals); + // const output = new common.TokenAmount(tokenOut).setWei(receipt.amountReceivedLD); + // } return { input, output, - fee: common.toBigUnit(fee, getNativeToken(this.chainId).decimals), - lzTokenFee: common.toBigUnit(lzTokenFee, getNativeToken(this.chainId).decimals), + fee: common.toBigUnit(fee, common.getNativeToken(this.chainId).decimals), receiver, }; } async build(fields: SwapTokenLogicFields, options: SwapTokenLogicOptions) { - const { input, output, fee, lzTokenFee, receiver, balanceBps } = fields; + const { input, output, fee, /*lzTokenFee,*/ receiver, balanceBps } = fields; const { account } = options; const refundAddress = account; - const to = getPoolByTokenAddress(this.chainId, input.token.address); - const dstEid = getEndpointId(output.token.chainId); - const amountLD = input.amountWei; - const minAmountLD = output.amountWei; - const sendParam = { - dstEid, - to: utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32), - amountLD, - minAmountLD, - extraOptions: utils.solidityPack(['string'], ['']), - composeMsg: utils.solidityPack(['string'], ['']), - oftCmd: utils.solidityPack(['string'], ['']), - }; - - const nativeToken = getNativeToken(this.chainId); - const messagingFee = { - nativeFee: new common.TokenAmount(nativeToken, fee).amountWei, - lzTokenFee: new common.TokenAmount(nativeToken, lzTokenFee).amountWei, - }; + const pool = getPoolConfigByTokenAddress(input.token.chainId, input.token.address); + const to = pool.address; - const data = StargatePool__factory.createInterface().encodeFunctionData('sendToken', [ - sendParam, - messagingFee, + const destChainId = getStargateChainId(output.token.chainId); + const receiverBytes32 = utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32); + const amount = input.amountWei; + const minAmount = output.amountWei; + const adapterParams = utils.solidityPack(['uint16', 'uint256'], [1, 200000]); + const lzCallParams = { refundAddress, - ]); + zroPaymentAddress: constants.AddressZero, + adapterParams, + }; + const feeObj = { + callerBps: 0, + caller: constants.AddressZero, + partnerId: utils.hexZeroPad(utils.solidityPack(['bytes'], [0]), 2), + }; + const amountOffset = balanceBps ? common.getParamOffset(3) : undefined; + + let data = ''; + if (pool.proxyOFT) { + data = OFTWrapper__factory.createInterface().encodeFunctionData('sendProxyOFTFeeV2', [ + pool.proxyOFT, + destChainId, + receiverBytes32, + amount, + minAmount, + lzCallParams, + feeObj, + ]); + } else if (pool.id == PoolId.OFT) { + data = OFTWrapper__factory.createInterface().encodeFunctionData('sendOFTFeeV2', [ + input.token.address, + destChainId, + receiverBytes32, + amount, + minAmount, + lzCallParams, + feeObj, + ]); + } + // else { + // const dstEid = getEndpointId(output.token.chainId); + // const amountLD = input.amountWei; + // const minAmountLD = output.amountWei; + // const sendParam = { + // dstEid, + // to: utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32), + // amountLD, + // minAmountLD, + // extraOptions: utils.solidityPack(['string'], ['']), + // composeMsg: utils.solidityPack(['string'], ['']), + // oftCmd: utils.solidityPack(['string'], ['']), + // }; + // const nativeToken = getNativeToken(this.chainId); + // const messagingFee = { + // nativeFee: new common.TokenAmount(nativeToken, fee).amountWei, + // lzTokenFee: new common.TokenAmount(nativeToken, lzTokenFee).amountWei, + // }; + // const data = StargatePool__factory.createInterface().encodeFunctionData('sendToken', [ + // sendParam, + // messagingFee, + // refundAddress, + // ]); + // does not support unwrapBefore so users need to unwrap wrapped native token first + // } - const amountOffset = balanceBps ? common.getParamOffset(2) : undefined; + // const amountOffset = balanceBps ? common.getParamOffset(2) : undefined; const inputs = [ core.newLogicInput({ @@ -145,10 +215,9 @@ export class SwapTokenLogic extends core.Logic implements core.LogicBuilderInter balanceBps, amountOffset, }), - core.newLogicInput({ input: new common.TokenAmount(getNativeToken(this.chainId), fee) }), + core.newLogicInput({ input: new common.TokenAmount(common.getNativeToken(this.chainId), fee) }), ]; - // does not support unwrapBefore so users need to unwrap wrapped native token first const wrapMode = core.WrapMode.none; return core.newLogic({ to, data, inputs, wrapMode }); } diff --git a/src/logics/stargate-v2/tokens/data/bnb.json b/src/logics/stargate-v2/tokens/data/bnb.json new file mode 100644 index 00000000..ef8a8829 --- /dev/null +++ b/src/logics/stargate-v2/tokens/data/bnb.json @@ -0,0 +1,9 @@ +{ + "CAKE": { + "chainId": 56, + "address": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82", + "decimals": 18, + "symbol": "CAKE", + "name": "PancakeSwap Token" + } +} diff --git a/src/logics/stargate-v2/tokens/data/mainnet.json b/src/logics/stargate-v2/tokens/data/mainnet.json index f57373e8..f0366991 100644 --- a/src/logics/stargate-v2/tokens/data/mainnet.json +++ b/src/logics/stargate-v2/tokens/data/mainnet.json @@ -5,5 +5,12 @@ "decimals": 18, "symbol": "Metis", "name": "Metis Token" + }, + "CAKE": { + "chainId": 1, + "address": "0x152649ea73beab28c5b49b26eb48f7ead6d4c898", + "decimals": 18, + "symbol": "CAKE", + "name": "PancakeSwap Token" } } diff --git a/src/logics/stargate-v2/tokens/data/polygonZkevm.json b/src/logics/stargate-v2/tokens/data/polygonZkevm.json new file mode 100644 index 00000000..bf4c77b8 --- /dev/null +++ b/src/logics/stargate-v2/tokens/data/polygonZkevm.json @@ -0,0 +1,9 @@ +{ + "CAKE": { + "chainId": 1101, + "address": "0x0D1E753a25eBda689453309112904807625bEFBe", + "decimals": 18, + "symbol": "CAKE", + "name": "PancakeSwap Token" + } +} diff --git a/src/logics/stargate-v2/tokens/index.ts b/src/logics/stargate-v2/tokens/index.ts index 369937b5..abac12dd 100644 --- a/src/logics/stargate-v2/tokens/index.ts +++ b/src/logics/stargate-v2/tokens/index.ts @@ -1,11 +1,21 @@ +import bnbTokensJSON from './data/bnb.json'; import * as common from '@protocolink/common'; import mainnetTokensJSON from './data/mainnet.json'; import metisTokensJSON from './data/metis.json'; +import polygonZkevmTokensJSON from './data/polygonZkevm.json'; type MainnetTokenSymbols = keyof typeof mainnetTokensJSON; export const mainnetTokens = common.toTokenMap(mainnetTokensJSON); +type BnbTokenSymbols = keyof typeof bnbTokensJSON; + +export const bnbTokens = common.toTokenMap(bnbTokensJSON); + type MetisTokenSymbols = keyof typeof metisTokensJSON; export const metisTokens = common.toTokenMap(metisTokensJSON); + +type PolygonZkevmTokenSymbols = keyof typeof polygonZkevmTokensJSON; + +export const polygonZkevmTokens = common.toTokenMap(polygonZkevmTokensJSON); diff --git a/test/logics/stargate-v2/swap-token-bnb.test.ts b/test/logics/stargate-v2/swap-token-bnb.test.ts new file mode 100644 index 00000000..23f65cc0 --- /dev/null +++ b/test/logics/stargate-v2/swap-token-bnb.test.ts @@ -0,0 +1,85 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import { getNativeToken } from '@protocolink/common'; +import hre from 'hardhat'; +import { polygonZkevmTokens } from 'src/logics/stargate-v2/tokens'; +import * as stargate from 'src/logics/stargate-v2'; +import * as utils from 'test/utils'; + +describe('bnb: Test StargateV2 SwapToken Logic', function () { + let chainId: number; + let user: SignerWithAddress; + + before(async function () { + chainId = await getChainId(); + [, user] = await hre.ethers.getSigners(); + await claimToken(chainId, user.address, common.bnbTokens.Cake, '10', '0x000000000000000000000000000000000000dead'); + }); + + snapshotAndRevertEach(); + + const testCases = [ + { + params: { + input: new common.TokenAmount(common.bnbTokens.Cake, '1'), + tokenOut: polygonZkevmTokens.CAKE, + }, + }, + { + params: { + input: new common.TokenAmount(common.bnbTokens.Cake, '1'), + tokenOut: polygonZkevmTokens.CAKE, + }, + balanceBps: 5000, + }, + ]; + + testCases.forEach(({ params, balanceBps }, i) => { + it(`case ${i + 1}`, async function () { + // 1. get input or output + const stargateSwapTokenLogic = new stargate.SwapTokenLogic(chainId); + const quotation = await stargateSwapTokenLogic.quote({ receiver: user.address, ...params }); + const { input, fee } = quotation; + + // 2. build funds, tokensReturn + const feeTokenAmount = new common.TokenAmount(getNativeToken(chainId), fee); + const funds = new common.TokenAmounts([feeTokenAmount]); + const tokensReturn = [input.token.elasticAddress]; + if (balanceBps) { + funds.add(utils.calcRequiredAmountByBalanceBps(input, balanceBps)); + tokensReturn.push(input.token.elasticAddress); + } else { + funds.add(input); + } + + // 3. build router logics + const routerLogics: core.DataType.LogicStruct[] = []; + routerLogics.push(await stargateSwapTokenLogic.build(quotation, { account: user.address })); + + // 4. get router permit2 datas + let permit2Datas; + if (!input.token.isNative) { + permit2Datas = await utils.getRouterPermit2Datas(chainId, user, funds.erc20); + } + // 5. send router tx + const routerKit = new core.RouterKit(chainId); + const transactionRequest = routerKit.buildExecuteTransactionRequest({ + permit2Datas, + routerLogics, + tokensReturn, + value: funds.native?.amountWei ?? 0, + }); + + await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; + if (input.token.isNative) { + await expect(user.address).to.changeBalance(getNativeToken(chainId), -input.add(fee).amount, 1); + } else { + await expect(user.address).to.changeBalance(input.token, -input.amount); + await expect(user.address).to.changeBalance(getNativeToken(chainId), -fee); + } + }); + }); +}); diff --git a/test/logics/stargate-v2/swap-token.test.ts b/test/logics/stargate-v2/swap-token-mainnet.test.ts.bkup similarity index 100% rename from test/logics/stargate-v2/swap-token.test.ts rename to test/logics/stargate-v2/swap-token-mainnet.test.ts.bkup diff --git a/test/logics/stargate-v2/swap-token-polygonZkevm.test.ts b/test/logics/stargate-v2/swap-token-polygonZkevm.test.ts new file mode 100644 index 00000000..a74399d7 --- /dev/null +++ b/test/logics/stargate-v2/swap-token-polygonZkevm.test.ts @@ -0,0 +1,91 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import { getNativeToken } from '@protocolink/common'; +import hre from 'hardhat'; +import { polygonZkevmTokens } from 'src/logics/stargate-v2/tokens'; +import * as stargate from 'src/logics/stargate-v2'; +import * as utils from 'test/utils'; + +describe('polygonZkevm: Test StargateV2 SwapToken Logic', function () { + let chainId: number; + let user: SignerWithAddress; + + before(async function () { + chainId = await getChainId(); + [, user] = await hre.ethers.getSigners(); + await claimToken( + chainId, + user.address, + polygonZkevmTokens.CAKE, + '10', + '0xb4BAB40e5a869eF1b5ff440a170A57d9feb228e9' + ); + }); + + snapshotAndRevertEach(); + + const testCases = [ + { + params: { + input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), + tokenOut: common.bnbTokens.Cake, + }, + }, + { + params: { + input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), + tokenOut: common.bnbTokens.Cake, + }, + balanceBps: 5000, + }, + ]; + + testCases.forEach(({ params, balanceBps }, i) => { + it(`case ${i + 1}`, async function () { + // 1. get input or output + const stargateSwapTokenLogic = new stargate.SwapTokenLogic(chainId); + const quotation = await stargateSwapTokenLogic.quote({ receiver: user.address, ...params }); + const { input, fee } = quotation; + + // 2. build funds, tokensReturn + const feeTokenAmount = new common.TokenAmount(getNativeToken(chainId), fee); + const funds = new common.TokenAmounts([feeTokenAmount]); + const tokensReturn = [input.token.elasticAddress]; + if (balanceBps) { + funds.add(utils.calcRequiredAmountByBalanceBps(input, balanceBps)); + tokensReturn.push(input.token.elasticAddress); + } else { + funds.add(input); + } + + // 3. build router logics + const routerLogics: core.DataType.LogicStruct[] = []; + routerLogics.push(await stargateSwapTokenLogic.build(quotation, { account: user.address })); + + // 4. get router permit2 datas + let permit2Datas; + if (!input.token.isNative) { + permit2Datas = await utils.getRouterPermit2Datas(chainId, user, funds.erc20); + } + // 5. send router tx + const routerKit = new core.RouterKit(chainId); + const transactionRequest = routerKit.buildExecuteTransactionRequest({ + permit2Datas, + routerLogics, + tokensReturn, + value: funds.native?.amountWei ?? 0, + }); + + await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; + if (input.token.isNative) { + await expect(user.address).to.changeBalance(getNativeToken(chainId), -input.add(fee).amount, 1); + } else { + await expect(user.address).to.changeBalance(input.token, -input.amount); + await expect(user.address).to.changeBalance(getNativeToken(chainId), -fee); + } + }); + }); +});