keeper

package
v22.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitHaltZoneEvent

func EmitHaltZoneEvent(ctx sdk.Context, hostZone types.HostZone)

Emits an event indicating a zone was halted

func EmitSuccessfulConfirmDelegationEvent

func EmitSuccessfulConfirmDelegationEvent(ctx sdk.Context, recordId uint64, delegationAmount sdkmath.Int, txHash string, sender string)

Emits an event indicated the delegation record is correctly marked as done

func EmitSuccessfulConfirmUnbondedTokenSweepEvent

func EmitSuccessfulConfirmUnbondedTokenSweepEvent(ctx sdk.Context, recordId uint64, nativeAmount sdkmath.Int, txHash string, sender string)

Emits an event indicated the unbonding record is correctly marked as claimable

func EmitSuccessfulConfirmUndelegationEvent

func EmitSuccessfulConfirmUndelegationEvent(ctx sdk.Context, recordId uint64, nativeAmount sdkmath.Int, txHash string, sender string)

Emits an event indicated the undelegation record is correctly marked as unbonding_in_progress

func EmitSuccessfulLiquidStakeEvent

func EmitSuccessfulLiquidStakeEvent(ctx sdk.Context, staker string, hostZone types.HostZone, nativeAmount, stAmount sdkmath.Int)

Emits a successful liquid stake event, and displays metadata such as the stToken amount

func EmitSuccessfulRedeemStakeEvent

func EmitSuccessfulRedeemStakeEvent(ctx sdk.Context, staker string, hostZone types.HostZone, nativeAmount, stAmount sdkmath.Int)

Emits a successful redeem stake event, and displays metadata such as the native amount

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of the MsgServer interface for the provided Keeper.

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,
	storeKey storetypes.StoreKey,
	accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	icaOracleKeeper types.ICAOracleKeeper,
	ratelimitKeeper types.RatelimitKeeper,
	transferKeeper types.TransferKeeper,
) *Keeper

func (Keeper) ArchiveDelegationRecord

func (k Keeper) ArchiveDelegationRecord(ctx sdk.Context, delegationRecord types.DelegationRecord)

Removes a delegation record from the active store and writes it to the archive store, to preserve history

func (Keeper) ArchiveFailedTransferRecord

func (k Keeper) ArchiveFailedTransferRecord(ctx sdk.Context, recordId uint64) error

func (Keeper) ArchiveUnbondingRecord

func (k Keeper) ArchiveUnbondingRecord(ctx sdk.Context, unbondingRecord types.UnbondingRecord)

Removes a unbonding record from the active store, and writes it to the archive store to preserve history

func (Keeper) BeforeEpochStart

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

This module has the following epochly triggers

  • Handle delegations daily
  • Handle undelegations every 4 days
  • Updates the redemption rate daily
  • Check for completed unbondings hourly
  • Process claims (if applicable) hourly

Note: The hourly processes are meant for actions that should run ASAP, but the hourly buffer makes it less expensive

func (Keeper) BeginBlocker

func (k Keeper) BeginBlocker(ctx sdk.Context)

func (Keeper) BurnRedeemedStTokens

func (k Keeper) BurnRedeemedStTokens(ctx sdk.Context, stTokensToBurn sdk.Coins, redemptionAddress string) error

Burn stTokens from the redemption account - this requires sending them to an module account first, then burning them from there. - we use the stakedym module account

func (Keeper) CheckIsOperatorAddress

func (k Keeper) CheckIsOperatorAddress(ctx sdk.Context, address string) error

CheckIsOperatorAddress checks if the given address is EITHER the safe admin OR operator admin address

func (Keeper) CheckIsSafeAddress

func (k Keeper) CheckIsSafeAddress(ctx sdk.Context, address string) error

CheckIsSafeAddress checks if the given address is the safe admin address

func (Keeper) CheckIsSafeOrOperatorAddress

func (k Keeper) CheckIsSafeOrOperatorAddress(ctx sdk.Context, address string) error

CheckIsSafeOrOperatorAddress checks if the given address is EITHER the safe admin OR operator admin address

func (Keeper) CheckRedemptionRateExceedsBounds

func (k Keeper) CheckRedemptionRateExceedsBounds(ctx sdk.Context) error

Checks whether the redemption rate has exceeded the inner or outer safety bounds and returns an error if so

func (Keeper) ConfirmDelegation

func (k Keeper) ConfirmDelegation(ctx sdk.Context, recordId uint64, txHash string, sender string) (err error)

Confirms a delegation has completed on the host zone, increments the internal delegated balance, and archives the record

func (Keeper) ConfirmUnbondedTokenSweep

