keeper

package
v9.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2023 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitTransferDeniedEvent

func EmitTransferDeniedEvent(ctx sdk.Context, reason, denom, channelId string, direction types.PacketDirection, amount sdkmath.Int, err error)

If the rate limit is exceeded or the denom is blacklisted, we emit an event

func GetRateLimitItemKey

func GetRateLimitItemKey(denom string, channelId string) []byte

Get the rate limit byte key built from the denom and channelId

func ParseDenomFromRecvPacket

func ParseDenomFromRecvPacket(packet channeltypes.Packet, packetData transfertypes.FungibleTokenPacketData) (denom string)

Parse the denom from the Recv Packet that will be used by the rate limit module The denom that the rate limiter will use for a RECEIVE packet depends on whether it was a source or sink

     Sink:   The token moves forward, to a chain different than its previous hop
             The new port and channel are APPENDED to the denom trace.
             (e.g. A -> B, B is a sink) (e.g. A -> B -> C, C is a sink)
		Source: The token moves backwards (i.e. revisits the last chain it was sent from)
				The port and channel are REMOVED from the denom trace - undoing the last hop.
             (e.g. A -> B -> A, A is a source) (e.g. A -> B -> C -> B, B is a source)

     If the chain is acting as a SINK:
     	We add on the Stride port and channel and hash it
         Ex1: uosmo sent from Osmosis to Stride
             Packet Denom:   uosmo
              -> Add Prefix: transfer/channel-X/uosmo
              -> Hash:       ibc/...

         Ex2: ujuno sent from Osmosis to Stride
             PacketDenom:    transfer/channel-Y/ujuno  (channel-Y is the Juno <> Osmosis channel)
              -> Add Prefix: transfer/channel-X/transfer/channel-Y/ujuno
              -> Hash:       ibc/...

     If the chain is acting as a SOURCE:
     	First, remove the prefix. Then if there is still a denom trace, hash it
         Ex1: ustrd sent back to Stride from Osmosis
             Packet Denom:      transfer/channel-X/ustrd
              -> Remove Prefix: ustrd
              -> Leave as is:   ustrd

			Ex2: juno was sent to Stride, then to Osmosis, then back to Stride
             Packet Denom:      transfer/channel-X/transfer/channel-Z/ujuno
              -> Remove Prefix: transfer/channel-Z/ujuno
              -> Hash:          ibc/...

func ParseDenomFromSendPacket

func ParseDenomFromSendPacket(packet transfertypes.FungibleTokenPacketData) (denom string)

Parse the denom from the Send Packet that will be used by the rate limit module The denom that the rate limiter will use for a SEND packet depends on whether

it was a NATIVE token (e.g. ustrd, stuatom, etc.) or NON-NATIVE token (e.g. ibc/...)...

We can identify if the token is native or not by parsing the trace denom from the packet If the token is NATIVE, it will not have a prefix (e.g. ustrd),

and if it is NON-NATIVE, it will have a prefix (e.g. transfer/channel-2/uosmo)

For NATIVE denoms, return as is (e.g. ustrd) For NON-NATIVE denoms, take the ibc hash (e.g. hash "transfer/channel-2/usoms" into "ibc/...")

Types

type Hooks

type Hooks struct {
	// contains filtered or unexported fields
}

func (Hooks) AfterEpochEnd

func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

func (Hooks) BeforeEpochStart

func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	key storetypes.StoreKey,
	ps paramtypes.Subspace,
	bankKeeper types.BankKeeper,
	channelKeeper types.ChannelKeeper,
	ics4Wrapper types.ICS4Wrapper,
) *Keeper

func (Keeper) AddDenomToBlacklist

func (k Keeper) AddDenomToBlacklist(ctx sdk.Context, denom string)

Adds a denom to a blacklist to prevent all IBC transfers with this denom

func (Keeper) AfterEpochEnd

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

func (Keeper) AllRateLimits

Query all rate limits

func (Keeper) BeforeEpochStart

func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInfo)

Before each hour epoch, check if any of the rate limits have expired,

and reset them if they have

func (Keeper) CheckRateLimitAndUpdateFlow

func (k Keeper) CheckRateLimitAndUpdateFlow(ctx sdk.Context, direction types.PacketDirection, denom string, channelId string, amount sdkmath.Int) error

Checks whether the given packet will exceed the rate limit Called by OnRecvPacket and OnSendPacket

func (Keeper) GetAllBlacklistedDenoms

func (k Keeper) GetAllBlacklistedDenoms(ctx sdk.Context) []string

Get all the blacklisted denoms

func (Keeper) GetAllRateLimits

func (k Keeper) GetAllRateLimits(ctx sdk.Context) []types.RateLimit

Returns all rate limits stored

func (Keeper) GetAppVersion

func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool)

GetAppVersion wraps IBC ChannelKeeper's GetAppVersion function

func (Keeper) GetChannelValue

func (k Keeper) GetChannelValue(ctx sdk.Context, denom string) sdkmath.Int

The total value on a given path (aka, the denominator in the percentage calculation) is the total supply of the given denom

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) types.Params

GetParams get all parameters as types.Params

func (Keeper) GetRateLimit

func (k Keeper) GetRateLimit(ctx sdk.Context, denom string, channelId string) (rateLimit types.RateLimit, found bool)

Grabs and returns a rate limit object from the store using denom and channel-id

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

func (Keeper) IsDenomBlacklisted

func (k Keeper) IsDenomBlacklisted(ctx sdk.Context, denom string) bool

Check if a denom is currently blacklistec

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) RateLimit

Query a rate limit by denom and channelId

func (Keeper) RateLimitsByChainId

Query all rate limits for a given chain

func (Keeper) RateLimitsByChannelId

Query all rate limits for a given channel

func (Keeper) ReceiveRateLimitedPacket

func (k Keeper) ReceiveRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet) error

Middleware implementation for RecvPacket with rate limiting

func (Keeper) RemoveDenomFromBlacklist

func (k Keeper) RemoveDenomFromBlacklist(ctx sdk.Context, denom string)

Removes a denom from a blacklist to re-enable IBC transfers for that denom

func (Keeper) RemoveRateLimit

func (k Keeper) RemoveRateLimit(ctx sdk.Context, denom string, channelId string)

Removes a rate limit object from the store using denom and channel-id

func (Keeper) ResetRateLimit

func (k Keeper) ResetRateLimit(ctx sdk.Context, denom string, channelId string) error

Reset the rate limit after expiration The inflow and outflow should get reset to 1 and the channelValue should be updated

func (Keeper) SendPacket

func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI) error

SendPacket wraps IBC ChannelKeeper's SendPacket function If the packet does not get rate limited, it passes the packet to the IBC Channel keeper

func (Keeper) SendRateLimitedPacket

func (k Keeper) SendRateLimitedPacket(ctx sdk.Context, packet ibcexported.PacketI) error

Middleware implementation for SendPacket with rate limiting

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams set the params

func (Keeper) SetRateLimit

func (k Keeper) SetRateLimit(ctx sdk.Context, rateLimit types.RateLimit)

Stores/Updates a rate limit object in the store

func (Keeper) UpdateFlow

func (k Keeper) UpdateFlow(rateLimit types.RateLimit, direction types.PacketDirection, amount sdkmath.Int) error

Adds an amount to the flow in either the SEND or RECV direction

func (Keeper) WriteAcknowledgement

func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error

WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL