Skip to content

Commit

Permalink
Use accessToken instead of nft
Browse files Browse the repository at this point in the history
  • Loading branch information
zZoMROT committed Jun 19, 2024
1 parent 2ee241b commit 35e6743
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions contracts/Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { SimpleSettlement } from "./SimpleSettlement.sol";
contract Settlement is SimpleSettlement {
error InvalidPriorityFee();

constructor(address limitOrderProtocol, IERC20 feeToken, IERC20 nft, address weth, address owner)
SimpleSettlement(limitOrderProtocol, feeToken, nft, weth, owner)
constructor(address limitOrderProtocol, IERC20 feeToken, IERC20 accessToken, address weth, address owner)
SimpleSettlement(limitOrderProtocol, feeToken, accessToken, weth, owner)
{}

function _postInteraction(
Expand Down
6 changes: 3 additions & 3 deletions contracts/SimpleSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ contract SimpleSettlement is ResolverValidationExtension, IntegratorFeeExtension
* @notice Initializes the contract.
* @param limitOrderProtocol The limit order protocol contract.
* @param feeToken The token to charge protocol fees in.
* @param nft The NFT contract address whose tokens allow filling limit orders with a fee for resolvers that are outside the whitelist.
* @param accessToken Contract address whose tokens allow filling limit orders with a fee for resolvers that are outside the whitelist.
* @param weth The WETH address.
* @param owner The owner of the contract.
*/
constructor(address limitOrderProtocol, IERC20 feeToken, IERC20 nft, address weth, address owner)
constructor(address limitOrderProtocol, IERC20 feeToken, IERC20 accessToken, address weth, address owner)
BaseExtension(limitOrderProtocol)
ResolverValidationExtension(feeToken, nft, owner)
ResolverValidationExtension(feeToken, accessToken, owner)
IntegratorFeeExtension(weth)
Ownable(owner)
{}
Expand Down
12 changes: 6 additions & 6 deletions contracts/extensions/ResolverValidationExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ExtensionLib } from "./ExtensionLib.sol";
/**
* @title Resolver Validation Extension
* @notice This abstract contract combines functionalities to enhance security and compliance in the order execution process.
* Ensures that only transactions from whitelisted resolvers or resolvers who own specific NFT tokens are processed within the post-interaction phase of order execution.
* Ensures that only transactions from whitelisted resolvers or resolvers who own specific accessToken are processed within the post-interaction phase of order execution.
* Additionally, it allows charging a fee to resolvers in the `postInteraction` method, providing a mechanism for resolver fee management.
*/
abstract contract ResolverValidationExtension is BaseExtension, FeeBankCharger {
Expand All @@ -20,11 +20,11 @@ abstract contract ResolverValidationExtension is BaseExtension, FeeBankCharger {
error ResolverCanNotFillOrder();

uint256 private constant _ORDER_FEE_BASE_POINTS = 1e15;
/// @notice NFT contract address whose tokens allow filling limit orders with a fee for resolvers that are outside the whitelist
IERC20 private immutable _NFT;
/// @notice Contract address whose tokens allow filling limit orders with a fee for resolvers that are outside the whitelist
IERC20 private immutable _ACCESS_TOKEN;

constructor(IERC20 feeToken, IERC20 nft, address owner) FeeBankCharger(feeToken, owner) {
_NFT = nft;
constructor(IERC20 feeToken, IERC20 accessToken, address owner) FeeBankCharger(feeToken, owner) {
_ACCESS_TOKEN = accessToken;
}

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ abstract contract ResolverValidationExtension is BaseExtension, FeeBankCharger {
unchecked {
uint256 whitelistSize = 4 + resolversCount * 12;
if (!_isWhitelisted(extraData[4:4+whitelistSize], resolversCount, taker)) {
if (_NFT.balanceOf(taker) == 0) revert ResolverCanNotFillOrder();
if (_ACCESS_TOKEN.balanceOf(taker) == 0) revert ResolverCanNotFillOrder();
if (extraData.resolverFeeEnabled()) {
uint256 resolverFee = _getResolverFee(uint256(uint32(bytes4(extraData[:4]))), order.makingAmount, makingAmount);
_chargeFee(taker, resolverFee);
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/SettlementMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Settlement } from "../Settlement.sol";

contract SettlementMock is Settlement {
constructor(address limitOrderProtocol, IERC20 token, IERC20 nft, address weth)
Settlement(limitOrderProtocol, token, nft, weth, msg.sender)
constructor(address limitOrderProtocol, IERC20 token, IERC20 accessToken, address weth)
Settlement(limitOrderProtocol, token, accessToken, weth, msg.sender)
{}

function decreaseAvailableCreditMock(address account, uint256 amount) external {
Expand Down
10 changes: 5 additions & 5 deletions test/MeasureGas.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ describe('MeasureGas', function () {
const [owner, alice] = await ethers.getSigners();
const chainId = await getChainId();
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
const { dai, weth, inch, nft, lopv3, lopv4 } = await deploySwapTokens();
const { dai, weth, inch, accessToken, lopv3, lopv4 } = await deploySwapTokens();

await dai.transfer(alice, ether('100'));
await inch.mint(owner, ether('100'));
await weth.deposit({ value: ether('1') });
await weth.connect(alice).deposit({ value: ether('1') });

const settlementExtension = await deployContract('Settlement', [lopv4, inch, nft, weth, owner]);
const settlementExtension = await deployContract('Settlement', [lopv4, inch, accessToken, weth, owner]);
const SettlementV1 = JSON.parse(fs.readFileSync(path.join(__dirname, '../artifacts-v1/SettlementV1.json'), 'utf8'));
// const settlement = await deployContract(SettlementV1.abi, [lopv3.address, inch.address]);
const ContractFactory = await ethers.getContractFactory(SettlementV1.abi, SettlementV1.bytecode);
Expand All @@ -50,7 +50,7 @@ describe('MeasureGas', function () {
await resolver.approve(weth, lopv4);

return {
contracts: { dai, weth, nft, lopv3, lopv4, settlement, settlementExtension, feeBank, resolversV1, resolver },
contracts: { dai, weth, accessToken, lopv3, lopv4, settlement, settlementExtension, feeBank, resolversV1, resolver },
accounts: { owner, alice },
others: { chainId, abiCoder },
};
Expand Down Expand Up @@ -227,8 +227,8 @@ describe('MeasureGas', function () {

describe('Extension check', function () {
it('post interaction', async function () {
const { contracts: { dai, weth, nft }, accounts: { owner } } = await loadFixture(initContractsAndApproves);
const settlementExtension = await deployContract('Settlement', [owner, weth, nft, weth, owner]);
const { contracts: { dai, weth, accessToken }, accounts: { owner } } = await loadFixture(initContractsAndApproves);
const settlementExtension = await deployContract('Settlement', [owner, weth, accessToken, weth, owner]);
const currentTime = (await time.latest()) - time.duration.minutes(1);

const postInteractionData = ethers.solidityPacked(
Expand Down
4 changes: 2 additions & 2 deletions test/PriorityFeeLimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('PriorityFeeLimiter', function () {
});

async function prepare() {
const { contracts: { dai, weth, nft }, accounts: { owner } } = await initContractsForSettlement();
const settlementExtension = await deployContract('Settlement', [owner, weth, nft, weth, owner]);
const { contracts: { dai, weth, accessToken }, accounts: { owner } } = await initContractsForSettlement();
const settlementExtension = await deployContract('Settlement', [owner, weth, accessToken, weth, owner]);
const currentTime = (await time.latest()) - time.duration.minutes(1);

const postInteractionData = ethers.solidityPacked(
Expand Down
20 changes: 10 additions & 10 deletions test/Settlement.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ describe('Settlement', function () {
);
});

it('should not pay resolver fee when whitelisted address and it has nft', async function () {
it('should not pay resolver fee when whitelisted address and it has accessToken', async function () {
const dataFormFixture = await loadFixture(initContractsForSettlement);
const auction = await buildAuctionDetails();
const setupData = { ...dataFormFixture, auction };
Expand Down Expand Up @@ -963,12 +963,12 @@ describe('Settlement', function () {
expect(await settlement.availableCredit(resolver)).to.equal(availableCreditBefore);
});

it('should not pay resolver fee when whitelisted address and it has not nft', async function () {
it('should not pay resolver fee when whitelisted address and it has not accessToken', async function () {
const dataFormFixture = await loadFixture(initContractsForSettlement);
const auction = await buildAuctionDetails();
const setupData = { ...dataFormFixture, auction };
const {
contracts: { dai, weth, nft, resolver, settlement },
contracts: { dai, weth, accessToken, resolver, settlement },
accounts: { alice },
} = setupData;

Expand All @@ -990,7 +990,7 @@ describe('Settlement', function () {
resolverFee: ORDER_FEE,
});

await nft.burn(resolver, 1);
await accessToken.burn(resolver, 1);

const availableCreditBefore = await settlement.availableCredit(resolver);
const txn = await resolver.settleOrders(fillOrderToData);
Expand All @@ -1000,7 +1000,7 @@ describe('Settlement', function () {
expect(await settlement.availableCredit(resolver)).to.equal(availableCreditBefore);
});

it('should pay resolver fee when non-whitelisted address and it has nft', async function () {
it('should pay resolver fee when non-whitelisted address and it has accessToken', async function () {
const dataFormFixture = await loadFixture(initContractsForSettlement);
const auction = await buildAuctionDetails();
const setupData = { ...dataFormFixture, auction };
Expand Down Expand Up @@ -1038,12 +1038,12 @@ describe('Settlement', function () {
);
});

it('should revert when non-whitelisted address and it has not nft', async function () {
it('should revert when non-whitelisted address and it has not accessToken', async function () {
const dataFormFixture = await loadFixture(initContractsForSettlement);
const auction = await buildAuctionDetails();
const setupData = { ...dataFormFixture, auction };
const {
contracts: { dai, weth, nft, resolver },
contracts: { dai, weth, accessToken, resolver },
accounts: { alice },
} = setupData;

Expand All @@ -1066,7 +1066,7 @@ describe('Settlement', function () {
whitelistData: '0x' + constants.ZERO_ADDRESS.substring(22),
});

await nft.burn(resolver, 1);
await accessToken.burn(resolver, 1);
await expect(resolver.settleOrders(fillOrderToData)).to.be.revertedWithCustomError(
dataFormFixture.contracts.settlement, 'ResolverCanNotFillOrder',
);
Expand All @@ -1078,7 +1078,7 @@ describe('Settlement', function () {
const auction = await buildAuctionDetails({ startTime: await time.latest() + time.duration.hours('3') });
const setupData = { ...dataFormFixture, auction };
const {
contracts: { dai, weth, nft, resolver },
contracts: { dai, weth, accessToken, resolver },
accounts: { owner, alice },
} = setupData;

Expand Down Expand Up @@ -1112,7 +1112,7 @@ describe('Settlement', function () {
additionalDataForSettlement: fillOrderToData1,
});

await nft.burn(resolver, 1);
await accessToken.burn(resolver, 1);

await expect(resolver.settleOrders(fillOrderToData0)).to.be.revertedWithCustomError(
setupData.contracts.settlement, 'ResolverCanNotFillOrder',
Expand Down
14 changes: 7 additions & 7 deletions test/WhitelistChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const { initContractsForSettlement } = require('./helpers/fixtures');
const { buildAuctionDetails, buildCalldataForOrder } = require('./helpers/fusionUtils');

describe('WhitelistChecker', function () {
describe('should not work with non-whitelisted address without nft', function () {
describe('should not work with non-whitelisted address without accessToken', function () {
it('whitelist check in postInteraction method', async function () {
const dataFormFixture = await loadFixture(initContractsForSettlement);
const auction = await buildAuctionDetails();
const setupData = { ...dataFormFixture, auction };
const {
contracts: { dai, weth, nft, resolver },
contracts: { dai, weth, accessToken, resolver },
accounts: { alice },
} = setupData;

Expand All @@ -34,7 +34,7 @@ describe('WhitelistChecker', function () {
whitelistData: '0x' + constants.ZERO_ADDRESS.substring(22),
});

await nft.burn(resolver, 1);
await accessToken.burn(resolver, 1);
await expect(resolver.settleOrders(fillOrderToData)).to.be.revertedWithCustomError(
dataFormFixture.contracts.settlement, 'ResolverCanNotFillOrder',
);
Expand Down Expand Up @@ -93,13 +93,13 @@ describe('WhitelistChecker', function () {
});
});

describe('should work with whitelisted address without nft', function () {
describe('should work with whitelisted address without accessToken', function () {
it('whitelist check in settleOrders method', async function () {
const dataFormFixture = await loadFixture(initContractsForSettlement);
const auction = await buildAuctionDetails();
const setupData = { ...dataFormFixture, auction };
const {
contracts: { dai, weth, nft, resolver },
contracts: { dai, weth, accessToken, resolver },
accounts: { alice },
} = setupData;

Expand All @@ -121,14 +121,14 @@ describe('WhitelistChecker', function () {
whitelistData: '0x' + resolver.target.substring(22),
});

await nft.burn(resolver, 1);
await accessToken.burn(resolver, 1);
const txn = await resolver.settleOrders(fillOrderToData);
await expect(txn).to.changeTokenBalances(dai, [alice, resolver], [ether('-100'), ether('100')]);
await expect(txn).to.changeTokenBalances(weth, [alice, resolver], [ether('0.1'), ether('-0.1')]);
});
});

describe('should work with non-whitelisted address with nft', function () {
describe('should work with non-whitelisted address with accessToken', function () {
it('whitelist check in settleOrders method', async function () {
const dataFormFixture = await loadFixture(initContractsForSettlement);
const auction = await buildAuctionDetails();
Expand Down
14 changes: 7 additions & 7 deletions test/helpers/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ async function deploySwapTokens() {
const dai = await deployContract('ERC20PermitMock', ['DAI', 'DAI', account, ether('1000')]);
const weth = await deployContract('WrappedTokenMock', ['WETH', 'WETH']);
const inch = await deployContract('TokenMock', ['1INCH', '1INCH']);
const nft = await deployContract('TokenMock', ['NFT', 'NFT']);
const accessToken = await deployContract('TokenMock', ['NFT', 'NFT']);
const lopv4 = await deployContract('LimitOrderProtocol', [weth]);

const LimitOrderProtocolV3 = JSON.parse(fs.readFileSync(path.join(__dirname, '../../artifacts-v1/LimitOrderProtocolV3.json'), 'utf8'));
const ContractFactory = await ethers.getContractFactory(LimitOrderProtocolV3.abi, LimitOrderProtocolV3.bytecode);
const lopv3 = await ContractFactory.deploy(weth);

return { dai, weth, inch, nft, lopv3, lopv4 };
return { dai, weth, inch, accessToken, lopv3, lopv4 };
}

async function initContractsForSettlement() {
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
const chainId = await getChainId();
const [owner, alice, bob] = await ethers.getSigners();

const { dai, weth, inch, nft, lopv4 } = await deploySwapTokens();
const { dai, weth, inch, accessToken, lopv4 } = await deploySwapTokens();

await dai.transfer(alice, ether('101'));
await inch.mint(owner, ether('100'));
await weth.deposit({ value: ether('1') });
await weth.connect(alice).deposit({ value: ether('1') });

const settlement = await deployContract('SettlementMock', [lopv4, inch, nft, weth]);
const settlement = await deployContract('SettlementMock', [lopv4, inch, accessToken, weth]);

const FeeBank = await ethers.getContractFactory('FeeBank');
const feeBank = FeeBank.attach(await settlement.FEE_BANK());
Expand All @@ -53,11 +53,11 @@ async function initContractsForSettlement() {
await resolver.approve(dai, lopv4);
await resolver.approve(weth, lopv4);

await nft.mint(resolver, 1);
await nft.mint(owner, 1);
await accessToken.mint(resolver, 1);
await accessToken.mint(owner, 1);

return {
contracts: { dai, weth, nft, lopv4, settlement, feeBank, resolver },
contracts: { dai, weth, accessToken, lopv4, settlement, feeBank, resolver },
accounts: { owner, alice, bob },
others: { chainId, abiCoder },
};
Expand Down

0 comments on commit 35e6743

Please sign in to comment.