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

refactor(staker): staker #437

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 35 additions & 35 deletions staker/_GET_no_receiver.gno
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func StakerPoolIncentives(poolPath string) []string {
CalcPoolPosition()
}

incentives, exist := poolIncentives[poolPath]
ictvList, exist := poolIncentives.Get(poolPath)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerPoolIncentives() || poolPath(%s) incentives does not exist", poolPath),
ufmt.Sprintf("poolPath(%s) incentives does not exist", poolPath),
))
}

return incentives
return ictvList
}

// StakerIncentiveTargetPoolPath returns the target pool path for a given incentive
Expand All @@ -59,15 +59,15 @@ func StakerIncentiveTargetPoolPath(incentiveId string) string {
CalcPoolPosition()
}

incentive, exist := incentives[incentiveId]
ictv, exist := incentives.Get(incentiveId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerIncentiveTargetPoolPath() || incentiveId(%s) incentive does not exist", incentiveId),
ufmt.Sprintf("incentiveId(%s) incentive does not exist", incentiveId),
))
}

return incentive.targetPoolPath
return ictv.targetPoolPath
}

// StakerIncentiveRewardToken returns the reward token for a given incentive
Expand All @@ -88,15 +88,15 @@ func StakerIncentiveRewardToken(incentiveId string) string {
CalcPoolPosition()
}

incentive, exist := incentives[incentiveId]
ictv, exist := incentives.Get(incentiveId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerIncentiveRewardToken() || incentiveId(%s) incentive does not exist", incentiveId),
ufmt.Sprintf("incentiveId(%s) incentive does not exist", incentiveId),
))
}

return incentive.rewardToken
return ictv.rewardToken
}

// StakerIncentiveRewardAmount returns the reward amount for a given incentive as a Uint256
Expand All @@ -117,15 +117,15 @@ func StakerIncentiveRewardAmount(incentiveId string) *u256.Uint {
CalcPoolPosition()
}

incentive, exist := incentives[incentiveId]
ictv, exist := incentives.Get(incentiveId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerIncentiveRewardAmount() || incentiveId(%s) incentive does not exist", incentiveId),
ufmt.Sprintf("incentiveId(%s) incentive does not exist", incentiveId),
))
}

return incentive.rewardAmount
return ictv.rewardAmount
}

// StakerIncentiveRewardAmountStr returns the reward amount for a given incentive as a string
Expand All @@ -146,15 +146,15 @@ func StakerIncentiveRewardAmountStr(incentiveId string) string {
CalcPoolPosition()
}

incentive, exist := incentives[incentiveId]
ictv, exist := incentives.Get(incentiveId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerIncentiveRewardAmount() || incentiveId(%s) incentive does not exist", incentiveId),
ufmt.Sprintf("incentiveId(%s) incentive does not exist", incentiveId),
))
}

return incentive.rewardAmount.ToString()
return ictv.rewardAmount.ToString()
}

// StakerIncentiveStartTimestamp returns the start timestamp for a given incentive
Expand All @@ -175,15 +175,15 @@ func StakerIncentiveStartTimestamp(incentiveId string) int64 {
CalcPoolPosition()
}

incentive, exist := incentives[incentiveId]
ictv, exist := incentives.Get(incentiveId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerIncentiveStartTimestamp() || incentiveId(%s) incentive does not exist", incentiveId),
ufmt.Sprintf("incentiveId(%s) incentive does not exist", incentiveId),
))
}

return incentive.startTimestamp
return ictv.startTimestamp
}

// StakerIncentiveEndTimestamp returns the end timestamp for a given incentive
Expand All @@ -204,15 +204,15 @@ func StakerIncentiveEndTimestamp(incentiveId string) int64 {
CalcPoolPosition()
}

incentive, exist := incentives[incentiveId]
ictv, exist := incentives.Get(incentiveId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerIncentiveEndTimestamp() || incentiveId(%s) incentive does not exist", incentiveId),
ufmt.Sprintf("incentiveId(%s) incentive does not exist", incentiveId),
))
}

return incentive.endTimestamp
return ictv.endTimestamp
}

// StakerIncentiveRefundee returns the refundee address for a given incentive
Expand All @@ -233,15 +233,15 @@ func StakerIncentiveRefundee(incentiveId string) std.Address {
CalcPoolPosition()
}

incentive, exist := incentives[incentiveId]
ictv, exist := incentives.Get(incentiveId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerIncentiveRefundee() || incentiveId(%s) incentive does not exist", incentiveId),
ufmt.Sprintf("incentiveId(%s) incentive does not exist", incentiveId),
))
}

return incentive.refundee
return ictv.refundee
}

