Skip to content

fix _MAKER_AMOUNT_FLAG setting #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/FeeTaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
56 changes: 28 additions & 28 deletions test/LimitOrderProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(),
Expand All @@ -1152,37 +1152,37 @@ describe('LimitOrderProtocol', function () {
},
);
const orderHash = await swap.hashOrder(order);

await ethOrders.connect(addr1).ethOrderDeposit(
order,
order.extension,
maximumPremium,
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(
Expand All @@ -1200,35 +1200,35 @@ describe('LimitOrderProtocol', function () {
},
);
const orderHash = await swap.hashOrder(order);

await ethOrders.connect(addr1).ethOrderDeposit(
order,
order.extension,
maximumPremium,
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);

const reward = 30000n * parseUnits('10', 9) * 125n / 100n; // 10 gwei + 25% auction boost

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(
Expand All @@ -1246,7 +1246,7 @@ describe('LimitOrderProtocol', function () {
},
);
const orderHash = await swap.hashOrder(order);

await ethOrders.connect(addr1).ethOrderDeposit(
order,
order.extension,
Expand All @@ -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(),
Expand All @@ -1280,15 +1280,15 @@ describe('LimitOrderProtocol', function () {
},
);
const orderHash = await swap.hashOrder(order);

await ethOrders.connect(addr1).ethOrderDeposit(
order,
order.extension,
maximumPremium,
auctionDuration,
{ value: ether('0.3') },
);

await time.increaseTo(expirationTime + 10);
await expect(
ethOrders.connect(addr3).cancelOrderByResolver(order.makerTraits, orderHash),
Expand All @@ -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(),
Expand All @@ -1315,15 +1315,15 @@ describe('LimitOrderProtocol', function () {
},
);
const orderHash = await swap.hashOrder(order);

await ethOrders.connect(addr1).ethOrderDeposit(
order,
order.extension,
0, // maximumPremium
0, // auctionDuration
{ value: ether('0.3') },
);

await time.increaseTo(expirationTime + 10);
await expect(
ethOrders.connect(addr2).cancelOrderByResolver(order.makerTraits, orderHash),
Expand Down Expand Up @@ -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]);
});
Expand Down
Loading