Skip to content

feat: added alliance module into app, implement ictest for the flow #301

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
- "ictest-pfm"
- "ictest-lsm"
- "ictest-liquidstake"
- "ictest-alliance"
fail-fast: false

steps:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ ictest-liquidstake: rm-testcache
ictest-liquidstake-all: rm-testcache
cd interchaintest && go test -race -v -run "(TestLiquidStakeStkXPRT|TestLiquidStakeUnstakeStkXPRT|TestPauseLiquidStakeStkXPRT)" .

ictest-alliance: rm-testcache
cd interchaintest && go test -race -v -run TestAllianceBasic .

rm-testcache:
go clean -testcache

Expand Down
34 changes: 29 additions & 5 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -94,6 +93,11 @@ import (
buildertypes "github.com/skip-mev/pob/x/builder/types"
"github.com/spf13/cast"

bankkeeper "github.com/terra-money/alliance/custom/bank/keeper"
alliancemodule "github.com/terra-money/alliance/x/alliance"
alliancemodulekeeper "github.com/terra-money/alliance/x/alliance/keeper"
alliancemoduletypes "github.com/terra-money/alliance/x/alliance/types"

"github.com/persistenceOne/persistenceCore/v11/wasmbindings"

// unnamed import of statik for swagger UI support
Expand All @@ -107,7 +111,7 @@ type AppKeepers struct {
memKeys map[string]*storetypes.MemoryStoreKey

AccountKeeper *authkeeper.AccountKeeper
BankKeeper *bankkeeper.BaseKeeper
BankKeeper *bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper *slashingkeeper.Keeper
Expand Down Expand Up @@ -138,6 +142,7 @@ type AppKeepers struct {
GroupKeeper *groupkeeper.Keeper
PacketForwardKeeper *packetforwardkeeper.Keeper
BuilderKeeper *builderkeeper.Keeper
AllianceKeeper *alliancemodulekeeper.Keeper

// Modules
TransferModule ibctransfer.AppModule
Expand Down Expand Up @@ -219,7 +224,7 @@ func NewAppKeeper(
bankKeeper := bankkeeper.NewBaseKeeper(
appCodec,
appKeepers.keys[banktypes.StoreKey],
appKeepers.AccountKeeper,
*appKeepers.AccountKeeper,
sendCoinBlockedAddrs, // these blocked address will be used in distribution keeper as well
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
Expand Down Expand Up @@ -325,8 +330,25 @@ func NewAppKeeper(
)
appKeepers.HalvingKeeper = &halvingKeeper

allianceKeeper := alliancemodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[alliancemoduletypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
appKeepers.DistributionKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
appKeepers.BankKeeper.RegisterKeepers(allianceKeeper, appKeepers.StakingKeeper)
appKeepers.AllianceKeeper = &allianceKeeper

appKeepers.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(appKeepers.DistributionKeeper.Hooks(), appKeepers.SlashingKeeper.Hooks()),
stakingtypes.NewMultiStakingHooks(
appKeepers.DistributionKeeper.Hooks(),
appKeepers.SlashingKeeper.Hooks(),
appKeepers.AllianceKeeper.StakingHooks(),
),
)

appKeepers.EpochsKeeper = epochskeeper.NewKeeper(appKeepers.keys[epochstypes.StoreKey])
Expand Down Expand Up @@ -589,7 +611,8 @@ func NewAppKeeper(
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramsproposal.RouterKey, params.NewParamChangeProposalHandler(*appKeepers.ParamsKeeper)). // this is kept for the modules that are yet to migrate from legacy x/params.
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibccoreclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper))
AddRoute(ibcclienttypes.RouterKey, ibccoreclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)).
AddRoute(alliancemoduletypes.RouterKey, alliancemodule.NewAllianceProposalHandler(*appKeepers.AllianceKeeper))

govConfig := govtypes.DefaultConfig()
govConfig.MaxMetadataLen = 5000
Expand Down Expand Up @@ -643,6 +666,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(oracletypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName)
paramsKeeper.Subspace(alliancemoduletypes.ModuleName)

return paramsKeeper
}
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
ratesynctypes "github.com/persistenceOne/pstake-native/v2/x/ratesync/types"
buildertypes "github.com/skip-mev/pob/x/builder/types"
alliancemoduletypes "github.com/terra-money/alliance/x/alliance/types"
)

func (appKeepers *AppKeepers) GenerateKeys() {
Expand Down Expand Up @@ -73,6 +74,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
stakingtypes.StoreKey,
upgradetypes.StoreKey,
wasm.StoreKey,
alliancemoduletypes.StoreKey,
)

