|
| 1 | +package staker |
| 2 | + |
| 3 | +import ( |
| 4 | + "math" |
| 5 | + "std" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "gno.land/p/demo/uassert" |
| 9 | + |
| 10 | + "gno.land/r/gnoswap/v1/consts" |
| 11 | + |
| 12 | + en "gno.land/r/gnoswap/v1/emission" |
| 13 | + pl "gno.land/r/gnoswap/v1/pool" |
| 14 | + pn "gno.land/r/gnoswap/v1/position" |
| 15 | + |
| 16 | + "gno.land/r/gnoswap/v1/gnft" |
| 17 | + "gno.land/r/gnoswap/v1/gns" |
| 18 | + |
| 19 | + "gno.land/r/onbloc/bar" |
| 20 | + "gno.land/r/onbloc/baz" |
| 21 | + "gno.land/r/onbloc/qux" |
| 22 | +) |
| 23 | + |
| 24 | +var testGnsBalanceTracker gnsBalanceTracker |
| 25 | + |
| 26 | +func TestShortWarmUpInternal(t *testing.T) { |
| 27 | + testInit(t) |
| 28 | + testDoubleMint(t) |
| 29 | + testCreatePool(t) |
| 30 | + testMintBarQux100_1(t) |
| 31 | + testMintBarBaz100_2(t) |
| 32 | + testStakeToken_1(t) |
| 33 | + testSetPoolTier(t) |
| 34 | + testStakeToken_2(t) |
| 35 | +} |
| 36 | + |
| 37 | +func testInit(t *testing.T) { |
| 38 | + t.Run("init pool tiers", func(t *testing.T) { |
| 39 | + // init pool tiers |
| 40 | + // tier 1 |
| 41 | + // delete(poolTiers, MUST_EXISTS_IN_TIER_1) |
| 42 | + deletePoolTier(t, MUST_EXISTS_IN_TIER_1) |
| 43 | + |
| 44 | + // poolTiers["gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100"] = InternalTier{ |
| 45 | + // tier: 1, |
| 46 | + // startTimestamp: time.Now().Unix(), |
| 47 | + // } |
| 48 | + addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) |
| 49 | + |
| 50 | + // override warm-up period for testing |
| 51 | + // warmUp[100] = 901 // 30m ~ |
| 52 | + // warmUp[70] = 301 // 10m ~ 30m |
| 53 | + // warmUp[50] = 151 // 5m ~ 10m |
| 54 | + // warmUp[30] = 1 // ~ 5m |
| 55 | + changeWarmup(t, 0, 150) |
| 56 | + changeWarmup(t, 1, 300) |
| 57 | + changeWarmup(t, 2, 900) |
| 58 | + changeWarmup(t, 3, math.MaxInt64) |
| 59 | + }) |
| 60 | +} |
| 61 | + |
| 62 | +func testDoubleMint(t *testing.T) { |
| 63 | + en.MintAndDistributeGns() |
| 64 | + en.MintAndDistributeGns() |
| 65 | + |
| 66 | + std.TestSkipHeights(1) |
| 67 | +} |
| 68 | + |
| 69 | +func testCreatePool(t *testing.T) { |
| 70 | + t.Run("create pool", func(t *testing.T) { |
| 71 | + std.TestSetRealm(adminRealm) |
| 72 | + |
| 73 | + gns.Approve(a2u(consts.POOL_ADDR), pl.GetPoolCreationFee()*3) |
| 74 | + |
| 75 | + pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") |
| 76 | + pl.CreatePool(barPath, bazPath, 3000, "79228162514264337593543950337") |
| 77 | + |
| 78 | + std.TestSkipHeights(1) |
| 79 | + }) |
| 80 | +} |
| 81 | + |
| 82 | +func testMintBarQux100_1(t *testing.T) { |
| 83 | + t.Run("mint bar qux 100", func(t *testing.T) { |
| 84 | + std.TestSetRealm(adminRealm) |
| 85 | + |
| 86 | + bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) |
| 87 | + qux.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) |
| 88 | + |
| 89 | + tokenId, liquidity, amount0, amount1 := pn.Mint( |
| 90 | + barPath, // token0 |
| 91 | + quxPath, // token1 |
| 92 | + fee100, // fee |
| 93 | + int32(-1000), // tickLower |
| 94 | + int32(1000), // tickUpper |
| 95 | + "50", // amount0Desired |
| 96 | + "50", // amount1Desired |
| 97 | + "1", // amount0Min |
| 98 | + "1", // amount1Min |
| 99 | + max_timeout, |
| 100 | + adminAddr, |
| 101 | + adminAddr, |
| 102 | + ) |
| 103 | + |
| 104 | + uassert.Equal(t, tokenId, uint64(1)) |
| 105 | + uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) |
| 106 | + |
| 107 | + // gpi := GetPrintInfo() |
| 108 | + // uassert.Equal(t, gpi, `{"height":126,"time":1234567896,"gns":{"staker":0,"devOps":8561643,"communityPool":34246574,"govStaker":0,"protocolFee":200000000,"GnoswapAdmin":99999800000000},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","startTimestamp":1234567890,"tier":1,"numPoolSameTier":1,"poolReward":0,"position":[]}]}`) |
| 109 | + |
| 110 | + std.TestSkipHeights(1) |
| 111 | + }) |
| 112 | +} |
| 113 | + |
| 114 | +func testMintBarBaz100_2(t *testing.T) { |
| 115 | + t.Run("mint bar baz 100", func(t *testing.T) { |
| 116 | + std.TestSetRealm(adminRealm) |
| 117 | + |
| 118 | + bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) |
| 119 | + baz.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) |
| 120 | + |
| 121 | + testGnsBalanceTracker = gnsBalanceCheck(t, testGnsBalanceTracker, false) |
| 122 | + |
| 123 | + tokenId, liquidity, amount0, amount1 := pn.Mint( |
| 124 | + barPath, // token0 |
| 125 | + bazPath, // token1 |
| 126 | + fee3000, // fee |
| 127 | + int32(-1020), // tickLower |
| 128 | + int32(1020), // tickUpper |
| 129 | + "50", // amount0Desired |
| 130 | + "50", // amount1Desired |
| 131 | + "1", // amount0Min |
| 132 | + "1", // amount1Min |
| 133 | + max_timeout, |
| 134 | + adminAddr, |
| 135 | + adminAddr, |
| 136 | + ) |
| 137 | + std.TestSkipHeights(1) |
| 138 | + |
| 139 | + uassert.Equal(t, tokenId, uint64(2)) |
| 140 | + uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) |
| 141 | + |
| 142 | + // gpi := GetPrintInfo() |
| 143 | + // uassert.Equal(t, gpi, `{"height":127,"time":1234567898,"gns":{"staker":0,"devOps":11415524,"communityPool":45662099,"govStaker":0,"protocolFee":200000000,"GnoswapAdmin":99999800000000},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","startTimestamp":1234567890,"tier":1,"numPoolSameTier":1,"poolReward":0,"position":[]}]}`) |
| 144 | + testGnsBalanceTracker = gnsBalanceCheck(t, testGnsBalanceTracker, true) |
| 145 | + |
| 146 | + }) |
| 147 | +} |
| 148 | + |
| 149 | +func testStakeToken_1(t *testing.T) { |
| 150 | + t.Run("stake token 1", func(t *testing.T) { |
| 151 | + std.TestSetRealm(adminRealm) |
| 152 | + |
| 153 | + testGnsBalanceTracker = gnsBalanceCheck(t, testGnsBalanceTracker, false) |
| 154 | + gnft.Approve(consts.STAKER_ADDR, tid(1)) |
| 155 | + StakeToken(1) |
| 156 | + std.TestSkipHeights(1) |
| 157 | + |
| 158 | + testGnsBalanceTracker = gnsBalanceCheck(t, testGnsBalanceTracker, true) |
| 159 | + |
| 160 | + // 1 block passed |
| 161 | + positionRewards := calcPositionReward(uint64(std.GetHeight()), 1) |
| 162 | + rewardPerWarmUp, penaltyPerWarmUp, rewardPerIncentivePerWarmUp, penaltyPertIncentivePerWarmUp := positionRewards.Internal, positionRewards.InternalPenalty, positionRewards.External, positionRewards.ExternalPenalty |
| 163 | + |
| 164 | + // uassert.Equal(t, uint64(6421232), rewardPerWarmUp[0]) |
| 165 | + |
| 166 | + println("rewardPerWarmUp") |
| 167 | + println(rewardPerWarmUp) |
| 168 | + println() |
| 169 | + println("penaltyPerWarmUp") |
| 170 | + println(penaltyPerWarmUp) |
| 171 | + println() |
| 172 | + println("rewardPerIncentivePerWarmUp") |
| 173 | + println(rewardPerIncentivePerWarmUp) |
| 174 | + println() |
| 175 | + println("penaltyPertIncentivePerWarmUp") |
| 176 | + println(penaltyPertIncentivePerWarmUp) |
| 177 | + println() |
| 178 | + }) |
| 179 | +} |
| 180 | + |
| 181 | +func testSetPoolTier(t *testing.T) { |
| 182 | + t.Run("set pool tier", func(t *testing.T) { |
| 183 | + |
| 184 | + std.TestSetRealm(adminRealm) |
| 185 | + addPoolTier(t, "gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000", 2) |
| 186 | + // gpi := GetPrintInfo() |
| 187 | + // uassert.Equal(t, gpi, `{"height":129,"time":1234567902,"gns":{"staker":10702055,"devOps":17123286,"communityPool":57791094,"govStaker":0,"protocolFee":200000000,"GnoswapAdmin":99999800000000},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","startTimestamp":1234567890,"tier":1,"numPoolSameTier":1,"poolReward":10702055,"position":[{"lpTokenId":1,"stakedHeight":128,"stakedTimestamp":1234567900,"stakedDuration":1,"fullAmount":10702055,"ratio":30,"warmUpAmount":3210616,"full30":10702055,"give30":3210616,"full50":0,"give50":0,"full70":0,"give70":0,"full100":0}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","startTimestamp":1234567902,"tier":2,"numPoolSameTier":1,"poolReward":0,"position":[]}]}`) |
| 188 | + |
| 189 | + std.TestSkipHeights(1) |
| 190 | + }) |
| 191 | +} |
| 192 | + |
| 193 | +func testStakeToken_2(t *testing.T) { |
| 194 | + t.Run("stake token 2", func(t *testing.T) { |
| 195 | + |
| 196 | + std.TestSetRealm(adminRealm) |
| 197 | + |
| 198 | + gnft.Approve(consts.STAKER_ADDR, tid(2)) |
| 199 | + StakeToken(2) |
| 200 | + |
| 201 | + // gpi := GetPrintInfo() |
| 202 | + // uassert.Equal(t, gpi, `{"height":130,"time":1234567904,"gns":{"staker":18193494,"devOps":19977167,"communityPool":61715180,"govStaker":0,"protocolFee":200000000,"GnoswapAdmin":99999800000000},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","startTimestamp":1234567890,"tier":1,"numPoolSameTier":1,"poolReward":18193493,"position":[{"lpTokenId":1,"stakedHeight":128,"stakedTimestamp":1234567900,"stakedDuration":2,"fullAmount":18193493,"ratio":30,"warmUpAmount":5458047,"full30":18193493,"give30":5458047,"full50":0,"give50":0,"full70":0,"give70":0,"full100":0}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","startTimestamp":1234567902,"tier":2,"numPoolSameTier":1,"poolReward":0,"position":[{"lpTokenId":2,"stakedHeight":130,"stakedTimestamp":1234567904,"stakedDuration":0,"fullAmount":0,"ratio":0,"warmUpAmount":0,"full30":0,"give30":0,"full50":0,"give50":0,"full70":0,"give70":0,"full100":0}]}]}`) |
| 203 | + |
| 204 | + std.TestSkipHeights(1) |
| 205 | + |
| 206 | + /* |
| 207 | + 소문자 |
| 208 | + calcPositionReward |
| 209 | + |
| 210 | + 웜업별 |
| 211 | + - 리워드 |
| 212 | + - 페널티 |
| 213 | + - 익스터널 리워드 |
| 214 | + - 익스터널 페널티 |
| 215 | + - 마지막 시점부터 |
| 216 | + */ |
| 217 | + |
| 218 | + // std.TestSkipHeights(1) |
| 219 | + // calcPositionReward(uint64(std.GetHeight()), 1) |
| 220 | + }) |
| 221 | +} |
0 commit comments