I'm glad to see this project moving forward, but as I'm going through the code, I'm having trouble understanding "numberOfStakes".
In fact, nothing prevents a user from calling several times the external function stakeToken()
, which will increment numberOfStakes and override the value for stakes[params.tokenId][incentiveId]
.
stakes[params.tokenId][incentiveId] = Stake(
secondsPerLiquidityInsideX128
)
The user, can have a numberOfStakes > 1 for his deposit, but only one snapshot of seconds per liquidity for the deposit position range is stored. If numberOfStakes > 1, you need to call unstakeToken
x times to decrement numberOfStakes and be able to call withdrawToken()
=> require(deposit.numberOfStakes == 0, 'NUMBER_OF_STAKES_NOT_ZERO');
.
Why is it not a Boolean called "staked" instead ? And check if deposit already staked before unstaking ?
There are certainly elements that I am missing, and my comment may not be relevant. But I will be happy to understand this mechanism a little better :)