Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/facets/DiamondManagerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ contract DiamondManagerFacet {
s.isSeasonClaimed[s.currentSeasonId] = true;
}

function setRewardControllerAddress(address _rewardsControllerAddress) external onlyOwner {
if (_rewardsControllerAddress == address(0)) {
revert DiamondManagerFacet__Invalid_Address();
}
s.rewardsControllerAddress = _rewardsControllerAddress;
emit RewardsControllerAddressSet(_rewardsControllerAddress);
}

// Getters

function getRewardTokenToDistribute(uint256 _seasonId) external view returns (uint256) {
Expand Down Expand Up @@ -364,4 +372,8 @@ contract DiamondManagerFacet {
function getSeasonIsClaimed(uint256 seasonId) external view returns (bool) {
return s.isSeasonClaimed[seasonId];
}

function getUnlockDiscount(uint256 tier) external view returns (uint256) {
return s.unlockTimestampDiscountForStratosphereMembers[tier];
}
}
6 changes: 6 additions & 0 deletions src/interfaces/IRewardsController.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

interface IRewardsController {
function tierOf(uint256 tokenId) external view returns (uint8);
}
2 changes: 0 additions & 2 deletions src/interfaces/IStratosphere.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ pragma solidity 0.8.18;

interface IStratosphere {
function tokenIdOf(address account) external view returns (uint256);

function tierOf(uint256 tokenId) external view returns (uint8);
}
4 changes: 4 additions & 0 deletions src/libraries/AppStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ struct AppStorage {
//////////////////
address gelatoExecutor;
mapping(uint256 => bool) isSeasonClaimed;
//////////////////////////
/// REWARDS CONTROLLER ///
//////////////////////////
address rewardsControllerAddress;
}
5 changes: 4 additions & 1 deletion src/libraries/LStratosphere.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.18;

import { AppStorage } from "./AppStorage.sol";
import { IStratosphere } from "../interfaces/IStratosphere.sol";
import { IRewardsController } from "../interfaces/IRewardsController.sol";

/// @title LStratosphere
/// @notice Library in charge of Stratosphere related logic
Expand All @@ -22,9 +23,11 @@ library LStratosphere {
) internal view returns (bool isStratosphereMember, uint8 tier) {
IStratosphere _stratosphere = IStratosphere(s.stratosphereAddress);
uint256 _tokenId = _stratosphere.tokenIdOf(_address);

if (_tokenId > 0) {
isStratosphereMember = true;
tier = 0;
IRewardsController _rewardsController = IRewardsController(s.rewardsControllerAddress);
Comment thread
royvardhan marked this conversation as resolved.
tier = _rewardsController.tierOf(_tokenId); // Revert if rewardsControllerAddress is not set
Comment on lines +29 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Issue: Ensure rewardsControllerAddress is correctly initialized.

The code now depends on rewardsControllerAddress being properly set. If this address is not correctly initialized, the call to tierOf will fail and revert the transaction. Consider adding a check to ensure that rewardsControllerAddress is not zero before making the call.

- tier = _rewardsController.tierOf(_tokenId); // Revert if rewardsControllerAddress is not set
+ if (s.rewardsControllerAddress == address(0)) revert("RewardsController address not set");
+ tier = _rewardsController.tierOf(_tokenId);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
IRewardsController _rewardsController = IRewardsController(s.rewardsControllerAddress);
tier = _rewardsController.tierOf(_tokenId); // Revert if rewardsControllerAddress is not set
IRewardsController _rewardsController = IRewardsController(s.rewardsControllerAddress);
if (s.rewardsControllerAddress == address(0)) revert("RewardsController address not set");
tier = _rewardsController.tierOf(_tokenId);

}
}
}
15 changes: 10 additions & 5 deletions src/upgradeInitializers/DiamondInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract DiamondInit {
address replenishmentPool;
address labsMultisig;
address burnWallet;
address rewardsController;
}

