From ea4c1e72216276d6f1d5fa124db732ff216e7e46 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 12:30:20 +0300 Subject: [PATCH 01/11] BACK-1226: Integrate PancakeSwapV2 on Arbitrum --- src/dex/uniswap-v2/config.ts | 9 +++ .../uniswap-v2-e2e-arbitrum.test.ts | 64 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/dex/uniswap-v2/config.ts b/src/dex/uniswap-v2/config.ts index 4c4399048..34fb93bc6 100644 --- a/src/dex/uniswap-v2/config.ts +++ b/src/dex/uniswap-v2/config.ts @@ -386,6 +386,15 @@ export const UniswapV2Config: DexConfigMap = { poolGasCost: 90 * 1000, feeCode: 25, }, + [Network.ARBITRUM]: { + subgraphURL: + 'https://api.studio.thegraph.com/query/45376/exchange-v2-arbitrum/version/latest', + factoryAddress: '0x02a84c1b3BBD7401a5f7fa98a384EBC70bB5749E', + initCode: + '0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d', + poolGasCost: 90 * 1000, + feeCode: 25, + }, }, PaintSwap: { [Network.FANTOM]: { diff --git a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts index 2ae9450b2..a430fa1cc 100644 --- a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts +++ b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts @@ -359,4 +359,68 @@ describe('UniswapV2 E2E Arbitrum', () => { }), ); }); + + describe('PancakeSwapV2', () => { + const dexKey = 'PancakeSwapV2'; + + const sideToContractMethods = new Map([ + [ + SwapSide.SELL, + [ + ContractMethod.simpleSwap, + ContractMethod.multiSwap, + ContractMethod.megaSwap, + ], + ], + [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]], + ]); + + const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [ + [ + { name: 'WETH', sellAmount: '700000000000', buyAmount: '1000' }, + { name: 'USDC', sellAmount: '100000', buyAmount: '4000' }, + ], + ]; + + sideToContractMethods.forEach((contractMethods, side) => + describe(`${side}`, () => { + contractMethods.forEach((contractMethod: ContractMethod) => { + pairs.forEach(pair => { + describe(`${contractMethod}`, () => { + it(`${pair[0].name} -> ${pair[1].name}`, async () => { + await testE2E( + tokens[pair[0].name], + tokens[pair[1].name], + holders[pair[0].name], + side === SwapSide.SELL + ? pair[0].sellAmount + : pair[0].buyAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + it(`${pair[1].name} -> ${pair[0].name}`, async () => { + await testE2E( + tokens[pair[1].name], + tokens[pair[0].name], + holders[pair[1].name], + side === SwapSide.SELL + ? pair[1].sellAmount + : pair[1].buyAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + }); + }); + }); + }), + ); + }); }); From 26f2dbd543f48727ebc60dd35efbb2dbc61df764 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Wed, 9 Aug 2023 22:28:51 +0300 Subject: [PATCH 02/11] BACK-1225: integrate PancakeSwapV3 on Arbitrum --- src/dex/pancakeswap-v3/config.ts | 15 ++++ .../pancakeswap-v3/pancakeswap-v3-e2e.test.ts | 78 +++++++++++++++++++ tests/constants-e2e.ts | 9 ++- 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/dex/pancakeswap-v3/config.ts b/src/dex/pancakeswap-v3/config.ts index b4ca340ff..8fe2533b1 100644 --- a/src/dex/pancakeswap-v3/config.ts +++ b/src/dex/pancakeswap-v3/config.ts @@ -38,6 +38,21 @@ export const PancakeswapV3Config: DexConfigMap = { subgraphURL: 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-bsc', }, + [Network.ARBITRUM]: { + factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865', + deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9', + quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997', + router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14', + supportedFees: PANCAKE_SUPPORTED_FEES, + stateMulticall: '0xaBB58098A7B5172A9b0B38a1925A522dbf0b4FC3', + uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984', + chunksCount: 10, + initRetryFrequency: 30, + initHash: + '0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2', + subgraphURL: + 'https://api.studio.thegraph.com/query/45376/exchange-v3-arbitrum/version/latest', + }, }, }; diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts b/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts index b9e03e693..badb0fdb4 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts @@ -229,4 +229,82 @@ describe('PancakeswapV3 E2E', () => { }), ); }); + + describe('PancakeswapV3 Arbitrum', () => { + const network = Network.ARBITRUM; + const tokens = Tokens[network]; + const holders = Holders[network]; + const provider = new StaticJsonRpcProvider( + generateConfig(network).privateHttpProvider, + network, + ); + + const sideToContractMethods = new Map([ + [ + SwapSide.SELL, + [ + ContractMethod.simpleSwap, + ContractMethod.multiSwap, + ContractMethod.megaSwap, + ], + ], + [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]], + ]); + + const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [ + [ + { + name: NativeTokenSymbols[network], + sellAmount: '2687649500000000', + buyAmount: '5000000', + }, + { + name: 'USDC', + sellAmount: '5000000', + buyAmount: '2687649500000000', + }, + ], + ]; + + sideToContractMethods.forEach((contractMethods, side) => + describe(`${side}`, () => { + contractMethods.forEach((contractMethod: ContractMethod) => { + pairs.forEach(pair => { + describe(`${contractMethod}`, () => { + it(`${pair[0].name} -> ${pair[1].name}`, async () => { + await testE2E( + tokens[pair[0].name], + tokens[pair[1].name], + holders[pair[0].name], + side === SwapSide.SELL + ? pair[0].sellAmount + : pair[0].buyAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + it(`${pair[1].name} -> ${pair[0].name}`, async () => { + await testE2E( + tokens[pair[1].name], + tokens[pair[0].name], + holders[pair[1].name], + side === SwapSide.SELL + ? pair[1].sellAmount + : pair[1].buyAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + }); + }); + }); + }), + ); + }); }); diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index 2fd50078d..f56bb0fbf 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -723,10 +723,14 @@ export const Tokens: { addAllowance: _allowancesFn, }, ETH: { address: ETHER_ADDRESS, decimals: 18 }, - USDC: { + USDCe: { address: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8', decimals: 6, }, + USDC: { + address: '0xaf88d065e77c8cc2239327c5edb3a432268e5831', + decimals: 6, + }, OHM: { address: '0xf0cb2dc0db5e6c66b9a70ac27b06b878da017028', decimals: 9, @@ -1005,7 +1009,8 @@ export const Holders: { ETH: '0xF977814e90dA44bFA03b6295A0616a897441aceC', DAI: '0x07d7f291e731a41d3f0ea4f1ae5b6d920ffb3fe0', WETH: '0xc31e54c7a869b9fcbecc14363cf510d1c41fa443', - USDC: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6', + USDCe: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6', + USDC: '0xa843392198862f98d17e3aa1421b08f2c2020cff', OHM: '0xebce5f29ff5ca9aa330ebdf7ec6b5f474bff271e', USDT: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6', POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591', From 701675ed37a7b0423060b78e48f3960fd991adad Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Wed, 9 Aug 2023 22:30:53 +0300 Subject: [PATCH 03/11] 2.28.4-pancake-swap-v3-arbitrum --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9ffe6e16..47e3d9a6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "2.28.3", + "version": "2.28.4-pancake-swap-v3-arbitrum", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From a225b24304dc10b657eca6ee71f4426bd95174c2 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 11:16:02 +0300 Subject: [PATCH 04/11] addd arbitrun adapters in config and updated state multicall address --- src/dex/pancakeswap-v3/config.ts | 6 +++++- src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts | 2 +- src/dex/pancakeswap-v3/pancakeswap-v3.ts | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/dex/pancakeswap-v3/config.ts b/src/dex/pancakeswap-v3/config.ts index 8fe2533b1..43636ee06 100644 --- a/src/dex/pancakeswap-v3/config.ts +++ b/src/dex/pancakeswap-v3/config.ts @@ -44,7 +44,7 @@ export const PancakeswapV3Config: DexConfigMap = { quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997', router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14', supportedFees: PANCAKE_SUPPORTED_FEES, - stateMulticall: '0xaBB58098A7B5172A9b0B38a1925A522dbf0b4FC3', + stateMulticall: '0xF8498aCeD3aFa417653415B8e32BAE9d764FBFf5', uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984', chunksCount: 10, initRetryFrequency: 30, @@ -65,4 +65,8 @@ export const Adapters: Record = { [SwapSide.SELL]: [{ name: 'BscAdapter02', index: 4 }], [SwapSide.BUY]: [{ name: 'BscBuyAdapter', index: 5 }], }, + [Network.ARBITRUM]: { + [SwapSide.SELL]: [{ name: 'ArbitrumAdapter01', index: 3 }], + [SwapSide.BUY]: [{ name: 'ArbitrumBuyAdapter', index: 2 }], + }, }; diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts b/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts index badb0fdb4..9be62cd7e 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts @@ -261,7 +261,7 @@ describe('PancakeswapV3 E2E', () => { { name: 'USDC', sellAmount: '5000000', - buyAmount: '2687649500000000', + buyAmount: '1000000000000000', }, ], ]; diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3.ts b/src/dex/pancakeswap-v3/pancakeswap-v3.ts index f399fd172..41d2de86e 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3.ts @@ -623,7 +623,7 @@ export class PancakeswapV3 balanceDestToken, ); - if (!unitResult || !pricesResult) { + if (!pricesResult) { this.logger.debug('Prices or unit is not calculated'); return null; } @@ -644,7 +644,7 @@ export class PancakeswapV3 }), ]; return { - unit: unitResult.outputs[0], + unit: unitResult?.outputs[0] || 0n, prices, data: { path: [ From 797785ab92c8710e211b098ab0d0140e885b4730 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 11:17:44 +0300 Subject: [PATCH 05/11] 2.28.4-pancake-swap-v3-arbitrum.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47e3d9a6a..0414daf2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "2.28.4-pancake-swap-v3-arbitrum", + "version": "2.28.4-pancake-swap-v3-arbitrum.2", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 4e4733c06dd28dc8dbd128c979ed3ba654cc6b0e Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 13:53:32 +0300 Subject: [PATCH 06/11] 2.28.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0414daf2a..a84134284 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "2.28.4-pancake-swap-v3-arbitrum.2", + "version": "2.28.4", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From df4fb51dda2483ee4f01867a79fe36f6c921069c Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 16:11:31 +0300 Subject: [PATCH 07/11] update tests --- src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts index a430fa1cc..5bc5e36a6 100644 --- a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts +++ b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts @@ -377,8 +377,8 @@ describe('UniswapV2 E2E Arbitrum', () => { const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [ [ - { name: 'WETH', sellAmount: '700000000000', buyAmount: '1000' }, - { name: 'USDC', sellAmount: '100000', buyAmount: '4000' }, + { name: 'ETH', sellAmount: '7000000000000000', buyAmount: '7000000000000000000' }, + { name: 'ARB', sellAmount: '7000000000000000000', buyAmount: '7000000000000000' }, ], ]; From dad39bfd5f7f12ac40485570a680e948c745498d Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 16:27:47 +0300 Subject: [PATCH 08/11] update tests --- src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts index 5bc5e36a6..c66242fce 100644 --- a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts +++ b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts @@ -377,8 +377,8 @@ describe('UniswapV2 E2E Arbitrum', () => { const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [ [ - { name: 'ETH', sellAmount: '7000000000000000', buyAmount: '7000000000000000000' }, - { name: 'ARB', sellAmount: '7000000000000000000', buyAmount: '7000000000000000' }, + { name: 'ETH', sellAmount: '505000000000000', buyAmount: '940617' }, + { name: 'USDC', sellAmount: '940617', buyAmount: '505000000000000' }, ], ]; From 26dc1d4c5a1d82737053ba5aca579b1a09b11a50 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 16:29:11 +0300 Subject: [PATCH 09/11] 2.28.5-pancake-swap-v2-arbitrum --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a84134284..37f8144e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "2.28.4", + "version": "2.28.5-pancake-swap-v2-arbitrum", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 7a0b7b60e4baafb310899e5de2d2d851bb76fd57 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 16:35:02 +0300 Subject: [PATCH 10/11] update tests --- src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts index c66242fce..923ccad4e 100644 --- a/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts +++ b/src/dex/uniswap-v2/uniswap-v2-e2e-arbitrum.test.ts @@ -380,6 +380,10 @@ describe('UniswapV2 E2E Arbitrum', () => { { name: 'ETH', sellAmount: '505000000000000', buyAmount: '940617' }, { name: 'USDC', sellAmount: '940617', buyAmount: '505000000000000' }, ], + [ + { name: 'ETH', sellAmount: '631955000000000', buyAmount: '1000000000000000000' }, + { name: 'ARB', sellAmount: '1000000000000000000', buyAmount: '631955000000000' }, + ], ]; sideToContractMethods.forEach((contractMethods, side) => From 1f5b49a7d5ec14cdbb10352972e9c2966ad851d9 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 10 Aug 2023 17:22:08 +0300 Subject: [PATCH 11/11] 2.28.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 37f8144e9..e75a76a3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "2.28.5-pancake-swap-v2-arbitrum", + "version": "2.28.5", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib",