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

Define new method to handle zero max cap #1

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bfe1849
Define new method to handle zero max cap
trinitys7 Jun 24, 2024
81458a6
Move update delegation to separate msg, revert change in bond and unbond
trinitys7 Jul 3, 2024
d05c51d
Fix e2e starship test
trinitys7 Jul 5, 2024
6387998
minor changes on valset updates
trinitys7 Jul 5, 2024
2ad925d
fix e2e slashing test
trinitys7 Jul 5, 2024
01165ea
make max_retrieve init variable works with e2e
trinitys7 Jul 9, 2024
b428fa6
fix abci test
trinitys7 Jul 9, 2024
dd148a1
add genesis cmd and run node
likesToEatFish Jul 18, 2024
4b109ce
Merge pull request #178 from decentrio/duong/runnode
vuong177 Jul 22, 2024
aa1ab2b
init meshsecurityprovider module
vuong177 Jul 26, 2024
8f8145d
Merge pull request #181 from osmosis-labs/vuong/provider-module
vuong177 Jul 26, 2024
379fa69
add handle plugin
neitdung Jul 27, 2024
4ef662b
add module provider to app
neitdung Jul 27, 2024
89c5886
update contract file and tests
neitdung Jul 27, 2024
e593473
fix consumer test
neitdung Jul 27, 2024
1e2b9e4
Merge pull request #182 from decentrio/feat/vesting-delegate-remake
vuong177 Aug 12, 2024
3fc4106
Add e2e test for stake vesting token
trinitys7 Aug 19, 2024
2922c1e
nit
trinitys7 Aug 21, 2024
c0bd5c7
Merge pull request #186 from osmosis-labs/trinity/e2etest-for-stake-v…
trinitys7 Aug 21, 2024
2830cae
merge main
trinitys7 Aug 21, 2024
2d17821
Add Zero Max Cap e2e test and fix logic
trinitys7 Aug 23, 2024
8a2f005
merge main
trinitys7 Aug 23, 2024
577a240
Remove unused field
trinitys7 Aug 23, 2024
c87ee8a
Use IsZero instead of Negative
trinitys7 Aug 23, 2024
943433d
Update proto
trinitys7 Aug 28, 2024
6663290
Merge pull request #188 from osmosis-labs/trinity/proto
vuong177 Aug 28, 2024
616de21
Merge branch 'main' into trinity/zero-max-cap
vuong177 Sep 3, 2024
082fbe5
Update schedule logic for zero max cap
trinitys7 Sep 5, 2024
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
20 changes: 20 additions & 0 deletions demo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ import (
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity"
meshseckeeper "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/keeper"
meshsectypes "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types"
meshsecprov "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider"
meshsecprovkeeper "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/keeper"
meshsecprovtypes "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types"
)