func (k Keeper) ConfirmUnbondedTokenSweep(ctx sdk.Context, recordId uint64, txHash string, sender string) (err error)

Confirms that unbonded tokens have been sent back to stride and marks the unbonding record CLAIMABLE

func (Keeper) ConfirmUndelegation

func (k Keeper) ConfirmUndelegation(ctx sdk.Context, recordId uint64, txHash string, sender string) (err error)

Confirms that an undelegation has been completed on the host zone Updates the record status to UNBONDING_IN_PROGRESS, decrements the delegated balance and burns stTokens

func (Keeper) DelegationRecords

Queries the delegation records with an optional to include archived records

func (Keeper) DistributeClaims

func (k Keeper) DistributeClaims(ctx sdk.Context) error

Iterates all unbonding records and distributes unbonded tokens to redeemers This function will operate atomically by using a cache context wrapper when it's invoked. This means that if any redemption send fails across any unbonding records, all partial state will be reverted

func (Keeper) DistributeClaimsForUnbondingRecord

func (k Keeper) DistributeClaimsForUnbondingRecord(
	ctx sdk.Context,
	hostNativeIbcDenom string,
	claimAddress sdk.AccAddress,
	unbondingRecordId uint64,
) error

Distribute claims for a given unbonding record

func (Keeper) ExportGenesis

func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState

Exports the current state

func (Keeper) GetAccumulatingUnbondingRecord

func (k Keeper) GetAccumulatingUnbondingRecord(ctx sdk.Context) (unbondingRecord types.UnbondingRecord, err error)

Gets the ACCUMULATING unbonding record (there should only be one)

func (Keeper) GetAllActiveDelegationRecords

func (k Keeper) GetAllActiveDelegationRecords(ctx sdk.Context) (delegationRecords []types.DelegationRecord)

Returns all active delegation records

func (Keeper) GetAllActiveUnbondingRecords

func (k Keeper) GetAllActiveUnbondingRecords(ctx sdk.Context) (unbondingRecords []types.UnbondingRecord)

Returns all active unbonding records

func (Keeper) GetAllArchivedDelegationRecords

func (k Keeper) GetAllArchivedDelegationRecords(ctx sdk.Context) (delegationRecords []types.DelegationRecord)

Returns all active delegation records

func (Keeper) GetAllArchivedUnbondingRecords

func (k Keeper) GetAllArchivedUnbondingRecords(ctx sdk.Context) (unbondingRecords []types.UnbondingRecord)

Returns all unbonding records that have been archived

func (Keeper) GetAllRedemptionRecords

func (k Keeper) GetAllRedemptionRecords(ctx sdk.Context) (redemptionRecords []types.RedemptionRecord)

Returns all redemption records

func (Keeper) GetAllSlashRecords

func (k Keeper) GetAllSlashRecords(ctx sdk.Context) (slashRecords []types.SlashRecord)

Returns all slash records

func (Keeper) GetAllTransferInProgressId

func (k Keeper) GetAllTransferInProgressId(ctx sdk.Context) (transferInProgressRecordIds []types.TransferInProgressRecordIds)

Get all pending transfers

func (Keeper) GetAllUnbondingRecordsByStatus

func (k Keeper) GetAllUnbondingRecordsByStatus(ctx sdk.Context, status types.UnbondingRecordStatus) (unbondingRecords []types.UnbondingRecord)

Returns all unbonding records with a specific status Searches only active records

func (Keeper) GetArchivedDelegationRecord

func (k Keeper) GetArchivedDelegationRecord(ctx sdk.Context, recordId uint64) (delegationRecord types.DelegationRecord, found bool)

Reads a delegation record from the archive store

func (Keeper) GetArchivedUnbondingRecord

func (k Keeper) GetArchivedUnbondingRecord(ctx sdk.Context, recordId uint64) (unbondingRecord types.UnbondingRecord, found bool)

Reads a unbonding record from the archive store

func (Keeper) GetDelegationRecord

func (k Keeper) GetDelegationRecord(ctx sdk.Context, recordId uint64) (delegationRecord types.DelegationRecord, found bool)

Reads a delegation record from the active store

func (Keeper) GetHostZone

func (k Keeper) GetHostZone(ctx sdk.Context) (hostZone types.HostZone, err error)

Reads a host zone from the store There should always be a host zone, so this should error if it is not found

func (Keeper) GetRedemptionRecord

func (k Keeper) GetRedemptionRecord(ctx sdk.Context, unbondingRecordId uint64, address string) (redemptionRecord types.RedemptionRecord, found bool)

Reads a redemption record from the store

func (Keeper) GetRedemptionRecordsFromAddress

func (k Keeper) GetRedemptionRecordsFromAddress(ctx sdk.Context, address string) (redemptionRecords []types.RedemptionRecord)

