Skip to content

Commit

Permalink
test(encoder): add 1inch swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed May 20, 2024
1 parent 029c915 commit f630b33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
23 changes: 21 additions & 2 deletions test/ExecutorEncoder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand All @@ -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);

Expand Down

0 comments on commit f630b33

Please sign in to comment.