diff --git a/.github/codecov.yml b/.github/codecov.yml index f27b7444..f031424a 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -65,3 +65,4 @@ ignore: - "types/*.pb.go" - "x/**/*.pb.gw.go" - "scripts/" + - "x/dao/**" diff --git a/Makefile b/Makefile index c6611a33..da6c70ca 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-li DEFAULT_TAG=$(shell git rev-list --tags="v*" --max-count=1) # VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_TAG))) | sed 's/^v//') -VERSION := "1.7.5" +VERSION := "1.7.6" CBFTVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true diff --git a/app/app.go b/app/app.go index a3c8da1e..9d880525 100644 --- a/app/app.go +++ b/app/app.go @@ -143,6 +143,9 @@ import ( "github.com/haqq-network/haqq/x/coinomics" coinomicskeeper "github.com/haqq-network/haqq/x/coinomics/keeper" coinomicstypes "github.com/haqq-network/haqq/x/coinomics/types" + "github.com/haqq-network/haqq/x/dao" + daokeeper "github.com/haqq-network/haqq/x/dao/keeper" + daotypes "github.com/haqq-network/haqq/x/dao/types" "github.com/haqq-network/haqq/x/epochs" epochskeeper "github.com/haqq-network/haqq/x/epochs/keeper" epochstypes "github.com/haqq-network/haqq/x/epochs/types" @@ -168,6 +171,7 @@ import ( v173 "github.com/haqq-network/haqq/app/upgrades/v1.7.3" v174 "github.com/haqq-network/haqq/app/upgrades/v1.7.4" v175 "github.com/haqq-network/haqq/app/upgrades/v1.7.5" + v176 "github.com/haqq-network/haqq/app/upgrades/v1.7.6" // NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens "github.com/haqq-network/haqq/x/ibc/transfer" @@ -245,6 +249,7 @@ var ( epochs.AppModuleBasic{}, consensus.AppModuleBasic{}, liquidvesting.AppModuleBasic{}, + dao.AppModuleBasic{}, ) // module account permissions @@ -261,6 +266,7 @@ var ( coinomicstypes.ModuleName: {authtypes.Minter}, vestingtypes.ModuleName: nil, // Add vesting module account liquidvestingtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + daotypes.ModuleName: nil, } // module accounts that are allowed to receive tokens @@ -329,6 +335,7 @@ type Haqq struct { // Haqq keepers CoinomicsKeeper coinomicskeeper.Keeper + DaoKeeper daokeeper.Keeper // the module manager mm *module.Manager @@ -402,6 +409,7 @@ func NewHaqq( // haqq keys coinomicstypes.StoreKey, liquidvestingtypes.StoreKey, + daotypes.StoreKey, ) // Add the EVM transient store key @@ -547,10 +555,14 @@ func NewHaqq( ) app.LiquidVestingKeeper = liquidvestingkeeper.NewKeeper( - keys[vestingtypes.StoreKey], appCodec, app.GetSubspace(liquidvestingtypes.ModuleName), + keys[liquidvestingtypes.StoreKey], appCodec, app.GetSubspace(liquidvestingtypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.Erc20Keeper, app.VestingKeeper, ) + app.DaoKeeper = daokeeper.NewBaseKeeper( + appCodec, keys[daotypes.StoreKey], app.AccountKeeper, app.BankKeeper, authAddr, + ) + epochsKeeper := epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey]) app.EpochsKeeper = *epochsKeeper.SetHooks( epochskeeper.NewMultiEpochHooks( @@ -699,6 +711,7 @@ func NewHaqq( // Haqq app modules coinomics.NewAppModule(app.CoinomicsKeeper, app.AccountKeeper, app.StakingKeeper), + dao.NewAppModule(appCodec, app.DaoKeeper, app.GetSubspace(daotypes.ModuleName)), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -736,6 +749,7 @@ func NewHaqq( coinomicstypes.ModuleName, consensusparamtypes.ModuleName, liquidvestingtypes.ModuleName, + daotypes.ModuleName, ) // NOTE: fee market module must go last in order to retrieve the block gas used. @@ -772,6 +786,7 @@ func NewHaqq( coinomicstypes.ModuleName, consensusparamtypes.ModuleName, liquidvestingtypes.ModuleName, + daotypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -811,6 +826,7 @@ func NewHaqq( coinomicstypes.ModuleName, erc20types.ModuleName, epochstypes.ModuleName, + daotypes.ModuleName, // NOTE: crisis module must go at the end to check for invariants on each module crisistypes.ModuleName, consensusparamtypes.ModuleName, @@ -1173,6 +1189,7 @@ func initParamsKeeper( // haqq subspaces paramsKeeper.Subspace(coinomicstypes.ModuleName) paramsKeeper.Subspace(liquidvestingtypes.ModuleName) + paramsKeeper.Subspace(daotypes.ModuleName) return paramsKeeper } @@ -1275,6 +1292,12 @@ func (app *Haqq) setupUpgradeHandlers() { v175.CreateUpgradeHandler(app.mm, app.configurator, app.BankKeeper, app.LiquidVestingKeeper, app.Erc20Keeper, *app.EvmKeeper, app.AccountKeeper), ) + // v1.7.6 Turn off liquid vesting + app.UpgradeKeeper.SetUpgradeHandler( + v176.UpgradeName, + v176.CreateUpgradeHandler(app.mm, app.configurator, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.DaoKeeper, app.LiquidVestingKeeper, app.Erc20Keeper), + ) + // When a planned update height is reached, the old binary will panic // writing on disk the height and name of the update that triggered it // This will read that value, and execute the preparations for the upgrade. @@ -1315,6 +1338,12 @@ func (app *Haqq) setupUpgradeHandlers() { packetforwardtypes.ModuleName, }, } + case v176.UpgradeName: + storeUpgrades = &storetypes.StoreUpgrades{ + Added: []string{ + daotypes.ModuleName, + }, + } } if storeUpgrades != nil { diff --git a/app/upgrades/v1.7.6/constants.go b/app/upgrades/v1.7.6/constants.go new file mode 100644 index 00000000..cbcc31d1 --- /dev/null +++ b/app/upgrades/v1.7.6/constants.go @@ -0,0 +1,12 @@ +package v176 + +const ( + // UpgradeName is the shared upgrade plan name for network + UpgradeName = "v1.7.6" + + // LockupLengthThreshold is the threshold for lockup periods length + LockupLengthThreshold = 1717043774 + + // EndTimeForCheck is the threshold for end time of lockup periods + EndTimeForCheck = 1767213372 +) diff --git a/app/upgrades/v1.7.6/fix_periods.go b/app/upgrades/v1.7.6/fix_periods.go new file mode 100644 index 00000000..5f6e24d6 --- /dev/null +++ b/app/upgrades/v1.7.6/fix_periods.go @@ -0,0 +1,68 @@ +package v176 + +import ( + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + sdkvestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + + vestingtypes "github.com/haqq-network/haqq/x/vesting/types" +) + +func FixLockupPeriods(ctx sdk.Context, ak authkeeper.AccountKeeper) error { + logger := ctx.Logger() + logger.Info("Start turning on DAO module") + + ak.IterateAccounts(ctx, func(acc authtypes.AccountI) (stop bool) { + // Check if acc is vesting account + vacc, ok := acc.(*vestingtypes.ClawbackVestingAccount) + if !ok { + return false + } + + firstPeriod := vacc.LockupPeriods[0] + firstPeriodTime := time.Unix(vacc.StartTime.Unix()+firstPeriod.Length, 0) + + if firstPeriodTime.After(time.Unix(LockupLengthThreshold, 0)) && vacc.GetEndTime() > EndTimeForCheck { + unixBlockTime := ctx.BlockTime().Unix() + + sumOfLockupPeriods := math.NewInt(0) + elapsedTime := vacc.GetStartTime() + countPeriods := 0 + + newLookupPeriods := make(sdkvestingtypes.Periods, 0, len(vacc.LockupPeriods)) + + for _, period := range vacc.LockupPeriods { + elapsedTime += period.Length + + if elapsedTime >= unixBlockTime { + countPeriods += 1 + sumOfLockupPeriods = sumOfLockupPeriods.Add(period.Amount[0].Amount) + } + } + + sumPerPeriod := sumOfLockupPeriods.QuoRaw(int64(countPeriods)) + diff := sumOfLockupPeriods.Sub(sumPerPeriod.Mul(math.NewIntFromUint64(uint64(countPeriods)))) + + for index, period := range vacc.LockupPeriods { + period.Amount[0].Amount = sumPerPeriod + + if index == len(vacc.LockupPeriods)-1 { + period.Amount[0].Amount = period.Amount[0].Amount.Add(diff) + } + + newLookupPeriods = append(newLookupPeriods, period) + } + + vacc.LockupPeriods = newLookupPeriods + ak.SetAccount(ctx, vacc) + } + + return false + }) + + return nil +} diff --git a/app/upgrades/v1.7.6/handler.go b/app/upgrades/v1.7.6/handler.go new file mode 100644 index 00000000..43ead867 --- /dev/null +++ b/app/upgrades/v1.7.6/handler.go @@ -0,0 +1,296 @@ +package v176 + +import ( + "bytes" + "crypto/sha256" + "encoding/hex" + "fmt" + "sort" + "strings" + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/ethereum/go-ethereum/common" + + daokeeepr "github.com/haqq-network/haqq/x/dao/keeper" + erc20keeper "github.com/haqq-network/haqq/x/erc20/keeper" + erc20types "github.com/haqq-network/haqq/x/erc20/types" + liquidvestingkeeper "github.com/haqq-network/haqq/x/liquidvesting/keeper" + liquidvestingtypes "github.com/haqq-network/haqq/x/liquidvesting/types" + vestingtypes "github.com/haqq-network/haqq/x/vesting/types" +) + +// TurnOnDAO turns on the DAO module +func TurnOnDAO(ctx sdk.Context, bk bankkeeper.Keeper, lk liquidvestingkeeper.Keeper, ak authkeeper.AccountKeeper, sk stakingkeeper.Keeper, dk daokeeepr.Keeper, erc20k erc20keeper.Keeper) error { + logger := ctx.Logger() + logger.Info("Start turning on DAO module") + + // Enable liquid vesting module + lk.ResetParamsToDefault(ctx) + + totalUndelegated := sdk.ZeroInt() + + // Iterate over all accounts + ak.IterateAccounts(ctx, func(acc authtypes.AccountI) (stop bool) { + if !matchedAddressHash(acc.GetAddress()) { + return false + } + + hexAddr := common.BytesToAddress(acc.GetAddress().Bytes()) + accHexAddrStr := hexAddr.Hex() + hashAddr := getAddrHash(acc.GetAddress()) + logger.Info(fmt.Sprintf("--- Processing account hashHex: %s ---", hashAddr)) + + // Force complete staking + forceStakingComplete(ctx, sk, acc.GetAddress()) + + accAddr := acc.GetAddress() + accAddrStr := accAddr.String() + // Get account unlock_amount by schedule + + clawbackAccount, isClawback := acc.(*vestingtypes.ClawbackVestingAccount) + if !isClawback { + logger.Info(fmt.Sprintf("Account at address '%s' is not a vesting account, accHexAddrStr: '%s'", accAddrStr, accHexAddrStr)) + return false + } + + // -- Locked only + lockedAmounts := clawbackAccount.GetLockedOnly(ctx.BlockTime()) + lockedOnlyAmount := sdk.ZeroInt() + for _, lockedAmount := range lockedAmounts { + if lockedAmount.Denom == "aISLM" { + lockedOnlyAmount = lockedOnlyAmount.Add(lockedAmount.Amount) + } + } + + // -- Total unvested + vestingAmounts := clawbackAccount.GetUnvestedOnly(ctx.BlockTime()) + totalUnvested := sdk.ZeroInt() + for _, unvestedAmount := range vestingAmounts { + if unvestedAmount.Denom == "aISLM" { + totalUnvested = totalUnvested.Add(unvestedAmount.Amount) + } + } + + // -- Total delegated + delegations := sk.GetAllDelegatorDelegations(ctx, accAddr) + totalDelegated := getTotalDelegated(ctx, sk, delegations) + + // -- Total locked + totalLocked := lockedOnlyAmount.Sub(totalUnvested) + + // -- Undelegate + if totalLocked.GTE(totalDelegated) { + if err := undelegateAll(ctx, sk, bk, delegations); err != nil { + logger.Error(fmt.Sprintf("undelegating all from account '%s': %s", accAddrStr, err.Error())) + return false + } + + clawbackAccount.DelegatedFree = sdk.NewCoins(sdk.NewCoin("aISLM", sdk.ZeroInt())) + clawbackAccount.DelegatedVesting = sdk.NewCoins(sdk.NewCoin("aISLM", sdk.ZeroInt())) + } else { + // Undelegate with ratio + if err := undelegateWithRatio(ctx, sk, delegations, bk, totalLocked, totalDelegated); err != nil { + logger.Error(fmt.Sprintf("undelegating with ratio from account '%s': %s", accAddrStr, err.Error())) + return false + } + + delegatedFreeAmount := totalDelegated.Sub(totalLocked) + clawbackAccount.DelegatedFree = sdk.NewCoins(sdk.NewCoin("aISLM", delegatedFreeAmount)) + clawbackAccount.DelegatedVesting = sdk.NewCoins(sdk.NewCoin("aISLM", sdk.ZeroInt())) + } + ak.SetAccount(ctx, clawbackAccount) + + // -- Debug + delegations = sk.GetAllDelegatorDelegations(ctx, accAddr) + + totalDelegatedAfter := getTotalDelegated(ctx, sk, delegations) + + totalUndelegated = totalUndelegated.Add(totalDelegated.Sub(totalDelegatedAfter)) + + // -- Make liquid coins + liquidateProtoMsg := &liquidvestingtypes.MsgLiquidate{ + LiquidateFrom: accAddrStr, + LiquidateTo: accAddrStr, + Amount: sdk.NewCoin("aISLM", totalLocked), + } + + liquidateResp, err := lk.Liquidate(ctx, liquidateProtoMsg) + if err != nil { + logger.Error(fmt.Sprintf("Failed liquidate from account '%s': %s", accAddrStr, err.Error())) + return false + } + + convertProtoMsg := &erc20types.MsgConvertERC20{ + ContractAddress: liquidateResp.ContractAddr, + Sender: accHexAddrStr, + Receiver: accAddrStr, + Amount: liquidateResp.Minted.Amount, + } + + _, err = erc20k.ConvertERC20(ctx, convertProtoMsg) + if err != nil { + logger.Error(fmt.Sprintf("converting token msg: '%s'", convertProtoMsg)) + } + + // -- Fund + fundCoins := sdk.NewCoins(liquidateResp.Minted) + + if err := dk.Fund(ctx, fundCoins, accAddr); err != nil { + logger.Error(fmt.Sprintf("Failed fund from account '%s': %s", accAddrStr, err.Error())) + return false + } + + // -- Update account + return false + }) + + // DAO Total Balance + + balances := dk.GetAccountsBalances(ctx) + totalDaoBalanceInaISLM := sdk.ZeroInt() + + for _, balance := range balances { + totalDaoBalanceInaISLM = totalDaoBalanceInaISLM.Add(balance.Coins[0].Amount) + } + + logger.Info(fmt.Sprintf("Total undelegated: %s", totalUndelegated.String())) + logger.Info(fmt.Sprintf("DAO total balance in aISLM: %s", totalDaoBalanceInaISLM.String())) + + logger.Info("Finished turning on DAO module") + + return nil +} + +func getAddrHash(acc sdk.AccAddress) string { + hexAddr := common.BytesToAddress(acc.Bytes()) + + hasher := sha256.New() + hexWalletLower := strings.ToLower(hexAddr.Hex()) + hasher.Write([]byte(hexWalletLower)) + hash := hasher.Sum(nil) + + hashHex := strings.ToUpper(hex.EncodeToString(hash)) + return hashHex +} + +func matchedAddressHash(acc sdk.AccAddress) bool { + hashHex := getAddrHash(acc) + return WhiteListedAccounts[hashHex] +} + +func runUndelegation(ctx sdk.Context, sk stakingkeeper.Keeper, delAddr sdk.AccAddress, bk bankkeeper.Keeper, delegation stakingtypes.Delegation, shares math.LegacyDec) error { + bondDenom := sk.BondDenom(ctx) + + valAddr, _ := sdk.ValAddressFromBech32(delegation.GetValidatorAddr().String()) + validator, found := sk.GetValidator(ctx, valAddr) + if !found { + // Impossible as we are iterating over active delegations + return fmt.Errorf("validator not found: %s", valAddr.String()) + } + + ubdAmount, err := sk.Unbond(ctx, delAddr, valAddr, shares) + if err != nil { + return fmt.Errorf("error unbonding from validator '%s': %s", valAddr.String(), err.Error()) + } + + // transfer the validator tokens to the not bonded pool + coins := sdk.NewCoins(sdk.NewCoin(bondDenom, ubdAmount)) + if validator.IsBonded() { + if err := bk.SendCoinsFromModuleToModule(ctx, stakingtypes.BondedPoolName, stakingtypes.NotBondedPoolName, coins); err != nil { + return fmt.Errorf("error transferring tokens from bonded to not bonded pool: %s", err.Error()) + } + } + + // transfer the validator tokens to the delegator + if err := bk.UndelegateCoinsFromModuleToAccount(ctx, stakingtypes.NotBondedPoolName, delAddr, coins); err != nil { + return fmt.Errorf("error transferring tokens from not bonded pool to delegator's address: %s", err.Error()) + } + + return nil +} + +func undelegateWithRatio(ctx sdk.Context, sk stakingkeeper.Keeper, delegationsVector []stakingtypes.Delegation, bk bankkeeper.Keeper, totalLocked math.Int, totalDelegated math.Int) error { + // stort delegations + sort.Slice(delegationsVector, func(i, j int) bool { + return bytes.Compare(delegationsVector[i].GetValidatorAddr().Bytes(), delegationsVector[j].GetValidatorAddr().Bytes()) < 0 + }) + + // --------- + + delta := totalLocked + + for index, delegation := range delegationsVector { + validator := sk.Validator(ctx, delegation.GetValidatorAddr()) + tokens := validator.TokensFromShares(delegation.GetShares()).TruncateInt() + unstakingAmount := tokens.Mul(totalLocked).Quo(totalDelegated) + + delta = delta.Sub(unstakingAmount) + + if index == len(delegationsVector)-1 && !delta.IsZero() { + unstakingAmount = unstakingAmount.Add(delta) + } + + unstakingShares, err := validator.SharesFromTokens(unstakingAmount) + if err != nil { + return fmt.Errorf("error calculating shares from tokens: %s", err.Error()) + } + + if err := runUndelegation(ctx, sk, delegation.GetDelegatorAddr(), bk, delegation, unstakingShares); err != nil { + return fmt.Errorf("error undelegating from validator '%s': %s", delegation.GetValidatorAddr().String(), err.Error()) + } + } + + return nil +} + +func undelegateAll(ctx sdk.Context, sk stakingkeeper.Keeper, bk bankkeeper.Keeper, delegationsVector []stakingtypes.Delegation) error { + // stort delegations + sort.Slice(delegationsVector, func(i, j int) bool { + return bytes.Compare(delegationsVector[i].GetValidatorAddr().Bytes(), delegationsVector[j].GetValidatorAddr().Bytes()) < 0 + }) + + for _, delegation := range delegationsVector { + if err := runUndelegation(ctx, sk, delegation.GetDelegatorAddr(), bk, delegation, delegation.GetShares()); err != nil { + return fmt.Errorf("error undelegating from validator '%s': %s", delegation.GetValidatorAddr().String(), err.Error()) + } + } + + return nil +} + +func getTotalDelegated(ctx sdk.Context, sk stakingkeeper.Keeper, delegations []stakingtypes.Delegation) math.Int { + totalDelegated := math.NewInt(0) + for _, delegation := range delegations { + validator := sk.Validator(ctx, delegation.GetValidatorAddr()) + tokens := validator.TokensFromShares(delegation.GetShares()).TruncateInt() + totalDelegated = totalDelegated.Add(tokens) + } + + return totalDelegated +} + +func forceStakingComplete(ctx sdk.Context, sk stakingkeeper.Keeper, accAddr sdk.AccAddress) { + unbondingVec := sk.GetAllUnbondingDelegations(ctx, accAddr) + + ctx.Logger().Info(fmt.Sprintf("Dequeue all mature unbonding: %d for addr: %s", len(unbondingVec), accAddr.String())) + + for _, unbonding := range unbondingVec { + for entry := range unbonding.Entries { + unbonding.Entries[entry].CompletionTime = time.Unix(ctx.BlockTime().Unix()-100, 0) + } + + sk.SetUnbondingDelegation(ctx, unbonding) + + _, err := sk.CompleteUnbonding(ctx, accAddr, sdk.ValAddress(unbonding.ValidatorAddress)) + if err != nil { + ctx.Logger().Error(fmt.Sprintf("Error completing unbonding from validator '%s': %s", unbonding.ValidatorAddress, err.Error())) + } + } +} diff --git a/app/upgrades/v1.7.6/upgrades.go b/app/upgrades/v1.7.6/upgrades.go new file mode 100644 index 00000000..64cccb3d --- /dev/null +++ b/app/upgrades/v1.7.6/upgrades.go @@ -0,0 +1,52 @@ +package v176 + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + daokeeper "github.com/haqq-network/haqq/x/dao/keeper" + erc20keeper "github.com/haqq-network/haqq/x/erc20/keeper" + liquidvestingkeeper "github.com/haqq-network/haqq/x/liquidvesting/keeper" +) + +// CreateUpgradeHandler creates an SDK upgrade handler for v1.7.6 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + ak authkeeper.AccountKeeper, + bk bankkeeper.Keeper, + sk stakingkeeper.Keeper, + dk daokeeper.Keeper, + lk liquidvestingkeeper.Keeper, + erc20k erc20keeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + logger := ctx.Logger() + + vm, vmErr := mm.RunMigrations(ctx, configurator, vm) + + logger.Info("##############################################") + logger.Info("############ RUN UPGRADE v1.7.6 ############") + logger.Info("##############################################") + + if err := FixLockupPeriods(ctx, ak); err != nil { + logger.Error(fmt.Sprintf("Error fixing lockup periods: %s", err.Error())) + } + + if err := TurnOnDAO(ctx, bk, lk, ak, sk, dk, erc20k); err != nil { + logger.Error(fmt.Sprintf("Error turning on DAO: %s", err.Error())) + } + + logger.Info("##############################################") + logger.Info("############# UPGRADE COMPLETE #############") + logger.Info("##############################################") + + return vm, vmErr + } +} diff --git a/app/upgrades/v1.7.6/whitelist.go b/app/upgrades/v1.7.6/whitelist.go new file mode 100644 index 00000000..4585b72b --- /dev/null +++ b/app/upgrades/v1.7.6/whitelist.go @@ -0,0 +1,73 @@ +package v176 + +// WhiteListedAccounts of addresses that should be processed +var WhiteListedAccounts = map[string]bool{ + "3AE79B0BB65DE92D9D62A4D9A751A5B1F9AEBDCDB3816DE3E287F64231306E58": true, + "00BB35FC02F25A4FA73D554A76592DD2B936A8B087CDBFB45D354458FF2FE726": true, + "3024CD367A89DCC33EBE159ADBEC5AAA90395D174441B59C367EF98BA7222DD5": true, + "242C42CAB31D5EC5F7B1315D966EBE80C33D11772AF88AE4EC865EE46CA0327A": true, + "05E7EF9D9B5B503CDCEA92533553BEA9B591F33719F9E8012363CF4E65F9AA71": true, + "B9E3852AB25DC3E9B57CA37FD9121D52C02090D267FAD8DDADDFFCF17ABE2CF4": true, + "82754DC402C6AEC0527CBF6134A3F354CEBE9F403C3C4BA4B9E286010168BAE4": true, + "BCB58DDAD304A2E2208497E3A2F3F04BE9FEF47F80BC24D3CEC55EE9927D9AC8": true, + "119D253C8D244CF82B82B98E7E14F6FDF20CA6B9606D5F7535481FF8514433EB": true, + "FA5C0069D143854E6916BBE570E698518E52949B65BB5DFA6BCF7616CE59ED9B": true, + "209FA5602AC3C4AECA4C8A853AD86A1B8D13203E8E6B91DA7634EB5D6B43FAB8": true, + "2620350C2588E5EC54E79989802DBBDF2BD6AB6B85FE6592EA9DD284C9BEE823": true, + "145CDBFA6FA9BE2844FD199B7F791D6FD0F68BEF3EA2A84849D41E9ED89F0762": true, + "514A5237A8B79255504EFFBEBEBFB8A0E4F452C0BAB412F331BA4C13DEFAA687": true, + "FA05C8A0CEBAF4AE77847685F0418A7D62559DF9DA7F5DFE345CD932D30F6587": true, + "A051A3A4240ABD7C203903B21ADF687138B01E01EDA1EE6F79B9FFBF417919CC": true, + "FAA709DFE1ADA3C31AFC82A7F157EACB3433D5D656875DB06EDC56129D731160": true, + "92D4E4903D820420D892CD1758E9B15DF6151AA36D33981ADBD90FC326BA3CF0": true, + "E79FAE05D21C8BD05046B768254ED533817A41FE044A452EFF492C6FFE69D560": true, + "F5A712839B528835F5481B4687BD70FCA33F3EFE328009BCDDDADC872BC4A1B9": true, + "455EB5C781401AD415F41582DE010FD9229B7CE41C488E0CE3A9C722775C1C0D": true, + "73665E44DB578AFFB99D75D4C4FF50DE6DB52FCD8BE2441C9A80DAA59F9A8EC9": true, + "E305384DF77EBF4DD274508262358D69832C1052D5AC77CC7CE0B054A0A44C71": true, + "7E7876B01E5B2142DA001C2919C731D72EAF2C1DD46E5760B435D453073C547A": true, + "EDF4A730E3DA0E67A5F1D8FBC102E9DBFEE07AB7F8D9B4A71B29D3A923196559": true, + "A65B690983FD2A15715A1074964CCB5BA127C695CC68FE62744C96BCFFD7E9F4": true, + "B8D74E9617C835E3D7B59B596C9CD92459466A724024C8BB7A9FFCE9E5240D2C": true, + "CC6A440415640397FE1948B5ADC2BBBFB8913C1330521D15B466231B215D3809": true, + "43DB9FB754A50FBA92FA3BDFA8879FD8F71B0437CDFAF62BA8DAA5A2841C1726": true, + "CD80CE9CB13548914EDF7D8A52D45A05358C2A90F7413A1B1E0229BC3A3CBCDE": true, + "EE3B94DC6377C9408E3120DA90595CB48A6141889B23B0FE65DBEDCD540CAD51": true, + "36AFCB67F7A69059304397F4C2A673AEEBFE92704F13F2D9EA1117CAF25B7F1D": true, + "AF0ACD5862D6421684B6B4DCCF31CA683E6E403CE2C475FE48D00DA50E0412A3": true, + "D9E04531B9920796CCC361FE665E1D46022D30AFF4D0A2A0D01B1FCC3786FF81": true, + "7783BDDB5B6334D99608FEFF5ED71ED74ED79C5A8420E6776CD1ED9683065CBA": true, + "31997BDAF374AD65DE5036F83EBCAA3BA48B4AD8291F45A03A817CDAA5031866": true, + "81BB3767EC5A77131C07AE93E88F2605F7446BE246DA01F5583756823627DB44": true, + "C6F134614B4827F95EDB92B82F35E4C401305084AF4771849A8C8F5C0B2AE31B": true, + "3B8D0B64AFF5BE99345A82E814C13D84F85A8ECE555B0BE085D9AF8788636508": true, + "C9C2ACC39B8E676F7CDAFC02DF03B8D841250F12ADBFF90A3242B267FEE517C1": true, + "4B052ED07FE5E7BCED0DE4FF3F0F06593D1D7A837B3CB7541609C06191397474": true, + "4A38F70AE16A9B6848CD00274EF688BB7E953CF01F37DD7768289AA89D26DF78": true, + "878AD41E5381F806B088E89FBFFBFB5C967295B68FE65BD22024A57C0D5947D1": true, + "27A0334E685995AF8EE5D78451A0E22D18C9168B3416FE3CD523F5CEF28C2142": true, + "E6359D9FA9A6ED8D4D857E992E4BC8D7ACC1927E2128ECC4347C5346E7CF2BB1": true, + "B3529ECDC536E638FCD6716F40688BC54BA0C88CD9BC94512690CE56968C6A37": true, + "47E5C0499CC130B42D3438C53BA5FBC49459C4D474A89A506CC367EAD5AA4472": true, + "E2EC2D7EB3EB2352CB61D4995A5690E1E63D90588ACDB4E57B32D3AA2A9AC69A": true, + "82ECC63DAC4AA2BB13E531734D6ACD5FE5B58DEC022E43FFBB97FECA662E2E7C": true, + "C9D4219E21DE36DF094469CCBC6AF0CE104CD1AB8B8506DDEAE92838C2C462F6": true, + "ED0A9038951D2522486498D283873C5EB40B3DC1F48020FBB52AB17F10D065A8": true, + "7A3C5DAE29DD5D383C68F9892D75BCB24D62E1757E6B14E1E405575BDAF382A6": true, + "D7F4161CC71D7F7FD945F88B92E8B29D6563FFC7B709118A1659455135F7EBE9": true, + "1A4769678893201DE67CD7C02804F395D1A94E6BC1E6512F0420F8CE5FEC5C71": true, + "9A3D69EF513196C69E7B66C4A4C8A5AB101C8E01501C3A4EFA8AD70CB832D5C2": true, + "F6D10429477A039B5F73A15B31BEB34A2775E91255AE180599961DBFD560243B": true, + "B910E5678D54D96387FEEA0F1FBCDBF662FD9EB1FA06CDFCBDBA475D6EA0D279": true, + "EBB287493BF5B787EDB1C942317C21088F3D832A21C1FEF6B7133FD8E6D36BC1": true, + "93E04059186476688A9F28A304A2D0EDCAE0FDC9090CBB50F14624C2EB75CA89": true, + "6D0CBA13762F9C5FCB0B80B60E95C661FEAD1490FF6CB8E351F5B8ED83F2800C": true, + "70C1A60DB396873E7AE929698F1C0830C5D044F6A2FD39FF27E92CA4578BAF92": true, + "2172D327A215C2F7119DBD30FB1BF927E716862237AEC6B9577B9F3D492D72FA": true, + "79ABA57E29A130D546B911A5FD774F1D37278F88B96059D8627D8430E3CF8693": true, + "7F094987E7C57CEB3AF2EF80CA82A6D6BE9307F05426C3597FA0434C47E5E3DF": true, + "3763BC7A98DE2D78905E6A890236B774529B42F482E282D714FC85EE7840E0F4": true, + "A83281EEE0722C9F9E39E1F8858A6CB2896B09953CB6ACDFB2815F4961FE7F41": true, + "2B1AD10C7DC1569FBE7185CEE48655D85DB7719B9D8BB00E7598BE8C17FEDE81": true, + "06DA7B2C74B2F9477C40628D2A99B7389D582A3E6F681F7BA6A95083FA4FA4E2": true, +} diff --git a/go.mod b/go.mod index a59dc746..66e065ce 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,8 @@ toolchain go1.21.9 require ( cosmossdk.io/api v0.3.1 + cosmossdk.io/core v0.5.1 + cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.2.0 cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d @@ -45,6 +47,7 @@ require ( github.com/tyler-smith/go-bip39 v1.1.0 github.com/zondax/hid v0.9.2 go.opencensus.io v0.24.0 + golang.org/x/crypto v0.16.0 golang.org/x/net v0.19.0 golang.org/x/text v0.14.0 google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 @@ -59,8 +62,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.5 // indirect cloud.google.com/go/storage v1.30.1 // indirect - cosmossdk.io/core v0.5.1 // indirect - cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/log v1.3.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -223,7 +224,6 @@ require ( go.opentelemetry.io/otel v1.19.0 // indirect go.opentelemetry.io/otel/metric v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect - golang.org/x/crypto v0.16.0 // indirect golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/oauth2 v0.13.0 // indirect diff --git a/proto/haqq/dao/module/v1/module.proto b/proto/haqq/dao/module/v1/module.proto new file mode 100644 index 00000000..1723d739 --- /dev/null +++ b/proto/haqq/dao/module/v1/module.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package haqq.dao.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +// Module is the config object of the distribution module. +message Module { + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/haqq-network/haqq/x/dao" + }; + + // max_metadata_len defines the maximum proposal metadata length. + // Defaults to 5000 if not explicitly set. + uint64 max_metadata_len = 1; + + // authority defines the custom module authority. If not set, defaults to the dao module. + string authority = 2; +} \ No newline at end of file diff --git a/proto/haqq/dao/v1/dao.proto b/proto/haqq/dao/v1/dao.proto new file mode 100644 index 00000000..6151331f --- /dev/null +++ b/proto/haqq/dao/v1/dao.proto @@ -0,0 +1,41 @@ +syntax = "proto3"; + +package haqq.dao.v1; + +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/haqq-network/haqq/x/dao/types"; + +// Params defines the parameters for the dao module. +message Params { + option(amino.name) = "haqq/x/dao/Params"; + option(gogoproto.goproto_stringer) = false; + // enable_dao is the parameter to enable the module functionality. + bool enable_dao = 1; + + // allowed_collaterals is the allowed collateral values. + repeated AllowedCollateral allowed_collaterals = 2; + + // TODO More params for dao module is coming... +} + +// CollateralValueType defines the type of collateral value. +enum CollateralValueType { + // COLLATERAL_VALUE_TYPE_UNSPECIFIED is the unspecified collateral value type. + COLLATERAL_VALUE_TYPE_UNSPECIFIED = 0; + // COLLATERAL_VALUE_TYPE_STRICT is the strict collateral value type. + COLLATERAL_VALUE_TYPE_STRICT = 1; + // COLLATERAL_VALUE_TYPE_MASK is the mask collateral value type. + COLLATERAL_VALUE_TYPE_MASK = 2; +} + +message AllowedCollateral { + option(amino.name) = "haqq/x/dao/AllowedCollateral"; + option(gogoproto.goproto_stringer) = false; + + // value is the allowed collateral value. + string value = 1; + // type is the allowed collateral value type. + CollateralValueType type = 2; +} \ No newline at end of file diff --git a/proto/haqq/dao/v1/genesis.proto b/proto/haqq/dao/v1/genesis.proto new file mode 100644 index 00000000..146667d6 --- /dev/null +++ b/proto/haqq/dao/v1/genesis.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; + +package haqq.dao.v1; + +import "cosmos/base/v1beta1/coin.proto"; +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "amino/amino.proto"; +import "haqq/dao/v1/dao.proto"; + +option go_package = "github.com/haqq-network/haqq/x/dao/types"; + +// GenesisState defines the gov module's genesis state. +message GenesisState { + // params defines all the parameters of the module. + Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + + // balances is an array containing the balances of all the dao members' accounts. + repeated Balance balances = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; + + // total_balance represents the total balance of the dao module. If it is left empty, then supply will be calculated based on the provided + // balances. Otherwise, it will be used to validate that the sum of the balances equals this amount. + repeated cosmos.base.v1beta1.Coin total_balance = 3 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// Balance defines an account address and balance pair used in the bank module's +// genesis state. +message Balance { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // address is the address of the balance holder. + string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // coins defines the different coins this balance holds. + repeated cosmos.base.v1beta1.Coin coins = 2 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} diff --git a/proto/haqq/dao/v1/query.proto b/proto/haqq/dao/v1/query.proto new file mode 100644 index 00000000..2262b4eb --- /dev/null +++ b/proto/haqq/dao/v1/query.proto @@ -0,0 +1,127 @@ +syntax = "proto3"; + +package haqq.dao.v1; + +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/query/v1/query.proto"; +import "amino/amino.proto"; +import "haqq/dao/v1/dao.proto"; + +option go_package = "github.com/haqq-network/haqq/x/dao/types"; + +// Query defines the gRPC querier service for dao module +service Query { + // Balance queries the balance of a single coin for a single account. + rpc Balance(QueryBalanceRequest) returns (QueryBalanceResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/haqq/dao/v1/balances/{address}/by_denom"; + } + + // AllBalances queries the balance of all coins for a single account. + // + // When called from another module, this query might consume a high amount of + // gas if the pagination field is incorrectly set. + rpc AllBalances(QueryAllBalancesRequest) returns (QueryAllBalancesResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/haqq/dao/v1/balances/{address}"; + } + + // TotalBalance queries the total balance of all coins locked in the module. + // + // When called from another module, this query might consume a high amount of + // gas if the pagination field is incorrectly set. + rpc TotalBalance(QueryTotalBalanceRequest) returns (QueryTotalBalanceResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/haqq/dao/v1/total_balance"; + } + + // Params queries the parameters of x/dao module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/haqq/dao/v1/params"; + } +} + +// QueryBalanceRequest is the request type for the Query/Balance RPC method. +message QueryBalanceRequest { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // address is the address to query balances for. + string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // denom is the coin denom to query balances for. + string denom = 2; +} + +// QueryBalanceResponse is the response type for the Query/Balance RPC method. +message QueryBalanceResponse { + // balance is the balance of the coin. + cosmos.base.v1beta1.Coin balance = 1; +} + +// QueryBalanceRequest is the request type for the Query/AllBalances RPC method. +message QueryAllBalancesRequest { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // address is the address to query balances for. + string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +// QueryAllBalancesResponse is the response type for the Query/AllBalances RPC +// method. +message QueryAllBalancesResponse { + // balances is the balances of all the coins. + repeated cosmos.base.v1beta1.Coin balances = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// QueryTotalBalanceRequest is the request type for the Query/TotalBalance RPC +// method. +message QueryTotalBalanceRequest { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // pagination defines an optional pagination for the request. + // + // Since: cosmos-sdk 0.43 + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QueryTotalBalanceResponse is the response type for the Query/TotalBalance RPC +// method +message QueryTotalBalanceResponse { + // supply is the supply of the coins + repeated cosmos.base.v1beta1.Coin total_balance = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + + // pagination defines the pagination in the response. + // + // Since: cosmos-sdk 0.43 + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// QueryParamsRequest defines the request type for querying x/dao parameters. +message QueryParamsRequest {} + +// QueryParamsResponse defines the response type for querying x/dao parameters. +message QueryParamsResponse { + Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} diff --git a/proto/haqq/dao/v1/tx.proto b/proto/haqq/dao/v1/tx.proto new file mode 100644 index 00000000..3a4932da --- /dev/null +++ b/proto/haqq/dao/v1/tx.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; + +package haqq.dao.v1; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; + +option go_package = "github.com/haqq-network/haqq/x/dao/types"; + +// Msg defines the dao Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // Fund defines a method to allow an account to directly fund the dao. + rpc Fund(MsgFund) returns (MsgFundResponse); +} + +// MsgFund allows an account to directly fund the dao. +message MsgFund { + option (cosmos.msg.v1.signer) = "depositor"; + option (amino.name) = "haqq/dao/MsgFund"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + repeated cosmos.base.v1beta1.Coin amount = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + string depositor = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + +// MsgFundResponse defines the Msg/Fund response type. +message MsgFundResponse {} diff --git a/proto/haqq/liquidvesting/v1/tx.proto b/proto/haqq/liquidvesting/v1/tx.proto index 2ef813f6..1a761575 100644 --- a/proto/haqq/liquidvesting/v1/tx.proto +++ b/proto/haqq/liquidvesting/v1/tx.proto @@ -36,7 +36,14 @@ message MsgLiquidate { } // MsgLiquidateResponse defines the Msg/Liquidate response type -message MsgLiquidateResponse {} +message MsgLiquidateResponse { + // amount of liquid tokens minted + cosmos.base.v1beta1.Coin minted = 1 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; + + // address of erc20 the liquidation denom contract + string contract_addr = 2; +} // MsgLiquidate represents message to redeem arbitrary amount of liquid vesting // tokens diff --git a/utils/conv.go b/utils/conv.go new file mode 100644 index 00000000..bf6ea0c5 --- /dev/null +++ b/utils/conv.go @@ -0,0 +1,26 @@ +package utils + +import ( + "reflect" + "unsafe" +) + +// UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes +// must not be altered after this function is called as it will cause a segmentation fault. +func UnsafeStrToBytes(s string) []byte { + var buf []byte + sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) + bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) + bufHdr.Data = sHdr.Data + bufHdr.Cap = sHdr.Len + bufHdr.Len = sHdr.Len + return buf +} + +// UnsafeBytesToStr is meant to make a zero allocation conversion +// from []byte -> string to speed up operations, it is not meant +// to be used generally, but for a specific pattern to delete keys +// from a map. +func UnsafeBytesToStr(b []byte) string { + return *(*string)(unsafe.Pointer(&b)) +} diff --git a/utils/utils.go b/utils/utils.go index df23796b..d8c239c8 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -15,6 +15,8 @@ import ( errortypes "github.com/cosmos/cosmos-sdk/types/errors" "golang.org/x/crypto/sha3" + "github.com/ethereum/go-ethereum/common" + "github.com/haqq-network/haqq/crypto/ethsecp256k1" ) @@ -43,21 +45,6 @@ func IsLocalNetwork(chainID string) bool { return strings.HasPrefix(chainID, LocalNetChainID) } -func IsAllowedVestingFunderAccount(funder string) bool { - // allowed accounts for vesting funder - funders := map[string]bool{ - "haqq1uu7epkq75j2qzqvlyzfkljc8h277gz7kxqah0v": true, // mainnet - "haqq185tcnd67yh9jngx090cggck0yrjsft9sj3lkht": true, - "haqq1527hg2arxkk0jd53pq80l0l9gjjlclsuxlwmq8": true, - "haqq1e666058j3ya392rspuxrt69tw6qhrxtxx8z9ha": true, - } - - // check if funder account is allowed - _, ok := funders[funder] - - return ok -} - // IsSupportedKey returns true if the pubkey type is supported by the chain // (i.e eth_secp256k1, amino multisig, ed25519). // NOTE: Nested multisigs are not supported. @@ -109,6 +96,11 @@ func GetHaqqAddressFromBech32(address string) (sdk.AccAddress, error) { return sdk.AccAddress(addressBz), nil } +func GetAccAddrFromEthAddress(addrString string) sdk.AccAddress { + addr := common.HexToAddress(addrString).Bytes() + return sdk.AccAddress(addr) +} + // parseHexValue -> parses a hex string into a big.Int func ParseHexValue(hexStr string) *big.Int { hexStr = Remove0xPrefix(hexStr) diff --git a/x/dao/client/cli/query.go b/x/dao/client/cli/query.go new file mode 100644 index 00000000..e1ac6a3b --- /dev/null +++ b/x/dao/client/cli/query.go @@ -0,0 +1,151 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/haqq-network/haqq/x/dao/types" +) + +const ( + FlagDenom = "denom" +) + +// GetQueryCmd returns the parent command for all x/dao CLi query commands. The +// provided clientCtx should have, at a minimum, a verifier, Tendermint RPC client, +// and marshaler set. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the dao module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + GetBalancesCmd(), + GetCmdQueryTotalBalance(), + ) + + return cmd +} + +func GetBalancesCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "balances [address]", + Short: "Query for account balances in the DAO by address", + Long: strings.TrimSpace( + fmt.Sprintf(`Query the total balance of an account or of a specific denomination. + +Example: + $ %s query %s balances [address] + $ %s query %s balances [address] --denom=[denom] +`, + version.AppName, types.ModuleName, version.AppName, types.ModuleName, + ), + ), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + denom, err := cmd.Flags().GetString(FlagDenom) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + addr, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + ctx := cmd.Context() + + if denom == "" { + params := types.NewQueryAllBalancesRequest(addr, pageReq) + + res, err := queryClient.AllBalances(ctx, params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + } + + params := types.NewQueryBalanceRequest(addr, denom) + + res, err := queryClient.Balance(ctx, params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res.Balance) + }, + } + + cmd.Flags().String(FlagDenom, "", "The specific balance denomination to query for") + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all balances") + + return cmd +} + +func GetCmdQueryTotalBalance() *cobra.Command { + cmd := &cobra.Command{ + Use: "total-balance", + Short: "Query the total balances of coins in the DAO", + Args: cobra.NoArgs, + Long: strings.TrimSpace( + fmt.Sprintf(`Query total balances of coins that are held by accounts in the DAO. + +Example: + $ %s query %s total-balance +`, + version.AppName, types.ModuleName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + ctx := cmd.Context() + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + res, err := queryClient.TotalBalance(ctx, &types.QueryTotalBalanceRequest{Pagination: pageReq}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "all supply totals") + + return cmd +} diff --git a/x/dao/client/cli/tx.go b/x/dao/client/cli/tx.go new file mode 100644 index 00000000..1e2269af --- /dev/null +++ b/x/dao/client/cli/tx.go @@ -0,0 +1,80 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + + "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" + + "github.com/haqq-network/haqq/x/dao/types" +) + +// Transaction flags for the x/distribution module +var ( + FlagCommission = "commission" + FlagMaxMessagesPerTx = "max-msgs" +) + +const ( + MaxMessagesPerTxDefault = 0 +) + +// NewTxCmd returns a root CLI command handler for all x/distribution transaction commands. +func NewTxCmd() *cobra.Command { + distTxCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Distribution transactions subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + distTxCmd.AddCommand( + NewFundDAOCmd(), + ) + + return distTxCmd +} + +// NewFundDAOCmd returns a CLI command handler for creating a MsgFund transaction. +func NewFundDAOCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "fund [amount]", + Args: cobra.ExactArgs(1), + Short: "Funds the DAO with the specified amount", + Long: strings.TrimSpace( + fmt.Sprintf(`Funds the dao with the specified amount + +Example: +$ %s tx %s fund 100aISLM --from mykey +`, + version.AppName, types.ModuleName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + depositorAddr := clientCtx.GetFromAddress() + amount, err := sdk.ParseCoinsNormalized(args[0]) + if err != nil { + return err + } + + msg := types.NewMsgFund(amount, depositorAddr) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/dao/exported/exported.go b/x/dao/exported/exported.go new file mode 100644 index 00000000..7ab9136e --- /dev/null +++ b/x/dao/exported/exported.go @@ -0,0 +1,25 @@ +package exported + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// GenesisBalance defines a genesis balance interface that allows for account +// address and balance retrieval. +type GenesisBalance interface { + GetAddress() sdk.AccAddress + GetCoins() sdk.Coins +} + +type ( + ParamSet = paramtypes.ParamSet + + // Subspace defines an interface that implements the legacy x/params Subspace + // type. + // + // NOTE: This is used solely for migration of x/params managed parameters. + Subspace interface { + GetParamSet(ctx sdk.Context, ps ParamSet) + } +) diff --git a/x/dao/keeper/account_balances.go b/x/dao/keeper/account_balances.go new file mode 100644 index 00000000..9276174d --- /dev/null +++ b/x/dao/keeper/account_balances.go @@ -0,0 +1,186 @@ +package keeper + +import ( + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/haqq-network/haqq/x/dao/types" +) + +// GetBalance returns the balance of a specific denomination for a given account +// by address. +func (k BaseKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin { + accountStore := k.getAccountStore(ctx, addr) + bz := accountStore.Get([]byte(denom)) + balance, err := UnmarshalBalanceCompat(k.cdc, bz, denom) + if err != nil { + panic(err) + } + + return balance +} + +// HasBalance returns whether or not an account has at least amt balance. +func (k BaseKeeper) HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool { + return k.GetBalance(ctx, addr, amt.Denom).IsGTE(amt) +} + +// IterateAccountBalances iterates over the balances of a single account and +// provides the token balance to a callback. If true is returned from the +// callback, iteration is halted. +func (k BaseKeeper) IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(sdk.Coin) bool) { + accountStore := k.getAccountStore(ctx, addr) + + iterator := accountStore.Iterator(nil, nil) + defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + + for ; iterator.Valid(); iterator.Next() { + denom := string(iterator.Key()) + balance, err := UnmarshalBalanceCompat(k.cdc, iterator.Value(), denom) + if err != nil { + panic(err) + } + + if cb(balance) { + break + } + } +} + +// IterateAllBalances iterates over all the balances of all accounts and +// denominations that are provided to a callback. If true is returned from the +// callback, iteration is halted. +func (k BaseKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddress, sdk.Coin) bool) { + store := ctx.KVStore(k.storeKey) + balancesStore := prefix.NewStore(store, types.BalancesPrefix) + + iterator := balancesStore.Iterator(nil, nil) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + address, denom, err := types.AddressAndDenomFromBalancesStore(iterator.Key()) + if err != nil { + k.Logger(ctx).With("key", iterator.Key(), "err", err).Error("failed to get address from balances store") + // TODO: revisit, for now, panic here to keep same behavior as in 0.42 + // ref: https://github.com/cosmos/cosmos-sdk/issues/7409 + panic(err) + } + + balance, err := UnmarshalBalanceCompat(k.cdc, iterator.Value(), denom) + if err != nil { + panic(err) + } + + if cb(address, balance) { + break + } + } +} + +// GetAccountsBalances returns all the accounts balances from the store. +func (k BaseKeeper) GetAccountsBalances(ctx sdk.Context) []types.Balance { + balances := make([]types.Balance, 0) + mapAddressToBalancesIdx := make(map[string]int) + + k.IterateAllBalances(ctx, func(addr sdk.AccAddress, balance sdk.Coin) bool { + idx, ok := mapAddressToBalancesIdx[addr.String()] + if ok { + // address is already on the set of accounts balances + balances[idx].Coins = balances[idx].Coins.Add(balance) + balances[idx].Coins.Sort() + return false + } + + accountBalance := types.Balance{ + Address: addr.String(), + Coins: sdk.NewCoins(balance), + } + balances = append(balances, accountBalance) + mapAddressToBalancesIdx[addr.String()] = len(balances) - 1 + return false + }) + + return balances +} + +// UnmarshalBalanceCompat unmarshal balance amount from storage, it's backward-compatible with the legacy format. +func UnmarshalBalanceCompat(cdc codec.BinaryCodec, bz []byte, denom string) (sdk.Coin, error) { + if err := sdk.ValidateDenom(denom); err != nil { + return sdk.Coin{}, err + } + + amount := math.ZeroInt() + if bz == nil { + return sdk.NewCoin(denom, amount), nil + } + + if err := amount.Unmarshal(bz); err != nil { + // try to unmarshal with the legacy format. + var balance sdk.Coin + if cdc.Unmarshal(bz, &balance) != nil { + // return with the original error + return sdk.Coin{}, err + } + return balance, nil + } + + return sdk.NewCoin(denom, amount), nil +} + +// setBalance sets the coin balance for an account by address. +func (k BaseKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error { + if !balance.IsValid() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, balance.String()) + } + + accountStore := k.getAccountStore(ctx, addr) + denomPrefixStore := k.getDenomAddressPrefixStore(ctx, balance.Denom) + + // x/bank invariants prohibit persistence of zero balances + if balance.IsZero() { + accountStore.Delete([]byte(balance.Denom)) + denomPrefixStore.Delete(address.MustLengthPrefix(addr)) + } else { + amount, err := balance.Amount.Marshal() + if err != nil { + return err + } + + accountStore.Set([]byte(balance.Denom), amount) + + // Store a reverse index from denomination to account address with a + // sentinel value. + denomAddrKey := address.MustLengthPrefix(addr) + if !denomPrefixStore.Has(denomAddrKey) { + denomPrefixStore.Set(denomAddrKey, []byte{0}) + } + } + + return nil +} + +// addCoinsToAccount increase the addr balance by the given amt. Fails if the provided +// amt is invalid. It emits a coin received event. +func (k BaseKeeper) addCoinsToAccount(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error { + if !amt.IsValid() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String()) + } + + for _, coin := range amt { + balance := k.GetBalance(ctx, addr, coin.Denom) + newBalance := balance.Add(coin) + + err := k.setBalance(ctx, addr, newBalance) + if err != nil { + return err + } + } + + // TODO emit coin received event + + return nil +} diff --git a/x/dao/keeper/genesis.go b/x/dao/keeper/genesis.go new file mode 100644 index 00000000..24e03603 --- /dev/null +++ b/x/dao/keeper/genesis.go @@ -0,0 +1,89 @@ +package keeper + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/haqq-network/haqq/x/dao/types" +) + +// InitGenesis initializes the bank module's state from a given genesis state. +func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { + if err := k.SetParams(ctx, genState.Params); err != nil { + panic(err) + } + + totalBalance := sdk.Coins{} + genState.Balances = types.SanitizeGenesisBalances(genState.Balances) + + for _, balance := range genState.Balances { + addr := balance.GetAddress() + + if err := k.initBalances(ctx, addr, balance.Coins); err != nil { + panic(fmt.Errorf("error on setting balances %w", err)) + } + + totalBalance = totalBalance.Add(balance.Coins...) + } + + if !genState.TotalBalance.Empty() && !genState.TotalBalance.IsEqual(totalBalance) { + panic(fmt.Errorf("genesis total balance is incorrect, expected %v, got %v", genState.TotalBalance, totalBalance)) + } + + for _, supply := range totalBalance { + k.setTotalBalanceOfCoin(ctx, supply) + } +} + +// ExportGenesis returns the bank module's genesis state. +func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + gs := types.NewGenesisState( + k.GetParams(ctx), + k.GetAccountsBalances(ctx), + k.GetTotalBalance(ctx), + ) + + return gs +} + +// initBalances sets the balance (multiple coins) for an account by address. +// An error is returned upon failure. +func (k BaseKeeper) initBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error { + accountStore := k.getAccountStore(ctx, addr) + denomPrefixStores := make(map[string]prefix.Store) // memoize prefix stores + + for i := range balances { + balance := balances[i] + if !balance.IsValid() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, balance.String()) + } + + // x/dao invariants prohibit persistence of zero balances + if !balance.IsZero() { + amount, err := balance.Amount.Marshal() + if err != nil { + return err + } + accountStore.Set([]byte(balance.Denom), amount) + + denomPrefixStore, ok := denomPrefixStores[balance.Denom] + if !ok { + denomPrefixStore = k.getDenomAddressPrefixStore(ctx, balance.Denom) + denomPrefixStores[balance.Denom] = denomPrefixStore + } + + // Store a reverse index from denomination to account address with a + // sentinel value. + denomAddrKey := address.MustLengthPrefix(addr) + if !denomPrefixStore.Has(denomAddrKey) { + denomPrefixStore.Set(denomAddrKey, []byte{0}) + } + } + } + + return nil +} diff --git a/x/dao/keeper/grpc_query.go b/x/dao/keeper/grpc_query.go new file mode 100644 index 00000000..910d9b0a --- /dev/null +++ b/x/dao/keeper/grpc_query.go @@ -0,0 +1,90 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/haqq-network/haqq/x/dao/types" +) + +var _ types.QueryServer = BaseKeeper{} + +// Balance implements the Query/Balance gRPC method +func (k BaseKeeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if err := sdk.ValidateDenom(req.Denom); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + address, err := sdk.AccAddressFromBech32(req.Address) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) + } + + balance := k.GetBalance(sdkCtx, address, req.Denom) + + return &types.QueryBalanceResponse{Balance: &balance}, nil +} + +// AllBalances implements the Query/AllBalances gRPC method +func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequest) (*types.QueryAllBalancesResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + addr, err := sdk.AccAddressFromBech32(req.Address) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + balances := sdk.NewCoins() + accountStore := k.getAccountStore(sdkCtx, addr) + + pageRes, err := query.Paginate(accountStore, req.Pagination, func(key, value []byte) error { + denom := string(key) + balance, err := UnmarshalBalanceCompat(k.cdc, value, denom) + if err != nil { + return err + } + balances = append(balances, balance) + return nil + }) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "paginate: %v", err) + } + + return &types.QueryAllBalancesResponse{Balances: balances, Pagination: pageRes}, nil +} + +// TotalBalance implements the Query/TotalSupply gRPC method +func (k BaseKeeper) TotalBalance(ctx context.Context, req *types.QueryTotalBalanceRequest) (*types.QueryTotalBalanceResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + totalBalance, pageRes, err := k.GetPaginatedTotalBalance(sdkCtx, req.Pagination) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryTotalBalanceResponse{TotalBalance: totalBalance, Pagination: pageRes}, nil +} + +// Params implements the gRPC service handler for querying x/bank parameters. +func (k BaseKeeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Errorf(codes.InvalidArgument, "empty request") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + params := k.GetParams(sdkCtx) + + return &types.QueryParamsResponse{Params: params}, nil +} diff --git a/x/dao/keeper/integration_test.go b/x/dao/keeper/integration_test.go new file mode 100644 index 00000000..c4bd28ad --- /dev/null +++ b/x/dao/keeper/integration_test.go @@ -0,0 +1,293 @@ +package keeper_test + +import ( + "strings" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/haqq-network/haqq/testutil" + "github.com/haqq-network/haqq/utils" + "github.com/haqq-network/haqq/x/dao/types" +) + +var _ = Describe("Feemarket", func() { + var ( + daoModuleAcc authtypes.ModuleAccountI + fundMsg *types.MsgFund + err error + ) + + Describe("Performing Cosmos transactions", func() { + oneHundred, _ := sdk.NewIntFromString("100000000000000000000") + oneHundredIslm := sdk.NewCoin(utils.BaseDenom, oneHundred) + oneIslm := sdk.NewInt64Coin(utils.BaseDenom, 1000000000000000000) + threeInvalid := sdk.NewInt64Coin("invalid", 3000000000000000000) + fiveLiquid1 := sdk.NewInt64Coin("aLIQUID1", 5000000000000000000) + sevenLiquid75 := sdk.NewInt64Coin("aLIQUID75", 7000000000000000000) + nineLiquidInvalid := sdk.NewInt64Coin("aLIQUID", 9000000000000000000) + gasPrice := sdkmath.NewInt(1000000000) + + Context("with invalid denom", func() { + BeforeEach(func() { + s.SetupTest() + + daoModuleAcc = s.app.AccountKeeper.GetModuleAccount(s.ctx, types.ModuleName) + + daoBalanceBefore := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), utils.BaseDenom) + Expect(daoBalanceBefore.IsZero()).To(BeTrue(), "dao account should have no balance") + + err = testutil.FundAccount(s.ctx, s.app.BankKeeper, s.address, sdk.NewCoins(oneHundredIslm, threeInvalid, fiveLiquid1, sevenLiquid75, nineLiquidInvalid)) + s.Require().NoError(err) + + s.Commit() + }) + + Context("correct aLIQUID with invalid", func() { + It("should fail", func() { + // Check balances before TX + daoBankBalanceBefore := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), fiveLiquid1.Denom) + Expect(daoBankBalanceBefore.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalBalanceBefore, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalBalanceBefore.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressBalanceBefore, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressBalanceBefore.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + + // TX Process + fundMsg = types.NewMsgFund( + sdk.NewCoins(threeInvalid, fiveLiquid1), + s.address, + ) + _, err = testutil.DeliverTx(s.ctx, s.app, s.priv, &gasPrice, fundMsg) + Expect(err).NotTo(BeNil(), "transaction should have failed") + Expect( + strings.Contains(err.Error(), + "denom invalid is not allowed"), + ).To(BeTrue(), err.Error()) + s.Commit() + + // Check balances after TX + daoBankBalanceAfter := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), fiveLiquid1.Denom) + Expect(daoBankBalanceAfter.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalBalanceAfter, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalBalanceAfter.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressBalanceAfter, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressBalanceAfter.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + }) + }) + + Context("correct aISLM with invalid", func() { + It("should fail", func() { + // Check balances before TX + daoBankBalanceBefore := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), oneIslm.Denom) + Expect(daoBankBalanceBefore.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalBalanceBefore, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalBalanceBefore.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressBalanceBefore, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressBalanceBefore.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + + // TX Process + fundMsg = types.NewMsgFund( + sdk.NewCoins(oneIslm, nineLiquidInvalid), + s.address, + ) + _, err = testutil.DeliverTx(s.ctx, s.app, s.priv, &gasPrice, fundMsg) + Expect(err).NotTo(BeNil(), "transaction should have failed") + Expect( + strings.Contains(err.Error(), + "denom aLIQUID is not allowed"), + ).To(BeTrue(), err.Error()) + s.Commit() + + // Check balances after TX + daoBankBalanceAfter := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), oneIslm.Denom) + Expect(daoBankBalanceAfter.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalBalanceAfter, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalBalanceAfter.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressBalanceAfter, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressBalanceAfter.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + }) + }) + }) + + Context("with correct denoms", func() { + BeforeEach(func() { + s.SetupTest() + + err = testutil.FundAccount(s.ctx, s.app.BankKeeper, s.address, sdk.NewCoins(oneHundredIslm, threeInvalid, fiveLiquid1, sevenLiquid75, nineLiquidInvalid)) + s.Require().NoError(err) + + s.Commit() + }) + + Context("correct standalone aLIQUID", func() { + It("should pass", func() { + // Check balances before TX + daoBankBalanceBefore := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), sevenLiquid75.Denom) + Expect(daoBankBalanceBefore.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalBalanceBefore, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalBalanceBefore.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressBalanceBefore, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressBalanceBefore.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + + // TX Process + fundMsg = types.NewMsgFund( + sdk.NewCoins(sevenLiquid75), + s.address, + ) + _, err = testutil.DeliverTx(s.ctx, s.app, s.priv, &gasPrice, fundMsg) + Expect(err).To(BeNil(), "transaction should have succeed") + s.Commit() + + // Check balances after TX + daoBankBalanceAfter := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), sevenLiquid75.Denom) + Expect(daoBankBalanceAfter.Amount.String()).To(Equal(sevenLiquid75.Amount.String()), "dao account should have received the funds") + + daoTotalBalanceAfter, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + ok, amount := daoTotalBalanceAfter.TotalBalance.Find(sevenLiquid75.Denom) + Expect(ok).To(BeTrue(), "dao total balance should have received the funds") + Expect(amount.String()).To(Equal(sevenLiquid75.String()), "dao total balance should have received the funds") + + daoAddressBalanceAfter, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + okAcc, amountAcc := daoAddressBalanceAfter.Balances.Find(sevenLiquid75.Denom) + Expect(okAcc).To(BeTrue(), "dao address balance should have received the funds") + Expect(amountAcc.String()).To(Equal(sevenLiquid75.String()), "dao address balance should have received the funds") + }) + }) + + Context("correct standalone aISLM", func() { + It("should pass", func() { + // Check balances before TX + daoBankBalanceBefore := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), oneIslm.Denom) + Expect(daoBankBalanceBefore.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalBalanceBefore, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalBalanceBefore.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressBalanceBefore, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressBalanceBefore.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + + // TX Process + fundMsg = types.NewMsgFund( + sdk.NewCoins(oneIslm), + s.address, + ) + _, err = testutil.DeliverTx(s.ctx, s.app, s.priv, &gasPrice, fundMsg) + Expect(err).To(BeNil(), "transaction should have succeed") + s.Commit() + + // Check balances after TX + daoBankBalanceAfter := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), oneIslm.Denom) + Expect(daoBankBalanceAfter.Amount.String()).To(Equal(oneIslm.Amount.String()), "dao account should have received the funds") + + daoTotalBalanceAfter, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + ok, amount := daoTotalBalanceAfter.TotalBalance.Find(oneIslm.Denom) + Expect(ok).To(BeTrue(), "dao total balance should have received the funds") + Expect(amount.String()).To(Equal(oneIslm.String()), "dao total balance should have received the funds") + + daoAddressBalanceAfter, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + okAcc, amountAcc := daoAddressBalanceAfter.Balances.Find(oneIslm.Denom) + Expect(okAcc).To(BeTrue(), "dao address balance should have received the funds") + Expect(amountAcc.String()).To(Equal(oneIslm.String()), "dao address balance should have received the funds") + }) + }) + + Context("correct aISLM and aLIQUID", func() { + It("should pass", func() { + // Check balances before TX + daoBankIslmBalanceBefore := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), oneIslm.Denom) + Expect(daoBankIslmBalanceBefore.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalIslmBalanceBefore, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalIslmBalanceBefore.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressIslmBalanceBefore, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressIslmBalanceBefore.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + + daoBankLiquidBalanceBefore := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), fiveLiquid1.Denom) + Expect(daoBankLiquidBalanceBefore.IsZero()).To(BeTrue(), "dao account should have no balance") + + daoTotalLiquidBalanceBefore, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoTotalLiquidBalanceBefore.TotalBalance.IsZero()).To(BeTrue(), "dao total balance should be empty") + + daoAddressLiquidBalanceBefore, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + Expect(daoAddressLiquidBalanceBefore.Balances.IsZero()).To(BeTrue(), "dao address balance should be empty") + + // TX Process + fundMsg = types.NewMsgFund( + sdk.NewCoins(oneIslm, fiveLiquid1), + s.address, + ) + _, err = testutil.DeliverTx(s.ctx, s.app, s.priv, &gasPrice, fundMsg) + Expect(err).To(BeNil(), "transaction should have succeed") + s.Commit() + + // Check balances after TX + daoBankIslmBalanceAfter := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), oneIslm.Denom) + Expect(daoBankIslmBalanceAfter.Amount.String()).To(Equal(oneIslm.Amount.String()), "dao account should have received the funds") + + daoTotalIslmBalanceAfter, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + ok, amount := daoTotalIslmBalanceAfter.TotalBalance.Find(oneIslm.Denom) + Expect(ok).To(BeTrue(), "dao total balance should have received the funds") + Expect(amount.String()).To(Equal(oneIslm.String()), "dao total balance should have received the funds") + + daoAddressIslmBalanceAfter, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + okAcc, amountAcc := daoAddressIslmBalanceAfter.Balances.Find(oneIslm.Denom) + Expect(okAcc).To(BeTrue(), "dao address balance should have received the funds") + Expect(amountAcc.String()).To(Equal(oneIslm.String()), "dao address balance should have received the funds") + + daoBankLiquidBalanceAfter := s.app.BankKeeper.GetBalance(s.ctx, daoModuleAcc.GetAddress(), fiveLiquid1.Denom) + Expect(daoBankLiquidBalanceAfter.Amount.String()).To(Equal(fiveLiquid1.Amount.String()), "dao account should have received the funds") + + daoTotalLiquidBalanceAfter, err := s.queryClient.TotalBalance(s.ctx, &types.QueryTotalBalanceRequest{}) + Expect(err).To(BeNil(), "query should have succeed") + ok, amountLiq := daoTotalLiquidBalanceAfter.TotalBalance.Find(fiveLiquid1.Denom) + Expect(ok).To(BeTrue(), "dao total balance should have received the funds") + Expect(amountLiq.String()).To(Equal(fiveLiquid1.String()), "dao total balance should have received the funds") + + daoAddressLiquidBalanceAfter, err := s.queryClient.AllBalances(s.ctx, &types.QueryAllBalancesRequest{Address: s.address.String()}) + Expect(err).To(BeNil(), "query should have succeed") + okAcc, amountLiqAcc := daoAddressLiquidBalanceAfter.Balances.Find(fiveLiquid1.Denom) + Expect(okAcc).To(BeTrue(), "dao address balance should have received the funds") + Expect(amountLiqAcc.String()).To(Equal(fiveLiquid1.String()), "dao address balance should have received the funds") + }) + }) + }) + }) +}) diff --git a/x/dao/keeper/keeper.go b/x/dao/keeper/keeper.go new file mode 100644 index 00000000..58efdaea --- /dev/null +++ b/x/dao/keeper/keeper.go @@ -0,0 +1,115 @@ +package keeper + +import ( + "context" + "fmt" + + sdkerrors "cosmossdk.io/errors" + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/haqq-network/haqq/utils" + "github.com/haqq-network/haqq/x/dao/types" +) + +var _ Keeper = (*BaseKeeper)(nil) + +// Keeper defines a module interface that facilitates the transfer of coins +// between accounts. +type Keeper interface { + GetTotalBalance(ctx sdk.Context) sdk.Coins + GetPaginatedTotalBalance(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error) + IterateTotalBalance(ctx sdk.Context, cb func(sdk.Coin) bool) + GetTotalBalanceOf(ctx sdk.Context, denom string) sdk.Coin + HasTotalBalanceOf(ctx sdk.Context, denom string) bool + + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool + IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(sdk.Coin) bool) + IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddress, sdk.Coin) bool) + GetAccountsBalances(ctx sdk.Context) []types.Balance + + Fund(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error + + // grpc query endpoints + Balance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) + AllBalances(ctx context.Context, req *types.QueryAllBalancesRequest) (*types.QueryAllBalancesResponse, error) + TotalBalance(ctx context.Context, req *types.QueryTotalBalanceRequest) (*types.QueryTotalBalanceResponse, error) + Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) + + // genesis methods + InitGenesis(ctx sdk.Context, genState *types.GenesisState) + ExportGenesis(ctx sdk.Context) *types.GenesisState +} + +// BaseKeeper manages transfers between accounts. It implements the Keeper interface. +type BaseKeeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + + ak types.AccountKeeper + bk types.BankKeeper +} + +func NewBaseKeeper( + cdc codec.BinaryCodec, + storeKey storetypes.StoreKey, + ak types.AccountKeeper, + bk types.BankKeeper, + authority string, +) BaseKeeper { + if _, err := sdk.AccAddressFromBech32(authority); err != nil { + panic(fmt.Errorf("invalid dao authority address: %w", err)) + } + + // TODO Add authority address to the keeper + return BaseKeeper{ + cdc: cdc, + storeKey: storeKey, + ak: ak, + bk: bk, + } +} + +// Fund allows an account to directly fund the community fund pool. +// The amount is first added to the distribution module account and then directly +// added to the pool. An error is returned if the amount cannot be sent to the +// module account. +func (k BaseKeeper) Fund(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error { + if !k.IsModuleEnabled(ctx) { + return types.ErrModuleDisabled + } + + if err := k.bk.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil { + return err + } + + for _, coin := range amount { + if coin.Denom != utils.BaseDenom && !IsLiquidToken(coin.Denom) { + return sdkerrors.Wrapf(types.ErrInvalidDenom, "denom %s is not allowed", coin.Denom) + } + + if coin.IsZero() { + continue + } + + err := k.addCoinsToAccount(ctx, sender, sdk.NewCoins(coin)) + if err != nil { + return err + } + + bal := k.GetTotalBalanceOf(ctx, coin.Denom) + bal = bal.Add(coin) + k.setTotalBalanceOfCoin(ctx, bal) + } + + return nil +} + +// Logger returns a module-specific logger. +func (k BaseKeeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", "x/"+types.ModuleName) +} diff --git a/x/dao/keeper/msg_server.go b/x/dao/keeper/msg_server.go new file mode 100644 index 00000000..a700cc79 --- /dev/null +++ b/x/dao/keeper/msg_server.go @@ -0,0 +1,35 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/haqq-network/haqq/x/dao/types" +) + +type msgServer struct { + Keeper +} + +var _ types.MsgServer = msgServer{} + +// NewMsgServerImpl returns an implementation of the distribution MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +func (k msgServer) Fund(goCtx context.Context, msg *types.MsgFund) (*types.MsgFundResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + depositer, err := sdk.AccAddressFromBech32(msg.Depositor) + if err != nil { + return nil, err + } + if err := k.Keeper.Fund(ctx, msg.Amount, depositer); err != nil { + return nil, err + } + + return &types.MsgFundResponse{}, nil +} diff --git a/x/dao/keeper/params.go b/x/dao/keeper/params.go new file mode 100644 index 00000000..6854af0f --- /dev/null +++ b/x/dao/keeper/params.go @@ -0,0 +1,38 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/haqq-network/haqq/x/dao/types" +) + +// GetParams returns the total set of dao parameters. +func (k BaseKeeper) GetParams(ctx sdk.Context) (params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams sets the total set of dao parameters. +func (k BaseKeeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + + store.Set(types.ParamsKey, bz) + + return nil +} + +func (k BaseKeeper) IsModuleEnabled(ctx sdk.Context) bool { + params := k.GetParams(ctx) + + return params.EnableDao +} diff --git a/x/dao/keeper/setup_test.go b/x/dao/keeper/setup_test.go new file mode 100644 index 00000000..077c86ad --- /dev/null +++ b/x/dao/keeper/setup_test.go @@ -0,0 +1,140 @@ +package keeper_test + +import ( + "testing" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + + "github.com/haqq-network/haqq/app" + "github.com/haqq-network/haqq/crypto/ethsecp256k1" + "github.com/haqq-network/haqq/encoding" + "github.com/haqq-network/haqq/testutil" + utiltx "github.com/haqq-network/haqq/testutil/tx" + haqqtypes "github.com/haqq-network/haqq/types" + "github.com/haqq-network/haqq/utils" + "github.com/haqq-network/haqq/x/dao/types" + evmtypes "github.com/haqq-network/haqq/x/evm/types" +) + +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + app *app.Haqq + queryClient types.QueryClient + priv *ethsecp256k1.PrivKey + address sdk.AccAddress + consAddress sdk.ConsAddress + + // for generate test tx + clientCtx client.Context + ethSigner ethtypes.Signer + + appCodec codec.Codec + signer keyring.Signer + denom string +} + +var s *KeeperTestSuite + +func TestKeeperTestSuite(t *testing.T) { + s = new(KeeperTestSuite) + suite.Run(t, s) + + // Run Ginkgo integration tests + RegisterFailHandler(Fail) + RunSpecs(t, "Keeper Suite") +} + +// SetupTest setup test environment, it uses`require.TestingT` to support both `testing.T` and `testing.B`. +func (suite *KeeperTestSuite) SetupTest() { + checkTx := false + suite.app, _ = app.Setup(checkTx, nil) + suite.SetupApp(checkTx) +} + +func (suite *KeeperTestSuite) SetupApp(checkTx bool) { + t := suite.T() + // account key + priv, err := ethsecp256k1.GenerateKey() + require.NoError(t, err) + suite.priv = priv + suite.address = priv.PubKey().Address().Bytes() + suite.signer = utiltx.NewSigner(priv) + + // consensus key + priv, err = ethsecp256k1.GenerateKey() + require.NoError(t, err) + suite.consAddress = sdk.ConsAddress(priv.PubKey().Address()) + + header := testutil.NewHeader( + 1, time.Now().UTC(), "haqq_11235-1", suite.consAddress, nil, nil, + ) + + suite.ctx = suite.app.BaseApp.NewContext(checkTx, header) + + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, suite.app.DaoKeeper) + suite.queryClient = types.NewQueryClient(queryHelper) + + acc := &haqqtypes.EthAccount{ + BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0), + CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(), + } + + suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + + valAddr := sdk.ValAddress(suite.address.Bytes()) + validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{}) + require.NoError(t, err) + validator = stakingkeeper.TestingUpdateValidator(&suite.app.StakingKeeper, suite.ctx, validator, true) + err = suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, validator.GetOperator()) + require.NoError(t, err) + + err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) + require.NoError(t, err) + suite.app.StakingKeeper.SetValidator(suite.ctx, validator) + + stakingParams := stakingtypes.DefaultParams() + stakingParams.BondDenom = utils.BaseDenom + err = suite.app.StakingKeeper.SetParams(suite.ctx, stakingParams) + require.NoError(t, err) + + encodingConfig := encoding.MakeConfig(app.ModuleBasics) + suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig) + suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID()) + suite.appCodec = encodingConfig.Codec + suite.denom = evmtypes.DefaultEVMDenom +} + +// Commit commits and starts a new block with an updated context. +func (suite *KeeperTestSuite) Commit() { + suite.CommitAfter(time.Second * 0) +} + +// Commit commits a block at a given time. +func (suite *KeeperTestSuite) CommitAfter(t time.Duration) { + var err error + suite.ctx, err = testutil.Commit(suite.ctx, suite.app, t, nil) + suite.Require().NoError(err) + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, suite.app.DaoKeeper) + suite.queryClient = types.NewQueryClient(queryHelper) +} diff --git a/x/dao/keeper/store.go b/x/dao/keeper/store.go new file mode 100644 index 00000000..4e81a844 --- /dev/null +++ b/x/dao/keeper/store.go @@ -0,0 +1,20 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/haqq-network/haqq/x/dao/types" +) + +// getAccountStore gets the account store of the given address. +func (k BaseKeeper) getAccountStore(ctx sdk.Context, addr sdk.AccAddress) prefix.Store { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.CreateAccountBalancesPrefix(addr)) +} + +// getDenomAddressPrefixStore returns a prefix store that acts as a reverse index +// between a denomination and account balance for that denomination. +func (k BaseKeeper) getDenomAddressPrefixStore(ctx sdk.Context, denom string) prefix.Store { + return prefix.NewStore(ctx.KVStore(k.storeKey), types.CreateDenomAddressPrefix(denom)) +} diff --git a/x/dao/keeper/total_balance.go b/x/dao/keeper/total_balance.go new file mode 100644 index 00000000..a88bf2d4 --- /dev/null +++ b/x/dao/keeper/total_balance.go @@ -0,0 +1,134 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/haqq-network/haqq/utils" + "github.com/haqq-network/haqq/x/dao/types" +) + +// GetTotalBalance get the global total balance of dao module +func (k BaseKeeper) GetTotalBalance(ctx sdk.Context) sdk.Coins { + balance := sdk.NewCoins() + + k.IterateTotalBalance(ctx, func(c sdk.Coin) bool { + if c.IsZero() { + return false + } + + balance = balance.Add(c) + + return false + }) + + return balance +} + +// GetPaginatedTotalBalance queries for the supply, ignoring 0 coins, with a given pagination +func (k BaseKeeper) GetPaginatedTotalBalance(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error) { + store := ctx.KVStore(k.storeKey) + supplyStore := prefix.NewStore(store, types.TotalBalanceKey) + + supply := sdk.NewCoins() + + pageRes, err := query.Paginate(supplyStore, pagination, func(key, value []byte) error { + var amount math.Int + err := amount.Unmarshal(value) + if err != nil { + return fmt.Errorf("unable to convert amount string to Int %v", err) + } + + // `Add` omits the 0 coins addition to the `supply`. + supply = supply.Add(sdk.NewCoin(string(key), amount)) + return nil + }) + if err != nil { + return nil, nil, err + } + + return supply, pageRes, nil +} + +// IterateTotalBalance iterates over the total balance calling the given cb (callback) function +// with the balance of each coin. +// The iteration stops if the callback returns true. +func (k BaseKeeper) IterateTotalBalance(ctx sdk.Context, cb func(sdk.Coin) bool) { + store := ctx.KVStore(k.storeKey) + supplyStore := prefix.NewStore(store, types.TotalBalanceKey) + + iterator := supplyStore.Iterator(nil, nil) + defer sdk.LogDeferred(ctx.Logger(), func() error { return iterator.Close() }) + + for ; iterator.Valid(); iterator.Next() { + var amount math.Int + err := amount.Unmarshal(iterator.Value()) + if err != nil { + panic(fmt.Errorf("unable to unmarshal supply value %v", err)) + } + + balance := sdk.Coin{ + Denom: string(iterator.Key()), + Amount: amount, + } + + if cb(balance) { + break + } + } +} + +// GetTotalBalanceOf retrieves the total balance of certain coin from store +func (k BaseKeeper) GetTotalBalanceOf(ctx sdk.Context, denom string) sdk.Coin { + store := ctx.KVStore(k.storeKey) + supplyStore := prefix.NewStore(store, types.TotalBalanceKey) + + bz := supplyStore.Get(utils.UnsafeStrToBytes(denom)) + if bz == nil { + return sdk.Coin{ + Denom: denom, + Amount: sdk.NewInt(0), + } + } + + var amount math.Int + err := amount.Unmarshal(bz) + if err != nil { + panic(fmt.Errorf("unable to unmarshal total balance value %v", err)) + } + + return sdk.Coin{ + Denom: denom, + Amount: amount, + } +} + +// HasTotalBalanceOf checks if the supply coin exists in store. +func (k BaseKeeper) HasTotalBalanceOf(ctx sdk.Context, denom string) bool { + store := ctx.KVStore(k.storeKey) + supplyStore := prefix.NewStore(store, types.TotalBalanceKey) + + return supplyStore.Has(utils.UnsafeStrToBytes(denom)) +} + +// setSupply sets the supply for the given coin +func (k BaseKeeper) setTotalBalanceOfCoin(ctx sdk.Context, coin sdk.Coin) { + intBytes, err := coin.Amount.Marshal() + if err != nil { + panic(fmt.Errorf("unable to marshal amount value %v", err)) + } + + store := ctx.KVStore(k.storeKey) + supplyStore := prefix.NewStore(store, types.TotalBalanceKey) + + // Bank invariants and IBC requires to remove zero coins. + if coin.IsZero() { + supplyStore.Delete(utils.UnsafeStrToBytes(coin.GetDenom())) + } else { + supplyStore.Set([]byte(coin.GetDenom()), intBytes) + } +} diff --git a/x/dao/keeper/utils.go b/x/dao/keeper/utils.go new file mode 100644 index 00000000..c523bc60 --- /dev/null +++ b/x/dao/keeper/utils.go @@ -0,0 +1,9 @@ +package keeper + +import "regexp" + +var aLiquidDenom = regexp.MustCompile(`^aLIQUID[0-9]+$`) + +func IsLiquidToken(denom string) bool { + return aLiquidDenom.MatchString(denom) +} diff --git a/x/dao/module.go b/x/dao/module.go new file mode 100644 index 00000000..03f3965f --- /dev/null +++ b/x/dao/module.go @@ -0,0 +1,212 @@ +package dao + +import ( + "context" + "encoding/json" + "fmt" + "time" + + modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + store "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "github.com/haqq-network/haqq/x/dao/client/cli" + "github.com/haqq-network/haqq/x/dao/exported" + "github.com/haqq-network/haqq/x/dao/keeper" + "github.com/haqq-network/haqq/x/dao/types" +) + +// ConsensusVersion defines the current x/dao module consensus version. +const ConsensusVersion = 1 + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} +) + +// AppModuleBasic defines the basic application module used by the dao module. +type AppModuleBasic struct { + cdc codec.Codec +} + +// Name returns the dao module's name. +func (AppModuleBasic) Name() string { return types.ModuleName } + +// RegisterLegacyAminoCodec registers the dao module's types on the LegacyAmino codec. +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// DefaultGenesis returns default genesis state as raw bytes for the dao module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the dao module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return data.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the dao module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the root tx command for the dao module. +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.NewTxCmd() +} + +// GetQueryCmd returns no root query command for the dao module. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// RegisterInterfaces registers interfaces and implementations of the dao module. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// AppModule implements an application module for the dao module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + + // legacySubspace is used solely for migration of x/params managed parameters + legacySubspace exported.Subspace +} + +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// NewAppModule creates a new AppModule object +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ss exported.Subspace) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{cdc: cdc}, + keeper: keeper, + legacySubspace: ss, + } +} + +// Name returns the dao module's name. +func (AppModule) Name() string { return types.ModuleName } + +// RegisterInvariants registers the dao module invariants. +func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} + +// QuerierRoute returns the dao module's querier route name. +func (AppModule) QuerierRoute() string { return types.RouterKey } + +// InitGenesis performs genesis initialization for the dao module. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + start := time.Now() + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + telemetry.MeasureSince(start, "InitGenesis", "crisis", "unmarshal") + + am.keeper.InitGenesis(ctx, &genesisState) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the exported genesis state as raw bytes for the dao module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the dao module. +func (AppModule) GenerateGenesisState(_ *module.SimulationState) {} + +// RegisterStoreDecoder registers a decoder for supply module's types +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return []simtypes.WeightedOperation{} +} + +// App Wiring Setup + +func init() { + appmodule.Register(&modulev1.Module{}, + appmodule.Provide(ProvideModule), + ) +} + +type DaoInputs struct { + depinject.In + + Config *modulev1.Module + Cdc codec.Codec + Key *store.KVStoreKey + + AccountKeeper types.AccountKeeper + BankKeeper types.BankKeeper + + // LegacySubspace is used solely for migration of x/params managed parameters + LegacySubspace exported.Subspace `optional:"true"` +} + +type DaoOutputs struct { + depinject.Out + + DaoKeeper keeper.BaseKeeper + Module appmodule.AppModule +} + +func ProvideModule(in DaoInputs) DaoOutputs { + // default to governance authority if not provided + authority := authtypes.NewModuleAddress(govtypes.ModuleName) + if in.Config.Authority != "" { + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + } + + daoKeeper := keeper.NewBaseKeeper( + in.Cdc, + in.Key, + in.AccountKeeper, + in.BankKeeper, + authority.String(), + ) + m := NewAppModule(in.Cdc, daoKeeper, in.LegacySubspace) + + return DaoOutputs{DaoKeeper: daoKeeper, Module: m} +} diff --git a/x/dao/spec/README.md b/x/dao/spec/README.md new file mode 100644 index 00000000..5424f211 --- /dev/null +++ b/x/dao/spec/README.md @@ -0,0 +1,21 @@ + + +## Abstract + +This document specifies the internal `x/dao` module of the Haqq Network. + +With the `x/dao` users on Haqq Network can make their ISLM locked in vesting liquid. + +## Contents + +1. **[Concepts](01_concepts.md)** +2. **[State](02_state.md)** +3. **[State Transitions](03_state_transitions.md)** +4. **[Transactions](04_transactions.md)** +5. **[Parameters](05_parameters.md)** +6. **[Clients](06_clients.md)** \ No newline at end of file diff --git a/x/dao/types/balance.go b/x/dao/types/balance.go new file mode 100644 index 00000000..eba50741 --- /dev/null +++ b/x/dao/types/balance.go @@ -0,0 +1,92 @@ +package types + +import ( + "bytes" + "encoding/json" + "sort" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/haqq-network/haqq/x/dao/exported" +) + +var _ exported.GenesisBalance = (*Balance)(nil) + +// GetAddress returns the account address of the Balance object. +func (b Balance) GetAddress() sdk.AccAddress { + return sdk.MustAccAddressFromBech32(b.Address) +} + +// GetCoins returns the account coins of the Balance object. +func (b Balance) GetCoins() sdk.Coins { + return b.Coins +} + +// Validate checks for address and coins correctness. +func (b Balance) Validate() error { + if _, err := sdk.AccAddressFromBech32(b.Address); err != nil { + return err + } + + if err := b.Coins.Validate(); err != nil { + return err + } + + return nil +} + +type balanceByAddress struct { + addresses []sdk.AccAddress + balances []Balance +} + +func (b balanceByAddress) Len() int { return len(b.addresses) } +func (b balanceByAddress) Less(i, j int) bool { + return bytes.Compare(b.addresses[i], b.addresses[j]) < 0 +} + +func (b balanceByAddress) Swap(i, j int) { + b.addresses[i], b.addresses[j] = b.addresses[j], b.addresses[i] + b.balances[i], b.balances[j] = b.balances[j], b.balances[i] +} + +// SanitizeGenesisBalances sorts addresses and coin sets. +func SanitizeGenesisBalances(balances []Balance) []Balance { + // Given that this function sorts balances, using the standard library's + // Quicksort based algorithms, we have algorithmic complexities of: + // * Best case: O(nlogn) + // * Worst case: O(n^2) + // The comparator used MUST be cheap to use lest we incur expenses like we had + // before whereby sdk.AccAddressFromBech32, which is a very expensive operation + // compared n * n elements yet discarded computations each time, as per: + // https://github.com/cosmos/cosmos-sdk/issues/7766#issuecomment-786671734 + + // 1. Retrieve the address equivalents for each Balance's address. + addresses := make([]sdk.AccAddress, len(balances)) + for i := range balances { + addr, _ := sdk.AccAddressFromBech32(balances[i].Address) + addresses[i] = addr + } + + // 2. Sort balances. + sort.Sort(balanceByAddress{addresses: addresses, balances: balances}) + + return balances +} + +// GenesisBalancesIterator implements genesis account iteration. +type GenesisBalancesIterator struct{} + +// IterateGenesisBalances iterates over all the genesis balances found in +// appGenesis and invokes a callback on each genesis account. If any call +// returns true, iteration stops. +func (GenesisBalancesIterator) IterateGenesisBalances( + cdc codec.JSONCodec, appState map[string]json.RawMessage, cb func(exported.GenesisBalance) (stop bool), +) { + for _, balance := range GetGenesisStateFromAppState(cdc, appState).Balances { + if cb(balance) { + break + } + } +} diff --git a/x/dao/types/codec.go b/x/dao/types/codec.go new file mode 100644 index 00000000..4bea78e0 --- /dev/null +++ b/x/dao/types/codec.go @@ -0,0 +1,44 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + + cryptocodec "github.com/haqq-network/haqq/crypto/codec" +) + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the dao module. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgFund{}, "haqq/dao/MsgFund") + + cdc.RegisterConcrete(Params{}, "haqq/x/dao/Params", nil) +} + +// RegisterInterfaces registers the interfaces types with the Interface Registry. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgFund{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz and dao Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances + RegisterLegacyAminoCodec(authzcodec.Amino) +} diff --git a/x/dao/types/dao.pb.go b/x/dao/types/dao.pb.go new file mode 100644 index 00000000..2399816b --- /dev/null +++ b/x/dao/types/dao.pb.go @@ -0,0 +1,623 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: haqq/dao/v1/dao.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/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 + +// CollateralValueType defines the type of collateral value. +type CollateralValueType int32 + +const ( + // COLLATERAL_VALUE_TYPE_UNSPECIFIED is the unspecified collateral value type. + CollateralValueType_COLLATERAL_VALUE_TYPE_UNSPECIFIED CollateralValueType = 0 + // COLLATERAL_VALUE_TYPE_STRICT is the strict collateral value type. + CollateralValueType_COLLATERAL_VALUE_TYPE_STRICT CollateralValueType = 1 + // COLLATERAL_VALUE_TYPE_MASK is the mask collateral value type. + CollateralValueType_COLLATERAL_VALUE_TYPE_MASK CollateralValueType = 2 +) + +var CollateralValueType_name = map[int32]string{ + 0: "COLLATERAL_VALUE_TYPE_UNSPECIFIED", + 1: "COLLATERAL_VALUE_TYPE_STRICT", + 2: "COLLATERAL_VALUE_TYPE_MASK", +} + +var CollateralValueType_value = map[string]int32{ + "COLLATERAL_VALUE_TYPE_UNSPECIFIED": 0, + "COLLATERAL_VALUE_TYPE_STRICT": 1, + "COLLATERAL_VALUE_TYPE_MASK": 2, +} + +func (x CollateralValueType) String() string { + return proto.EnumName(CollateralValueType_name, int32(x)) +} + +func (CollateralValueType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_c994d20d8e0ea63f, []int{0} +} + +// Params defines the parameters for the dao module. +type Params struct { + // enable_dao is the parameter to enable the module functionality. + EnableDao bool `protobuf:"varint,1,opt,name=enable_dao,json=enableDao,proto3" json:"enable_dao,omitempty"` + // allowed_collaterals is the allowed collateral values. + AllowedCollaterals []*AllowedCollateral `protobuf:"bytes,2,rep,name=allowed_collaterals,json=allowedCollaterals,proto3" json:"allowed_collaterals,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_c994d20d8e0ea63f, []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) GetEnableDao() bool { + if m != nil { + return m.EnableDao + } + return false +} + +func (m *Params) GetAllowedCollaterals() []*AllowedCollateral { + if m != nil { + return m.AllowedCollaterals + } + return nil +} + +type AllowedCollateral struct { + // value is the allowed collateral value. + Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + // type is the allowed collateral value type. + Type CollateralValueType `protobuf:"varint,2,opt,name=type,proto3,enum=haqq.dao.v1.CollateralValueType" json:"type,omitempty"` +} + +func (m *AllowedCollateral) Reset() { *m = AllowedCollateral{} } +func (*AllowedCollateral) ProtoMessage() {} +func (*AllowedCollateral) Descriptor() ([]byte, []int) { + return fileDescriptor_c994d20d8e0ea63f, []int{1} +} +func (m *AllowedCollateral) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AllowedCollateral) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AllowedCollateral.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 *AllowedCollateral) XXX_Merge(src proto.Message) { + xxx_messageInfo_AllowedCollateral.Merge(m, src) +} +func (m *AllowedCollateral) XXX_Size() int { + return m.Size() +} +func (m *AllowedCollateral) XXX_DiscardUnknown() { + xxx_messageInfo_AllowedCollateral.DiscardUnknown(m) +} + +var xxx_messageInfo_AllowedCollateral proto.InternalMessageInfo + +func (m *AllowedCollateral) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +func (m *AllowedCollateral) GetType() CollateralValueType { + if m != nil { + return m.Type + } + return CollateralValueType_COLLATERAL_VALUE_TYPE_UNSPECIFIED +} + +func init() { + proto.RegisterEnum("haqq.dao.v1.CollateralValueType", CollateralValueType_name, CollateralValueType_value) + proto.RegisterType((*Params)(nil), "haqq.dao.v1.Params") + proto.RegisterType((*AllowedCollateral)(nil), "haqq.dao.v1.AllowedCollateral") +} + +func init() { proto.RegisterFile("haqq/dao/v1/dao.proto", fileDescriptor_c994d20d8e0ea63f) } + +var fileDescriptor_c994d20d8e0ea63f = []byte{ + // 379 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0x48, 0x2c, 0x2c, + 0xd4, 0x4f, 0x49, 0xcc, 0xd7, 0x2f, 0x33, 0x04, 0x51, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, + 0xdc, 0x20, 0x61, 0x3d, 0x10, 0xbf, 0xcc, 0x50, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0x2c, 0xae, + 0x0f, 0x62, 0x41, 0x94, 0x48, 0x09, 0x26, 0xe6, 0x66, 0xe6, 0xe5, 0xeb, 0x83, 0x49, 0x88, 0x90, + 0xd2, 0x14, 0x46, 0x2e, 0xb6, 0x80, 0xc4, 0xa2, 0xc4, 0xdc, 0x62, 0x21, 0x59, 0x2e, 0xae, 0xd4, + 0xbc, 0xc4, 0xa4, 0x9c, 0xd4, 0xf8, 0x94, 0xc4, 0x7c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x8e, 0x20, + 0x4e, 0x88, 0x88, 0x4b, 0x62, 0xbe, 0x90, 0x3f, 0x97, 0x70, 0x62, 0x4e, 0x4e, 0x7e, 0x79, 0x6a, + 0x4a, 0x7c, 0x72, 0x7e, 0x4e, 0x4e, 0x62, 0x49, 0x6a, 0x51, 0x62, 0x4e, 0xb1, 0x04, 0x93, 0x02, + 0xb3, 0x06, 0xb7, 0x91, 0x9c, 0x1e, 0x92, 0xed, 0x7a, 0x8e, 0x10, 0x75, 0xce, 0x70, 0x65, 0x41, + 0x42, 0x89, 0xe8, 0x42, 0xc5, 0x56, 0x52, 0x33, 0x16, 0xc8, 0x33, 0x74, 0x3d, 0xdf, 0xa0, 0x25, + 0x08, 0xf6, 0x50, 0x05, 0xd8, 0x4b, 0x10, 0xb7, 0x28, 0xb5, 0x31, 0x72, 0x09, 0x62, 0x98, 0x22, + 0x24, 0xc2, 0xc5, 0x5a, 0x96, 0x98, 0x53, 0x9a, 0x0a, 0x76, 0x1c, 0x67, 0x10, 0x84, 0x23, 0x64, + 0xc2, 0xc5, 0x52, 0x52, 0x59, 0x90, 0x2a, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x67, 0xa4, 0x80, 0xe2, + 0x12, 0x84, 0xe6, 0x30, 0x90, 0xda, 0x90, 0xca, 0x82, 0xd4, 0x20, 0xb0, 0x6a, 0x2b, 0x55, 0x98, + 0xed, 0x32, 0x48, 0xb6, 0x63, 0x58, 0xa9, 0x55, 0xc7, 0x25, 0x8c, 0xc5, 0x0c, 0x21, 0x55, 0x2e, + 0x45, 0x67, 0x7f, 0x1f, 0x1f, 0xc7, 0x10, 0xd7, 0x20, 0x47, 0x9f, 0xf8, 0x30, 0x47, 0x9f, 0x50, + 0xd7, 0xf8, 0x90, 0xc8, 0x00, 0xd7, 0xf8, 0x50, 0xbf, 0xe0, 0x00, 0x57, 0x67, 0x4f, 0x37, 0x4f, + 0x57, 0x17, 0x01, 0x06, 0x21, 0x05, 0x2e, 0x19, 0xec, 0xca, 0x82, 0x43, 0x82, 0x3c, 0x9d, 0x43, + 0x04, 0x18, 0x85, 0xe4, 0xb8, 0xa4, 0xb0, 0xab, 0xf0, 0x75, 0x0c, 0xf6, 0x16, 0x60, 0x72, 0x72, + 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, + 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x8d, 0xf4, 0xcc, 0x92, 0x8c, + 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x90, 0x17, 0x74, 0xf3, 0x52, 0x4b, 0xca, 0xf3, 0x8b, + 0xb2, 0xf5, 0x91, 0xfc, 0x03, 0xf2, 0x69, 0x71, 0x12, 0x1b, 0x38, 0xaa, 0x8d, 0x01, 0x01, 0x00, + 0x00, 0xff, 0xff, 0xe7, 0x56, 0xd1, 0x3e, 0x39, 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 + if len(m.AllowedCollaterals) > 0 { + for iNdEx := len(m.AllowedCollaterals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AllowedCollaterals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDao(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.EnableDao { + i-- + if m.EnableDao { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *AllowedCollateral) 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 *AllowedCollateral) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AllowedCollateral) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Type != 0 { + i = encodeVarintDao(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x10 + } + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintDao(dAtA, i, uint64(len(m.Value))) + 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 *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EnableDao { + n += 2 + } + if len(m.AllowedCollaterals) > 0 { + for _, e := range m.AllowedCollaterals { + l = e.Size() + n += 1 + l + sovDao(uint64(l)) + } + } + return n +} + +func (m *AllowedCollateral) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Value) + if l > 0 { + n += 1 + l + sovDao(uint64(l)) + } + if m.Type != 0 { + n += 1 + sovDao(uint64(m.Type)) + } + 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 *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 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: 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 EnableDao", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDao + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.EnableDao = bool(v != 0) + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowedCollaterals", 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.AllowedCollaterals = append(m.AllowedCollaterals, &AllowedCollateral{}) + if err := m.AllowedCollaterals[len(m.AllowedCollaterals)-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 *AllowedCollateral) 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: AllowedCollateral: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AllowedCollateral: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", 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.Value = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDao + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= CollateralValueType(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 new file mode 100644 index 00000000..59311228 --- /dev/null +++ b/x/dao/types/errors.go @@ -0,0 +1,9 @@ +package types + +import sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + +var ( + ErrInvalidKey = sdkerrors.Register(ModuleName, 1, "invalid key") + ErrModuleDisabled = sdkerrors.Register(ModuleName, 2, "module is disabled") + ErrInvalidDenom = sdkerrors.Register(ModuleName, 3, "invalid denom") +) diff --git a/x/dao/types/expected_keepers.go b/x/dao/types/expected_keepers.go new file mode 100644 index 00000000..1483be20 --- /dev/null +++ b/x/dao/types/expected_keepers.go @@ -0,0 +1,42 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// AccountKeeper defines the account contract that must be fulfilled when +// creating a x/bank keeper. +type AccountKeeper interface { + NewAccount(sdk.Context, types.AccountI) types.AccountI + NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + GetAllAccounts(ctx sdk.Context) []types.AccountI + HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool + SetAccount(ctx sdk.Context, acc types.AccountI) + + IterateAccounts(ctx sdk.Context, process func(types.AccountI) bool) + + ValidatePermissions(macc types.ModuleAccountI) error + + GetModuleAddress(moduleName string) sdk.AccAddress + GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) + GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (types.ModuleAccountI, []string) + GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI + SetModuleAccount(ctx sdk.Context, macc types.ModuleAccountI) + GetModulePermissions() map[string]types.PermissionsForAddress +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + + SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + + BlockedAddr(addr sdk.AccAddress) bool +} diff --git a/x/dao/types/genesis.go b/x/dao/types/genesis.go new file mode 100644 index 00000000..20add460 --- /dev/null +++ b/x/dao/types/genesis.go @@ -0,0 +1,42 @@ +package types + +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Validate performs basic validation of supply genesis data returning an +// error for any failed validation criteria. +func (gs GenesisState) Validate() error { + // TODO Add custom validation logic + + return nil +} + +// NewGenesisState creates a new genesis state. +func NewGenesisState(params Params, balances []Balance, total sdk.Coins) *GenesisState { + return &GenesisState{ + Params: params, + Balances: balances, + TotalBalance: total, + } +} + +// DefaultGenesisState returns a default dao module genesis state. +func DefaultGenesisState() *GenesisState { + return NewGenesisState(DefaultParams(), []Balance{}, sdk.Coins{}) +} + +// GetGenesisStateFromAppState returns x/dao GenesisState given raw application +// genesis state. +func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.RawMessage) *GenesisState { + var genesisState GenesisState + + if appState[ModuleName] != nil { + cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) + } + + return &genesisState +} diff --git a/x/dao/types/genesis.pb.go b/x/dao/types/genesis.pb.go new file mode 100644 index 00000000..472a7be9 --- /dev/null +++ b/x/dao/types/genesis.pb.go @@ -0,0 +1,688 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: haqq/dao/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/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 gov module's genesis state. +type GenesisState struct { + // params defines all the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // balances is an array containing the balances of all the dao members' accounts. + Balances []Balance `protobuf:"bytes,2,rep,name=balances,proto3" json:"balances"` + // total_balance represents the total balance of the dao module. If it is left empty, then supply will be calculated based on the provided + // balances. Otherwise, it will be used to validate that the sum of the balances equals this amount. + TotalBalance github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=total_balance,json=totalBalance,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"total_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_11e6573181b615fb, []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) GetBalances() []Balance { + if m != nil { + return m.Balances + } + return nil +} + +func (m *GenesisState) GetTotalBalance() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.TotalBalance + } + return nil +} + +// Balance defines an account address and balance pair used in the bank module's +// genesis state. +type Balance struct { + // address is the address of the balance holder. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // coins defines the different coins this balance holds. + Coins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=coins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"coins"` +} + +func (m *Balance) Reset() { *m = Balance{} } +func (m *Balance) String() string { return proto.CompactTextString(m) } +func (*Balance) ProtoMessage() {} +func (*Balance) Descriptor() ([]byte, []int) { + return fileDescriptor_11e6573181b615fb, []int{1} +} +func (m *Balance) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Balance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Balance.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 *Balance) XXX_Merge(src proto.Message) { + xxx_messageInfo_Balance.Merge(m, src) +} +func (m *Balance) XXX_Size() int { + return m.Size() +} +func (m *Balance) XXX_DiscardUnknown() { + xxx_messageInfo_Balance.DiscardUnknown(m) +} + +var xxx_messageInfo_Balance proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "haqq.dao.v1.GenesisState") + proto.RegisterType((*Balance)(nil), "haqq.dao.v1.Balance") +} + +func init() { proto.RegisterFile("haqq/dao/v1/genesis.proto", fileDescriptor_11e6573181b615fb) } + +var fileDescriptor_11e6573181b615fb = []byte{ + // 404 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x51, 0xbd, 0x6e, 0xdb, 0x30, + 0x10, 0x16, 0x6b, 0xd4, 0x3f, 0xb4, 0x3b, 0x54, 0x75, 0x01, 0xd9, 0x83, 0x64, 0x78, 0x32, 0x0a, + 0x98, 0x84, 0x5c, 0xb4, 0x43, 0x3b, 0x55, 0x1d, 0xba, 0x16, 0xf6, 0xd6, 0xc5, 0xa0, 0x24, 0x56, + 0x16, 0x6c, 0x89, 0xb6, 0x48, 0xbb, 0xcd, 0x1b, 0x64, 0xcc, 0x23, 0x78, 0x0c, 0xb2, 0x24, 0x43, + 0x1e, 0xc2, 0xa3, 0x91, 0x29, 0x53, 0x12, 0xd8, 0x43, 0xf2, 0x0c, 0x99, 0x02, 0x91, 0x74, 0xa0, + 0xec, 0x59, 0xa4, 0xe3, 0x7d, 0xf7, 0x7d, 0xf7, 0xdd, 0x1d, 0x6c, 0x4d, 0xc8, 0x62, 0x81, 0x43, + 0xc2, 0xf0, 0xca, 0xc5, 0x11, 0x4d, 0x29, 0x8f, 0x39, 0x9a, 0x67, 0x4c, 0x30, 0xb3, 0x9e, 0x43, + 0x28, 0x24, 0x0c, 0xad, 0xdc, 0xb6, 0x1d, 0x30, 0x9e, 0x30, 0x8e, 0x7d, 0xc2, 0x29, 0x5e, 0xb9, + 0x3e, 0x15, 0xc4, 0xc5, 0x01, 0x8b, 0x53, 0x55, 0xdc, 0x6e, 0x46, 0x2c, 0x62, 0x32, 0xc4, 0x79, + 0xa4, 0xb3, 0x2d, 0xc5, 0x1a, 0x2b, 0x40, 0x3d, 0x34, 0xf4, 0x9e, 0x24, 0x71, 0xca, 0xb0, 0xfc, + 0xea, 0xd4, 0xc7, 0xa2, 0x97, 0xbc, 0xaf, 0x4c, 0x77, 0x1f, 0x01, 0x6c, 0xfc, 0x52, 0xce, 0x46, + 0x82, 0x08, 0x6a, 0x7e, 0x85, 0xe5, 0x39, 0xc9, 0x48, 0xc2, 0x2d, 0xd0, 0x01, 0xbd, 0xfa, 0xe0, + 0x03, 0x2a, 0x38, 0x45, 0xbf, 0x25, 0xe4, 0xd5, 0x36, 0x37, 0x8e, 0x71, 0x7a, 0x7f, 0xf1, 0x09, + 0x0c, 0x75, 0xb5, 0xf9, 0x1d, 0x56, 0x7d, 0x32, 0x23, 0x69, 0x40, 0xb9, 0xf5, 0xa6, 0x53, 0xea, + 0xd5, 0x07, 0xcd, 0x17, 0x4c, 0x4f, 0x81, 0x45, 0xea, 0x33, 0xc1, 0x5c, 0xc2, 0x77, 0x82, 0x09, + 0x32, 0x1b, 0xeb, 0x8c, 0x55, 0x92, 0x0a, 0x2d, 0xa4, 0xa7, 0xca, 0x17, 0x83, 0xf4, 0x62, 0xd0, + 0x4f, 0x16, 0xa7, 0xde, 0x97, 0x5c, 0xe6, 0xec, 0xd6, 0xe9, 0x45, 0xb1, 0x98, 0x2c, 0x7d, 0x14, + 0xb0, 0x44, 0xaf, 0x40, 0xff, 0xfa, 0x3c, 0x9c, 0x62, 0x71, 0x34, 0xa7, 0x5c, 0x12, 0xb8, 0x6a, + 0xd9, 0x90, 0x6d, 0xb4, 0x97, 0xee, 0x39, 0x80, 0x15, 0x1d, 0x9b, 0x03, 0x58, 0x21, 0x61, 0x98, + 0x51, 0xae, 0x06, 0xaf, 0x79, 0xd6, 0xd5, 0x65, 0xbf, 0xa9, 0xfb, 0xff, 0x50, 0xc8, 0x48, 0x64, + 0x71, 0x1a, 0x0d, 0x0f, 0x85, 0xe6, 0x5f, 0xf8, 0x36, 0xbf, 0xd2, 0x61, 0xe0, 0xd7, 0xb7, 0xab, + 0xe4, 0xbf, 0x55, 0x8f, 0xd7, 0x8e, 0xf1, 0xb0, 0x76, 0x0c, 0xcf, 0xdb, 0xec, 0x6c, 0xb0, 0xdd, + 0xd9, 0xe0, 0x6e, 0x67, 0x83, 0x93, 0xbd, 0x6d, 0x6c, 0xf7, 0xb6, 0x71, 0xbd, 0xb7, 0x8d, 0x3f, + 0x45, 0xe5, 0x7c, 0xef, 0xfd, 0x94, 0x8a, 0x7f, 0x2c, 0x9b, 0xca, 0x07, 0xfe, 0x2f, 0x2f, 0x2f, + 0xf5, 0xfd, 0xb2, 0xbc, 0xfc, 0xe7, 0xa7, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbd, 0x1b, 0xc6, 0xbb, + 0x9e, 0x02, 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.TotalBalance) > 0 { + for iNdEx := len(m.TotalBalance) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TotalBalance[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Balances) > 0 { + for iNdEx := len(m.Balances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Balances[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 (m *Balance) 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 *Balance) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Balance) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Coins) > 0 { + for iNdEx := len(m.Coins) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Coins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) + 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.Balances) > 0 { + for _, e := range m.Balances { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.TotalBalance) > 0 { + for _, e := range m.TotalBalance { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *Balance) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Coins) > 0 { + for _, e := range m.Coins { + 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 Balances", 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.Balances = append(m.Balances, Balance{}) + if err := m.Balances[len(m.Balances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalBalance", 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.TotalBalance = append(m.TotalBalance, types.Coin{}) + if err := m.TotalBalance[len(m.TotalBalance)-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 (m *Balance) 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: Balance: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Balance: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Coins", 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.Coins = append(m.Coins, types.Coin{}) + if err := m.Coins[len(m.Coins)-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/keys.go b/x/dao/types/keys.go new file mode 100644 index 00000000..dff384dd --- /dev/null +++ b/x/dao/types/keys.go @@ -0,0 +1,67 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/types/kv" +) + +const ( + // ModuleName is the module name constant used in many places + ModuleName = "dao" + + // StoreKey is the store key string for distribution + StoreKey = ModuleName + + // RouterKey is the message route for distribution + RouterKey = ModuleName +) + +var ( + TotalBalanceKey = []byte{0x00} // key for global dao state + + // BalancesPrefix is the prefix for the account balances store. We use a byte + // (instead of `[]byte("balances")` to save some disk space). + BalancesPrefix = []byte{0x01} + DenomAddressPrefix = []byte{0x02} + + ParamsKey = []byte{0x03} // key for dao module params +) + +// CreateAccountBalancesPrefix creates the prefix for an account's balances. +func CreateAccountBalancesPrefix(addr []byte) []byte { + return append(BalancesPrefix, address.MustLengthPrefix(addr)...) +} + +// CreateDenomAddressPrefix creates a prefix for a reverse index of denomination +// to account balance for that denomination. +func CreateDenomAddressPrefix(denom string) []byte { + // we add a "zero" byte at the end - null byte terminator, to allow prefix denom prefix + // scan. Setting it is not needed (key[last] = 0) - because this is the default. + key := make([]byte, len(DenomAddressPrefix)+len(denom)+1) + copy(key, DenomAddressPrefix) + copy(key[len(DenomAddressPrefix):], denom) + + return key +} + +// AddressAndDenomFromBalancesStore returns an account address and denom from a balances prefix +// store. The key must not contain the prefix BalancesPrefix as the prefix store +// iterator discards the actual prefix. +// +// If invalid key is passed, AddressAndDenomFromBalancesStore returns ErrInvalidKey. +func AddressAndDenomFromBalancesStore(key []byte) (sdk.AccAddress, string, error) { + if len(key) == 0 { + return nil, "", ErrInvalidKey + } + + kv.AssertKeyAtLeastLength(key, 1) + + addrBound := int(key[0]) + + if len(key)-1 < addrBound { + return nil, "", ErrInvalidKey + } + + return key[1 : addrBound+1], string(key[addrBound+1:]), nil +} diff --git a/x/dao/types/msg.go b/x/dao/types/msg.go new file mode 100644 index 00000000..5495e790 --- /dev/null +++ b/x/dao/types/msg.go @@ -0,0 +1,60 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + proto "github.com/cosmos/gogoproto/proto" +) + +const ( + TypeMsgFund = "fund_dao" +) + +// Verify interface at compile time +var ( + _ sdk.Msg = (*MsgFund)(nil) +) + +// NewMsgFund returns a new MsgFund with a sender and +// a funding amount. +func NewMsgFund(amount sdk.Coins, depositor sdk.AccAddress) *MsgFund { + return &MsgFund{ + Amount: amount, + Depositor: depositor.String(), + } +} + +// Route returns the MsgFundCommunityPool message route. +func (msg MsgFund) Route() string { return ModuleName } + +// Type returns the MsgFundCommunityPool message type. +func (msg MsgFund) Type() string { return TypeMsgFund } + +// GetSigners returns the signer addresses that are expected to sign the result +// of GetSignBytes. +func (msg MsgFund) GetSigners() []sdk.AccAddress { + depositor, _ := sdk.AccAddressFromBech32(msg.Depositor) + return []sdk.AccAddress{depositor} +} + +// GetSignBytes returns the raw bytes for a MsgFundCommunityPool message that +// the expected signer needs to sign. +func (msg MsgFund) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs basic MsgFundCommunityPool message validation. +func (msg MsgFund) ValidateBasic() error { + if !msg.Amount.IsValid() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String()) + } + if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid depositor address: %s", err) + } + return nil +} + +func (m *AllowedCollateral) String() string { + return proto.CompactTextString(m) +} diff --git a/x/dao/types/params.go b/x/dao/types/params.go new file mode 100644 index 00000000..69266d16 --- /dev/null +++ b/x/dao/types/params.go @@ -0,0 +1,33 @@ +package types + +import ( + "fmt" + + "sigs.k8s.io/yaml" +) + +// DefaultParams returns default distribution parameters +func DefaultParams() Params { + return Params{ + EnableDao: true, + } +} + +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +// ValidateBasic performs basic validation on distribution parameters. +func (p Params) ValidateBasic() error { + return validateBool(p.EnableDao) +} + +func validateBool(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} diff --git a/x/dao/types/querier.go b/x/dao/types/querier.go new file mode 100644 index 00000000..e7934f8d --- /dev/null +++ b/x/dao/types/querier.go @@ -0,0 +1,20 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" +) + +// NewQueryBalanceRequest creates a new instance of QueryBalanceRequest. +// +//nolint:interfacer +func NewQueryBalanceRequest(addr sdk.AccAddress, denom string) *QueryBalanceRequest { + return &QueryBalanceRequest{Address: addr.String(), Denom: denom} +} + +// NewQueryAllBalancesRequest creates a new instance of QueryAllBalancesRequest. +// +//nolint:interfacer +func NewQueryAllBalancesRequest(addr sdk.AccAddress, req *query.PageRequest) *QueryAllBalancesRequest { + return &QueryAllBalancesRequest{Address: addr.String(), Pagination: req} +} diff --git a/x/dao/types/query.pb.go b/x/dao/types/query.pb.go new file mode 100644 index 00000000..c10e0ed1 --- /dev/null +++ b/x/dao/types/query.pb.go @@ -0,0 +1,1970 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: haqq/dao/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/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 + +// QueryBalanceRequest is the request type for the Query/Balance RPC method. +type QueryBalanceRequest struct { + // address is the address to query balances for. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // denom is the coin denom to query balances for. + Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *QueryBalanceRequest) Reset() { *m = QueryBalanceRequest{} } +func (m *QueryBalanceRequest) String() string { return proto.CompactTextString(m) } +func (*QueryBalanceRequest) ProtoMessage() {} +func (*QueryBalanceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b3031ac23b74ba5, []int{0} +} +func (m *QueryBalanceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBalanceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBalanceRequest.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 *QueryBalanceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBalanceRequest.Merge(m, src) +} +func (m *QueryBalanceRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryBalanceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBalanceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBalanceRequest proto.InternalMessageInfo + +// QueryBalanceResponse is the response type for the Query/Balance RPC method. +type QueryBalanceResponse struct { + // balance is the balance of the coin. + Balance *types.Coin `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance,omitempty"` +} + +func (m *QueryBalanceResponse) Reset() { *m = QueryBalanceResponse{} } +func (m *QueryBalanceResponse) String() string { return proto.CompactTextString(m) } +func (*QueryBalanceResponse) ProtoMessage() {} +func (*QueryBalanceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9b3031ac23b74ba5, []int{1} +} +func (m *QueryBalanceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBalanceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBalanceResponse.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 *QueryBalanceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBalanceResponse.Merge(m, src) +} +func (m *QueryBalanceResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryBalanceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBalanceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBalanceResponse proto.InternalMessageInfo + +func (m *QueryBalanceResponse) GetBalance() *types.Coin { + if m != nil { + return m.Balance + } + return nil +} + +// QueryBalanceRequest is the request type for the Query/AllBalances RPC method. +type QueryAllBalancesRequest struct { + // address is the address to query balances for. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // pagination defines an optional pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBalancesRequest) Reset() { *m = QueryAllBalancesRequest{} } +func (m *QueryAllBalancesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllBalancesRequest) ProtoMessage() {} +func (*QueryAllBalancesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b3031ac23b74ba5, []int{2} +} +func (m *QueryAllBalancesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBalancesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBalancesRequest.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 *QueryAllBalancesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBalancesRequest.Merge(m, src) +} +func (m *QueryAllBalancesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBalancesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBalancesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBalancesRequest proto.InternalMessageInfo + +// QueryAllBalancesResponse is the response type for the Query/AllBalances RPC +// method. +type QueryAllBalancesResponse struct { + // balances is the balances of all the coins. + Balances github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=balances,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"balances"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllBalancesResponse) Reset() { *m = QueryAllBalancesResponse{} } +func (m *QueryAllBalancesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllBalancesResponse) ProtoMessage() {} +func (*QueryAllBalancesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9b3031ac23b74ba5, []int{3} +} +func (m *QueryAllBalancesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllBalancesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllBalancesResponse.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 *QueryAllBalancesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllBalancesResponse.Merge(m, src) +} +func (m *QueryAllBalancesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllBalancesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllBalancesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllBalancesResponse proto.InternalMessageInfo + +func (m *QueryAllBalancesResponse) GetBalances() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Balances + } + return nil +} + +func (m *QueryAllBalancesResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryTotalBalanceRequest is the request type for the Query/TotalBalance RPC +// method. +type QueryTotalBalanceRequest struct { + // pagination defines an optional pagination for the request. + // + // Since: cosmos-sdk 0.43 + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryTotalBalanceRequest) Reset() { *m = QueryTotalBalanceRequest{} } +func (m *QueryTotalBalanceRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTotalBalanceRequest) ProtoMessage() {} +func (*QueryTotalBalanceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9b3031ac23b74ba5, []int{4} +} +func (m *QueryTotalBalanceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalBalanceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalBalanceRequest.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 *QueryTotalBalanceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalBalanceRequest.Merge(m, src) +} +func (m *QueryTotalBalanceRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalBalanceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalBalanceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalBalanceRequest proto.InternalMessageInfo + +// QueryTotalBalanceResponse is the response type for the Query/TotalBalance RPC +// method +type QueryTotalBalanceResponse struct { + // supply is the supply of the coins + TotalBalance github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=total_balance,json=totalBalance,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"total_balance"` + // pagination defines the pagination in the response. + // + // Since: cosmos-sdk 0.43 + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryTotalBalanceResponse) Reset() { *m = QueryTotalBalanceResponse{} } +func (m *QueryTotalBalanceResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTotalBalanceResponse) ProtoMessage() {} +func (*QueryTotalBalanceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9b3031ac23b74ba5, []int{5} +} +func (m *QueryTotalBalanceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalBalanceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalBalanceResponse.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 *QueryTotalBalanceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalBalanceResponse.Merge(m, src) +} +func (m *QueryTotalBalanceResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalBalanceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalBalanceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalBalanceResponse proto.InternalMessageInfo + +func (m *QueryTotalBalanceResponse) GetTotalBalance() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.TotalBalance + } + return nil +} + +func (m *QueryTotalBalanceResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryParamsRequest defines the request type for querying x/dao parameters. +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_9b3031ac23b74ba5, []int{6} +} +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 defines the response type for querying x/dao parameters. +type QueryParamsResponse struct { + 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_9b3031ac23b74ba5, []int{7} +} +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 + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*QueryBalanceRequest)(nil), "haqq.dao.v1.QueryBalanceRequest") + proto.RegisterType((*QueryBalanceResponse)(nil), "haqq.dao.v1.QueryBalanceResponse") + proto.RegisterType((*QueryAllBalancesRequest)(nil), "haqq.dao.v1.QueryAllBalancesRequest") + proto.RegisterType((*QueryAllBalancesResponse)(nil), "haqq.dao.v1.QueryAllBalancesResponse") + proto.RegisterType((*QueryTotalBalanceRequest)(nil), "haqq.dao.v1.QueryTotalBalanceRequest") + proto.RegisterType((*QueryTotalBalanceResponse)(nil), "haqq.dao.v1.QueryTotalBalanceResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "haqq.dao.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "haqq.dao.v1.QueryParamsResponse") +} + +func init() { proto.RegisterFile("haqq/dao/v1/query.proto", fileDescriptor_9b3031ac23b74ba5) } + +var fileDescriptor_9b3031ac23b74ba5 = []byte{ + // 698 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4f, 0x4f, 0x13, 0x4f, + 0x18, 0xee, 0xf0, 0xfb, 0xf1, 0x6f, 0x8a, 0x07, 0x87, 0x12, 0xca, 0x4a, 0xb6, 0xa5, 0x51, 0x20, + 0x44, 0x76, 0xd2, 0x12, 0x3c, 0x78, 0xa3, 0x26, 0x7a, 0x30, 0x26, 0x58, 0x3d, 0x79, 0x21, 0xd3, + 0x76, 0xb2, 0x6c, 0xd8, 0xdd, 0xd9, 0xee, 0x4c, 0x51, 0x62, 0xbc, 0x98, 0x68, 0x38, 0x1a, 0xfd, + 0x00, 0x72, 0x34, 0x9e, 0x3c, 0xf8, 0x21, 0x38, 0xa2, 0x5e, 0x4c, 0x4c, 0xd4, 0x80, 0x89, 0x7e, + 0x0c, 0xb3, 0x33, 0xb3, 0x76, 0xd6, 0x56, 0x7a, 0x10, 0x2f, 0xb0, 0xfb, 0xce, 0xfb, 0xbe, 0xcf, + 0xf3, 0xbc, 0xfb, 0xbc, 0x53, 0x38, 0xbb, 0x4d, 0x3a, 0x1d, 0xdc, 0x26, 0x0c, 0xef, 0x56, 0x71, + 0xa7, 0x4b, 0xe3, 0x3d, 0x27, 0x8a, 0x99, 0x60, 0x28, 0x9f, 0x1c, 0x38, 0x6d, 0xc2, 0x9c, 0xdd, + 0xaa, 0xb5, 0xd2, 0x62, 0x3c, 0x60, 0x1c, 0x37, 0x09, 0xa7, 0x2a, 0x0b, 0xef, 0x56, 0x9b, 0x54, + 0x90, 0x2a, 0x8e, 0x88, 0xeb, 0x85, 0x44, 0x78, 0x2c, 0x54, 0x85, 0x56, 0xc1, 0x65, 0x2e, 0x93, + 0x8f, 0x38, 0x79, 0xd2, 0xd1, 0x79, 0x97, 0x31, 0xd7, 0xa7, 0x98, 0x44, 0x1e, 0x26, 0x61, 0xc8, + 0x84, 0x2c, 0xe1, 0xfa, 0xd4, 0x36, 0xfb, 0xa7, 0x9d, 0x5b, 0xcc, 0x4b, 0x7b, 0xce, 0xa9, 0xf3, + 0x2d, 0xd5, 0x56, 0xbd, 0xe8, 0xa3, 0x0b, 0xba, 0x34, 0x65, 0x65, 0x8a, 0xb0, 0xce, 0x93, 0xc0, + 0x0b, 0x19, 0x96, 0x7f, 0x75, 0x68, 0xc6, 0x14, 0x9c, 0xc8, 0x93, 0xe1, 0x8a, 0x07, 0xa7, 0x6f, + 0x27, 0x85, 0x75, 0xe2, 0x93, 0xb0, 0x45, 0x1b, 0xb4, 0xd3, 0xa5, 0x5c, 0xa0, 0x1a, 0x1c, 0x27, + 0xed, 0x76, 0x4c, 0x39, 0x2f, 0x82, 0x32, 0x58, 0x9e, 0xac, 0x17, 0xdf, 0xbf, 0x5d, 0x2d, 0x68, + 0x02, 0x1b, 0xea, 0xe4, 0x8e, 0x88, 0xbd, 0xd0, 0x6d, 0xa4, 0x89, 0xa8, 0x00, 0x47, 0xdb, 0x34, + 0x64, 0x41, 0x71, 0x24, 0xa9, 0x68, 0xa8, 0x97, 0xab, 0x13, 0xfb, 0x07, 0xa5, 0xdc, 0x8f, 0x83, + 0x52, 0xae, 0x72, 0x13, 0x16, 0xb2, 0x50, 0x3c, 0x62, 0x21, 0xa7, 0x68, 0x0d, 0x8e, 0x37, 0x55, + 0x48, 0x62, 0xe5, 0x6b, 0x73, 0x8e, 0x06, 0x4a, 0xc6, 0xe2, 0xe8, 0xb1, 0x38, 0xd7, 0x98, 0x17, + 0x36, 0xd2, 0xcc, 0xca, 0x4b, 0x00, 0x67, 0x65, 0xb7, 0x0d, 0xdf, 0xd7, 0x0d, 0xf9, 0xdf, 0x90, + 0xbf, 0x0e, 0x61, 0xef, 0x8b, 0x4a, 0x05, 0xf9, 0xda, 0x62, 0x86, 0x87, 0x9a, 0x6f, 0xca, 0x66, + 0x93, 0xb8, 0xe9, 0xb0, 0x1a, 0x46, 0xa5, 0x21, 0xf7, 0x1d, 0x80, 0xc5, 0x7e, 0x86, 0x5a, 0xb3, + 0x0f, 0x27, 0xb4, 0x92, 0x84, 0xe3, 0x7f, 0xa7, 0x8a, 0xae, 0xaf, 0x1f, 0x7e, 0x2e, 0xe5, 0x5e, + 0x7f, 0x29, 0x2d, 0xbb, 0x9e, 0xd8, 0xee, 0x36, 0x9d, 0x16, 0x0b, 0xb4, 0x17, 0xf4, 0xbf, 0x55, + 0xde, 0xde, 0xc1, 0x62, 0x2f, 0xa2, 0x5c, 0x16, 0xf0, 0x57, 0xdf, 0xdf, 0xac, 0x80, 0xc6, 0x2f, + 0x04, 0x74, 0x63, 0x80, 0xb8, 0xa5, 0xa1, 0xe2, 0x14, 0x55, 0x53, 0x5d, 0xc5, 0xd7, 0x92, 0xee, + 0x32, 0x41, 0xfc, 0xdf, 0x2c, 0x93, 0x9d, 0x20, 0x38, 0x83, 0x09, 0x7e, 0x02, 0x70, 0x6e, 0x00, + 0x9c, 0x1e, 0x61, 0x17, 0x9e, 0x13, 0x49, 0x7c, 0xab, 0x67, 0x9e, 0x7f, 0x33, 0xc7, 0x29, 0x61, + 0xc0, 0x9f, 0xdd, 0x2c, 0x0b, 0x10, 0x49, 0x71, 0x9b, 0x24, 0x26, 0x41, 0xea, 0xdd, 0xca, 0x2d, + 0xbd, 0x8f, 0x69, 0x54, 0x8b, 0xbd, 0x02, 0xc7, 0x22, 0x19, 0xd1, 0x83, 0x9d, 0x76, 0x8c, 0x6b, + 0xca, 0x51, 0xc9, 0xf5, 0xc9, 0x44, 0x9f, 0xe2, 0xac, 0xb3, 0x6b, 0xcf, 0xff, 0x87, 0xa3, 0xb2, + 0x1f, 0x7a, 0x02, 0xe0, 0x78, 0xaa, 0xa1, 0x9c, 0xa9, 0x1e, 0xb0, 0xff, 0xd6, 0xc2, 0x29, 0x19, + 0x8a, 0x52, 0x65, 0x7d, 0x3f, 0x41, 0x7a, 0xfc, 0xe1, 0xdb, 0x8b, 0x91, 0x15, 0xb4, 0x8c, 0xcd, + 0xeb, 0x25, 0x35, 0x1e, 0x7e, 0xa8, 0xd7, 0xeb, 0x11, 0x6e, 0xee, 0x6d, 0xc9, 0xfb, 0x00, 0xed, + 0x03, 0x98, 0x37, 0x36, 0x02, 0x5d, 0xec, 0x47, 0xea, 0x5f, 0x69, 0xeb, 0xd2, 0x90, 0x2c, 0xcd, + 0xe9, 0x72, 0x8f, 0xd3, 0x02, 0x2a, 0x0d, 0xe1, 0x84, 0x9e, 0x02, 0x38, 0x65, 0x5a, 0x0b, 0x0d, + 0x40, 0x19, 0xe0, 0x74, 0x6b, 0x71, 0x58, 0x9a, 0x66, 0xb3, 0xd4, 0x63, 0x33, 0x8f, 0xac, 0x0c, + 0x9b, 0x8c, 0x73, 0x51, 0x00, 0xc7, 0xd4, 0x27, 0x44, 0xa5, 0xfe, 0xd6, 0x19, 0x7f, 0x58, 0xe5, + 0x3f, 0x27, 0x68, 0xd4, 0x72, 0x0f, 0x75, 0x06, 0x4d, 0x67, 0x50, 0x95, 0x29, 0xea, 0xf5, 0xc3, + 0x63, 0x1b, 0x1c, 0x1d, 0xdb, 0xe0, 0xeb, 0xb1, 0x0d, 0x9e, 0x9d, 0xd8, 0xb9, 0xa3, 0x13, 0x3b, + 0xf7, 0xf1, 0xc4, 0xce, 0xdd, 0x33, 0x37, 0x23, 0x29, 0x5c, 0x0d, 0xa9, 0xb8, 0xcf, 0xe2, 0x1d, + 0xd5, 0xe5, 0x81, 0xec, 0x23, 0xf7, 0xa3, 0x39, 0x26, 0x7f, 0x3e, 0xd6, 0x7e, 0x06, 0x00, 0x00, + 0xff, 0xff, 0x48, 0xb5, 0xa0, 0x29, 0x48, 0x07, 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 { + // Balance queries the balance of a single coin for a single account. + Balance(ctx context.Context, in *QueryBalanceRequest, opts ...grpc.CallOption) (*QueryBalanceResponse, error) + // AllBalances queries the balance of all coins for a single account. + // + // When called from another module, this query might consume a high amount of + // gas if the pagination field is incorrectly set. + AllBalances(ctx context.Context, in *QueryAllBalancesRequest, opts ...grpc.CallOption) (*QueryAllBalancesResponse, error) + // TotalBalance queries the total balance of all coins locked in the module. + // + // When called from another module, this query might consume a high amount of + // gas if the pagination field is incorrectly set. + TotalBalance(ctx context.Context, in *QueryTotalBalanceRequest, opts ...grpc.CallOption) (*QueryTotalBalanceResponse, error) + // Params queries the parameters of x/dao module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Balance(ctx context.Context, in *QueryBalanceRequest, opts ...grpc.CallOption) (*QueryBalanceResponse, error) { + out := new(QueryBalanceResponse) + err := c.cc.Invoke(ctx, "/haqq.dao.v1.Query/Balance", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AllBalances(ctx context.Context, in *QueryAllBalancesRequest, opts ...grpc.CallOption) (*QueryAllBalancesResponse, error) { + out := new(QueryAllBalancesResponse) + err := c.cc.Invoke(ctx, "/haqq.dao.v1.Query/AllBalances", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) TotalBalance(ctx context.Context, in *QueryTotalBalanceRequest, opts ...grpc.CallOption) (*QueryTotalBalanceResponse, error) { + out := new(QueryTotalBalanceResponse) + err := c.cc.Invoke(ctx, "/haqq.dao.v1.Query/TotalBalance", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/haqq.dao.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Balance queries the balance of a single coin for a single account. + Balance(context.Context, *QueryBalanceRequest) (*QueryBalanceResponse, error) + // AllBalances queries the balance of all coins for a single account. + // + // When called from another module, this query might consume a high amount of + // gas if the pagination field is incorrectly set. + AllBalances(context.Context, *QueryAllBalancesRequest) (*QueryAllBalancesResponse, error) + // TotalBalance queries the total balance of all coins locked in the module. + // + // When called from another module, this query might consume a high amount of + // gas if the pagination field is incorrectly set. + TotalBalance(context.Context, *QueryTotalBalanceRequest) (*QueryTotalBalanceResponse, error) + // Params queries the parameters of x/dao module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Balance(ctx context.Context, req *QueryBalanceRequest) (*QueryBalanceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Balance not implemented") +} +func (*UnimplementedQueryServer) AllBalances(ctx context.Context, req *QueryAllBalancesRequest) (*QueryAllBalancesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AllBalances not implemented") +} +func (*UnimplementedQueryServer) TotalBalance(ctx context.Context, req *QueryTotalBalanceRequest) (*QueryTotalBalanceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TotalBalance not implemented") +} +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Balance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryBalanceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Balance(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/haqq.dao.v1.Query/Balance", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Balance(ctx, req.(*QueryBalanceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AllBalances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllBalancesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AllBalances(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/haqq.dao.v1.Query/AllBalances", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AllBalances(ctx, req.(*QueryAllBalancesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_TotalBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTotalBalanceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TotalBalance(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/haqq.dao.v1.Query/TotalBalance", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TotalBalance(ctx, req.(*QueryTotalBalanceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +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: "/haqq.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) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "haqq.dao.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Balance", + Handler: _Query_Balance_Handler, + }, + { + MethodName: "AllBalances", + Handler: _Query_AllBalances_Handler, + }, + { + MethodName: "TotalBalance", + Handler: _Query_TotalBalance_Handler, + }, + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "haqq/dao/v1/query.proto", +} + +func (m *QueryBalanceRequest) 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 *QueryBalanceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBalanceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryBalanceResponse) 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 *QueryBalanceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBalanceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Balance != nil { + { + size, err := m.Balance.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 *QueryAllBalancesRequest) 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 *QueryAllBalancesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBalancesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllBalancesResponse) 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 *QueryAllBalancesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllBalancesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Balances) > 0 { + for iNdEx := len(m.Balances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Balances[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 (m *QueryTotalBalanceRequest) 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 *QueryTotalBalanceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalBalanceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.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 *QueryTotalBalanceResponse) 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 *QueryTotalBalanceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalBalanceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.TotalBalance) > 0 { + for iNdEx := len(m.TotalBalance) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TotalBalance[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 (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 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 *QueryBalanceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryBalanceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Balance != nil { + l = m.Balance.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllBalancesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllBalancesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Balances) > 0 { + for _, e := range m.Balances { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTotalBalanceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTotalBalanceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.TotalBalance) > 0 { + for _, e := range m.TotalBalance { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +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 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 *QueryBalanceRequest) 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: QueryBalanceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBalanceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + 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 *QueryBalanceResponse) 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: QueryBalanceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBalanceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", 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 m.Balance == nil { + m.Balance = &types.Coin{} + } + if err := m.Balance.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 *QueryAllBalancesRequest) 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: QueryAllBalancesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBalancesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.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 *QueryAllBalancesResponse) 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: QueryAllBalancesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllBalancesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balances", 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.Balances = append(m.Balances, types.Coin{}) + if err := m.Balances[len(m.Balances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.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 *QueryTotalBalanceRequest) 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: QueryTotalBalanceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalBalanceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.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 *QueryTotalBalanceResponse) 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: QueryTotalBalanceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalBalanceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalBalance", 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.TotalBalance = append(m.TotalBalance, types.Coin{}) + if err := m.TotalBalance[len(m.TotalBalance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", 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 m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.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 *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 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 new file mode 100644 index 00000000..e3e0cfcd --- /dev/null +++ b/x/dao/types/query.pb.gw.go @@ -0,0 +1,474 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: haqq/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/metadata" + "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 +var _ = metadata.Join + +var ( + filter_Query_Balance_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_Balance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBalanceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Balance_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Balance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Balance_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBalanceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Balance_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Balance(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_AllBalances_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + +func request_Query_AllBalances_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBalancesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllBalances_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AllBalances(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AllBalances_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllBalancesRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllBalances_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AllBalances(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_TotalBalance_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_TotalBalance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalBalanceRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TotalBalance_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.TotalBalance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TotalBalance_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalBalanceRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TotalBalance_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.TotalBalance(ctx, &protoReq) + return msg, metadata, err + +} + +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 + +} + +// 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 to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Balance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + 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_Balance_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Balance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AllBalances_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + 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_AllBalances_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AllBalances_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + 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_TotalBalance_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TotalBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + 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() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + 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) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + 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()...) + + }) + + 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_Balance_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_Balance_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_Balance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AllBalances_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_AllBalances_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_AllBalances_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalBalance_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_TotalBalance_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_TotalBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + 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()...) + + }) + + return nil +} + +var ( + pattern_Query_Balance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"haqq", "dao", "v1", "balances", "address", "by_denom"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AllBalances_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"haqq", "dao", "v1", "balances", "address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_TotalBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqq", "dao", "v1", "total_balance"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqq", "dao", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Balance_0 = runtime.ForwardResponseMessage + + forward_Query_AllBalances_0 = runtime.ForwardResponseMessage + + forward_Query_TotalBalance_0 = runtime.ForwardResponseMessage + + forward_Query_Params_0 = runtime.ForwardResponseMessage +) diff --git a/x/dao/types/tx.pb.go b/x/dao/types/tx.pb.go new file mode 100644 index 00000000..c8d0eefa --- /dev/null +++ b/x/dao/types/tx.pb.go @@ -0,0 +1,591 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: haqq/dao/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + 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 + +// MsgFund allows an account to directly fund the dao. +type MsgFund struct { + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` + Depositor string `protobuf:"bytes,2,opt,name=depositor,proto3" json:"depositor,omitempty"` +} + +func (m *MsgFund) Reset() { *m = MsgFund{} } +func (m *MsgFund) String() string { return proto.CompactTextString(m) } +func (*MsgFund) ProtoMessage() {} +func (*MsgFund) Descriptor() ([]byte, []int) { + return fileDescriptor_32cf174189eaa32b, []int{0} +} +func (m *MsgFund) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgFund) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgFund.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 *MsgFund) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgFund.Merge(m, src) +} +func (m *MsgFund) XXX_Size() int { + return m.Size() +} +func (m *MsgFund) XXX_DiscardUnknown() { + xxx_messageInfo_MsgFund.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgFund proto.InternalMessageInfo + +// MsgFundResponse defines the Msg/Fund response type. +type MsgFundResponse struct { +} + +func (m *MsgFundResponse) Reset() { *m = MsgFundResponse{} } +func (m *MsgFundResponse) String() string { return proto.CompactTextString(m) } +func (*MsgFundResponse) ProtoMessage() {} +func (*MsgFundResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_32cf174189eaa32b, []int{1} +} +func (m *MsgFundResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgFundResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgFundResponse.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 *MsgFundResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgFundResponse.Merge(m, src) +} +func (m *MsgFundResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgFundResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgFundResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgFundResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgFund)(nil), "haqq.dao.v1.MsgFund") + proto.RegisterType((*MsgFundResponse)(nil), "haqq.dao.v1.MsgFundResponse") +} + +func init() { proto.RegisterFile("haqq/dao/v1/tx.proto", fileDescriptor_32cf174189eaa32b) } + +var fileDescriptor_32cf174189eaa32b = []byte{ + // 391 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc9, 0x48, 0x2c, 0x2c, + 0xd4, 0x4f, 0x49, 0xcc, 0xd7, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0xe2, 0x06, 0x89, 0xea, 0xa5, 0x24, 0xe6, 0xeb, 0x95, 0x19, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, + 0xe7, 0x83, 0xc5, 0xf5, 0x41, 0x2c, 0x88, 0x12, 0x29, 0xb9, 0xe4, 0xfc, 0xe2, 0xdc, 0xfc, 0x62, + 0xfd, 0xa4, 0xc4, 0xe2, 0x54, 0xfd, 0x32, 0xc3, 0xa4, 0xd4, 0x92, 0x44, 0x43, 0xfd, 0xe4, 0xfc, + 0xcc, 0x3c, 0xa8, 0xbc, 0x24, 0x44, 0x3e, 0x1e, 0xa2, 0x11, 0xc2, 0x81, 0x4a, 0x89, 0x43, 0xb5, + 0xe6, 0x16, 0xa7, 0x83, 0x6c, 0xcd, 0x2d, 0x4e, 0x87, 0x4a, 0x08, 0x26, 0xe6, 0x66, 0xe6, 0xe5, + 0xeb, 0x83, 0x49, 0x88, 0x90, 0xd2, 0x0d, 0x46, 0x2e, 0x76, 0xdf, 0xe2, 0x74, 0xb7, 0xd2, 0xbc, + 0x14, 0xa1, 0x0c, 0x2e, 0xb6, 0xc4, 0xdc, 0xfc, 0xd2, 0xbc, 0x12, 0x09, 0x46, 0x05, 0x66, 0x0d, + 0x6e, 0x23, 0x49, 0x3d, 0xa8, 0xb1, 0x20, 0x37, 0xe8, 0x41, 0xdd, 0xa0, 0xe7, 0x9c, 0x9f, 0x99, + 0xe7, 0x64, 0x7a, 0xe2, 0x9e, 0x3c, 0xc3, 0xaa, 0xfb, 0xf2, 0x1a, 0xe9, 0x99, 0x25, 0x19, 0xa5, + 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0x50, 0x37, 0x40, 0x29, 0xdd, 0xe2, 0x94, 0x6c, 0xfd, 0x92, 0xca, + 0x82, 0xd4, 0x62, 0xb0, 0x86, 0xe2, 0x15, 0xcf, 0x37, 0x68, 0x31, 0x06, 0x41, 0xcd, 0x17, 0x32, + 0xe3, 0xe2, 0x4c, 0x49, 0x2d, 0xc8, 0x2f, 0xce, 0x2c, 0xc9, 0x2f, 0x92, 0x60, 0x52, 0x60, 0xd4, + 0xe0, 0x74, 0x92, 0xb8, 0xb4, 0x45, 0x57, 0x04, 0x6a, 0x9f, 0x63, 0x4a, 0x4a, 0x51, 0x6a, 0x71, + 0x71, 0x70, 0x49, 0x51, 0x66, 0x5e, 0x7a, 0x10, 0x42, 0xa9, 0x95, 0x76, 0xc7, 0x02, 0x79, 0x86, + 0x17, 0x0b, 0xe4, 0x19, 0x9a, 0x9e, 0x6f, 0xd0, 0x42, 0x88, 0x77, 0x3d, 0xdf, 0xa0, 0x25, 0x00, + 0x0f, 0x68, 0xa8, 0x77, 0x94, 0x04, 0xb9, 0xf8, 0xa1, 0xcc, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, + 0xe2, 0x54, 0x23, 0x0f, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0x21, 0x2b, 0x2e, 0x16, 0xb0, 0x87, 0x45, + 0xf4, 0x90, 0xe2, 0x41, 0x0f, 0xaa, 0x58, 0x4a, 0x06, 0x9b, 0x28, 0xcc, 0x08, 0x29, 0xd6, 0x06, + 0x90, 0x4f, 0x9c, 0x9c, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, + 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x0a, 0x39, + 0x48, 0x40, 0x06, 0xe9, 0xe6, 0xa5, 0x96, 0x94, 0xe7, 0x17, 0x65, 0x83, 0x39, 0xfa, 0x15, 0x60, + 0x27, 0x82, 0x03, 0x26, 0x89, 0x0d, 0x1c, 0x05, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x91, + 0xd4, 0x66, 0x8c, 0x24, 0x02, 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 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // Fund defines a method to allow an account to directly fund the dao. + Fund(ctx context.Context, in *MsgFund, opts ...grpc.CallOption) (*MsgFundResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Fund(ctx context.Context, in *MsgFund, opts ...grpc.CallOption) (*MsgFundResponse, error) { + out := new(MsgFundResponse) + err := c.cc.Invoke(ctx, "/haqq.dao.v1.Msg/Fund", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // Fund defines a method to allow an account to directly fund the dao. + Fund(context.Context, *MsgFund) (*MsgFundResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) Fund(ctx context.Context, req *MsgFund) (*MsgFundResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Fund not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_Fund_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgFund) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Fund(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/haqq.dao.v1.Msg/Fund", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Fund(ctx, req.(*MsgFund)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "haqq.dao.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Fund", + Handler: _Msg_Fund_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "haqq/dao/v1/tx.proto", +} + +func (m *MsgFund) 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 *MsgFund) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgFund) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Depositor) > 0 { + i -= len(m.Depositor) + copy(dAtA[i:], m.Depositor) + i = encodeVarintTx(dAtA, i, uint64(len(m.Depositor))) + i-- + dAtA[i] = 0x12 + } + 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *MsgFundResponse) 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 *MsgFundResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgFundResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgFund) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.Depositor) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgFundResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgFund) 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 ErrIntOverflowTx + } + 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: MsgFund: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgFund: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Depositor", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Depositor = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgFundResponse) 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 ErrIntOverflowTx + } + 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: MsgFundResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgFundResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/liquidvesting/keeper/msg_server.go b/x/liquidvesting/keeper/msg_server.go index ad469b3c..661d188a 100644 --- a/x/liquidvesting/keeper/msg_server.go +++ b/x/liquidvesting/keeper/msg_server.go @@ -138,7 +138,7 @@ func (k Keeper) Liquidate(goCtx context.Context, msg *types.MsgLiquidate) (*type } // bind newly created denom to erc20 token - _, err = k.erc20Keeper.RegisterCoin(ctx, liquidTokenMetadata) + tokenPair, err := k.erc20Keeper.RegisterCoin(ctx, liquidTokenMetadata) if err != nil { return nil, errorsmod.Wrapf(types.ErrLiquidationFailed, "failed to create erc20 token pair: %s", err.Error()) } @@ -162,7 +162,12 @@ func (k Keeper) Liquidate(goCtx context.Context, msg *types.MsgLiquidate) (*type }, ) - return &types.MsgLiquidateResponse{}, nil + responseMsg := &types.MsgLiquidateResponse{ + Minted: liquidTokenCoin, + ContractAddr: tokenPair.Erc20Address, + } + + return responseMsg, nil } // Redeem redeems specified amount of liquid token into original locked token and adds them to account diff --git a/x/liquidvesting/keeper/msg_server_test.go b/x/liquidvesting/keeper/msg_server_test.go index 21cb2d9e..7718a473 100644 --- a/x/liquidvesting/keeper/msg_server_test.go +++ b/x/liquidvesting/keeper/msg_server_test.go @@ -28,9 +28,9 @@ var ( liquidDenomAmount = sdk.NewCoins(sdk.NewInt64Coin("aLIQUID0", 3_000_000)) lockupPeriods = sdkvesting.Periods{ - {Length: 100, Amount: third}, - {Length: 100, Amount: third}, - {Length: 100, Amount: third}, + {Length: 100000, Amount: third}, + {Length: 100000, Amount: third}, + {Length: 100000, Amount: third}, } vestingPeriods = sdkvesting.Periods{ {Length: 0, Amount: amount}, @@ -63,6 +63,21 @@ func (suite *KeeperTestSuite) TestLiquidate() { amount: sdk.NewCoin("aISLM", third.AmountOf("aISLM")), expectPass: true, }, + { + name: "ok - standard liquidation two thirds", + malleate: func() { + funder := sdk.AccAddress(types.ModuleName) + baseAccount := authtypes.NewBaseAccountWithAddress(addr1) + startTime := suite.ctx.BlockTime().Add(-10 * time.Second) + clawbackAccount := vestingtypes.NewClawbackVestingAccount(baseAccount, funder, amount, startTime, lockupPeriods, vestingPeriods, nil) + testutil.FundAccount(s.ctx, s.app.BankKeeper, addr1, amount) //nolint:errcheck + s.app.AccountKeeper.SetAccount(s.ctx, clawbackAccount) + }, + from: addr1, + to: addr2, + amount: sdk.NewCoin("aISLM", third.AmountOf("aISLM")).Add(sdk.NewCoin("aISLM", third.AmountOf("aISLM"))), + expectPass: true, + }, { name: "ok - block time matches end of current period", malleate: func() { @@ -146,7 +161,7 @@ func (suite *KeeperTestSuite) TestLiquidate() { malleate: func() { funder := sdk.AccAddress(types.ModuleName) baseAccount := authtypes.NewBaseAccountWithAddress(addr1) - startTime := suite.ctx.BlockTime().Add(-201 * time.Second) + startTime := suite.ctx.BlockTime().Add(-200001 * time.Second) clawbackAccount := vestingtypes.NewClawbackVestingAccount(baseAccount, funder, amount, startTime, lockupPeriods, vestingPeriods, nil) testutil.FundAccount(s.ctx, s.app.BankKeeper, addr1, amount) //nolint:errcheck s.app.AccountKeeper.SetAccount(s.ctx, clawbackAccount) @@ -209,14 +224,28 @@ func (suite *KeeperTestSuite) TestLiquidate() { tc.malleate() + accFrom := suite.app.AccountKeeper.GetAccount(suite.ctx, tc.from) + vaFrom, ok := accFrom.(*vestingtypes.ClawbackVestingAccount) + if !ok { + suite.T().Fatal("account is not clawback vesting account") + } + suite.T().Logf("locked only coins: %s", vaFrom.GetLockedOnly(suite.ctx.BlockTime()).String()) + suite.T().Logf("UN-locked only coins: %s", vaFrom.GetUnlockedOnly(suite.ctx.BlockTime()).String()) + spendable := suite.app.BankKeeper.SpendableCoin(suite.ctx, tc.from, "aISLM") + suite.T().Logf("spendable coins: %s", spendable.String()) + suite.T().Logf("liquidation amount: %s", tc.amount.String()) + msg := types.NewMsgLiquidate(tc.from, tc.to, tc.amount) resp, err := suite.app.LiquidVestingKeeper.Liquidate(ctx, msg) - expResponse := &types.MsgLiquidateResponse{} + expResponse := &types.MsgLiquidateResponse{ + Minted: sdk.NewCoin(types.DenomBaseNameFromID(0), tc.amount.Amount), + } if tc.expectPass { // check returns suite.Require().NoError(err) - suite.Require().Equal(expResponse, resp) + suite.Require().Equal(expResponse.Minted, resp.Minted) + suite.Require().NotEmpty(resp.ContractAddr) // check target account exists and has liquid token accIto := suite.app.AccountKeeper.GetAccount(suite.ctx, tc.to) @@ -275,11 +304,14 @@ func (suite *KeeperTestSuite) TestMultipleLiquidationsFromOneAccount() { // FIRST LIQUIDATION msg := types.NewMsgLiquidate(from, to, liquidationAmount) resp, err := suite.app.LiquidVestingKeeper.Liquidate(ctx, msg) - expResponse := &types.MsgLiquidateResponse{} + expResponse := &types.MsgLiquidateResponse{ + Minted: sdk.NewCoin("aLIQUID0", liquidationAmount.Amount), + } // check returns suite.Require().NoError(err) - suite.Require().Equal(expResponse, resp) + suite.Require().Equal(expResponse.Minted, resp.Minted) + suite.Require().NotEmpty(resp.ContractAddr) // check target account exists and has liquid token accIto := suite.app.AccountKeeper.GetAccount(suite.ctx, to) @@ -312,9 +344,14 @@ func (suite *KeeperTestSuite) TestMultipleLiquidationsFromOneAccount() { msg = types.NewMsgLiquidate(from, to, liquidationAmount) resp, err = suite.app.LiquidVestingKeeper.Liquidate(ctx, msg) + expResponse = &types.MsgLiquidateResponse{ + Minted: sdk.NewCoin("aLIQUID1", liquidationAmount.Amount), + } + // check returns suite.Require().NoError(err) - suite.Require().Equal(expResponse, resp) + suite.Require().Equal(expResponse.Minted, resp.Minted) + suite.Require().NotEmpty(resp.ContractAddr) // check target account exists and has liquid token balanceTarget = suite.app.BankKeeper.GetBalance(suite.ctx, to, types.DenomBaseNameFromID(1)) @@ -391,7 +428,7 @@ func (suite *KeeperTestSuite) TestRedeem() { testutil.FundModuleAccount(s.ctx, s.app.BankKeeper, types.ModuleName, amount) //nolint:errcheck // create liquid vesting denom // subs 150 second, it is the half of the second period now - startTime := s.ctx.BlockTime().Add(-150 * time.Second) + startTime := s.ctx.BlockTime().Add(-150000 * time.Second) s.app.LiquidVestingKeeper.SetDenom(s.ctx, types.Denom{ BaseDenom: "aLIQUID0", DisplayDenom: "LIQUID0", diff --git a/x/liquidvesting/keeper/params.go b/x/liquidvesting/keeper/params.go index 98263c92..f3011d73 100644 --- a/x/liquidvesting/keeper/params.go +++ b/x/liquidvesting/keeper/params.go @@ -6,7 +6,7 @@ import ( "github.com/haqq-network/haqq/x/liquidvesting/types" ) -var isTrue = []byte("0x01") +// var isTrue = []byte("0x01") // GetParams returns the total set of liquidvesting parameters. func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { @@ -20,23 +20,29 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { return err } - k.SetLiquidVestingEnabled(ctx, params.EnableLiquidVesting) - k.paramstore.SetParamSet(ctx, ¶ms) return nil } func (k Keeper) IsLiquidVestingEnabled(ctx sdk.Context) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(types.ParamStoreKeyEnableLiquidVesting) + params := k.GetParams(ctx) + return params.EnableLiquidVesting } func (k Keeper) SetLiquidVestingEnabled(ctx sdk.Context, enable bool) { - store := ctx.KVStore(k.storeKey) - if enable { - store.Set(types.ParamStoreKeyEnableLiquidVesting, isTrue) - return + params := k.GetParams(ctx) + params.EnableLiquidVesting = enable + err := k.SetParams(ctx, params) + if err != nil { + panic(err) + } +} + +func (k Keeper) ResetParamsToDefault(ctx sdk.Context) { + params := types.DefaultParams() + err := k.SetParams(ctx, params) + if err != nil { + panic(err) } - store.Delete(types.ParamStoreKeyEnableLiquidVesting) } diff --git a/x/liquidvesting/keeper/params_test.go b/x/liquidvesting/keeper/params_test.go index ba7a9786..200b3d76 100644 --- a/x/liquidvesting/keeper/params_test.go +++ b/x/liquidvesting/keeper/params_test.go @@ -14,6 +14,8 @@ func (suite *KeeperTestSuite) TestParams() { suite.Require().Equal(expParams, params) + params.EnableLiquidVesting = false + err := suite.app.LiquidVestingKeeper.SetParams(suite.ctx, params) if err != nil { panic(fmt.Errorf("error setting params %s", err)) diff --git a/x/liquidvesting/types/tx.pb.go b/x/liquidvesting/types/tx.pb.go index b412d6c4..d06e8be4 100644 --- a/x/liquidvesting/types/tx.pb.go +++ b/x/liquidvesting/types/tx.pb.go @@ -98,6 +98,10 @@ func (m *MsgLiquidate) GetAmount() types.Coin { // MsgLiquidateResponse defines the Msg/Liquidate response type type MsgLiquidateResponse struct { + // amount of liquid tokens minted + Minted types.Coin `protobuf:"bytes,1,opt,name=minted,proto3" json:"minted"` + // address of erc20 the liquidation denom contract + ContractAddr string `protobuf:"bytes,2,opt,name=contract_addr,json=contractAddr,proto3" json:"contract_addr,omitempty"` } func (m *MsgLiquidateResponse) Reset() { *m = MsgLiquidateResponse{} } @@ -133,6 +137,20 @@ func (m *MsgLiquidateResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgLiquidateResponse proto.InternalMessageInfo +func (m *MsgLiquidateResponse) GetMinted() types.Coin { + if m != nil { + return m.Minted + } + return types.Coin{} +} + +func (m *MsgLiquidateResponse) GetContractAddr() string { + if m != nil { + return m.ContractAddr + } + return "" +} + // MsgLiquidate represents message to redeem arbitrary amount of liquid vesting // tokens type MsgRedeem struct { @@ -244,35 +262,37 @@ func init() { func init() { proto.RegisterFile("haqq/liquidvesting/v1/tx.proto", fileDescriptor_cfdce5e8d421730a) } var fileDescriptor_cfdce5e8d421730a = []byte{ - // 444 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x41, 0x6b, 0x13, 0x41, - 0x14, 0xc7, 0x33, 0x29, 0x04, 0x77, 0x52, 0x85, 0xae, 0x55, 0x62, 0x94, 0x69, 0xdc, 0x52, 0x58, - 0x2c, 0xce, 0xb0, 0xf1, 0xea, 0xa9, 0x82, 0xa7, 0xe6, 0xb2, 0x78, 0xf2, 0x22, 0xb3, 0xe9, 0x38, - 0x1d, 0xcc, 0xce, 0xdb, 0xec, 0x4c, 0xd6, 0x7a, 0xf1, 0xe0, 0x45, 0xf0, 0x24, 0x0a, 0x7e, 0x06, - 0x8f, 0x7e, 0x8c, 0x1e, 0x0b, 0x5e, 0x3c, 0x89, 0x24, 0x82, 0x5f, 0x43, 0x32, 0xb3, 0xdd, 0x46, - 0x31, 0x28, 0x78, 0x59, 0xde, 0xfe, 0xdf, 0x7f, 0xdf, 0xfc, 0xf6, 0x3f, 0x0f, 0x93, 0x63, 0x3e, - 0x9d, 0xb2, 0x89, 0x9a, 0xce, 0xd4, 0x51, 0x25, 0x8c, 0x55, 0x5a, 0xb2, 0x2a, 0x61, 0xf6, 0x84, - 0x16, 0x25, 0x58, 0x08, 0xaf, 0x2d, 0xfb, 0xf4, 0x97, 0x3e, 0xad, 0x92, 0xfe, 0x16, 0xcf, 0x95, - 0x06, 0xe6, 0x9e, 0xde, 0xd9, 0xdf, 0x96, 0x20, 0xc1, 0x95, 0x6c, 0x59, 0xd5, 0xea, 0x2d, 0x09, - 0x20, 0x27, 0x82, 0xf1, 0x42, 0x31, 0xae, 0x35, 0x58, 0x6e, 0x15, 0x68, 0x53, 0x77, 0xc9, 0x18, - 0x4c, 0x0e, 0x86, 0x65, 0xdc, 0x08, 0x56, 0x25, 0x99, 0xb0, 0x3c, 0x61, 0x63, 0x50, 0xda, 0xf7, - 0xa3, 0x0f, 0x08, 0x6f, 0x8e, 0x8c, 0x3c, 0x74, 0xc7, 0x73, 0x2b, 0xc2, 0x3d, 0x7c, 0x65, 0x72, - 0xfe, 0xf2, 0xe4, 0x69, 0x09, 0x79, 0x0f, 0x0d, 0x50, 0x1c, 0xa4, 0x97, 0x1b, 0xf5, 0x61, 0x09, - 0x79, 0x78, 0x1b, 0x6f, 0x5e, 0xd8, 0x2c, 0xf4, 0xda, 0xce, 0xd4, 0x6d, 0xb4, 0x47, 0x10, 0xde, - 0xc7, 0x1d, 0x9e, 0xc3, 0x4c, 0xdb, 0xde, 0xc6, 0x00, 0xc5, 0xdd, 0xe1, 0x0d, 0xea, 0x59, 0xe8, - 0x92, 0x85, 0xd6, 0x2c, 0xf4, 0x01, 0x28, 0x7d, 0x10, 0x9c, 0x7e, 0xdd, 0x69, 0x7d, 0xfc, 0xf1, - 0xe9, 0x0e, 0x4a, 0xeb, 0x6f, 0xa2, 0xeb, 0x78, 0x7b, 0x95, 0x2b, 0x15, 0xa6, 0x00, 0x6d, 0x44, - 0xf4, 0x1a, 0xe1, 0x60, 0x64, 0x64, 0x2a, 0x8e, 0x84, 0xc8, 0xc3, 0x1d, 0xdc, 0x2d, 0x5d, 0xb5, - 0x8a, 0x8a, 0xbd, 0xe4, 0x38, 0x6f, 0xe2, 0xa0, 0x36, 0x34, 0x90, 0x97, 0xbc, 0xf0, 0xdf, 0x84, - 0x57, 0xf1, 0x56, 0x03, 0x72, 0x8e, 0x37, 0x7c, 0xd7, 0xc6, 0x1b, 0x23, 0x23, 0xc3, 0x37, 0x08, - 0x07, 0x17, 0xa1, 0xee, 0xd2, 0x3f, 0x5e, 0x32, 0x5d, 0xfd, 0xc3, 0xfe, 0xfe, 0x3f, 0x98, 0x9a, - 0x18, 0xf6, 0x5f, 0x7d, 0xfe, 0xfe, 0xbe, 0xbd, 0x17, 0xed, 0xb2, 0x75, 0xeb, 0xc5, 0x9a, 0xbb, - 0x08, 0x5f, 0xe2, 0x4e, 0x9d, 0xd7, 0x60, 0xfd, 0x19, 0xde, 0xd1, 0x8f, 0xff, 0xe6, 0x68, 0x10, - 0x62, 0x87, 0x10, 0x45, 0x83, 0xf5, 0x08, 0x3e, 0xe9, 0x83, 0xc3, 0xd3, 0x39, 0x41, 0x67, 0x73, - 0x82, 0xbe, 0xcd, 0x09, 0x7a, 0xbb, 0x20, 0xad, 0xb3, 0x05, 0x69, 0x7d, 0x59, 0x90, 0xd6, 0xe3, - 0xa1, 0x54, 0xf6, 0x78, 0x96, 0xd1, 0x31, 0xe4, 0x6e, 0xca, 0x5d, 0x2d, 0xec, 0x73, 0x28, 0x9f, - 0xf9, 0x91, 0x27, 0xbf, 0x0d, 0xb5, 0x2f, 0x0a, 0x61, 0xb2, 0x8e, 0xdb, 0xdc, 0x7b, 0x3f, 0x03, - 0x00, 0x00, 0xff, 0xff, 0x0c, 0xa4, 0x9a, 0x8a, 0x59, 0x03, 0x00, 0x00, + // 479 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0x41, 0x6b, 0x13, 0x41, + 0x14, 0xc7, 0x33, 0x29, 0x04, 0x77, 0x92, 0x0a, 0x5d, 0x2b, 0xc4, 0x28, 0xdb, 0xb8, 0xa1, 0x10, + 0x2c, 0xce, 0x90, 0x78, 0xf5, 0x62, 0x05, 0x4f, 0xcd, 0x25, 0x78, 0xf2, 0x52, 0x26, 0xbb, 0xe3, + 0x74, 0x30, 0x3b, 0x2f, 0x99, 0x99, 0xc4, 0xf6, 0xe2, 0xc1, 0x8b, 0xe0, 0x49, 0x14, 0xfc, 0x0c, + 0x1e, 0xfd, 0x18, 0x3d, 0x16, 0xbc, 0x78, 0x12, 0x49, 0x04, 0xbf, 0x86, 0x64, 0x66, 0x77, 0x1b, + 0xc5, 0x60, 0xc1, 0x4b, 0x78, 0xf9, 0xbf, 0xff, 0xbc, 0xf7, 0xe3, 0x3f, 0xb3, 0x38, 0x3a, 0x61, + 0xd3, 0x29, 0x1d, 0xcb, 0xe9, 0x4c, 0xa6, 0x73, 0x6e, 0xac, 0x54, 0x82, 0xce, 0x7b, 0xd4, 0x9e, + 0x92, 0x89, 0x06, 0x0b, 0xe1, 0xcd, 0x55, 0x9f, 0xfc, 0xd6, 0x27, 0xf3, 0x5e, 0x6b, 0x87, 0x65, + 0x52, 0x01, 0x75, 0xbf, 0xde, 0xd9, 0xda, 0x15, 0x20, 0xc0, 0x95, 0x74, 0x55, 0xe5, 0xea, 0x1d, + 0x01, 0x20, 0xc6, 0x9c, 0xb2, 0x89, 0xa4, 0x4c, 0x29, 0xb0, 0xcc, 0x4a, 0x50, 0x26, 0xef, 0x46, + 0x09, 0x98, 0x0c, 0x0c, 0x1d, 0x31, 0xc3, 0xe9, 0xbc, 0x37, 0xe2, 0x96, 0xf5, 0x68, 0x02, 0x52, + 0xf9, 0x7e, 0xfc, 0x11, 0xe1, 0xc6, 0xc0, 0x88, 0x23, 0xb7, 0x9e, 0x59, 0x1e, 0xee, 0xe3, 0xeb, + 0xe3, 0xe2, 0xcf, 0xf1, 0x73, 0x0d, 0x59, 0x13, 0xb5, 0x51, 0x37, 0x18, 0x6e, 0x97, 0xea, 0x13, + 0x0d, 0x59, 0x78, 0x17, 0x37, 0x2e, 0x6d, 0x16, 0x9a, 0x55, 0x67, 0xaa, 0x97, 0xda, 0x53, 0x08, + 0x1f, 0xe2, 0x1a, 0xcb, 0x60, 0xa6, 0x6c, 0x73, 0xab, 0x8d, 0xba, 0xf5, 0xfe, 0x2d, 0xe2, 0x59, + 0xc8, 0x8a, 0x85, 0xe4, 0x2c, 0xe4, 0x31, 0x48, 0x75, 0x18, 0x9c, 0x7f, 0xdb, 0xab, 0x7c, 0xfa, + 0xf9, 0xf9, 0x1e, 0x1a, 0xe6, 0x67, 0xe2, 0x33, 0xbc, 0xbb, 0xce, 0x35, 0xe4, 0x66, 0x02, 0xca, + 0xf0, 0xd5, 0xd4, 0x4c, 0x2a, 0xcb, 0x53, 0xc7, 0x75, 0xe5, 0xa9, 0xfe, 0x4c, 0xd8, 0xc1, 0xdb, + 0x09, 0x28, 0xab, 0x59, 0x62, 0x8f, 0x59, 0x9a, 0xea, 0x9c, 0xbb, 0x51, 0x88, 0x8f, 0xd2, 0x54, + 0xc7, 0x6f, 0x10, 0x0e, 0x06, 0x46, 0x0c, 0x79, 0xca, 0x79, 0x16, 0xee, 0xe1, 0xba, 0x76, 0xd5, + 0x7a, 0x1a, 0xd8, 0x4b, 0x2e, 0x8a, 0xdb, 0x38, 0xc8, 0x0d, 0x65, 0x0e, 0xd7, 0xbc, 0xf0, 0xdf, + 0x21, 0xdc, 0xc0, 0x3b, 0x25, 0x48, 0x91, 0x40, 0xff, 0x7d, 0x15, 0x6f, 0x0d, 0x8c, 0x08, 0xdf, + 0x22, 0x1c, 0x5c, 0xde, 0x5b, 0x87, 0xfc, 0xf5, 0x1d, 0x91, 0xf5, 0x10, 0x5b, 0x07, 0x57, 0x30, + 0x15, 0x7b, 0xe2, 0x83, 0xd7, 0x5f, 0x7e, 0x7c, 0xa8, 0xee, 0xc7, 0x1d, 0xba, 0xe9, 0x05, 0xd3, + 0xf2, 0xba, 0xc3, 0x57, 0xb8, 0x96, 0xe7, 0xd5, 0xde, 0xbc, 0xc3, 0x3b, 0x5a, 0xdd, 0x7f, 0x39, + 0x4a, 0x84, 0xae, 0x43, 0x88, 0xe3, 0xf6, 0x66, 0x04, 0x9f, 0xf4, 0xe1, 0xd1, 0xf9, 0x22, 0x42, + 0x17, 0x8b, 0x08, 0x7d, 0x5f, 0x44, 0xe8, 0xdd, 0x32, 0xaa, 0x5c, 0x2c, 0xa3, 0xca, 0xd7, 0x65, + 0x54, 0x79, 0xd6, 0x17, 0xd2, 0x9e, 0xcc, 0x46, 0x24, 0x81, 0xcc, 0x4d, 0xb9, 0xaf, 0xb8, 0x7d, + 0x09, 0xfa, 0x85, 0x1f, 0x79, 0xfa, 0xc7, 0x50, 0x7b, 0x36, 0xe1, 0x66, 0x54, 0x73, 0x1f, 0xc7, + 0x83, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xfa, 0x0f, 0x20, 0x6d, 0xbc, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -466,6 +486,23 @@ func (m *MsgLiquidateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.ContractAddr) > 0 { + i -= len(m.ContractAddr) + copy(dAtA[i:], m.ContractAddr) + i = encodeVarintTx(dAtA, i, uint64(len(m.ContractAddr))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Minted.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -575,6 +612,12 @@ func (m *MsgLiquidateResponse) Size() (n int) { } var l int _ = l + l = m.Minted.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.ContractAddr) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -788,6 +831,71 @@ func (m *MsgLiquidateResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgLiquidateResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Minted", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Minted.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContractAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:])