Returns all redemption records for a given address

func (Keeper) GetRedemptionRecordsFromUnbondingId

func (k Keeper) GetRedemptionRecordsFromUnbondingId(ctx sdk.Context, unbondingRecordId uint64) (redemptionRecords []types.RedemptionRecord)

Returns all redemption records for a given unbonding record

func (Keeper) GetTransferInProgressRecordId

func (k Keeper) GetTransferInProgressRecordId(ctx sdk.Context, channelId string, sequence uint64) (recordId uint64, found bool)

Gets the record ID for a pending outbound transfer of native tokens

func (Keeper) GetUnbondingRecord

func (k Keeper) GetUnbondingRecord(ctx sdk.Context, recordId uint64) (unbondingRecord types.UnbondingRecord, found bool)

Reads a unbonding record from the active store

func (Keeper) GetUnhaltedHostZone

func (k Keeper) GetUnhaltedHostZone(ctx sdk.Context) (hostZone types.HostZone, err error)

Reads a host zone from the store and errors if the host zone is halted

func (Keeper) HaltZone

func (k Keeper) HaltZone(ctx sdk.Context)

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

func (Keeper) HostZone

Queries the host zone struct

func (Keeper) IncrementSlashRecordId

func (k Keeper) IncrementSlashRecordId(ctx sdk.Context) uint64

Increments the current slash record ID and returns the new ID

func (Keeper) InitGenesis

func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState)

Initializes the genesis state in the store

func (Keeper) LiquidStake

func (k Keeper) LiquidStake(ctx sdk.Context, liquidStaker string, nativeAmount sdkmath.Int) (stToken sdk.Coin, err error)

Liquid stakes native tokens and returns stTokens to the user The staker's native tokens (which exist as an IBC denom on stride) are escrowed in the deposit account StTokens are minted at the current redemption rate

func (Keeper) LiquidStakeAndDistributeFees

func (k Keeper) LiquidStakeAndDistributeFees(ctx sdk.Context) error

Liquid stakes tokens in the fee account and distributes them to the fee collector

func (Keeper) Logger

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

func (Keeper) MarkFinishedUnbondings

func (k Keeper) MarkFinishedUnbondings(ctx sdk.Context)

Checks for any unbonding records that have finished unbonding, identified by having status UNBONDING_IN_PROGRESS and an unbonding that's older than the current time. Records are annotated with a new status UNBONDED

func (Keeper) OnAcknowledgementPacket

func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte) error

OnAcknowledgementPacket success: Update the DelegationRecord's status to DELEGATION_QUEUE OnAcknowledgementPacket failure: Delete the DelegationRecord

func (Keeper) OnTimeoutPacket

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

OnTimeoutPacket: Delete the DelegationRecord

func (Keeper) PostRedemptionRateToOracles

func (k Keeper) PostRedemptionRateToOracles(ctx sdk.Context) error

Pushes a redemption rate update to the ICA oracle

func (Keeper) PrepareDelegation

func (k Keeper) PrepareDelegation(ctx sdk.Context, epochNumber uint64, epochDuration time.Duration) error

IBC transfers all DYM in the deposit account and sends it to the delegation account

func (Keeper) PrepareUndelegation

func (k Keeper) PrepareUndelegation(ctx sdk.Context, epochNumber uint64) error

Freezes the ACCUMULATING record by changing the status to UNBONDING_QUEUE and updating the native token amounts on the unbonding and redemption records

func (Keeper) RedeemStake

func (k Keeper) RedeemStake(ctx sdk.Context, redeemer string, stTokenAmount sdkmath.Int) (nativeToken sdk.Coin, err error)

Takes custody of staked tokens in an escrow account, updates the current accumulating UnbondingRecord with the amount taken, and creates or updates the RedemptionRecord for this user

func (Keeper) RedemptionRecord

Queries a single user redemption record

func (Keeper) RedemptionRecords

Queries all redemption records with an optional filter by address

func (Keeper) RemoveDelegationRecord

func (k Keeper) RemoveDelegationRecord(ctx sdk.Context, recordId uint64)

Removes a delegation record from the active store

func (Keeper) RemoveHostZone

func (k Keeper) RemoveHostZone(ctx sdk.Context)

Removes a host zone from the store Note: This is only for testing - it should never be used elsewhere

func (Keeper) RemoveRedemptionRecord

func (k Keeper) RemoveRedemptionRecord(ctx sdk.Context, unbondingRecordId uint64, address string)

Removes a redemption record from the store

func (Keeper) RemoveTransferInProgressRecordId

func (k Keeper) RemoveTransferInProgressRecordId(ctx sdk.Context, channelId string, sequence uint64)

