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: configure rewards controller && update init params #64

Open
wants to merge 6 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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 getUnlockDiscountForStratosphereMember(uint256 tier) external view returns (uint256) {
royvardhan marked this conversation as resolved.
Show resolved Hide resolved
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);
royvardhan marked this conversation as resolved.
Show resolved Hide resolved
tier = _rewardsController.tierOf(_tokenId);
}
}
}
10 changes: 5 additions & 5 deletions src/upgradeInitializers/DiamondInit.sol
royvardhan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,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
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
Loading