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

[Do not Merge]Implement virtual blocks #58

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
aa92b2c
initial commit
maptuhec Oct 1, 2021
b96a75b
Implement virtual block solutions and fix some tests
maptuhec Oct 1, 2021
7fd4ae8
Fix autostake and rewards pool base tests
maptuhec Oct 5, 2021
ef8ea5e
Fixing unit tests
maptuhec Oct 11, 2021
52ed21f
Implement virtual blocks in throttled exit
maptuhec Oct 18, 2021
5a8e00f
Fix unit tests
maptuhec Oct 19, 2021
115ca29
fixig unit tests& upgrade lock schemes and lmcs
maptuhec Oct 26, 2021
3ad9ad5
Adding the increaseTime for increasing time in the EVM
guillermoriv Oct 26, 2021
4a79a6d
Formatting in the test file of the factory
guillermoriv Oct 26, 2021
56006ed
Adding the increaseTime to the factory
guillermoriv Oct 26, 2021
4e07f3a
Deleting unused function
guillermoriv Oct 26, 2021
679c2fa
Adding the test case for extending the campaign
guillermoriv Oct 26, 2021
cd17cfa
Adding some console.logs just to guide
guillermoriv Oct 26, 2021
3e701ed
Making some console.logs just to see the possible solutions
guillermoriv Oct 26, 2021
b85e3d6
Removing the check on the abstract pool and adding a check in the factor
guillermoriv Oct 26, 2021
86f8628
Doing some refactor
guillermoriv Oct 27, 2021
3ad0f47
Returning 0 if the campaign is expired
guillermoriv Oct 28, 2021
5115eae
Adding a solution for the expired campaign to be availabel to extend
guillermoriv Oct 28, 2021
41f3890
Adding a more specific test for the pool extend when expired
guillermoriv Oct 29, 2021
07ac105
Fixing the error with the block.timestamp with the difference of seconds
guillermoriv Oct 29, 2021
aa05746
Deleting the .only in the discribe
guillermoriv Oct 29, 2021
18deb85
Add deployment scripsts and fix unit testsing
maptuhec Nov 1, 2021
434405e
Add NoLock LMC
maptuhec Nov 2, 2021
80acfa3
Removing unused timestamp
guillermoriv Nov 2, 2021
e45fd1c
Add No lock lmc
maptuhec Nov 4, 2021
9b1fe72
Merge pull request #57 from Stichting-AllianceBlock-Foundation/fix/ex…
maptuhec Nov 4, 2021
af1cc76
Merge branch 'implement-virtual-blocks' of https://github.com/Stichti…
maptuhec Nov 4, 2021
5a60917
Add test for no lock
maptuhec Nov 8, 2021
84d96bf
small improvements
maptuhec Nov 10, 2021
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ coverage
.DS_Store
.prettierrc
coverage.json
coverage
coverage
175 changes: 89 additions & 86 deletions contracts/AbstractPoolsFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,90 +7,93 @@ import "./SafeERC20Detailed.sol";
import "./interfaces/IERC20Detailed.sol";

abstract contract AbstractPoolsFactory {
using SafeMath for uint256;
using SafeERC20Detailed for IERC20Detailed;

/** @dev all rewards pools
*/
address[] public rewardsPools;
address public owner;
address internal pendingOwner;

event OwnershipTransferProposed(address indexed _oldOwner, address indexed _newOwner);
event OwnershipTransferred(address indexed _newOwner);
event RewardsWithdrawn(address rewardsToken, uint256 amount);

constructor() public {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner, "onlyOwner:: The caller is not the owner");
_;
}

function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0x0), "Cannot set owner to 0 address");
pendingOwner = newOwner;
emit OwnershipTransferProposed(msg.sender, owner);
}

function acceptOwnership() public {
require(msg.sender == pendingOwner, "Sender is different from proposed owner");

owner = pendingOwner;
emit OwnershipTransferred(owner);
}

/** @dev Returns the total number of rewards pools.
*/
function getRewardsPoolNumber() public view returns (uint256) {
return rewardsPools.length;
}

/** @dev Helper function to calculate how much tokens should be transffered to a rewards pool.
*/
function calculateRewardsAmount(
uint256 _startBlock,
uint256 _endBlock,
uint256 _rewardPerBlock
) public pure returns (uint256) {
require(
_rewardPerBlock > 0,
"calculateRewardsAmount:: Rewards per block must be greater than zero"
);

uint256 rewardsPeriod = _endBlock.sub(_startBlock);

return _rewardPerBlock.mul(rewardsPeriod);
}

/** @dev Triggers the withdrawal of LP rewards from the rewards pool contract to the given recipient address
* @param rewardsPoolAddress The address of the token being staked
* @param recipient The address to whom the rewards will be trasferred
* @param lpTokenContract The address of the rewards contract
*/
function withdrawLPRewards(
address rewardsPoolAddress,
address recipient,
address lpTokenContract
) external onlyOwner {
require(
rewardsPoolAddress != address(0),
"startStaking:: not deployed"
);
IRewardsPoolBase pool = IRewardsPoolBase(rewardsPoolAddress);
pool.withdrawLPRewards(recipient, lpTokenContract);
}

/** @dev Function to withdraw any rewards leftover, mainly from extend with lower rate.
* @param _rewardsToken The address of the rewards to be withdrawn.
*/
function withdrawRewardsLeftovers(address _rewardsToken) external onlyOwner {

uint256 contractBalance = IERC20Detailed(_rewardsToken).balanceOf(address(this));
IERC20Detailed(_rewardsToken).safeTransfer(msg.sender,contractBalance );

emit RewardsWithdrawn(_rewardsToken,contractBalance);
}
using SafeMath for uint256;
using SafeERC20Detailed for IERC20Detailed;

/** @dev all rewards pools
*/
address[] public rewardsPools;
address public owner;
address internal pendingOwner;

event OwnershipTransferProposed(address indexed _oldOwner, address indexed _newOwner);
event OwnershipTransferred(address indexed _newOwner);
event RewardsWithdrawn(address rewardsToken, uint256 amount);

constructor() public {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner, "onlyOwner:: The caller is not the owner");
_;
}

function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0x0), "Cannot set owner to 0 address");
pendingOwner = newOwner;
emit OwnershipTransferProposed(msg.sender, owner);
}

function acceptOwnership() public {
require(msg.sender == pendingOwner, "Sender is different from proposed owner");

owner = pendingOwner;
emit OwnershipTransferred(owner);
}

/** @dev Returns the total number of rewards pools.
*/
function getRewardsPoolNumber() public view returns (uint256) {
return rewardsPools.length;
}

/** @dev Helper function to calculate how much tokens should be transffered to a rewards pool.
*/
function calculateRewardsAmount(
uint256 _startTimestamp,
uint256 _endTimestamp,
uint256 _rewardPerBlock,
uint256 _virtualBlockTime
) public pure returns (uint256) {
require(_rewardPerBlock > 0, "calculateRewardsAmount:: Rewards per block must be greater than zero");

if (_startTimestamp > _endTimestamp) {
/**
@dev If the _startTimestamp is greater than the _endTimestamp
we will return 0.
**/
return 0;
}

uint256 rewardsPeriodSeconds = _endTimestamp.sub(_startTimestamp);
uint256 rewardsPeriodBlocks = rewardsPeriodSeconds.div(_virtualBlockTime);

return _rewardPerBlock.mul(rewardsPeriodBlocks);
}

/** @dev Triggers the withdrawal of LP rewards from the rewards pool contract to the given recipient address
* @param rewardsPoolAddress The address of the token being staked
* @param recipient The address to whom the rewards will be trasferred
* @param lpTokenContract The address of the rewards contract
*/
function withdrawLPRewards(
address rewardsPoolAddress,
address recipient,
address lpTokenContract
) external onlyOwner {
require(rewardsPoolAddress != address(0), "startStaking:: not deployed");
IRewardsPoolBase pool = IRewardsPoolBase(rewardsPoolAddress);
pool.withdrawLPRewards(recipient, lpTokenContract);
}

/** @dev Function to withdraw any rewards leftover, mainly from extend with lower rate.
* @param _rewardsToken The address of the rewards to be withdrawn.
*/
function withdrawRewardsLeftovers(address _rewardsToken) external onlyOwner {
uint256 contractBalance = IERC20Detailed(_rewardsToken).balanceOf(address(this));
IERC20Detailed(_rewardsToken).safeTransfer(msg.sender, contractBalance);

emit RewardsWithdrawn(_rewardsToken, contractBalance);
}
}
9 changes: 5 additions & 4 deletions contracts/LiquidityMiningCampaign.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ contract LiquidityMiningCampaign is StakeTransferer, OnlyExitFeature {

constructor(
IERC20Detailed _stakingToken,
uint256 _startBlock,
uint256 _endBlock,
uint256 _startTimeStamp,
uint256 _endTimeStamp,
address[] memory _rewardsTokens,
uint256[] memory _rewardPerBlock,
address _albtAddress,
uint256 _stakeLimit,
uint256 _contractStakeLimit) public RewardsPoolBase(_stakingToken, _startBlock, _endBlock, _rewardsTokens, _rewardPerBlock,_stakeLimit,_contractStakeLimit)
uint256 _contractStakeLimit,
uint256 _virtualBlockTime) public RewardsPoolBase(_stakingToken, _startTimeStamp, _endTimeStamp, _rewardsTokens, _rewardPerBlock,_stakeLimit,_contractStakeLimit,_virtualBlockTime)
{
require(_albtAddress == _rewardsTokens[0], "constructor:: The first reward address is different from the ALBT");
rewardToken = _rewardsTokens[0];
Expand Down Expand Up @@ -84,7 +85,7 @@ contract LiquidityMiningCampaign is StakeTransferer, OnlyExitFeature {
@param _userAddress the address of the staker
*/
function _exitAndUnlock(address _userAddress) internal {
UserInfo storage user = userInfo[_userAddress];
UserInfo storage user = userInfo[_userAddress];

if (user.amountStaked == 0) {
return;
Expand Down
Loading