// You can add parameters to this function in order to pass in
Expand Down Expand Up @@ -67,11 +68,11 @@ contract DiamondInit {
s.unlockFee = _args.unlockFee;

s.unlockTimestampDiscountForStratosphereMembers[0] = 500; // 5%
s.unlockTimestampDiscountForStratosphereMembers[1] = 550; // 5.5%
s.unlockTimestampDiscountForStratosphereMembers[2] = 650; // 6.5%
s.unlockTimestampDiscountForStratosphereMembers[3] = 800; // 8%
s.unlockTimestampDiscountForStratosphereMembers[4] = 1000; // 10%
s.unlockTimestampDiscountForStratosphereMembers[5] = 1500; // 15%
s.unlockTimestampDiscountForStratosphereMembers[1] = 650; // 6.5%
s.unlockTimestampDiscountForStratosphereMembers[2] = 900; // 9%
s.unlockTimestampDiscountForStratosphereMembers[3] = 1300; // 13%
s.unlockTimestampDiscountForStratosphereMembers[4] = 2000; // 20%
s.unlockTimestampDiscountForStratosphereMembers[5] = 3250; // 32.5%
s.unlockFeeReceivers.push(_args.replenishmentPool);
s.unlockFeeReceivers.push(_args.labsMultisig);
s.unlockFeeReceivers.push(_args.burnWallet);
Expand Down Expand Up @@ -148,5 +149,9 @@ contract DiamondInit {
s.miningPassFeeReceiversShares.push(6500); // 65%
s.miningPassFeeReceiversShares.push(3000); // 30%
s.miningPassFeeReceiversShares.push(500); // 5%

// Rewards Controller

s.rewardsControllerAddress = _args.rewardsController;
}
}
153 changes: 81 additions & 72 deletions test/foundry/Facets/BoostFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DiamondManagerFacet } from "src/facets/DiamondManagerFacet.sol";
import { ERC20Mock } from "test/foundry/mocks/ERC20Mock.sol";
import { StratosphereMock } from "test/foundry/mocks/StratosphereMock.sol";
import { LPercentages } from "src/libraries/LPercentages.sol";
import { RewardsControllerMock } from "test/foundry/mocks/RewardsControllerMock.sol";

