From 04181361811c1721f4584066831e9818569c8049 Mon Sep 17 00:00:00 2001 From: neokry Date: Tue, 31 Oct 2023 13:38:16 +0700 Subject: [PATCH] Fix protocol rewards optionality --- addresses/84531.json | 18 ++++++------ deploys/84531.version2_core.txt | 14 ++++----- deploys/84531.version2_new.txt | 4 +-- src/auction/Auction.sol | 36 +++++++++++++++--------- test/utils/mocks/MockProtocolRewards.sol | 18 +++++++++++- 5 files changed, 58 insertions(+), 32 deletions(-) diff --git a/addresses/84531.json b/addresses/84531.json index 0aabe33..aa197c7 100644 --- a/addresses/84531.json +++ b/addresses/84531.json @@ -3,13 +3,13 @@ "WETH": "0x4200000000000000000000000000000000000006", "CrossDomainMessenger": "0x4200000000000000000000000000000000000007", "ProtocolRewards": "0x7777777F279eba3d3Ad8F4E708545291A6fDBA8B", - "Manager": "0x2177ab5b03866ca31b5acd0b837d7fd54c7d2936", - "ManagerImpl": "0x7d09fcd78ded047e112060f66ce4d4ec7c59e0be", - "Auction": "0xc7f35eb5896aa32b4decbe7768c903db43a20044", - "Token": "0x209452d7b38a36b042967ab0d9c6366ae1242dca", - "MetadataRenderer": "0x4238d016947087d21e9959c628688b6b5a527adc", - "Treasury": "0x23cbb0637dfe7eec42202c885cbfe76c09c7c759", - "Governor": "0x11e646c27529af1a18e6977d909be90d0cf504f5", - "MerkleReserveMinter": "0x1991abb6d9613ae4e339a1a747a894201d5e4dae", - "MigrationDeployer": "0xfad4bd5777fb472609f97fcde9fb001f5c0dd506" + "Manager": "0x58cc1c84f1176cb1b05d1c3e63eafbbc10019efb", + "ManagerImpl": "0x2c3b472e6f7bafa4f1bd3c5728388e1c046a3a73", + "Auction": "0xe46bce14dc5fcdca8628cc4b78bda75aef6717fe", + "Token": "0x8fdc5959e45567e1e4ec96cc1119e36d2e54bc0c", + "MetadataRenderer": "0xdcfcd6df2500b919e16ccae3366b765f6573dc25", + "Treasury": "0x06dfa84ea3867211670cfae7f2cff4aeb5fdf176", + "Governor": "0x22c95521d0850aa09078de7d5826faf3dbd638a6", + "MerkleReserveMinter": "0x8dfa3bc1683c8ad8ef34eabfd39bc733a1df5395", + "MigrationDeployer": "0x01e2d618d5752f99047ba611ad35d9f8a9cc85bf" } diff --git a/deploys/84531.version2_core.txt b/deploys/84531.version2_core.txt index 62f64ad..5ab396f 100644 --- a/deploys/84531.version2_core.txt +++ b/deploys/84531.version2_core.txt @@ -1,7 +1,7 @@ -Manager: 0x2177ab5b03866ca31b5acd0b837d7fd54c7d2936 -Token implementation: 0x209452d7b38a36b042967ab0d9c6366ae1242dca -Metadata Renderer implementation: 0x4238d016947087d21e9959c628688b6b5a527adc -Auction implementation: 0xc7f35eb5896aa32b4decbe7768c903db43a20044 -Treasury implementation: 0x23cbb0637dfe7eec42202c885cbfe76c09c7c759 -Governor implementation: 0x11e646c27529af1a18e6977d909be90d0cf504f5 -Manager implementation: 0x7d09fcd78ded047e112060f66ce4d4ec7c59e0be +Manager: 0x58cc1c84f1176cb1b05d1c3e63eafbbc10019efb +Token implementation: 0x8fdc5959e45567e1e4ec96cc1119e36d2e54bc0c +Metadata Renderer implementation: 0xdcfcd6df2500b919e16ccae3366b765f6573dc25 +Auction implementation: 0xe46bce14dc5fcdca8628cc4b78bda75aef6717fe +Treasury implementation: 0x06dfa84ea3867211670cfae7f2cff4aeb5fdf176 +Governor implementation: 0x22c95521d0850aa09078de7d5826faf3dbd638a6 +Manager implementation: 0x2c3b472e6f7bafa4f1bd3c5728388e1c046a3a73 diff --git a/deploys/84531.version2_new.txt b/deploys/84531.version2_new.txt index 793e3d2..0dbe807 100644 --- a/deploys/84531.version2_new.txt +++ b/deploys/84531.version2_new.txt @@ -1,2 +1,2 @@ -Merkle Reserve Minter: 0x1991abb6d9613ae4e339a1a747a894201d5e4dae -Migration Deployer: 0xfad4bd5777fb472609f97fcde9fb001f5c0dd506 +Merkle Reserve Minter: 0x8dfa3bc1683c8ad8ef34eabfd39bc733a1df5395 +Migration Deployer: 0x01e2d618d5752f99047ba611ad35d9f8a9cc85bf diff --git a/src/auction/Auction.sol b/src/auction/Auction.sol index 6da44de..f3b1d63 100644 --- a/src/auction/Auction.sol +++ b/src/auction/Auction.sol @@ -55,10 +55,10 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard, IProtocolRewards private immutable rewardsManager; /// @notice The builder reward BPS as a percent of settled auction amount - uint16 private immutable builderRewardsBPS; + uint16 public immutable builderRewardsBPS; /// @notice The referral reward BPS as a percent of settled auction amount - uint16 private immutable referralRewardsBPS; + uint16 public immutable referralRewardsBPS; /// /// /// CONSTRUCTOR /// @@ -481,20 +481,30 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard, // Calulate total rewards split.totalRewards = (_finalBidAmount * totalBPS) / BPS_PER_100_PERCENT; - // Set the recipients - split.recipients = new address[](3); - split.recipients[0] = founderReward.recipient; - split.recipients[1] = _currentBidRefferal != address(0) ? _currentBidRefferal : builderRecipient; - split.recipients[2] = builderRecipient; + // Check if founder reward is enabled + bool hasFounderReward = _founderRewardBps > 0 && founderReward.recipient != address(0); + + // Set array size based on if founder reward is enabled + uint256 arraySize = hasFounderReward ? 3 : 2; + + // Initialize arrays + split.recipients = new address[](arraySize); + split.amounts = new uint256[](arraySize); + split.reasons = new bytes4[](arraySize); - // Calculate reward splits - split.amounts = new uint256[](3); - split.amounts[0] = (_finalBidAmount * _founderRewardBps) / BPS_PER_100_PERCENT; + // Set builder reward + split.recipients[0] = builderRecipient; + split.amounts[0] = (_finalBidAmount * builderRewardsBPS) / BPS_PER_100_PERCENT; + + // Set referral reward + split.recipients[1] = _currentBidRefferal != address(0) ? _currentBidRefferal : builderRecipient; split.amounts[1] = (_finalBidAmount * referralRewardsBPS) / BPS_PER_100_PERCENT; - split.amounts[2] = (_finalBidAmount * builderRewardsBPS) / BPS_PER_100_PERCENT; - // Leave reasons empty - split.reasons = new bytes4[](3); + // Set founder reward if enabled + if (hasFounderReward) { + split.recipients[2] = founderReward.recipient; + split.amounts[2] = (_finalBidAmount * _founderRewardBps) / BPS_PER_100_PERCENT; + } } /// /// diff --git a/test/utils/mocks/MockProtocolRewards.sol b/test/utils/mocks/MockProtocolRewards.sol index a21da7d..8e16dfe 100644 --- a/test/utils/mocks/MockProtocolRewards.sol +++ b/test/utils/mocks/MockProtocolRewards.sol @@ -4,6 +4,10 @@ pragma solidity 0.8.16; /// @title ProtocolRewards /// @notice Manager of deposits & withdrawals for protocol rewards contract MockProtocolRewards { + error ADDRESS_ZERO(); + error ARRAY_LENGTH_MISMATCH(); + error INVALID_DEPOSIT(); + /// @notice An account's balance mapping(address => uint256) public balanceOf; @@ -26,11 +30,15 @@ contract MockProtocolRewards { function depositBatch( address[] calldata recipients, uint256[] calldata amounts, - bytes4[] calldata, + bytes4[] calldata reasons, string calldata ) external payable { uint256 numRecipients = recipients.length; + if (numRecipients != amounts.length || numRecipients != reasons.length) { + revert ARRAY_LENGTH_MISMATCH(); + } + uint256 expectedTotalValue; for (uint256 i; i < numRecipients; ) { @@ -41,6 +49,10 @@ contract MockProtocolRewards { } } + if (msg.value != expectedTotalValue) { + revert INVALID_DEPOSIT(); + } + address currentRecipient; uint256 currentAmount; @@ -48,6 +60,10 @@ contract MockProtocolRewards { currentRecipient = recipients[i]; currentAmount = amounts[i]; + if (currentRecipient == address(0)) { + revert ADDRESS_ZERO(); + } + balanceOf[currentRecipient] += currentAmount; unchecked {