MCPcopy Create free account
hub / github.com/Sifchain/sifnode / SingleExternalBalanceModuleAccountCheck

Method SingleExternalBalanceModuleAccountCheck

x/clp/keeper/invariants.go:50–87  ·  view source on GitHub ↗
(externalAsset string)

Source from the content-addressed store, hash-verified

48}
49
50func (k Keeper) SingleExternalBalanceModuleAccountCheck(externalAsset string) sdk.Invariant {
51 return func(ctx sdk.Context) (string, bool) {
52 pool, err := k.GetPool(ctx, externalAsset)
53 if err == nil {
54 clpModuleTotalExternalBalance := k.GetBankKeeper().GetBalance(ctx, types.GetCLPModuleAddress(), pool.ExternalAsset.Symbol)
55 clpModuleTotalExternalBalanceUint := sdk.NewUintFromString(clpModuleTotalExternalBalance.Amount.String())
56
57 ok := pool.ExternalAssetBalance.Add(pool.ExternalCustody).Equal(clpModuleTotalExternalBalanceUint)
58 if !ok {
59 return fmt.Sprintf("external balance mismatch in pool %s (module: %s != pool: %s)",
60 pool.ExternalAsset.Symbol,
61 clpModuleTotalExternalBalanceUint.String(),
62 pool.ExternalAssetBalance.String()), true
63 }
64 }
65
66 // Get Rowan Balance from CLP Module
67 clpModuleTotalNativeBalance := k.GetBankKeeper().GetBalance(ctx, types.GetCLPModuleAddress(), types.GetSettlementAsset().Symbol)
68 clpModuleTotalNativeBalanceUint := sdk.NewUintFromString(clpModuleTotalNativeBalance.Amount.String())
69
70 pools := k.GetPools(ctx)
71 poolsTotalNativeBalanceUint := sdk.ZeroUint()
72 poolsTotalNativeCustodyUint := sdk.ZeroUint()
73 for _, pool := range pools {
74 poolsTotalNativeBalanceUint = poolsTotalNativeBalanceUint.Add(pool.NativeAssetBalance)
75 poolsTotalNativeCustodyUint = poolsTotalNativeCustodyUint.Add(pool.NativeCustody)
76 }
77
78 ok := poolsTotalNativeBalanceUint.Add(poolsTotalNativeCustodyUint).Equal(clpModuleTotalNativeBalanceUint)
79 if !ok {
80 return fmt.Sprintf("native balance mismatch across all pools (module: %s != pools: %s)",
81 clpModuleTotalNativeBalanceUint.String(),
82 poolsTotalNativeBalanceUint.String()), true
83 }
84
85 return "pool and module account balances match", false
86 }
87}
88
89func (k Keeper) UnitsCheck() sdk.Invariant {
90 return func(ctx sdk.Context) (string, bool) {

Callers

nothing calls this directly

Calls 7

GetPoolMethod · 0.95
GetBankKeeperMethod · 0.95
GetPoolsMethod · 0.95
AddMethod · 0.80
GetBalanceMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected