Skip to content

Commit

Permalink
add feeTaker builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Nov 20, 2024
1 parent fec2379 commit d721b32
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 102 deletions.
152 changes: 50 additions & 102 deletions test/FeeTaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const { ethers } = hre;
const { expect } = require('@1inch/solidity-utils');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { deploySwapTokens } = require('./helpers/fixtures');
const { buildOrder, buildTakerTraits, signOrder, buildMakerTraits } = require('./helpers/orderUtils');
const { buildOrder, buildTakerTraits, signOrder, buildMakerTraits, buildFeeTakerExtensions } = require('./helpers/orderUtils');
const { ether } = require('./helpers/utils');

describe('FeeTaker', function () {
describe.only('FeeTaker', function () {
let addr, addr1, addr2, addr3;
before(async function () {
[addr, addr1, addr2, addr3] = await ethers.getSigners();
Expand Down Expand Up @@ -40,7 +40,6 @@ describe('FeeTaker', function () {

const makingAmount = ether('300');
const takingAmount = ether('0.3');
const fee = 0;
const feeRecipient = addr2.address;

const order = buildOrder(
Expand All @@ -52,12 +51,10 @@ describe('FeeTaker', function () {
makingAmount,
takingAmount,
},
{
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), '0x00', feeRecipient, fee, fee, 50, '0x00'],
),
},
buildFeeTakerExtensions({
feeTaker: await feeTaker.getAddress(),
feeRecipient,
}),
);

const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1));
Expand All @@ -75,7 +72,6 @@ describe('FeeTaker', function () {

const makingAmount = ether('300');
const takingAmount = ether('0.3');
const fee = 0;
const feeRecipient = addr2.address;
const makerReceiver = addr3.address;

Expand All @@ -88,12 +84,11 @@ describe('FeeTaker', function () {
makingAmount,
takingAmount,
},
{
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address', 'address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), '0x01', feeRecipient, makerReceiver, fee, fee, 50, '0x00'],
),
},
buildFeeTakerExtensions({
feeTaker: await feeTaker.getAddress(),
feeRecipient,
makerReceiver,
}),
);

const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1));
Expand Down Expand Up @@ -125,25 +120,14 @@ describe('FeeTaker', function () {
makingAmount,
takingAmount,
},
{
// * 2 bytes — integrator fee percentage (in 1e5)
// * 2 bytes — resolver fee percentage (in 1e5)
// * 20 bytes — fee recipient
// * 1 byte - taker whitelist size
// * (bytes10)[N] — taker whitelist
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address', 'uint16', 'uint16', 'uint8', 'bytes1', 'bytes'],
[await feeTaker.getAddress(), '0x00', feeRecipient, integratorFee, resolverFee, 50, '0x0a', whitelist],
),
makingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1', 'bytes'],
[await feeTaker.getAddress(), integratorFee, resolverFee, 50, '0x0a', whitelist],
),
takingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1', 'bytes'],
[await feeTaker.getAddress(), integratorFee, resolverFee, 50, '0x0a', whitelist],
),
},
buildFeeTakerExtensions({
feeTaker: await feeTaker.getAddress(),
feeRecipient,
integratorFee,
resolverFee,
whitelistLength: 10,
whitelist,
}),
);

const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1));
Expand Down Expand Up @@ -178,25 +162,14 @@ describe('FeeTaker', function () {
makingAmount,
takingAmount,
},
{
// * 2 bytes — integrator fee percentage (in 1e5)
// * 2 bytes — resolver fee percentage (in 1e5)
// * 20 bytes — fee recipient
// * 1 byte - taker whitelist size
// * (bytes10)[N] — taker whitelist
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address', 'uint16', 'uint16', 'uint8', 'bytes1', 'bytes'],
[await feeTaker.getAddress(), '0x00', feeRecipient, integratorFee, resolverFee, 50, '0x0a', whitelist],
),
makingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1', 'bytes'],
[await feeTaker.getAddress(), integratorFee, resolverFee, 50, '0x0a', whitelist],
),
takingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1', 'bytes'],
[await feeTaker.getAddress(), integratorFee, resolverFee, 50, '0x0a', whitelist],
),
},
buildFeeTakerExtensions({
feeTaker: await feeTaker.getAddress(),
feeRecipient,
integratorFee,
resolverFee,
whitelistLength: 10,
whitelist,
}),
);

