Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paraswap v6.2 migration #596

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/contract-helpers/src/commons/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ describe('Utils', () => {
const offset = augustusToAmountOffsetFromCalldata('0x87a63926');
expect(offset).toEqual(68);
});

it('Expects 132 when Augustus V6 swapExactAmountOut', () => {
const offset = augustusToAmountOffsetFromCalldata('0x7f457675');
expect(offset).toEqual(132);
});

it('Expects 36 when Augustus V6 swapExactAmountOutOnBalancerV2', () => {
const offset = augustusToAmountOffsetFromCalldata('0xd6ed22e6');
expect(offset).toEqual(36);
});

it('Expects 196 when Augustus V6 swapExactAmountOutOnUniswapV2', () => {
const offset = augustusToAmountOffsetFromCalldata('0xa76f4eb6');
expect(offset).toEqual(196);
});

it('Expects 196 when Augustus V6 swapExactAmountOutOnUniswapV3', () => {
const offset = augustusToAmountOffsetFromCalldata('0x5e94e28d');
expect(offset).toEqual(196);
});

it('Expects 100 when Augustus V6 swapExactAmountInOutOnMakerPSM', () => {
const offset = augustusToAmountOffsetFromCalldata('0x987e7d8e');
expect(offset).toEqual(100);
});

it('Expects Error', () => {
expect(() => augustusToAmountOffsetFromCalldata('asdf')).toThrowError(
`Unrecognized function selector for Augustus`,
Expand Down
12 changes: 11 additions & 1 deletion packages/contract-helpers/src/commons/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,18 @@ export const augustusToAmountOffsetFromCalldata = (
case '0xb66bcbac': // Augustus V5 buy (old)
case '0x35326910': // Augustus V5 buy
return 164; // 4 + 5 * 32
case '0x87a63926': // directUniV3Buy
case '0x87a63926': // Augustus V5 directUniV3Buy
return 68; // 4 + 2 * 32
case '0x7f457675': // Augustus V6 swapExactAmountOut
return 132; // 4 + 4 * 32
case '0xd6ed22e6': // Augustus V6 swapExactAmountOutOnBalancerV2
return 36; // 4 + 1 * 32
case '0xa76f4eb6': // Augustus V6 swapExactAmountOutOnUniswapV2
return 196; // 4 + 6 * 32
case '0x5e94e28d': // Augustus V6 swapExactAmountOutOnUniswapV3
return 196; // 4 + 6 * 32
case '0x987e7d8e': // Augustus V6 swapExactAmountInOutOnMakerPSM
return 100; // 4 + 3 * 32
default:
throw new Error('Unrecognized function selector for Augustus');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { IParaSwapLiquiditySwapAdapter } from './typechain/IParaSwapLiquiditySwapAdapter';
import { IParaSwapLiquiditySwapAdapter__factory } from './typechain/IParaSwapLiquiditySwapAdapter__factory';

export function augustusFromAmountOffsetFromCalldata(calldata: string): number {

Check warning on line 19 in packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/index.ts

View workflow job for this annotation

GitHub Actions / build

Function 'augustusFromAmountOffsetFromCalldata' has a complexity of 24. Maximum allowed is 20
switch (calldata.slice(0, 10)) {
case '0xda8567c8': // Augustus V3 multiSwap
return 100; // 4 + 3 * 32
Expand All @@ -40,15 +40,29 @@
return 68; // 4 + 2 * 32
case '0x46c67b6d': // Augustus V5 megaSwap
return 68; // 4 + 2 * 32
case '0xb22f4db8': // directBalancerV2GivenInSwap
case '0xb22f4db8': // Augustus V5 directBalancerV2GivenInSwap
return 68; // 4 + 2 * 32
case '0x19fc5be0': // directBalancerV2GivenOutSwap
case '0x19fc5be0': // Augustus V5 directBalancerV2GivenOutSwap
return 68; // 4 + 2 * 32
case '0x3865bde6': // directCurveV1Swap
case '0x3865bde6': // Augustus V5 directCurveV1Swap
return 68; // 4 + 2 * 32
case '0x58f15100': // directCurveV2Swap
case '0x58f15100': // Augustus V5 directCurveV2Swap
return 68; // 4 + 2 * 32
case '0xa6866da9': // directUniV3Swap
case '0xa6866da9': // Augustus V5 directUniV3Swap
return 68; // 4 + 2 * 32
case '0xe3ead59e': // Augustus V6 swapExactAmountIn
return 100; // 4 + 3 * 32
case '0xd85ca173': // Augustus V6 swapExactAmountInOnBalancerV2
return 4; // 4 + 0 * 32
case '0x1a01c532': // Augustus V6 swapExactAmountInOnCurveV1
return 132; // 4 + 4 * 32
case '0xe37ed256': // Augustus V6 swapExactAmountInOnCurveV2
return 196; // 4 + 6 * 32
case '0xe8bb3b6c': // Augustus V6 swapExactAmountInOnUniswapV2
return 164; // 4 + 4 * 32
case '0x876a02f6': // Augustus V6 swapExactAmountInOnUniswapV3
return 164; // 4 + 4 * 32
case '0x987e7d8e': // Augustus V6 swapExactAmountInOutOnMakerPSM
return 68; // 4 + 2 * 32
default:
throw new Error('Unrecognized function selector for Augustus');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,56 @@ describe('LiquiditySwapAdapterService', () => {

expect(offset).toEqual(68);
});

it('Expects 100 when Augustus V6 swapExactAmountIn', () => {
const callData = '0xe3ead59e0000000000otherCallData000000000';
const offset = augustusFromAmountOffsetFromCalldata(callData);

expect(offset).toEqual(100);
});

it('Expects 4 when Augustus V6 swapExactAmountInOnBalancerV2', () => {
const callData = '0xd85ca1730000000000otherCallData000000000';
const offset = augustusFromAmountOffsetFromCalldata(callData);

expect(offset).toEqual(4);
});

it('Expects 132 when Augustus V6 swapExactAmountInOnCurveV1', () => {
const callData = '0x1a01c5320000000000otherCallData000000000';
const offset = augustusFromAmountOffsetFromCalldata(callData);

expect(offset).toEqual(132);
});

it('Expects 196 when Augustus V6 swapExactAmountInOnCurveV2', () => {
const callData = '0xe37ed2560000000000otherCallData000000000';
const offset = augustusFromAmountOffsetFromCalldata(callData);

expect(offset).toEqual(196);
});

it('Expects 164 when Augustus V6 swapExactAmountInOnUniswapV2', () => {
const callData = '0xe8bb3b6c0000000000otherCallData000000000';
const offset = augustusFromAmountOffsetFromCalldata(callData);

expect(offset).toEqual(164);
});

it('Expects 164 when Augustus V6 swapExactAmountInOnUniswapV3', () => {
const callData = '0x876a02f60000000000otherCallData000000000';
const offset = augustusFromAmountOffsetFromCalldata(callData);

expect(offset).toEqual(164);
});

it('Expects 68 when Augustus V6 swapExactAmountInOutOnMakerPSM', () => {
const callData = '0x987e7d8e0000000000otherCallData000000000';
const offset = augustusFromAmountOffsetFromCalldata(callData);

expect(offset).toEqual(68);
});

it('Expects to fail if non recognizable Augustus function selector', () => {
const callData = 'bad calldata';
expect(() => augustusFromAmountOffsetFromCalldata(callData)).toThrowError(
Expand Down
Loading