// Define transient store keys
Expand Down
7 changes: 7 additions & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (
"github.com/persistenceOne/pstake-native/v2/x/lscosmos"
"github.com/persistenceOne/pstake-native/v2/x/ratesync"
buildermodule "github.com/skip-mev/pob/x/builder"

alliancemodule "github.com/terra-money/alliance/x/alliance"
alliancemoduleclient "github.com/terra-money/alliance/x/alliance/client"
)

// AppModuleBasics defines the module BasicManager is in charge of setting up basic,
Expand All @@ -63,6 +66,9 @@ var AppModuleBasics = []module.AppModuleBasic{
upgradeclient.LegacyCancelProposalHandler,
ibcclient.UpdateClientProposalHandler,
ibcclient.UpgradeProposalHandler,
alliancemoduleclient.CreateAllianceProposalHandler,
alliancemoduleclient.UpdateAllianceProposalHandler,
alliancemoduleclient.DeleteAllianceProposalHandler,
},
),
params.AppModuleBasic{},
Expand Down Expand Up @@ -93,4 +99,5 @@ var AppModuleBasics = []module.AppModuleBasic{
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
buildermodule.AppModuleBasic{},
alliancemodule.AppModuleBasic{},
}
14 changes: 12 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -66,6 +65,10 @@ import (
"github.com/skip-mev/pob/x/builder"
buildertypes "github.com/skip-mev/pob/x/builder/types"

custombankmodule "github.com/terra-money/alliance/custom/bank"
alliancemodule "github.com/terra-money/alliance/x/alliance"
alliancemoduletypes "github.com/terra-money/alliance/x/alliance/types"

appparams "github.com/persistenceOne/persistenceCore/v11/app/params"
)

Expand All @@ -86,12 +89,15 @@ var ModuleAccountPermissions = map[string][]string{
liquidstakeibctypes.UndelegationModuleAccount: {authtypes.Burner},
buildertypes.ModuleName: nil,
liquidstaketypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.RewardsPoolName: nil,
}

var receiveAllowedMAcc = map[string]bool{
liquidstakeibctypes.DepositModuleAccount: true,
liquidstakeibctypes.UndelegationModuleAccount: true,
liquidstaketypes.ModuleName: true,
alliancemoduletypes.ModuleName: true,
}

func appModules(
Expand All @@ -108,7 +114,7 @@ func appModules(
),
auth.NewAppModule(appCodec, *app.AccountKeeper, authsimulation.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(*app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, *app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
custombankmodule.NewAppModule(appCodec, *app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, *app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), // nil -> SDK's default inflation function.
Expand Down Expand Up @@ -137,6 +143,7 @@ func appModules(
ratesync.NewAppModule(appCodec, *app.RateSyncKeeper, app.AccountKeeper, app.BankKeeper),
oracle.NewAppModule(appCodec, *app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
builder.NewAppModule(appCodec, *app.BuilderKeeper),
alliancemodule.NewAppModule(appCodec, *app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancemoduletypes.ModuleName)),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
}
}
Expand Down Expand Up @@ -189,6 +196,7 @@ func orderBeginBlockers() []string {
liquidstaketypes.ModuleName,
ratesynctypes.ModuleName,
oracletypes.ModuleName,
alliancemoduletypes.ModuleName,
}
}

Expand Down Expand Up @@ -228,6 +236,7 @@ func orderEndBlockers() []string {
ratesynctypes.ModuleName,
oracletypes.ModuleName,
buildertypes.ModuleName,
alliancemoduletypes.ModuleName,
}
}

Expand Down Expand Up @@ -272,5 +281,6 @@ func orderInitGenesis() []string {
ratesynctypes.ModuleName,
oracletypes.ModuleName,
buildertypes.ModuleName,
alliancemoduletypes.ModuleName,
}
}
20 changes: 20 additions & 0 deletions app/upgrades/testnet/v12.0.0-rc0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v12_0_0_rc0

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/persistenceOne/persistenceCore/v11/app/upgrades"
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
)

const (
// UpgradeName defines the on-chain upgrade name.
UpgradeName = "v12" //ONLY FOR MAINNET
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{alliancetypes.StoreKey},
},
}
19 changes: 19 additions & 0 deletions app/upgrades/testnet/v12.0.0-rc0/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v12_0_0_rc0

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

"github.com/persistenceOne/persistenceCore/v11/app/upgrades"
)

// This was buggy in mainnet upgrade -> potantial fix/ diff should have been -> https://github.com/persistenceOne/persistenceCore/pull/308
// PR #308 is not merged to preserve upgrade history as is.
func CreateUpgradeHandler(args upgrades.UpgradeHandlerArgs) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("running upgrade handler")

