From f630b339f4f715edc2e67d2c33fabe442e77af91 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Mon, 20 May 2024 09:25:45 +0200 Subject: [PATCH] test(encoder): add 1inch swap --- hardhat.config.ts | 2 +- test/ExecutorEncoder.spec.ts | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index eb7cac7..4ab07ed 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -18,7 +18,7 @@ const config: HardhatUserConfig = { chainId: 1, forking: { url: rpcUrl, - blockNumber: 18_843_810, + blockNumber: 19_909_475, }, allowBlocksWithSameTimestamp: true, accounts: { count: 2 }, diff --git a/test/ExecutorEncoder.spec.ts b/test/ExecutorEncoder.spec.ts index ac380c6..f768067 100644 --- a/test/ExecutorEncoder.spec.ts +++ b/test/ExecutorEncoder.spec.ts @@ -20,6 +20,7 @@ export const aaveV2PoolAddress = "0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9"; export const aaveV3PoolAddress = "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"; export const balancerVaultAddress = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"; export const makerVaultAddress = "0x60744434d6339a6B27d73d9Eda62b6F66a0a04FA"; +export const oneInchAddress = "0x111111125421ca6dc452d289314280a0f8842a65"; // V2 @@ -201,8 +202,8 @@ describe("ExecutorEncoder", () => { .exec(); }); - it("should swap USDC for WETH", async () => { - const amountIn = 1000_000000; + it("should swap USDC for WETH via UniswapV3", async () => { + const amountIn = 1000_000000n; await deal(usdc, encoder.address, amountIn); @@ -220,6 +221,24 @@ describe("ExecutorEncoder", () => { expect(wethBalance.toWadFloat()).to.be.greaterThan(0.025); }); + it.only("should swap sDAI for ETH via 1inch", async () => { + const amountIn = 1000_000000n; + + await deal(usdc, encoder.address, amountIn); + + await encoder + .erc20Approve(usdc, oneInchAddress, amountIn) + .pushCall( + oneInchAddress, + 0n, + `0x07ed2379000000000000000000000000e37e799d5077682fa0a244d46e5649f71457bd09000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000e37e799d5077682fa0a244d46e5649f71457bd09${AbiCoder.defaultAbiCoder().encode(["address"], [encoder.address]).substring(2)}000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000046d2bdd1d47d45800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000017a00000000000000000000000000000000000000015c00014200012c0000f05132831bf48183b999fde45294b14b55199072f0801ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb48004475d39ecb000000000000000000000000e37e799d5077682fa0a244d46e5649f71457bd090000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000276a4000000000000000000000000000000000000000000000000046d2bdd1d47d45800000000000000000000000000000000000000000000000000000000665191334101c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200042e1a7d4d0000000000000000000000000000000000000000000000000000000000000000c061111111125421ca6dc452d289314280a0f8842a6500206b4be0b9111111125421ca6dc452d289314280a0f8842a65000000000000e70d93f7`, + ) + .exec(); + + const ethBalance = await ethers.provider.getBalance(encoder.address); + expect(ethBalance.toWadFloat()).to.be.greaterThan(0.32); + }); + it("should not trigger fallback via Balancer from unknown account", async () => { const balancerVault = BalancerVault__factory.connect(balancerVaultAddress, hacker);