Skip to content

Commit

Permalink
Merge pull request #265 from 1inch/refactor/remove_compactSignature
Browse files Browse the repository at this point in the history
remove compactSignature function
  • Loading branch information
ZumZoom authored Sep 22, 2023
2 parents c545d4c + c3422d2 commit 313a1f8
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 138 deletions.
10 changes: 5 additions & 5 deletions test/ChainLinkExample.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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')]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)]);
Expand Down
14 changes: 7 additions & 7 deletions test/DutchAuctionCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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')));
Expand All @@ -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')));
Expand All @@ -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')));
Expand All @@ -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')));
Expand All @@ -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')));
Expand All @@ -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')));
Expand Down
40 changes: 22 additions & 18 deletions test/Interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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')));
Expand Down Expand Up @@ -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,
Expand All @@ -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')));
Expand Down Expand Up @@ -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,
Expand All @@ -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')));
Expand Down Expand Up @@ -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')));
Expand Down Expand Up @@ -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');
});
Expand Down Expand Up @@ -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')));
Expand Down Expand Up @@ -410,15 +414,15 @@ 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')));
expect(await weth.balanceOf(addr1.address)).to.equal(addr1weth.sub(ether('0.05')));
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');
});
Expand All @@ -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[]'],
Expand Down
Loading

0 comments on commit 313a1f8

Please sign in to comment.