Skip to content

Commit

Permalink
feat: add transfer ownership feature to dao module (#329)
Browse files Browse the repository at this point in the history
* feat: add transfer ownership feature to doa module

* test: add tests for transfer ownership feature

* chore: rename dao module to ucdao

* chore: bump version in Makefile

* fix: upgrade handler

---------

Co-authored-by: Evgeniy Abramov <[email protected]>
  • Loading branch information
Yurist-85 and kioqq authored Jul 26, 2024
1 parent 6c2cce7 commit 31c96a3
Show file tree
Hide file tree
Showing 42 changed files with 1,276 additions and 369 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.6"
VERSION := "1.7.7"
CBFTVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
Expand Down
46 changes: 31 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ 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"
Expand All @@ -156,6 +153,9 @@ import (
"github.com/haqq-network/haqq/x/liquidvesting"
liquidvestingkeeper "github.com/haqq-network/haqq/x/liquidvesting/keeper"
liquidvestingtypes "github.com/haqq-network/haqq/x/liquidvesting/types"
"github.com/haqq-network/haqq/x/ucdao"
ucdaokeeper "github.com/haqq-network/haqq/x/ucdao/keeper"
ucdaotypes "github.com/haqq-network/haqq/x/ucdao/types"
"github.com/haqq-network/haqq/x/vesting"
vestingkeeper "github.com/haqq-network/haqq/x/vesting/keeper"
vestingtypes "github.com/haqq-network/haqq/x/vesting/types"
Expand All @@ -172,6 +172,7 @@ import (
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"
v177 "github.com/haqq-network/haqq/app/upgrades/v1.7.7"

// NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens
"github.com/haqq-network/haqq/x/ibc/transfer"
Expand Down Expand Up @@ -249,7 +250,7 @@ var (
epochs.AppModuleBasic{},
consensus.AppModuleBasic{},
liquidvesting.AppModuleBasic{},
dao.AppModuleBasic{},
ucdao.AppModuleBasic{},
)

// module account permissions
Expand All @@ -266,7 +267,7 @@ var (
coinomicstypes.ModuleName: {authtypes.Minter},
vestingtypes.ModuleName: nil, // Add vesting module account
liquidvestingtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
daotypes.ModuleName: nil,
ucdaotypes.ModuleName: nil,
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -335,7 +336,7 @@ type Haqq struct {

// Haqq keepers
CoinomicsKeeper coinomicskeeper.Keeper
DaoKeeper daokeeper.Keeper
DaoKeeper ucdaokeeper.Keeper

// the module manager
mm *module.Manager
Expand Down Expand Up @@ -409,7 +410,7 @@ func NewHaqq(
// haqq keys
coinomicstypes.StoreKey,
liquidvestingtypes.StoreKey,
daotypes.StoreKey,
ucdaotypes.StoreKey,
)

// Add the EVM transient store key
Expand Down Expand Up @@ -559,8 +560,8 @@ func NewHaqq(
app.AccountKeeper, app.BankKeeper, app.Erc20Keeper, app.VestingKeeper,
)

app.DaoKeeper = daokeeper.NewBaseKeeper(
appCodec, keys[daotypes.StoreKey], app.AccountKeeper, app.BankKeeper, authAddr,
app.DaoKeeper = ucdaokeeper.NewBaseKeeper(
appCodec, keys[ucdaotypes.StoreKey], app.AccountKeeper, app.BankKeeper, authAddr,
)

epochsKeeper := epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey])
Expand Down Expand Up @@ -711,7 +712,7 @@ func NewHaqq(

// Haqq app modules
coinomics.NewAppModule(app.CoinomicsKeeper, app.AccountKeeper, app.StakingKeeper),
dao.NewAppModule(appCodec, app.DaoKeeper, app.GetSubspace(daotypes.ModuleName)),
ucdao.NewAppModule(appCodec, app.DaoKeeper, app.GetSubspace(ucdaotypes.ModuleName)),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -749,7 +750,7 @@ func NewHaqq(
coinomicstypes.ModuleName,
consensusparamtypes.ModuleName,
liquidvestingtypes.ModuleName,
daotypes.ModuleName,
ucdaotypes.ModuleName,
)

// NOTE: fee market module must go last in order to retrieve the block gas used.
Expand Down Expand Up @@ -786,7 +787,7 @@ func NewHaqq(
coinomicstypes.ModuleName,
consensusparamtypes.ModuleName,
liquidvestingtypes.ModuleName,
daotypes.ModuleName,
ucdaotypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -826,7 +827,7 @@ func NewHaqq(
coinomicstypes.ModuleName,
erc20types.ModuleName,
epochstypes.ModuleName,
daotypes.ModuleName,
ucdaotypes.ModuleName,
// NOTE: crisis module must go at the end to check for invariants on each module
crisistypes.ModuleName,
consensusparamtypes.ModuleName,
Expand Down Expand Up @@ -1189,7 +1190,7 @@ func initParamsKeeper(
// haqq subspaces
paramsKeeper.Subspace(coinomicstypes.ModuleName)
paramsKeeper.Subspace(liquidvestingtypes.ModuleName)
paramsKeeper.Subspace(daotypes.ModuleName)
paramsKeeper.Subspace(ucdaotypes.ModuleName)

return paramsKeeper
}
Expand Down Expand Up @@ -1298,6 +1299,12 @@ func (app *Haqq) setupUpgradeHandlers() {
v176.CreateUpgradeHandler(app.mm, app.configurator, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.DaoKeeper, app.LiquidVestingKeeper, app.Erc20Keeper),
)

// v1.7.7 Rename DAO module to United Contributors DAO
app.UpgradeKeeper.SetUpgradeHandler(
v177.UpgradeName,
v177.CreateUpgradeHandler(app.mm, app.configurator),
)

// 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.
Expand Down Expand Up @@ -1341,7 +1348,16 @@ func (app *Haqq) setupUpgradeHandlers() {
case v176.UpgradeName:
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{
daotypes.ModuleName,
ucdaotypes.ModuleOldName,
},
}
case v177.UpgradeName:
storeUpgrades = &storetypes.StoreUpgrades{
Renamed: []storetypes.StoreRename{
{
OldKey: ucdaotypes.ModuleOldName,
NewKey: ucdaotypes.ModuleName,
},
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v1.7.6/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
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"
daokeeepr "github.com/haqq-network/haqq/x/ucdao/keeper"
vestingtypes "github.com/haqq-network/haqq/x/vesting/types"
)

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v1.7.6/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
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"
daokeeper "github.com/haqq-network/haqq/x/ucdao/keeper"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v1.7.6
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v1.7.7/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v177

const (
// UpgradeName is the shared upgrade plan name for mainnet and testnet
UpgradeName = "v1.7.7"
)
20 changes: 20 additions & 0 deletions app/upgrades/v1.7.7/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v177

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v1.7.7
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger()
logger.Info("run migration v1.7.7")

return mm.RunMigrations(ctx, configurator, vm)
}
}
2 changes: 1 addition & 1 deletion proto/haqq/dao/module/v1/module.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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"
go_import: "github.com/haqq-network/haqq/x/ucdao"
};

// max_metadata_len defines the maximum proposal metadata length.
Expand Down
6 changes: 3 additions & 3 deletions proto/haqq/dao/v1/dao.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package haqq.dao.v1;
import "gogoproto/gogo.proto";
import "amino/amino.proto";

option go_package = "github.com/haqq-network/haqq/x/dao/types";
option go_package = "github.com/haqq-network/haqq/x/ucdao/types";

// Params defines the parameters for the dao module.
message Params {
option(amino.name) = "haqq/x/dao/Params";
option(amino.name) = "haqq/x/ucdao/Params";
option(gogoproto.goproto_stringer) = false;
// enable_dao is the parameter to enable the module functionality.
bool enable_dao = 1;
Expand All @@ -31,7 +31,7 @@ enum CollateralValueType {
}

message AllowedCollateral {
option(amino.name) = "haqq/x/dao/AllowedCollateral";
option(amino.name) = "haqq/x/ucdao/AllowedCollateral";
option(gogoproto.goproto_stringer) = false;

// value is the allowed collateral value.
Expand Down
2 changes: 1 addition & 1 deletion proto/haqq/dao/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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";
option go_package = "github.com/haqq-network/haqq/x/ucdao/types";

// GenesisState defines the gov module's genesis state.
message GenesisState {
Expand Down
2 changes: 1 addition & 1 deletion proto/haqq/dao/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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";
option go_package = "github.com/haqq-network/haqq/x/ucdao/types";

// Query defines the gRPC querier service for dao module
service Query {
Expand Down
23 changes: 22 additions & 1 deletion proto/haqq/dao/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ 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";
option go_package = "github.com/haqq-network/haqq/x/ucdao/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);

// TransferOwnership defines a method to allow an account to transfer the ownership of shares to another account.
rpc TransferOwnership(MsgTransferOwnership) returns (MsgTransferOwnershipResponse);
}

// MsgFund allows an account to directly fund the dao.
Expand All @@ -36,3 +39,21 @@ message MsgFund {

// MsgFundResponse defines the Msg/Fund response type.
message MsgFundResponse {}

// MsgTransferOwnership allows an account transfer the ownership of shares to another account.
message MsgTransferOwnership {
option (cosmos.msg.v1.signer) = "owner";
option (amino.name) = "haqq/dao/MsgTransferOwnership";

option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// owner is a current owner of the shares in dao.
string owner = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// new_owner is a new owner of the shares in dao.
string new_owner = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgTransferOwnershipResponse defines the Msg/TransferOwnership response type.
message MsgTransferOwnershipResponse {}
Loading

0 comments on commit 31c96a3

Please sign in to comment.