(externalAsset string)
| 48 | } |
| 49 | |
| 50 | func (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 | |
| 89 | func (k Keeper) UnitsCheck() sdk.Invariant { |
| 90 | return func(ctx sdk.Context) (string, bool) { |
nothing calls this directly
no test coverage detected