Skip to content

Commit

Permalink
updates L2Reward.createPosition to resolve reentrancy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
has5aan committed Jul 2, 2024
1 parent 861607a commit 69af817
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/L2/L2Reward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,22 @@ contract L2Reward is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, IS
function createPosition(uint256 amount, uint256 duration) public virtual returns (uint256) {
updateGlobalState();

// create a new position
// slither-disable-next-line unchecked-transfer
IL2LiskToken(l2TokenContract).transferFrom(msg.sender, address(this), amount);
// slither-disable-next-line unused-return
IL2LiskToken(l2TokenContract).approve(stakingContract, amount);
uint256 id = IL2Staking(stakingContract).lockAmount(msg.sender, amount, duration);
uint256 today = todayDay();
lastClaimDate[id] = today;

// update total weight and amount
totalWeight += amount * (duration + OFFSET);
totalAmountLocked += amount;
dailyUnlockedAmounts[today + duration] += amount;
pendingUnlockAmount += amount;

// create a new position
// slither-disable-next-line unchecked-transfer
IL2LiskToken(l2TokenContract).transferFrom(msg.sender, address(this), amount);
// slither-disable-next-line unused-return
IL2LiskToken(l2TokenContract).approve(stakingContract, amount);
uint256 id = IL2Staking(stakingContract).lockAmount(msg.sender, amount, duration);
lastClaimDate[id] = today;

emit LockingPositionCreated(id);

return id;
Expand All @@ -213,7 +214,6 @@ contract L2Reward is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, IS
// claim rewards and updates staking contract
_claimReward(lockID);
IL2Staking(stakingContract).unlock(lockID);

delete lastClaimDate[lockID];

emit LockingPositionDeleted(lockID);
Expand Down

0 comments on commit 69af817

Please sign in to comment.