const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1));
Expand All @@ -220,8 +193,8 @@ describe('FeeTaker', function () {

const makingAmount = ether('300');
const takingAmount = ether('0.3');
const fee = BigInt(1e4);
const feeCalculated = takingAmount * fee / BigInt(1e5);
const integratorFee = BigInt(1e4);
const feeCalculated = takingAmount * integratorFee / BigInt(1e5);
const feeRecipient = addr2.address;
const makerReceiver = addr3.address;

Expand All @@ -234,20 +207,12 @@ describe('FeeTaker', function () {
makingAmount,
takingAmount,
},
{
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address', 'address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), '0x01', feeRecipient, makerReceiver, fee, 0, 50, '0x00'],
),
makingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), fee, 0, 50, '0x00'],
),
takingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), fee, 0, 50, '0x00'],
),
},
buildFeeTakerExtensions({
feeTaker: await feeTaker.getAddress(),
feeRecipient,
makerReceiver,
integratorFee,
}),
);

const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1));
Expand All @@ -265,8 +230,8 @@ describe('FeeTaker', function () {

const makingAmount = ether('300');
const takingAmount = ether('0.3');
const fee = BigInt(1e4);
const feeCalculated = takingAmount * fee / BigInt(1e5);
const integratorFee = BigInt(1e4);
const feeCalculated = takingAmount * integratorFee / BigInt(1e5);
const feeRecipient = addr2.address;

const order = buildOrder(
Expand All @@ -279,20 +244,11 @@ describe('FeeTaker', function () {
takingAmount,
makerTraits: buildMakerTraits({ unwrapWeth: true }),
},
{
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), '0x00', feeRecipient, fee, 0, 50, '0x00'],
),
makingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), fee, 0, 50, '0x00'],
),
takingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), fee, 0, 50, '0x00'],
),
},
buildFeeTakerExtensions({
feeTaker: await feeTaker.getAddress(),
feeRecipient,
integratorFee,
}),
);

const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1));
Expand All @@ -311,8 +267,8 @@ describe('FeeTaker', function () {

const makingAmount = ether('300');
const takingAmount = ether('0.3');
const fee = BigInt(1e4);
const feeCalculated = takingAmount * fee / BigInt(1e5);
const integratorFee = BigInt(1e4);
const feeCalculated = takingAmount * integratorFee / BigInt(1e5);
const feeRecipient = addr2.address;
const makerReceiver = addr3.address;

Expand All @@ -326,20 +282,12 @@ describe('FeeTaker', function () {
takingAmount,
makerTraits: buildMakerTraits({ unwrapWeth: true }),
},
{
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address', 'address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), '0x01', feeRecipient, makerReceiver, fee, 0, 50, '0x00'],
),
makingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), fee, 0, 50, '0x00'],
),
takingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'bytes1'],
[await feeTaker.getAddress(), fee, 0, 50, '0x00'],
),
},
buildFeeTakerExtensions({
feeTaker: await feeTaker.getAddress(),
feeRecipient,
makerReceiver,
integratorFee,
}),
);

const { r, yParityAndS: vs } = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr1));
Expand Down
34 changes: 34 additions & 0 deletions test/helpers/orderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@ function buildMakerTraits ({
).toString(16).padStart(64, '0');
}

function buildFeeTakerExtensions({

Check failure on line 127 in test/helpers/orderUtils.js

View workflow job for this annotation

GitHub Actions / lint

Missing space before function parentheses
feeTaker,
feeRecipient,
makerReceiver = undefined,
integratorFee = 0,
resolverFee = 0,
whitelistDiscount = 50,
whitelistLength = 0,
whitelist = '0x',
whitelistPostInteraction = whitelist,
}) {
return {
makingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'uint8', 'bytes'],
[feeTaker, integratorFee, resolverFee, whitelistDiscount, whitelistLength, whitelist],
),
takingAmountData: ethers.solidityPacked(
['address', 'uint16', 'uint16', 'uint8', 'uint8', 'bytes'],
[feeTaker, integratorFee, resolverFee, whitelistDiscount, whitelistLength, whitelist],
),
postInteraction: ethers.solidityPacked(
['address', 'bytes1', 'address'].concat(
makerReceiver ? ['address'] : [],
['uint16', 'uint16', 'uint8', 'uint8', 'bytes'],
),
[feeTaker, makerReceiver ? '0x01' : '0x00', feeRecipient].concat(
makerReceiver ? [makerReceiver] : [],
[integratorFee, resolverFee, whitelistDiscount, whitelistLength, whitelistPostInteraction],
),
),
}

Check failure on line 157 in test/helpers/orderUtils.js

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
}

function buildOrderRFQ (
{
maker,
Expand Down Expand Up @@ -276,6 +309,7 @@ module.exports = {
buildTakerTraits,
buildMakerTraits,
buildMakerTraitsRFQ,
buildFeeTakerExtensions,
buildOrder,
buildOrderRFQ,
buildOrderData,
Expand Down

0 comments on commit d721b32

Please sign in to comment.