Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply Module #4210

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
cf8a1c9
supply and token holder
fedekunze Apr 10, 2019
f36e8a8
move logic to bank module
fedekunze Apr 10, 2019
e2c5216
token minter
fedekunze Apr 11, 2019
c173225
fix interfaces
fedekunze Apr 11, 2019
d18b617
supplier, bank keeper and update minting logic
fedekunze Apr 12, 2019
a8b2f9c
remove token minter as per Alessio's comments
fedekunze Apr 13, 2019
f8112f3
minor fixes to supply and keeper interfaces
fedekunze Apr 13, 2019
8dc2378
genesis, add codec and cleanup
fedekunze Apr 15, 2019
908d78b
rename pool supply; genesis supply
fedekunze Apr 15, 2019
5c1cd32
update bank keeper and holders
fedekunze Apr 15, 2019
7a3787c
use token holder on gov instead of acc
fedekunze Apr 15, 2019
949c342
minor tests instances fixes
fedekunze Apr 15, 2019
28b17e5
module supply
fedekunze Apr 16, 2019
3a5eed9
more cleanup
fedekunze Apr 16, 2019
575e484
errors and more cleanup
fedekunze Apr 16, 2019
053bb86
genesis stuff
fedekunze Apr 16, 2019
b62f9b2
fixes; now it builds
fedekunze Apr 16, 2019
4e0d389
fix total supply
fedekunze Apr 16, 2019
390d0bf
delete token holders
fedekunze Apr 18, 2019
62d8161
implement module accounts
fedekunze Apr 18, 2019
044a0c6
check for module acc on genesis
fedekunze Apr 18, 2019
913793c
update vesting and circulating supply
fedekunze Apr 18, 2019
c2b30ce
move invariants out of staking
fedekunze Apr 23, 2019
4fcf036
update gov genesis
fedekunze Apr 23, 2019
34a658a
update invariants
fedekunze Apr 23, 2019
d2c271e
more invariance and total supply
fedekunze Apr 23, 2019
a22bcca
add rewards to total supply
fedekunze Apr 23, 2019
b93fc11
add remaining
fedekunze Apr 23, 2019
021e6c9
total supply invariant
fedekunze Apr 24, 2019
6111451
changes from develop
fedekunze Apr 24, 2019
669160a
clean up mint
fedekunze Apr 24, 2019
895ce15
update module client
fedekunze Apr 24, 2019
365f9df
update supply on withdrawal
fedekunze Apr 24, 2019
896b295
update supply on deposits
fedekunze Apr 24, 2019
bcdc20a
change vesting supply to initial vesting
fedekunze Apr 24, 2019
e7cbc40
update references and aliases
fedekunze Apr 24, 2019
f83af2f
calculate total supply on initialization
fedekunze Apr 24, 2019
006c1eb
fix build
fedekunze Apr 25, 2019
bd6b5a9
initial testing
fedekunze Apr 25, 2019
e6b4e79
fix gov tests
fedekunze Apr 25, 2019
7b9dd43
add invariant to bonded tokens
fedekunze Apr 26, 2019
d612bc1
minor fixes
fedekunze Apr 26, 2019
1fddb0e
minor invariant changes
fedekunze Apr 28, 2019
392e342
fix some gov tests; pending invariance
fedekunze Apr 29, 2019
7b5bfea
changes from master
fedekunze Apr 30, 2019
b985bac
delete mint account from genaccs
fedekunze Apr 30, 2019
2f0d7d0
cleanup
fedekunze Apr 30, 2019
acdc8e2
add type supply
fedekunze Apr 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
check for module acc on genesis
  • Loading branch information
fedekunze committed Apr 18, 2019
commit 044a0c69b5ede2a507d901ded7ab49227b5f273f
62 changes: 41 additions & 21 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ type GenesisAccount struct {
DelegatedVesting sdk.Coins `json:"delegated_vesting"` // delegated vesting coins at time of delegation
StartTime int64 `json:"start_time"` // vesting start time (UNIX Epoch time)
EndTime int64 `json:"end_time"` // vesting end time (UNIX Epoch time)

// module account fields
Module string `json:"module"` // name of the module
AllowMint bool `json:"allow_mint"` // checks for module account type
}

