-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from 1inch/feature/priority-fee-limiter
add priority fee limiter
- Loading branch information
Showing
3 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const { expect, deployContract, time, ether, trim0x, constants } = require('@1inch/solidity-utils'); | ||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); | ||
const { buildOrder, buildMakerTraits } = require('@1inch/limit-order-protocol-contract/test/helpers/orderUtils'); | ||
const { initContractsForSettlement } = require('./helpers/fixtures'); | ||
const hre = require('hardhat'); | ||
const { ethers, network } = hre; | ||
|
||
describe('PriorityFeeLimiter', function () { | ||
before(async function () { | ||
if (hre.__SOLIDITY_COVERAGE_RUNNING) { this.skip(); } | ||
}); | ||
|
||
after(async function () { | ||
await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0x1']); | ||
}); | ||
|
||
async function prepare() { | ||
const { contracts: { dai, weth }, accounts: { owner } } = await initContractsForSettlement(); | ||
const settlementExtension = await deployContract('SettlementExtension', [owner.address, weth.address]); | ||
const currentTime = (await time.latest()) - time.duration.minutes(1); | ||
|
||
const postInteractionData = ethers.utils.solidityPack( | ||
['uint8', 'uint32', 'bytes10', 'uint16'], | ||
[0, currentTime, '0x' + owner.address.substring(22), 0], | ||
); | ||
|
||
const order = buildOrder({ | ||
maker: owner.address, | ||
makerAsset: dai.address, | ||
takerAsset: weth.address, | ||
makingAmount: ether('10'), | ||
takingAmount: ether('1'), | ||
makerTraits: buildMakerTraits(), | ||
}, { | ||
postInteraction: settlementExtension.address + trim0x(postInteractionData), | ||
}); | ||
|
||
return { order, owner, postInteractionData, settlementExtension }; | ||
} | ||
|
||
function sendPostInteractionTxn(settlementExtension, order, owner, postInteractionData, maxPriorityFeePerGas) { | ||
return settlementExtension.postInteraction( | ||
order, '0x', constants.ZERO_BYTES32, owner.address, ether('10'), ether('1'), ether('10'), postInteractionData, | ||
{ maxPriorityFeePerGas }, | ||
); | ||
} | ||
|
||
it('8 gwei base, 4 gwei priority should work', async function () { | ||
const { order, owner, postInteractionData, settlementExtension } = await loadFixture(prepare); | ||
|
||
await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0x1dcd65000']); // 8 gwei | ||
|
||
await sendPostInteractionTxn(settlementExtension, order, owner, postInteractionData, 4000000000); | ||
}); | ||
|
||
it('8 gwei base, 6 gwei priority should not work', async function () { | ||
const { order, owner, postInteractionData, settlementExtension } = await loadFixture(prepare); | ||
|
||
await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0x1dcd65000']); // 8 gwei | ||
|
||
const postInteractionTxn = sendPostInteractionTxn(settlementExtension, order, owner, postInteractionData, 6000000000); | ||
await expect(postInteractionTxn).to.be.revertedWithCustomError(settlementExtension, 'InvalidPriorityFee'); | ||
}); | ||
|
||
it('50 gwei base, 25 gwei priority should work', async function () { | ||
const { order, owner, postInteractionData, settlementExtension } = await loadFixture(prepare); | ||
|
||
await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0xba43b7400']); // 50 gwei | ||
|
||
await sendPostInteractionTxn(settlementExtension, order, owner, postInteractionData, 25000000000); | ||
}); | ||
|
||
it('50 gwei base, 26 gwei priority should not work', async function () { | ||
const { order, owner, postInteractionData, settlementExtension } = await loadFixture(prepare); | ||
|
||
await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0xba43b7400']); // 50 gwei | ||
|
||
const postInteractionTxn = sendPostInteractionTxn(settlementExtension, order, owner, postInteractionData, 26000000000); | ||
await expect(postInteractionTxn).to.be.revertedWithCustomError(settlementExtension, 'InvalidPriorityFee'); | ||
}); | ||
|
||
it('150 gwei base, 90 gwei priority should work', async function () { | ||
const { order, owner, postInteractionData, settlementExtension } = await loadFixture(prepare); | ||
|
||
await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0x22ecb25c00']); // 150 gwei | ||
|
||
await sendPostInteractionTxn(settlementExtension, order, owner, postInteractionData, 90000000000); | ||
}); | ||
|
||
it('150 gwei base, 100 gwei priority should not work', async function () { | ||
const { order, owner, postInteractionData, settlementExtension } = await loadFixture(prepare); | ||
|
||
await network.provider.send('hardhat_setNextBlockBaseFeePerGas', ['0x22ecb25c00']); // 150 gwei | ||
|
||
const postInteractionTxn = sendPostInteractionTxn(settlementExtension, order, owner, postInteractionData, 100000000000); | ||
await expect(postInteractionTxn).to.be.revertedWithCustomError(settlementExtension, 'InvalidPriorityFee'); | ||
}); | ||
}); |