return args.ModuleManager.RunMigrations(ctx, args.Configurator, vm)
}
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.9.0
github.com/terra-money/alliance v0.3.5
)

require (
Expand Down Expand Up @@ -207,3 +208,5 @@ replace (

// replace with persistence's LSM fork
replace github.com/cosmos/cosmos-sdk => github.com/persistenceOne/cosmos-sdk v0.47.10-lsm-rc0

replace github.com/terra-money/alliance => github.com/persistenceOne/alliance v0.3.4-lsm
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,8 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/persistenceOne/alliance v0.3.4-lsm h1:0+GyiZaT6o0WH1D6RE8bTKeRWBVMhpuoPVwX+H+tUA0=
github.com/persistenceOne/alliance v0.3.4-lsm/go.mod h1:5HcwoYt2u8oZmkIHcH0Nu/DY73h91qLjJOwpWruHbws=
github.com/persistenceOne/cosmos-sdk v0.47.10-lsm-rc0 h1:lbSQZUdaaKIpoSAznVESl0vMv7pwGiXeIRsGXBlefCE=
github.com/persistenceOne/cosmos-sdk v0.47.10-lsm-rc0/go.mod h1:Q/eHvXB0Awenk3NCh77NvjpeKGPigawFHIXlz2ayfos=
github.com/persistenceOne/persistence-sdk/v2 v2.2.0-rc0 h1:SXvhBcOX8Vik4sP4fKf6VlFUNIfR0bxFXrCN3y6yL08=
Expand Down
1 change: 1 addition & 0 deletions interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-20230905210439-3e17efc70581
github.com/stretchr/testify v1.9.0
github.com/terra-money/alliance v0.3.5
go.uber.org/zap v1.25.0
)

Expand Down
2 changes: 2 additions & 0 deletions interchaintest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/terra-money/alliance v0.3.5 h1:7bLlw9ZUNaFFxGYiKyJKB7x2SV2+6lVvMYbmBm3OORU=
github.com/terra-money/alliance v0.3.5/go.mod h1:HDiUexeXRUkLkLRw5jLQcHuVt1Sx43HfyVl0kfwW3JM=
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand Down
33 changes: 33 additions & 0 deletions interchaintest/helpers/alliance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package helpers

import (
"context"
"encoding/json"
"testing"

"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/stretchr/testify/require"
)

// QueryAlliance gets info about particular alliance
func QueryAlliance(
t *testing.T,
ctx context.Context,
chainNode *cosmos.ChainNode,
allianceDenom string,
) Alliance {
stdout, _, err := chainNode.ExecQuery(ctx, "alliance", "alliance", allianceDenom)
require.NoError(t, err)

debugOutput(t, string(stdout))

var allianceResp queryAllianceResponse
err = json.Unmarshal([]byte(stdout), &allianceResp)
require.NoError(t, err)

return allianceResp.Alliance
}

type queryAllianceResponse struct {
Alliance Alliance `json:"alliance"`
}
25 changes: 24 additions & 1 deletion interchaintest/helpers/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package helpers

import "cosmossdk.io/math"
import (
"time"

"cosmossdk.io/math"
)

type QueryMsg struct {
// IBCHooks
Expand Down Expand Up @@ -80,3 +84,22 @@ type SuperFluidInstantiateMsg struct {
Owner string `json:"owner"`
AllowedLockableTokens []AssetInfo `json:"allowed_lockable_tokens"`
}

type Alliance struct {
Denom string `json:"denom"`
RewardWeight math.LegacyDec `json:"reward_weight"`
TakeRate math.LegacyDec `json:"take_rate"`
TotalTokens math.Int `json:"total_tokens"`
TotalValidatorShares math.LegacyDec `json:"total_validator_shares"`
RewardStartTime time.Time `json:"reward_start_time"`
RewardChangeRate math.LegacyDec `json:"reward_change_rate"`
RewardChangeInterval string `json:"reward_change_interval"`
LastRewardChangeTime time.Time `json:"last_reward_change_time"`

RewardWeightRange struct {
Min math.LegacyDec `json:"min"`
Max math.LegacyDec `json:"max"`
} `json:"reward_weight_range"`

IsInitialized bool `json:"is_initialized"`
}
2 changes: 1 addition & 1 deletion interchaintest/ibc_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestPersistenceGaiaIBCTransfer(t *testing.T) {
},
{
Name: "gaia",
Version: "v9.1.0",
Version: "v14.1.0",
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
Expand Down
Loading