diff --git a/Makefile b/Makefile index 26d1cf2b2..d2191acdc 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ build: go build $(BUILD_FLAGS) -o bin/centaurid ./cmd/centaurid docker-build-debug: - @DOCKER_BUILDKIT=1 docker build -t centauri:debug -f Dockerfile . + @DOCKER_BUILDKIT=1 docker build -t centauri:local -f Dockerfile . lint: @find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -name '*.gw.go' | xargs go run mvdan.cc/gofumpt -w . diff --git a/app/app.go b/app/app.go index 78be271d3..d23bfcfe9 100644 --- a/app/app.go +++ b/app/app.go @@ -36,7 +36,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" "github.com/notional-labs/composable/v6/app/keepers" - "github.com/notional-labs/composable/v6/app/upgrades/v6_4_7" + "github.com/notional-labs/composable/v6/app/upgrades/v6_4_8" // bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -147,7 +147,7 @@ var ( // https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34 EnableSpecificProposals = "" - Upgrades = []upgrades.Upgrade{v6_4_7.Upgrade} + Upgrades = []upgrades.Upgrade{v6_4_8.Upgrade} Forks = []upgrades.Fork{} ) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 6db33ec70..b3a95d7d6 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -210,6 +210,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appCodec, appKeepers.keys[distrtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + appKeepers.StakingKeeper.RegisterKeepers(appKeepers.DistrKeeper, appKeepers.BankKeeper) appKeepers.SlashingKeeper = slashingkeeper.NewKeeper( appCodec, cdc, appKeepers.keys[slashingtypes.StoreKey], appKeepers.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) diff --git a/app/upgrades/v6_4_8/constants.go b/app/upgrades/v6_4_8/constants.go new file mode 100644 index 000000000..9acdab086 --- /dev/null +++ b/app/upgrades/v6_4_8/constants.go @@ -0,0 +1,15 @@ +package v6_4_8 + +import ( + "github.com/notional-labs/composable/v6/app/upgrades" +) + +const ( + // UpgradeName defines the on-chain upgrade name for the composable upgrade. + UpgradeName = "v6_4_8" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, +} diff --git a/app/upgrades/v6_4_8/upgrade.go b/app/upgrades/v6_4_8/upgrade.go new file mode 100644 index 000000000..dde896d6b --- /dev/null +++ b/app/upgrades/v6_4_8/upgrade.go @@ -0,0 +1,43 @@ +package v6_4_8 + +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/cosmos/cosmos-sdk/codec" + "github.com/notional-labs/composable/v6/app/keepers" + "github.com/notional-labs/composable/v6/app/upgrades" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + _ upgrades.BaseAppParamManager, + _ codec.Codec, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // remove broken proposals + BrokenProposals := [3]uint64{2, 6, 11} + for _, proposal_id := range BrokenProposals { + _, ok := keepers.GovKeeper.GetProposal(ctx, proposal_id) + if ok { + keepers.GovKeeper.DeleteProposal(ctx, proposal_id) + } + + } + + // burn extra ppica in escrow account + // this ppica is unused because it is a native token stored in escrow account + // it was unnecessarily minted to match pica escrowed on picasso to ppica minted + // in genesis, to make initial native ppica transferrable to picasso + amount, ok := sdk.NewIntFromString("1066669217167120000000") + if ok { + coins := sdk.Coins{sdk.NewCoin("ppica", amount)} + keepers.BankKeeper.SendCoinsFromAccountToModule(ctx, sdk.MustAccAddressFromBech32("centauri12k2pyuylm9t7ugdvz67h9pg4gmmvhn5vmvgw48"), "gov", coins) + keepers.BankKeeper.BurnCoins(ctx, "gov", coins) + } + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/custom/bank/keeper/keeper.go b/custom/bank/keeper/keeper.go index a7c312c6d..5422ac308 100644 --- a/custom/bank/keeper/keeper.go +++ b/custom/bank/keeper/keeper.go @@ -18,7 +18,6 @@ import ( transfermiddlewarekeeper "github.com/notional-labs/composable/v6/x/transfermiddleware/keeper" alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper" - alliancetypes "github.com/terra-money/alliance/x/alliance/types" ) type Keeper struct { @@ -68,16 +67,6 @@ func (k Keeper) SupplyOf(c context.Context, req *types.QuerySupplyOfRequest) (*t ctx := sdk.UnwrapSDKContext(c) supply := k.GetSupply(ctx, req.Denom) - if req.Denom == k.sk.BondDenom(ctx) { - assets := k.ak.GetAllAssets(ctx) - totalRewardWeights := sdk.ZeroDec() - for _, asset := range assets { - totalRewardWeights = totalRewardWeights.Add(asset.RewardWeight) - } - allianceBonded := k.ak.GetAllianceBondedAmount(ctx, k.acck.GetModuleAddress(alliancetypes.ModuleName)) - supply.Amount = supply.Amount.Sub(allianceBonded) - } - return &types.QuerySupplyOfResponse{Amount: sdk.NewCoin(req.Denom, supply.Amount)}, nil } @@ -93,11 +82,5 @@ func (k Keeper) TotalSupply(ctx context.Context, req *types.QueryTotalSupplyRequ duplicateCoins := k.tfmk.GetTotalEscrowedToken(sdkCtx) totalSupply = totalSupply.Sub(duplicateCoins...) - allianceBonded := k.ak.GetAllianceBondedAmount(sdkCtx, k.acck.GetModuleAddress(alliancetypes.ModuleName)) - bondDenom := k.sk.BondDenom(sdkCtx) - if totalSupply.AmountOf(bondDenom).IsPositive() { - totalSupply = totalSupply.Sub(sdk.NewCoin(bondDenom, allianceBonded)) - } - return &types.QueryTotalSupplyResponse{Supply: totalSupply, Pagination: pageRes}, nil } diff --git a/custom/staking/keeper/keeper.go b/custom/staking/keeper/keeper.go index 2c5b6a5dd..7549e8faf 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -1,13 +1,18 @@ package keeper import ( + "fmt" + + "cosmossdk.io/math" abcicometbft "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/codec" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/cosmos/cosmos-sdk/x/staking/types" + minttypes "github.com/notional-labs/composable/v6/x/mint/types" stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" ) @@ -16,6 +21,9 @@ type Keeper struct { cdc codec.BinaryCodec Stakingmiddleware *stakingmiddleware.Keeper authority string + mintKeeper minttypes.BankKeeper + distrKeeper distkeeper.Keeper + authKeeper minttypes.AccountKeeper } func (k Keeper) BlockValidatorUpdates(ctx sdk.Context, height int64) []abcicometbft.ValidatorUpdate { @@ -117,6 +125,39 @@ func NewKeeper( authority: authority, Stakingmiddleware: stakingmiddleware, cdc: cdc, + mintKeeper: nil, + distrKeeper: distkeeper.Keeper{}, + authKeeper: ak, } return &keeper } + +func (k *Keeper) RegisterKeepers(dk distkeeper.Keeper, mk minttypes.BankKeeper) { + k.distrKeeper = dk + k.mintKeeper = mk +} + +// SlashWithInfractionReason send coins to community pool +func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight, power int64, slashFactor sdk.Dec, _ types.Infraction) math.Int { + // keep slashing logic the same + amountBurned := k.Slash(ctx, consAddr, infractionHeight, power, slashFactor) + // after usual slashing and burning is done, mint burned coinds into community pool + coins := sdk.NewCoins(sdk.NewCoin(k.BondDenom(ctx), amountBurned)) + err := k.mintKeeper.MintCoins(ctx, types.ModuleName, coins) + if err != nil { + k.Logger(ctx).Error("Failed to mint slashed coins: ", amountBurned) + } else { + err = k.distrKeeper.FundCommunityPool(ctx, coins, k.authKeeper.GetModuleAddress(types.ModuleName)) + if err != nil { + k.Logger(ctx).Error(fmt.Sprintf("Failed to fund community pool. Tokens minted to the staking module account: %d. ", amountBurned)) + } else { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + minttypes.EventTypeMintSlashed, + sdk.NewAttribute(sdk.AttributeKeyAmount, amountBurned.String()), + ), + ) + } + } + return amountBurned +} diff --git a/go.mod b/go.mod index bafa84462..959c4fae2 100644 --- a/go.mod +++ b/go.mod @@ -332,7 +332,7 @@ replace ( github.com/cosmos/cosmos-sdk v0.47.5 => github.com/rust-ninja/cosmos-sdk v0.47.5-patch-validators-trim-tag - github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20231027045618-f659894b12d9 + github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 => github.com/ComposableFi/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20240320115741-f32994360827 // ibc-go with wasm client github.com/cosmos/ibc-go/v7 => github.com/notional-labs/ibc-go/v7 v7.2.1-0.20231010040541-6cf43006971f diff --git a/go.sum b/go.sum index 8d9694860..de6ea89d6 100644 --- a/go.sum +++ b/go.sum @@ -221,6 +221,8 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= +github.com/ComposableFi/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20240320115741-f32994360827 h1:PkDT2gEjAgttuF9lZTP+niYjcXutnmqHHK2UaAL9bLs= +github.com/ComposableFi/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20240320115741-f32994360827/go.mod h1:3PHOr4UiPNtnZJutT22fm5+pjIefTlDEgtWGoOJg3A0= github.com/CosmWasm/wasmd v0.40.1 h1:LxbO78t/6S8TkeQlUrJ0m5O87HtAwLx4RGHq3rdrOEU= github.com/CosmWasm/wasmd v0.40.1/go.mod h1:6EOwnv7MpuFaEqxcUOdFV9i4yvrdOciaY6VQ1o7A3yg= github.com/CosmWasm/wasmvm v1.2.6 h1:QmOaiJUyeh8+pPCjJBTgWrbi/hCzCuWewduDO85Pcpc= @@ -968,8 +970,6 @@ github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= github.com/notional-labs/alliance v1.0.1-0.20231106184124-5cc1ff759647 h1:vCSokMIO60u0td51l7NB+pikUChJozIwIb4u8UeqTKI= github.com/notional-labs/alliance v1.0.1-0.20231106184124-5cc1ff759647/go.mod h1:GFQ8TsXDMTpu7kif0Dwddz6rxazy0ZJQHfN38ZmAodI= -github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20231027045618-f659894b12d9 h1:4rte3LTbrQnlu0Gnw6gouj2voGwgjweORA1dcgnQxlU= -github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20231027045618-f659894b12d9/go.mod h1:3PHOr4UiPNtnZJutT22fm5+pjIefTlDEgtWGoOJg3A0= github.com/notional-labs/ibc-go/v7 v7.2.1-0.20231010040541-6cf43006971f h1:Uw35VHCdLTsQf8B4UGTjHCR6HqcYFF6dwPW8uJzS0f4= github.com/notional-labs/ibc-go/v7 v7.2.1-0.20231010040541-6cf43006971f/go.mod h1:hjcl3RPLSDf0LSXrFyk2iTQCCFs5pfLbJb8h/5gJ2Vg= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 384f31cb5..be7fe8df1 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -45,11 +45,7 @@ func GetDockerImageInfo() (repo, version string) { if !found { // make local-image repo = "centauri" - branchVersion = "debug" + branchVersion = "local" } - - // github converts / to - for pushed docker images - // branchVersion = strings.ReplaceAll(branchVersion, "/", "-") - branchVersion = "latest" return repo, branchVersion } diff --git a/x/mint/abci.go b/x/mint/abci.go index c24f80747..42964667d 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -25,7 +25,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculatio minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply) k.SetMinter(ctx, minter) - // mint coins, update supply + // calculate how many we would mint, but we dont mint them, we take them from the prefunded account mintedCoin := minter.BlockProvision(params) mintedCoins := sdk.NewCoins(mintedCoin) @@ -41,10 +41,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculatio ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeMint, - sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()), - sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()), - sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()), + types.EventTypeReward, sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), ), ) diff --git a/x/mint/types/events.go b/x/mint/types/events.go index 891f50768..92d52efac 100644 --- a/x/mint/types/events.go +++ b/x/mint/types/events.go @@ -3,6 +3,8 @@ package types // Minting module event types const ( EventTypeMint = ModuleName + EventTypeReward = "reward_distributed" + EventTypeMintSlashed = "mint_slashed_into_comminity_pool" EventAddAllowedFundAddress = "add_allowed_fund" AttributeKeyBondedRatio = "bonded_ratio" diff --git a/x/transfermiddleware/ibc_ante_test.go b/x/transfermiddleware/ibc_ante_test.go index da9aafd9f..bbf739a8c 100644 --- a/x/transfermiddleware/ibc_ante_test.go +++ b/x/transfermiddleware/ibc_ante_test.go @@ -17,7 +17,7 @@ import ( // NOTE: This is the address of the gov authority on the chain that is being tested. // This means that we need to check bech32 .... everywhere. -var govAuthorityAddress = "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" +var govAuthorityAddress = "centauri10556m38z4x6pqalr9rl5ytf3cff8q46nk85k9m" // ORIGINAL NOTES: // convert from: centauri10556m38z4x6pqalr9rl5ytf3cff8q46nk85k9m