Skip to content

Commit

Permalink
[CORE-645] Update test reward denom to -18 (#698)
Browse files Browse the repository at this point in the history
* update test reward denom to -18

* Update protocol/x/rewards/keeper/keeper_test.go

Co-authored-by: Crystal Lemire <crystal.lemire@gmail.com>

* Update protocol/x/rewards/keeper/keeper_test.go

Co-authored-by: Crystal Lemire <crystal.lemire@gmail.com>

* Update protocol/x/rewards/keeper/keeper_test.go

Co-authored-by: Crystal Lemire <crystal.lemire@gmail.com>

---------

Co-authored-by: Crystal Lemire <crystal.lemire@gmail.com>
  • Loading branch information
teddyding and clemire authored Oct 24, 2023
1 parent eb7c6ff commit 65f556f
Showing 1 changed file with 103 additions and 61 deletions.
164 changes: 103 additions & 61 deletions protocol/x/rewards/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ func TestAddRewardSharesForFill(t *testing.T) {
func TestProcessRewardsForBlock(t *testing.T) {
testRewardTokenMarketId := uint32(33)
testRewardTokenMarket := "test-market"
// TODO(CORE-645): Update test to -18 denom for consistency with prod.
TestRewardTokenDenomExp := int32(-6)
TestRewardTokenDenomExp := int32(-18)

tokenPrice2Usdc := pricestypes.MarketPrice{
Id: testRewardTokenMarketId,
Expand All @@ -326,17 +325,21 @@ func TestProcessRewardsForBlock(t *testing.T) {
expectedBalances []banktypes.Balance
}{
"zero reward share, no change in treasury balance": {
rewardShares: []types.RewardShare{},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewInt(1_000_000_000), // 1000 full coins
feeMultiplierPpm: 1_000_000, // 100%
rewardShares: []types.RewardShare{},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(1000, 18), // 1000 full coins
),
feeMultiplierPpm: 1_000_000, // 100%
// 1$ / 2$ * 100% = 0.5 full coin, all paid to TestAddress1
expectedBalances: []banktypes.Balance{
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(1_000_000_000),
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(1000, 18), // 1000 full coins
),
}},
},
},
Expand All @@ -348,23 +351,27 @@ func TestProcessRewardsForBlock(t *testing.T) {
Weight: dtypes.NewInt(1_000_000), // $1 weight of fee
},
},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewInt(1_000_000_000), // 1000 full coins
feeMultiplierPpm: 1_000_000, // 100%
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(1000, 18), // 1000 full coins
),
feeMultiplierPpm: 1_000_000, // 100%
// 1$ / 2$ * 100% = 0.5 full coin, all paid to TestAddress1
expectedBalances: []banktypes.Balance{
{
Address: TestAddress1,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(500_000),
Amount: sdkmath.NewInt(5e17), // 0.5 full coin
}},
},
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(999_500_000), // 999.5 full coins
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(9995, 17), // 999.5 full coins
),
}},
},
},
Expand All @@ -376,23 +383,29 @@ func TestProcessRewardsForBlock(t *testing.T) {
Weight: dtypes.NewInt(1_000_000), // $1 weight of fee
},
},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewInt(1_000_000_000), // 1000 full coins
feeMultiplierPpm: 950_000, // 95%
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(1, 20), // 100 full coins
),
feeMultiplierPpm: 950_000, // 95%
// 1$ / 2$ * 95% = 0.475 full coin, all paid to TestAddress1
expectedBalances: []banktypes.Balance{
{
Address: TestAddress1,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(475_000),
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(475, 15), // 0.475 full coin
),
}},
},
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(999_525_000), // 999.525 full coins
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(99525, 15), // 99.525 full coin
),
}},
},
},
Expand All @@ -404,16 +417,20 @@ func TestProcessRewardsForBlock(t *testing.T) {
Weight: dtypes.NewInt(1_000_000), // $1 weight of fee
},
},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewInt(200_000), // 0.2 full coin
feeMultiplierPpm: 1_000_000, // 100%
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(2, 17), // 0.2 full coins
),
feeMultiplierPpm: 1_000_000, // 100%
// 1$ / 2$ * 100% = 0.5 full coin > 0.2 full coin. Pay 0.2 full coin to TestAddress1.
expectedBalances: []banktypes.Balance{
{
Address: TestAddress1,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(200_000),
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(2, 17), // 0.2 full coins
),
}},
},
ZeroTreasuryAccountBalance, // No balance left in treasury.
Expand Down Expand Up @@ -457,38 +474,44 @@ func TestProcessRewardsForBlock(t *testing.T) {
},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(2_000_123, 18), //~2_000_123 full coin.
), // 1000 full coins
big_testutil.Int64MulPow10(2_000_123, 18), // ~2_000_123 full coin.
),
feeMultiplierPpm: 990_000, // 99%
expectedBalances: []banktypes.Balance{
{
Address: TestAddress1,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(507_667_050), // $1 weight / $2 price * 99% = 0.495 full coin
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.MustFirst(new(big.Int).SetString("507667050000000000000", 10)),
), // $1025.59 weight / $2 price * 99% ~= 507.667 full coin
}},
},
{
Address: TestAddress2,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(1_000_543_500), // $2021.3 weight / $2 price * 99% ~= 1000 full coin
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.MustFirst(new(big.Int).SetString("1000543500000000000000", 10)),
), // $2021.3 weight / $2 price * 99% ~= 1000 full coin
}},
},
{
Address: TestAddress3,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(413_651_700), // $835.66 weight / $2 price * 99% ~= 413 full coin
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.MustFirst(new(big.Int).SetString("413651700000000000000", 10)),
), // $835.66 weight / $2 price * 99% ~= 413 full coin
}},
},
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.MustFirst(new(big.Int).SetString("2000122999999998078137750", 10)),
), // ~2_000_122.9 full coins
big_testutil.MustFirst(new(big.Int).SetString("1998201137750000000000000", 10)),
), // 2_000_123 - 507.667 - 1000.5435 - 413.6517 ~= 1_998_201.1 full coins
}},
},
},
Expand All @@ -508,36 +531,40 @@ func TestProcessRewardsForBlock(t *testing.T) {
Weight: dtypes.NewInt(30_000_000), // $30 weight of fee
},
},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewInt(10_000_000), // 10 full coins
feeMultiplierPpm: 1_000_000, // 100%
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(10, 18),
), // 10 full coins
feeMultiplierPpm: 1_000_000, // 100%
expectedBalances: []banktypes.Balance{
{
Address: TestAddress1,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(1_666_666), // 1/6 of 10 = 1.666666 full coins
Amount: sdkmath.NewInt(1_666_666_666_666_666_666), // 1/6 of 10 = 1.666666 full coins
}},
},
{
Address: TestAddress2,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(3_333_333), // 1/3 of 10 = 3.333333 full coins
Amount: sdkmath.NewInt(3_333_333_333_333_333_333), // 1/3 of 10 = 3.333333 full coins
}},
},
{
Address: TestAddress3,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(5_000_000), // 1/2 of 10 = 5 full coins
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(5, 18),
), // 1/2 of 10 = 5 full coins
}},
},
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(1), // 0.000001 full coins left due to rounding
Amount: sdkmath.NewInt(1), // 1e-18 full coins left due to rounding
}},
},
},
Expand All @@ -557,36 +584,44 @@ func TestProcessRewardsForBlock(t *testing.T) {
Weight: dtypes.NewInt(95_300_000), // $95.3 weight of fee (~43.05% of total weight)
},
},
tokenPrice: tokenPrice1_18Usdc,
treasuryAccountBalance: sdkmath.NewInt(100_000_000), // 100 full coins
feeMultiplierPpm: 990_000, // 99%
tokenPrice: tokenPrice1_18Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(100, 18),
), // 100 full coins
feeMultiplierPpm: 990_000, // 99%
expectedBalances: []banktypes.Balance{
{
Address: TestAddress1,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(56_722081), // 56.722081 full coins
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.MustFirst(new(big.Int).SetString("56722081676906396819", 10)),
), // 56.722081 full coins
}},
},
{
Address: TestAddress2,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(225_876), // 0.225876 full coin
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.MustFirst(new(big.Int).SetString("225876400433682688", 10)),
), // 0.225876 full coin
}},
},
{
Address: TestAddress3,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(43_052_041), // 43.052041 full coins
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.MustFirst(new(big.Int).SetString("43052041922659920491", 10)),
), // 43.052041 full coins
}},
},
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(2), // 0.000002 full coins left due to rounding
Amount: sdkmath.NewInt(2), // 2e-18 full coins left due to rounding
}},
},
},
Expand All @@ -602,29 +637,33 @@ func TestProcessRewardsForBlock(t *testing.T) {
Weight: dtypes.NewInt(1), // $0.000001 weight of fee
},
},
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewInt(1_000), // 0.001 full coins
feeMultiplierPpm: 990_000, // 0.99
tokenPrice: tokenPrice2Usdc,
treasuryAccountBalance: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(1, 15),
), // 0.001 full coins
feeMultiplierPpm: 990_000, // 0.99
expectedBalances: []banktypes.Balance{
{
Address: TestAddress1,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(999),
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewIntFromBigInt(
big_testutil.Int64MulPow10(99_999_999, 7),
), // 0.001 * 100_000_000 / 100_000_001 = 0.00099999999 full coin
}},
},
{
Address: TestAddress2,
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(0), // rounded to 0
Amount: sdkmath.NewInt(9_999_999), // rounded to 9.9e-12 full coins
}},
},
{
Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(),
Coins: []sdk.Coin{{
Denom: TestRewardTokenDenom,
Amount: sdkmath.NewInt(1),
Amount: sdkmath.NewInt(1), // 0.001 - 0.00099999999 + 9.9e-12 = 1e-18 full coin left due to rounding
}},
},
},
Expand Down Expand Up @@ -698,6 +737,9 @@ func TestProcessRewardsForBlock(t *testing.T) {
require.Equal(t,
expectedBalance.Coins[0], // Only checking reward token balance in `expectedBalances`.
gotBalance,
"expected balance: %s, got: %s",
expectedBalance.Coins[0],
gotBalance,
)
}
})
Expand Down

0 comments on commit 65f556f

Please sign in to comment.