Skip to content

Commit

Permalink
Fix protocol rewards optionality
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Oct 31, 2023
1 parent 3284e1c commit 0418136
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 32 deletions.
18 changes: 9 additions & 9 deletions addresses/84531.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
14 changes: 7 additions & 7 deletions deploys/84531.version2_core.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions deploys/84531.version2_new.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Merkle Reserve Minter: 0x1991abb6d9613ae4e339a1a747a894201d5e4dae
Migration Deployer: 0xfad4bd5777fb472609f97fcde9fb001f5c0dd506
Merkle Reserve Minter: 0x8dfa3bc1683c8ad8ef34eabfd39bc733a1df5395
Migration Deployer: 0x01e2d618d5752f99047ba611ad35d9f8a9cc85bf
36 changes: 23 additions & 13 deletions src/auction/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 ///
Expand Down Expand Up @@ -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;
}
}

/// ///
Expand Down
18 changes: 17 additions & 1 deletion test/utils/mocks/MockProtocolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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; ) {
Expand All @@ -41,13 +49,21 @@ contract MockProtocolRewards {
}
}

if (msg.value != expectedTotalValue) {
revert INVALID_DEPOSIT();
}

address currentRecipient;
uint256 currentAmount;

for (uint256 i; i < numRecipients; ) {
currentRecipient = recipients[i];
currentAmount = amounts[i];

if (currentRecipient == address(0)) {
revert ADDRESS_ZERO();
}

balanceOf[currentRecipient] += currentAmount;

unchecked {
Expand Down

0 comments on commit 0418136

Please sign in to comment.