Skip to content

Commit

Permalink
Revert "Merge pull request #451 from ComposableFi/slashing_fix"
Browse files Browse the repository at this point in the history
This reverts commit 1ad4293, reversing
changes made to 85e2bf9.
  • Loading branch information
RustNinja authored and kkast committed Mar 20, 2024
1 parent bb19b89 commit 69cf6f2
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ build:
go build $(BUILD_FLAGS) -o bin/centaurid ./cmd/centaurid

docker-build-debug:
@DOCKER_BUILDKIT=1 docker build -t centauri:local -f Dockerfile .
@DOCKER_BUILDKIT=1 docker build -t centauri:debug -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 .
Expand Down
2 changes: 0 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ 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(),
)
Expand Down
6 changes: 0 additions & 6 deletions app/upgrades/v6_4_5/constants.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package v6_4_5

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/notional-labs/composable/v6/app/upgrades"
ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
)

const (
Expand All @@ -14,8 +12,4 @@ const (
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{ibctransfermiddleware.StoreKey},
Deleted: []string{},
},
}
17 changes: 0 additions & 17 deletions app/upgrades/v6_4_5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/notional-labs/composable/v6/app/keepers"
"github.com/notional-labs/composable/v6/app/upgrades"
ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
)

func CreateUpgradeHandler(
Expand All @@ -19,26 +18,10 @@ func CreateUpgradeHandler(
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 := range BrokenProposals {
keepers.GovKeeper.DeleteProposal(ctx, proposal)
}

// 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)
}

custommiddlewareparams := ibctransfermiddleware.DefaultGenesisState()
keepers.IbcTransferMiddlewareKeeper.SetParams(ctx, custommiddlewareparams.Params)

return mm.RunMigrations(ctx, configurator, vm)
}
}
22 changes: 22 additions & 0 deletions app/upgrades/v6_4_6/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v6_4_6

import (
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/notional-labs/composable/v6/app/upgrades"
ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
)

const (
// UpgradeName defines the on-chain upgrade name for the composable upgrade.
UpgradeName = "v6_4_6"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{ibctransfermiddleware.StoreKey},
Deleted: []string{},
},
}
28 changes: 28 additions & 0 deletions app/upgrades/v6_4_6/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v6_4_6

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"
ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
)

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) {
// Add params for custom middleware
custommiddlewareparams := ibctransfermiddleware.DefaultGenesisState()
keepers.IbcTransferMiddlewareKeeper.SetParams(ctx, custommiddlewareparams.Params)

return mm.RunMigrations(ctx, configurator, vm)
}
}
19 changes: 19 additions & 0 deletions custom/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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 {
Expand Down Expand Up @@ -67,6 +68,16 @@ 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
}

Expand All @@ -77,8 +88,16 @@ func (k Keeper) TotalSupply(ctx context.Context, req *types.QueryTotalSupplyRequ
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

// Get duplicate token from transfermiddeware
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
}
46 changes: 3 additions & 43 deletions custom/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package keeper

import (
"fmt"

"cosmossdk.io/math"
abcicometbft "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
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"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper"
)

Expand All @@ -20,9 +16,6 @@ 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 {
Expand Down Expand Up @@ -124,39 +117,6 @@ 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
}
3 changes: 2 additions & 1 deletion tests/interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ func GetDockerImageInfo() (repo, version string) {
if !found {
// make local-image
repo = "centauri"
branchVersion = "local"
branchVersion = "debug"
}

// github converts / to - for pushed docker images
// branchVersion = strings.ReplaceAll(branchVersion, "/", "-")
branchVersion = "latest"
return repo, branchVersion
}
7 changes: 5 additions & 2 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

// calculate how many we would mint, but we dont mint them, we take them from the prefunded account
// mint coins, update supply
mintedCoin := minter.BlockProvision(params)
mintedCoins := sdk.NewCoins(mintedCoin)

Expand All @@ -41,7 +41,10 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculatio

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeReward,
types.EventTypeMint,
sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()),
sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()),
sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()),
),
)
Expand Down
2 changes: 0 additions & 2 deletions x/mint/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ 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"
Expand Down

0 comments on commit 69cf6f2

Please sign in to comment.