diff --git a/app/app.go b/app/app.go index abb7b5ec..796d2486 100644 --- a/app/app.go +++ b/app/app.go @@ -108,10 +108,6 @@ import ( v1_1_2 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.2" v1_1_4 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.4" "github.com/onomyprotocol/onomy/docs" - "github.com/onomyprotocol/onomy/x/dao" - daoclient "github.com/onomyprotocol/onomy/x/dao/client" - daokeeper "github.com/onomyprotocol/onomy/x/dao/keeper" - daotypes "github.com/onomyprotocol/onomy/x/dao/types" ) const ( @@ -131,8 +127,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler { upgradeclient.CancelProposalHandler, ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler, - daoclient.FundTreasuryProposalHandler, - daoclient.ExchangeWithTreasuryProposalProposalHandler, ibcproviderclient.ConsumerAdditionProposalHandler, ibcproviderclient.ConsumerRemovalProposalHandler, ibcproviderclient.EquivocationProposalHandler, @@ -167,14 +161,12 @@ var ( evidence.AppModuleBasic{}, transfer.AppModuleBasic{}, vesting.AppModuleBasic{}, - dao.AppModuleBasic{}, ibcprovider.AppModuleBasic{}, ) // module account permissions. maccPerms = map[string][]string{ // nolint:gochecknoglobals // cosmos-sdk application style authtypes.FeeCollectorName: nil, - daotypes.ModuleName: {authtypes.Minter}, distrtypes.ModuleName: nil, minttypes.ModuleName: {authtypes.Minter}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, @@ -187,7 +179,6 @@ var ( // module accounts that are allowed to receive tokens. allowedReceivingModAcc = map[string]bool{ // nolint:gochecknoglobals // cosmos-sdk application style distrtypes.ModuleName: true, - daotypes.ModuleName: true, // provider chain note: the fee-pool is allowed to receive tokens authtypes.FeeCollectorName: true, } @@ -254,8 +245,6 @@ type OnomyApp struct { ScopedTransferKeeper capabilitykeeper.ScopedKeeper ScopedIBCProviderKeeper capabilitykeeper.ScopedKeeper - DaoKeeper daokeeper.Keeper - // mm is the module manager mm *module.Manager configurator module.Configurator @@ -382,19 +371,6 @@ func New( // nolint:funlen // app new cosmos func // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper - app.DaoKeeper = *daokeeper.NewKeeper( - appCodec, - keys[daotypes.StoreKey], - keys[daotypes.MemStoreKey], - app.GetSubspace(daotypes.ModuleName), - &app.BankKeeper, - &app.AccountKeeper, - &app.DistrKeeper, - &app.GovKeeper, - &app.MintKeeper, - &app.StakingKeeper, - ) - // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks app.StakingKeeper = *stakingKeeper.SetHooks( @@ -405,13 +381,6 @@ func New( // nolint:funlen // app new cosmos func ), ) - // protect the dao module form the slashing - app.StakingKeeper = *stakingKeeper.SetSlashingProtestedModules(func() map[string]struct{} { - return map[string]struct{}{ - daotypes.ModuleName: {}, - } - }) - app.ProviderKeeper = ibcproviderkeeper.NewKeeper( appCodec, keys[providertypes.StoreKey], @@ -444,7 +413,6 @@ func New( // nolint:funlen // app new cosmos func AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). - AddRoute(daotypes.RouterKey, dao.NewProposalHandler(app.DaoKeeper)). AddRoute(providertypes.RouterKey, ibcprovider.NewProviderProposalHandler(app.ProviderKeeper)) app.GovKeeper = govkeeper.NewKeeper( @@ -483,7 +451,6 @@ func New( // nolint:funlen // app new cosmos func params.NewAppModule(app.ParamsKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), transferModule, - dao.NewAppModule(appCodec, app.DaoKeeper), providerModule, ) @@ -510,7 +477,6 @@ func New( // nolint:funlen // app new cosmos func paramstypes.ModuleName, vestingtypes.ModuleName, feegrant.ModuleName, - daotypes.ModuleName, providertypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -532,7 +498,6 @@ func New( // nolint:funlen // app new cosmos func paramstypes.ModuleName, vestingtypes.ModuleName, feegrant.ModuleName, - daotypes.ModuleName, providertypes.ModuleName, ) @@ -560,7 +525,6 @@ func New( // nolint:funlen // app new cosmos func paramstypes.ModuleName, vestingtypes.ModuleName, feegrant.ModuleName, - daotypes.ModuleName, providertypes.ModuleName, ) @@ -588,7 +552,6 @@ func New( // nolint:funlen // app new cosmos func authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), transferModule, - dao.NewAppModule(appCodec, app.DaoKeeper), ) app.sm.RegisterStoreDecoders() @@ -787,7 +750,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) - paramsKeeper.Subspace(daotypes.ModuleName) paramsKeeper.Subspace(providertypes.ModuleName) return paramsKeeper diff --git a/go.mod b/go.mod index 84c71cb1..31faca02 100644 --- a/go.mod +++ b/go.mod @@ -6,20 +6,12 @@ require ( github.com/cosmos/cosmos-sdk v0.45.16-ics github.com/cosmos/ibc-go/v4 v4.4.2 github.com/cosmos/interchain-security v1.1.0-multiden - github.com/gogo/protobuf v1.3.3 - github.com/golang/protobuf v1.5.3 - github.com/gorilla/mux v1.8.0 - github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/spf13/cast v1.5.1 github.com/spf13/cobra v1.7.0 - github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.3 github.com/tendermint/starport v0.19.3 github.com/tendermint/tendermint v0.34.27 github.com/tendermint/tm-db v0.6.7 - google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 - google.golang.org/grpc v1.59.0 - gopkg.in/yaml.v2 v2.4.0 ) require ( @@ -72,14 +64,18 @@ require ( github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/gateway v1.1.0 // indirect + github.com/gogo/protobuf v1.3.3 // indirect github.com/golang/glog v1.0.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/gorilla/handlers v1.5.1 // indirect + github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect + github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect @@ -122,6 +118,7 @@ require ( github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/spf13/afero v1.9.2 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.14.0 // indirect github.com/subosito/gotenv v1.4.1 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect @@ -138,9 +135,12 @@ require ( golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect + google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect ) diff --git a/tests/src/bin/onomyd_only.rs b/tests/src/bin/onomyd_only.rs index 5b0fe1c4..0835a642 100644 --- a/tests/src/bin/onomyd_only.rs +++ b/tests/src/bin/onomyd_only.rs @@ -100,9 +100,7 @@ async fn onomyd_runner(args: &Args) -> Result<()> { info!("{}", get_delegations_to(valoper_addr).await.stack()?); info!("{:?}", get_staking_pool().await.stack()?); - info!("{}", get_treasury().await.stack()?); - info!("{}", get_treasury_inflation_annual().await.stack()?); - + sh([format!( "cosmovisor run tx bank send {addr} onomy1a69w3hfjqere4crkgyee79x2mxq0w2pfj9tu2m 1337anom \ --fees 1000000anom -y -b block" diff --git a/x/dao/abci.go b/x/dao/abci.go deleted file mode 100644 index 8fbac781..00000000 --- a/x/dao/abci.go +++ /dev/null @@ -1,43 +0,0 @@ -package dao - -import ( - "runtime/debug" - "time" - - "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/x/dao/keeper" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// BeginBlocker does any custom logic for the DAO upon `BeginBlocker` -func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { -} - -// EndBlocker calls the dao re-balancing every block. -func EndBlocker(ctx sdk.Context, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) - - if k.GetDaoDelegationSupply(ctx).GT(sdk.NewDec(0)) { - if err := k.VoteAbstain(ctx); err != nil { - k.Logger(ctx).Error("dao EndBlocker error: %v", err) - debug.PrintStack() - } - - if err := k.WithdrawReward(ctx); err != nil { - k.Logger(ctx).Error("dao EndBlocker error: %v", err) - debug.PrintStack() - } - - if err := k.UndelegateAllValidators(ctx); err != nil { - k.Logger(ctx).Error("dao EndBlocker error: %v", err) - debug.PrintStack() - } - } - - if err := k.InflateDao(ctx); err != nil { - k.Logger(ctx).Error("dao EndBlocker error: %v", err) - debug.PrintStack() - } -} diff --git a/x/dao/abci_test.go b/x/dao/abci_test.go deleted file mode 100644 index 91315e9a..00000000 --- a/x/dao/abci_test.go +++ /dev/null @@ -1,690 +0,0 @@ -package dao_test - -/** -import ( - "encoding/json" - "testing" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" - - "github.com/onomyprotocol/onomy/testutil/simapp" - "github.com/onomyprotocol/onomy/x/dao/types" -) - - -var ( - fiftyPercents = sdk.NewDec(1).QuoInt64(2) //nolint:gochecknoglobals - tenPercents = sdk.NewDec(1).Quo(sdk.NewDec(10)) //nolint:gochecknoglobals - nanoBondCoins = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000000) // not enough for validator to be bonded - twoBondCoins = sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(2, sdk.DefaultPowerReduction)) //nolint:gochecknoglobals - tenBondCoins = sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)) //nolint:gochecknoglobals - hundredBondCoins = sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)) //nolint:gochecknoglobals - lowCommission = stakingtypes.NewCommissionRates(tenPercents, tenPercents, tenPercents) //nolint:gochecknoglobals - zeroCommission = stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) //nolint:gochecknoglobals - highCommission = stakingtypes.NewCommissionRates(fiftyPercents, fiftyPercents, fiftyPercents) //nolint:gochecknoglobals - hundredBondWithoutStakingPoolRate = hundredBondCoins.Amount.ToDec().Mul(sdk.OneDec().Sub(types.DefaultPoolRate)) //nolint:gochecknoglobals -) - -type valAssertion struct { - bondStatus stakingtypes.BondStatus - selfBondAmount sdk.Dec - daoBondAmount sdk.Dec -} - -func TestEndBlocker_ReBalance(t *testing.T) { - type args struct { - // initial validators - vals map[string]simapp.ValReq - treasuryBalance sdk.Coin - // the validators which will be added to the running chain - incomingVals map[string]simapp.ValReq - } - - type wantAssertion struct { - vals map[string]valAssertion - treasuryBalance sdk.Coin - } - - tests := []struct { - name string - args args - want wantAssertion - }{ - { - name: "positive_with_different_validator_states", - args: args{ - vals: map[string]simapp.ValReq{ - "val1": { // bonded - SelfBondCoin: twoBondCoins, - Commission: lowCommission, - }, - "val2": { // bonded - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - }, - "val3": { // won't be bonded - SelfBondCoin: nanoBondCoins, - Commission: lowCommission, - }, - "val4": { // bonded, but high Commission to be staked - SelfBondCoin: tenBondCoins, - Commission: highCommission, - }, - }, - treasuryBalance: hundredBondCoins, - }, - want: wantAssertion{ - vals: map[string]valAssertion{ - "val1": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: twoBondCoins.Amount.ToDec(), - // full * self bond / total bond - daoBondAmount: twoBondCoins.Amount.ToDec(). - Mul(hundredBondWithoutStakingPoolRate). - Quo(twoBondCoins.Amount.Add(tenBondCoins.Amount).ToDec()).TruncateDec(), - }, - "val2": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec(), - daoBondAmount: tenBondCoins.Amount.ToDec(). - Mul(hundredBondWithoutStakingPoolRate). - Quo(twoBondCoins.Amount.Add(tenBondCoins.Amount).ToDec()).TruncateDec(), - }, - "val3": { - bondStatus: stakingtypes.Unbonded, - selfBondAmount: nanoBondCoins.Amount.ToDec(), - daoBondAmount: sdk.ZeroDec(), - }, - "val4": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec(), - daoBondAmount: sdk.ZeroDec(), - }, - }, - treasuryBalance: sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(5, sdk.DefaultPowerReduction).AddRaw(1)), - }, - }, - { - name: "positive_with_incoming_validator", - args: args{ - vals: map[string]simapp.ValReq{ - "val1": { // bonded - SelfBondCoin: tenBondCoins, - Commission: zeroCommission, - Reward: twoBondCoins, - }, - }, - treasuryBalance: hundredBondCoins, - incomingVals: map[string]simapp.ValReq{ - "val2": { // bonded - SelfBondCoin: tenBondCoins, - Commission: zeroCommission, - Balance: sdk.NewCoins(tenBondCoins), - }, - }, - }, - want: wantAssertion{ - vals: map[string]valAssertion{ - "val1": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec(), - daoBondAmount: func() sdk.Dec { - // this constant is a sum of initially delegated by DAO and the delegation after the reward - // where the rewards is without the validator's reward - res, err := sdk.NewDecFromStr("48359523809523809495") - require.NoError(t, err) - return res - }(), - }, - "val2": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec(), - daoBondAmount: func() sdk.Dec { - res, err := sdk.NewDecFromStr("48359523809523809495") - require.NoError(t, err) - return res - }(), - }, - }, - - treasuryBalance: sdk.NewCoin(sdk.DefaultBondDenom, func() sdk.Int { - // The final treasury amount is increased as well because of the reward - res, err := sdk.NewDecFromStr("5090476190476190475") - require.NoError(t, err) - return res.TruncateInt() - }()), - }, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - simApp, _ := createSimAppWithValidatorsAndTreasury(t, tt.args.vals, tt.args.treasuryBalance) - - // emulate some blocks - for i := 0; i < 5; i++ { - simApp.BeginNextBlock() - ctx := simApp.NewNextContext() - simApp.EndBlockAndCommit(ctx) - } - - // allocate the reward - allocated := allocateValidatorsReward(t, simApp, tt.args.vals) - // add new validators on the running chain - for moniker, val := range tt.args.incomingVals { - // create new account - simApp.BeginNextBlock() - ctx := simApp.NewNextContext() - - balance := val.Balance - // create account - privateKey := secp256k1.GenPrivKey() - accountAddress := sdk.AccAddress(privateKey.PubKey().Address()) - account := simApp.OnomyApp().AccountKeeper.NewAccount(ctx, &authtypes.BaseAccount{ - Address: accountAddress.String(), - }) - simApp.OnomyApp().AccountKeeper.SetAccount(ctx, account) - simApp.EndBlockAndCommit(ctx) - - // fund account - simApp.BeginNextBlock() - ctx = simApp.NewNextContext() - require.NoError(t, simApp.OnomyApp().BankKeeper.MintCoins(ctx, types.ModuleName, balance)) - require.NoError(t, simApp.OnomyApp().BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, account.GetAddress(), balance)) - simApp.EndBlockAndCommit(ctx) - - // create validator - description := stakingtypes.Description{Moniker: moniker} - simApp.CreateValidator(t, val.SelfBondCoin, description, val.Commission, sdk.OneInt(), privateKey) - } - - // iterate couple times to check that the state is the same - for i := 0; i < 10; i++ { - // this is a tricky part which emulate the minting on ech block, this action should affect the assertion anyhow - allocateValidatorsReward(t, simApp, tt.args.vals) - - simApp.BeginNextBlock() - ctx := simApp.NewNextContext() - - // assertions - assertValidators(t, simApp, ctx, tt.want.vals) - - daoKeeper := simApp.OnomyApp().DaoKeeper - gotTreasuryBalance := daoKeeper.Treasury(ctx) - require.Equal(t, sdk.NewCoins(tt.want.treasuryBalance).String(), gotTreasuryBalance.String()) - - // pool rate = current pool / total - require.Equal(t, gotTreasuryBalance[0].Amount.ToDec().Quo(daoKeeper.GetDaoDelegationSupply(ctx).Add(gotTreasuryBalance[0].Amount.ToDec())), types.DefaultPoolRate) - - // the check the overall balance remains the same in case there we no reward - if !allocated { - require.Equal(t, daoKeeper.GetDaoDelegationSupply(ctx).Add(gotTreasuryBalance[0].Amount.ToDec()), tt.args.treasuryBalance.Amount.ToDec()) - } - simApp.EndBlockAndCommit(ctx) - } - }) - } -} - -func TestEndBlocker_WithdrawReward(t *testing.T) { - validatorReward := sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000000) - expectedDaoFullReward := sdk.NewInt64Coin(sdk.DefaultBondDenom, 1486956434) - - type args struct { - vals map[string]simapp.ValReq - treasuryBalance sdk.Coin - } - - type wantAssertion struct { - vals map[string]valAssertion - treasuryBalance sdk.Coin - } - - tests := []struct { - name string - args args - want wantAssertion - }{ - { - name: "positive", - args: args{ - vals: map[string]simapp.ValReq{ - "val1": { // bonded - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - Reward: validatorReward, - }, - "val2": { // bonded - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - Reward: validatorReward, - }, - "val3": { // won't be bonded - SelfBondCoin: nanoBondCoins, - Commission: lowCommission, - Reward: validatorReward, - }, - }, - treasuryBalance: hundredBondCoins, - }, - want: wantAssertion{ - vals: map[string]valAssertion{ - "val1": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec(), - daoBondAmount: - // initial dao staking - hundredBondWithoutStakingPoolRate.QuoInt64(2). - // the Reward - Add(expectedDaoFullReward.Amount.ToDec().QuoInt64(2).Mul(sdk.OneDec().Sub(types.DefaultPoolRate))).TruncateDec(), - }, - "val2": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec(), - daoBondAmount: - // initial dao staking - hundredBondWithoutStakingPoolRate.QuoInt64(2). - // the Reward - Add(expectedDaoFullReward.Amount.ToDec().QuoInt64(2).Mul(sdk.OneDec().Sub(types.DefaultPoolRate))).TruncateDec(), - }, - "val3": { - bondStatus: stakingtypes.Unbonded, - selfBondAmount: nanoBondCoins.Amount.ToDec(), - daoBondAmount: sdk.ZeroDec(), - }, - }, - treasuryBalance: sdk.NewCoin(sdk.DefaultBondDenom, - sdk.TokensFromConsensusPower(5, sdk.DefaultPowerReduction). - Add(expectedDaoFullReward.Amount.ToDec().Mul(types.DefaultPoolRate).RoundInt())), - }, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - const withdrawRewardPeriod = 6 // the simApp.BeginNextBlock() in assertion will be executed with that block number - simApp, _ := createSimAppWithValidatorsAndTreasury(t, tt.args.vals, tt.args.treasuryBalance) - simApp.BeginNextBlock() - ctx := simApp.NewNextContext() - // update dao params to withdraw Reward - daoKeeper := simApp.OnomyApp().DaoKeeper - daoParams := daoKeeper.GetParams(ctx) - daoParams.WithdrawRewardPeriod = withdrawRewardPeriod - daoKeeper.SetParams(ctx, daoParams) - // allocate validator rewards - for moniker := range tt.args.vals { - moniker := moniker - simApp.OnomyApp().StakingKeeper.IterateValidators(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) { - if moniker == validator.GetMoniker() { - // mind and send coins as a validator Reward - require.NoError(t, simApp.OnomyApp().BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(tt.args.vals[moniker].Reward))) - require.NoError(t, simApp.OnomyApp().BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, distrtypes.ModuleName, sdk.NewCoins(tt.args.vals[moniker].Reward))) - - simApp.OnomyApp().DistrKeeper.AllocateTokensToValidator(ctx, validator, sdk.NewDecCoinsFromCoins(tt.args.vals[moniker].Reward)) - return true - } - return false - }) - } - simApp.EndBlockAndCommit(ctx) - - // assertions - simApp.BeginNextBlock() - ctx = simApp.NewNextContext() - dao.EndBlocker(ctx, simApp.OnomyApp().DaoKeeper) - assertValidators(t, simApp, ctx, tt.want.vals) - - gotTreasuryBalance := daoKeeper.Treasury(ctx) - require.Equal(t, sdk.NewCoins(tt.want.treasuryBalance), gotTreasuryBalance) - - // pool rate = current pool / total - require.Equal(t, gotTreasuryBalance[0].Amount.ToDec().Quo(daoKeeper.GetDaoDelegationSupply(ctx).Add(gotTreasuryBalance[0].Amount.ToDec())), types.DefaultPoolRate) - - // the check the overall balance is increased - require.Equal(t, daoKeeper.GetDaoDelegationSupply(ctx).Add(gotTreasuryBalance[0].Amount.ToDec()). - // substitute the Reward from the total dao - Sub(expectedDaoFullReward.Amount.ToDec()), tt.args.treasuryBalance.Amount.ToDec()) - }) - } -} -/** -/** -func TestEndBlocker_Vote(t *testing.T) { - type valWithProposalsReq struct { - simapp.ValReq - deposit sdk.Coin - } - - type args struct { - vals map[string]valWithProposalsReq - } - - type wantAssertion struct { - wantDaoProposal map[string]bool // [moniker]should dao vote - } - - tests := []struct { - name string - args args - want wantAssertion - }{ - { - name: "positive_two_active_proposals", - args: args{ - vals: map[string]valWithProposalsReq{ - "val1": { - ValReq: simapp.ValReq{ - Balance: sdk.NewCoins(tenBondCoins.Add(tenBondCoins)), - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - }, - deposit: tenBondCoins, - }, - "val2": { - ValReq: simapp.ValReq{ - Balance: sdk.NewCoins(tenBondCoins.Add(tenBondCoins)), - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - }, - deposit: tenBondCoins, - }, - }, - }, - want: wantAssertion{ - wantDaoProposal: map[string]bool{ - "val1": true, - "val2": true, - }, - }, - }, - { - name: "positive_one_active_proposal", - args: args{ - vals: map[string]valWithProposalsReq{ - "val1": { - ValReq: simapp.ValReq{ - Balance: sdk.NewCoins(tenBondCoins.Add(tenBondCoins)), - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - }, - deposit: tenBondCoins, - }, - "val2": { - ValReq: simapp.ValReq{ - Balance: sdk.NewCoins(tenBondCoins.Add(tenBondCoins)), - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - }, - deposit: nanoBondCoins, // low deposit so the dao shouldn't vote - }, - }, - }, - want: wantAssertion{ - wantDaoProposal: map[string]bool{ - "val1": true, - "val2": false, - }, - }, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - const proposalNamePattern = "proposal-%s" - - vals := make(map[string]simapp.ValReq, len(tt.args.vals)) - for moniker := range tt.args.vals { - vals[moniker] = tt.args.vals[moniker].ValReq - } - simApp, privs := createSimAppWithValidatorsAndTreasury(t, vals, sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)) - - // create the text proposals - for moniker := range tt.args.vals { - priv := privs[moniker] - textProposalContent := govtypes.ContentFromProposalType(fmt.Sprintf(proposalNamePattern, moniker), "description", govtypes.ProposalTypeText) - simApp.CreateProposal(t, textProposalContent, tt.args.vals[moniker].deposit, priv) - } - - simApp.BeginNextBlock() - ctx := simApp.NewContext() - dao.EndBlocker(ctx, simApp.OnomyApp().DaoKeeper) - - // assertions - govKeeper := simApp.OnomyApp().GovKeeper - accountKeeper := simApp.OnomyApp().AccountKeeper - daoAddress := accountKeeper.GetModuleAddress(types.ModuleName) - - votes := govKeeper.GetAllVotes(ctx) - for moniker, want := range tt.want.wantDaoProposal { - found := false - for _, vote := range votes { - // all votes should from the dao only - require.Equal(t, daoAddress.String(), vote.Voter) - proposal, _ := govKeeper.GetProposal(ctx, vote.ProposalId) - if fmt.Sprintf(proposalNamePattern, moniker) == proposal.GetContent().GetTitle() { - found = true - break - } - } - require.Equal(t, want, found) - } - }) - } -} - -func TestEndBlocker_Slashing_Protection(t *testing.T) { - // 50% slashing fraction - fraction := sdk.NewDecWithPrec(5, 1) - - type valWithSlashingReq struct { - simapp.ValReq - shouldSlash bool - } - - type args struct { - vals map[string]valWithSlashingReq - treasuryBalance sdk.Coin - } - - type wantAssertion struct { - vals map[string]valAssertion - treasuryBalance sdk.Coin - } - - tests := []struct { - name string - args args - want wantAssertion - }{ - { - name: "positive", - args: args{ - vals: map[string]valWithSlashingReq{ - "val1": { - ValReq: simapp.ValReq{ - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - }, - shouldSlash: false, - }, - "val2": { // bonded - ValReq: simapp.ValReq{ - SelfBondCoin: tenBondCoins, - Commission: lowCommission, - }, - shouldSlash: true, - }, - }, - treasuryBalance: hundredBondCoins, - }, - want: wantAssertion{ - vals: map[string]valAssertion{ - "val1": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec(), - // the val2 was slashed so the final amount will higher than val2 - // also the slashing of the validator is based on the voting power, hence the initial - // amount to slash will be rounded - // full * self bond / total bond - daoBondAmount: tenBondCoins.Amount.ToDec(). - // 25*10^16 here is the rounded part - Mul(hundredBondWithoutStakingPoolRate). - Quo(tenBondCoins.Amount.ToDec().Mul(fraction).Add(sdk.NewIntWithDecimal(25, 16).ToDec()).Add(tenBondCoins.Amount.ToDec())).TruncateDec(), - }, - "val2": { - bondStatus: stakingtypes.Bonded, - selfBondAmount: tenBondCoins.Amount.ToDec().Mul(fraction).Add(sdk.NewIntWithDecimal(25, 16).ToDec()), - // the val2 was slashed so the final amount will higher lower val1 - // full * self bond / total bond - daoBondAmount: tenBondCoins.Amount.ToDec().Mul(fraction).Add(sdk.NewIntWithDecimal(25, 16).ToDec()). - // 25*10^16 here is the rounded part - Mul(hundredBondWithoutStakingPoolRate). - Quo(tenBondCoins.Amount.ToDec().Mul(fraction).Add(sdk.NewIntWithDecimal(25, 16).ToDec()).Add(tenBondCoins.Amount.ToDec())).TruncateDec(), - }, - }, - treasuryBalance: sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(5, sdk.DefaultPowerReduction).AddRaw(1)), - }, - }, - } - - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - vals := make(map[string]simapp.ValReq, len(tt.args.vals)) - for moniker := range tt.args.vals { - vals[moniker] = tt.args.vals[moniker].ValReq - } - simApp, _ := createSimAppWithValidatorsAndTreasury(t, vals, tt.args.treasuryBalance) - // initial rebalance - simApp.BeginNextBlock() - ctx := simApp.NewNextContext() - simApp.EndBlockAndCommit(ctx) - - // slashing - simApp.BeginNextBlock() - ctx = simApp.NewNextContext() - for moniker := range tt.args.vals { - if !tt.args.vals[moniker].shouldSlash { - continue - } - for _, val := range simApp.OnomyApp().StakingKeeper.GetAllValidators(ctx) { - if val.GetMoniker() == moniker { - power := simApp.OnomyApp().StakingKeeper.GetLastValidatorPower(ctx, val.GetOperator()) - consAddr, err := val.GetConsAddr() - require.NoError(t, err) - simApp.OnomyApp().StakingKeeper.Slash(ctx, consAddr, ctx.BlockHeight(), power, fraction, stakingtypes.InfractionEmpty) - } - } - } - simApp.EndBlockAndCommit(ctx) - - // finalize rebalance - simApp.BeginNextBlock() - ctx = simApp.NewNextContext() - simApp.EndBlockAndCommit(ctx) - - // assertions - assertValidators(t, simApp, ctx, tt.want.vals) - - daoKeeper := simApp.OnomyApp().DaoKeeper - gotTreasuryBalance := daoKeeper.Treasury(ctx) - require.Equal(t, sdk.NewCoins(tt.want.treasuryBalance), gotTreasuryBalance) - - // pool rate = current pool / total - require.Equal(t, gotTreasuryBalance[0].Amount.ToDec().Quo(daoKeeper.GetDaoDelegationSupply(ctx).Add(gotTreasuryBalance[0].Amount.ToDec())), types.DefaultPoolRate) - - // the check the overall balance remains the same - require.Equal(t, daoKeeper.GetDaoDelegationSupply(ctx).Add(gotTreasuryBalance[0].Amount.ToDec()), tt.args.treasuryBalance.Amount.ToDec()) - }) - } -} - - -func createSimAppWithValidatorsAndTreasury(t *testing.T, vals map[string]simapp.ValReq, treasuryBalance sdk.Coin) (*simapp.SimApp, map[string]*secp256k1.PrivKey) { - t.Helper() - - // treasury genesis - treasuryOverrideOpt := simapp.WithGenesisOverride( - func(m map[string]json.RawMessage) map[string]json.RawMessage { - daoGenesis := types.DefaultGenesis() - daoGenesis.TreasuryBalance = sdk.NewCoins(treasuryBalance) - daoGenesisString, err := json.Marshal(daoGenesis) - require.NoError(t, err) - m[types.ModuleName] = daoGenesisString - return m - }) - - return simapp.SetupWithValidators(t, vals, treasuryOverrideOpt) -} - -func allocateValidatorsReward(t *testing.T, simApp *simapp.SimApp, vals map[string]simapp.ValReq) bool { - t.Helper() - - allocated := false - for moniker := range vals { - moniker := moniker - if vals[moniker].Reward.IsNil() { - continue - } - // allocate the reward - simApp.BeginNextBlock() - ctx := simApp.NewNextContext() - simApp.OnomyApp().StakingKeeper.IterateValidators(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) { - if moniker == validator.GetMoniker() { - // mind and send coins as a validator Reward - require.NoError(t, simApp.OnomyApp().BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(vals[moniker].Reward))) - require.NoError(t, simApp.OnomyApp().BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, distrtypes.ModuleName, sdk.NewCoins(vals[moniker].Reward))) - - simApp.OnomyApp().DistrKeeper.AllocateTokensToValidator(ctx, validator, sdk.NewDecCoinsFromCoins(vals[moniker].Reward)) - allocated = true - return true - } - return false - }) - simApp.EndBlockAndCommit(ctx) - } - - return allocated -} - -/* -func assertValidators(t *testing.T, simApp *simapp.SimApp, ctx sdk.Context, vals map[string]valAssertion) { - t.Helper() - - accountKeeper := simApp.OnomyApp().AccountKeeper - stakingKeeper := simApp.OnomyApp().StakingKeeper - daoAddress := accountKeeper.GetModuleAddress(types.ModuleName) - updatedValidators := stakingKeeper.GetAllValidators(ctx) - require.Equal(t, len(vals), len(updatedValidators)) - - for _, val := range updatedValidators { - delegations := stakingKeeper.GetValidatorDelegations(ctx, val.GetOperator()) - require.LessOrEqual(t, 1, len(delegations)) - - valAssert, ok := vals[val.GetMoniker()] - require.True(t, ok) - require.Equal(t, valAssert.bondStatus, val.Status, val.GetMoniker()) - - for _, delegation := range delegations { - switch delegation.DelegatorAddress { - case daoAddress.String(): - { - require.Equal(t, valAssert.daoBondAmount, val.TokensFromShares(delegation.Shares), val.GetMoniker()) - } - case sdk.AccAddress(val.GetOperator()).String(): - { - require.Equal(t, valAssert.selfBondAmount, val.TokensFromShares(delegation.Shares), val.GetMoniker()) - } - default: - { - t.Errorf("unexpected delegation %+v, of val %q, address: %q", delegation, val.GetMoniker(), val.GetOperator().String()) - } - } - } - } -} -.*/ diff --git a/x/dao/client/cli/query.go b/x/dao/client/cli/query.go deleted file mode 100644 index 2dda27b0..00000000 --- a/x/dao/client/cli/query.go +++ /dev/null @@ -1,79 +0,0 @@ -package cli - -import ( - "context" - "fmt" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/spf13/cobra" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// GetQueryCmd returns the cli query commands for this module. -func GetQueryCmd(_ string) *cobra.Command { - // Group dao queries under a subcommand - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, // nolint:gomnd - RunE: client.ValidateCmd, - } - - cmd.AddCommand(CmdShowParams()) - cmd.AddCommand(CmdShowTreasury()) - - return cmd -} - -// CmdShowParams returns CmdShowParams cobra.Command. -func CmdShowParams() *cobra.Command { - cmd := &cobra.Command{ - Use: "show-params", - Short: "shows the parameters of the module", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -// CmdShowTreasury returns CmdShowTreasury cobra.Command. -func CmdShowTreasury() *cobra.Command { - cmd := &cobra.Command{ - Use: "show-treasury", - Short: "Shows treasury balance.", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Treasury(context.Background(), &types.QueryTreasuryRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/dao/client/cli/query_test.go b/x/dao/client/cli/query_test.go deleted file mode 100644 index 3178dcdc..00000000 --- a/x/dao/client/cli/query_test.go +++ /dev/null @@ -1,102 +0,0 @@ -package cli_test - -import ( - "fmt" - "testing" - - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" - "google.golang.org/grpc/status" - - "github.com/onomyprotocol/onomy/testutil/network" - "github.com/onomyprotocol/onomy/x/dao/client/cli" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -func TestCLI_CmdShowParams(t *testing.T) { - for _, tt := range []struct { - name string - args []string - prep func(testNetwork *network.TestNetwork) - err error - want types.QueryParamsResponse - }{ - { - name: "positive_default", - want: types.QueryParamsResponse{ - Params: types.DefaultParams(), - }, - }, - } { - tt := tt - t.Run(tt.name, func(t *testing.T) { - testNetwork := network.New(t) - defer testNetwork.Cleanup() - - if tt.prep != nil { - tt.prep(testNetwork) - } - - tt.args = append(tt.args, fmt.Sprintf("--%s=json", tmcli.OutputFlag)) - ctx := testNetwork.Validator1Ctx() - - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowParams(), tt.args) - if tt.err != nil { - stat, ok := status.FromError(tt.err) - require.True(t, ok) - require.ErrorIs(t, stat.Err(), tt.err) - } else { - require.NoError(t, err) - var resp types.QueryParamsResponse - require.NoError(t, testNetwork.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.NotNil(t, resp) - require.Equal(t, tt.want, resp) - } - }) - } -} - -func TestCLI_ShowTreasury(t *testing.T) { - for _, tt := range []struct { - name string - args []string - prep func(testNetwork *network.TestNetwork) - err error - want types.QueryTreasuryResponse - }{ - { - name: "positive_empty", - want: types.QueryTreasuryResponse{ - TreasuryBalance: []sdk.Coin{}, - }, - }, - } { - tt := tt - t.Run(tt.name, func(t *testing.T) { - testNetwork := network.New(t) - defer testNetwork.Cleanup() - - if tt.prep != nil { - tt.prep(testNetwork) - } - - tt.args = append(tt.args, fmt.Sprintf("--%s=json", tmcli.OutputFlag)) - ctx := testNetwork.Validator1Ctx() - - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowTreasury(), tt.args) - if tt.err != nil { - stat, ok := status.FromError(tt.err) - require.True(t, ok) - require.ErrorIs(t, stat.Err(), tt.err) - } else { - require.NoError(t, err) - var resp types.QueryTreasuryResponse - require.NoError(t, testNetwork.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.NotNil(t, resp) - require.Equal(t, tt.want, resp) - } - }) - } -} diff --git a/x/dao/client/cli/tx.go b/x/dao/client/cli/tx.go deleted file mode 100644 index afb21466..00000000 --- a/x/dao/client/cli/tx.go +++ /dev/null @@ -1,257 +0,0 @@ -// Package cli contains dao module cli utils. -package cli - -import ( - "fmt" - "strings" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/version" - govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -type proposalGeneric struct { - Title string - Description string - Deposit string -} - -func addTxFlags(cmd *cobra.Command) *cobra.Command { - flags.AddTxFlagsToCmd(cmd) - return cmd -} - -// GetTxCmd returns the transaction commands for this module. -func GetTxCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s dao subcommands", types.ModuleName), - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, // nolint:gomnd - RunE: client.ValidateCmd, - } - - cmd.AddCommand(addTxFlags(CmdFundTreasuryProposal())) - cmd.AddCommand(addTxFlags(CmdExchangeWithTreasuryProposal())) - cmd.AddCommand(addTxFlags((CmdFundAccountProposal()))) - - return cmd -} - -// CmdFundTreasuryProposal implements the command to submit a fund-treasury proposal. -func CmdFundTreasuryProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "fund-treasury amount", - Args: cobra.ExactArgs(1), - Short: "Submit a fund treasury proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a fund treasury proposal along with an initial deposit. -Example: -$ %s tx gov submit-proposal fund-treasury 5000000000000000000anom --title="Test Proposal" --description="My awesome proposal" --deposit="10000000000000000000anom" --from mykey`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - amount, err := sdk.ParseCoinsNormalized(args[0]) - if err != nil { - return err - } - - proposalGeneric, err := parseSubmitProposalFlags(cmd.Flags()) - if err != nil { - return err - } - - deposit, err := sdk.ParseCoinsNormalized(proposalGeneric.Deposit) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - content := types.NewFundTreasuryProposal(from, proposalGeneric.Title, proposalGeneric.Description, amount) - - msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - addProposalFlags(cmd) - - return cmd -} - -// CmdExchangeWithTreasuryProposal implements the command to submit еру exchange-with-treasury proposal. -func CmdExchangeWithTreasuryProposal() *cobra.Command { // nolint:gocognit,gocyclo,cyclop // the command is long but not complicated - cmd := &cobra.Command{ - Use: "exchange-with-treasury coins-pairs", - Args: cobra.ExactArgs(1), - Short: "Submit an exchange with treasury proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Submitan exchange with treasury proposal along with an initial deposit. -Example (the anom in the example is ask coin, ousd is bid coin): -$ %s tx gov submit-proposal exchange-with-treasury "5000000000000000000anom/5000000000000000000ousd" --title="Test Proposal" --description="My awesome proposal" --deposit="10000000000000000000anom" --from mykey`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - exchangeCoins := make([]types.CoinsExchangePair, 0) - pairsStrings := strings.Split(args[0], ",") - for i := range pairsStrings { - coinsString := strings.Split(pairsStrings[i], "/") - if len(coinsString) != 2 { // nolint:gomnd // pair number - return fmt.Errorf("coins pair %s is invalid", pairsStrings[i]) - } - - coinAsk, err := sdk.ParseCoinNormalized(coinsString[0]) - if err != nil { - return err - } - if err := coinAsk.Validate(); err != nil { - return err - } - coinBid, err := sdk.ParseCoinNormalized(coinsString[1]) - if err != nil { - return err - } - if err := coinBid.Validate(); err != nil { - return err - } - - exchangeCoins = append(exchangeCoins, types.CoinsExchangePair{ - CoinAsk: coinAsk, - CoinBid: coinBid, - }) - } - - proposalGeneric, err := parseSubmitProposalFlags(cmd.Flags()) - if err != nil { - return err - } - - deposit, err := sdk.ParseCoinsNormalized(proposalGeneric.Deposit) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - content := types.NewExchangeWithTreasuryProposal(from, proposalGeneric.Title, proposalGeneric.Description, exchangeCoins) - - msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - addProposalFlags(cmd) - - return cmd -} - -// CmdFundAccountProposal implements the command to submit a fund-account proposal. -func CmdFundAccountProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "fund-account recipient amount", - Args: cobra.ExactArgs(2), // nolint:gomnd // the args count - Short: "Submit a fund account proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a fund account proposal along with an initial deposit. -Example: -$ %s tx gov submit-proposal fund-account recipient-address 5000000000000000000anom --title="Test Proposal" --description="My awesome proposal" --deposit="10000000000000000000anom" --from mykey`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - recipient, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - amount, err := sdk.ParseCoinsNormalized(args[1]) - if err != nil { - return err - } - - proposalGeneric, err := parseSubmitProposalFlags(cmd.Flags()) - if err != nil { - return err - } - - deposit, err := sdk.ParseCoinsNormalized(proposalGeneric.Deposit) - if err != nil { - return err - } - - content := types.NewFundAccountProposal(recipient, proposalGeneric.Title, proposalGeneric.Description, amount) - - from := clientCtx.GetFromAddress() - msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - addProposalFlags(cmd) - - return cmd -} - -func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposalGeneric, error) { - title, err := fs.GetString(govcli.FlagTitle) - if err != nil { - return nil, err - } - description, err := fs.GetString(govcli.FlagDescription) - if err != nil { - return nil, err - } - - deposit, err := fs.GetString(govcli.FlagDeposit) - if err != nil { - return nil, err - } - - return &proposalGeneric{ - Title: title, - Description: description, - Deposit: deposit, - }, nil -} - -func addProposalFlags(cmd *cobra.Command) { - cmd.Flags().String(govcli.FlagTitle, "", "The proposal title") - cmd.Flags().String(govcli.FlagDescription, "", "The proposal description") - cmd.Flags().String(govcli.FlagDeposit, "", "The proposal deposit") -} diff --git a/x/dao/client/cli/tx_test.go b/x/dao/client/cli/tx_test.go deleted file mode 100644 index fd7f4954..00000000 --- a/x/dao/client/cli/tx_test.go +++ /dev/null @@ -1,169 +0,0 @@ -package cli_test - -import ( - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/cosmos/cosmos-sdk/client/flags" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/stretchr/testify/require" - - "github.com/onomyprotocol/onomy/testutil/network" - "github.com/onomyprotocol/onomy/testutil/simapp" - "github.com/onomyprotocol/onomy/x/dao/client/cli" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -const ( - normalToken = "node0token" - stakeToken = "stake" -) - -func TestCLI_FundTreasuryProposal(t *testing.T) { - for _, tt := range []struct { - name string - args string - err error - code uint32 - }{ - { - name: "positive", - args: fmt.Sprintf("5000000000000000000%s --title=Title --description=Description --deposit=1000000000000000000%s", normalToken, stakeToken), - }, - { - name: "negative_insufficient_balance", - args: fmt.Sprintf("5000000000000000000%s --title=Title --description=Description --deposit=1000000000000000000%s", "newcoin", stakeToken), - code: govtypes.ErrInvalidProposalContent.ABCICode(), - }, - } { - tt := tt - t.Run(tt.name, func(t *testing.T) { - testNetwork := network.New(t) - defer testNetwork.Cleanup() - args := strings.Split(tt.args, " ") - args = append(args, testNetwork.TxValidator1Args()...) - ctx := testNetwork.Validator1Ctx() - // on the onomy chain those flag will be added ny the gov module - cmd := cli.CmdFundTreasuryProposal() - flags.AddTxFlagsToCmd(cmd) - out, err := clitestutil.ExecTestCLICmd(ctx, cmd, args) - if tt.err != nil { - require.ErrorIs(t, err, tt.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, testNetwork.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tt.code, resp.Code, fmt.Sprintf("%+v", resp)) - } - }) - } -} - -func TestCLI_ExchangeWithTreasuryProposal(t *testing.T) { - for _, tt := range []struct { - name string - treasuryBalance sdk.Coins - args string - err error - code uint32 - }{ - { - name: "positive", - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(stakeToken, 5000000000000000000)), - args: fmt.Sprintf("500000000%s/100000000%s --title=Title --description=Description --deposit=1000000000000000000%s", stakeToken, normalToken, stakeToken), - }, - { - name: "negative_wrong_coins_format", - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(stakeToken, 5000000000000000000)), - args: fmt.Sprintf("500000000%s --title=Title --description=Description --deposit=1000000000000000000%s", normalToken, stakeToken), - err: fmt.Errorf("coins pair 500000000%s is invalid", normalToken), - }, - } { // nolint:dupl // test template - tt := tt - t.Run(tt.name, func(t *testing.T) { - testNetwork := network.New(t, network.WithGenesisOverride( - func(m map[string]json.RawMessage) map[string]json.RawMessage { - daoGenesis := types.DefaultGenesis() - daoGenesis.TreasuryBalance = tt.treasuryBalance - daoGenesisString, err := json.Marshal(daoGenesis) - require.NoError(t, err) - m[types.ModuleName] = daoGenesisString - return m - })) - defer testNetwork.Cleanup() - - args := strings.Split(tt.args, " ") - args = append(args, testNetwork.TxValidator1Args()...) - ctx := testNetwork.Validator1Ctx() - // on the onomy chain those flag will be added ny the gov module - cmd := cli.CmdExchangeWithTreasuryProposal() - flags.AddTxFlagsToCmd(cmd) - out, err := clitestutil.ExecTestCLICmd(ctx, cmd, args) - if tt.err != nil { - require.Equal(t, err, tt.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, testNetwork.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tt.code, resp.Code, fmt.Sprintf("%+v", resp)) - } - }) - } -} - -func TestCLI_FundAccountProposal(t *testing.T) { - accountAddress := simapp.GenAccountAddress() - - for _, tt := range []struct { - name string - treasuryBalance sdk.Coins - args string - err error - code uint32 - }{ - { - name: "positive", - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(normalToken, 5000000000000000000)), - args: fmt.Sprintf("%s 500000000%s --title=Title --description=Description --deposit=1000000000000000000%s", accountAddress.String(), normalToken, stakeToken), - }, - { - name: "negative_insufficient_balance", - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(normalToken, 1000000000000000000)), - args: fmt.Sprintf("%s 500000000%s --title=Title --description=Description --deposit=1000000000000000000%s", accountAddress.String(), "newcoin", stakeToken), - code: govtypes.ErrInvalidProposalContent.ABCICode(), - }, - } { // nolint:dupl // test template - tt := tt - t.Run(tt.name, func(t *testing.T) { - testNetwork := network.New(t, network.WithGenesisOverride( - func(m map[string]json.RawMessage) map[string]json.RawMessage { - daoGenesis := types.DefaultGenesis() - daoGenesis.TreasuryBalance = tt.treasuryBalance - daoGenesisString, err := json.Marshal(daoGenesis) - require.NoError(t, err) - m[types.ModuleName] = daoGenesisString - return m - })) - defer testNetwork.Cleanup() - args := strings.Split(tt.args, " ") - args = append(args, testNetwork.TxValidator1Args()...) - ctx := testNetwork.Validator1Ctx() - // on the onomy chain those flag will be added ny the gov module - cmd := cli.CmdFundAccountProposal() - flags.AddTxFlagsToCmd(cmd) - out, err := clitestutil.ExecTestCLICmd(ctx, cmd, args) - if tt.err != nil { - require.ErrorIs(t, err, tt.err) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, testNetwork.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.Equal(t, tt.code, resp.Code, fmt.Sprintf("%+v", resp)) - } - }) - } -} diff --git a/x/dao/client/proposal_handler.go b/x/dao/client/proposal_handler.go deleted file mode 100644 index dc20414a..00000000 --- a/x/dao/client/proposal_handler.go +++ /dev/null @@ -1,29 +0,0 @@ -// Package client contains dao client implementation. -package client - -import ( - "net/http" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/types/rest" - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" - govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" - - "github.com/onomyprotocol/onomy/x/dao/client/cli" -) - -var ( - // FundTreasuryProposalHandler is the cli handler used for the gov cli integration. - FundTreasuryProposalHandler = govclient.NewProposalHandler(cli.CmdFundTreasuryProposal, emptyRestHandler) // nolint:gochecknoglobals // cosmos-sdk style - // ExchangeWithTreasuryProposalProposalHandler is the cli handler used for the gov cli integration. - ExchangeWithTreasuryProposalProposalHandler = govclient.NewProposalHandler(cli.CmdExchangeWithTreasuryProposal, emptyRestHandler) // nolint:gochecknoglobals // cosmos-sdk style -) - -func emptyRestHandler(client.Context) govrest.ProposalRESTHandler { - return govrest.ProposalRESTHandler{ - SubRoute: "unsupported-dao-routes", - Handler: func(w http.ResponseWriter, r *http.Request) { - rest.WriteErrorResponse(w, http.StatusBadRequest, "Legacy REST Routes are not supported for DAO proposals") - }, - } -} diff --git a/x/dao/genesis.go b/x/dao/genesis.go deleted file mode 100644 index 76a2394a..00000000 --- a/x/dao/genesis.go +++ /dev/null @@ -1,23 +0,0 @@ -package dao - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/x/dao/keeper" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// InitGenesis initializes the dao module's state from a provided genesis -// state. -func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { - if err := k.InitGenesis(ctx, genState); err != nil { - panic(fmt.Errorf("can't init genesis for %q module, genState: %+v, err: %w", types.ModuleName, genState, err)) - } -} - -// ExportGenesis returns the dao module's exported genesis. -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { - return k.ExportGenesis(ctx) -} diff --git a/x/dao/genesis_test.go b/x/dao/genesis_test.go deleted file mode 100644 index 68a78cdb..00000000 --- a/x/dao/genesis_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package dao_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - - "github.com/onomyprotocol/onomy/testutil/simapp" - "github.com/onomyprotocol/onomy/x/dao" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -func TestInitGenesis(t *testing.T) { - const ( - denom1 = "denom1" - denom2 = "denom2" - ) - type args struct { - genState types.GenesisState - } - - tests := []struct { - name string - args args - }{ - { - name: "init_and_check_bank", - args: args{ - genState: types.GenesisState{ - Params: types.DefaultParams(), - TreasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 1), sdk.NewInt64Coin(denom2, 2)), - }, - }, - }, - } - for _, tt := range tests { - tt := tt - simApp := simapp.Setup() - ctx := simApp.NewContext() - t.Run(tt.name, func(t *testing.T) { - dao.InitGenesis(ctx, simApp.OnomyApp().DaoKeeper, tt.args.genState) - exportedModuleBalance := simApp.OnomyApp().BankKeeper.GetAllBalances(ctx, simApp.OnomyApp().AccountKeeper.GetModuleAddress(types.ModuleName)) - require.Equal(t, tt.args.genState.TreasuryBalance, exportedModuleBalance) - require.Equal(t, tt.args.genState.Params, simApp.OnomyApp().DaoKeeper.GetParams(ctx)) - }) - } -} - -func TestInitAndExportGenesis(t *testing.T) { - const ( - denom1 = "denom1" - denom2 = "denom2" - ) - type args struct { - genState types.GenesisState - } - - tests := []struct { - name string - args args - }{ - { - name: "import_same_as_export", - args: args{ - genState: types.GenesisState{ - TreasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 1), sdk.NewInt64Coin(denom2, 2)), - Params: types.DefaultParams(), - }, - }, - }, - } - for _, tt := range tests { - tt := tt - simApp := simapp.Setup() - ctx := simApp.NewContext() - t.Run(tt.name, func(t *testing.T) { - dao.InitGenesis(ctx, simApp.OnomyApp().DaoKeeper, tt.args.genState) - exportedGenesis := dao.ExportGenesis(ctx, simApp.OnomyApp().DaoKeeper) - require.Equal(t, &tt.args.genState, exportedGenesis) - }) - } -} diff --git a/x/dao/handler.go b/x/dao/handler.go deleted file mode 100644 index 31ef84bd..00000000 --- a/x/dao/handler.go +++ /dev/null @@ -1,42 +0,0 @@ -package dao - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - - "github.com/onomyprotocol/onomy/x/dao/keeper" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// NewHandler ... -func NewHandler() sdk.Handler { - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - switch msg := msg.(type) { // nolint:gocritic //the module doesn't support messages handling - default: - errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - } - } -} - -// NewProposalHandler defines the dao proposal handler. -func NewProposalHandler(k keeper.Keeper) govtypes.Handler { - return func(ctx sdk.Context, content govtypes.Content) error { - switch c := content.(type) { - case *types.FundTreasuryProposal: - return k.FundTreasuryProposal(ctx, c) - - case *types.ExchangeWithTreasuryProposal: - return k.ExchangeWithTreasuryProposal(ctx, c) - - case *types.FundAccountProposal: - return k.FundAccountProposal(ctx, c) - - default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c) - } - } -} diff --git a/x/dao/keeper/delegation.go b/x/dao/keeper/delegation.go deleted file mode 100644 index e18d56f2..00000000 --- a/x/dao/keeper/delegation.go +++ /dev/null @@ -1,212 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// ReBalanceDelegation re-balances the DAO staking among validators bases on the current validators self bond. -func (k Keeper) ReBalanceDelegation(ctx sdk.Context) error { - daoAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) - vals := k.stakingKeeper.GetAllValidators(ctx) - targetDaoStaking := k.getTargetDelegationState(ctx, vals) - delegations, undelegations := k.computeDelegationsAndUndelegation(ctx, daoAddr, vals, targetDaoStaking) - - if len(delegations) == 0 && len(undelegations) == 0 { - return nil - } - - // If we have updates in the (un)delegations we should withdraw the rewards and recompute the (un)delegations - // with the received reward. Otherwise, it will be withdrawn during the (un)delegations execution (via staking hook), - // and that will cause the re-balancing for each following block. - if err := k.WithdrawReward(ctx); err != nil { - return err - } - - vals = k.stakingKeeper.GetAllValidators(ctx) - targetDaoStaking = k.getTargetDelegationState(ctx, vals) - delegations, undelegations = k.computeDelegationsAndUndelegation(ctx, daoAddr, vals, targetDaoStaking) - - if err := undelegateValidators(ctx, vals, undelegations, k, daoAddr); err != nil { - return err - } - - return k.delegateValidators(ctx, vals, delegations, daoAddr) -} - -// GetDaoDelegationSupply returns total amount of the treasury bonded coins. -func (k Keeper) GetDaoDelegationSupply(ctx sdk.Context) sdk.Dec { - return k.getDaoDelegationSupply(ctx, k.stakingKeeper.GetAllValidators(ctx)) -} - -// getTargetDelegationState builds a map of the validators and the stake amount they should have now. -// if the validator is not in the map, the DAO stake is zero. -func (k Keeper) getTargetDelegationState(ctx sdk.Context, vals []stakingtypes.Validator) map[string]sdk.Int { - maxValCommission := k.MaxValCommission(ctx) - valsSelfBonds := make(map[string]sdk.Dec) // the key is OperatorAddress - valsSelfBondsSupply := sdk.ZeroDec() - for _, val := range vals { - if !val.IsBonded() { - continue - } - if val.GetCommission().GT(maxValCommission) { - continue - } - - valOper := val.GetOperator() - valAddr := sdk.AccAddress(valOper) - selfDelegation, found := k.stakingKeeper.GetDelegation(ctx, valAddr, valOper) - if !found || selfDelegation.GetShares().IsZero() { - continue - } - selfDelegationAmount := val.TokensFromShares(selfDelegation.GetShares()) - valsSelfBonds[valOper.String()] = selfDelegationAmount - valsSelfBondsSupply = valsSelfBondsSupply.Add(selfDelegationAmount) - } - - daoDelegationSupply := k.getDaoDelegationSupply(ctx, vals) - daoBondDenomSupply := k.treasuryBondDenomAmount(ctx).ToDec().Add(daoDelegationSupply) - - daoBondDenomToDelegate := daoBondDenomSupply.Sub(daoBondDenomSupply.Mul(k.PoolRate(ctx))) - - targetDelegationState := make(map[string]sdk.Int) // the key is OperatorAddress - for valAddr, selfDelegationAmt := range valsSelfBonds { - valDaoDelegationAmt := selfDelegationAmt.Mul(daoBondDenomToDelegate).Quo(valsSelfBondsSupply).TruncateInt() - if !valDaoDelegationAmt.IsZero() { - targetDelegationState[valAddr] = valDaoDelegationAmt - } - } - - return targetDelegationState -} - -// getDaoDelegationSupply returns total amount of the treasury bonded coins. -func (k Keeper) getDaoDelegationSupply(ctx sdk.Context, vals []stakingtypes.Validator) sdk.Dec { - daoAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) - - totalStakingSupply := sdk.ZeroDec() - for _, val := range vals { - delegation, found := k.stakingKeeper.GetDelegation(ctx, daoAddr, val.GetOperator()) - if !found || delegation.GetShares().IsZero() { - continue - } - delegationAmount := val.TokensFromShares(delegation.GetShares()) - totalStakingSupply = totalStakingSupply.Add(delegationAmount) - } - - return totalStakingSupply -} - -// computeDelegationsAndUndelegation computes the target (un)delegations. -func (k Keeper) computeDelegationsAndUndelegation( - ctx sdk.Context, - daoAddr sdk.AccAddress, - vals []stakingtypes.Validator, - targetDaoStaking map[string]sdk.Int, -) (map[string]sdk.Int, map[string]sdk.Int) { - delegations := make(map[string]sdk.Int) - undelegations := make(map[string]sdk.Int) - for _, val := range vals { - valAddr := val.GetOperator() - targetDaoDelegation, ok := targetDaoStaking[valAddr.String()] - delegatedByDao := sdk.ZeroInt() - delegation, found := k.stakingKeeper.GetDelegation(ctx, daoAddr, valAddr) - if found { - delegatedByDao = val.TokensFromShares(delegation.GetShares()).TruncateInt() - } - // for the validators not in the target list the target amount is zero - if !ok { - targetDaoDelegation = sdk.ZeroInt() - } - - delegationDelta := targetDaoDelegation.Sub(delegatedByDao) - if delegationDelta.IsZero() { - continue - } - - if delegationDelta.IsNegative() { - undelegations[valAddr.String()] = delegatedByDao.Sub(targetDaoDelegation) - continue - } - - delegations[valAddr.String()] = delegationDelta - } - return delegations, undelegations -} - -// undelegateValidators undelegates the requested amount from the validators in the undelegations. -func undelegateValidators(ctx sdk.Context, vals []stakingtypes.Validator, undelegations map[string]sdk.Int, k Keeper, daoAddr sdk.AccAddress) error { - for _, val := range vals { - valOper := val.GetOperator() - undelegationAmt, ok := undelegations[valOper.String()] - if !ok { - continue - } - if undelegationAmt.IsZero() { - continue - } - undelegationShares, err := val.SharesFromTokens(undelegationAmt) - if err != nil { - return err - } - if undelegationShares.IsZero() { - continue - } - - if _, err := k.stakingKeeper.UnbondAndUndelegateCoins(ctx, daoAddr, valOper, undelegationShares); err != nil { - return err - } - } - if len(undelegations) > 0 { - k.Logger(ctx).Info(fmt.Sprintf("rebalanced, undelegated: %+v", undelegations)) - } - - return nil -} - -// UndelegateAllValidators undelegate all validators. -func (k Keeper) UndelegateAllValidators(ctx sdk.Context) (err error) { - daoAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) - - vals := k.stakingKeeper.GetAllValidators(ctx) - - for _, val := range vals { - valAddr := val.GetOperator() - - delegation, found := k.stakingKeeper.GetDelegation(ctx, daoAddr, val.GetOperator()) - if !found || delegation.GetShares().IsZero() { - continue - } - - if _, err = k.stakingKeeper.UnbondAndUndelegateCoins(ctx, daoAddr, valAddr, delegation.GetShares()); err != nil { - return err - } - } - - return err -} - -// delegateValidators delegates the requested amount from the validators in the delegations. -func (k Keeper) delegateValidators(ctx sdk.Context, vals []stakingtypes.Validator, delegations map[string]sdk.Int, daoAddr sdk.AccAddress) error { - for _, val := range vals { - delegation, ok := delegations[val.GetOperator().String()] - if !ok { - continue - } - if delegation.IsZero() { - continue - } - if _, err := k.stakingKeeper.Delegate(ctx, daoAddr, delegation, stakingtypes.Unbonded, val, true); err != nil { - return err - } - } - if len(delegations) > 0 { - k.Logger(ctx).Info(fmt.Sprintf("rebalanced, delegated: %+v", delegations)) - } - - return nil -} diff --git a/x/dao/keeper/genesis.go b/x/dao/keeper/genesis.go deleted file mode 100644 index 451bec99..00000000 --- a/x/dao/keeper/genesis.go +++ /dev/null @@ -1,30 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// InitGenesis sets dao module information from genesis. -func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) error { - k.SetParams(ctx, genState.Params) - - // if the height is 1 or 0 the chain is in the initial state - if ctx.BlockHeight() <= 1 { - balance := genState.TreasuryBalance - if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, balance); err != nil { - return err - } - } - - return nil -} - -// ExportGenesis returns a GenesisState for a given context and keeper. -func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - return &types.GenesisState{ - Params: k.getParams(ctx), - TreasuryBalance: k.treasury(ctx), - } -} diff --git a/x/dao/keeper/grpc_query.go b/x/dao/keeper/grpc_query.go deleted file mode 100644 index 3b7b9518..00000000 --- a/x/dao/keeper/grpc_query.go +++ /dev/null @@ -1,43 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// QueryServer is keep wrapper which provides query capabilities. -type QueryServer struct { - keeper Keeper -} - -// NewQueryServer creates a new instance of QueryServer. -func NewQueryServer(keeper Keeper) *QueryServer { - return &QueryServer{ - keeper: keeper, - } -} - -var _ types.QueryServer = QueryServer{} - -// Params return dao module current params values. -func (q QueryServer) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - ctx := sdk.UnwrapSDKContext(c) - - return &types.QueryParamsResponse{Params: q.keeper.GetParams(ctx)}, nil -} - -// Treasury returns the treasury balance. -func (q QueryServer) Treasury(c context.Context, _ *types.QueryTreasuryRequest) (*types.QueryTreasuryResponse, error) { - ctx := sdk.UnwrapSDKContext(c) - return &types.QueryTreasuryResponse{ - TreasuryBalance: q.keeper.Treasury(ctx), - }, nil -} diff --git a/x/dao/keeper/keeper.go b/x/dao/keeper/keeper.go deleted file mode 100644 index 5266d280..00000000 --- a/x/dao/keeper/keeper.go +++ /dev/null @@ -1,70 +0,0 @@ -// Package keeper contains dao module keeper. -package keeper - -import ( - "fmt" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/tendermint/tendermint/libs/log" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -type ( - // Keeper is a dao keeper struct. - Keeper struct { - cdc codec.BinaryCodec - storeKey sdk.StoreKey - memKey sdk.StoreKey - ps types.ParamSubspace - bankKeeper types.BankKeeper - accountKeeper types.AccountKeeper - distributionKeeper types.DistributionKeeper - govKeeper types.GovKeeper - mintKeeper types.MintKeeper - stakingKeeper types.StakingKeeper - } -) - -// NewKeeper creates new dao keeper. -func NewKeeper( - cdc codec.BinaryCodec, - storeKey, - memKey sdk.StoreKey, - ps types.ParamSubspace, - bankKeeper types.BankKeeper, - accountKeeper types.AccountKeeper, - distributionKeeper types.DistributionKeeper, - govKeeper types.GovKeeper, - mintKeeper types.MintKeeper, - stakingKeeper types.StakingKeeper, -) *Keeper { - // set KeyTable if it has not already been set - if !ps.HasKeyTable() { - ps = ps.WithKeyTable(types.ParamKeyTable()) - } - - // ensure dao module account is set - if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil { - panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) - } - - return &Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, - ps: ps, - bankKeeper: bankKeeper, - accountKeeper: accountKeeper, - distributionKeeper: distributionKeeper, - govKeeper: govKeeper, - mintKeeper: mintKeeper, - stakingKeeper: stakingKeeper, - } -} - -// Logger returns keeper logger. -func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) -} diff --git a/x/dao/keeper/mint.go b/x/dao/keeper/mint.go deleted file mode 100644 index ff12a302..00000000 --- a/x/dao/keeper/mint.go +++ /dev/null @@ -1,27 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// InflateDao inflates treasury by APR from minter. -func (k Keeper) InflateDao(ctx sdk.Context) (err error) { - daoAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) - daoBalance := k.bankKeeper.GetBalance(ctx, daoAddr, "anom") - minter := k.mintKeeper.GetMinter(ctx) - params := k.mintKeeper.GetParams(ctx) - minter.AnnualProvisions = minter.NextAnnualProvisions(params, daoBalance.Amount) - - // mint coins, update supply - mintedCoin := minter.BlockProvision(params) - mintedCoins := sdk.NewCoins(mintedCoin) - - err = k.bankKeeper.MintCoins(ctx, types.ModuleName, mintedCoins) - if err != nil { - panic(err) - } - - return err -} diff --git a/x/dao/keeper/params.go b/x/dao/keeper/params.go deleted file mode 100644 index 0f4528e1..00000000 --- a/x/dao/keeper/params.go +++ /dev/null @@ -1,46 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// GetParams returns the total set of dao parameters. -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return k.getParams(ctx) -} - -// SetParams set the params. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.ps.SetParamSet(ctx, ¶ms) -} - -// WithdrawRewardPeriod - the blocks period to dao staking reward. -func (k Keeper) WithdrawRewardPeriod(ctx sdk.Context) (res int64) { - k.ps.Get(ctx, types.KeyWithdrawRewardPeriod, &res) - return -} - -// MaxValCommission - the max validator's commission to be staked by the dao. -func (k Keeper) MaxValCommission(ctx sdk.Context) (res sdk.Dec) { - k.ps.Get(ctx, types.KeyMaxValCommission, &res) - return -} - -// MaxProposalRate - the rate of max allowed proposal from the treasury amount. -func (k Keeper) MaxProposalRate(ctx sdk.Context) (res sdk.Dec) { - k.ps.Get(ctx, types.KeyMaxProposalRate, &res) - return -} - -// PoolRate - the rate of total dao's staking coins to keep unstaked. -func (k Keeper) PoolRate(ctx sdk.Context) (res sdk.Dec) { - k.ps.Get(ctx, types.KeyPoolRate, &res) - return -} - -func (k Keeper) getParams(ctx sdk.Context) (params types.Params) { - k.ps.GetParamSet(ctx, ¶ms) - return params -} diff --git a/x/dao/keeper/params_test.go b/x/dao/keeper/params_test.go deleted file mode 100644 index efc3191a..00000000 --- a/x/dao/keeper/params_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/onomyprotocol/onomy/testutil/simapp" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -func TestKeeper_GetAndSetParams(t *testing.T) { - type args struct { - params types.Params - } - - tests := []struct { - name string - args args - }{ - { - name: "positive", - args: args{ - params: types.DefaultParams(), - }, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - simApp := simapp.Setup() - ctx := simApp.NewContext() - - simApp.OnomyApp().DaoKeeper.SetParams(ctx, tt.args.params) - got := simApp.OnomyApp().DaoKeeper.GetParams(ctx) - - require.Equal(t, tt.args.params, got) - }) - } -} diff --git a/x/dao/keeper/proposal.go b/x/dao/keeper/proposal.go deleted file mode 100644 index 31a9c1d5..00000000 --- a/x/dao/keeper/proposal.go +++ /dev/null @@ -1,91 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// FundTreasuryProposal submits the FundTreasuryProposal. -func (k Keeper) FundTreasuryProposal(ctx sdk.Context, request *types.FundTreasuryProposal) error { - senderAddr, err := sdk.AccAddressFromBech32(request.Sender) - if err != nil { - return err - } - - senderBalance := k.bankKeeper.GetAllBalances(ctx, senderAddr) - amountToSend := request.Amount - if _, isNegative := senderBalance.SafeSub(amountToSend); isNegative { - return sdkerrors.Wrapf(types.ErrInsufficientBalance, "sender balance is less than amount to send") - } - - return k.bankKeeper.SendCoinsFromAccountToModule(ctx, senderAddr, types.ModuleName, amountToSend) -} - -// ExchangeWithTreasuryProposal submits the ExchangeWithTreasuryProposal. -func (k Keeper) ExchangeWithTreasuryProposal(ctx sdk.Context, request *types.ExchangeWithTreasuryProposal) error { - senderAddr, err := sdk.AccAddressFromBech32(request.Sender) - if err != nil { - return err - } - - coinsAsk := sdk.NewCoins() - coinsBid := sdk.NewCoins() - for i := range request.CoinsPairs { - coinsAsk = coinsAsk.Add(request.CoinsPairs[i].CoinAsk) - coinsBid = coinsBid.Add(request.CoinsPairs[i].CoinBid) - } - - senderBalance := k.bankKeeper.GetAllBalances(ctx, senderAddr) - if _, isNegative := senderBalance.SafeSub(coinsBid); isNegative { - return sdkerrors.Wrapf(types.ErrInsufficientBalance, "sender balance is less than bid coins amount") - } - - treasuryBalance := k.bankKeeper.GetAllBalances(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName)) - if _, isNegative := treasuryBalance.SafeSub(coinsAsk); isNegative { - return sdkerrors.Wrapf(types.ErrInsufficientBalance, "treasury balance is less than ask coins amount") - } - - if err := k.validateMaxProposalRate(ctx, treasuryBalance, coinsAsk); err != nil { - return err - } - - if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, senderAddr, types.ModuleName, coinsBid); err != nil { - return err - } - - return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, senderAddr, coinsAsk) -} - -// FundAccountProposal submits the FundAccountProposal. -func (k Keeper) FundAccountProposal(ctx sdk.Context, request *types.FundAccountProposal) error { - recipientAddr, err := sdk.AccAddressFromBech32(request.Recipient) - if err != nil { - return err - } - - treasuryBalance := k.bankKeeper.GetAllBalances(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName)) - amountToSend := request.Amount - if _, isNegative := treasuryBalance.SafeSub(amountToSend); isNegative { - return sdkerrors.Wrapf(types.ErrInsufficientBalance, "treasury balance is less than amount to send") - } - if err := k.validateMaxProposalRate(ctx, treasuryBalance, amountToSend); err != nil { - return err - } - - return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, recipientAddr, amountToSend) -} - -func (k Keeper) validateMaxProposalRate(ctx sdk.Context, treasuryBalance, coinsAsk sdk.Coins) error { - maxProposalRate := k.MaxProposalRate(ctx) - for _, tcoin := range treasuryBalance { - askAmount := coinsAsk.AmountOf(tcoin.Denom) - allowedAmount := tcoin.Amount.ToDec().Mul(maxProposalRate).TruncateInt() - if allowedAmount.LT(askAmount) { - return sdkerrors.Wrapf(types.ErrProhibitedCoinsAmount, "requested %s:%s amount is more than max allowed %s:%s ", - tcoin.Denom, askAmount, tcoin.Denom, allowedAmount.String()) - } - } - return nil -} diff --git a/x/dao/keeper/proposal_test.go b/x/dao/keeper/proposal_test.go deleted file mode 100644 index 2c02eff6..00000000 --- a/x/dao/keeper/proposal_test.go +++ /dev/null @@ -1,567 +0,0 @@ -package keeper_test - -import ( - "encoding/json" - "testing" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/gov" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/params/types/proposal" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" - - "github.com/onomyprotocol/onomy/testutil/simapp" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -func TestKeeper_FundTreasuryProposal(t *testing.T) { - const ( - denom1 = "denom1" - denom2 = "denom2" - ) - - accountAddress := simapp.GenAccountAddress() - - type args struct { - accountBalance sdk.Coins - sender string - amount sdk.Coins - } - - tests := []struct { - name string - args args - wantTreasuryBalance sdk.Coins - wantErr error - }{ - { - name: "positive_one_coin_full", - args: args{ - accountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - sender: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - wantTreasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - { - name: "positive_one_coin_partial", - args: args{ - accountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - sender: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5)), - }, - wantTreasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5)), - }, - { - name: "positive_two_coins_partial", - args: args{ - accountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10), sdk.NewInt64Coin(denom2, 8)), - sender: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5), sdk.NewInt64Coin(denom2, 8)), - }, - wantTreasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5), sdk.NewInt64Coin(denom2, 8)), - }, - { - name: "negative_insufficient_balance", - args: args{ - accountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - sender: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 11)), - }, - wantErr: sdkerrors.Wrapf(types.ErrInsufficientBalance, "sender balance is less than amount to send"), - }, - { - name: "negative_not_existing_token", - args: args{ - accountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - sender: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom2, 10)), - }, - wantErr: sdkerrors.Wrapf(types.ErrInsufficientBalance, "sender balance is less than amount to send"), - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - simApp := simapp.Setup() - ctx := simApp.NewContext() - require.NoError(t, simApp.OnomyApp().BankKeeper.MintCoins(ctx, types.ModuleName, tt.args.accountBalance)) - - senderAddr, err := sdk.AccAddressFromBech32(tt.args.sender) - require.NoError(t, err) - require.NoError(t, simApp.OnomyApp().BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, senderAddr, tt.args.accountBalance)) - - err = simApp.OnomyApp().DaoKeeper.FundTreasuryProposal(ctx, &types.FundTreasuryProposal{ - Sender: tt.args.sender, - Amount: tt.args.amount, - }) - - if tt.wantErr != nil { - require.Equal(t, tt.wantErr.Error(), err.Error()) - return - } - require.NoError(t, err, err) - - got := simApp.OnomyApp().DaoKeeper.Treasury(ctx) - require.Equal(t, tt.wantTreasuryBalance, got) - }) - } -} - -func TestKeeper_ExchangeWithTreasuryProposal(t *testing.T) { - const ( - denom1 = "denom1" - denom2 = "denom2" - denom3 = "denom3" - denom4 = "denom4" - ) - - accountAddress := simapp.GenAccountAddress() - - type args struct { - treasuryBalance sdk.Coins - accountBalance sdk.Coins - sender string - coinsPairs []types.CoinsExchangePair - } - - tests := []struct { - name string - args args - wantAccountBalance sdk.Coins - wantTreasuryBalance sdk.Coins - wantErr error - }{ - { - name: "positive_exchange_full", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10000)), - accountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom2, 10)), - sender: accountAddress.String(), - coinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom1, 8), - CoinBid: sdk.NewInt64Coin(denom2, 10), - }, - }, - }, - wantTreasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom2, 10), sdk.NewInt64Coin(denom1, 9992)), - wantAccountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 8)), - }, - { - name: "positive_exchange_multiple_pairs", - args: args{ - treasuryBalance: sdk.NewCoins( - sdk.NewInt64Coin(denom1, 50000), - sdk.NewInt64Coin(denom2, 50000), - sdk.NewInt64Coin(denom3, 50000), - sdk.NewInt64Coin(denom4, 50000), - ), - accountBalance: sdk.NewCoins( - sdk.NewInt64Coin(denom1, 100), - sdk.NewInt64Coin(denom2, 100), - sdk.NewInt64Coin(denom3, 100), - ), - sender: accountAddress.String(), - coinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom1, 8), - CoinBid: sdk.NewInt64Coin(denom2, 10), - }, - { - CoinAsk: sdk.NewInt64Coin(denom1, 4), - CoinBid: sdk.NewInt64Coin(denom2, 2), - }, - { - CoinAsk: sdk.NewInt64Coin(denom3, 5), - CoinBid: sdk.NewInt64Coin(denom1, 5), - }, - }, - }, - wantTreasuryBalance: sdk.NewCoins( - // 50000 - 8 - 4 + 5 - sdk.NewInt64Coin(denom1, 49993), - // 50000 + 10 + 2 - sdk.NewInt64Coin(denom2, 50012), - // 50000 - 5 - sdk.NewInt64Coin(denom3, 49995), - sdk.NewInt64Coin(denom4, 50000), - ), - wantAccountBalance: sdk.NewCoins( - // 100 + 8 + 4 - 5 - sdk.NewInt64Coin(denom1, 107), - // 100 - 10 - 2 - sdk.NewInt64Coin(denom2, 88), - // 100 + 5 - sdk.NewInt64Coin(denom3, 105), - ), - }, - { - name: "negative_insufficient_sender_balance", - args: args{ - treasuryBalance: sdk.NewCoins( - sdk.NewInt64Coin(denom1, 50), - sdk.NewInt64Coin(denom2, 50), - ), - accountBalance: sdk.NewCoins( - sdk.NewInt64Coin(denom1, 4), - sdk.NewInt64Coin(denom2, 12), - ), - sender: accountAddress.String(), - coinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom1, 8), - CoinBid: sdk.NewInt64Coin(denom2, 10), - }, - { - CoinAsk: sdk.NewInt64Coin(denom1, 4), - CoinBid: sdk.NewInt64Coin(denom2, 2), - }, - { - CoinAsk: sdk.NewInt64Coin(denom3, 5), - CoinBid: sdk.NewInt64Coin(denom1, 5), - }, - }, - }, - wantErr: sdkerrors.Wrapf(types.ErrInsufficientBalance, "sender balance is less than bid coins amount"), - }, - { - name: "negative_insufficient_treasury_balance", - args: args{ - treasuryBalance: sdk.NewCoins( - sdk.NewInt64Coin(denom1, 50), - sdk.NewInt64Coin(denom3, 2), - ), - accountBalance: sdk.NewCoins( - sdk.NewInt64Coin(denom1, 100), - sdk.NewInt64Coin(denom2, 100), - ), - sender: accountAddress.String(), - coinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom1, 8), - CoinBid: sdk.NewInt64Coin(denom2, 10), - }, - { - CoinAsk: sdk.NewInt64Coin(denom1, 4), - CoinBid: sdk.NewInt64Coin(denom2, 2), - }, - { - CoinAsk: sdk.NewInt64Coin(denom3, 5), - CoinBid: sdk.NewInt64Coin(denom1, 5), - }, - }, - }, - wantErr: sdkerrors.Wrapf(types.ErrInsufficientBalance, "treasury balance is less than ask coins amount"), - }, - { - name: "negative_prohibited_proposal_amount", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 100)), - accountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom2, 10)), - sender: accountAddress.String(), - coinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom1, 8), - CoinBid: sdk.NewInt64Coin(denom2, 10), - }, - }, - }, - wantErr: sdkerrors.Wrapf(types.ErrProhibitedCoinsAmount, "requested denom1:8 amount is more than max allowed denom1:5 "), - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - simApp := simapp.Setup() - ctx := simApp.NewContext() - - simApp.OnomyApp().DaoKeeper.SetParams(ctx, types.DefaultParams()) - require.NoError(t, simApp.OnomyApp().BankKeeper.MintCoins(ctx, types.ModuleName, tt.args.treasuryBalance)) - require.NoError(t, simApp.OnomyApp().BankKeeper.MintCoins(ctx, types.ModuleName, tt.args.accountBalance)) - senderAddr, err := sdk.AccAddressFromBech32(tt.args.sender) - require.NoError(t, err) - require.NoError(t, simApp.OnomyApp().BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, senderAddr, tt.args.accountBalance)) - - err = simApp.OnomyApp().DaoKeeper.ExchangeWithTreasuryProposal(ctx, &types.ExchangeWithTreasuryProposal{ - Sender: tt.args.sender, - CoinsPairs: tt.args.coinsPairs, - }) - - if tt.wantErr != nil { - require.Equal(t, tt.wantErr.Error(), err.Error()) - return - } - require.NoError(t, err, err) - - got := simApp.OnomyApp().DaoKeeper.Treasury(ctx) - require.Equal(t, tt.wantTreasuryBalance, got) - - senderBalance := simApp.OnomyApp().BankKeeper.GetAllBalances(ctx, senderAddr) - require.Equal(t, tt.wantAccountBalance, senderBalance) - }) - } -} - -func TestKeeper_FundAccountProposal(t *testing.T) { - const ( - denom1 = "denom1" - denom2 = "denom2" - ) - - accountAddress := simapp.GenAccountAddress() - - type args struct { - treasuryBalance sdk.Coins - recipient string - amount sdk.Coins - } - - tests := []struct { - name string - args args - wantAccountBalance sdk.Coins - wantErr error - }{ - { - name: "positive_one_coin_full", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10000)), - recipient: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - wantAccountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - { - name: "positive_one_coin_partial", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10000)), - recipient: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5)), - }, - wantAccountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5)), - }, - { - name: "positive_two_coins_partial", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10000), sdk.NewInt64Coin(denom2, 80000)), - recipient: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5), sdk.NewInt64Coin(denom2, 8)), - }, - wantAccountBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5), sdk.NewInt64Coin(denom2, 8)), - }, - { - name: "negative_insufficient_balance", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - recipient: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 11)), - }, - wantErr: sdkerrors.Wrapf(types.ErrInsufficientBalance, "treasury balance is less than amount to send"), - }, - { - name: "negative_not_existing_token", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - recipient: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom2, 10)), - }, - wantErr: sdkerrors.Wrapf(types.ErrInsufficientBalance, "treasury balance is less than amount to send"), - }, - { - name: "negative_prohibited_proposal_amount", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 50)), - recipient: accountAddress.String(), - amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 5)), - }, - wantErr: sdkerrors.Wrapf(types.ErrProhibitedCoinsAmount, "requested denom1:5 amount is more than max allowed denom1:2 "), - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - simApp := simapp.Setup() - ctx := simApp.NewContext() - simApp.OnomyApp().DaoKeeper.SetParams(ctx, types.DefaultParams()) - - require.NoError(t, simApp.OnomyApp().BankKeeper.MintCoins(ctx, types.ModuleName, tt.args.treasuryBalance)) - err := simApp.OnomyApp().DaoKeeper.FundAccountProposal(ctx, &types.FundAccountProposal{ - Recipient: tt.args.recipient, - Amount: tt.args.amount, - }) - - if tt.wantErr != nil { - require.Equal(t, tt.wantErr.Error(), err.Error()) - return - } - require.NoError(t, err, err) - - recipientAddr, err := sdk.AccAddressFromBech32(tt.args.recipient) - require.NoError(t, err) - got := simApp.OnomyApp().BankKeeper.GetAllBalances(ctx, recipientAddr) - require.Equal(t, tt.wantAccountBalance, got) - }) - } -} - -func TestKeeper_ProposalsFullCycle(t *testing.T) { - var ( - accountAddress = simapp.GenAccountAddress() - tenPercents = sdk.NewDec(1).QuoInt64(10) - oneBondCoin = sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction)) - twoBondCoins = sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(2, sdk.DefaultPowerReduction)) - tenBondCoins = sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)) - thousandBondCoins = sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)) - commission = stakingtypes.NewCommissionRates(tenPercents, tenPercents, tenPercents) - ) - - type args struct { - treasuryBalance sdk.Coins - proposal func(proposer sdk.AccAddress) govtypes.Content - } - - tests := []struct { - name string - args args - wantTreasuryBalance sdk.Coins - }{ - { - name: "positive_fund_treasury", - args: args{ - proposal: func(proposer sdk.AccAddress) govtypes.Content { - return types.NewFundTreasuryProposal(proposer, "title", "desc", sdk.NewCoins(oneBondCoin)) - }, - }, - // the expectation includes the DefaultPoolRate logic because of the end-blocker rebalancer, - // also we add 1 because of the redelegation truncation - wantTreasuryBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, oneBondCoin.Amount)), - }, - { - name: "positive_exchange_with_treasury", - args: args{ - treasuryBalance: sdk.NewCoins(thousandBondCoins), - proposal: func(proposer sdk.AccAddress) govtypes.Content { - return types.NewExchangeWithTreasuryProposal(proposer, "title", "desc", []types.CoinsExchangePair{ - { - CoinAsk: oneBondCoin, - CoinBid: twoBondCoins, - }, - }) - }, - }, - - wantTreasuryBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, thousandBondCoins.Sub(oneBondCoin).Add(twoBondCoins).Amount)), - }, - { - name: "positive_fund_account", - args: args{ - treasuryBalance: sdk.NewCoins(thousandBondCoins), - proposal: func(_ sdk.AccAddress) govtypes.Content { - // we can any accountAddress for that proposal - return types.NewFundAccountProposal(accountAddress, "title", "desc", sdk.NewCoins(oneBondCoin)) - }, - }, - - wantTreasuryBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, thousandBondCoins.Sub(oneBondCoin).Amount)), - }, - { - name: "positive_change_pool_rate_param", - args: args{ - treasuryBalance: sdk.NewCoins(thousandBondCoins), - proposal: func(_ sdk.AccAddress) govtypes.Content { - return proposal.NewParameterChangeProposal("title", "desc", []proposal.ParamChange{ - { - Subspace: types.ModuleName, - Key: string(types.KeyPoolRate), - Value: `"0.5"`, - }, - }) - }, - }, - // new pool rate must change the treasury pool - wantTreasuryBalance: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, thousandBondCoins.Amount)), - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - const ( - proposer = "proposer" - voter = "voter" - ) - - vals := map[string]simapp.ValReq{ - // low voting poser - proposer: { - SelfBondCoin: oneBondCoin, - Commission: commission, - Balance: sdk.NewCoins(tenBondCoins), - }, - // high voting poser - voter: { - SelfBondCoin: tenBondCoins, - Commission: commission, - Balance: sdk.NewCoins(tenBondCoins.Add(tenBondCoins)), - }, - } - - options := make([]simapp.Option, 0) - if tt.args.treasuryBalance != nil { - // treasury genesis - treasuryOverrideOpt := simapp.WithGenesisOverride( - func(m map[string]json.RawMessage) map[string]json.RawMessage { - daoGenesis := types.DefaultGenesis() - daoGenesis.TreasuryBalance = tt.args.treasuryBalance - daoGenesisString, err := json.Marshal(daoGenesis) - require.NoError(t, err) - m[types.ModuleName] = daoGenesisString - return m - }) - options = append(options, treasuryOverrideOpt) - } - - simApp, privs := simapp.SetupWithValidators(t, vals, options...) - - privProposer := privs[proposer] - privVoter := privs[voter] - - simApp.BeginNextBlock() - ctx := simApp.CurrentContext() - - addressProposer := sdk.AccAddress(privProposer.PubKey().Address()) - simApp.CreateProposal(t, tt.args.proposal(addressProposer), oneBondCoin, privProposer) - - simApp.EndBlock(ctx) - - proposalID := uint64(1) - - // vote - simApp.BeginNextBlock() - ctx = simApp.CurrentContext() - simApp.VoteProposal(t, proposalID, govtypes.OptionYes, privVoter) - simApp.EndBlock(ctx) - - // execute the proposal - simApp.BeginNextBlock() - ctx = simApp.CurrentContext() - // +30 days to finish the voting - ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Hour * 24 * 30)) - gov.EndBlocker(ctx, simApp.OnomyApp().GovKeeper) - // assert the proposal - proposal, _ := simApp.OnomyApp().GovKeeper.GetProposal(ctx, proposalID) - require.Equal(t, govtypes.StatusPassed, proposal.Status) - - // execute the proposal - simApp.BeginNextBlock() - ctx = simApp.CurrentContext() - simApp.EndBlock(ctx) - - // assert treasury - require.Equal(t, tt.wantTreasuryBalance.String(), simApp.OnomyApp().DaoKeeper.Treasury(ctx).String()) - }) - } -} diff --git a/x/dao/keeper/reward.go b/x/dao/keeper/reward.go deleted file mode 100644 index 4d8c172a..00000000 --- a/x/dao/keeper/reward.go +++ /dev/null @@ -1,33 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// WithdrawReward withdraw dao delegation reward. -func (k Keeper) WithdrawReward(ctx sdk.Context) error { - vals := k.stakingKeeper.GetAllValidators(ctx) - daoAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) - for _, val := range vals { - valOperator := val.GetOperator() - _, found := k.stakingKeeper.GetDelegation(ctx, daoAddr, valOperator) - if !found { - continue - } - // check existence of delegator starting info - if !k.distributionKeeper.HasDelegatorStartingInfo(ctx, valOperator, daoAddr) { - continue - } - - reward, err := k.distributionKeeper.WithdrawDelegationRewards(ctx, daoAddr, valOperator) - if err != nil { - return err - } - k.Logger(ctx).Info(fmt.Sprintf("withdrawn reward: %s", reward.String())) - } - return nil -} diff --git a/x/dao/keeper/treasury.go b/x/dao/keeper/treasury.go deleted file mode 100644 index 01da6bff..00000000 --- a/x/dao/keeper/treasury.go +++ /dev/null @@ -1,33 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// Treasury returns the treasury balance. -func (k Keeper) Treasury(ctx sdk.Context) sdk.Coins { - return k.treasury(ctx) -} - -func (k Keeper) treasuryBondDenomAmount(ctx sdk.Context) sdk.Int { - denom := k.stakingKeeper.BondDenom(ctx) - return k.treasury(ctx).AmountOf(denom) -} - -// treasury returns the treasury balance. -func (k Keeper) treasury(ctx sdk.Context) sdk.Coins { - daoAddress := k.accountKeeper.GetModuleAddress(types.ModuleName) - return k.bankKeeper.GetAllBalances(ctx, daoAddress) -} - -// GetBalance returns account balance. -func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin { - return k.bankKeeper.GetBalance(ctx, addr, denom) -} - -// SendCoins transfers coins from one account to another. -func (k Keeper) SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error { - return k.bankKeeper.SendCoins(ctx, fromAddr, toAddr, amt) -} diff --git a/x/dao/keeper/treasury_test.go b/x/dao/keeper/treasury_test.go deleted file mode 100644 index df0ef13b..00000000 --- a/x/dao/keeper/treasury_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - "github.com/onomyprotocol/onomy/testutil/simapp" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -func TestKeeper_Treasury(t *testing.T) { - const ( - denom1 = "denom1" - denom2 = "denom2" - ) - - type args struct { - treasuryBalance sdk.Coins - } - - tests := []struct { - name string - args args - want sdk.Coins - }{ - { - name: "get_from_genesis", - args: args{ - treasuryBalance: sdk.NewCoins(sdk.NewInt64Coin(denom1, 1), sdk.NewInt64Coin(denom2, 2)), - }, - want: sdk.NewCoins(sdk.NewInt64Coin(denom1, 1), sdk.NewInt64Coin(denom2, 2)), - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - simApp := simapp.Setup() - ctx := simApp.OnomyApp().BaseApp.NewContext(false, tmproto.Header{}) - - err := simApp.OnomyApp().DaoKeeper.InitGenesis(ctx, types.GenesisState{ - Params: types.DefaultParams(), - TreasuryBalance: tt.args.treasuryBalance, - }) - require.NoError(t, err) - - got := simApp.OnomyApp().DaoKeeper.Treasury(ctx) - require.Equal(t, tt.want, got) - }) - } -} diff --git a/x/dao/keeper/voting.go b/x/dao/keeper/voting.go deleted file mode 100644 index a4d76bfe..00000000 --- a/x/dao/keeper/voting.go +++ /dev/null @@ -1,32 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// VoteAbstain votes abstain on all the proposals from the DAO account. -func (k Keeper) VoteAbstain(ctx sdk.Context) (err error) { - daoAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) - k.govKeeper.IterateProposals(ctx, func(proposal govtypes.Proposal) bool { - if proposal.Status != govtypes.StatusVotingPeriod { - return false - } - _, found := k.govKeeper.GetVote(ctx, proposal.ProposalId, daoAddr) - // the dao should vote now - if !found { - err = k.govKeeper.AddVote(ctx, proposal.ProposalId, daoAddr, govtypes.NewNonSplitVoteOption(govtypes.OptionAbstain)) - if err != nil { - return true - } - k.Logger(ctx).Info(fmt.Sprintf("voted abstain on proposal[%d]: %s", proposal.ProposalId, proposal.GetTitle())) - } - return false - }) - - return err -} diff --git a/x/dao/module.go b/x/dao/module.go deleted file mode 100644 index 7de34afe..00000000 --- a/x/dao/module.go +++ /dev/null @@ -1,177 +0,0 @@ -// Package dao contains dao module implementation. -package dao - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/onomyprotocol/onomy/x/dao/client/cli" - "github.com/onomyprotocol/onomy/x/dao/keeper" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} -) - -// ---------------------------------------------------------------------------- -// AppModuleBasic. -// ----------------------------------------------------------------------------. - -// AppModuleBasic implements the AppModuleBasic interface for the dao module. -type AppModuleBasic struct { - cdc codec.BinaryCodec -} - -// NewAppModuleBasic creates new AppModuleBasic. -func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { - return AppModuleBasic{cdc: cdc} -} - -// Name returns the dao module's name. -func (AppModuleBasic) Name() string { - return types.ModuleName -} - -// RegisterCodec registers default codec. -func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} - -// RegisterLegacyAminoCodec registers amino codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} - -// RegisterInterfaces registers the module's interface types. -func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { - types.RegisterInterfaces(reg) -} - -// DefaultGenesis returns the dao module's default genesis state. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesis()) -} - -// ValidateGenesis performs genesis state validation for the dao module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { - var genState types.GenesisState - if err := cdc.UnmarshalJSON(bz, &genState); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) - } - return genState.Validate() -} - -// RegisterRESTRoutes registers the dao module's REST service handlers. -func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { -} - -// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { - panic(err) - } -} - -// GetTxCmd returns the dao module's root tx command. -func (a AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.GetTxCmd() -} - -// GetQueryCmd returns the dao module's root query command. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(types.StoreKey) -} - -// ----------------------------------------------------------------------------. -// AppModule. -// ----------------------------------------------------------------------------. - -// AppModule implements the AppModule interface for the dao module. -type AppModule struct { - AppModuleBasic - keeper keeper.Keeper -} - -// NewAppModule creates dao AppModule. -func NewAppModule( - cdc codec.Codec, - keeper keeper.Keeper, -) AppModule { - return AppModule{ - AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, - } -} - -// Name returns the dao module's name. -func (am AppModule) Name() string { - return am.AppModuleBasic.Name() -} - -// Route returns the dao module's message routing key. -func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(types.RouterKey, NewHandler()) -} - -// QuerierRoute returns the dao module's query routing key. -func (AppModule) QuerierRoute() string { return types.QuerierRoute } - -// LegacyQuerierHandler returns the dao module's Querier. -func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { - return nil -} - -// RegisterServices registers a GRPC query service to respond to the -// module-specific GRPC queries. -func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) -} - -// RegisterInvariants registers the dao module's invariants. -func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} - -// InitGenesis performs the dao module's genesis initialization It returns -// no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { - var genState types.GenesisState - // Initialize global index to index in genesis state - cdc.MustUnmarshalJSON(gs, &genState) - - InitGenesis(ctx, am.keeper, genState) - - return []abci.ValidatorUpdate{} -} - -// ExportGenesis returns the dao module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := ExportGenesis(ctx, am.keeper) - return cdc.MustMarshalJSON(genState) -} - -// ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 2 } // nolint:gomnd // constant number for cosmos sdk - -// BeginBlock executes all ABCI BeginBlock logic respective to the dao module. -func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - BeginBlocker(ctx, am.keeper) -} - -// EndBlock executes all ABCI EndBlock logic respective to the dao module. It -// returns no validator updates. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - EndBlocker(ctx, am.keeper) - return []abci.ValidatorUpdate{} -} diff --git a/x/dao/module_simulation.go b/x/dao/module_simulation.go deleted file mode 100644 index 5dc436ad..00000000 --- a/x/dao/module_simulation.go +++ /dev/null @@ -1,50 +0,0 @@ -package dao - -import ( - "math/rand" - - "github.com/cosmos/cosmos-sdk/baseapp" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/simulation" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -// avoid unused import issue. -var ( - _ = simappparams.StakePerAccount - _ = simulation.MsgEntryKind - _ = baseapp.Paramspace -) - -// GenerateGenesisState creates a randomized GenState of the module. -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - accs := make([]string, len(simState.Accounts)) - for i, acc := range simState.Accounts { - accs[i] = acc.Address.String() - } - daoGenesis := types.GenesisState{} - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&daoGenesis) -} - -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { - return nil -} - -// RandomizedParams creates randomized param changes for the simulator. -func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - -// RegisterStoreDecoder registers a decoder. -func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} - -// WeightedOperations returns the all the gov module operations with their respective weights. -func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { - operations := make([]simtypes.WeightedOperation, 0) - return operations -} diff --git a/x/dao/spec/01_state.md b/x/dao/spec/01_state.md deleted file mode 100644 index 498c3380..00000000 --- a/x/dao/spec/01_state.md +++ /dev/null @@ -1,18 +0,0 @@ - - -# State - -## Treasury - -The Treasury or DAO wallet is a DAO module account with the initial coins amount set in the genesis file. Apart from -the genesis, the treasury holds the coins received after the proposal operations. - -## Staking - -The DAO module extends the "staking" module for the staking operation. - -## Slashing - -The DAO module, in the chain, will be protected from slashing by the extended slashing configuration options. diff --git a/x/dao/spec/02_state_transitions.md b/x/dao/spec/02_state_transitions.md deleted file mode 100644 index 74c82fdd..00000000 --- a/x/dao/spec/02_state_transitions.md +++ /dev/null @@ -1,55 +0,0 @@ - - -# State Transitions - -This document describes the state transition operations: - -1. [Delegation](02_state_transitions.md#delegation) -2. [WithdrawReward](02_state_transitions.md#withdrawreward) -3. [Voting](02_state_transitions.md#voting) -4. [Proposals](02_state_transitions.md#proposals) - -## Delegation - -### Delegate - -The DAO delegates its staking coins (NOMs) from the treasury to validators proportionately based on the self-bonded amount -of each validator with respect to the total self-bonded amount of all validators, in addition, if the validator commission rate -more than "max_val_commission" param the validator will be excluded from the DAO staking. The DAO -limits the delegation by the "pool_rate" parameter. It means that "pool_rate" of the total -amount of DAO's staking coins (NOMs) won't be staked. - -### Rebalance - -The rebalance is a process of the unbonding and delegation of the treasury staking coins (NOMs) based on -the [delegation](#Delegate) rules. - -## WithdrawReward - -Since the DAO is a delegator it can withdraw the delegator reward. Once the delegation reward is withdrawn it goes -to the treasury. The withdrawal reward is called based on the "withdraw_reward_period" parameter, specified in blocks. - -## Voting - -### Vote - -Since the DAO is a delegator it can vote for the proposals otherwise the validator inherits its voting power. In -order to exclude the DAO's voting power, that DAO votes "Abstain" for all created proposals. - -## Proposals - -The DAO module extends the existing proposals with new types of proposals: - -- `FundTreasuryProposal` - the user provides the amount to fund. If accepted the coins will be sent from the user's - account to the treasury. -- `ExchangeWithTreasuryProposal` - the user provides the list of pairs to exchange with the treasury. If accepted the - coins will be sent from the treasury to the user's account. -- `FundAccountProposal` - the user provides the amount to fund and recipient. If accepted the coins will be - sent from the treasury to the recipient's account. - -Additional proposals rule: - -* Each funding or exchange proposal may not exceed more than the "max_proposal_rate" of the total amount of - DAO's staking coins (NOMs). diff --git a/x/dao/spec/03_end_block.md b/x/dao/spec/03_end_block.md deleted file mode 100644 index a99bb11b..00000000 --- a/x/dao/spec/03_end_block.md +++ /dev/null @@ -1,11 +0,0 @@ - - -# End-Block - -Each abci end block call, the operations will be executed: - -- [WithdrawReward](02_state_transitions.md#withdrawreward) -- [Rebalance](02_state_transitions.md#rebalance) -- [Vote](02_state_transitions.md#vote) diff --git a/x/dao/spec/04_params.md b/x/dao/spec/04_params.md deleted file mode 100644 index d2c8f521..00000000 --- a/x/dao/spec/04_params.md +++ /dev/null @@ -1,14 +0,0 @@ - - -# Parameters - -The DAO module contains the following parameters: - -| Key | Type | Example | -|------------------|--------|--------------------------------------------------------------------------------------------------------------| -| params | object | {"pool_rate":"0.05", "max_proposal_rate":"0.05", "max_val_commission":"0.1", "withdraw_reward_period":51840} | -| treasury_balance | array | [{"denom": "anom", "amount": "0"}] | - -__NOTE__: The "params" might be changed using `ParameterChangeProposal`. diff --git a/x/dao/spec/README.md b/x/dao/spec/README.md deleted file mode 100644 index e84f44eb..00000000 --- a/x/dao/spec/README.md +++ /dev/null @@ -1,31 +0,0 @@ - - -# `dao` - -## Abstract - -This paper specifies the DAO (Decentralized Autonomous Organization) module of the onomy chain. The DAO module provides -the advanced model of funding and exchange using governance proposals. Additionally, it extends the existing -staking by the dynamic delegation of the staking tokens from the treasury to the validators. - -## Contents - -1. **[State](01_state.md)** - - [Treasury](01_state.md#treasury) - - [Params](01_state.md#params) - - [Staking](01_state.md#staking) - -2. **[State Transitions](02_state_transitions.md)** - - [Delegation](02_state_transitions.md#delegation) - - [WithdrawReward](02_state_transitions.md#withdrawreward) - - [Voting](02_state_transitions.md#voting) - - [Proposals](02_state_transitions.md#proposals) - -5. **[End-Block](03_end_block.md)** - -4. **[Parameters](04_params.md)** \ No newline at end of file diff --git a/x/dao/types/codec.go b/x/dao/types/codec.go deleted file mode 100644 index 8e162ea9..00000000 --- a/x/dao/types/codec.go +++ /dev/null @@ -1,33 +0,0 @@ -package types - -import ( - "fmt" - - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" -) - -// RegisterCodec registers the legacy amino codec. -func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&FundTreasuryProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeFundTreasuryProposal), nil) - cdc.RegisterConcrete(&ExchangeWithTreasuryProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeExchangeWithTreasuryProposal), nil) - cdc.RegisterConcrete(&FundAccountProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeFundAccountProposal), nil) -} - -// RegisterInterfaces registers the cdctypes interface. -func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - registry.RegisterImplementations( - (*govtypes.Content)(nil), - &FundTreasuryProposal{}, - &ExchangeWithTreasuryProposal{}, - &FundAccountProposal{}, - ) -} - -var ( - // Amino holds the LegacyAmino codec. - Amino = codec.NewLegacyAmino() // nolint:gochecknoglobals // cosmos sdk style - // ModuleCdc holds the default proto codec. - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) // nolint:gochecknoglobals // cosmos sdk style -) diff --git a/x/dao/types/dao.pb.go b/x/dao/types/dao.pb.go deleted file mode 100644 index 08f0389d..00000000 --- a/x/dao/types/dao.pb.go +++ /dev/null @@ -1,1339 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: onomyprotocol/dao/v1/dao.proto - -package types - -import ( - fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// FundTreasuryProposal details a dao fund treasury proposal. -type FundTreasuryProposal struct { - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` - Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` - Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount" yaml:"amount"` -} - -func (m *FundTreasuryProposal) Reset() { *m = FundTreasuryProposal{} } -func (*FundTreasuryProposal) ProtoMessage() {} -func (*FundTreasuryProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_763c2cafbce2acfd, []int{0} -} -func (m *FundTreasuryProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *FundTreasuryProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_FundTreasuryProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *FundTreasuryProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_FundTreasuryProposal.Merge(m, src) -} -func (m *FundTreasuryProposal) XXX_Size() int { - return m.Size() -} -func (m *FundTreasuryProposal) XXX_DiscardUnknown() { - xxx_messageInfo_FundTreasuryProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_FundTreasuryProposal proto.InternalMessageInfo - -// ExchangeWithTreasuryProposal details a dao exchange with treasury proposal. -type ExchangeWithTreasuryProposal struct { - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` - Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` - CoinsPairs []CoinsExchangePair `protobuf:"bytes,4,rep,name=coins_pairs,json=coinsPairs,proto3" json:"coins_pairs" yaml:"coins_pairs"` -} - -func (m *ExchangeWithTreasuryProposal) Reset() { *m = ExchangeWithTreasuryProposal{} } -func (*ExchangeWithTreasuryProposal) ProtoMessage() {} -func (*ExchangeWithTreasuryProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_763c2cafbce2acfd, []int{1} -} -func (m *ExchangeWithTreasuryProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ExchangeWithTreasuryProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ExchangeWithTreasuryProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ExchangeWithTreasuryProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_ExchangeWithTreasuryProposal.Merge(m, src) -} -func (m *ExchangeWithTreasuryProposal) XXX_Size() int { - return m.Size() -} -func (m *ExchangeWithTreasuryProposal) XXX_DiscardUnknown() { - xxx_messageInfo_ExchangeWithTreasuryProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_ExchangeWithTreasuryProposal proto.InternalMessageInfo - -// CoinsExchangePair is an ask/bid coins pair to exchange. -type CoinsExchangePair struct { - CoinAsk types.Coin `protobuf:"bytes,1,opt,name=coin_ask,json=coinAsk,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coin" json:"coin_ask" yaml:"coin_ask"` - CoinBid types.Coin `protobuf:"bytes,2,opt,name=coin_bid,json=coinBid,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coin" json:"coin_bid" yaml:"coin_bid"` -} - -func (m *CoinsExchangePair) Reset() { *m = CoinsExchangePair{} } -func (m *CoinsExchangePair) String() string { return proto.CompactTextString(m) } -func (*CoinsExchangePair) ProtoMessage() {} -func (*CoinsExchangePair) Descriptor() ([]byte, []int) { - return fileDescriptor_763c2cafbce2acfd, []int{2} -} -func (m *CoinsExchangePair) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *CoinsExchangePair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_CoinsExchangePair.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *CoinsExchangePair) XXX_Merge(src proto.Message) { - xxx_messageInfo_CoinsExchangePair.Merge(m, src) -} -func (m *CoinsExchangePair) XXX_Size() int { - return m.Size() -} -func (m *CoinsExchangePair) XXX_DiscardUnknown() { - xxx_messageInfo_CoinsExchangePair.DiscardUnknown(m) -} - -var xxx_messageInfo_CoinsExchangePair proto.InternalMessageInfo - -func (m *CoinsExchangePair) GetCoinAsk() types.Coin { - if m != nil { - return m.CoinAsk - } - return types.Coin{} -} - -func (m *CoinsExchangePair) GetCoinBid() types.Coin { - if m != nil { - return m.CoinBid - } - return types.Coin{} -} - -// FundAccountProposal details a dao fund account proposal. -type FundAccountProposal struct { - Recipient string `protobuf:"bytes,1,opt,name=recipient,proto3" json:"recipient,omitempty"` - Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` - Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` - Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,4,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount" yaml:"amount"` -} - -func (m *FundAccountProposal) Reset() { *m = FundAccountProposal{} } -func (*FundAccountProposal) ProtoMessage() {} -func (*FundAccountProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_763c2cafbce2acfd, []int{3} -} -func (m *FundAccountProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *FundAccountProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_FundAccountProposal.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *FundAccountProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_FundAccountProposal.Merge(m, src) -} -func (m *FundAccountProposal) XXX_Size() int { - return m.Size() -} -func (m *FundAccountProposal) XXX_DiscardUnknown() { - xxx_messageInfo_FundAccountProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_FundAccountProposal proto.InternalMessageInfo - -func init() { - proto.RegisterType((*FundTreasuryProposal)(nil), "onomyprotocol.dao.v1.FundTreasuryProposal") - proto.RegisterType((*ExchangeWithTreasuryProposal)(nil), "onomyprotocol.dao.v1.ExchangeWithTreasuryProposal") - proto.RegisterType((*CoinsExchangePair)(nil), "onomyprotocol.dao.v1.CoinsExchangePair") - proto.RegisterType((*FundAccountProposal)(nil), "onomyprotocol.dao.v1.FundAccountProposal") -} - -func init() { proto.RegisterFile("onomyprotocol/dao/v1/dao.proto", fileDescriptor_763c2cafbce2acfd) } - -var fileDescriptor_763c2cafbce2acfd = []byte{ - // 485 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x54, 0x41, 0x8b, 0x13, 0x31, - 0x14, 0x9e, 0xec, 0x6a, 0x75, 0x53, 0x45, 0x1c, 0x8b, 0xd4, 0xb2, 0x64, 0xca, 0x5c, 0xb6, 0x08, - 0x4e, 0xa8, 0xde, 0xf6, 0xd6, 0x11, 0xc5, 0xe3, 0x52, 0x04, 0xc1, 0xcb, 0x92, 0x49, 0x42, 0x1b, - 0xda, 0x49, 0x86, 0x24, 0x2d, 0xed, 0x2f, 0xd0, 0xa3, 0x47, 0x8f, 0x3d, 0x8a, 0xbf, 0x64, 0x8f, - 0x7b, 0xf4, 0xb4, 0xca, 0xf4, 0x22, 0x5e, 0x04, 0x7f, 0x81, 0x24, 0x33, 0xee, 0x76, 0x55, 0xc4, - 0x1e, 0x3c, 0x78, 0x4a, 0xde, 0x7b, 0x79, 0xef, 0x7b, 0xdf, 0xfb, 0x1e, 0x81, 0x48, 0x49, 0x95, - 0x2f, 0x0b, 0xad, 0xac, 0xa2, 0x6a, 0x8a, 0x19, 0x51, 0x78, 0xde, 0x77, 0x47, 0xe2, 0x7d, 0x61, - 0xeb, 0x52, 0x3c, 0x71, 0x81, 0x79, 0xbf, 0xd3, 0x1a, 0xa9, 0x91, 0xf2, 0x4e, 0xec, 0x6e, 0xd5, - 0xdb, 0x0e, 0xa2, 0xca, 0xe4, 0xca, 0xe0, 0x8c, 0x18, 0x8e, 0xe7, 0xfd, 0x8c, 0x5b, 0xd2, 0xc7, - 0x54, 0x09, 0x59, 0xc5, 0xe3, 0x2f, 0x00, 0xb6, 0x9e, 0xce, 0x24, 0x7b, 0xae, 0x39, 0x31, 0x33, - 0xbd, 0x3c, 0xd2, 0xaa, 0x50, 0x86, 0x4c, 0xc3, 0xbb, 0xb0, 0x61, 0xb8, 0x64, 0x5c, 0xb7, 0x41, - 0x17, 0xf4, 0xf6, 0x86, 0xb5, 0x15, 0xb6, 0xe0, 0x55, 0x2b, 0xec, 0x94, 0xb7, 0x77, 0xbc, 0xbb, - 0x32, 0xc2, 0x2e, 0x6c, 0x32, 0x6e, 0xa8, 0x16, 0x85, 0x15, 0x4a, 0xb6, 0x77, 0x7d, 0x6c, 0xd3, - 0x15, 0x5a, 0xd8, 0x20, 0xb9, 0x9a, 0x49, 0xdb, 0xbe, 0xd2, 0xdd, 0xed, 0x35, 0x1f, 0xde, 0x4b, - 0xaa, 0xce, 0x12, 0xd7, 0x59, 0x52, 0x77, 0x96, 0x3c, 0x56, 0x42, 0xa6, 0x83, 0x93, 0xb3, 0x28, - 0xf8, 0x76, 0x16, 0xdd, 0x5c, 0x92, 0x7c, 0x7a, 0x18, 0x57, 0x69, 0xf1, 0xfb, 0x8f, 0x51, 0x6f, - 0x24, 0xec, 0x78, 0x96, 0x25, 0x54, 0xe5, 0xb8, 0xe6, 0x55, 0x1d, 0x0f, 0x0c, 0x9b, 0x60, 0xbb, - 0x2c, 0xb8, 0xf1, 0x15, 0xcc, 0xb0, 0xc6, 0x3a, 0xbc, 0xf1, 0x7a, 0x15, 0x05, 0x6f, 0x57, 0x51, - 0xf0, 0x79, 0x15, 0x05, 0x71, 0x09, 0xe0, 0xfe, 0x93, 0x05, 0x1d, 0x13, 0x39, 0xe2, 0x2f, 0x84, - 0x1d, 0xff, 0x73, 0xd2, 0x0c, 0x36, 0xdd, 0xac, 0xcd, 0x71, 0x41, 0x84, 0x36, 0x35, 0xf3, 0x83, - 0xe4, 0x77, 0xfa, 0x55, 0x8d, 0xff, 0xe8, 0xee, 0x88, 0x08, 0x9d, 0x76, 0xea, 0x39, 0x84, 0xd5, - 0x1c, 0x36, 0x2a, 0xc5, 0x43, 0xe8, 0x2d, 0xf7, 0xcc, 0xfc, 0x44, 0xf2, 0xd5, 0x0e, 0xbc, 0xfd, - 0x4b, 0xad, 0x70, 0x01, 0xaf, 0xbb, 0x8c, 0x63, 0x62, 0x26, 0x9e, 0xdb, 0x1f, 0x05, 0x48, 0x6b, - 0xe0, 0x5b, 0x17, 0xc0, 0x2e, 0xd1, 0x49, 0x70, 0xf0, 0x97, 0x12, 0x0c, 0xaf, 0xb9, 0xac, 0x81, - 0x99, 0x9c, 0x23, 0x67, 0x82, 0xf9, 0xf1, 0x6d, 0x8d, 0x9c, 0x09, 0xb6, 0x3d, 0x72, 0x2a, 0x58, - 0xfc, 0x15, 0xc0, 0x3b, 0x6e, 0xb7, 0x07, 0x94, 0xba, 0x65, 0x38, 0x57, 0x79, 0x1f, 0xee, 0x69, - 0x4e, 0x45, 0x21, 0xb8, 0xb4, 0xb5, 0xd0, 0x17, 0x8e, 0xff, 0x79, 0xc1, 0xd3, 0x67, 0xef, 0x4a, - 0x04, 0x4e, 0x4a, 0x04, 0x4e, 0x4b, 0x04, 0x3e, 0x95, 0x08, 0xbc, 0x59, 0xa3, 0xe0, 0x74, 0x8d, - 0x82, 0x0f, 0x6b, 0x14, 0xbc, 0xbc, 0xbf, 0x51, 0xfd, 0xf2, 0x17, 0xe3, 0x2d, 0xbc, 0xf0, 0x5f, - 0x8d, 0x47, 0xc9, 0x1a, 0x3e, 0xf6, 0xe8, 0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9b, 0x99, 0xd3, - 0x78, 0x8c, 0x04, 0x00, 0x00, -} - -func (this *CoinsExchangePair) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*CoinsExchangePair) - if !ok { - that2, ok := that.(CoinsExchangePair) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.CoinAsk.Equal(&that1.CoinAsk) { - return false - } - if !this.CoinBid.Equal(&that1.CoinBid) { - return false - } - return true -} -func (m *FundTreasuryProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *FundTreasuryProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *FundTreasuryProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Amount) > 0 { - for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDao(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintDao(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x1a - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintDao(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0x12 - } - if len(m.Sender) > 0 { - i -= len(m.Sender) - copy(dAtA[i:], m.Sender) - i = encodeVarintDao(dAtA, i, uint64(len(m.Sender))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ExchangeWithTreasuryProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ExchangeWithTreasuryProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ExchangeWithTreasuryProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CoinsPairs) > 0 { - for iNdEx := len(m.CoinsPairs) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.CoinsPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDao(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintDao(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x1a - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintDao(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0x12 - } - if len(m.Sender) > 0 { - i -= len(m.Sender) - copy(dAtA[i:], m.Sender) - i = encodeVarintDao(dAtA, i, uint64(len(m.Sender))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *CoinsExchangePair) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CoinsExchangePair) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *CoinsExchangePair) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.CoinBid.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDao(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - { - size, err := m.CoinAsk.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDao(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *FundAccountProposal) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *FundAccountProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *FundAccountProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Amount) > 0 { - for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDao(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintDao(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x1a - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintDao(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0x12 - } - if len(m.Recipient) > 0 { - i -= len(m.Recipient) - copy(dAtA[i:], m.Recipient) - i = encodeVarintDao(dAtA, i, uint64(len(m.Recipient))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintDao(dAtA []byte, offset int, v uint64) int { - offset -= sovDao(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *FundTreasuryProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Sender) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - l = len(m.Title) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - if len(m.Amount) > 0 { - for _, e := range m.Amount { - l = e.Size() - n += 1 + l + sovDao(uint64(l)) - } - } - return n -} - -func (m *ExchangeWithTreasuryProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Sender) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - l = len(m.Title) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - if len(m.CoinsPairs) > 0 { - for _, e := range m.CoinsPairs { - l = e.Size() - n += 1 + l + sovDao(uint64(l)) - } - } - return n -} - -func (m *CoinsExchangePair) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.CoinAsk.Size() - n += 1 + l + sovDao(uint64(l)) - l = m.CoinBid.Size() - n += 1 + l + sovDao(uint64(l)) - return n -} - -func (m *FundAccountProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Recipient) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - l = len(m.Title) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovDao(uint64(l)) - } - if len(m.Amount) > 0 { - for _, e := range m.Amount { - l = e.Size() - n += 1 + l + sovDao(uint64(l)) - } - } - return n -} - -func sovDao(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozDao(x uint64) (n int) { - return sovDao(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *FundTreasuryProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: FundTreasuryProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: FundTreasuryProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Sender = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Amount = append(m.Amount, types.Coin{}) - if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipDao(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthDao - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ExchangeWithTreasuryProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ExchangeWithTreasuryProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ExchangeWithTreasuryProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Sender = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CoinsPairs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CoinsPairs = append(m.CoinsPairs, CoinsExchangePair{}) - if err := m.CoinsPairs[len(m.CoinsPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipDao(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthDao - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CoinsExchangePair) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CoinsExchangePair: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CoinsExchangePair: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CoinAsk", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.CoinAsk.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CoinBid", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.CoinBid.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipDao(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthDao - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *FundAccountProposal) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: FundAccountProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: FundAccountProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Recipient = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDao - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDao - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDao - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Amount = append(m.Amount, types.Coin{}) - if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipDao(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthDao - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipDao(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowDao - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowDao - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowDao - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthDao - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupDao - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthDao - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthDao = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowDao = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupDao = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/dao/types/errors.go b/x/dao/types/errors.go deleted file mode 100644 index 31f4ccac..00000000 --- a/x/dao/types/errors.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -import sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - -var ( - // ErrInsufficientBalance - the balance is insufficient for the operation. - ErrInsufficientBalance = sdkerrors.Register(ModuleName, 1, "insufficient balance") - // ErrInvalidCoinsPair - the coins pair is invalid. - ErrInvalidCoinsPair = sdkerrors.Register(ModuleName, 2, "invalid coins pair") // nolint:gomnd // error number - // ErrProhibitedCoinsAmount - the requested amount is prohibited. - ErrProhibitedCoinsAmount = sdkerrors.Register(ModuleName, 3, "prohibited coins amount") // nolint:gomnd // error number -) diff --git a/x/dao/types/expected_keepers.go b/x/dao/types/expected_keepers.go deleted file mode 100644 index 98602d5e..00000000 --- a/x/dao/types/expected_keepers.go +++ /dev/null @@ -1,62 +0,0 @@ -package types - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// ParamSubspace defines the expected Subspace interface. -type ParamSubspace interface { - HasKeyTable() bool - WithKeyTable(paramtypes.KeyTable) paramtypes.Subspace - Get(sdk.Context, []byte, interface{}) - GetParamSet(sdk.Context, paramtypes.ParamSet) - SetParamSet(sdk.Context, paramtypes.ParamSet) -} - -// AccountKeeper defines the contract required for account APIs. -type AccountKeeper interface { - GetModuleAddress(string) sdk.AccAddress -} - -// BankKeeper defines the contract needed to be fulfilled for banking and supply dependencies. -type BankKeeper interface { - GetAllBalances(sdk.Context, sdk.AccAddress) sdk.Coins - GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin - SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error - SendCoinsFromAccountToModule(sdk.Context, sdk.AccAddress, string, sdk.Coins) error - SendCoinsFromModuleToAccount(sdk.Context, string, sdk.AccAddress, sdk.Coins) error - SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error - MintCoins(sdk.Context, string, sdk.Coins) error -} - -// DistributionKeeper expected distribution keeper. -type DistributionKeeper interface { - HasDelegatorStartingInfo(sdk.Context, sdk.ValAddress, sdk.AccAddress) bool - WithdrawDelegationRewards(sdk.Context, sdk.AccAddress, sdk.ValAddress) (sdk.Coins, error) -} - -// GovKeeper expected gov keeper. -type GovKeeper interface { - AddVote(sdk.Context, uint64, sdk.AccAddress, govtypes.WeightedVoteOptions) error - GetVote(sdk.Context, uint64, sdk.AccAddress) (govtypes.Vote, bool) - IterateProposals(sdk.Context, func(proposal govtypes.Proposal) bool) -} - -// MintKeeper expected mint keeper. -type MintKeeper interface { - GetMinter(ctx sdk.Context) (minter minttypes.Minter) - GetParams(ctx sdk.Context) (params minttypes.Params) -} - -// StakingKeeper expected staking keeper. -type StakingKeeper interface { - BondDenom(sdk.Context) string - Delegate(sdk.Context, sdk.AccAddress, sdk.Int, stakingtypes.BondStatus, stakingtypes.Validator, bool) (sdk.Dec, error) - GetDelegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) (stakingtypes.Delegation, bool) - GetAllValidators(sdk.Context) []stakingtypes.Validator - UnbondAndUndelegateCoins(sdk.Context, sdk.AccAddress, sdk.ValAddress, sdk.Dec) (sdk.Int, error) -} diff --git a/x/dao/types/genesis.go b/x/dao/types/genesis.go deleted file mode 100644 index 67da6f80..00000000 --- a/x/dao/types/genesis.go +++ /dev/null @@ -1,26 +0,0 @@ -package types - -import sdk "github.com/cosmos/cosmos-sdk/types" - -// NewGenesisState creates a new GenesisState object. -func NewGenesisState(params Params, treasuryBalance sdk.Coins) *GenesisState { - return &GenesisState{ - Params: params, - TreasuryBalance: treasuryBalance, - } -} - -// DefaultGenesis returns the default dao genesis state. -func DefaultGenesis() *GenesisState { - return &GenesisState{ - Params: DefaultParams(), - } -} - -// Validate performs basic genesis state validation returning an error upon any failure. -func (m GenesisState) Validate() error { - if err := m.Params.Validate(); err != nil { - return err - } - return m.TreasuryBalance.Validate() -} diff --git a/x/dao/types/genesis.pb.go b/x/dao/types/genesis.pb.go deleted file mode 100644 index fddf4a87..00000000 --- a/x/dao/types/genesis.pb.go +++ /dev/null @@ -1,396 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: onomyprotocol/dao/v1/genesis.proto - -package types - -import ( - fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// GenesisState defines the dao module's genesis state. -type GenesisState struct { - // the dao module managed params - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - // the list of dao module coins - TreasuryBalance github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=treasury_balance,json=treasuryBalance,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"treasury_balance" yaml:"treasury_balance"` -} - -func (m *GenesisState) Reset() { *m = GenesisState{} } -func (m *GenesisState) String() string { return proto.CompactTextString(m) } -func (*GenesisState) ProtoMessage() {} -func (*GenesisState) Descriptor() ([]byte, []int) { - return fileDescriptor_de36a61e75260a5e, []int{0} -} -func (m *GenesisState) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *GenesisState) XXX_Merge(src proto.Message) { - xxx_messageInfo_GenesisState.Merge(m, src) -} -func (m *GenesisState) XXX_Size() int { - return m.Size() -} -func (m *GenesisState) XXX_DiscardUnknown() { - xxx_messageInfo_GenesisState.DiscardUnknown(m) -} - -var xxx_messageInfo_GenesisState proto.InternalMessageInfo - -func (m *GenesisState) GetParams() Params { - if m != nil { - return m.Params - } - return Params{} -} - -func (m *GenesisState) GetTreasuryBalance() github_com_cosmos_cosmos_sdk_types.Coins { - if m != nil { - return m.TreasuryBalance - } - return nil -} - -func init() { - proto.RegisterType((*GenesisState)(nil), "onomyprotocol.dao.v1.GenesisState") -} - -func init() { - proto.RegisterFile("onomyprotocol/dao/v1/genesis.proto", fileDescriptor_de36a61e75260a5e) -} - -var fileDescriptor_de36a61e75260a5e = []byte{ - // 311 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xca, 0xcf, 0xcb, 0xcf, - 0xad, 0x2c, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x4f, 0x49, 0xcc, 0xd7, 0x2f, 0x33, - 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x03, 0x8b, 0x0b, 0x89, 0xa0, 0xa8, 0xd1, - 0x4b, 0x49, 0xcc, 0xd7, 0x2b, 0x33, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x0b, 0xea, 0x83, - 0x58, 0x10, 0xb5, 0x52, 0x72, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xfa, 0x49, 0x89, 0xc5, 0xa9, - 0xfa, 0x65, 0x86, 0x49, 0xa9, 0x25, 0x89, 0x86, 0xfa, 0xc9, 0xf9, 0x99, 0x79, 0x50, 0x79, 0x45, - 0xac, 0xf6, 0x15, 0x24, 0x16, 0x25, 0xe6, 0x42, 0xad, 0x53, 0xba, 0xc7, 0xc8, 0xc5, 0xe3, 0x0e, - 0x71, 0x40, 0x70, 0x49, 0x62, 0x49, 0xaa, 0x90, 0x15, 0x17, 0x1b, 0x44, 0x81, 0x04, 0xa3, 0x02, - 0xa3, 0x06, 0xb7, 0x91, 0x8c, 0x1e, 0x36, 0x07, 0xe9, 0x05, 0x80, 0xd5, 0x38, 0xb1, 0x9c, 0xb8, - 0x27, 0xcf, 0x10, 0x04, 0xd5, 0x21, 0x34, 0x91, 0x91, 0x4b, 0xa0, 0xa4, 0x28, 0x35, 0xb1, 0xb8, - 0xb4, 0xa8, 0x32, 0x3e, 0x29, 0x31, 0x27, 0x31, 0x2f, 0x39, 0x55, 0x82, 0x49, 0x81, 0x59, 0x83, - 0xdb, 0x48, 0x52, 0x0f, 0xe2, 0x56, 0x3d, 0x90, 0x5b, 0xf5, 0xa0, 0x6e, 0xd5, 0x73, 0xce, 0xcf, - 0xcc, 0x73, 0xf2, 0x06, 0x99, 0xf1, 0xe9, 0x9e, 0xbc, 0x78, 0x65, 0x62, 0x6e, 0x8e, 0x95, 0x12, - 0xba, 0x01, 0x4a, 0xab, 0xee, 0xcb, 0x6b, 0xa4, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, - 0xe7, 0xea, 0x43, 0xfd, 0x0c, 0xa1, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, - 0xc1, 0x66, 0x15, 0x07, 0xf1, 0xc3, 0xb4, 0x3b, 0x41, 0x74, 0x3b, 0xb9, 0x9c, 0x78, 0x24, 0xc7, - 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, - 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x16, 0x92, 0xa1, 0xa8, 0x01, 0x05, 0xe6, 0xe9, 0x57, - 0x80, 0x03, 0x0c, 0x6c, 0x78, 0x12, 0x1b, 0x58, 0xce, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x73, - 0xa0, 0xac, 0x52, 0xc2, 0x01, 0x00, 0x00, -} - -func (m *GenesisState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.TreasuryBalance) > 0 { - for iNdEx := len(m.TreasuryBalance) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.TreasuryBalance[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { - offset -= sovGenesis(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *GenesisState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Params.Size() - n += 1 + l + sovGenesis(uint64(l)) - if len(m.TreasuryBalance) > 0 { - for _, e := range m.TreasuryBalance { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - return n -} - -func sovGenesis(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGenesis(x uint64) (n int) { - return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *GenesisState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TreasuryBalance", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TreasuryBalance = append(m.TreasuryBalance, types.Coin{}) - if err := m.TreasuryBalance[len(m.TreasuryBalance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipGenesis(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGenesis - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthGenesis - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupGenesis - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthGenesis - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/dao/types/genesis_test.go b/x/dao/types/genesis_test.go deleted file mode 100644 index 00b33b0b..00000000 --- a/x/dao/types/genesis_test.go +++ /dev/null @@ -1,136 +0,0 @@ -package types_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - - "github.com/onomyprotocol/onomy/x/dao/types" -) - -func TestGenesisState_Validate(t *testing.T) { - for _, tc := range []struct { - desc string - genState *types.GenesisState - valid bool - }{ - { - desc: "positive_default", - genState: types.DefaultGenesis(), - valid: true, - }, - { - desc: "positive_custom_params", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: 1, - PoolRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(1).Quo(sdk.NewDec(10)), - }, - }, - valid: true, - }, - { - desc: "negative_empty", - genState: &types.GenesisState{}, - valid: false, - }, - { - desc: "negative_negative_withdraw_reward_period", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: -1, - PoolRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(1).Quo(sdk.NewDec(10)), - }, - }, - valid: false, - }, - { - desc: "negative_negative_pool_rate", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: 1, - PoolRate: sdk.NewDec(-1).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(1).Quo(sdk.NewDec(10)), - }, - }, - valid: false, - }, - { - desc: "negative_more_than_one_pool_rate", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: 1, - PoolRate: sdk.NewDec(11).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(1).Quo(sdk.NewDec(10)), - }, - }, - valid: false, - }, - { - desc: "negative_negative_max_proposal_rate", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: 1, - PoolRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(-1).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(1).Quo(sdk.NewDec(10)), - }, - }, - valid: false, - }, - { - desc: "negative_negative_more_than_one_max_proposal_rate", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: 1, - PoolRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(11).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(1).Quo(sdk.NewDec(10)), - }, - }, - valid: false, - }, - { - desc: "negative_negative_max_val_commission", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: 1, - PoolRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(-1).Quo(sdk.NewDec(10)), - }, - }, - valid: false, - }, - { - desc: "negative_negative_more_than_one_max_val_commission", - genState: &types.GenesisState{ - Params: types.Params{ - WithdrawRewardPeriod: 1, - PoolRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxProposalRate: sdk.NewDec(1).Quo(sdk.NewDec(10)), - MaxValCommission: sdk.NewDec(11).Quo(sdk.NewDec(10)), - }, - }, - valid: false, - }, - } { - tc := tc - - t.Run(tc.desc, func(t *testing.T) { - err := tc.genState.Validate() - if tc.valid { - require.NoError(t, err) - } else { - require.Error(t, err) - } - }) - } -} diff --git a/x/dao/types/keys.go b/x/dao/types/keys.go deleted file mode 100644 index 8300d61b..00000000 --- a/x/dao/types/keys.go +++ /dev/null @@ -1,18 +0,0 @@ -package types - -const ( - // ModuleName defines the module name. - ModuleName = "dao" - - // StoreKey defines the primary module store key. - StoreKey = ModuleName - - // RouterKey is the message route for slashing. - RouterKey = ModuleName - - // QuerierRoute defines the module's query routing key. - QuerierRoute = ModuleName - - // MemStoreKey defines the in-memory store key. - MemStoreKey = "mem_dao" -) diff --git a/x/dao/types/params.go b/x/dao/types/params.go deleted file mode 100644 index 7f9bf401..00000000 --- a/x/dao/types/params.go +++ /dev/null @@ -1,154 +0,0 @@ -package types - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "gopkg.in/yaml.v2" -) - -var ( - // DefaultWithdrawRewardPeriod is default value for the DefaultWithdrawRewardPeriod param. - DefaultWithdrawRewardPeriod = int64(51840) //nolint:gomnd,gochecknoglobals // cosmos-sdk style - // DefaultPoolRate is default value for the DefaultPoolRate param. - DefaultPoolRate = sdk.NewDec(1).Quo(sdk.NewDec(20)) //nolint:gomnd,gochecknoglobals // cosmos-sdk style - // DefaultMaxProposalRate is default value for the DefaultMaxProposalRate param. - DefaultMaxProposalRate = sdk.NewDec(1).Quo(sdk.NewDec(20)) //nolint:gomnd,gochecknoglobals // cosmos-sdk style - // DefaultMaxValCommission is default value for the DefaultMaxValCommission param. - DefaultMaxValCommission = sdk.NewDec(1).Quo(sdk.NewDec(10)) //nolint:gomnd,gochecknoglobals // cosmos-sdk style -) - -// Parameter store keys. -var ( - // KeyWithdrawRewardPeriod is byte key for KeyWithdrawRewardPeriod param. - KeyWithdrawRewardPeriod = []byte("WithdrawRewardPeriod") //nolint:gochecknoglobals // cosmos-sdk style - // KeyPoolRate is byte key for KeyPoolRate param. - KeyPoolRate = []byte("PoolRate") //nolint:gochecknoglobals // cosmos-sdk style - // KeyMaxProposalRate is byte key for KeyMaxProposalRate param. - KeyMaxProposalRate = []byte("MaxProposalRate") //nolint:gochecknoglobals // cosmos-sdk style - // KeyMaxValCommission is byte key for KeyMaxValCommission param. - KeyMaxValCommission = []byte("MaxValCommission") //nolint:gochecknoglobals // cosmos-sdk style -) - -var _ paramtypes.ParamSet = (*Params)(nil) - -// ParamKeyTable the param key table for launch module. -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// NewParams creates a new Params instance. -func NewParams( - withdrawRewardPeriod int64, - poolRate, - maxProposalRate, - maxValCommission sdk.Dec, -) Params { - return Params{ - WithdrawRewardPeriod: withdrawRewardPeriod, - PoolRate: poolRate, - MaxProposalRate: maxProposalRate, - MaxValCommission: maxValCommission, - } -} - -// DefaultParams returns a default set of parameters. -func DefaultParams() Params { - return NewParams( - DefaultWithdrawRewardPeriod, DefaultPoolRate, DefaultMaxProposalRate, - DefaultMaxValCommission, - ) -} - -// ParamSetPairs get the params.ParamSet. -func (m *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyWithdrawRewardPeriod, &m.WithdrawRewardPeriod, validateWithdrawRewardPeriod), - paramtypes.NewParamSetPair(KeyPoolRate, &m.PoolRate, validatePoolRate), - paramtypes.NewParamSetPair(KeyMaxProposalRate, &m.MaxProposalRate, validateMaxProposalRate), - paramtypes.NewParamSetPair(KeyMaxValCommission, &m.MaxValCommission, validateMaxValCommission), - } -} - -// Validate validates the set of params. -func (m Params) Validate() error { - if err := validateWithdrawRewardPeriod(m.WithdrawRewardPeriod); err != nil { - return err - } - if err := validatePoolRate(m.PoolRate); err != nil { - return err - } - if err := validateMaxProposalRate(m.MaxProposalRate); err != nil { - return err - } - - return validateMaxValCommission(m.MaxValCommission) -} - -// String implements the Stringer interface. -func (m Params) String() string { - out, _ := yaml.Marshal(m) //nolint:errcheck // error is not expected here - return string(out) -} - -func validateWithdrawRewardPeriod(i interface{}) error { - v, ok := i.(int64) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v <= 0 { - return fmt.Errorf("withdraw reward period must be positive: %d", v) - } - - return nil -} - -func validatePoolRate(i interface{}) error { - v, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v.IsNil() || v.IsNegative() { - return fmt.Errorf("staking token pool rate cannot be negative or nil: %s", v) - } - if v.GT(sdk.OneDec()) { - return fmt.Errorf("staking token pool rate too large: %s", v) - } - - return nil -} - -func validateMaxProposalRate(i interface{}) error { - v, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v.IsNil() || v.IsNegative() { - return fmt.Errorf("staking token max proposal rate cannot be negative or nil: %s", v) - } - if v.GT(sdk.OneDec()) { - return fmt.Errorf("staking token max proposal rate too large: %s", v) - } - - return nil -} - -func validateMaxValCommission(i interface{}) error { - v, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v.IsNil() || v.IsNegative() { - return fmt.Errorf("staking max commission rate cannot be negative or nil: %s", v) - } - if v.GT(sdk.OneDec()) { - return fmt.Errorf("staking max commission rate too large: %s", v) - } - - return nil -} diff --git a/x/dao/types/params.pb.go b/x/dao/types/params.pb.go deleted file mode 100644 index 523cc7d6..00000000 --- a/x/dao/types/params.pb.go +++ /dev/null @@ -1,455 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: onomyprotocol/dao/v1/params.proto - -package types - -import ( - fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Params defines the parameters for the module. -type Params struct { - // the period of blocks to withdraw the dao staking reward - WithdrawRewardPeriod int64 `protobuf:"varint,1,opt,name=withdraw_reward_period,json=withdrawRewardPeriod,proto3" json:"withdraw_reward_period,omitempty" yaml:"withdraw_reward_period"` - // the rate of total dao's staking coins to keep unstaked - PoolRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=pool_rate,json=poolRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"pool_rate" yaml:"pool_rate"` - // the max rage of total dao's staking coins to be allowed in proposals - MaxProposalRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=max_proposal_rate,json=maxProposalRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_proposal_rate" yaml:"max_proposal_rate"` - // the max validator's commission to be staked by the dao - MaxValCommission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=max_val_commission,json=maxValCommission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_val_commission" yaml:"max_val_commission"` -} - -func (m *Params) Reset() { *m = Params{} } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_1367893a600edc4a, []int{0} -} -func (m *Params) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Params.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Params) XXX_Merge(src proto.Message) { - xxx_messageInfo_Params.Merge(m, src) -} -func (m *Params) XXX_Size() int { - return m.Size() -} -func (m *Params) XXX_DiscardUnknown() { - xxx_messageInfo_Params.DiscardUnknown(m) -} - -var xxx_messageInfo_Params proto.InternalMessageInfo - -func (m *Params) GetWithdrawRewardPeriod() int64 { - if m != nil { - return m.WithdrawRewardPeriod - } - return 0 -} - -func init() { - proto.RegisterType((*Params)(nil), "onomyprotocol.dao.v1.Params") -} - -func init() { proto.RegisterFile("onomyprotocol/dao/v1/params.proto", fileDescriptor_1367893a600edc4a) } - -var fileDescriptor_1367893a600edc4a = []byte{ - // 358 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xc1, 0x4e, 0xea, 0x40, - 0x14, 0x86, 0xdb, 0x0b, 0x21, 0xf7, 0x36, 0x37, 0xb9, 0xdc, 0x86, 0x98, 0x6a, 0x62, 0x0b, 0x5d, - 0x18, 0x62, 0x62, 0x27, 0xc4, 0x1d, 0xcb, 0xca, 0x4a, 0x37, 0xa4, 0x0b, 0x4d, 0xdc, 0x34, 0x87, - 0xb6, 0x81, 0xc6, 0x0e, 0x67, 0x32, 0x53, 0x4b, 0xfb, 0x16, 0x2e, 0x5d, 0xfa, 0x1e, 0xbe, 0x00, - 0x4b, 0x96, 0xc6, 0x45, 0x63, 0xe0, 0x0d, 0x78, 0x02, 0xc3, 0x80, 0x28, 0xd1, 0x0d, 0xab, 0x9e, - 0x7e, 0xe7, 0x9f, 0xff, 0xdb, 0x1c, 0xad, 0x85, 0x63, 0xa4, 0x05, 0xe3, 0x98, 0x62, 0x80, 0x09, - 0x09, 0x01, 0x49, 0xd6, 0x21, 0x0c, 0x38, 0x50, 0xe1, 0x48, 0xac, 0x37, 0x76, 0x22, 0x4e, 0x08, - 0xe8, 0x64, 0x9d, 0xa3, 0xc6, 0x10, 0x87, 0x28, 0x21, 0x59, 0x4d, 0xeb, 0xac, 0xfd, 0x5c, 0xd1, - 0x6a, 0x7d, 0xf9, 0x58, 0xbf, 0xd1, 0x0e, 0x26, 0x71, 0x3a, 0x0a, 0x39, 0x4c, 0x7c, 0x1e, 0x4d, - 0x80, 0x87, 0x3e, 0x8b, 0x78, 0x8c, 0xa1, 0xa1, 0x36, 0xd5, 0x76, 0xc5, 0x6d, 0x2d, 0x4b, 0xeb, - 0xb8, 0x00, 0x9a, 0x74, 0xed, 0x9f, 0x73, 0xb6, 0xd7, 0xf8, 0x58, 0x78, 0x92, 0xf7, 0x25, 0xd6, - 0x7d, 0xed, 0x0f, 0x43, 0x4c, 0x7c, 0x0e, 0x69, 0x64, 0xfc, 0x6a, 0xaa, 0xed, 0xbf, 0xae, 0x3b, - 0x2d, 0x2d, 0xe5, 0xb5, 0xb4, 0x4e, 0x86, 0x71, 0x3a, 0xba, 0x1f, 0x38, 0x01, 0x52, 0x12, 0xa0, - 0xa0, 0x28, 0x36, 0x9f, 0x33, 0x11, 0xde, 0x91, 0xb4, 0x60, 0x91, 0x70, 0x7a, 0x51, 0xb0, 0x2c, - 0xad, 0xfa, 0xda, 0xbc, 0x2d, 0xb2, 0xbd, 0xdf, 0xab, 0xd9, 0x83, 0x34, 0xd2, 0x33, 0xed, 0x3f, - 0x85, 0xdc, 0x67, 0x1c, 0x19, 0x0a, 0xd8, 0x88, 0x2a, 0x52, 0x74, 0xb9, 0xb7, 0xc8, 0x58, 0x8b, - 0xbe, 0x15, 0xda, 0xde, 0x3f, 0x0a, 0x79, 0x7f, 0x83, 0xa4, 0xb7, 0xd0, 0xf4, 0x55, 0x2c, 0x83, - 0xc4, 0x0f, 0x90, 0xd2, 0x58, 0x88, 0x18, 0xc7, 0x46, 0x55, 0x8a, 0xaf, 0xf6, 0x16, 0x1f, 0x7e, - 0x8a, 0x77, 0x1b, 0x6d, 0xaf, 0x4e, 0x21, 0xbf, 0x86, 0xe4, 0x62, 0x8b, 0xba, 0xd5, 0xc7, 0x27, - 0x4b, 0x71, 0x7b, 0xd3, 0xb9, 0xa9, 0xce, 0xe6, 0xa6, 0xfa, 0x36, 0x37, 0xd5, 0x87, 0x85, 0xa9, - 0xcc, 0x16, 0xa6, 0xf2, 0xb2, 0x30, 0x95, 0xdb, 0xd3, 0x2f, 0xda, 0xdd, 0x8b, 0x91, 0x7f, 0x24, - 0x97, 0x97, 0x23, 0xf5, 0x83, 0x9a, 0xdc, 0x9d, 0xbf, 0x07, 0x00, 0x00, 0xff, 0xff, 0x16, 0xbc, - 0x25, 0x78, 0x5b, 0x02, 0x00, 0x00, -} - -func (m *Params) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.MaxValCommission.Size() - i -= size - if _, err := m.MaxValCommission.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintParams(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - { - size := m.MaxProposalRate.Size() - i -= size - if _, err := m.MaxProposalRate.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintParams(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - { - size := m.PoolRate.Size() - i -= size - if _, err := m.PoolRate.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintParams(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if m.WithdrawRewardPeriod != 0 { - i = encodeVarintParams(dAtA, i, uint64(m.WithdrawRewardPeriod)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintParams(dAtA []byte, offset int, v uint64) int { - offset -= sovParams(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.WithdrawRewardPeriod != 0 { - n += 1 + sovParams(uint64(m.WithdrawRewardPeriod)) - } - l = m.PoolRate.Size() - n += 1 + l + sovParams(uint64(l)) - l = m.MaxProposalRate.Size() - n += 1 + l + sovParams(uint64(l)) - l = m.MaxValCommission.Size() - n += 1 + l + sovParams(uint64(l)) - return n -} - -func sovParams(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozParams(x uint64) (n int) { - return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Params) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Params: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field WithdrawRewardPeriod", wireType) - } - m.WithdrawRewardPeriod = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.WithdrawRewardPeriod |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PoolRate", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthParams - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthParams - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.PoolRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxProposalRate", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthParams - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthParams - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MaxProposalRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxValCommission", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthParams - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthParams - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MaxValCommission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipParams(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipParams(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthParams - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupParams - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthParams - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/dao/types/proposal.go b/x/dao/types/proposal.go deleted file mode 100644 index 4ded8e47..00000000 --- a/x/dao/types/proposal.go +++ /dev/null @@ -1,225 +0,0 @@ -package types - -import ( - "fmt" - "strings" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" -) - -const ( - // ProposalTypeFundTreasuryProposal defines the type for a FundTreasuryProposal. - ProposalTypeFundTreasuryProposal = "FundTreasuryProposal" - // ProposalTypeExchangeWithTreasuryProposal defines the type for a ExchangeWithTreasuryProposal. - ProposalTypeExchangeWithTreasuryProposal = "ExchangeWithTreasuryProposal" - // ProposalTypeFundAccountProposal defines the type for a FundAccountProposal. - ProposalTypeFundAccountProposal = "FundAccountProposal" -) - -var ( - _ govtypes.Content = &FundTreasuryProposal{} - _ govtypes.Content = &ExchangeWithTreasuryProposal{} - _ govtypes.Content = &FundAccountProposal{} -) - -func init() { // nolint:gochecknoinits // cosmos sdk style - govtypes.RegisterProposalType(ProposalTypeFundTreasuryProposal) - govtypes.RegisterProposalTypeCodec(&FundTreasuryProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeFundTreasuryProposal)) - - govtypes.RegisterProposalType(ProposalTypeExchangeWithTreasuryProposal) - govtypes.RegisterProposalTypeCodec(&ExchangeWithTreasuryProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeExchangeWithTreasuryProposal)) - - govtypes.RegisterProposalType(ProposalTypeFundAccountProposal) - govtypes.RegisterProposalTypeCodec(&FundAccountProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeFundAccountProposal)) -} - -// NewFundTreasuryProposal creates a new fund treasury proposal. -func NewFundTreasuryProposal(sender sdk.AccAddress, title, description string, amount sdk.Coins) *FundTreasuryProposal { - return &FundTreasuryProposal{sender.String(), title, description, amount} -} - -// GetTitle returns the title of a fund treasury proposal. -func (m *FundTreasuryProposal) GetTitle() string { return m.Title } - -// GetDescription returns the description of a fund treasury proposal. -func (m *FundTreasuryProposal) GetDescription() string { return m.Description } - -// ProposalRoute returns the routing key of a fund treasury proposal. -func (m *FundTreasuryProposal) ProposalRoute() string { return RouterKey } - -// ProposalType returns the type of the fund treasury proposal. -func (m *FundTreasuryProposal) ProposalType() string { return ProposalTypeFundTreasuryProposal } - -// ValidateBasic runs basic stateless validity checks. -func (m *FundTreasuryProposal) ValidateBasic() error { - err := govtypes.ValidateAbstract(m) - if err != nil { - return err - } - sender, err := sdk.AccAddressFromBech32(m.Sender) - if err != nil { - return err - } - if err := sdk.VerifyAddressFormat(sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address: %s", err) - } - - if !m.Amount.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, m.Amount.String()) - } - - if !m.Amount.IsAllPositive() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, m.Amount.String()) - } - - return nil -} - -// GetProposer returns the proposer from the proposal struct. -func (m *FundTreasuryProposal) GetProposer() string { return m.Sender } - -// String implements the Stringer interface. -func (m FundTreasuryProposal) String() string { - var b strings.Builder - b.WriteString(fmt.Sprintf(`Fund treasury proposal: - Sender: %s - Title: %s - Description: %s - Amount: %s -`, m.Sender, m.Title, m.Description, m.Amount)) - return b.String() -} - -// NewExchangeWithTreasuryProposal creates a new fund treasury proposal. -func NewExchangeWithTreasuryProposal(sender sdk.AccAddress, title, description string, coinsPairs []CoinsExchangePair) *ExchangeWithTreasuryProposal { - return &ExchangeWithTreasuryProposal{sender.String(), title, description, coinsPairs} -} - -// GetTitle returns the title of a fund treasury proposal. -func (m *ExchangeWithTreasuryProposal) GetTitle() string { return m.Title } - -// GetDescription returns the description of a fund treasury proposal. -func (m *ExchangeWithTreasuryProposal) GetDescription() string { return m.Description } - -// ProposalRoute returns the routing key of a fund treasury proposal. -func (m *ExchangeWithTreasuryProposal) ProposalRoute() string { return RouterKey } - -// ProposalType returns the type of the fund treasury proposal. -func (m *ExchangeWithTreasuryProposal) ProposalType() string { - return ProposalTypeExchangeWithTreasuryProposal -} - -// ValidateBasic runs basic stateless validity checks. -func (m *ExchangeWithTreasuryProposal) ValidateBasic() error { - err := govtypes.ValidateAbstract(m) - if err != nil { - return err - } - sender, err := sdk.AccAddressFromBech32(m.Sender) - if err != nil { - return err - } - if err := sdk.VerifyAddressFormat(sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address: %s", err) - } - - if len(m.CoinsPairs) == 0 { - return sdkerrors.Wrapf(ErrInvalidCoinsPair, "coins pairs can't be empty") - } - - for i := range m.CoinsPairs { - if err := m.CoinsPairs[i].ValidateBasic(); err != nil { - return err - } - } - - return nil -} - -// GetProposer returns the proposer from the proposal struct. -func (m *ExchangeWithTreasuryProposal) GetProposer() string { return m.Sender } - -// String implements the Stringer interface. -func (m ExchangeWithTreasuryProposal) String() string { - var b strings.Builder - b.WriteString(fmt.Sprintf(`Exchange with treasury proposal: - Sender: %s - Title: %s - Description: %s - Coin Pairs: %s -`, m.Sender, m.Title, m.Description, m.CoinsPairs)) - return b.String() -} - -// ValidateBasic validates CoinsExchangePair basic options. -func (m *CoinsExchangePair) ValidateBasic() error { - if m == nil { - return sdkerrors.Wrapf(ErrInvalidCoinsPair, "coins pairs can't be nil") - } - - if !m.CoinAsk.IsValid() || m.CoinAsk.IsZero() { - return sdkerrors.Wrapf(ErrInvalidCoinsPair, "invalid coin ask") - } - - if !m.CoinBid.IsValid() || m.CoinBid.IsZero() { - return sdkerrors.Wrapf(ErrInvalidCoinsPair, "invalid coin bid") - } - - return nil -} - -// NewFundAccountProposal creates a new fund account proposal. -func NewFundAccountProposal(recipient sdk.AccAddress, title, description string, amount sdk.Coins) *FundAccountProposal { - return &FundAccountProposal{recipient.String(), title, description, amount} -} - -// GetTitle returns the title of a fund account proposal. -func (m *FundAccountProposal) GetTitle() string { return m.Title } - -// GetDescription returns the description of a fund account proposal. -func (m *FundAccountProposal) GetDescription() string { return m.Description } - -// ProposalRoute returns the routing key of a fund account proposal. -func (m *FundAccountProposal) ProposalRoute() string { return RouterKey } - -// ProposalType returns the type of the fund account proposal. -func (m *FundAccountProposal) ProposalType() string { return ProposalTypeFundAccountProposal } - -// ValidateBasic runs basic stateless validity checks. -func (m *FundAccountProposal) ValidateBasic() error { - err := govtypes.ValidateAbstract(m) - if err != nil { - return err - } - sender, err := sdk.AccAddressFromBech32(m.Recipient) - if err != nil { - return err - } - if err := sdk.VerifyAddressFormat(sender); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address: %s", err) - } - - if !m.Amount.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, m.Amount.String()) - } - - if !m.Amount.IsAllPositive() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, m.Amount.String()) - } - - return nil -} - -// String implements the Stringer interface. -func (m FundAccountProposal) String() string { - var b strings.Builder - b.WriteString(fmt.Sprintf(`Fund account proposal: - Recipient: %s - Title: %s - Description: %s - Amount: %s -`, m.Recipient, m.Title, m.Description, m.Amount)) - return b.String() -} diff --git a/x/dao/types/proposal_test.go b/x/dao/types/proposal_test.go deleted file mode 100644 index abb3e32e..00000000 --- a/x/dao/types/proposal_test.go +++ /dev/null @@ -1,192 +0,0 @@ -package types_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/onomyprotocol/onomy/testutil/simapp" - "github.com/onomyprotocol/onomy/x/dao/types" -) - -func TestFundTreasuryProposal_ValidateBasic(t *testing.T) { //nolint:dupl // test template - const denom1 = "denom1" - - type fields struct { - Sender string - Title string - Description string - Amount sdk.Coins - } - tests := []struct { - name string - fields fields - wantErr bool - }{ - { - name: "positive", - fields: fields{ - Sender: simapp.GenAccountAddress().String(), - Title: "title", - Description: "desc", - Amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - }, - { - name: "negative_invalid_sender", - fields: fields{ - Sender: "invalid-sender", - Title: "title", - Description: "desc", - Amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - wantErr: true, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - m := &types.FundTreasuryProposal{ - Sender: tt.fields.Sender, - Title: tt.fields.Title, - Description: tt.fields.Description, - Amount: tt.fields.Amount, - } - if err := m.ValidateBasic(); (err != nil) != tt.wantErr { - t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestExchangeWithTreasuryProposal_ValidateBasic(t *testing.T) { - const ( - denom1 = "denom1" - denom2 = "denom2" - ) - - type fields struct { - Sender string - Title string - Description string - CoinsPairs []types.CoinsExchangePair - } - tests := []struct { - name string - fields fields - wantErr bool - }{ - { - name: "positive", - fields: fields{ - Sender: simapp.GenAccountAddress().String(), - Title: "title", - Description: "desc", - CoinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom1, 10), - CoinBid: sdk.NewInt64Coin(denom2, 5), - }, - { - CoinAsk: sdk.NewInt64Coin(denom2, 10), - CoinBid: sdk.NewInt64Coin(denom1, 5), - }, - }, - }, - wantErr: false, - }, - { - name: "negative_zero_coin", - fields: fields{ - Sender: simapp.GenAccountAddress().String(), - Title: "title", - Description: "desc", - CoinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom1, 10), - }, - }, - }, - wantErr: true, - }, - { - name: "negative_invalid_sender", - fields: fields{ - Sender: "invalid-sender", - Title: "title", - Description: "desc", - CoinsPairs: []types.CoinsExchangePair{ - { - CoinAsk: sdk.NewInt64Coin(denom2, 10), - CoinBid: sdk.NewInt64Coin(denom1, 5), - }, - }, - }, - wantErr: true, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - m := &types.ExchangeWithTreasuryProposal{ - Sender: tt.fields.Sender, - Title: tt.fields.Title, - Description: tt.fields.Description, - CoinsPairs: tt.fields.CoinsPairs, - } - if err := m.ValidateBasic(); (err != nil) != tt.wantErr { - t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestFundAccountProposal_ValidateBasic(t *testing.T) { // nolint:dupl // test template - const denom1 = "denom1" - - type fields struct { - Recipient string - Title string - Description string - Amount sdk.Coins - } - tests := []struct { - name string - fields fields - wantErr bool - }{ - { - name: "positive", - fields: fields{ - Recipient: simapp.GenAccountAddress().String(), - Title: "title", - Description: "desc", - Amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - }, - { - name: "negative_invalid_sender", - fields: fields{ - Recipient: "invalid-sender", - Title: "title", - Description: "desc", - Amount: sdk.NewCoins(sdk.NewInt64Coin(denom1, 10)), - }, - wantErr: true, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - m := &types.FundAccountProposal{ - Recipient: tt.fields.Recipient, - Title: tt.fields.Title, - Description: tt.fields.Description, - Amount: tt.fields.Amount, - } - if err := m.ValidateBasic(); (err != nil) != tt.wantErr { - t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} diff --git a/x/dao/types/query.pb.go b/x/dao/types/query.pb.go deleted file mode 100644 index 697af66e..00000000 --- a/x/dao/types/query.pb.go +++ /dev/null @@ -1,873 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: onomyprotocol/dao/v1/query.proto - -package types - -import ( - context "context" - fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/gogo/protobuf/gogoproto" - grpc1 "github.com/gogo/protobuf/grpc" - proto "github.com/gogo/protobuf/proto" - _ "google.golang.org/genproto/googleapis/api/annotations" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// QueryParamsRequest is request type for the Query/Params RPC method. -type QueryParamsRequest struct { -} - -func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } -func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryParamsRequest) ProtoMessage() {} -func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1d6940140b83f0f7, []int{0} -} -func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryParamsRequest.Merge(m, src) -} -func (m *QueryParamsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryParamsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo - -// QueryParamsResponse is response type for the Query/Params RPC method. -type QueryParamsResponse struct { - // params holds all the parameters of this module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` -} - -func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } -func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryParamsResponse) ProtoMessage() {} -func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1d6940140b83f0f7, []int{1} -} -func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryParamsResponse.Merge(m, src) -} -func (m *QueryParamsResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryParamsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo - -// QueryTreasuryRequest is request type for the Query/Treasury RPC method. -type QueryTreasuryRequest struct { -} - -func (m *QueryTreasuryRequest) Reset() { *m = QueryTreasuryRequest{} } -func (m *QueryTreasuryRequest) String() string { return proto.CompactTextString(m) } -func (*QueryTreasuryRequest) ProtoMessage() {} -func (*QueryTreasuryRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1d6940140b83f0f7, []int{2} -} -func (m *QueryTreasuryRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryTreasuryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryTreasuryRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryTreasuryRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryTreasuryRequest.Merge(m, src) -} -func (m *QueryTreasuryRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryTreasuryRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryTreasuryRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryTreasuryRequest proto.InternalMessageInfo - -// QueryTreasuryResponse is response type for the Query/Treasury RPC method. -type QueryTreasuryResponse struct { - TreasuryBalance github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=treasury_balance,json=treasuryBalance,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"treasury_balance" yaml:"treasury_balance"` -} - -func (m *QueryTreasuryResponse) Reset() { *m = QueryTreasuryResponse{} } -func (m *QueryTreasuryResponse) String() string { return proto.CompactTextString(m) } -func (*QueryTreasuryResponse) ProtoMessage() {} -func (*QueryTreasuryResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1d6940140b83f0f7, []int{3} -} -func (m *QueryTreasuryResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryTreasuryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryTreasuryResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryTreasuryResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryTreasuryResponse.Merge(m, src) -} -func (m *QueryTreasuryResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryTreasuryResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryTreasuryResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryTreasuryResponse proto.InternalMessageInfo - -func init() { - proto.RegisterType((*QueryParamsRequest)(nil), "onomyprotocol.dao.v1.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "onomyprotocol.dao.v1.QueryParamsResponse") - proto.RegisterType((*QueryTreasuryRequest)(nil), "onomyprotocol.dao.v1.QueryTreasuryRequest") - proto.RegisterType((*QueryTreasuryResponse)(nil), "onomyprotocol.dao.v1.QueryTreasuryResponse") -} - -func init() { proto.RegisterFile("onomyprotocol/dao/v1/query.proto", fileDescriptor_1d6940140b83f0f7) } - -var fileDescriptor_1d6940140b83f0f7 = []byte{ - // 440 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x31, 0x8f, 0xd3, 0x30, - 0x14, 0xc7, 0xe3, 0x03, 0x2a, 0xe4, 0x1b, 0x40, 0xa6, 0xc0, 0x51, 0x55, 0x6e, 0x89, 0x10, 0x2a, - 0x87, 0xb0, 0xd5, 0xb2, 0xdd, 0x58, 0x46, 0x18, 0xb8, 0x8a, 0x89, 0x05, 0x39, 0xa9, 0x15, 0x22, - 0x1a, 0xbf, 0x5c, 0xec, 0x54, 0x64, 0x85, 0x91, 0x05, 0xc4, 0xc8, 0x37, 0x80, 0x2f, 0xd2, 0xf1, - 0x24, 0x96, 0x9b, 0x0e, 0xae, 0xe5, 0x13, 0xf0, 0x09, 0x50, 0x6c, 0x17, 0xd1, 0x12, 0x9d, 0x6e, - 0x6a, 0xf3, 0xde, 0xfb, 0xff, 0xdf, 0xff, 0xfd, 0x8c, 0xfb, 0xa0, 0x20, 0xab, 0xf2, 0x02, 0x0c, - 0xc4, 0x30, 0xe3, 0x53, 0x01, 0x7c, 0x3e, 0xe4, 0x47, 0xa5, 0x2c, 0x2a, 0x66, 0xab, 0xa4, 0xbd, - 0x31, 0xc1, 0xa6, 0x02, 0xd8, 0x7c, 0xd8, 0x69, 0x27, 0x90, 0x80, 0x2d, 0xf2, 0xfa, 0x9f, 0x9b, - 0xed, 0xd0, 0x18, 0x74, 0x06, 0x9a, 0x47, 0x42, 0x4b, 0x3e, 0x1f, 0x46, 0xd2, 0x88, 0x21, 0x8f, - 0x21, 0x55, 0xbe, 0xdf, 0x4d, 0x00, 0x92, 0x99, 0xe4, 0x22, 0x4f, 0xb9, 0x50, 0x0a, 0x8c, 0x30, - 0x29, 0x28, 0xed, 0xbb, 0x77, 0x1b, 0xb3, 0xe4, 0xa2, 0x10, 0x99, 0x1f, 0x09, 0xdb, 0x98, 0x1c, - 0xd6, 0xd9, 0x9e, 0xdb, 0xe2, 0x44, 0x1e, 0x95, 0x52, 0x9b, 0xf0, 0x10, 0xdf, 0xd8, 0xa8, 0xea, - 0x1c, 0x94, 0x96, 0xe4, 0x00, 0xb7, 0x9c, 0x78, 0x0f, 0xf5, 0xd1, 0x60, 0x77, 0xd4, 0x65, 0x4d, - 0xa7, 0x30, 0xa7, 0x1a, 0x5f, 0x5e, 0x9c, 0xf6, 0x82, 0x89, 0x57, 0x84, 0xb7, 0x70, 0xdb, 0x5a, - 0xbe, 0x28, 0xa4, 0xd0, 0x65, 0x51, 0xad, 0x57, 0x7d, 0x43, 0xf8, 0xe6, 0x56, 0xc3, 0x6f, 0xfb, - 0x84, 0xf0, 0x75, 0xe3, 0x8b, 0xaf, 0x22, 0x31, 0x13, 0x2a, 0x96, 0x7b, 0xa8, 0x7f, 0x69, 0xb0, - 0x3b, 0xba, 0xc3, 0x1c, 0x17, 0x56, 0x73, 0x61, 0x9e, 0x0b, 0x7b, 0x02, 0xa9, 0x1a, 0x3f, 0xad, - 0xb7, 0xfe, 0x3e, 0xed, 0xdd, 0xae, 0x44, 0x36, 0x3b, 0x08, 0xb7, 0x0d, 0xc2, 0xaf, 0x3f, 0x7a, - 0x83, 0x24, 0x35, 0xaf, 0xcb, 0x88, 0xc5, 0x90, 0x71, 0xcf, 0xd7, 0xfd, 0x3c, 0xd2, 0xd3, 0x37, - 0xdc, 0x54, 0xb9, 0xd4, 0xd6, 0x4b, 0x4f, 0xae, 0xad, 0xe5, 0x63, 0xa7, 0x1e, 0x7d, 0xd9, 0xc1, - 0x57, 0x6c, 0x5a, 0xf2, 0x1e, 0xe1, 0x96, 0x3b, 0x94, 0x0c, 0x9a, 0x31, 0xfc, 0xcf, 0xb5, 0xf3, - 0xe0, 0x02, 0x93, 0xee, 0xfa, 0xf0, 0xde, 0xbb, 0xef, 0xbf, 0x3e, 0xef, 0x50, 0xd2, 0xe5, 0xe7, - 0x3c, 0x22, 0xf9, 0x80, 0xf0, 0xd5, 0x35, 0x38, 0xb2, 0x7f, 0x8e, 0xfb, 0x16, 0xf6, 0xce, 0xc3, - 0x0b, 0xcd, 0xfa, 0x2c, 0xf7, 0x6d, 0x96, 0x3e, 0xa1, 0xcd, 0x59, 0xfe, 0x42, 0x7a, 0xb6, 0x38, - 0xa3, 0xc1, 0xc9, 0x19, 0x45, 0x8b, 0x25, 0x45, 0xc7, 0x4b, 0x8a, 0x7e, 0x2e, 0x29, 0xfa, 0xb8, - 0xa2, 0xc1, 0xf1, 0x8a, 0x06, 0x27, 0x2b, 0x1a, 0xbc, 0xdc, 0xff, 0x07, 0xfd, 0xa6, 0x97, 0xfd, - 0xe2, 0x6f, 0xad, 0xa7, 0x7d, 0x82, 0xa8, 0x65, 0x7b, 0x8f, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, - 0x35, 0x78, 0x27, 0xe5, 0x52, 0x03, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// QueryClient is the client API for Query service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type QueryClient interface { - // Parameters queries the parameters of the module. - Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // Treasury queries the dao treasury. - Treasury(ctx context.Context, in *QueryTreasuryRequest, opts ...grpc.CallOption) (*QueryTreasuryResponse, error) -} - -type queryClient struct { - cc grpc1.ClientConn -} - -func NewQueryClient(cc grpc1.ClientConn) QueryClient { - return &queryClient{cc} -} - -func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { - out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, "/onomyprotocol.dao.v1.Query/Params", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) Treasury(ctx context.Context, in *QueryTreasuryRequest, opts ...grpc.CallOption) (*QueryTreasuryResponse, error) { - out := new(QueryTreasuryResponse) - err := c.cc.Invoke(ctx, "/onomyprotocol.dao.v1.Query/Treasury", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// QueryServer is the server API for Query service. -type QueryServer interface { - // Parameters queries the parameters of the module. - Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // Treasury queries the dao treasury. - Treasury(context.Context, *QueryTreasuryRequest) (*QueryTreasuryResponse, error) -} - -// UnimplementedQueryServer can be embedded to have forward compatible implementations. -type UnimplementedQueryServer struct { -} - -func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") -} -func (*UnimplementedQueryServer) Treasury(ctx context.Context, req *QueryTreasuryRequest) (*QueryTreasuryResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Treasury not implemented") -} - -func RegisterQueryServer(s grpc1.Server, srv QueryServer) { - s.RegisterService(&_Query_serviceDesc, srv) -} - -func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryParamsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Params(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/onomyprotocol.dao.v1.Query/Params", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_Treasury_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryTreasuryRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Treasury(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/onomyprotocol.dao.v1.Query/Treasury", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Treasury(ctx, req.(*QueryTreasuryRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "onomyprotocol.dao.v1.Query", - HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Params", - Handler: _Query_Params_Handler, - }, - { - MethodName: "Treasury", - Handler: _Query_Treasury_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "onomyprotocol/dao/v1/query.proto", -} - -func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *QueryTreasuryRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryTreasuryRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryTreasuryRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QueryTreasuryResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryTreasuryResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryTreasuryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.TreasuryBalance) > 0 { - for iNdEx := len(m.TreasuryBalance) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.TreasuryBalance[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { - offset -= sovQuery(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *QueryParamsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QueryParamsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Params.Size() - n += 1 + l + sovQuery(uint64(l)) - return n -} - -func (m *QueryTreasuryRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QueryTreasuryResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.TreasuryBalance) > 0 { - for _, e := range m.TreasuryBalance { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) - } - } - return n -} - -func sovQuery(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozQuery(x uint64) (n int) { - return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryTreasuryRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryTreasuryRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryTreasuryRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryTreasuryResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryTreasuryResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryTreasuryResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TreasuryBalance", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TreasuryBalance = append(m.TreasuryBalance, types.Coin{}) - if err := m.TreasuryBalance[len(m.TreasuryBalance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipQuery(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowQuery - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthQuery - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupQuery - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthQuery - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/dao/types/query.pb.gw.go b/x/dao/types/query.pb.gw.go deleted file mode 100644 index beaceb8a..00000000 --- a/x/dao/types/query.pb.gw.go +++ /dev/null @@ -1,210 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: onomyprotocol/dao/v1/query.proto - -/* -Package types is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package types - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage - -func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryParamsRequest - var metadata runtime.ServerMetadata - - msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryParamsRequest - var metadata runtime.ServerMetadata - - msg, err := server.Params(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_Treasury_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryTreasuryRequest - var metadata runtime.ServerMetadata - - msg, err := client.Treasury(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Treasury_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryTreasuryRequest - var metadata runtime.ServerMetadata - - msg, err := server.Treasury(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". -// UnaryRPC :call QueryServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. -func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Treasury_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Treasury_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Treasury_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterQueryHandler(ctx, mux, conn) -} - -// RegisterQueryHandler registers the http handlers for service Query to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) -} - -// RegisterQueryHandlerClient registers the http handlers for service Query -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "QueryClient" to call the correct interceptors. -func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_Treasury_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Treasury_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Treasury_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"onomyprotocol", "dao", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_Treasury_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"onomyprotocol", "dao", "v1", "treasury"}, "", runtime.AssumeColonVerbOpt(false))) -) - -var ( - forward_Query_Params_0 = runtime.ForwardResponseMessage - - forward_Query_Treasury_0 = runtime.ForwardResponseMessage -) diff --git a/x/dao/types/types.go b/x/dao/types/types.go deleted file mode 100644 index 17537cec..00000000 --- a/x/dao/types/types.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package types contains dao module types. -package types