Skip to content

Commit

Permalink
Testing Aurora Plus πŸ’š rewards in Centauri Tokens πŸͺ
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Sosa committed Apr 14, 2023
1 parent c8a4da4 commit 6487ccc
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 41 deletions.
11 changes: 8 additions & 3 deletions contracts/Depositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

// import "hardhat/console.sol";

contract Depositor is AccessControl, IDepositor {
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -72,22 +74,25 @@ contract Depositor is AccessControl, IDepositor {
IAuroraStaking(auroraStaking).unstakeAll();
}

/// @dev The param of 0 in withdraw refers the streamId for the Aurora Token.
function withdraw(uint256 _assets) external onlyManager {
IAuroraStaking(auroraStaking).withdraw(0);
IERC20(auroraToken).safeTransfer(stakingManager, _assets);
}

function getReleaseTime(uint256 _streamId) external view returns (uint256) {
return IAuroraStaking(auroraStaking).getReleaseTime(_streamId, address(this));
}

/// @dev The param of 0 in getPendings refers the streamId for the Aurora Token.
function getPendingAurora() external view returns (uint256) {
return IAuroraStaking(auroraStaking).getPending(0, address(this));
}

/// Reward functions, for streamId greater than 0.

function getPendingRewards(uint256 _streamId) external view returns (uint256) {
return IAuroraStaking(auroraStaking).getPending(_streamId, address(this));
}

// TODO β›” The next 2 functions are not testest.
function moveRewardsToPending(
uint256 _streamId
) external onlyRole(COLLECT_REWARDS_ROLE) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/StakingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ contract StakingManager is AccessControl {
/// @notice Users will NOT receive back the exact same amount of shares they had before.
/// @dev The last inclusive index to process will be (from_index + limit - 1).
/// @param from_index The inclusive withdraw order index the clear will start (cannot be zero).
/// @param limit The number of orders to process.
/// @param limit Number of orders to process.
function emergencyClearWithdrawOrders(
uint256 from_index,
uint256 limit
Expand Down
33 changes: 16 additions & 17 deletions contracts/interfaces/IAuroraStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ enum StreamStatus {

interface IAuroraStaking {
function getPending(uint256 _streamId, address _account) external view returns (uint256);
function getStream(uint256 streamId)
external
view
returns (
address streamOwner,
address rewardToken,
uint256 auroraDepositAmount,
uint256 auroraClaimedAmount,
uint256 rewardDepositAmount,
uint256 rewardClaimedAmount,
uint256 maxDepositAmount,
uint256 lastTimeOwnerClaimed,
uint256 rps,
uint256 tau,
StreamStatus status
);
function getReleaseTime(uint256 _streamId, address _account) external view returns (uint256);
function getStream(uint256 _streamId) external view returns (
address streamOwner,
address rewardToken,
uint256 auroraDepositAmount,
uint256 auroraClaimedAmount,
uint256 rewardDepositAmount,
uint256 rewardClaimedAmount,
uint256 maxDepositAmount,
uint256 lastTimeOwnerClaimed,
uint256 rps,
uint256 tau,
StreamStatus status
);
function getTotalAmountOfStakedAurora() external view returns (uint256);
function getUserShares(address account) external view returns (uint256);
function getUserShares(address _account) external view returns (uint256);
function moveRewardsToPending(uint256 _streamId) external;
function stake(uint256 _amount) external;
function totalAuroraShares() external view returns (uint256);
function unstake(uint256 _amount) external;
function unstakeAll() external;
function withdraw(uint256 _streamId) external;

}
82 changes: 62 additions & 20 deletions contracts/testing/AuroraStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ contract AuroraStaking {
uint256 public totalAuroraShares;
uint256 public tauAuroraStream;

/// @dev Centauri Token for Rewards
address public stream1Token;
/// @dev Centauri Token for Rewards >> Stream 1 <<
address public centauriToken;
uint256 public tauCentauriStream;

mapping(address => uint256) deposits;
mapping(address => uint256) auroraShares;
Expand All @@ -35,12 +36,13 @@ contract AuroraStaking {
_;
}

constructor(address _auroraToken, address _stream1Token) {
constructor(address _auroraToken, address _centauriToken) {
auroraToken = _auroraToken;
touchedAt = block.timestamp;
// tauAuroraStream = 2 * 24 * 60 * 60; // 2 days in seconds.
tauAuroraStream = 1 * 60 * 60; // 1 hour in seconds.
stream1Token = _stream1Token;
tauCentauriStream = 30 * 60; // 0.5 hour in seconds.
centauriToken = _centauriToken;
}

/// @dev get the stream data
Expand All @@ -65,19 +67,37 @@ contract AuroraStaking {
StreamStatus status
)
{
return (
address(0),
address(0),
streamId,
0,
0,
0,
0,
0,
0,
tauAuroraStream,
StreamStatus.ACTIVE
);
if (streamId == 0) {
return (
address(0),
auroraToken,
streamId,
0,
0,
0,
0,
0,
0,
tauAuroraStream,
StreamStatus.ACTIVE
);
} else if (streamId == 1) {
return (
address(0),
centauriToken,
streamId,
0,
0,
0,
0,
0,
0,
tauCentauriStream,
StreamStatus.ACTIVE
);
} else {
revert("INVALID_STREAM_ID");
}
}

/// @dev gets the total user deposit
Expand Down Expand Up @@ -121,6 +141,18 @@ contract AuroraStaking {
return totalAmountOfStakedAurora + getRewardsAmount(0, touchedAt);
}

/// @dev gets the user's stream reward release time
/// @param streamId stream index
/// @param account user account
/// @return user.releaseTime[streamId]
function getReleaseTime(uint256 streamId, address account)
external
view
returns (uint256)
{
return releaseTime[account][streamId];
}

/// @dev withdraw amount in the pending pool. User should wait for
/// pending time (tau constant) in order to be able to withdraw.
/// @param streamId stream index
Expand Down Expand Up @@ -256,11 +288,21 @@ contract AuroraStaking {
function _withdraw(uint256 streamId) internal {
uint256 pendingAmount = pendings[msg.sender][streamId];
pendings[msg.sender][streamId] = 0;
IERC20Upgradeable(auroraToken).safeTransfer(msg.sender, pendingAmount);
if (streamId == 0) {
IERC20Upgradeable(auroraToken).safeTransfer(msg.sender, pendingAmount);
} else if (streamId == 1) {
IERC20Upgradeable(centauriToken).safeTransfer(msg.sender, pendingAmount);
} else {
revert("INVALID_STREAM_ID");
}
}

function moveRewardsToPending(uint256 streamId) external {
// _before();
// _moveRewardsToPending(msg.sender, streamId);
require(auroraShares[msg.sender] != 0, "USER_DOES_NOT_HAVE_ACTUAL_STAKE");
_before();

// Dummy contract increase the rewards pending by 1.
pendings[msg.sender][streamId] += 1 ether;
releaseTime[msg.sender][streamId] = block.timestamp + tauCentauriStream;
}
}
44 changes: 44 additions & 0 deletions test/staking_pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,4 +935,48 @@ describe("Staking Pool AURORA", function () {
);
});
});

describe("Get the Aurora Plus πŸ’š rewards (Centauri Token πŸͺ)", function () {
it("Should get pending and move to pending rewards.", async function () {
const {
depositor00Contract,
alice,
reward_collector
} = await loadFixture(depositPoolFixture);

expect(await depositor00Contract.getPendingRewards(1)).to.equal(0);
await expect(
depositor00Contract.connect(alice).moveRewardsToPending(1)
).to.be.revertedWith("AccessControl: account 0x976ea74026e726554db657fa54763abd0c3a0aa9 is missing role 0x131c12305311744a3f7cfa41d985c1cd8592681deca082296d27adcfcc21a0b8");
await depositor00Contract.connect(reward_collector).moveRewardsToPending(1);
expect(await depositor00Contract.getPendingRewards(1)).to.be.greaterThan(0);
});

it("Should withdraw pending rewards and give the allowance to a 3rd party.", async function () {
const {
depositor00Contract,
centauriTokenContract,
alice,
reward_collector
} = await loadFixture(depositPoolFixture);

await depositor00Contract.connect(reward_collector).moveRewardsToPending(1);
await expect(
depositor00Contract.connect(reward_collector).withdrawRewards(1, alice.address)
).to.be.revertedWith("INVALID_RELEASE_TIME");

// Move forward: From pending to available.
await time.increaseTo(await depositor00Contract.getReleaseTime(1));

expect(await centauriTokenContract.balanceOf(depositor00Contract.address)).to.equal(0);
await depositor00Contract.connect(reward_collector).withdrawRewards(1, alice.address);

const transferedRewards = await centauriTokenContract.balanceOf(depositor00Contract.address);
expect(transferedRewards).to.be.greaterThan(0);

expect(await centauriTokenContract.balanceOf(alice.address)).to.equal(0);
await centauriTokenContract.connect(alice).transferFrom(depositor00Contract.address, alice.address, transferedRewards);
expect(await centauriTokenContract.balanceOf(alice.address)).to.equal(transferedRewards);
});
});
});
7 changes: 7 additions & 0 deletions test/test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ async function deployPoolFixture() {
// Fixtures can return anything you consider useful for your tests
return {
auroraTokenContract,
centauriTokenContract,
auroraStakingContract,
stakedAuroraVaultContract,
stakingManagerContract,
Expand All @@ -175,6 +176,7 @@ async function deployPoolFixture() {
async function depositPoolFixture() {
const {
auroraTokenContract,
centauriTokenContract,
auroraStakingContract,
stakedAuroraVaultContract,
stakingManagerContract,
Expand Down Expand Up @@ -231,6 +233,7 @@ async function depositPoolFixture() {

return {
auroraTokenContract,
centauriTokenContract,
auroraStakingContract,
stakedAuroraVaultContract,
stakingManagerContract,
Expand All @@ -252,6 +255,7 @@ async function depositPoolFixture() {
async function liquidityPoolFixture() {
const {
auroraTokenContract,
centauriTokenContract,
auroraStakingContract,
stakedAuroraVaultContract,
stakingManagerContract,
Expand Down Expand Up @@ -294,6 +298,7 @@ async function liquidityPoolFixture() {

return {
auroraTokenContract,
centauriTokenContract,
auroraStakingContract,
stakedAuroraVaultContract,
stakingManagerContract,
Expand All @@ -315,6 +320,7 @@ async function liquidityPoolFixture() {
async function botsHordeFixture() {
const {
auroraTokenContract,
centauriTokenContract,
auroraStakingContract,
stakedAuroraVaultContract,
stakingManagerContract,
Expand Down Expand Up @@ -383,6 +389,7 @@ async function botsHordeFixture() {

return {
auroraTokenContract,
centauriTokenContract,
auroraStakingContract,
stakedAuroraVaultContract,
stakingManagerContract,
Expand Down

0 comments on commit 6487ccc

Please sign in to comment.