// NewGenesisAccount creates a GenesisAccount instance from a BaseAccount
func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount {
return GenesisAccount{
Address: acc.Address,
Expand All @@ -109,6 +114,7 @@ func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount {
}
}

// NewGenesisAccountI creates a GenesisAccount instance from an Account interface
func NewGenesisAccountI(acc auth.Account) GenesisAccount {
gacc := GenesisAccount{
Address: acc.GetAddress(),
Expand All @@ -126,10 +132,20 @@ func NewGenesisAccountI(acc auth.Account) GenesisAccount {
gacc.EndTime = vacc.GetEndTime()
}

macc, ok := acc.(auth.ModuleAccount)
if ok {
gacc.Module = macc.GetModuleName()
if err := macc.SetCoins(macc.GetCoins()); err == nil {
gacc.AllowMint = true
} else {
gacc.AllowMint = false
}
}

return gacc
}

// convert GenesisAccount to auth.BaseAccount
// ToAccount converts a GenesisAccount to an Account interface
func (ga *GenesisAccount) ToAccount() auth.Account {
bacc := &auth.BaseAccount{
Address: ga.Address,
Expand All @@ -138,6 +154,7 @@ func (ga *GenesisAccount) ToAccount() auth.Account {
Sequence: ga.Sequence,
}

// vesting accounts
if !ga.OriginalVesting.IsZero() {
baseVestingAcc := &auth.BaseVestingAccount{
BaseAccount: bacc,
Expand All @@ -161,10 +178,18 @@ func (ga *GenesisAccount) ToAccount() auth.Account {
}
}

// module accounts
if ga.Module != "" {
if ga.AllowMint {
return auth.NewModuleMinterAccount(ga.Module)
}
return auth.NewModuleHolderAccount(ga.Module)
}

return bacc
}

// Create the core parameters for genesis initialization for gaia
// GaiaAppGenState creates the core parameters for genesis initialization for gaia
// note that the pubkey input is this machines pubkey
func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) (
genesisState GenesisState, err error) {
Expand Down Expand Up @@ -196,14 +221,8 @@ func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []js
}
}

circulatingSupply, vestingSupply, notBondedSupply, bondedSupply :=
supplyFromGenAccounts(genesisState.Accounts, genesisState.StakingData.Params.BondDenom)

// update supply
genesisState.SupplyData.Supplier.CirculatingSupply = circulatingSupply
genesisState.SupplyData.Supplier.VestingSupply = vestingSupply
genesisState.SupplyData.Supplier.TotalSupply =
genesisState.SupplyData.Supplier.TotalSupply.Add(circulatingSupply).Add(vestingSupply)
notBondedSupply, bondedSupply :=
updateSupply(genesisState.Accounts, genesisState.StakingData.Params.BondDenom, &genesisState.SupplyData.Supplier)

genesisState.StakingData.Pool.NotBondedTokens = notBondedSupply
genesisState.StakingData.Pool.BondedTokens = bondedSupply
Expand Down Expand Up @@ -417,21 +436,22 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
return appGenTxs, persistentPeers, nil
}

// supplyFromGenAccounts calculates the circulating, vesting, and stakingToken
// (bonded and not bonded) total supply from the genesis accounts
func supplyFromGenAccounts(genAccounts []GenesisAccount, bondDenom string,
) (
circulatingSupply, vestingSupply sdk.Coins,
notBondedTokens, bondedTokens sdk.Int,
) {
// updateSupply calculates the circulating, vesting, and staking (bonded and not bonded)
// total supply from the genesis accounts
func updateSupply(genAccounts []GenesisAccount, bondDenom string, supplier *supply.Supplier) (notBondedTokens, bondedTokens sdk.Int) {

for _, genAcc := range genAccounts {

// circulating amount not subject to vesting (i.e free)
circulatingSupply = circulatingSupply.Add(genAcc.Coins)
supplier.Inflate(supply.TypeCirculating, genAcc.OriginalVesting)

// vesting and bonded supply from vesting accounts
if genAcc.DelegatedVesting.IsAllPositive() {
vestingSupply = vestingSupply.Add(genAcc.OriginalVesting)
bondedTokens = bondedTokens.Add(genAcc.DelegatedVesting.AmountOf(bondDenom))
if genAcc.OriginalVesting.IsAllPositive() {
supplier.Inflate(supply.TypeVesting, genAcc.OriginalVesting)

if genAcc.DelegatedVesting.IsAllPositive() {
bondedTokens = bondedTokens.Add(genAcc.DelegatedVesting.AmountOf(bondDenom))
}
}

// staking pool's not bonded supply
Expand Down
49 changes: 28 additions & 21 deletions x/auth/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,44 +520,51 @@ func (dva *DelayedVestingAccount) GetEndTime() int64 {
}

//-----------------------------------------------------------------------------
// Module Holder Account
// Module Minter Account

var _ ModuleAccount = (*ModuleHolderAccount)(nil)
var _ ModuleAccount = (*ModuleMinterAccount)(nil)

// ModuleHolderAccount defines an account for modules that held coins on a pool
type ModuleHolderAccount struct {
// ModuleMinterAccount defines an account for modules that held coins on a pool
type ModuleMinterAccount struct {
*BaseAccount

Module string `json:"module"` // name of the module
}

// NewModuleHolderAccount creates a new BaseTokenHolder instance
func NewModuleHolderAccount(baseAcc *BaseAccount, moduleName string) *ModuleHolderAccount {
return &ModuleHolderAccount{
BaseAccount: baseAcc,
// NewModuleMinterAccount creates a new BaseTokenHolder instance
func NewModuleMinterAccount(moduleName string) *ModuleMinterAccount {
moduleAddress := sdk.AccAddress(crypto.AddressHash([]byte(moduleName)))

baseAcc := NewBaseAccountWithAddress(moduleAddress)
return &ModuleMinterAccount{
BaseAccount: &baseAcc,
Module: moduleName,
}
}

// GetModuleName returns the the name of the holder's module
func (mha ModuleHolderAccount) GetModuleName() string {
return mha.Module
func (mma ModuleMinterAccount) GetModuleName() string {
return mma.Module
}

//-----------------------------------------------------------------------------
// Module Minter Account
// Module Holder Account

var _ ModuleAccount = (*ModuleMinterAccount)(nil)
var _ ModuleAccount = (*ModuleHolderAccount)(nil)

// ModuleMinterAccount defines an account for modules that held coins on a pool
type ModuleMinterAccount struct {
*ModuleHolderAccount
// ModuleHolderAccount defines an account for modules that held coins on a pool
type ModuleHolderAccount struct {
*ModuleMinterAccount
}

// NewModuleMinterAccount creates a new BaseTokenHolder instance
func NewModuleMinterAccount(baseAcc *BaseAccount, moduleName string) *ModuleHolderAccount {
return &ModuleHolderAccount{
BaseAccount: baseAcc,
Module: moduleName,
}
// NewModuleHolderAccount creates a new BaseTokenHolder instance
func NewModuleHolderAccount(moduleName string) *ModuleHolderAccount {
moduleMinterAcc := NewModuleMinterAccount(moduleName)

return &ModuleHolderAccount{ModuleMinterAccount: moduleMinterAcc}
}

// SetCoins not supported for ModuleHolderAccount
func (mha ModuleHolderAccount) SetCoins(coins sdk.Coins) error {
return fmt.Errorf("module holders account don't support setting coins")
}
3 changes: 1 addition & 2 deletions x/supply/types/supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DefaultSupplier() Supplier {
}

// Inflate adds coins to a given supply type and updates the total supply
func (supplier *Supplier) Inflate(supplyType string, amount sdk.Coins) error {
func (supplier *Supplier) Inflate(supplyType string, amount sdk.Coins) {
switch supplyType {
case TypeCirculating:
supplier.CirculatingSupply = supplier.CirculatingSupply.Add(amount)
Expand All @@ -49,7 +49,6 @@ func (supplier *Supplier) Inflate(supplyType string, amount sdk.Coins) error {
panic(fmt.Errorf("invalid type %s", supplyType))
}
supplier.TotalSupply = supplier.TotalSupply.Add(amount)
return nil
}

// Deflate safe subtracts coins for a given supply and updates the total supply
Expand Down