Documentation ¶
Index ¶
- func CalculateNewCapacityList(bigTvl *big.Int, limiterCapacityList []types.LimiterCapacity, ...) (newCapacityList []dtypes.SerializableInt)
- func GetBaseline(currentTvl *big.Int, limiter types.Limiter) *big.Int
- func ParseDenomFromRecvPacket(packet channeltypes.Packet, ...) (denom string)
- func ParseDenomFromSendPacket(packet ibctransfertypes.FungibleTokenPacketData) (denom string)
- func ParsePacketInfo(packet channeltypes.Packet, direction types.PacketDirection) (types.IBCTransferPacketInfo, error)
- func UnpackAcknowledgementResponseForTransfer(ctx sdk.Context, logger log.Logger, ack []byte) (*types.AcknowledgementResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateNewCapacityList ¶
func CalculateNewCapacityList( bigTvl *big.Int, limiterCapacityList []types.LimiterCapacity, timeSinceLastBlock time.Duration, ) ( newCapacityList []dtypes.SerializableInt, )
CalculateNewCapacityList calculates the new capacity list for the given current `tvl` and `limitParams“. Input invariant: `len(prevCapacityList) == len(limitParams.Limiters)` Detailed math for calculating the updated capacity:
`baseline = max(baseline_minimum, baseline_tvl_ppm * tvl)` `capacity_diff = max(baseline, capacity-baseline) * (time_since_last_block / period)`
This is basically saying that the capacity returns to the baseline over the course of the `period`. Usually in a linear way, but if the `capacity` is more than twice the `baseline`, then in an exponential way.
`capacity =` if `abs(capacity - baseline) < capacity_diff` then `capacity = baseline` else if `capacity < baseline` then `capacity += capacity_diff` else `capacity -= capacity_diff`
On a high level, `capacity` trends towards `baseline` by `capacity_diff` but does not “cross” it.
func GetBaseline ¶
GetBaseline returns the current capacity baseline for the given limiter. `baseline` formula:
baseline = max(baseline_minimum, baseline_tvl_ppm * current_tvl)
func ParseDenomFromRecvPacket ¶
func ParseDenomFromRecvPacket( packet channeltypes.Packet, packetData ibctransfertypes.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`, explained here: https://github.com/cosmos/ibc-go/blob/04531d83bf/modules/apps/transfer/keeper/relay.go#L23-L54
If the chain is acting as a SINK: Add on the dYdX Chain port and channel and hash it Ex1: uusdc sent from Noble to dYdX Packet Denom: uusdc -> Add Prefix: transfer/channel-0/uusdc -> Hash: ibc/... Ex2: ujuno sent from Osmosis to dYdX Chain 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: adv4tnt sent back to dYdX chain from Osmosis Packet Denom: transfer/channel-X/adv4tnt -> Remove Prefix: adv4tnt -> Leave as is: adv4tnt Ex2: juno was sent to dYdX Chain, then to Osmosis, then back to dYdX Chain Packet Denom: transfer/channel-X/transfer/channel-Z/ujuno -> Remove Prefix: transfer/channel-Z/ujuno -> Hash: ibc/...
func ParseDenomFromSendPacket ¶
func ParseDenomFromSendPacket(packet ibctransfertypes.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. adv4tnt, 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. adv4tnt), 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. adv4tnt) For NON-NATIVE denoms, take the ibc hash (e.g. hash "transfer/channel-2/usoms" into "ibc/...")
func ParsePacketInfo ¶
func ParsePacketInfo( packet channeltypes.Packet, direction types.PacketDirection, ) (types.IBCTransferPacketInfo, error)
Parses the following information from a packet needed for transfer rate limit: - channelID - denom - amount
This function is similar to Stride's implementation below except it ignores the `Sender` and `Receiver` information. https://github.com/Stride-Labs/stride/blob/eb3564c7/x/ratelimit/keeper/packet.go#L127
func UnpackAcknowledgementResponseForTransfer ¶
func UnpackAcknowledgementResponseForTransfer( ctx sdk.Context, logger log.Logger, ack []byte, ) (*types.AcknowledgementResponse, error)
UnpackAcknowledgementResponseForTransfer unmarshals Acknowledgements for IBC transfers, determines the status of the acknowledgement (success or failure).
Types ¶
This section is empty.