Remove the record ID for a pending outbound transfer of native tokens Happens after the packet acknowledement comes back to stride

func (Keeper) RemoveUnbondingRecord

func (k Keeper) RemoveUnbondingRecord(ctx sdk.Context, recordId uint64)

Removes an unbonding record from the active store

func (Keeper) SafelyDistributeClaims

func (k Keeper) SafelyDistributeClaims(ctx sdk.Context) error

Runs distribute claims with a cache context wrapper so revert any partial state changes

func (Keeper) SafelyLiquidStakeAndDistributeFees

func (k Keeper) SafelyLiquidStakeAndDistributeFees(ctx sdk.Context) error

Liquid stakes fees with a cache context wrapper so revert any partial state changes

func (Keeper) SafelyPrepareDelegation

func (k Keeper) SafelyPrepareDelegation(ctx sdk.Context, epochNumber uint64, epochDuration time.Duration) error

Runs prepare delegations with a cache context wrapper so revert any partial state changes

func (Keeper) SafelyPrepareUndelegation

func (k Keeper) SafelyPrepareUndelegation(ctx sdk.Context, epochNumber uint64) error

Runs prepare undelegations with a cache context wrapper so revert any partial state changes

func (Keeper) SafelySetDelegationRecord

func (k Keeper) SafelySetDelegationRecord(ctx sdk.Context, delegationRecord types.DelegationRecord) error

Writes a delegation record to the store only if a record does not already exist for that ID

func (Keeper) SafelySetUnbondingRecord

func (k Keeper) SafelySetUnbondingRecord(ctx sdk.Context, unbondingRecord types.UnbondingRecord) error

Sets the unbonding record only if a record does not already exist for that ID

func (Keeper) SetArchivedDelegationRecord

func (k Keeper) SetArchivedDelegationRecord(ctx sdk.Context, delegationRecord types.DelegationRecord)

Writes a delegation record to the archive store

func (Keeper) SetArchivedUnbondingRecord

func (k Keeper) SetArchivedUnbondingRecord(ctx sdk.Context, unbondingRecord types.UnbondingRecord)

Writes an unbonding record to the archive store

func (Keeper) SetDelegationRecord

func (k Keeper) SetDelegationRecord(ctx sdk.Context, delegationRecord types.DelegationRecord)

Writes a delegation record to the active store

func (Keeper) SetHostZone

func (k Keeper) SetHostZone(ctx sdk.Context, hostZone types.HostZone)

Writes a host zone to the store

func (Keeper) SetRedemptionRecord

func (k Keeper) SetRedemptionRecord(ctx sdk.Context, redemptionRecord types.RedemptionRecord)

Writes a redemption record to the store

func (Keeper) SetSlashRecord

func (k Keeper) SetSlashRecord(ctx sdk.Context, slashRecord types.SlashRecord)

Writes a slash record to the store

func (Keeper) SetTransferInProgressRecordId

func (k Keeper) SetTransferInProgressRecordId(ctx sdk.Context, channelId string, sequence uint64, recordId uint64)

Stores the record ID for a pending outbound transfer of native tokens

func (Keeper) SetUnbondingRecord

func (k Keeper) SetUnbondingRecord(ctx sdk.Context, unbondingRecord types.UnbondingRecord)

Writes an unbonding record to the active store

func (Keeper) SlashRecords

Queries all slash records

func (Keeper) UnbondingRecords

Queries the unbonding records with an optional to include archived records

func (Keeper) UpdateRedemptionRate

func (k Keeper) UpdateRedemptionRate(ctx sdk.Context) error

Updates the redemption rate for each host zone At a high level, the redemption rate is equal to the amount of native tokens locked divided by the stTokens in existence. The equation is broken down further into the following sub-components:

Native Tokens Locked:
  1. Deposit Account Balance: tokens deposited from liquid stakes, that are still living on Stride
  2. Undelegated Balance:     tokens that are ready to be staked
                              (they're either currently in the delegation account or currently being transferred there)
  3. Delegated Balance:       Delegations on the host zone

StToken Amount:
  1. Total Supply of the stToken

Redemption Rate = (Deposit Account Balance + Undelegated Balance + Delegated Balance) / (stToken Supply)

Note: Reinvested tokens are sent to the deposit account and are automatically included in this formula

func (Keeper) VerifyImpliedRedemptionRateFromUnbonding

func (k Keeper) VerifyImpliedRedemptionRateFromUnbonding(ctx sdk.Context, stTokenSupplyBefore sdkmath.Int, delegatedBalanceBefore sdkmath.Int) error

Sanity check helper for checking diffs on delegated balance and stToken supply are within outer RR bounds

Jump to

Keyboard shortcuts

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