Skip to content

Commit

Permalink
removal of global startBlock infavor of per-pool startBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoMan0x committed Jun 10, 2024
1 parent b4cf6d4 commit 18b59d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 44 deletions.
48 changes: 13 additions & 35 deletions contracts/farm/SophonFarming.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
* @param weEthAllocPoint_ weEth alloc points
* @param sDAIAllocPoint_ sdai alloc points
* @param _pointsPerBlock points per block
* @param _startBlock start block
* @param _initialPoolStartBlock start block
* @param _boosterMultiplier booster multiplier
*/
function initialize(uint256 wstEthAllocPoint_, uint256 weEthAllocPoint_, uint256 sDAIAllocPoint_, uint256 _pointsPerBlock, uint256 _startBlock, uint256 _boosterMultiplier) public virtual onlyOwner {
function initialize(uint256 wstEthAllocPoint_, uint256 weEthAllocPoint_, uint256 sDAIAllocPoint_, uint256 _pointsPerBlock, uint256 _initialPoolStartBlock, uint256 _boosterMultiplier) public virtual onlyOwner {
if (_initialized) {
revert AlreadyInitialized();
}
Expand All @@ -130,11 +130,6 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
}
pointsPerBlock = _pointsPerBlock;

if (_startBlock == 0) {
revert InvalidStartBlock();
}
startBlock = _startBlock;

if (_boosterMultiplier < 1e18 || _boosterMultiplier > 10e18) {
revert InvalidBooster();
}
Expand All @@ -148,15 +143,15 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
_initialized = true;

// sDAI
typeToId[PredefinedPool.sDAI] = add(sDAIAllocPoint_, sDAI, "sDAI");
typeToId[PredefinedPool.sDAI] = add(sDAIAllocPoint_, sDAI, "sDAI", _initialPoolStartBlock);
IERC20(dai).approve(sDAI, 2**256-1);

// wstETH
typeToId[PredefinedPool.wstETH] = add(wstEthAllocPoint_, wstETH, "wstETH");
typeToId[PredefinedPool.wstETH] = add(wstEthAllocPoint_, wstETH, "wstETH", _initialPoolStartBlock);
IERC20(stETH).approve(wstETH, 2**256-1);

// weETH
typeToId[PredefinedPool.weETH] = add(weEthAllocPoint_, weETH, "weETH");
typeToId[PredefinedPool.weETH] = add(weEthAllocPoint_, weETH, "weETH", _initialPoolStartBlock);
IERC20(eETH).approve(weETH, 2**256-1);
}