const appName = "MeshApp"
Expand Down Expand Up @@ -200,6 +203,7 @@ var (
ica.AppModuleBasic{},
ibcfee.AppModuleBasic{},
meshsecurity.AppModuleBasic{},
meshsecprov.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -263,6 +267,7 @@ type MeshApp struct {
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
MeshSecKeeper *meshseckeeper.Keeper
MeshSecProvKeeper *meshsecprovkeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -314,6 +319,7 @@ func NewMeshApp(
wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
meshsectypes.StoreKey,
meshsecprovtypes.StoreKey,
)

tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -417,6 +423,15 @@ func NewMeshApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.MeshSecProvKeeper = meshsecprovkeeper.NewKeeper(
appCodec,
keys[meshsecprovtypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.BankKeeper,
app.WasmKeeper,
app.StakingKeeper,
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
legacyAmino,
Expand Down Expand Up @@ -589,6 +604,7 @@ func NewMeshApp(
nested,
// append our custom message handler for mesh-security
meshseckeeper.NewDefaultCustomMsgHandler(app.MeshSecKeeper),
meshsecprovkeeper.CustomMessageDecorator(app.MeshSecProvKeeper),
)
})
wasmOpts = append(wasmOpts, meshMessageHandler,
Expand Down Expand Up @@ -694,6 +710,7 @@ func NewMeshApp(
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
meshsecurity.NewAppModule(appCodec, app.MeshSecKeeper),
meshsecprov.NewAppModule(app.MeshSecProvKeeper),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
)

Expand All @@ -715,6 +732,7 @@ func NewMeshApp(
ibcfeetypes.ModuleName,
wasmtypes.ModuleName,
meshsectypes.ModuleName,
meshsecprovtypes.ModuleName,
)

app.ModuleManager.SetOrderEndBlockers(
Expand All @@ -731,6 +749,7 @@ func NewMeshApp(
ibcfeetypes.ModuleName,
wasmtypes.ModuleName,
meshsectypes.ModuleName, // last to capture all chain events
meshsecprovtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -755,6 +774,7 @@ func NewMeshApp(
// wasm after ibc transfer
wasmtypes.ModuleName,
meshsectypes.ModuleName,
meshsecprovtypes.ModuleName,
}
app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down
Binary file added demo/build/meshd
Binary file not shown.
182 changes: 182 additions & 0 deletions demo/cmd/meshd/genaccount.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package main

import (
"bufio"
"encoding/json"
"errors"
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)

const (
flagVestingStart = "vesting-start-time"
flagVestingEnd = "vesting-end-time"
flagVestingAmt = "vesting-amount"
)

// AddGenesisAccountCmd returns add-genesis-account cobra Command.
func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
Short: "Add a genesis account to genesis.json",
Long: `Add a genesis account to genesis.json. The provided account must specify
the account address or key name and a list of initial coins. If a key name is given,
the address will be looked up in the local Keybase. The list of initial tokens must
contain valid denominations. Accounts may optionally be supplied with vesting parameters.
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
depCdc := clientCtx.Codec
cdc := depCdc

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config

config.SetRoot(clientCtx.HomeDir)

addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)

// attempt to lookup address from Keybase if no address was provided
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf, clientCtx.Codec)
if err != nil {
return err
}

info, err := kb.Key(args[0])
if err != nil {
return fmt.Errorf("failed to get address from Keybase: %w", err)
}

addr, err = info.GetAddress()
if err != nil {
return err
}
}

coins, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return fmt.Errorf("failed to parse coins: %w", err)
}

vestingStart, _ := cmd.Flags().GetInt64(flagVestingStart)
vestingEnd, _ := cmd.Flags().GetInt64(flagVestingEnd)
vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt)

vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr)
if err != nil {
return fmt.Errorf("failed to parse vesting amount: %w", err)
}

// create concrete account type based on input parameters
var genAccount authtypes.GenesisAccount

balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}
baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0)

if !vestingAmt.IsZero() {
baseVestingAccount := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd)

if (balances.Coins.IsZero() && !baseVestingAccount.OriginalVesting.IsZero()) ||
baseVestingAccount.OriginalVesting.IsAnyGT(balances.Coins) {
return errors.New("vesting amount cannot be greater than total amount")
}

switch {
case vestingStart != 0 && vestingEnd != 0:
genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart)

case vestingEnd != 0:
genAccount = authvesting.NewDelayedVestingAccountRaw(baseVestingAccount)

default:
return errors.New("invalid vesting parameters; must supply start and end time or end time")
}
} else {
genAccount = baseAccount
}

if err := genAccount.Validate(); err != nil {
return fmt.Errorf("failed to validate new genesis account: %w", err)
}

genFile := config.GenesisFile()
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState)

accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
if err != nil {
return fmt.Errorf("failed to get accounts from any: %w", err)
}

if accs.Contains(addr) {
return fmt.Errorf("cannot add account at existing address %s", addr)
}

// Add the new account to the set of genesis accounts and sanitize the
// accounts afterwards.
accs = append(accs, genAccount)
accs = authtypes.SanitizeGenesisAccounts(accs)

genAccs, err := authtypes.PackAccounts(accs)
if err != nil {
return fmt.Errorf("failed to convert accounts into any's: %w", err)
}
authGenState.Accounts = genAccs

authGenStateBz, err := cdc.MarshalJSON(&authGenState)
if err != nil {
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
}

appState[authtypes.ModuleName] = authGenStateBz

bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState)
bankGenState.Balances = append(bankGenState.Balances, balances)
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)

bankGenStateBz, err := cdc.MarshalJSON(bankGenState)
if err != nil {
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
}

appState[banktypes.ModuleName] = bankGenStateBz

appStateJSON, err := json.Marshal(appState)
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
}

genDoc.AppState = appStateJSON
return genutil.ExportGenesisFile(genDoc, genFile)
},
}

cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
flags.AddQueryFlagsToCmd(cmd)

return cmd
}
12 changes: 12 additions & 0 deletions demo/cmd/meshd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"fmt"
"io"
"os"

Expand Down Expand Up @@ -32,8 +33,11 @@ import (
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutil "github.com/cosmos/cosmos-sdk/x/genutil"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

"github.com/osmosis-labs/mesh-security-sdk/demo/app"
"github.com/osmosis-labs/mesh-security-sdk/demo/app/params"
Expand Down Expand Up @@ -148,11 +152,19 @@ func initAppConfig() (string, interface{}) {
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
gentxModule, ok := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
if !ok {
panic(fmt.Errorf("expected %s module to be an instance of type %T", genutiltypes.ModuleName, genutil.AppModuleBasic{}))
}
rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator),
// testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
AddGenesisAccountCmd(app.DefaultNodeHome),
debug.Cmd(),
config.Cmd(),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
pruning.PruningCmd(newApp),
)

Expand Down
18 changes: 18 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Table of Contents

- [osmosis/meshsecurity/v1beta1/meshsecurity.proto](#osmosis/meshsecurity/v1beta1/meshsecurity.proto)
- [Delegation](#osmosis.meshsecurity.v1beta1.Delegation)
- [Params](#osmosis.meshsecurity.v1beta1.Params)
- [VirtualStakingMaxCapInfo](#osmosis.meshsecurity.v1beta1.VirtualStakingMaxCapInfo)

Expand Down Expand Up @@ -41,6 +42,23 @@



<a name="osmosis.meshsecurity.v1beta1.Delegation"></a>

### Delegation
Delegation represents the bond with tokens held by an account.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `delegator_address` | [string](#string) | | delegator_address is the bech32-encoded address of the delegator. |
| `validator_address` | [string](#string) | | validator_address is the bech32-encoded address of the validator. |
| `amount` | [string](#string) | | amount define the delegation amount. |






<a name="osmosis.meshsecurity.v1beta1.Params"></a>

### Params
Expand Down
Loading