@@ -2,7 +2,9 @@ package keeper
2
2
3
3
import (
4
4
errorsmod "cosmossdk.io/errors"
5
+ "github.com/ExocoreNetwork/exocore/utils"
5
6
"github.com/ExocoreNetwork/exocore/x/assets/types"
7
+ delegationtypes "github.com/ExocoreNetwork/exocore/x/delegation/types"
6
8
sdk "github.com/cosmos/cosmos-sdk/types"
7
9
)
8
10
@@ -46,6 +48,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
46
48
}
47
49
}
48
50
51
+ exoDelegation := sdk .ZeroInt ()
49
52
for _ , assets := range data .OperatorAssets {
50
53
for _ , assetInfo := range assets .AssetsState {
51
54
// #nosec G703 // already validated
@@ -55,8 +58,26 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
55
58
if err != nil {
56
59
panic (errorsmod .Wrap (err , "failed to set operator asset info" ))
57
60
}
61
+ if assetInfo .AssetID == types .ExocoreAssetID {
62
+ exoDelegation = exoDelegation .Add (assetInfo .Info .TotalAmount )
63
+ }
58
64
}
59
65
}
66
+
67
+ // check that this exoDelegation amount is reflected in x/bank
68
+ address := k .ak .GetModuleAccount (ctx , delegationtypes .DelegatedPoolName ).GetAddress ()
69
+ balance := k .bk .GetBalance (ctx , address , utils .BaseDenom )
70
+ // slashing is lazily applied at the time of withdrawal. it means that
71
+ // exoDelegation may have been slashed, but balance will never be slashed.
72
+ // it implies that exoDelegation should be less than or equal to balance.
73
+ // or conversely, if exoDelegation is greater than balance, we have a problem.
74
+ if exoDelegation .GT (balance .Amount ) {
75
+ panic (errorsmod .Wrapf (
76
+ types .ErrInvalidGenesisData ,
77
+ "delegated pool account balance is too low, exoDelegation: %s, balance: %s" ,
78
+ exoDelegation , balance .Amount ,
79
+ ).Error ())
80
+ }
60
81
}
61
82
62
83
// ExportGenesis returns the module's exported genesis.
0 commit comments