Expand All @@ -165,10 +160,10 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
* @param _allocPoint alloc point for new pool
* @param _lpToken lpToken address
* @param _description description of new pool
* @param _startBlock block at which points start to accrue
* @param _poolStartBlock block at which points start to accrue for the pool
* @return uint256 The pid of the newly created asset
*/
function add(uint256 _allocPoint, address _lpToken, string memory _description, uint256 _startBlock) public onlyOwner returns (uint256) {
function add(uint256 _allocPoint, address _lpToken, string memory _description, uint256 _poolStartBlock) public onlyOwner returns (uint256) {
if (_lpToken == address(0)) {
revert ZeroAddress();
}
Expand All @@ -182,7 +177,7 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
massUpdatePools();

uint256 lastRewardBlock =
getBlockNumber() > _startBlock ? getBlockNumber() : _startBlock;
getBlockNumber() > _poolStartBlock ? getBlockNumber() : _poolStartBlock;
totalAllocPoint = totalAllocPoint + _allocPoint;
poolExists[_lpToken] = true;

Expand Down Expand Up @@ -211,9 +206,9 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
* @notice Updates the given pool's allocation point. Can only be called by the owner.
* @param _pid The pid to update
* @param _allocPoint The new alloc point to set for the pool
* @param _startBlock block at which points start to accrue
* @param _poolStartBlock block at which points start to accrue for the pool
*/
function set(uint256 _pid, uint256 _allocPoint, uint256 _startBlock) external onlyOwner {
function set(uint256 _pid, uint256 _allocPoint, uint256 _poolStartBlock) external onlyOwner {
if (isFarmingEnded()) {
revert FarmingIsEnded();
}
Expand All @@ -228,9 +223,9 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
totalAllocPoint = totalAllocPoint - pool.allocPoint + _allocPoint;
pool.allocPoint = _allocPoint;

// you can always move further pool starting block unless its already started
// pool starting block is updated, unless it's already started
if (getBlockNumber() < pool.lastRewardBlock) {
pool.lastRewardBlock = _startBlock;
pool.lastRewardBlock = _poolStartBlock;
}

emit Set(lpToken, _pid, _allocPoint);
Expand Down Expand Up @@ -295,23 +290,6 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
poolInfo[_pid].l2Farm = _l2Farm;
}

/**
* @notice Set the start block of the farm
* @param _startBlock the start block
*/
function setStartBlock(uint256 _startBlock) external onlyOwner {
uint256 blockNumber = getBlockNumber();
if (_startBlock == 0 || blockNumber > _startBlock || (endBlock != 0 && _startBlock >= endBlock)) {
revert InvalidStartBlock();
}
if (blockNumber > startBlock) {
revert FarmingIsStarted();
}

massUpdatePools();
startBlock = _startBlock;
}

/**
* @notice Set the end block of the farm
* @param _endBlock the end block
Expand All @@ -323,7 +301,7 @@ contract SophonFarming is Upgradeable2Step, SophonFarmingState {
}
uint256 _endBlockForWithdrawals;
if (_endBlock != 0) {
if (_endBlock <= startBlock || getBlockNumber() > _endBlock) {
if (getBlockNumber() > _endBlock) {
revert InvalidEndBlock();
}
_endBlockForWithdrawals = _endBlock + _withdrawalBlocks;
Expand Down
3 changes: 0 additions & 3 deletions contracts/farm/SophonFarmingState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ contract SophonFarmingState {
// Total allocation points. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint;

// The block number when point mining starts.
uint256 public startBlock;

// The block number when point mining ends.
uint256 public endBlock;

Expand Down
12 changes: 6 additions & 6 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def createMockSetup(deployTokens = False):
sDAIAllocPoint = 20000

pointsPerBlock = 100*10**18
startBlock = chain.height
startBlock = chain.height + 45
boosterMultiplier = 2e18

createFarm(weth, stETH, wstETH, wstEthAllocPoint, eETH, eETHLiquidityPool, weETH, weEthAllocPoint, dai, sDAI, sDAIAllocPoint, pointsPerBlock, startBlock, boosterMultiplier)

acct, acct1, acct2, farm, mock0, mock1, weth, stETH, wstETH, eETH, eETHLiquidityPool, weETH, dai, sDAI = getMocks()

farm.add(10000, mock0, "mock0", {"from": acct})
farm.add(30000, mock1, "mock1", {"from": acct})
farm.add(10000, mock0, "mock0", startBlock, {"from": acct})
farm.add(30000, mock1, "mock1", startBlock, {"from": acct})


## Approvals
Expand Down Expand Up @@ -258,15 +258,15 @@ def testMainnetOnFork():
weEthAllocPoint = 20000
sDAIAllocPoint = 20000
pointsPerBlock = 25*10**18
startBlock = chain.height
startBlock = chain.height + 45
boosterMultiplier = 2e18

createFarm(weth, stETH, wstETH, wstEthAllocPoint, eETH, eETHLiquidityPool, weETH, weEthAllocPoint, dai, sDAI, sDAIAllocPoint, pointsPerBlock, startBlock, boosterMultiplier)

acct, acct1, acct2, farm, mock0, mock1, weth, stETH, wstETH, eETH, eETHLiquidityPool, weETH, dai, sDAI = getMocks()

farm.add(10000, mock0, "mock0", {"from": acct})
farm.add(30000, mock1, "mock1", {"from": acct})
farm.add(10000, mock0, "mock0", startBlock, {"from": acct})
farm.add(30000, mock1, "mock1", startBlock, {"from": acct})


## Approvals
Expand Down

0 comments on commit 18b59d5

Please sign in to comment.