Unverified Commit cb44016b authored by mconcat's avatar mconcat Committed by GitHub
Browse files

Synthlock Invariant (#841)


* add synthlock invariant in progress

add synthlock invariant

* Update x/lockup/keeper/invariants.go

Co-authored-by: default avatarDev Ojha <ValarDragon@users.noreply.github.com>

Co-authored-by: default avatarDev Ojha <ValarDragon@users.noreply.github.com>
parent 1f8327e3
Showing with 37 additions and 1 deletion
+37 -1
package keeper
// DONTCOVER
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/x/gamm/types"
)
// RegisterInvariants registers all governance invariants
func RegisterInvariants(ir sdk.InvariantRegistry, keeper Keeper) {
ir.RegisterRoute(types.ModuleName, "synthetic-lockup-invariant", SyntheticLockupInvariant(keeper))
}
func SyntheticLockupInvariant(keeper Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
synthlocks := keeper.GetAllSyntheticLockups(ctx)
for _, synthlock := range synthlocks {
baselock, err := keeper.GetLockByID(ctx, synthlock.UnderlyingLockId)
if err != nil {
panic(err)
}
if !baselock.Coins.IsAllGTE(synthlock.Coins) {
return sdk.FormatInvariant(types.ModuleName, "synthetic-lockup-invariant",
fmt.Sprintf("\tSynthetic lock token amount %s\n\tUnderlying lock ID: %d, token amount %s\n",
synthlock.Coins, baselock.ID, baselock.Coins)), true
}
}
return sdk.FormatInvariant(types.ModuleName, "synthetic-lockup-invariant", "All synthetic lockup invariant passed"), false
}
}
......@@ -146,7 +146,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
}
// RegisterInvariants registers the capability module's invariants.
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
keeper.RegisterInvariants(ir, am.keeper)
}
// InitGenesis performs the capability module's genesis initialization It returns
// no validator updates.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment