From 01735dcc5b1b8ec6dbc13e2703ca69bd0c79b674 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 24 Dec 2024 15:54:49 +0300 Subject: [PATCH 1/6] fix destTokenPos for root vertical branch in ex02 encoding --- src/executor/Executor02BytecodeBuilder.ts | 41 ++++++++++++++----- .../executor02-bytecode-builder-e2e.test.ts | 30 ++++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/executor/Executor02BytecodeBuilder.ts b/src/executor/Executor02BytecodeBuilder.ts index 90cf76be8..f7096df67 100644 --- a/src/executor/Executor02BytecodeBuilder.ts +++ b/src/executor/Executor02BytecodeBuilder.ts @@ -28,6 +28,7 @@ import { ZEROS_4_BYTES, DEFAULT_RETURN_AMOUNT_POS, } from './constants'; +import * as constants from 'constants'; const { utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack }, @@ -475,6 +476,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder< swap: OptimalSwap, swapCallData: string, flag: Flag, + isRoot = false, ) { const data = this.packVerticalBranchingData(swapCallData); @@ -486,16 +488,34 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder< let destTokenPos: number; if (isEthDest) { - anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative( - priceRoute, - swap, - exchangeParams, - ); - anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative( - priceRoute, - swap, - exchangeParams, - ); + if (!isRoot) { + anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative( + priceRoute, + swap, + exchangeParams, + ); + anyDexOnSwapDoesntNeedWrapNative = + this.anyDexOnSwapDoesntNeedWrapNative( + priceRoute, + swap, + exchangeParams, + ); + } else { + anyDexOnSwapNeedsWrapNative = priceRoute.bestRoute.some(route => + this.anyDexOnSwapNeedsWrapNative( + priceRoute, + route.swaps[route.swaps.length - 1], + exchangeParams, + ), + ); + anyDexOnSwapDoesntNeedWrapNative = priceRoute.bestRoute.some(route => + this.anyDexOnSwapDoesntNeedWrapNative( + priceRoute, + route.swaps[route.swaps.length - 1], + exchangeParams, + ), + ); + } } if ( @@ -1313,6 +1333,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder< needWrapEth ? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 0 : Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP, // 8 + true, // isRoot branch ); } diff --git a/src/executor/executor02-bytecode-builder-e2e.test.ts b/src/executor/executor02-bytecode-builder-e2e.test.ts index 514fc60e2..04b47edf7 100644 --- a/src/executor/executor02-bytecode-builder-e2e.test.ts +++ b/src/executor/executor02-bytecode-builder-e2e.test.ts @@ -1497,6 +1497,36 @@ describe('Executor02ByteCodeBuilder e2e tests', () => { ); }); }); + + describe('USDCe -> MATIC', () => { + const dexKeys = ['CurveV2', 'UniswapV3', 'SushiSwapV3', 'SwaapV2']; + + const tokenASymbol: string = 'USDCe'; + const tokenBSymbol: string = 'MATIC'; + const tokenAAmount: string = '1978798814'; + + const side = SwapSide.SELL; + + it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[tokenBSymbol], + holders[tokenASymbol], + tokenAAmount, + side, + dexKeys, + contractMethod, + network, + provider, + undefined, + undefined, + undefined, + 100, + 2000, + false, + ); + }); + }); }); }); From 3325dedd3a89f5ae1421353707dc96e33831855d Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 24 Dec 2024 15:55:38 +0300 Subject: [PATCH 2/6] remove imports --- src/executor/Executor02BytecodeBuilder.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/executor/Executor02BytecodeBuilder.ts b/src/executor/Executor02BytecodeBuilder.ts index f7096df67..120819c4e 100644 --- a/src/executor/Executor02BytecodeBuilder.ts +++ b/src/executor/Executor02BytecodeBuilder.ts @@ -7,7 +7,6 @@ import { } from '@paraswap/core'; import { DexExchangeBuildParam, - DexExchangeParam, DexExchangeParamWithBooleanNeedWrapNative, } from '../types'; import { Executors, Flag, SpecialDex } from './types'; @@ -28,7 +27,6 @@ import { ZEROS_4_BYTES, DEFAULT_RETURN_AMOUNT_POS, } from './constants'; -import * as constants from 'constants'; const { utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack }, From 23d1176ea20b0d19b48843ebe89fa12a6685fd8d Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 24 Dec 2024 15:57:17 +0300 Subject: [PATCH 3/6] 4.0.10-destTokenPos-fix-ex02.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f38f3ecd0..ee0f353e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "4.0.9", + "version": "4.0.10-destTokenPos-fix-ex02.0", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 5aa8d4d72ee832a22e9929dffcb4450df34c2b58 Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Wed, 25 Dec 2024 13:39:55 +0200 Subject: [PATCH 4/6] fix: encode `isStable` for dystopian forks params --- src/dex/camelot/camelot.ts | 11 ++++++++++- src/dex/solidly/solidly.ts | 11 ++++++++++- src/dex/solidly/types.ts | 7 +++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/dex/camelot/camelot.ts b/src/dex/camelot/camelot.ts index 9ad942f86..8f6b80db3 100644 --- a/src/dex/camelot/camelot.ts +++ b/src/dex/camelot/camelot.ts @@ -646,6 +646,7 @@ export class Camelot isFeeTokenInRoute: Object.values(transferFees).some(f => f !== 0), pools: [ { + stable: pairParam.stable, address: pairParam.exchange, fee: parseInt(pairParam.fee), direction: pairParam.direction, @@ -843,9 +844,17 @@ export class Camelot if (side === SwapSide.BUY) throw new Error('Buy not supported'); let exchangeDataTypes = ['bytes4', 'bytes32']; + const isStable = data.pools.some(pool => !!pool.stable); + const isStablePoolAndPoolCount = isStable + ? BigNumber.from(1) + .shl(255) + .or(BigNumber.from(data.pools.length)) + .toHexString() + : hexZeroPad(hexlify(data.pools.length), 32); + let exchangeDataToPack = [ hexZeroPad(hexlify(0), 4), - hexZeroPad(hexlify(data.pools.length), 32), + isStablePoolAndPoolCount, ]; const pools = encodePools(data.pools, this.feeFactor); diff --git a/src/dex/solidly/solidly.ts b/src/dex/solidly/solidly.ts index 6bd7fd853..369b2b21d 100644 --- a/src/dex/solidly/solidly.ts +++ b/src/dex/solidly/solidly.ts @@ -409,6 +409,7 @@ export class Solidly extends UniswapV2 { isFeeTokenInRoute: Object.values(transferFees).some(f => f !== 0), pools: [ { + stable: pairParam.stable, address: pairParam.exchange, fee: parseInt(pairParam.fee), direction: pairParam.direction, @@ -657,9 +658,17 @@ export class Solidly extends UniswapV2 { if (side === SwapSide.BUY) throw new Error(`Buy not supported`); let exchangeDataTypes = ['bytes4', 'bytes32']; + const isStable = data.pools.some(pool => !!pool.stable); + const isStablePoolAndPoolCount = isStable + ? BigNumber.from(1) + .shl(255) + .or(BigNumber.from(data.pools.length)) + .toHexString() + : hexZeroPad(hexlify(data.pools.length), 32); + let exchangeDataToPack = [ hexZeroPad(hexlify(0), 4), - hexZeroPad(hexlify(data.pools.length), 32), + isStablePoolAndPoolCount, ]; const pools = encodePools(data.pools, this.feeFactor); diff --git a/src/dex/solidly/types.ts b/src/dex/solidly/types.ts index 4db1c4b32..b0895dd5c 100644 --- a/src/dex/solidly/types.ts +++ b/src/dex/solidly/types.ts @@ -19,9 +19,12 @@ export interface SolidlyPoolOrderedParams extends UniswapV2PoolOrderedParams { stable: boolean; } -export type SolidlyData = UniswapV2Data & { isFeeTokenInRoute: boolean }; +export type SolidlyPool = UniswapPool & { stable: boolean }; -export type SolidlyPool = UniswapPool; +export type SolidlyData = { + isFeeTokenInRoute: boolean; + pools: SolidlyPool[]; +} & UniswapV2Data; export interface DexParams extends Omit { feeCode: number; From b7fb684b2b43ebcfcd331fc6c5f564dc7f48a5b7 Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Wed, 25 Dec 2024 13:43:58 +0200 Subject: [PATCH 5/6] 4.0.10-destTokenPos-fix-ex02.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee0f353e8..77fea7707 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "4.0.10-destTokenPos-fix-ex02.0", + "version": "4.0.10-destTokenPos-fix-ex02.1", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 35b63afd33bd7df4f813f8b3f8b1c488a5f51558 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 26 Dec 2024 11:31:00 +0300 Subject: [PATCH 6/6] 4.0.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77fea7707..5ac38a9e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "4.0.10-destTokenPos-fix-ex02.1", + "version": "4.0.10", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib",