Skip to content

Commit

Permalink
Reduce contract bytecode size
Browse files Browse the repository at this point in the history
  • Loading branch information
corddry committed Nov 14, 2024
1 parent 3d5f5ef commit 91808ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
19 changes: 9 additions & 10 deletions src/WrappedVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,16 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {
}

/// @dev The max amount of reward campaigns a user can be involved in
uint256 public constant MAX_REWARDS = 20;
uint256 private constant MAX_REWARDS = 20;
/// @dev The minimum duration a reward campaign must last
uint256 public constant MIN_CAMPAIGN_DURATION = 1 weeks;
/// @dev The minimum lifespan of an extended campaign
uint256 public constant MIN_CAMPAIGN_EXTENSION = 1 weeks;
uint256 private constant MIN_CAMPAIGN_DURATION = 1 weeks;
/// @dev RewardsPerToken.accumulated is scaled up to prevent loss of incentives
uint256 public constant RPT_PRECISION = 1e27;
uint256 private constant RPT_PRECISION = 1e27;

/// @dev The address of the underlying vault being incentivized
IWrappedVault public immutable VAULT;
/// @dev The underlying asset being deposited into the vault
ERC20 internal immutable DEPOSIT_ASSET;
ERC20 private immutable DEPOSIT_ASSET;
/// @dev The address of the canonical points program factory
PointsFactory public immutable POINTS_FACTORY;
/// @dev The address of the canonical WrappedVault factory
Expand Down Expand Up @@ -217,10 +215,10 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {
}
}

/// @notice Extend the rewards interval for a given rewards campaign by adding more rewards
/// @notice Extend the rewards interval for a given rewards campaign by adding more rewards, must run for at least 1 more week
/// @param reward The reward token / points campaign to extend rewards for
/// @param rewardsAdded The amount of rewards to add to the campaign
/// @param newEnd The end date of the rewards campaign
/// @param newEnd The end date of the rewards campaign, must be more than 1 week after the updated campaign start
/// @param frontendFeeRecipient The address to reward for directing IP flow
function extendRewardsInterval(address reward, uint256 rewardsAdded, uint256 newEnd, address frontendFeeRecipient) external payable onlyOwner {
if (!isReward[reward]) revert InvalidReward();
Expand All @@ -241,7 +239,7 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {

uint32 newStart = block.timestamp > uint256(rewardsInterval.start) ? block.timestamp.toUint32() : rewardsInterval.start;

if ((newEnd - newStart) < MIN_CAMPAIGN_EXTENSION) revert InvalidIntervalDuration();
if ((newEnd - newStart) < MIN_CAMPAIGN_DURATION) revert InvalidIntervalDuration();

uint256 remainingRewards = rewardsInterval.rate * (rewardsInterval.end - newStart);
uint256 rate = (rewardsAdded - frontendFeeTaken - protocolFeeTaken + remainingRewards) / (newEnd - newStart);
Expand All @@ -259,9 +257,10 @@ contract WrappedVault is Owned, ERC20, IWrappedVault {
}

/// @dev Set a rewards schedule
/// @notice Starts a rewards schedule, must run for at least 1 week
/// @param reward The reward token or points program to set the interval for
/// @param start The start timestamp of the interval
/// @param end The end timestamp of the interval
/// @param end The end timestamp of the interval, interval must be more than 1 week long
/// @param totalRewards The amount of rewards to distribute over the interval
/// @param frontendFeeRecipient The address to reward the frontendFee
function setRewardsInterval(address reward, uint256 start, uint256 end, uint256 totalRewards, address frontendFeeRecipient) external payable onlyOwner {
Expand Down
8 changes: 4 additions & 4 deletions src/WrappedVaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ contract WrappedVaultFactory is Owned {
STORAGE
//////////////////////////////////////////////////////////////*/

uint256 public constant MAX_PROTOCOL_FEE = 0.3e18;
uint256 public constant MAX_MIN_REFERRAL_FEE = 0.3e18;
uint256 private constant MAX_PROTOCOL_FEE = 0.3e18;
uint256 private constant MAX_MIN_REFERRAL_FEE = 0.3e18;

address public immutable pointsFactory;

Expand Down Expand Up @@ -75,14 +75,14 @@ contract WrappedVaultFactory is Owned {
OWNER CONTROLS
//////////////////////////////////////////////////////////////*/

/// @param newProtocolFee The new protocol fee to set for a given vault
/// @param newProtocolFee The new protocol fee to set for a given vault, must be less than MAX_PROTOCOL_FEE
function updateProtocolFee(uint256 newProtocolFee) external payable onlyOwner {
if (newProtocolFee > MAX_PROTOCOL_FEE) revert ProtocolFeeTooHigh();
protocolFee = newProtocolFee;
emit ProtocolFeeUpdated(newProtocolFee);
}

/// @param newMinimumReferralFee The new minimum referral fee to set for all incentivized vaults
/// @param newMinimumReferralFee The new minimum referral fee to set for all incentivized vaults, must be less than MAX_MIN_REFERRAL_FEE
function updateMinimumReferralFee(uint256 newMinimumReferralFee) external payable onlyOwner {
if (newMinimumReferralFee > MAX_MIN_REFERRAL_FEE) revert ReferralFeeTooHigh();
minimumFrontendFee = newMinimumReferralFee;
Expand Down
12 changes: 6 additions & 6 deletions test/WrappedVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract WrappedVaultTest is Test {
vm.stopPrank();

vm.startPrank(testFactory.owner());
uint256 maxProtocolFee = testFactory.MAX_PROTOCOL_FEE();
uint256 maxProtocolFee = /*testFactory.MAX_PROTOCOL_FEE()*/ 0.3e18;
vm.expectRevert(WrappedVaultFactory.ProtocolFeeTooHigh.selector);
testFactory.updateProtocolFee(maxProtocolFee + 1);

Expand All @@ -77,7 +77,7 @@ contract WrappedVaultTest is Test {
vm.stopPrank();

vm.startPrank(testFactory.owner());
uint256 maxMinFee = testFactory.MAX_MIN_REFERRAL_FEE();
uint256 maxMinFee = /*testFactory.MAX_MIN_REFERRAL_FEE()*/ 0.3e18;
vm.expectRevert(WrappedVaultFactory.ReferralFeeTooHigh.selector);
testFactory.updateMinimumReferralFee(maxMinFee + 1);

Expand Down Expand Up @@ -126,7 +126,7 @@ contract WrappedVaultTest is Test {
}

function testAddRewardTokenMaxReached() public {
for (uint256 i = 0; i < testIncentivizedVault.MAX_REWARDS(); i++) {
for (uint256 i = 0; i < 20 /*testIncentivizedVault.MAX_REWARDS()*/; i++) {
testIncentivizedVault.addRewardsToken(address(new MockERC20("", "")));
}

Expand All @@ -148,7 +148,7 @@ contract WrappedVaultTest is Test {
}

function testSetRewardsInterval(uint32 start, uint32 duration, uint256 totalRewards) public {
vm.assume(duration >= testIncentivizedVault.MIN_CAMPAIGN_DURATION());
vm.assume(duration >= /*testIncentivizedVault.MIN_CAMPAIGN_DURATION_OR_EXTENSION()*/1 weeks);
vm.assume(duration <= type(uint32).max - start); //If this is not here, then 'end' variable will overflow
vm.assume(totalRewards > 0 && totalRewards < type(uint96).max);
vm.assume(totalRewards / duration > 1e6);
Expand Down Expand Up @@ -179,7 +179,7 @@ contract WrappedVaultTest is Test {
uint256 remainingSpace = type(uint32).max - start;

// Get the minimum campaign duration
uint256 minCampaignDuration = testIncentivizedVault.MIN_CAMPAIGN_DURATION();
uint256 minCampaignDuration = /*testIncentivizedVault.MIN_CAMPAIGN_DURATION_OR_EXTENSION()*/ 1 weeks;

// Ensure there is enough remaining space for the initial duration
if (remainingSpace < minCampaignDuration) {
Expand Down Expand Up @@ -298,7 +298,7 @@ contract WrappedVaultTest is Test {
start = uint32(block.timestamp + 10_000);
}

vm.assume(duration >= testIncentivizedVault.MIN_CAMPAIGN_DURATION());
vm.assume(duration >= /*testIncentivizedVault.MIN_CAMPAIGN_DURATION_OR_EXTENSION()*/ 1 weeks);
vm.assume(duration <= type(uint32).max - start); //If this is not here, then 'end' variable will overflow
vm.assume(totalRewards > 0 && totalRewards < type(uint96).max);
vm.assume(totalRewards / duration > 1e6);
Expand Down

0 comments on commit 91808ad

Please sign in to comment.