-
Notifications
You must be signed in to change notification settings - Fork 2
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
refactor(staker): staker #437
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- do not inline
get -> data check -> if nil panic -> if not nil type assertion
for avl data- make it as separate function
- for testcase screenshot, run it from gnoswap's repo(with current br branch), not from gno
I don't think this will be a problem, since I just moved the entire main branch over to the gno side. |
5d4ad09
to
ba7d799
Compare
@@ -518,3 +517,13 @@ func externalDepositGnsAmount() uint64 { | |||
|
|||
return amount | |||
} | |||
|
|||
|
|||
func getPoolTiers() map[string]InternalTier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be avl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calc_pool_position_XXX prefix series files will be removed. don't need to change
if callerIsOwner { // if caller is owner, transfer NFT ownership to staker contract | ||
transferDeposit(tokenId, consts.STAKER_ADDR) | ||
if err := applyStake(result); err != nil { | ||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need err codes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The applyStake
already returns errNoPermission
in the transferDeposit
function, so it does not have to handle it again.
// applyStake performs the actual staking operation by updating contract state.
func applyStake(s *stakeResult) error {
deposits.Set(s.tokenId, s.deposit)
if s.owner == s.caller {
if err := transferDeposit(s.tokenId, s.owner, s.caller, consts.STAKER_ADDR); err != nil { // <-
return err
}
}
pn.SetPositionOperator(s.tokenId, s.caller)
positionsInternalWarmUpAmount[s.tokenId] = warmUpAmount{}
return nil
}
func transferDeposit(tokenId uint64, owner, caller, to std.Address) error {
if caller == to {
return ufmt.Errorf(
"%v: only owner(%s) can transfer tokenId(%d), called from %s",
errNoPermission, owner, tokenId, caller,
) // <-
}
// transfer NFT ownership
gnft.TransferFrom(a2u(owner), a2u(to), tid(tokenId))
return nil
}
} | ||
|
||
externalWarmUpAmount, exist := positionsExternalWarmUpAmount[tokenId][incentiveId] | ||
externalWarmUpAmount, exist := positionsExternalWarmUpAmount[tokenId][ictvId] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate getter(and setter) will be much better for nested avl datas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as here: #437 (comment)
that global variable will be removed
staker/reward_recipient_store.gno
Outdated
// Add position's liquidity to total liquidity | ||
positionLiquidity := position.GetLiquidity() | ||
if positionLiquidity != nil { | ||
p.totalLiquidity.Add(p.totalLiquidity, positionLiquidity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
liquidity is already huge number (that's why we use uint256 for it).
adding u256 + u256 does need overflow check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
branch has merged with PR #438 |
Description
staker
file to a separatestaker_external_incentive
filegetTokenPairBalanceFromPosition
functionpn.PositionGetPositionPoolKey(tokenId)
method, it is unnecessary to process it internally.Newly Added Test Files
manage_pool_tiers
reward_internal_emission
reward_manager
reward_recipient_store
staker
Test Result