(sctx sdk.Context)
| 880 | } |
| 881 | |
| 882 | func (k *keeper) mintStatusUpdate(sctx sdk.Context) (bmetypes.Status, bool) { |
| 883 | params, err := k.GetParams(sctx) |
| 884 | if err != nil { |
| 885 | // if unable to load params, something went horribly wrong |
| 886 | panic(err) |
| 887 | } |
| 888 | |
| 889 | cb, err := k.status.Get(sctx) |
| 890 | if err != nil { |
| 891 | // if unable to load circuit breaker state, something went horribly wrong |
| 892 | panic(err) |
| 893 | } |
| 894 | pCb := cb |
| 895 | |
| 896 | cr, err := k.calculateCR(sctx) |
| 897 | if err != nil { |
| 898 | cb.Status = bmetypes.MintStatusHaltCR |
| 899 | if errors.Is(err, otypes.ErrPriceStalled) || errors.Is(err, bmetypes.ErrZeroPrice) { |
| 900 | cb.Status = bmetypes.MintStatusHaltOracle |
| 901 | } |
| 902 | } else { |
| 903 | // Clamp CR in BPS to math.MaxUint32 to prevent int64→uint32 overflow |
| 904 | // when CR is extremely large (e.g., zero outstanding ACT supply). |
| 905 | crInt := cr.Mul(sdkmath.LegacyNewDec(10000)).TruncateInt64() |
| 906 | if crInt > math.MaxUint32 { |
| 907 | crInt = math.MaxUint32 |
| 908 | } |
| 909 | |
| 910 | warnThreshold := int64(params.CircuitBreakerWarnThreshold) |
| 911 | haltThreshold := int64(params.CircuitBreakerHaltThreshold) |
| 912 | |
| 913 | if crInt > warnThreshold { |
| 914 | cb.Status = bmetypes.MintStatusHealthy |
| 915 | cb.EpochHeightDiff = calculateBlocksDiff(params, crInt) |
| 916 | } else if crInt <= warnThreshold && crInt > haltThreshold { |
| 917 | cb.Status = bmetypes.MintStatusWarning |
| 918 | cb.EpochHeightDiff = calculateBlocksDiff(params, crInt) |
| 919 | } else { |
| 920 | // halt ACT mint |
| 921 | cb.Status = bmetypes.MintStatusHaltCR |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | changed := !cb.Equal(pCb) |
| 926 | |
| 927 | if changed { |
| 928 | cb.PreviousStatus = pCb.Status |
| 929 | |
| 930 | err = k.status.Set(sctx, cb) |
| 931 | if err != nil { |
| 932 | panic(err) |
| 933 | } |
| 934 | |
| 935 | err = sctx.EventManager().EmitTypedEvent(&bmetypes.EventMintStatusChange{ |
| 936 | PreviousStatus: cb.PreviousStatus, |
| 937 | NewStatus: cb.Status, |
| 938 | CollateralRatio: cr, |
| 939 | }) |
no test coverage detected