Skip to content

Commit

Permalink
adding code comments/documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
spoo-bar committed Mar 13, 2023
1 parent a8c1563 commit e8897c4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ func mintAndDistribute(k keeper.Keeper, ctx sdk.Context, tokenToMint sdk.Dec) {
denom := k.BondDenom(ctx)
mintCoin := sdk.NewInt64Coin(denom, tokenToMint.BigInt().Int64()) // as sdk.Coin

err := k.MintCoins(ctx, sdk.NewCoins(mintCoin))
err := k.MintCoins(ctx, sdk.NewCoins(mintCoin)) // mint the tokens into x/mint
if err != nil {
panic(err)
}

for _, distribution := range mintParams.GetInflationRecipients() {
amount := distribution.Ratio.MulInt(mintCoin.Amount) // totalCoinsToMint * distribution.Ratio
amount := distribution.Ratio.MulInt(mintCoin.Amount) // distribution.Ratio * mintedCoins
coin := sdk.NewCoin(denom, amount.TruncateInt()) // as sdk.Coin

err := k.SendCoinsToModule(ctx, distribution.Recipient, sdk.NewCoins(coin))
err := k.SendCoinsToModule(ctx, distribution.Recipient, sdk.NewCoins(coin)) // distribute the tokens from x/mint
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions x/mint/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

const REWARDSMODULE string = "rewards"
const REWARDS_MODULE string = "rewards"

func (s *KeeperTestSuite) TestBeginBlocker() {
currentTime := time.Now()
Expand Down Expand Up @@ -52,7 +52,7 @@ func (s *KeeperTestSuite) TestBeginBlocker() {
s.Require().True(found)
s.Require().True(rewardsCollected.Amount.GT(sdk.ZeroInt()))

s.Require().True(feeCollected.IsGTE(rewardsCollected)) // feeCollected should be greater than rewards
s.Require().True(feeCollected.IsGTE(rewardsCollected)) // feeCollected should be greater than rewards cuz we set up inflation distribution that way
})
}

Expand All @@ -66,7 +66,7 @@ func getTestParams() types.Params {
Recipient: authtypes.FeeCollectorName,
Ratio: sdk.MustNewDecFromStr("0.9"), // 90%
}, {
Recipient: REWARDSMODULE,
Recipient: REWARDS_MODULE,
Ratio: sdk.MustNewDecFromStr("0.1"), // 10%
}})
return params
Expand Down
1 change: 1 addition & 0 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (k Keeper) BondDenom(ctx sdk.Context) string {
return k.stakingKeeper.BondDenom(ctx)
}

// SendCoinsFromModuleToModule sends the given number of coins from one module account to another module account
func (k Keeper) SendCoinsToModule(ctx sdk.Context, recipientModule string, amt sdk.Coins) error {
return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, recipientModule, amt)
}
2 changes: 1 addition & 1 deletion x/mint/keeper/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (k Keeper) GetInflationForRecipient(ctx sdk.Context, recipientName string)
return mintAmount, true
}

// SetInflationForRecipient sets the sdk.Coin distributed to the given module for the current block
func (k Keeper) SetInflationForRecipient(ctx sdk.Context, recipientName string, mintAmount sdk.Coin) {
store := ctx.KVStore(k.storeKey)
value := k.cdc.MustMarshal(&mintAmount)
Expand Down Expand Up @@ -59,7 +60,6 @@ func (k Keeper) GetBlockProvisions(ctx sdk.Context) (tokens sdk.Dec, blockInflat
bondedTokenSupply := k.GetBondedTokenSupply(ctx)

tokens = blockInflation.MulInt(bondedTokenSupply.Amount).Mul(sdk.NewDecFromBigInt(big.NewInt(int64(elapsed.Seconds()))).QuoInt64(int64(Year.Seconds()))) // amount := (inflation * bondedTokenSupply) * (elapsed/Year)
//tokens = sdk.NewInt64Coin(bondDenom, tokenAmount.BigInt().Int64()) // as sdk.Coin
return
}

Expand Down
2 changes: 1 addition & 1 deletion x/mint/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type BankKeeper interface {
MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error
// GetSupply retrieves the given token supply from store
GetSupply(ctx sdk.Context, denom string) sdk.Coin

// SendCoinsFromModuleToModule sends the given number of coins from one module account to another module account
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
}

Expand Down
2 changes: 2 additions & 0 deletions x/mint/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var (
MintDistribution = []byte{0x00}
)

// GetMintDistributionRecipientKey gets the store prefix to fetch the inflation distribution for the recipient
// returns MintDistribution + currentBlockHeight + recipientName
func GetMintDistributionRecipientKey(blockHeight int64, recipientName string) []byte {
return append(append(MintDistribution, byte(blockHeight)), []byte(recipientName)...)
}
3 changes: 3 additions & 0 deletions x/rewards/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ type BankKeeperExpected interface {
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error
}

// BankKeeperExpected defines the interface for the x/mint module dependency.
type MintKeeperExpected interface {
// GetInflationForRecipient gets the sdk.Coin distributed to the given module in the current block
GetInflationForRecipient(ctx sdk.Context, recipientName string) (sdk.Coin, bool)
}

Expand Down Expand Up @@ -110,6 +112,7 @@ func (k Keeper) GetRewardsRecords(ctx sdk.Context, rewardsAddr sdk.AccAddress, p
return k.state.RewardsRecord(ctx).GetRewardsRecordByRewardsAddressPaginated(rewardsAddr, pageReq)
}

// GetInflationForRecipient gets the sdk.Coin distributed to the x/rewards in the current block
func (k Keeper) GetInflationForRewards(ctx sdk.Context) (sdk.Coin, bool) {
return k.mintKeeper.GetInflationForRecipient(ctx, types.ModuleName)
}

0 comments on commit e8897c4

Please sign in to comment.