Skip to content

Commit

Permalink
Paraswap v6.2 migration (#596)
Browse files Browse the repository at this point in the history
* feat: add v6 selectors

* test: new paraswap v6.2 selector offsets
  • Loading branch information
KanievskyiDanylo authored Oct 16, 2024
1 parent 521b4d9 commit 0d58abe
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 6 deletions.
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 @@ -40,15 +40,29 @@ export function augustusFromAmountOffsetFromCalldata(calldata: string): number {
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

0 comments on commit 0d58abe

Please sign in to comment.