Skip to content

Commit

Permalink
feat: accept initial platform-fee config in SWAP2 constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR4N committed Jul 13, 2024
1 parent 2b95e51 commit 062b8e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/SWAP2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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});
}

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/Owner.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/SwapperTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 062b8e2

Please sign in to comment.