Skip to content
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

feat: accept initial platform-fee config in SWAP2 constructor #35

Merged
merged 1 commit into from
Jul 13, 2024
Merged
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
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