Skip to content

Commit

Permalink
Merge branch 'mconcat/refactor-emission-part-1' of github.com:gnoswap…
Browse files Browse the repository at this point in the history
…-labs/gnoswap into mconcat/refactor-emission-part-1
  • Loading branch information
mconcat committed Dec 30, 2024
2 parents a50ce35 + cf77377 commit 08c4de1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ type ApiEmissionDebugPosition struct {
}

func GetPrintInfo() string {
/*
emissionDebug := ApiEmissionDebugInfo{}
emissionDebug.Height = std.GetHeight()
emissionDebug.Time = time.Now().Unix()
Expand All @@ -127,7 +126,7 @@ func GetPrintInfo() string {
pool.PoolPath = poolPath
pool.Tier = tier

numTier1, numTier2, numTier3 := getNumPoolTiers()
numTier1, numTier2, numTier3 := getNumPoolTiers(t)
if tier == 1 {
pool.NumPoolInSameTier = numTier1
} else if tier == 2 {
Expand All @@ -136,8 +135,6 @@ func GetPrintInfo() string {
pool.NumPoolInSameTier = numTier3
}

pool.PoolReward = poolGns[poolPath]

for lpTokenId, deposit := range deposits {
if deposit.targetPoolPath == poolPath {
position := ApiEmissionDebugPosition{}
Expand All @@ -146,10 +143,7 @@ func GetPrintInfo() string {
position.StakedTimestamp = deposit.stakeTimestamp
position.StakedDuration = emissionDebug.Height - deposit.stakeHeight

position.FullAmount = positionGns[lpTokenId]
position.Ratio = getRewardRatio(position.StakedDuration)
position.RatioAmount = (position.FullAmount * position.Ratio) / 100

position.Ratio = getRewardRatio(t, position.StakedDuration)
pool.Position = append(pool.Position, position)
}
}
Expand Down Expand Up @@ -177,16 +171,13 @@ func GetPrintInfo() string {
}

return string(b)
*/
panic("SHOULD BE REIMPLEMENTED BEFORE MERGING")
}

func makePoolsNode(emissionPool []ApiEmissionDebugPool) []*json.Node {
/*
pools := make([]*json.Node, 0)

poolTiers.Iter(func(poolPath string, internalTier InternalTier) {
numTier1, numTier2, numTier3 := getNumPoolTiers()
numTier1, numTier2, numTier3 := getNumPoolTiers(t)
numPoolSameTier := uint64(0)
tier := internalTier.tier
if tier == 1 {
Expand All @@ -202,14 +193,11 @@ func makePoolsNode(emissionPool []ApiEmissionDebugPool) []*json.Node {
"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
*/
panic("SHOULD BE REIMPLEMENTED BEFORE MERGING")
}

func makePositionsNode(poolPath string) []*json.Node {
Expand Down
37 changes: 37 additions & 0 deletions staker/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func init() {
}

var (
adminAddr = consts.ADMIN
admin = pusers.AddressOrName(consts.ADMIN)
alice = pusers.AddressOrName(testutils.TestAddress("alice"))
pool = pusers.AddressOrName(consts.POOL_ADDR)
Expand Down Expand Up @@ -493,6 +494,7 @@ func burnAllNFT(t *testing.T) {
}

func TestBeforeResetObject(t *testing.T) {
t.Skip("can not be run with other tests")
// make actual data to test resetting not only position's state but also pool's state
std.TestSetRealm(adminRealm)

Expand Down Expand Up @@ -540,3 +542,38 @@ func TestBeforeResetObject(t *testing.T) {
// burnAllNFT(t)
// uassert.Equal(t, gnft.TotalSupply(), uint64(0), "gnft total supply should be 0")
// }

func deletePoolTier(t *testing.T, poolPath string) {
poolTier.changeTier(uint64(std.GetHeight()), poolPath, 0)
}

func addPoolTier(t *testing.T, poolPath string, tier uint64) {
poolTier.changeTier(uint64(std.GetHeight()), poolPath, tier)
pools.GetOrCreate(poolPath)
}

func changeWarmup(t *testing.T, index int, blockDuration int64) {
modifyWarmup(index, blockDuration)
}

func getNumPoolTiers(t *testing.T) (uint64, uint64, uint64) {
tier1Num := poolTier.count[1].tree.Size()
tier2Num := poolTier.count[2].tree.Size()
tier3Num := poolTier.count[3].tree.Size()

return uint64(tier1Num), uint64(tier2Num), uint64(tier3Num)
}

func getRewardRatio(t *testing.T, height int64) uint64 {
t.Helper()
warmups := InstantiateWarmup(height)

for _, warmup := range warmups {
if height < warmup.NextWarmupHeight {
return warmup.WarmupRatio
}
}

// passed all warmup-periods
return 100
}

0 comments on commit 08c4de1

Please sign in to comment.