From a7b240d40516307dddbc9518bf95cc1609826f5d Mon Sep 17 00:00:00 2001 From: Mikhail Melnik Date: Tue, 24 Dec 2024 23:44:39 +0400 Subject: [PATCH 1/2] support fee flow updates --- package.json | 2 +- test/Settlement.js | 72 +++++++++++++++++++++---------------- test/helpers/fixtures.js | 4 +-- test/helpers/fusionUtils.js | 6 ++-- yarn.lock | 8 ++--- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index f4cce1b..cf1476a 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "dependencies": { "@1inch/delegating": "1.1.0", - "@1inch/limit-order-protocol-contract": "4.2.1", + "@1inch/limit-order-protocol-contract": "4.2.2", "@1inch/solidity-utils": "6.2.0", "@1inch/st1inch": "2.2.0", "@openzeppelin/contracts": "5.1.0" diff --git a/test/Settlement.js b/test/Settlement.js index c95c06c..27e7ff2 100644 --- a/test/Settlement.js +++ b/test/Settlement.js @@ -164,7 +164,7 @@ describe('Settlement', function () { const setupData = { ...dataFormFixture, auction }; const { contracts: { dai, weth, resolver }, - accounts: { owner, alice, bob }, + accounts: { owner, alice, bob, charlie }, } = setupData; const fillOrderToData1 = await buildCalldataForOrder({ @@ -180,7 +180,8 @@ describe('Settlement', function () { setupData, threshold: ether('101'), isInnermostOrder: true, - integrator: bob.address, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, integratorFee: 100, }); @@ -197,13 +198,14 @@ describe('Settlement', function () { setupData, threshold: ether('0.11'), additionalDataForSettlement: fillOrderToData1, - integrator: bob.address, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, integratorFee: 100, }); const txn = await resolver.settleOrders(fillOrderToData0); - await expect(txn).to.changeTokenBalances(dai, [owner, alice, bob], [ether('-100.1'), ether('100'), ether('0.1')]); - await expect(txn).to.changeTokenBalances(weth, [owner, alice, bob, resolver], [ether('0.1'), ether('-0.11'), ether('0.0001'), ether('0.0099')]); + await expect(txn).to.changeTokenBalances(dai, [owner, alice, bob, charlie], [ether('-100.1'), ether('100'), ether('0.05'), ether('0.05')]); + await expect(txn).to.changeTokenBalances(weth, [owner, alice, bob, charlie, resolver], [ether('0.1'), ether('-0.11'), ether('0.00005'), ether('0.00005'), ether('0.0099')]); }); it('unidirectional recursive swap', async function () { @@ -276,7 +278,7 @@ describe('Settlement', function () { const setupData = { ...dataFormFixture, auction }; const { contracts: { dai, weth, resolver }, - accounts: { owner, alice, bob }, + accounts: { owner, alice, bob, charlie }, } = setupData; const INTEGRATOR_FEE = 115n; @@ -294,8 +296,9 @@ describe('Settlement', function () { threshold: ether('101'), isInnermostOrder: true, resolverFee: BACK_ORDER_FEE, - integrator: bob.address, integratorFee: INTEGRATOR_FEE, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); const fillOrderToData0 = await buildCalldataForOrder({ @@ -312,13 +315,14 @@ describe('Settlement', function () { threshold: ether('0.11'), additionalDataForSettlement: fillOrderToData1, resolverFee: ORDER_FEE, - integrator: bob.address, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); const tx = await resolver.settleOrders(fillOrderToData0); - await expect(tx).to.changeTokenBalances(dai, [owner, alice, bob], [ether('-100.24'), ether('100'), ether('0.24')]); - await expect(tx).to.changeTokenBalances(weth, [owner, alice, bob, resolver], [ether('0.1'), ether('-0.11'), ether('0.0001'), ether('0.0099')]); + await expect(tx).to.changeTokenBalances(dai, [owner, alice, bob, charlie], [ether('-100.24'), ether('100'), ether('0.115') / 2n, ether('0.125') + ether('0.115') / 2n]); + await expect(tx).to.changeTokenBalances(weth, [owner, alice, bob, charlie, resolver], [ether('0.1'), ether('-0.11'), 0, ether('0.0001'), ether('0.0099')]); }); it('opposite direction recursive swap with resolverFee and integratorFee and custom receiver', async function () { @@ -327,10 +331,10 @@ describe('Settlement', function () { const setupData = { ...dataFormFixture, auction }; const { contracts: { dai, weth, resolver }, - accounts: { owner, alice, bob }, + accounts: { owner, alice, bob, charlie }, } = setupData; - const [,,, aliceReciever, ownerReciever] = await ethers.getSigners(); + const [,,,, aliceReciever, ownerReciever] = await ethers.getSigners(); const INTEGRATOR_FEE = 115n; const fillOrderToData1 = await buildCalldataForOrder({ @@ -347,9 +351,10 @@ describe('Settlement', function () { setupData, threshold: ether('101'), isInnermostOrder: true, - resolverFee: BACK_ORDER_FEE, - integrator: bob.address, integratorFee: INTEGRATOR_FEE, + resolverFee: BACK_ORDER_FEE, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); const fillOrderToData0 = await buildCalldataForOrder({ @@ -367,13 +372,14 @@ describe('Settlement', function () { threshold: ether('0.11'), additionalDataForSettlement: fillOrderToData1, resolverFee: ORDER_FEE, - integrator: bob.address, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); const tx = await resolver.settleOrders(fillOrderToData0); - await expect(tx).to.changeTokenBalances(dai, [owner, aliceReciever, bob], [ether('-100.24'), ether('100'), ether('0.24')]); - await expect(tx).to.changeTokenBalances(weth, [alice, ownerReciever, bob, resolver], [ether('-0.11'), ether('0.1'), ether('0.0001'), ether('0.0099')]); + await expect(tx).to.changeTokenBalances(dai, [owner, aliceReciever, bob, charlie], [ether('-100.24'), ether('100'), ether('0.115') / 2n, ether('0.125') + ether('0.115') / 2n]); + await expect(tx).to.changeTokenBalances(weth, [alice, ownerReciever, bob, charlie, resolver], [ether('-0.11'), ether('0.1'), 0, ether('0.0001'), ether('0.0099')]); }); it('opposite direction recursive swap with resolverFee and integratorFee and custom receiver and weth unwrapping', async function () { @@ -382,10 +388,10 @@ describe('Settlement', function () { const setupData = { ...dataFormFixture, auction }; const { contracts: { dai, weth, resolver }, - accounts: { owner, alice, bob }, + accounts: { owner, alice, bob, charlie }, } = setupData; - const [,,, aliceReciever, ownerReciever] = await ethers.getSigners(); + const [,,,, aliceReciever, ownerReciever] = await ethers.getSigners(); const INTEGRATOR_FEE = 115n; const fillOrderToData1 = await buildCalldataForOrder({ @@ -403,7 +409,8 @@ describe('Settlement', function () { threshold: ether('101'), isInnermostOrder: true, resolverFee: BACK_ORDER_FEE, - integrator: bob.address, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); const fillOrderToData0 = await buildCalldataForOrder({ @@ -420,16 +427,17 @@ describe('Settlement', function () { setupData, threshold: ether('0.11'), additionalDataForSettlement: fillOrderToData1, - resolverFee: ORDER_FEE, - integrator: bob.address, integratorFee: INTEGRATOR_FEE, + resolverFee: ORDER_FEE, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); const tx = await resolver.settleOrders(fillOrderToData0); - await expect(tx).to.changeTokenBalances(dai, [owner, aliceReciever, bob], [ether('-100.125'), ether('100'), ether('0.125')]); - await expect(tx).to.changeTokenBalances(weth, [alice, ownerReciever, bob, resolver], [ether('-0.11'), 0, 0, ether('0.009785')]); - await expect(tx).to.changeEtherBalances([alice, ownerReciever, bob], [0, ether('0.1'), ether('0.000215')]); + await expect(tx).to.changeTokenBalances(dai, [owner, aliceReciever, bob, charlie], [ether('-100.125'), ether('100'), 0, ether('0.125')]); + await expect(tx).to.changeTokenBalances(weth, [alice, ownerReciever, bob, charlie, resolver], [ether('-0.11'), 0, 0, 0, ether('0.009785')]); + await expect(tx).to.changeEtherBalances([alice, ownerReciever, bob, charlie], [0, ether('0.1'), ether('0.000115') / 2n, ether('0.0001') + ether('0.000115') / 2n]); }); it('triple recursive swap', async function () { @@ -693,7 +701,7 @@ describe('Settlement', function () { const setupData = { ...dataFormFixture, auction }; const { contracts: { dai, weth, resolver }, - accounts: { owner, alice, bob }, + accounts: { owner, alice, bob, charlie }, others: { abiCoder }, } = setupData; @@ -730,14 +738,15 @@ describe('Settlement', function () { isInnermostOrder: true, fillingAmount: ether('10') * partialModifier / points, resolverFee: ORDER_FEE, - integrator: bob.address, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); await weth.approve(resolver, ether('0.01')); const txn = await resolver.settleOrders(fillOrderToData0); await expect(txn).to.changeTokenBalances(dai, [resolver, alice], [ether('10') * partialModifier / points, ether('-10') * partialModifier / points]); - await expect(txn).to.changeTokenBalances(weth, [owner, alice], [ether('-0.01') * partialModifier / points * (ORDER_FEE + FEE_BASE) / FEE_BASE, ether('0.01') * partialModifier / points]); + await expect(txn).to.changeTokenBalances(weth, [owner, alice, bob, charlie], [ether('-0.01') * partialModifier / points * (ORDER_FEE + FEE_BASE) / FEE_BASE, ether('0.01') * partialModifier / points, 0, ether('0.01') * partialModifier / points * ORDER_FEE / FEE_BASE]); }); it('should not pay resolver fee when whitelisted address and it has accessToken', async function () { @@ -814,7 +823,7 @@ describe('Settlement', function () { const setupData = { ...dataFormFixture, auction }; const { contracts: { dai, weth, resolver }, - accounts: { alice, bob }, + accounts: { alice, bob, charlie }, } = setupData; weth.transfer(resolver, ether('0.1001')); @@ -833,12 +842,13 @@ describe('Settlement', function () { threshold: ether('0.11'), isInnermostOrder: true, resolverFee: ORDER_FEE, - integrator: bob.address, + integratorFeeRecipient: bob.address, + protocolFeeRecipient: charlie.address, }); const txn = await resolver.settleOrders(fillOrderToData); await expect(txn).to.changeTokenBalances(dai, [alice, resolver], [ether('-100'), ether('100')]); - await expect(txn).to.changeTokenBalances(weth, [alice, resolver, bob], [ether('0.1'), ether('-0.1001'), ether('0.0001')]); + await expect(txn).to.changeTokenBalances(weth, [alice, resolver, bob, charlie], [ether('0.1'), ether('-0.1001'), 0, ether('0.0001')]); }); it('should revert when non-whitelisted address and it has not accessToken', async function () { diff --git a/test/helpers/fixtures.js b/test/helpers/fixtures.js index 2ec0b7d..8cdb164 100644 --- a/test/helpers/fixtures.js +++ b/test/helpers/fixtures.js @@ -24,7 +24,7 @@ async function deploySwapTokens() { async function initContractsForSettlement() { const abiCoder = ethers.AbiCoder.defaultAbiCoder(); const chainId = await getChainId(); - const [owner, alice, bob] = await ethers.getSigners(); + const [owner, alice, bob, charlie] = await ethers.getSigners(); const { dai, weth, accessToken, lopv4 } = await deploySwapTokens(); @@ -50,7 +50,7 @@ async function initContractsForSettlement() { return { contracts: { dai, weth, accessToken, lopv4, settlement, resolver }, - accounts: { owner, alice, bob }, + accounts: { owner, alice, bob, charlie }, others: { chainId, abiCoder }, }; } diff --git a/test/helpers/fusionUtils.js b/test/helpers/fusionUtils.js index 121c04a..c993b5d 100644 --- a/test/helpers/fusionUtils.js +++ b/test/helpers/fusionUtils.js @@ -13,7 +13,8 @@ async function buildCalldataForOrder({ isInnermostOrder = false, isMakingAmount = true, fillingAmount = isMakingAmount ? orderData.makingAmount : orderData.takingAmount, - integrator = orderSigner.address, + integratorFeeRecipient = orderSigner.address, + protocolFeeRecipient = orderSigner.address, resolverFee = 0, integratorFee = 0, whitelistResolvers = [], // bytes10[] @@ -44,7 +45,8 @@ async function buildCalldataForOrder({ buildFeeTakerExtensions({ feeTaker: await settlement.getAddress(), getterExtraPrefix: auctionDetails, - feeRecipient: integrator, + integratorFeeRecipient, + protocolFeeRecipient, makerReceiver: (makerReceiver && makerReceiver !== constants.ZERO_ADDRESS) ? makerReceiver : undefined, integratorFee, resolverFee, diff --git a/yarn.lock b/yarn.lock index b27450f..cc217ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21,10 +21,10 @@ "@1inch/token-plugins" "1.3.0" "@openzeppelin/contracts" "5.0.1" -"@1inch/limit-order-protocol-contract@4.2.1": - version "4.2.1" - resolved "https://registry.yarnpkg.com/@1inch/limit-order-protocol-contract/-/limit-order-protocol-contract-4.2.1.tgz#255a4bebf84e537b7c862a578748e48e1fbd3461" - integrity sha512-a8ST22sjxMiA9uCHWc+2OAdlTqWps2nJMHhgFi4e2VfwqcOf4JoIJGxwEHFU1fFuOq3xMyxSZONinmyFsINYWg== +"@1inch/limit-order-protocol-contract@4.2.2": + version "4.2.2" + resolved "https://registry.yarnpkg.com/@1inch/limit-order-protocol-contract/-/limit-order-protocol-contract-4.2.2.tgz#237c3cf34942ee39ea1c29d57204b11e741660a7" + integrity sha512-5KcR0O00WP1Z79zX9/xeudzVStLPtiQurmLYmoV+cepTx/Qr67FTKHJKenyIlSQ1p5gg2EOc022gQvSZ2K7m4A== dependencies: "@1inch/solidity-utils" "6.0.0" "@chainlink/contracts" "0.8.0" From 45ee0cb3360d4c52fe41cb34beacc6b5785777ba Mon Sep 17 00:00:00 2001 From: Mikhail Melnik Date: Tue, 24 Dec 2024 23:45:25 +0400 Subject: [PATCH 2/2] linter --- test/Settlement.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/Settlement.js b/test/Settlement.js index 27e7ff2..53ea113 100644 --- a/test/Settlement.js +++ b/test/Settlement.js @@ -746,7 +746,16 @@ describe('Settlement', function () { const txn = await resolver.settleOrders(fillOrderToData0); await expect(txn).to.changeTokenBalances(dai, [resolver, alice], [ether('10') * partialModifier / points, ether('-10') * partialModifier / points]); - await expect(txn).to.changeTokenBalances(weth, [owner, alice, bob, charlie], [ether('-0.01') * partialModifier / points * (ORDER_FEE + FEE_BASE) / FEE_BASE, ether('0.01') * partialModifier / points, 0, ether('0.01') * partialModifier / points * ORDER_FEE / FEE_BASE]); + await expect(txn).to.changeTokenBalances( + weth, + [owner, alice, bob, charlie], + [ + ether('-0.01') * partialModifier / points * (ORDER_FEE + FEE_BASE) / FEE_BASE, + ether('0.01') * partialModifier / points, + 0, + ether('0.01') * partialModifier / points * ORDER_FEE / FEE_BASE, + ], + ); }); it('should not pay resolver fee when whitelisted address and it has accessToken', async function () {