diff --git a/.env.bnb b/.env.bnb index ccc44ad..4782d42 100644 --- a/.env.bnb +++ b/.env.bnb @@ -1,2 +1,2 @@ CHAIN_ID=56 -HTTP_RPC_URL=https://bsc-dataseed.binance.org +HTTP_RPC_URL=https://rpc.ankr.com/bsc diff --git a/.env.polygonZkevm b/.env.polygonZkevm new file mode 100644 index 0000000..2c728d4 --- /dev/null +++ b/.env.polygonZkevm @@ -0,0 +1,2 @@ +CHAIN_ID=1101 +HTTP_RPC_URL=https://zkevm-rpc.com diff --git a/package.json b/package.json index 1c37d47..8102525 100644 --- a/package.json +++ b/package.json @@ -20,19 +20,21 @@ "lint": "eslint --fix src", "prepublishOnly": "yarn build", "test": "mocha", - "test:e2e:latest": "yarn run test:e2e:mainnet && yarn run test:e2e:metis", + "test:e2e:latest": "yarn run test:e2e:mainnet && yarn run test:e2e:metis && yarn run test:e2e:bnb && yarn run test:e2e:polygonZkevm", "test:e2e:mainnet": "env-cmd -f .env.mainnet hardhat test --grep 'mainnet:'", "test:e2e:mainnet:pb": "env-cmd -f .env.mainnet.pb hardhat test --grep 'mainnet-pb:'", "test:e2e:optimism:pb": "env-cmd -f .env.optimism.pb hardhat test --grep 'optimism-pb:'", "test:e2e:iota:pb": "env-cmd -f .env.iota.pb hardhat test --grep 'iota-pb:'", "test:e2e:metis": "env-cmd -f .env.metis hardhat test --grep 'metis:'", + "test:e2e:bnb": "env-cmd -f .env.bnb hardhat test --grep 'bnb:'", + "test:e2e:polygonZkevm": "env-cmd -f .env.polygonZkevm hardhat test --grep 'polygonZkevm:'", "test:unit": "mocha --recursive src" }, "dependencies": { "@paraswap/sdk": "^6.6.0", - "@protocolink/common": "^0.5.3", - "@protocolink/core": "^0.6.2", - "@protocolink/smart-accounts": "^0.1.6", + "@protocolink/common": "^0.5.4", + "@protocolink/core": "^0.6.3", + "@protocolink/smart-accounts": "^0.1.7", "@types/lodash": "^4.14.195", "@uniswap/sdk": "^3.0.3", "@uniswap/sdk-core": "^3.2.6", @@ -50,7 +52,7 @@ "@nomicfoundation/hardhat-chai-matchers": "^1.0.6", "@nomicfoundation/hardhat-network-helpers": "^1.0.8", "@nomiclabs/hardhat-ethers": "^2.2.3", - "@protocolink/test-helpers": "^0.4.4", + "@protocolink/test-helpers": "^0.4.5", "@typechain/ethers-v5": "^11.0.0", "@types/chai": "^4.3.5", "@types/fs-extra": "^11.0.1", diff --git a/src/logics/stargate-v2/configs.ts b/src/logics/stargate-v2/configs.ts index ad999f2..4816bff 100644 --- a/src/logics/stargate-v2/configs.ts +++ b/src/logics/stargate-v2/configs.ts @@ -1,4 +1,3 @@ -import { bnbTokens, mainnetTokens, metisTokens, polygonZkevmTokens } from './tokens'; import * as common from '@protocolink/common'; export enum StargateChainId { @@ -51,51 +50,51 @@ 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 }], - // // }, + // { + // 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 }], + // }, // ], // }, { @@ -105,7 +104,7 @@ export const configs: Config[] = [ pools: [ { id: PoolId.OFT, - token: bnbTokens.CAKE, + token: common.bnbTokens.Cake, address: '0x86355F02119bdBC28ED6A4D5E0cA327Ca7730fFF', // OFTWrapper proxyOFT: '0xb274202daBA6AE180c665B4fbE59857b7c3a8091', destinations: [{ chainId: common.ChainId.polygonZkevm, endpointId: EndpointId.OFT }], @@ -185,7 +184,7 @@ export const configs: Config[] = [ pools: [ { id: PoolId.OFT, - token: polygonZkevmTokens.CAKE, + token: common.polygonZkevmTokens.Cake, address: '0x86355F02119bdBC28ED6A4D5E0cA327Ca7730fFF', // OFTWrapper destinations: [{ chainId: common.ChainId.bnb, endpointId: EndpointId.OFT }], }, diff --git a/src/logics/stargate-v2/logic.swap-token.test.ts b/src/logics/stargate-v2/logic.swap-token.test.ts index 0a2a060..f1cd4da 100644 --- a/src/logics/stargate-v2/logic.swap-token.test.ts +++ b/src/logics/stargate-v2/logic.swap-token.test.ts @@ -1,7 +1,6 @@ import { LogicTestCase } from 'test/types'; -import { OFTWrapper__factory, StargatePool__factory } from './contracts'; +import { OFTWrapper__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'; @@ -26,8 +25,8 @@ describe('StargateV2 SwapTokenLogic', function () { const testCases: LogicTestCase[] = [ { fields: { - input: new common.TokenAmount(bnbTokens.CAKE, '1'), - output: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), + input: new common.TokenAmount(common.bnbTokens.Cake, '1'), + output: new common.TokenAmount(common.polygonZkevmTokens.Cake, '1'), receiver: account, fee: '0', }, @@ -35,8 +34,8 @@ describe('StargateV2 SwapTokenLogic', function () { }, { fields: { - input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), - output: new common.TokenAmount(bnbTokens.CAKE, '1'), + input: new common.TokenAmount(common.polygonZkevmTokens.Cake, '1'), + output: new common.TokenAmount(common.bnbTokens.Cake, '1'), receiver: account, fee: '0.1', }, @@ -44,8 +43,8 @@ describe('StargateV2 SwapTokenLogic', function () { }, { fields: { - input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), - output: new common.TokenAmount(bnbTokens.CAKE, '1'), + input: new common.TokenAmount(common.polygonZkevmTokens.Cake, '1'), + output: new common.TokenAmount(common.bnbTokens.Cake, '1'), receiver: account, fee: '0.1', balanceBps: 5000, diff --git a/src/logics/stargate-v2/logic.swap-token.ts b/src/logics/stargate-v2/logic.swap-token.ts index 56f953f..223feb3 100644 --- a/src/logics/stargate-v2/logic.swap-token.ts +++ b/src/logics/stargate-v2/logic.swap-token.ts @@ -85,10 +85,18 @@ export class SwapTokenLogic extends core.Logic implements core.LogicBuilderInter adapterParameters, feeObj ); + fee = common.calcSlippage(fee, -1); // slightly higher than the quoted fee const [amount] = await oftWrapper.getAmountAndFees(oft, srcAmount, feeObj.callerBps); output = output.setWei(amount); } + + return { + input, + output, + fee: common.toBigUnit(fee, common.getNativeToken(this.chainId).decimals), + receiver, + }; // } else { // // check if tokenOut is legit @@ -126,12 +134,6 @@ export class SwapTokenLogic extends core.Logic implements core.LogicBuilderInter // 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, common.getNativeToken(this.chainId).decimals), - receiver, - }; } async build(fields: SwapTokenLogicFields, options: SwapTokenLogicOptions) { diff --git a/src/logics/stargate-v2/tokens/data/bnb.json b/src/logics/stargate-v2/tokens/data/bnb.json deleted file mode 100644 index ef8a882..0000000 --- a/src/logics/stargate-v2/tokens/data/bnb.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "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 f036699..f57373e 100644 --- a/src/logics/stargate-v2/tokens/data/mainnet.json +++ b/src/logics/stargate-v2/tokens/data/mainnet.json @@ -5,12 +5,5 @@ "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 deleted file mode 100644 index bf4c77b..0000000 --- a/src/logics/stargate-v2/tokens/data/polygonZkevm.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "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 abac12d..369937b 100644 --- a/src/logics/stargate-v2/tokens/index.ts +++ b/src/logics/stargate-v2/tokens/index.ts @@ -1,21 +1,11 @@ -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 index 23f65cc..ff09243 100644 --- a/test/logics/stargate-v2/swap-token-bnb.test.ts +++ b/test/logics/stargate-v2/swap-token-bnb.test.ts @@ -5,7 +5,6 @@ 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'; @@ -25,13 +24,13 @@ describe('bnb: Test StargateV2 SwapToken Logic', function () { { params: { input: new common.TokenAmount(common.bnbTokens.Cake, '1'), - tokenOut: polygonZkevmTokens.CAKE, + tokenOut: common.polygonZkevmTokens.Cake, }, }, { params: { input: new common.TokenAmount(common.bnbTokens.Cake, '1'), - tokenOut: polygonZkevmTokens.CAKE, + tokenOut: common.polygonZkevmTokens.Cake, }, balanceBps: 5000, }, @@ -78,7 +77,7 @@ describe('bnb: Test StargateV2 SwapToken Logic', function () { 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); + await expect(user.address).to.changeBalance(getNativeToken(chainId), -fee, 1); } }); }); diff --git a/test/logics/stargate-v2/swap-token-polygonZkevm.test.ts b/test/logics/stargate-v2/swap-token-polygonZkevm.test.ts index a74399d..e398f36 100644 --- a/test/logics/stargate-v2/swap-token-polygonZkevm.test.ts +++ b/test/logics/stargate-v2/swap-token-polygonZkevm.test.ts @@ -5,7 +5,6 @@ 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'; @@ -19,7 +18,7 @@ describe('polygonZkevm: Test StargateV2 SwapToken Logic', function () { await claimToken( chainId, user.address, - polygonZkevmTokens.CAKE, + common.polygonZkevmTokens.Cake, '10', '0xb4BAB40e5a869eF1b5ff440a170A57d9feb228e9' ); @@ -30,13 +29,13 @@ describe('polygonZkevm: Test StargateV2 SwapToken Logic', function () { const testCases = [ { params: { - input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), + input: new common.TokenAmount(common.polygonZkevmTokens.Cake, '1'), tokenOut: common.bnbTokens.Cake, }, }, { params: { - input: new common.TokenAmount(polygonZkevmTokens.CAKE, '1'), + input: new common.TokenAmount(common.polygonZkevmTokens.Cake, '1'), tokenOut: common.bnbTokens.Cake, }, balanceBps: 5000, @@ -84,7 +83,7 @@ describe('polygonZkevm: Test StargateV2 SwapToken Logic', function () { 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); + await expect(user.address).to.changeBalance(getNativeToken(chainId), -fee, 1); } }); }); diff --git a/yarn.lock b/yarn.lock index 6653385..efcb06e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1020,10 +1020,10 @@ bignumber.js "^9.0.2" ts-essentials "^9.1.2" -"@protocolink/common@^0.5.3": - version "0.5.3" - resolved "https://registry.yarnpkg.com/@protocolink/common/-/common-0.5.3.tgz#d0e2bc756d5fa2da679b16e3fa389e37f76e1b33" - integrity sha512-ZGHzalkFnt7nSt7wKrxOOMrNfmxSSinGSUE0+g/8m3ZMiTVmuQLrkkiAHWC0gIx7b1oRsTTyeUhuue9igmdPcg== +"@protocolink/common@^0.5.4": + version "0.5.4" + resolved "https://registry.yarnpkg.com/@protocolink/common/-/common-0.5.4.tgz#77eba2a0f79ed2f109cb0c48bf86a50a3ff1a83b" + integrity sha512-/8nxm2Tw7eryq3YF19tUnlsNRN5oyjqUWeZ11jclabOq5CQAdjeKNjbv0/GS2rkVbPUwPhXIv3bHGzuBntWD8g== dependencies: "@types/lodash" "^4.14.195" axios "^1.3.6" @@ -1035,34 +1035,34 @@ type-fest "^3.12.0" zksync-web3 "^0.14.3" -"@protocolink/core@^0.6.2": - version "0.6.2" - resolved "https://registry.yarnpkg.com/@protocolink/core/-/core-0.6.2.tgz#ae4d9d7fe6e24e260bdd2bfa365754d61fe5bd51" - integrity sha512-0iZOf0DrovkG4jXzaxlIKOrzgwpOAUEQRrp9llB4fyq4b/+KbJPTfYC4/OmkYfxAcJtaRK0zNnx2AH8NivAk2A== +"@protocolink/core@^0.6.3": + version "0.6.3" + resolved "https://registry.yarnpkg.com/@protocolink/core/-/core-0.6.3.tgz#d220f18a36daa42b0d0652b21447372688a22987" + integrity sha512-v/ZEJuJRPCPLE+x3QmVLa0/OHJhWzoUTPuHDLpdLhq1GBj1hAZ4X3UKkIkYM52kU7zj3c71idB4OY1mas4inLw== dependencies: - "@protocolink/common" "^0.5.3" + "@protocolink/common" "^0.5.4" "@uniswap/permit2-sdk" "^1.2.0" ethers "^5.7.2" tiny-invariant "^1.3.1" -"@protocolink/smart-accounts@^0.1.6": - version "0.1.6" - resolved "https://registry.yarnpkg.com/@protocolink/smart-accounts/-/smart-accounts-0.1.6.tgz#3853d6508e91f25f36046f8ea8ecff8357f80e2d" - integrity sha512-S85Z0DovdqBYBXctFKIvUXfML7aS8ucS5zKgS6vHIxWfsXNiRbcX3gxoAw12KZYrz1+nbXQvTGxdocvaOpEXBA== +"@protocolink/smart-accounts@^0.1.7": + version "0.1.7" + resolved "https://registry.yarnpkg.com/@protocolink/smart-accounts/-/smart-accounts-0.1.7.tgz#8b87b5c48738062b3cc1c1e8f4d8bd5a05c3396c" + integrity sha512-MlUZ/8kFAxolY7vVu8RPvS1x+yhVUuFq9sY7UvUUMWDqQcjtwzPm8r3ATszUwCPWUywe8tsd0W/Ve5635iKZnQ== dependencies: - "@protocolink/common" "^0.5.3" + "@protocolink/common" "^0.5.4" ethers "^5.7.2" tiny-invariant "^1.3.1" -"@protocolink/test-helpers@^0.4.4": - version "0.4.4" - resolved "https://registry.yarnpkg.com/@protocolink/test-helpers/-/test-helpers-0.4.4.tgz#7f8faa2aa8547c094fd1972a67e9383d59465fef" - integrity sha512-sGWQb1PGhqpNAg50nqYrvqZkqR6K8+zPbCmoFonQGElhzoGCYSJ4lQEINCoEwvOsn0AlLxnT5PX59Y92g7u7ig== +"@protocolink/test-helpers@^0.4.5": + version "0.4.5" + resolved "https://registry.yarnpkg.com/@protocolink/test-helpers/-/test-helpers-0.4.5.tgz#fb39525e02feee3d3021aa5f498102de1d48555f" + integrity sha512-Asjd4jqHwbjQlGdPrFbHLrnPZyalsIuxkwQ2/+TzL2X4cdFmb3JD1rahPhbWZ156gdiZC1FL0bj103oNuSw7kg== dependencies: "@nomicfoundation/hardhat-chai-matchers" "^1.0.6" "@nomicfoundation/hardhat-network-helpers" "^1.0.8" "@nomiclabs/hardhat-ethers" "^2.2.3" - "@protocolink/common" "^0.5.3" + "@protocolink/common" "^0.5.4" "@types/chai" "^4.3.5" "@types/mocha" "^10.0.1" chai "^4.3.7"