Skip to content

Commit

Permalink
fix destTokenPos for root vertical branch in ex02 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 24, 2024
1 parent 5dca844 commit 01735dc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/executor/Executor02BytecodeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -475,6 +476,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
swap: OptimalSwap,
swapCallData: string,
flag: Flag,
isRoot = false,
) {
const data = this.packVerticalBranchingData(swapCallData);

Expand All @@ -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 (
Expand Down Expand Up @@ -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
);
}

Expand Down
30 changes: 30 additions & 0 deletions src/executor/executor02-bytecode-builder-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
});
});
});

Expand Down

0 comments on commit 01735dc

Please sign in to comment.