Skip to content

Commit

Permalink
chore: implemented feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Jun 7, 2024
1 parent 7cb0734 commit 517b9e3
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
13 changes: 6 additions & 7 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4757,21 +4757,20 @@ paths:
min_funding_amount is the minimum required amount of
this denom that needs

to be funded. this has to be an Int because else a
coin with 18 decimals could
to be funded. It is of type math.Int since a uint64
is not sufficient for a

only have a max value of 18
coin with 18 decimals
min_funding_amount_per_bundle:
type: string
title: >-
min_funding_amount_per_bundle is the minimum
required amount of this denom

that needs to be funded per bundle. this has to be
an Int because else a
that needs to be funded per bundle. It is of type
math.Int since a uint64

coin with 18 decimals could only have a max value of
18
is not sufficient for a coin with 18 decimals
coin_weight:
type: string
description: >-
Expand Down
8 changes: 4 additions & 4 deletions proto/kyve/funders/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ message WhitelistCoinEntry {
// coin_decimals are the decimals of the coin
uint32 coin_decimals = 2;
// min_funding_amount is the minimum required amount of this denom that needs
// to be funded. this has to be an Int because else a coin with 18 decimals could
// only have a max value of 18
// to be funded. It is of type math.Int since a uint64 is not sufficient for a
// coin with 18 decimals
string min_funding_amount = 3 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// min_funding_amount_per_bundle is the minimum required amount of this denom
// that needs to be funded per bundle. this has to be an Int because else a
// coin with 18 decimals could only have a max value of 18
// that needs to be funded per bundle. It is of type math.Int since a uint64
// is not sufficient for a coin with 18 decimals
string min_funding_amount_per_bundle = 4 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
Expand Down
6 changes: 5 additions & 1 deletion testutil/integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package integration

import (
"cosmossdk.io/math"
"fmt"
globalTypes "github.com/KYVENetwork/chain/x/global/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (suite *KeeperTestSuite) MustNewIntFromStr(amount string) math.Int {
result, _ := math.NewIntFromString(amount)
result, ok := math.NewIntFromString(amount)
if !ok {
panic(fmt.Sprintf("error parsing \"%s\" to math.Int", amount))
}
return result
}

Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const (

var (
KYVE_DENOM = globalTypes.Denom
A_DENOM = "acoin"
A_DENOM = "zcoin"
B_DENOM = "bcoin"
C_DENOM = "ccoin"
)
Expand Down
6 changes: 4 additions & 2 deletions x/bundles/keeper/keeper_suite_inflation_splitting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,8 @@ var _ = Describe("inflation splitting", Ordered, func() {
Expect(c2.Sub(c1...).AmountOf(i.C_DENOM).Uint64()).To(BeZero())

// assert total pool funds
Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId)[0].Amount.Uint64()).To(Equal(200*i.KYVE - 10_000))
Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId).AmountOf(i.A_DENOM).Int64()).To(Equal(200*i.T_KYVE - 2*amountPerBundle))
Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId).AmountOf(i.B_DENOM).Int64()).To(Equal(200*i.T_KYVE - 4*amountPerBundle))
Expect(fundingState.ActiveFunderAddresses).To(HaveLen(2))
})

Expand Down Expand Up @@ -1642,7 +1643,8 @@ var _ = Describe("inflation splitting", Ordered, func() {
Expect(c2.Sub(c1...).AmountOf(i.C_DENOM).Uint64()).To(BeZero())

// assert total pool funds
Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId)[0].Amount.Uint64()).To(Equal(200*i.KYVE - 10_000))
Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId).AmountOf(i.A_DENOM).Int64()).To(Equal(200*i.T_KYVE - 2*amountPerBundle))
Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId).AmountOf(i.B_DENOM).Int64()).To(Equal(200*i.T_KYVE - 4*amountPerBundle))
Expect(fundingState.ActiveFunderAddresses).To(HaveLen(2))
})

Expand Down
1 change: 0 additions & 1 deletion x/bundles/keeper/keeper_suite_valid_bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var _ = Describe("valid bundles", Ordered, func() {
var initialBalanceStaker0, initialBalanceValaddress0, initialBalanceStaker1, initialBalanceValaddress1, initialBalanceStaker2, initialBalanceValaddress2 sdk.Coins

amountPerBundle := int64(10_000)

BeforeEach(func() {
// init new clean chain
s = i.NewCleanChain()
Expand Down
13 changes: 11 additions & 2 deletions x/bundles/keeper/logic_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,25 @@ func (k Keeper) calculatePayouts(ctx sdk.Context, poolId uint64, totalPayout sdk
// funds left of each coin, and in the case there are not enough the coins are removed and therefore for the
// next bundle we split between the other remaining coins.
whitelist := k.fundersKeeper.GetCoinWhitelistMap(ctx)
// wantedStorageRewards are the amounts based on the current storage cost we want to pay out, this can be more
// than we have available in totalPayout
wantedStorageRewards := sdk.NewCoins()
// storageCostPerCoin is the storage cost in $USD for each coin. This implies that each coin contributes the same
// amount of value to the storage rewards
storageCostPerCoin := k.GetStorageCost(ctx, bundleProposal.StorageProviderId).MulInt64(int64(bundleProposal.DataSize)).QuoInt64(int64(totalPayout.Len()))
for _, coin := range totalPayout {
weight := whitelist[coin.Denom].CoinWeight
if weight.IsZero() {
continue
}

amount := storageCostPerCoin.Mul(math.LegacyNewDec(10).Power(uint64(whitelist[coin.Denom].CoinDecimals))).Quo(weight)
wantedStorageRewards = wantedStorageRewards.Add(sdk.NewCoin(coin.Denom, amount.TruncateInt()))
// currencyUnit is the amount of base denoms of the currency
currencyUnit := math.LegacyNewDec(10).Power(uint64(whitelist[coin.Denom].CoinDecimals))
// amount is the value of storageCostPerCoin in the base denomination of the currency. We calculate this
// by multiplying first with the amount of base denoms of the currency and then divide this by the $USD
// value per currency unit which is the weight.
amount := storageCostPerCoin.Mul(currencyUnit).Quo(weight).TruncateInt()
wantedStorageRewards = wantedStorageRewards.Add(sdk.NewCoin(coin.Denom, amount))
}

// we take the min here since there can be the case where we want to charge more coins for the storage
Expand Down
3 changes: 3 additions & 0 deletions x/funders/types/funders.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
func (f *Funding) GetScore(whitelist map[string]WhitelistCoinEntry) (score uint64) {
for _, coin := range f.Amounts {
if entry, found := whitelist[coin.Denom]; found {
// we first multiply the coin weight which is the USD value per currency unit and then times the amount,
// because dividing with the amount of base denoms (10^coin_decimals) first could exceed the decimal
// precision of 18
score += uint64(entry.CoinWeight.MulInt(coin.Amount).Quo(math.LegacyNewDec(10).Power(uint64(entry.CoinDecimals))).TruncateInt64())
}
}
Expand Down
8 changes: 4 additions & 4 deletions x/funders/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 517b9e3

Please sign in to comment.