diff --git a/packages/contract-helpers/src/commons/utils.test.ts b/packages/contract-helpers/src/commons/utils.test.ts index 2e2a0205..57cddfec 100644 --- a/packages/contract-helpers/src/commons/utils.test.ts +++ b/packages/contract-helpers/src/commons/utils.test.ts @@ -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`, diff --git a/packages/contract-helpers/src/commons/utils.ts b/packages/contract-helpers/src/commons/utils.ts index 04c16bba..7355195d 100644 --- a/packages/contract-helpers/src/commons/utils.ts +++ b/packages/contract-helpers/src/commons/utils.ts @@ -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'); } diff --git a/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/index.ts b/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/index.ts index 60e4d120..7e792f48 100644 --- a/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/index.ts +++ b/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/index.ts @@ -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'); diff --git a/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/paraswapLiquiditySwapAdapter.test.ts b/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/paraswapLiquiditySwapAdapter.test.ts index 862636a2..fb61e2d3 100644 --- a/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/paraswapLiquiditySwapAdapter.test.ts +++ b/packages/contract-helpers/src/paraswap-liquiditySwapAdapter-contract/paraswapLiquiditySwapAdapter.test.ts @@ -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(