contract BoostFacetTest is DiamondTest {
// StdCheats cheats = StdCheats(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
Expand All @@ -18,15 +19,21 @@ contract BoostFacetTest is DiamondTest {
ClaimFacet internal claimFacet;
BoostFacet internal boostFacet;
DiamondManagerFacet internal diamondManagerFacet;
RewardsControllerMock internal rewardsControllerMock;

// setup addresses
address feeReceiver1 = makeAddr("feeReceiver1");
address feeReceiver2 = makeAddr("feeReceiver2");
address diamondOwner = makeAddr("diamondOwner");
address user = makeAddr("user");

// Stratosphere Mocks
address stratosphereMemberBasic = makeAddr("stratosphereMemberBasic");
address stratosphereMemberSilver = makeAddr("stratosphereMemberSilver");
address stratosphereMemberGold = makeAddr("stratosphereMemberGold");
address stratosphereMemberPlatinum = makeAddr("stratosphereMemberPlatinum");
address stratosphereMemberDiamond = makeAddr("stratosphereMemberDiamond");
address stratosphereMemberObsidian = makeAddr("stratosphereMemberObsidian");
// setup test details
uint256 rewardTokenToDistribute = 10000 * 1e18;
uint256 testDepositAmount = 5000 * 1e18;
Expand All @@ -39,24 +46,24 @@ contract BoostFacetTest is DiamondTest {
uint256 boostFeeLvl2 = 3 * 1e6;
uint256 boostFeeLvl3 = 4 * 1e6;
// boost data setup
uint256 boostLvl1Tier1 = 22;
uint256 boostLvl1Tier2 = 28;
uint256 boostLvl1Tier3 = 37;
uint256 boostLvl1Tier4 = 51;
uint256 boostLvl1Tier5 = 74;
uint256 boostLvl1Tier6 = 115;
uint256 boostLvl2Tier1 = 24;
uint256 boostLvl2Tier2 = 30;
uint256 boostLvl2Tier3 = 40;
uint256 boostLvl2Tier4 = 55;
uint256 boostLvl2Tier5 = 81;
uint256 boostLvl2Tier6 = 125;
uint256 boostLvl3Tier1 = 26;
uint256 boostLvl3Tier2 = 33;
uint256 boostLvl3Tier3 = 44;
uint256 boostLvl3Tier4 = 60;
uint256 boostLvl3Tier5 = 87;
uint256 boostLvl3Tier6 = 135;
uint256 boostLvl1Tier0 = 22;
uint256 boostLvl1Tier1 = 28;
uint256 boostLvl1Tier2 = 37;
uint256 boostLvl1Tier3 = 51;
uint256 boostLvl1Tier4 = 74;
uint256 boostLvl1Tier5 = 115;
uint256 boostLvl2Tier0 = 24;
uint256 boostLvl2Tier1 = 30;
uint256 boostLvl2Tier2 = 40;
uint256 boostLvl2Tier3 = 55;
uint256 boostLvl2Tier4 = 81;
uint256 boostLvl2Tier5 = 125;
uint256 boostLvl3Tier0 = 26;
uint256 boostLvl3Tier1 = 33;
uint256 boostLvl3Tier2 = 44;
uint256 boostLvl3Tier3 = 60;
uint256 boostLvl3Tier4 = 87;
uint256 boostLvl3Tier5 = 135;

function setUp() public {
vm.startPrank(diamondOwner);
Expand All @@ -66,10 +73,12 @@ contract BoostFacetTest is DiamondTest {
depositFacet = DepositFacet(address(diamond));
claimFacet = ClaimFacet(address(diamond));
boostFacet = BoostFacet(address(diamond));
rewardsControllerMock = new RewardsControllerMock();

// Set up season details for deposit
rewardToken.mint(address(diamond), rewardTokenToDistribute);
diamondManagerFacet.startNewSeason(rewardTokenToDistribute);
diamondManagerFacet.setRewardControllerAddress(address(rewardsControllerMock));

vm.stopPrank();
}
Expand Down Expand Up @@ -109,7 +118,7 @@ contract BoostFacetTest is DiamondTest {
depositPointsTillNow,
boostPointsTillNow,
depositAmount,
boostLvl1Tier1
boostLvl1Tier0
);
uint256 expectedTotalPoints = totalPointsTillNow + _caculatedPoints;
console.log("[BoostFacetTest] expectedTotalPoints", expectedTotalPoints);
Expand All @@ -126,58 +135,58 @@ contract BoostFacetTest is DiamondTest {
vm.stopPrank();
}

// FIXME: test case is failing because of Stratosphere tierOf being hardcoded to 0
// function test_BoostWithStratSilverLvl1() public {
// vm.startPrank(stratosphereMemberSilver);
// uint256 _currentSeasonId = diamondManagerFacet.getCurrentSeasonId();
// _mintAndDeposit(stratosphereMemberSilver, testDepositAmount);
// _fundUserWithBoostFeeToken(stratosphereMemberSilver, boostFeeLvl1);
// assertEq(feeToken.balanceOf(stratosphereMemberSilver), boostFeeLvl1);

// (uint256 depositPointsTillNow, uint256 boostPointsTillNow) = diamondManagerFacet.getUserPoints(
// stratosphereMemberSilver,
// _currentSeasonId
// );
// uint256 totalPointsTillNow = depositPointsTillNow + boostPointsTillNow;

// vm.warp(block.timestamp + 3 days);
// uint256 expectedTotalPoints = totalPointsTillNow + _calculatePoints(totalPointsTillNow, boostLvl1Tier2);

// boostFacet.claimBoost(1);

// uint256 lastBoostClaimedAmount = diamondManagerFacet.getUserLastBoostClaimedAmount(
// stratosphereMemberSilver,
// _currentSeasonId
// );
// assertEq(totalPointsTillNow + lastBoostClaimedAmount, expectedTotalPoints);
// assertEq(feeToken.balanceOf(stratosphereMemberSilver), 0);
// assertEq(feeToken.balanceOf(address(boostFacet)), boostFeeLvl1);
// vm.stopPrank();
// }

// FIXME: test case is failing because of Stratosphere tierOf being hardcoded to 0
// function test_BoostWithStratGoldLvl1() public {
// vm.startPrank(stratosphereMemberGold);
// _mintAndDeposit(stratosphereMemberGold, testDepositAmount);
// _fundUserWithBoostFeeToken(stratosphereMemberGold, boostFeeLvl1);
// assertEq(feeToken.balanceOf(stratosphereMemberGold), boostFeeLvl1);

// (uint256 depositPointsTillNow, uint256 boostPointsTillNow) = diamondManagerFacet.getUserPoints(
// stratosphereMemberGold,
// 1
// );
// uint256 totalPointsTillNow = depositPointsTillNow + boostPointsTillNow;

// vm.warp(block.timestamp + 3 days);
// uint256 expectedTotalPoints = totalPointsTillNow + _calculatePoints(totalPointsTillNow, boostLvl1Tier3);

// boostFacet.claimBoost(1);
// uint256 lastBoostClaimedAmount = diamondManagerFacet.getUserLastBoostClaimedAmount(stratosphereMemberGold, 1);
// assertEq(totalPointsTillNow + lastBoostClaimedAmount, expectedTotalPoints);
// assertEq(feeToken.balanceOf(stratosphereMemberGold), 0);
// assertEq(feeToken.balanceOf(address(boostFacet)), boostFeeLvl1);
// vm.stopPrank();
// }
function test_BoostWithStratSilverLvl1() public {
vm.startPrank(stratosphereMemberSilver);
uint256 _currentSeasonId = diamondManagerFacet.getCurrentSeasonId();
_mintAndDeposit(stratosphereMemberSilver, testDepositAmount);
_fundUserWithBoostFeeToken(stratosphereMemberSilver, boostFeeLvl1);
assertEq(feeToken.balanceOf(stratosphereMemberSilver), boostFeeLvl1);

(uint256 depositPointsTillNow, uint256 boostPointsTillNow) = diamondManagerFacet.getUserPoints(
stratosphereMemberSilver,
_currentSeasonId
);
uint256 totalPointsTillNow = depositPointsTillNow + boostPointsTillNow;

vm.warp(block.timestamp + 3 days);
uint256 expectedTotalPoints = totalPointsTillNow +
_calculatePoints(totalPointsTillNow, boostLvl1Tier1, testDepositAmount, boostLvl1Tier1);

boostFacet.claimBoost(1);

uint256 lastBoostClaimedAmount = diamondManagerFacet.getUserLastBoostClaimedAmount(
stratosphereMemberSilver,
_currentSeasonId
);
assertEq(totalPointsTillNow + lastBoostClaimedAmount, expectedTotalPoints);
assertEq(feeToken.balanceOf(stratosphereMemberSilver), 0);
assertEq(feeToken.balanceOf(address(boostFacet)), boostFeeLvl1);
vm.stopPrank();
}

function test_BoostWithStratGoldLvl1() public {
vm.startPrank(stratosphereMemberGold);
_mintAndDeposit(stratosphereMemberGold, testDepositAmount);
_fundUserWithBoostFeeToken(stratosphereMemberGold, boostFeeLvl1);
assertEq(feeToken.balanceOf(stratosphereMemberGold), boostFeeLvl1);

(uint256 depositPointsTillNow, uint256 boostPointsTillNow) = diamondManagerFacet.getUserPoints(
stratosphereMemberGold,
1
);
uint256 totalPointsTillNow = depositPointsTillNow + boostPointsTillNow;

vm.warp(block.timestamp + 3 days);
uint256 expectedTotalPoints = totalPointsTillNow +
_calculatePoints(totalPointsTillNow, boostLvl1Tier2, testDepositAmount, boostLvl1Tier2);

boostFacet.claimBoost(1);
uint256 lastBoostClaimedAmount = diamondManagerFacet.getUserLastBoostClaimedAmount(stratosphereMemberGold, 1);
assertEq(totalPointsTillNow + lastBoostClaimedAmount, expectedTotalPoints);
assertEq(feeToken.balanceOf(stratosphereMemberGold), 0);
assertEq(feeToken.balanceOf(address(boostFacet)), boostFeeLvl1);
vm.stopPrank();
}

function test_BoostWithStratBasicLvl2() public {
vm.startPrank(stratosphereMemberBasic);
Expand All @@ -196,7 +205,7 @@ contract BoostFacetTest is DiamondTest {
vm.warp(block.timestamp + 3 days);

uint256 expectedTotalPoints = totalPointsTillNow +
_calculatePoints(depositPointsTillNow, boostPointsTillNow, depositAmount, boostLvl2Tier1);
_calculatePoints(depositPointsTillNow, boostPointsTillNow, depositAmount, boostLvl2Tier0);
boostFacet.claimBoost(2);
uint256 lastBoostClaimedAmount = diamondManagerFacet.getUserLastBoostClaimedAmount(
stratosphereMemberBasic,
Expand Down
4 changes: 4 additions & 0 deletions test/foundry/Facets/FeeCollectorFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DiamondManagerFacet } from "src/facets/DiamondManagerFacet.sol";
import { ERC20Mock } from "test/foundry/mocks/ERC20Mock.sol";
import { StratosphereMock } from "test/foundry/mocks/StratosphereMock.sol";
import "src/libraries/LPercentages.sol";
import { RewardsControllerMock } from "test/foundry/mocks/RewardsControllerMock.sol";

contract FeeCollectorFacetTest is DiamondTest {
// StdCheats cheats = StdCheats(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
Expand All @@ -22,6 +23,7 @@ contract FeeCollectorFacetTest is DiamondTest {
FeeCollectorFacet internal feeCollectorFacet;
ClaimFacet internal claimFacet;
BoostFacet internal boostFacet;
RewardsControllerMock internal rewardsControllerMock;
address depositFeeReceiver1 = makeAddr("depositFeeReceiver1");
address depositFeeReceiver2 = makeAddr("depositFeeReceiver2");
address stratosphereMemberBasic = makeAddr("stratosphereMemberBasic");
Expand All @@ -37,6 +39,7 @@ contract FeeCollectorFacetTest is DiamondTest {
feeCollectorFacet = FeeCollectorFacet(address(diamond));
claimFacet = ClaimFacet(address(diamond));
boostFacet = BoostFacet(address(diamond));
rewardsControllerMock = new RewardsControllerMock();

// diamondManagerFacet.setCurrentSeasonId(1);
// diamondManagerFacet.setSeasonEndTimestamp(1, block.timestamp + 30 days);
Expand All @@ -51,6 +54,7 @@ contract FeeCollectorFacetTest is DiamondTest {
depositFeeProportions[1] = 2500;
diamondManagerFacet.setUnlockFeeReceivers(depositFeeReceivers, depositFeeProportions);
diamondManagerFacet.setBoostFeeReceivers(depositFeeReceivers, depositFeeProportions);
diamondManagerFacet.setRewardControllerAddress(address(rewardsControllerMock));

vm.stopPrank();
}
Expand Down
Loading