// StakerDepositOwner returns the owner address of a deposit for a given LP token ID
Expand All @@ -262,11 +262,11 @@ func StakerDepositOwner(lpTokenId uint64) std.Address {
CalcPoolPosition()
}

deposit, exist := deposits[lpTokenId]
deposit, exist := deposits.Get(lpTokenId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerDepositOwner() || tokenId(%d) deposit does not exist", lpTokenId),
ufmt.Sprintf("tokenId(%d) deposit does not exist", lpTokenId),
))
}

Expand All @@ -291,11 +291,11 @@ func StakerDepositNumberOfStakes(lpTokenId uint64) uint64 {
CalcPoolPosition()
}

deposit, exist := deposits[lpTokenId]
deposit, exist := deposits.Get(lpTokenId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerDepositNumberOfStakes() || tokenId(%d) deposit does not exist", lpTokenId),
ufmt.Sprintf("tokenId(%d) deposit does not exist", lpTokenId),
))
}

Expand All @@ -320,11 +320,11 @@ func StakerDepositStakeTimestamp(lpTokenId uint64) int64 {
CalcPoolPosition()
}

deposit, exist := deposits[lpTokenId]
deposit, exist := deposits.Get(lpTokenId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerDepositStakeTimestamp() || tokenId(%d) deposit does not exist", lpTokenId),
ufmt.Sprintf("tokenId(%d) deposit does not exist", lpTokenId),
))
}

Expand All @@ -349,11 +349,11 @@ func StakerDepositTargetPoolPath(lpTokenId uint64) string {
CalcPoolPosition()
}

deposit, exist := deposits[lpTokenId]
deposit, exist := deposits.Get(lpTokenId)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerDepositTargetPoolPath() || tokenId(%d) deposit does not exist", lpTokenId),
ufmt.Sprintf("tokenId(%d) deposit does not exist", lpTokenId),
))
}

Expand All @@ -371,13 +371,13 @@ func StakerDepositTargetPoolPath(lpTokenId uint64) string {
// Panics:
// - If the pool tier does not exist for the given poolPath
func StakerPoolTier(poolPath string) uint64 {
internal, exist := poolTiers[poolPath]
internalTier, exist := poolTiers.Get(poolPath)
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("_GET_no_receiver.gno__StakerPoolTier() || poolPath(%s) poolTier does not exist", poolPath),
ufmt.Sprintf("poolPath(%s) poolTier does not exist", poolPath),
))
}

return internal.tier
return internalTier.Tier()
}
14 changes: 7 additions & 7 deletions staker/_GET_qa_internal_emission.gno
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func GetPrintInfo() string {
emissionDebug.GnsProtocolFee = gns.BalanceOf(a2u(consts.PROTOCOL_FEE_ADDR))
emissionDebug.GnsADMIN = gns.BalanceOf(a2u(consts.ADMIN))

for poolPath, internal := range poolTiers {
tier := internal.tier
poolTiers.Iter(func(poolPath string, internalTier InternalTier) {
tier := internalTier.tier
pool := ApiEmissionDebugPool{}
pool.PoolPath = poolPath
pool.Tier = tier
Expand Down Expand Up @@ -158,7 +158,7 @@ func GetPrintInfo() string {
}

emissionDebug.Pool = append(emissionDebug.Pool, pool)
}
})

node := json.ObjectNode("", map[string]*json.Node{
"height": json.NumberNode("", float64(emissionDebug.Height)),
Expand All @@ -185,10 +185,10 @@ func GetPrintInfo() string {
func makePoolsNode(emissionPool []ApiEmissionDebugPool) []*json.Node {
pools := make([]*json.Node, 0)

for poolPath, internal := range poolTiers {
poolTiers.Iter(func(poolPath string, internalTier InternalTier) {
numTier1, numTier2, numTier3 := getNumPoolTiers()
numPoolSameTier := uint64(0)
tier := internal.tier
tier := internalTier.tier
if tier == 1 {
numPoolSameTier = numTier1
} else if tier == 2 {
Expand All @@ -199,13 +199,13 @@ func makePoolsNode(emissionPool []ApiEmissionDebugPool) []*json.Node {

pools = append(pools, json.ObjectNode("", map[string]*json.Node{
"poolPath": json.StringNode("poolPath", poolPath),
"startTimestamp": json.NumberNode("startTimestamp", float64(internal.startTimestamp)),
"startTimestamp": json.NumberNode("startTimestamp", float64(internalTier.startTimestamp)),
"tier": json.NumberNode("tier", float64(tier)),
"numPoolSameTier": json.NumberNode("numPoolSameTier", float64(numPoolSameTier)),
"poolReward": json.NumberNode("poolReward", float64(poolGns[poolPath])),
"position": json.ArrayNode("", makePositionsNode(poolPath)),
}))
}
})

return pools
}
Expand Down
Loading
Loading