From 062b8e268507633850c2f9db60a4ed73ed413d05 Mon Sep 17 00:00:00 2001 From: Arran Schlosberg Date: Sat, 13 Jul 2024 17:07:37 +0100 Subject: [PATCH] feat: accept initial platform-fee config in `SWAP2` constructor --- src/SWAP2.sol | 13 +++++++++++-- test/Owner.t.sol | 4 ++-- test/SwapperTestBase.t.sol | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/SWAP2.sol b/src/SWAP2.sol index 172d300..78a91d8 100644 --- a/src/SWAP2.sol +++ b/src/SWAP2.sol @@ -38,8 +38,11 @@ contract SWAP2Deployer is * @param initialOwner Initial owner of the contract. SHOULD be a multisig as this address can modify platform-fee * configuration. */ - constructor(address initialOwner, Escrow escrow_) Ownable(initialOwner) { + constructor(address initialOwner, Escrow escrow_, address payable feeRecipient, uint16 feeBasisPoints) + Ownable(initialOwner) + { escrow = escrow_; + _setPlatformFee(feeRecipient, feeBasisPoints); } /// @dev Packs platform-fee configuration into a single word. @@ -60,6 +63,10 @@ contract SWAP2Deployer is * @param basisPoints One-hundredths of a percentage point of swap consideration to charge as a platform fee. */ function setPlatformFee(address payable recipient, uint16 basisPoints) external onlyOwner { + _setPlatformFee(recipient, basisPoints); + } + + function _setPlatformFee(address payable recipient, uint16 basisPoints) private { feeConfig = PlatformFeeConfig({recipient: recipient, basisPoints: basisPoints}); } @@ -103,7 +110,9 @@ contract SWAP2Proposer is SWAP2ProposerBase { /// @notice A combined SWAP2{Deployer,Proposer}. contract SWAP2 is SWAP2Deployer, SWAP2ProposerBase { - constructor(address initialOwner, Escrow escrow) SWAP2Deployer(initialOwner, escrow) {} + constructor(address initialOwner, Escrow escrow, address payable feeRecipient, uint16 feeBasisPoints) + SWAP2Deployer(initialOwner, escrow, feeRecipient, feeBasisPoints) + {} /// @dev The current contract is the swapper deployer for all types. function _swapperDeployer() internal view override returns (address) { diff --git a/test/Owner.t.sol b/test/Owner.t.sol index 3145ee3..01da05e 100644 --- a/test/Owner.t.sol +++ b/test/Owner.t.sol @@ -15,7 +15,7 @@ contract OwnerTest is Test { vm.assume(initial != address(0)); vm.assume(newOwner != address(0)); - SWAP2 s = new SWAP2(initial, new Escrow()); + SWAP2 s = new SWAP2(initial, new Escrow(), payable(0), 0); vm.prank(initial); s.transferOwnership(newOwner); @@ -34,7 +34,7 @@ contract OwnerTest is Test { vm.assume(owner != address(0)); vm.assume(owner != vandal); - SWAP2 s = new SWAP2(owner, new Escrow()); + SWAP2 s = new SWAP2(owner, new Escrow(), payable(0), 0); vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, vandal)); vm.prank(vandal); diff --git a/test/SwapperTestBase.t.sol b/test/SwapperTestBase.t.sol index 4e49e56..fc2b385 100644 --- a/test/SwapperTestBase.t.sol +++ b/test/SwapperTestBase.t.sol @@ -70,7 +70,7 @@ abstract contract SwapperTestBase is Test, ITestEvents { address immutable owner = makeAddr("owner"); function setUp() public virtual { - factory = new SWAP2(owner, new Escrow()); + factory = new SWAP2(owner, new Escrow(), payable(0), 0); vm.label(address(factory), "SWAP2"); token = new Token(); vm.label(address(token), "FakeERC721");