diff --git a/test/ChainLinkExample.js b/test/ChainLinkExample.js index 338dcd62..d0e274a8 100644 --- a/test/ChainLinkExample.js +++ b/test/ChainLinkExample.js @@ -1,6 +1,6 @@ const { expect, trim0x } = require('@1inch/solidity-utils'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { fillWithMakingAmount, compactSignature, signOrder, buildOrder } = require('./helpers/orderUtils'); +const { fillWithMakingAmount, signOrder, buildOrder } = require('./helpers/orderUtils'); const { cutLastArg, ether, setn } = require('./helpers/utils'); const { deploySwapTokens } = require('./helpers/fixtures'); const { ethers } = require('hardhat'); @@ -74,7 +74,7 @@ describe('ChainLinkExample', function () { const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); // taking threshold = 4000 + 1% + eps const filltx = swap.fillOrderExt(order, r, vs, ether('1'), fillWithMakingAmount(ether('4040.01')), order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [ether('-4040'), ether('4040')]); @@ -104,7 +104,7 @@ describe('ChainLinkExample', function () { ); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); // taking threshold = exact taker amount + eps const filltx = swap.fillOrderExt(order, r, vs, makingAmount, fillWithMakingAmount(takingAmount.add(ether('0.01'))), order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [takingAmount.mul(-1), takingAmount]); @@ -132,7 +132,7 @@ describe('ChainLinkExample', function () { ); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect( swap.fillOrderExt(order, r, vs, fillWithMakingAmount(makingAmount), takingAmount.add(ether('0.01')), order.extension), // taking threshold = exact taker amount + eps ).to.be.revertedWithCustomError(swap, 'PredicateIsNotTrue'); @@ -162,7 +162,7 @@ describe('ChainLinkExample', function () { ); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const filltx = swap.fillOrderExt(order, r, vs, makingAmount, fillWithMakingAmount(takingAmount), order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [takingAmount.mul(-1), takingAmount]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [makingAmount, makingAmount.mul(-1)]); diff --git a/test/DutchAuctionCalculator.js b/test/DutchAuctionCalculator.js index 99d9e8ec..b16df7fe 100644 --- a/test/DutchAuctionCalculator.js +++ b/test/DutchAuctionCalculator.js @@ -2,7 +2,7 @@ const { expect, trim0x, time, assertRoughlyEqualValues } = require('@1inch/solid const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { cutLastArg, ether } = require('./helpers/utils'); const { deploySwapTokens } = require('./helpers/fixtures'); -const { fillWithMakingAmount, compactSignature, buildOrder, signOrder } = require('./helpers/orderUtils'); +const { fillWithMakingAmount, buildOrder, signOrder } = require('./helpers/orderUtils'); const { ethers } = require('hardhat'); describe('Dutch auction', function () { @@ -62,7 +62,7 @@ describe('Dutch auction', function () { await time.increaseTo(ts + 43200n); // 50% auction time - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('100'), fillWithMakingAmount(ether('0.08')), order.extension); expect(await dai.balanceOf(addr.address)).to.equal(makerDaiBefore.sub(ether('100'))); @@ -76,7 +76,7 @@ describe('Dutch auction', function () { await time.increaseTo(ts + 43200n); // 50% auction time - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('0.075'), ether('100'), order.extension); expect(await dai.balanceOf(addr.address)).to.equal(makerDaiBefore.sub(ether('100'))); @@ -88,7 +88,7 @@ describe('Dutch auction', function () { it('swap with makingAmount 0% time passed', async function () { const { dai, weth, swap, order, signature, makerDaiBefore, takerDaiBefore, makerWethBefore, takerWethBefore } = await loadFixture(deployAndBuildOrder); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('100'), fillWithMakingAmount(ether('0.1')), order.extension); expect(await dai.balanceOf(addr.address)).to.equal(makerDaiBefore.sub(ether('100'))); @@ -100,7 +100,7 @@ describe('Dutch auction', function () { it('swap with takingAmount 0% time passed', async function () { const { dai, weth, swap, order, signature, makerDaiBefore, takerDaiBefore, makerWethBefore, takerWethBefore } = await loadFixture(deployAndBuildOrder); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('0.1'), ether('100'), order.extension); expect(await dai.balanceOf(addr.address)).to.equal(makerDaiBefore.sub(ether('100'))); @@ -114,7 +114,7 @@ describe('Dutch auction', function () { await time.increaseTo(ts + 86500n); // >100% auction time - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('100'), fillWithMakingAmount(ether('0.05')), order.extension); expect(await dai.balanceOf(addr.address)).to.equal(makerDaiBefore.sub(ether('100'))); @@ -128,7 +128,7 @@ describe('Dutch auction', function () { await time.increaseTo(ts + 86500n); // >100% auction time - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('0.05'), ether('100'), order.extension); expect(await dai.balanceOf(addr.address)).to.equal(makerDaiBefore.sub(ether('100'))); diff --git a/test/Interactions.js b/test/Interactions.js index 687654fc..2668e85d 100644 --- a/test/Interactions.js +++ b/test/Interactions.js @@ -3,7 +3,7 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { deploySwapTokens } = require('./helpers/fixtures'); const { ethers } = require('hardhat'); const { ether } = require('./helpers/utils'); -const { fillWithMakingAmount, signOrder, buildOrder, compactSignature, buildMakerTraits } = require('./helpers/orderUtils'); +const { fillWithMakingAmount, signOrder, buildOrder, buildMakerTraits } = require('./helpers/orderUtils'); describe('Interactions', function () { let addr, addr1; @@ -76,10 +76,11 @@ describe('Interactions', function () { ], ).substring(2); + const { r: backOrderR, _vs: backOrderVs } = ethers.utils.splitSignature(signatureBackOrder); const interaction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ backOrder, - compactSignature(signatureBackOrder).r, - compactSignature(signatureBackOrder).vs, + backOrderR, + backOrderVs, ether('0.1'), fillWithMakingAmount(ether('100')), matcher.address, @@ -91,7 +92,7 @@ describe('Interactions', function () { const addrdai = await dai.balanceOf(addr.address); const addr1dai = await dai.balanceOf(addr1.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await matcher.matchOrders(swap.address, order, r, vs, ether('100'), fillWithMakingAmount(ether('0.1')), interaction); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.add(ether('0.1'))); @@ -140,10 +141,11 @@ describe('Interactions', function () { ], ).substring(2); + const { r: backOrderR, _vs: backOrderVs } = ethers.utils.splitSignature(signatureBackOrder); const interaction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ backOrder, - compactSignature(signatureBackOrder).r, - compactSignature(signatureBackOrder).vs, + backOrderR, + backOrderVs, ether('15'), fillWithMakingAmount(ether('0.015')), matcher.address, @@ -156,7 +158,7 @@ describe('Interactions', function () { const addr1dai = await dai.balanceOf(addr1.address); await weth.approve(matcher.address, ether('0.025')); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await matcher.matchOrders(swap.address, order, r, vs, ether('10'), fillWithMakingAmount(ether('0.01')), interaction); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.sub(ether('0.025'))); @@ -213,20 +215,22 @@ describe('Interactions', function () { ], ).substring(2); + const { r: backOrderR, _vs: backOrderVs } = ethers.utils.splitSignature(signatureBackOrder); const internalInteraction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ backOrder, - compactSignature(signatureBackOrder).r, - compactSignature(signatureBackOrder).vs, + backOrderR, + backOrderVs, ether('0.025'), fillWithMakingAmount(ether('25')), matcher.address, matchingParams, ]).substring(10); + const { r: order2R, _vs: order2Vs } = ethers.utils.splitSignature(signature2); const externalInteraction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ order2, - compactSignature(signature2).r, - compactSignature(signature2).vs, + order2R, + order2Vs, ether('15'), fillWithMakingAmount(ether('0.015')), matcher.address, @@ -238,7 +242,7 @@ describe('Interactions', function () { const addrdai = await dai.balanceOf(addr.address); const addr1dai = await dai.balanceOf(addr1.address); - const { r, vs } = compactSignature(signature1); + const { r, _vs: vs } = ethers.utils.splitSignature(signature1); await matcher.matchOrders(swap.address, order1, r, vs, ether('10'), fillWithMakingAmount(ether('0.01')), externalInteraction); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.sub(ether('0.025'))); @@ -284,7 +288,7 @@ describe('Interactions', function () { await hashChecker.setHashOrderStatus(order, true); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrderExt(order, r, vs, ether('100'), fillWithMakingAmount(ether('0.1')), order.extension); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.sub(ether('100'))); @@ -312,7 +316,7 @@ describe('Interactions', function () { const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect(swap.fillOrderExt(order, r, vs, ether('100'), fillWithMakingAmount(ether('0.1')), order.extension)) .to.be.revertedWithCustomError(hashChecker, 'IncorrectOrderHash'); }); @@ -353,7 +357,7 @@ describe('Interactions', function () { const addrdai = await dai.balanceOf(addr.address); const addr1dai = await dai.balanceOf(addr1.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('50'), fillWithMakingAmount(ether('0.1')), order.extension); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.add(ether('0.05'))); @@ -410,7 +414,7 @@ describe('Interactions', function () { const addrdai = await dai.balanceOf(addr.address); const addr1dai = await dai.balanceOf(addr1.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.connect(addr1).fillOrderExt(order, r, vs, ether('50'), fillWithMakingAmount(ether('0.1')), order.extension); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.add(ether('0.05'))); @@ -418,7 +422,7 @@ describe('Interactions', function () { expect(await dai.balanceOf(addr.address)).to.equal(addrdai.sub(ether('50'))); expect(await dai.balanceOf(addr1.address)).to.equal(addr1dai.add(ether('50'))); - const { r: r2, vs: vs2 } = compactSignature(signaturePartial); + const { r: r2, _vs: vs2 } = ethers.utils.splitSignature(signaturePartial); await expect(swap.connect(addr1).fillOrderExt(partialOrder, r2, vs2, ether('50'), fillWithMakingAmount(ether('0.1')), order.extension)) .to.be.revertedWithCustomError(orderIdInvalidator, 'InvalidOrderHash'); }); @@ -441,7 +445,7 @@ describe('Interactions', function () { }); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const interaction = takerIncreaser.address + abiCoder.encode( ['address[]', 'bytes[]'], diff --git a/test/LimitOrderProtocol.js b/test/LimitOrderProtocol.js index 92e600d2..8d1b6344 100644 --- a/test/LimitOrderProtocol.js +++ b/test/LimitOrderProtocol.js @@ -1,7 +1,7 @@ const hre = require('hardhat'); const { ethers, tracer } = hre; const { expect, time, constants, getPermit2, permit2Contract } = require('@1inch/solidity-utils'); -const { fillWithMakingAmount, unwrapWethTaker, skipMakerPermit, buildMakerTraits, buildOrder, signOrder, compactSignature, buildOrderData } = require('./helpers/orderUtils'); +const { fillWithMakingAmount, unwrapWethTaker, skipMakerPermit, buildMakerTraits, buildOrder, signOrder, buildOrderData } = require('./helpers/orderUtils'); const { getPermit, withTarget } = require('./helpers/eip712'); const { joinStaticCalls, ether, findTrace, countAllItems } = require('./helpers/utils'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); @@ -58,7 +58,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(fakeOrder, r, vs, 1, fillWithMakingAmount(1))) .to.be.revertedWithCustomError(swap, 'BadSignature'); }); @@ -74,7 +74,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 2, fillWithMakingAmount(1))) .to.be.revertedWithCustomError(swap, 'TakingAmountTooHigh'); }); @@ -90,7 +90,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 2, 3)) .to.be.revertedWithCustomError(swap, 'MakingAmountTooLow'); }); @@ -107,7 +107,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowMultipleFills: true }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const swapWithoutThreshold = await swap.fillOrder(order, r, vs, 5, 0); const gasUsedWithoutThreshold = (await swapWithoutThreshold.wait()).gasUsed; @@ -127,7 +127,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 0, 0)) .to.be.revertedWithCustomError(swap, 'SwapWithZeroAmount'); }); @@ -145,7 +145,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); 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]); @@ -170,7 +170,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); 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]); @@ -195,7 +195,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 9, 1); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-9, 9]); @@ -214,7 +214,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 4, 0)) .to.be.revertedWithCustomError(swap, 'SwapWithZeroAmount'); }); @@ -232,7 +232,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 4, fillWithMakingAmount(1)); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [4, -4]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -253,7 +253,7 @@ describe('LimitOrderProtocol', function () { await weth.connect(addr1).deposit({ value: ether('2') }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, ether('5'), unwrapWethTaker(ether('1'))); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [ether('-5'), ether('5')]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [ether('0'), ether('-1')]); @@ -285,7 +285,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, 10, fillWithMakingAmount(10), order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [10, -10]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-10, 10]); @@ -315,7 +315,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowMultipleFills: false }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 4, fillWithMakingAmount(1)); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [4, -4]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -338,7 +338,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ shouldCheckEpoch: true }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 4, fillWithMakingAmount(1)); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [4, -4]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -358,7 +358,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ shouldCheckEpoch: true, nonce: 1 }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 4, fillWithMakingAmount(1))) .to.be.revertedWithCustomError(swap, 'WrongSeriesNonce'); }); @@ -377,7 +377,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ unwrapWeth: true }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 10, fillWithMakingAmount(2)); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [10, -10]); await expect(filltx).to.changeTokenBalance(weth, addr, -2); @@ -398,7 +398,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowPriceImprovement: true }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderTo(order, r, vs, 10, 2, addr.address, takerIncreaser.address); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [10, -10]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-3, 3]); @@ -427,7 +427,7 @@ describe('LimitOrderProtocol', function () { const { dai, weth, swap, chainId, order, signature } = await loadFixture(deployContractsAndInitPermit); const permit = await getPermit(addr.address, addr, weth, '1', chainId, swap.address, '1'); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const filltx = swap.fillOrderToWithPermit(order, r, vs, 1, fillWithMakingAmount(1), addr.address, permit, '0x'); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -449,7 +449,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ usePermit2: true }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderToWithPermit(order, r, vs, 1, fillWithMakingAmount(1), addr.address, permit, '0x'); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -460,7 +460,7 @@ describe('LimitOrderProtocol', function () { const permit = await getPermit(addr.address, addr, weth, '1', chainId, swap.address, '1'); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrderToWithPermit(order, r, vs, 1, 1, addr.address, permit, '0x'); await expect(swap.fillOrderToWithPermit(order, r, vs, 1, 1, addr.address, permit, '0x')) .to.be.revertedWith('ERC20Permit: invalid signature'); @@ -471,7 +471,7 @@ describe('LimitOrderProtocol', function () { const permit = await getPermit(addr.address, addr2, weth, '1', chainId, swap.address, '1'); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect(swap.fillOrderToWithPermit(order, r, vs, 1, 1, addr.address, permit, '0x')) .to.be.revertedWith('ERC20Permit: invalid signature'); }); @@ -482,7 +482,7 @@ describe('LimitOrderProtocol', function () { const deadline = (await time.latest()) - time.duration.weeks(1); const permit = await getPermit(addr.address, addr1, weth, '1', chainId, swap.address, '1', deadline); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect(swap.fillOrderToWithPermit(order, r, vs, 1, 1, addr.address, permit, '0x')) .to.be.revertedWith('ERC20Permit: expired deadline'); }); @@ -511,7 +511,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr)); return { dai, weth, swap, order, r, vs, permit }; }; @@ -553,7 +553,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowPartialFill: false }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 10, fillWithMakingAmount(10)); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [10, -10]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-10, 10]); @@ -571,7 +571,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowPartialFill: false }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 5, fillWithMakingAmount(5))) .to.be.revertedWithCustomError(swap, 'PartialFillNotAllowed'); }); @@ -588,7 +588,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowPartialFill: false }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 5, 5)) .to.be.revertedWithCustomError(swap, 'PartialFillNotAllowed'); }); @@ -605,7 +605,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowPartialFill: false }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 10, 10); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [10, -10]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-10, 10]); @@ -743,7 +743,7 @@ describe('LimitOrderProtocol', function () { }); return { dai, weth, swap, chainId, order }; }; - + it('should revert for new order', async function () { const { swap, chainId, order } = await loadFixture(orderCancelationInit); const data = buildOrderData(chainId, swap.address, order); @@ -754,7 +754,7 @@ describe('LimitOrderProtocol', function () { it('should return correct remaining for partially filled order', async function () { const { swap, chainId, order } = await loadFixture(orderCancelationInit); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const data = buildOrderData(chainId, swap.address, order); const orderHash = ethers.utils._TypedDataEncoder.hash(data.domain, data.types, data.value); @@ -766,7 +766,7 @@ describe('LimitOrderProtocol', function () { it('should return zero remaining for filled order', async function () { const { swap, chainId, order } = await loadFixture(orderCancelationInit); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const data = buildOrderData(chainId, swap.address, order); const orderHash = ethers.utils._TypedDataEncoder.hash(data.domain, data.types, data.value); @@ -837,7 +837,7 @@ describe('LimitOrderProtocol', function () { it('should not fill cancelled order', async function () { const { swap, chainId, order } = await loadFixture(orderCancelationInit); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const data = buildOrderData(chainId, swap.address, order); const orderHash = ethers.utils._TypedDataEncoder.hash(data.domain, data.types, data.value); @@ -852,7 +852,7 @@ describe('LimitOrderProtocol', function () { await swap.connect(addr1).increaseEpoch(1); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 2, fillWithMakingAmount(2))) .to.be.revertedWithCustomError(swap, 'WrongSeriesNonce'); }); @@ -862,7 +862,7 @@ describe('LimitOrderProtocol', function () { await swap.connect(addr2).increaseEpoch(1); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); 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]); @@ -871,7 +871,7 @@ describe('LimitOrderProtocol', function () { it('epoch change, partially filled order should fail', async function () { const { dai, weth, swap, chainId, order } = await loadFixture(orderWithEpochInit); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); 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]); @@ -908,7 +908,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowedSender: addr.address }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); 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]); @@ -926,7 +926,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ allowedSender: addr1.address }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1))) .to.be.revertedWithCustomError(swap, 'PrivateOrder'); }); @@ -962,7 +962,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, 1, 1, order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -990,7 +990,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrderExt(order, r, vs, 1, 1, order.extension)) .to.be.revertedWithCustomError(swap, 'PredicateIsNotTrue'); }); @@ -1021,7 +1021,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, 1, 1, order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -1053,7 +1053,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrderExt(order, r, vs, 1, 1, order.extension)) .to.be.revertedWithCustomError(swap, 'PredicateIsNotTrue'); }); @@ -1084,7 +1084,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, 1, 1, order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -1116,7 +1116,7 @@ describe('LimitOrderProtocol', function () { }, ); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrderExt(order, r, vs, 1, 1, order.extension)) .to.be.revertedWithCustomError(swap, 'PredicateIsNotTrue'); }); @@ -1141,7 +1141,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ expiry: (await time.latest()) + 3600 }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, fillWithMakingAmount(1), 1); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -1159,7 +1159,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ expiry: 0xff0000n }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1))) .to.be.revertedWithCustomError(swap, 'OrderExpired'); }); @@ -1176,7 +1176,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ expiry: await time.latest() }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 4, fillWithMakingAmount(1))) .to.be.revertedWithCustomError(swap, 'OrderExpired'); }); @@ -1193,7 +1193,7 @@ describe('LimitOrderProtocol', function () { makerTraits: buildMakerTraits({ expiry: await time.latest() + 1800 }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); 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]); @@ -1215,7 +1215,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 3, 2); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [2, -2]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-2, 2]); @@ -1232,7 +1232,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 3, fillWithMakingAmount(3)); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [2, -2]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-2, 2]); @@ -1257,7 +1257,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 900, fillWithMakingAmount(3), { value: 3 }); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [900, -900]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [0, 3]); @@ -1275,7 +1275,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 900, fillWithMakingAmount(3), { value: 2 })) .to.be.revertedWithCustomError(swap, 'InvalidMsgValue'); }); @@ -1291,7 +1291,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrder(order, r, vs, 900, fillWithMakingAmount(3), { value: 4 }); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [900, -900]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [0, 3]); @@ -1312,7 +1312,7 @@ describe('LimitOrderProtocol', function () { maker: addr1.address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); await expect(swap.fillOrder(order, r, vs, 900, fillWithMakingAmount(900), { value: 1 })) .to.be.revertedWithCustomError(swap, 'InvalidMsgValue'); }); diff --git a/test/MeasureGas.js b/test/MeasureGas.js index e9852e72..db1f2ff2 100644 --- a/test/MeasureGas.js +++ b/test/MeasureGas.js @@ -3,7 +3,7 @@ const { ethers } = hre; const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { deploySwapTokens } = require('./helpers/fixtures'); const { ether } = require('./helpers/utils'); -const { fillWithMakingAmount, signOrder, buildOrder, compactSignature, buildMakerTraits } = require('./helpers/orderUtils'); +const { fillWithMakingAmount, signOrder, buildOrder, buildMakerTraits } = require('./helpers/orderUtils'); describe('MeasureGas', function () { before(async function () { @@ -39,7 +39,7 @@ describe('MeasureGas', function () { maker: addrs[1].address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addrs[1])); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addrs[1])); const tx = await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); console.log(`swap without predicates gasUsed: ${(await tx.wait()).gasUsed}`); }); @@ -55,7 +55,7 @@ describe('MeasureGas', function () { maker: addrs[1].address, }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addrs[1])); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addrs[1])); const tx = await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); console.log(`swap partial fill without predicates gasUsed: ${(await tx.wait()).gasUsed}`); }); @@ -72,7 +72,7 @@ describe('MeasureGas', function () { makerTraits: buildMakerTraits({ nonce: 1 }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addrs[1])); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addrs[1])); const tx = await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); console.log(`swap with predicate nonce gasUsed: ${(await tx.wait()).gasUsed}`); }); @@ -89,7 +89,7 @@ describe('MeasureGas', function () { makerTraits: buildMakerTraits({ expiry: 0xff00000000 }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addrs[1])); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addrs[1])); const tx = await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); console.log(`swap with predicate expiry gasUsed: ${(await tx.wait()).gasUsed}`); }); @@ -106,7 +106,7 @@ describe('MeasureGas', function () { makerTraits: buildMakerTraits({ nonce: 1, expiry: 0xff00000000 }), }); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addrs[1])); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addrs[1])); const tx = await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); console.log(`swap with predicate nonce and expiry gasUsed: ${(await tx.wait()).gasUsed}`); }); diff --git a/test/RangeLimitOrders.js b/test/RangeLimitOrders.js index eed04f35..5e052513 100644 --- a/test/RangeLimitOrders.js +++ b/test/RangeLimitOrders.js @@ -2,7 +2,7 @@ const { ethers } = require('hardhat'); const { parseUnits } = require('ethers/lib/utils.js'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { expect, trim0x } = require('@1inch/solidity-utils'); -const { fillWithMakingAmount, buildMakerTraits, buildOrder, signOrder, compactSignature } = require('./helpers/orderUtils'); +const { fillWithMakingAmount, buildMakerTraits, buildOrder, signOrder } = require('./helpers/orderUtils'); const { cutLastArg, ether } = require('./helpers/utils'); const { deploySwapTokens, deployRangeAmountCalculator } = require('./helpers/fixtures'); @@ -72,7 +72,7 @@ describe('RangeLimitOrders', function () { ))), }); const signature = await signOrder(order, chainId, swap.address, maker); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); return { order, r, vs, startPrice, endPrice, makingAmount, takingAmount }; } diff --git a/test/RfqInteractions.js b/test/RfqInteractions.js index d3cc51c6..873b37c8 100644 --- a/test/RfqInteractions.js +++ b/test/RfqInteractions.js @@ -3,7 +3,7 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { deploySwapTokens } = require('./helpers/fixtures'); const { ethers } = require('hardhat'); const { ether } = require('./helpers/utils'); -const { buildOrderRFQ, signOrder, compactSignature, buildMakerTraits } = require('./helpers/orderUtils'); +const { buildOrderRFQ, signOrder, buildMakerTraits } = require('./helpers/orderUtils'); const { constants } = require('ethers'); describe('RfqInteractions', function () { @@ -69,10 +69,11 @@ describe('RfqInteractions', function () { ], ).substring(2); + const { r: backOrderR, _vs: backOrderVs } = ethers.utils.splitSignature(signatureBackOrder); const interaction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ backOrder, - compactSignature(signatureBackOrder).r, - compactSignature(signatureBackOrder).vs, + backOrderR, + backOrderVs, ether('100'), ether('0.1'), constants.AddressZero, @@ -84,7 +85,7 @@ describe('RfqInteractions', function () { const addrdai = await dai.balanceOf(addr.address); const addr1dai = await dai.balanceOf(addr1.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await matcher.matchOrders(swap.address, order, r, vs, ether('0.1'), ether('100'), interaction); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.add(ether('0.1'))); @@ -131,10 +132,11 @@ describe('RfqInteractions', function () { ], ).substring(2); + const { r: backOrderR, _vs: backOrderVs } = ethers.utils.splitSignature(signatureBackOrder); const interaction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ backOrder, - compactSignature(signatureBackOrder).r, - compactSignature(signatureBackOrder).vs, + backOrderR, + backOrderVs, ether('0.015'), ether('15'), constants.AddressZero, @@ -147,7 +149,7 @@ describe('RfqInteractions', function () { const addr1dai = await dai.balanceOf(addr1.address); await weth.approve(matcher.address, ether('0.025')); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await matcher.matchOrders(swap.address, order, r, vs, ether('0.01'), ether('10'), interaction); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.sub(ether('0.025'))); @@ -202,20 +204,22 @@ describe('RfqInteractions', function () { ], ).substring(2); + const { r: backOrderR, _vs: backOrderVs } = ethers.utils.splitSignature(signatureBackOrder); const internalInteraction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ backOrder, - compactSignature(signatureBackOrder).r, - compactSignature(signatureBackOrder).vs, + backOrderR, + backOrderVs, ether('25'), ether('0.025'), constants.AddressZero, matchingParams, ]).substring(10); + const { r: order2R, _vs: order2Vs } = ethers.utils.splitSignature(signature2); const externalInteraction = matcher.address + '00' + swap.interface.encodeFunctionData('fillOrderTo', [ order2, - compactSignature(signature2).r, - compactSignature(signature2).vs, + order2R, + order2Vs, ether('0.015'), ether('15'), constants.AddressZero, @@ -227,7 +231,7 @@ describe('RfqInteractions', function () { const addrdai = await dai.balanceOf(addr.address); const addr1dai = await dai.balanceOf(addr1.address); - const { r, vs } = compactSignature(signature1); + const { r, _vs: vs } = ethers.utils.splitSignature(signature1); await matcher.matchOrders(swap.address, order1, r, vs, ether('0.01'), ether('10'), externalInteraction); expect(await weth.balanceOf(addr.address)).to.equal(addrweth.sub(ether('0.025'))); diff --git a/test/RfqOrders.js b/test/RfqOrders.js index c2c35c59..f4ed960a 100644 --- a/test/RfqOrders.js +++ b/test/RfqOrders.js @@ -2,7 +2,7 @@ const hre = require('hardhat'); const { ethers } = hre; const { expect, time, profileEVM, trackReceivedTokenAndTx, getPermit2, permit2Contract } = require('@1inch/solidity-utils'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { buildOrderRFQ, signOrder, compactSignature, fillWithMakingAmount, unwrapWethTaker, buildMakerTraits, buildOrderData } = require('./helpers/orderUtils'); +const { buildOrderRFQ, signOrder, fillWithMakingAmount, unwrapWethTaker, buildMakerTraits, buildOrderData } = require('./helpers/orderUtils'); const { getPermit } = require('./helpers/eip712'); const { deploySwapTokens } = require('./helpers/fixtures'); const { constants } = require('ethers'); @@ -56,7 +56,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const receipt = await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) { @@ -94,7 +94,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrderToWithPermit(order, r, vs, 1, fillWithMakingAmount(1), addr.address, permit, emptyInteraction); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.sub(1)); @@ -124,7 +124,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrderToWithPermit(order, r, vs, 1, fillWithMakingAmount(1), addr.address, permit, emptyInteraction); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.sub(1)); @@ -146,7 +146,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const signature = await signOrder(order, chainId, swap.address, addr1); const permit = await getPermit(addr.address, addr, weth, '1', chainId, swap.address, '1'); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const requestFunc = () => swap.fillOrderToWithPermit(order, r, vs, 1, 1, addr.address, permit, emptyInteraction); await requestFunc(); await expect(requestFunc()).to.be.revertedWith('ERC20Permit: invalid signature'); @@ -165,7 +165,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const signature = await signOrder(order, chainId, swap.address, addr1); const permit = await getPermit(addr.address, addr2, weth, '1', chainId, swap.address, '1'); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect(swap.fillOrderToWithPermit(order, r, vs, 1, 1, addr.address, permit, emptyInteraction)).to.be.revertedWith('ERC20Permit: invalid signature'); }); @@ -183,7 +183,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const signature = await signOrder(order, chainId, swap.address, addr1); const permit = await getPermit(addr.address, addr1, weth, '1', chainId, swap.address, '1', deadline); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect(swap.fillOrderToWithPermit(order, r, vs, 1, 1, addr.address, permit, emptyInteraction)).to.be.revertedWith('ERC20Permit: expired deadline'); }); }); @@ -244,7 +244,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const signature = await signOrder(order, chainId, swap.address, addr1); await swap.connect(addr1).cancelOrder(order.makerTraits, orderHash); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect( swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)), ).to.be.revertedWithCustomError(swap, 'BitInvalidatedOrder'); @@ -269,7 +269,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.sub(1)); @@ -295,7 +295,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrder(order, r, vs, 1, fillWithMakingAmount(1)); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.sub(1)); @@ -321,7 +321,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrder(order, r, vs, 1, 1); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.sub(1)); @@ -342,7 +342,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { }); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect( swap.fillOrder(order, r, vs, 1, 0), ).to.be.revertedWithCustomError(swap, 'SwapWithZeroAmount'); @@ -360,7 +360,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { }); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect( swap.fillOrder(order, r, vs, fillWithMakingAmount(1), 1), ).to.be.revertedWithCustomError(swap, 'OrderExpired'); @@ -386,7 +386,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrder(order, r, vs, 3, 900, { value: 3 }); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.sub(900)); @@ -412,7 +412,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { const makerWeth = await weth.balanceOf(addr1.address); const takerWeth = await weth.balanceOf(addr.address); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await swap.fillOrder(order, r, vs, 3, unwrapWethTaker(fillWithMakingAmount(900))); expect(await dai.balanceOf(addr1.address)).to.equal(makerDai.add(900)); @@ -433,7 +433,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { }); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect( swap.fillOrder(order, r, vs, 900, fillWithMakingAmount(3), { value: 2 }), ).to.be.revertedWithCustomError(swap, 'InvalidMsgValue'); @@ -451,7 +451,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { }); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); const promise = () => swap.fillOrder(order, r, vs, 900, fillWithMakingAmount(3), { value: 4 }); const [ethDiff] = await trackReceivedTokenAndTx(ethers.provider, { address: constants.AddressZero }, addr.address, promise); expect(ethDiff).to.equal(-3n); @@ -470,7 +470,7 @@ describe('RFQ Orders in LimitOrderProtocol', function () { }); const signature = await signOrder(order, chainId, swap.address, addr1); - const { r, vs } = compactSignature(signature); + const { r, _vs: vs } = ethers.utils.splitSignature(signature); await expect( swap.fillOrder(order, r, vs, 900, fillWithMakingAmount(900), { value: 1 }), ).to.be.revertedWithCustomError(swap, 'InvalidMsgValue'); diff --git a/test/examples/LimitOrderProtocol-example.js b/test/examples/LimitOrderProtocol-example.js index 1bcec466..1a1c0b1d 100644 --- a/test/examples/LimitOrderProtocol-example.js +++ b/test/examples/LimitOrderProtocol-example.js @@ -1,7 +1,7 @@ const hre = require('hardhat'); const { ethers } = hre; const { expect, time, constants, trim0x } = require('@1inch/solidity-utils'); -const { fillWithMakingAmount, buildMakerTraits, buildOrder, signOrder, compactSignature, ABIOrder } = require('../helpers/orderUtils'); +const { fillWithMakingAmount, buildMakerTraits, buildOrder, signOrder, ABIOrder } = require('../helpers/orderUtils'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { joinStaticCalls, ether, cutLastArg } = require('../helpers/utils'); @@ -115,7 +115,7 @@ describe.skip('LimitOrderProtocol usage example', function () { console.log('simple order'); console.log(orderCalldata.substring(2).replace(/(.{8})/g, '$1 ').replace(/(.{72})/g, '$1\n')); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, 1, 1, order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalance(weth, addr, -1); @@ -158,7 +158,7 @@ describe.skip('LimitOrderProtocol usage example', function () { console.log('order', order); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, 1, 1, order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-1, 1]); @@ -191,7 +191,7 @@ describe.skip('LimitOrderProtocol usage example', function () { console.log('order', order); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderToExt(order, r, vs, 1, 1, addr.address, order.extension, takerInteraction); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [1, -1]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-4, 4]); @@ -207,7 +207,7 @@ describe.skip('LimitOrderProtocol usage example', function () { [addr1.address, constants.ZERO_ADDRESS, 0, 10, dai.address], // leave only 2 extra arguments ).substring(202); - + const takerAssetSuffix = '0x' + erc721proxy.interface.encodeFunctionData( 'func_60iHVgK', // ERC721Proxy arguments (2 last passed as extra) @@ -236,7 +236,7 @@ describe.skip('LimitOrderProtocol usage example', function () { console.log('order', order); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, 10, fillWithMakingAmount(10), order.extension); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [10, -10]); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [-10, 10]); @@ -276,7 +276,7 @@ describe.skip('LimitOrderProtocol usage example', function () { console.log('order', order); - const { r, vs } = compactSignature(await signOrder(order, chainId, swap.address, addr1)); + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); const filltx = swap.fillOrderExt(order, r, vs, ether('2'), fillWithMakingAmount(ether('6200')), order.extension); await expect(filltx).to.changeTokenBalances(weth, [addr, addr1], [ether('2'), ether('-2')]); await expect(filltx).to.changeTokenBalances(dai, [addr, addr1], [ether('-6200'), ether('6200')]); diff --git a/test/helpers/orderUtils.js b/test/helpers/orderUtils.js index 68ae7127..bd0d2441 100644 --- a/test/helpers/orderUtils.js +++ b/test/helpers/orderUtils.js @@ -1,6 +1,5 @@ const { constants, trim0x } = require('@1inch/solidity-utils'); const { assert } = require('chai'); -const { ethers } = require('ethers'); const { keccak256 } = require('ethers/lib/utils'); const { setn } = require('./utils'); @@ -224,14 +223,6 @@ async function signOrder (order, chainId, target, wallet) { return await wallet._signTypedData(orderData.domain, orderData.types, orderData.value); } -function compactSignature (signature) { - const sig = ethers.utils.splitSignature(signature); - return { - r: sig.r, - vs: sig._vs, - }; -} - function fillWithMakingAmount (amount) { return setn(amount, 255, true).toString(); } @@ -252,7 +243,6 @@ module.exports = { buildOrderRFQ, buildOrderData, signOrder, - compactSignature, fillWithMakingAmount, unwrapWethTaker, skipMakerPermit,