From fd12429677ddf32e8b930233723dbd586c788f30 Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Wed, 16 Apr 2025 12:48:57 +0700 Subject: [PATCH] fix _MAKER_AMOUNT_FLAG setting --- test/FeeTaker.js | 5 ++++ test/LimitOrderProtocol.js | 56 +++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/test/FeeTaker.js b/test/FeeTaker.js index a7d29aa8..08ff081a 100644 --- a/test/FeeTaker.js +++ b/test/FeeTaker.js @@ -55,6 +55,7 @@ describe('FeeTaker', function () { const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1)); const takerTraits = buildTakerTraits({ + makingAmount: true, extension: order.extension, }); const fillTx = swap.fillOrderArgs(order, r, vs, makingAmount, takerTraits.traits, takerTraits.args); @@ -85,6 +86,7 @@ describe('FeeTaker', function () { const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1)); const takerTraits = buildTakerTraits({ + makingAmount: true, extension: order.extension, }); const fillTx = swap.fillOrderArgs(order, r, vs, makingAmount, takerTraits.traits, takerTraits.args); @@ -220,6 +222,7 @@ describe('FeeTaker', function () { const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1)); const takerTraits = buildTakerTraits({ + makingAmount: true, extension: order.extension, }); const fillTx = swap.fillOrderArgs(order, r, vs, makingAmount, takerTraits.traits, takerTraits.args); @@ -266,6 +269,7 @@ describe('FeeTaker', function () { const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1)); const takerTraits = buildTakerTraits({ + makingAmount: true, extension: order.extension, }); const fillTx = swap.fillOrderArgs(order, r, vs, makingAmount, takerTraits.traits, takerTraits.args); @@ -307,6 +311,7 @@ describe('FeeTaker', function () { const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1)); const takerTraits = buildTakerTraits({ + makingAmount: true, extension: order.extension, }); const fillTx = swap.fillOrderArgs(order, r, vs, makingAmount, takerTraits.traits, takerTraits.args); diff --git a/test/LimitOrderProtocol.js b/test/LimitOrderProtocol.js index 52377f9e..abba641c 100644 --- a/test/LimitOrderProtocol.js +++ b/test/LimitOrderProtocol.js @@ -970,7 +970,7 @@ describe('LimitOrderProtocol', function () { describe('ETH Maker Orders', function () { const maximumPremium = 500; // 50% const auctionDuration = time.duration.days(1); - + it('Partial fill', async function () { const { tokens: { dai, weth }, contracts: { swap, ethOrders }, chainId } = await loadFixture(deployContractsAndInit); @@ -1136,7 +1136,7 @@ describe('LimitOrderProtocol', function () { const { tokens: { dai, weth }, contracts: { swap, ethOrders } } = await loadFixture(deployContractsAndInit); const expirationTime = await time.latest() + time.duration.hours(1); - + const order = buildOrder( { maker: await ethOrders.getAddress(), @@ -1152,7 +1152,7 @@ describe('LimitOrderProtocol', function () { }, ); const orderHash = await swap.hashOrder(order); - + await ethOrders.connect(addr1).ethOrderDeposit( order, order.extension, @@ -1160,29 +1160,29 @@ describe('LimitOrderProtocol', function () { auctionDuration, { value: ether('0.3') }, ); - + await time.increaseTo(expirationTime); await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0x2540be400']); // 10 gwei - + const cancelTx = ethOrders.connect(addr2).cancelOrderByResolver(order.makerTraits, orderHash); - + await expect(cancelTx).to.changeTokenBalance(weth, ethOrders, ether('-0.3')); await expect(cancelTx).to.emit(ethOrders, 'ETHOrderCancelledByThirdParty'); - + const orderMakerBalance = await ethOrders.ordersMakersBalances(orderHash); expect(orderMakerBalance.balance).to.equal(0); - + const reward = 30000n * parseUnits('10', 9); // 10 gwei await expect(cancelTx).to.changeEtherBalances([addr1, addr2], [ether('0.3') - reward, reward]); }); - + it('Resolver cancellation in middle of auction period', async function () { if (hre.__SOLIDITY_COVERAGE_RUNNING) { this.skip(); } const { tokens: { dai, weth }, contracts: { swap, ethOrders } } = await loadFixture(deployContractsAndInit); - + const expirationTime = await time.latest() + time.duration.hours(1); const order = buildOrder( @@ -1200,7 +1200,7 @@ describe('LimitOrderProtocol', function () { }, ); const orderHash = await swap.hashOrder(order); - + await ethOrders.connect(addr1).ethOrderDeposit( order, order.extension, @@ -1208,16 +1208,16 @@ describe('LimitOrderProtocol', function () { auctionDuration, { value: ether('0.3') }, ); - + await time.increaseTo(expirationTime + auctionDuration / 2); await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0x2540be400']); // 10 gwei - + const cancelTx = ethOrders.connect(addr2).cancelOrderByResolver(order.makerTraits, orderHash); - + await expect(cancelTx).to.changeTokenBalance(weth, ethOrders, ether('-0.3')); await expect(cancelTx).to.emit(ethOrders, 'ETHOrderCancelledByThirdParty'); - + const orderMakerBalance = await ethOrders.ordersMakersBalances(orderHash); expect(orderMakerBalance.balance).to.equal(0); @@ -1225,10 +1225,10 @@ describe('LimitOrderProtocol', function () { await expect(cancelTx).to.changeEtherBalances([addr1, addr2], [ether('0.3') - reward, reward]); }); - + it('Resolver cancellation fails before expiration', async function () { const { tokens: { dai, weth }, contracts: { swap, ethOrders } } = await loadFixture(deployContractsAndInit); - + const expirationTime = await time.latest() + time.duration.hours(1); const order = buildOrder( @@ -1246,7 +1246,7 @@ describe('LimitOrderProtocol', function () { }, ); const orderHash = await swap.hashOrder(order); - + await ethOrders.connect(addr1).ethOrderDeposit( order, order.extension, @@ -1259,12 +1259,12 @@ describe('LimitOrderProtocol', function () { ethOrders.connect(addr2).cancelOrderByResolver(order.makerTraits, orderHash), ).to.be.revertedWithCustomError(ethOrders, 'OrderNotExpired'); }); - + it('Resolver cancellation fails without access token', async function () { const { tokens: { dai, weth }, contracts: { swap, ethOrders } } = await loadFixture(deployContractsAndInit); - + const expirationTime = await time.latest() + time.duration.hours(1); - + const order = buildOrder( { maker: await ethOrders.getAddress(), @@ -1280,7 +1280,7 @@ describe('LimitOrderProtocol', function () { }, ); const orderHash = await swap.hashOrder(order); - + await ethOrders.connect(addr1).ethOrderDeposit( order, order.extension, @@ -1288,7 +1288,7 @@ describe('LimitOrderProtocol', function () { auctionDuration, { value: ether('0.3') }, ); - + await time.increaseTo(expirationTime + 10); await expect( ethOrders.connect(addr3).cancelOrderByResolver(order.makerTraits, orderHash), @@ -1297,9 +1297,9 @@ describe('LimitOrderProtocol', function () { it('Resolver cancellation fails when maximum premium is 0', async function () { const { tokens: { dai, weth }, contracts: { swap, ethOrders } } = await loadFixture(deployContractsAndInit); - + const expirationTime = await time.latest() + time.duration.hours(1); - + const order = buildOrder( { maker: await ethOrders.getAddress(), @@ -1315,7 +1315,7 @@ describe('LimitOrderProtocol', function () { }, ); const orderHash = await swap.hashOrder(order); - + await ethOrders.connect(addr1).ethOrderDeposit( order, order.extension, @@ -1323,7 +1323,7 @@ describe('LimitOrderProtocol', function () { 0, // auctionDuration { value: ether('0.3') }, ); - + await time.increaseTo(expirationTime + 10); await expect( ethOrders.connect(addr2).cancelOrderByResolver(order.makerTraits, orderHash), @@ -1994,7 +1994,7 @@ describe('LimitOrderProtocol', function () { }); const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1)); - const fillTx = swap.fillOrder(order, r, vs, fillWithMakingAmount(1), 1); + const fillTx = swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); await expect(fillTx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(fillTx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); });