2020-08-17 17:09:02 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
2023-04-05 23:21:59 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
2020-08-17 17:09:02 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
2024-08-03 09:51:56 +00:00
|
|
|
"github.com/0glabs/0g-chain/x/issuance/types"
|
2020-08-17 17:09:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetParams returns the params from the store
|
|
|
|
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
|
|
|
|
var p types.Params
|
|
|
|
k.paramSubspace.GetParamSet(ctx, &p)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetParams sets params on the store
|
|
|
|
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|
|
|
k.paramSubspace.SetParamSet(ctx, ¶ms)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAsset returns an asset from the params and a boolean for if it was found
|
|
|
|
func (k Keeper) GetAsset(ctx sdk.Context, denom string) (types.Asset, bool) {
|
|
|
|
params := k.GetParams(ctx)
|
|
|
|
for _, asset := range params.Assets {
|
|
|
|
if asset.Denom == denom {
|
|
|
|
return asset, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return types.Asset{}, false
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAsset sets an asset in the params
|
|
|
|
func (k Keeper) SetAsset(ctx sdk.Context, asset types.Asset) {
|
|
|
|
params := k.GetParams(ctx)
|
|
|
|
for i := range params.Assets {
|
|
|
|
if params.Assets[i].Denom == asset.Denom {
|
|
|
|
params.Assets[i] = asset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
k.SetParams(ctx, params)
|
|
|
|
}
|
2020-08-21 22:56:20 +00:00
|
|
|
|
|
|
|
// GetRateLimit returns the rete-limit parameters for the input denom
|
|
|
|
func (k Keeper) GetRateLimit(ctx sdk.Context, denom string) (types.RateLimit, error) {
|
|
|
|
asset, found := k.GetAsset(ctx, denom)
|
|
|
|
if !found {
|
2023-04-05 23:21:59 +00:00
|
|
|
errorsmod.Wrap(types.ErrAssetNotFound, denom)
|
2020-08-21 22:56:20 +00:00
|
|
|
}
|
|
|
|
return asset.RateLimit, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SynchronizeBlockList resets the block list to empty for any asset that is not blockable - could happen if this value is changed via governance
|
|
|
|
func (k Keeper) SynchronizeBlockList(ctx sdk.Context) {
|
|
|
|
params := k.GetParams(ctx)
|
|
|
|
for _, asset := range params.Assets {
|
|
|
|
if !asset.Blockable && len(asset.BlockedAddresses) > 0 {
|
2022-01-08 00:39:27 +00:00
|
|
|
asset.BlockedAddresses = []string{}
|
2020-08-21 22:56:20 +00:00
|
|
|
k.SetAsset(ctx, asset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|