Documentation
¶
Index ¶
- Constants
- func NewMsgServer(keeper *Keeper) types.MsgServer
- func NewQueryServer(keeper *Keeper) types.QueryServer
- type Keeper
- func (k *Keeper) AllowSwapInAmount(ctx sdk.Context, swapInAsset sdk.Coin, vault types.VaultAccount) (bool, string, error)
- func (k *Keeper) AllowSwapOutAmount(ctx sdk.Context, assets sdk.Coin, vault types.VaultAccount) (bool, string, error)
- func (k *Keeper) BeginBlocker(ctx sdk.Context) error
- func (k Keeper) CalculateAccruedAUMFee(ctx sdk.Context, vault types.VaultAccount, totalAssets sdkmath.Int) (sdkmath.Int, error)
- func (k Keeper) CalculateAccruedAUMFeePayment(ctx sdk.Context, vault types.VaultAccount, totalAssets sdkmath.Int) (sdk.Coin, error)
- func (k Keeper) CalculateAccruedInterest(ctx sdk.Context, vault types.VaultAccount, principal sdk.Coin) (sdkmath.Int, error)
- func (k Keeper) CalculateOutstandingFeeUnderlying(ctx sdk.Context, vault types.VaultAccount) (sdkmath.Int, error)
- func (k Keeper) CalculateVaultTotalAssets(ctx sdk.Context, vault *types.VaultAccount, principal sdk.Coin) (sdkmath.Int, error)
- func (k Keeper) CanPayInterestDuration(ctx sdk.Context, vault *types.VaultAccount, duration int64) (bool, error)
- func (k Keeper) ConvertDepositToSharesInUnderlyingAsset(ctx sdk.Context, vault types.VaultAccount, in sdk.Coin) (sdk.Coin, error)
- func (k Keeper) ConvertSharesToRedeemCoin(ctx sdk.Context, vault types.VaultAccount, shares math.Int, redeemDenom string) (sdk.Coin, error)
- func (k *Keeper) CreateVault(ctx sdk.Context, attributes VaultAttributer) (*types.VaultAccount, error)
- func (k *Keeper) EndBlocker(ctx sdk.Context) error
- func (k Keeper) EstimateTotalVaultValue(ctx sdk.Context, vault *types.VaultAccount) (sdk.Coin, error)
- func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState
- func (k *Keeper) FindVaultAccount(ctx sdk.Context, id string) (*types.VaultAccount, error)
- func (k Keeper) FromUnderlyingAssetAmount(ctx sdk.Context, vault types.VaultAccount, inAmount math.Int, ...) (math.Int, error)
- func (k Keeper) GetAUMFeeAddress(ctx sdk.Context) (sdk.AccAddress, error)
- func (k Keeper) GetAuthority() []byte
- func (k Keeper) GetNAVPerShareInUnderlyingAsset(ctx sdk.Context, vault types.VaultAccount) (math.Int, error)
- func (k Keeper) GetTVVInUnderlyingAsset(ctx sdk.Context, vault types.VaultAccount) (math.Int, error)
- func (k Keeper) GetVault(ctx sdk.Context, address sdk.AccAddress) (*types.VaultAccount, error)
- func (k *Keeper) GetVaults(ctx context.Context) ([]sdk.AccAddress, error)
- func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState)
- func (k Keeper) MigrateVaultAccountPaymentDenomDefaults(ctx sdk.Context) error
- func (k Keeper) OpenKVStore(ctx sdk.Context) store.KVStore
- func (k Keeper) PerformVaultFeeTransfer(ctx sdk.Context, vault *types.VaultAccount) error
- func (k Keeper) PerformVaultInterestTransfer(ctx sdk.Context, vault *types.VaultAccount) error
- func (k Keeper) RescheduleFeeTimeout(ctx sdk.Context, vault *types.VaultAccount, oldTimeout int64) error
- func (k Keeper) ReschedulePayoutTimeout(ctx sdk.Context, vault *types.VaultAccount, oldTimeout int64) error
- func (k Keeper) SafeAddPayoutVerification(ctx sdk.Context, vault *types.VaultAccount) error
- func (k Keeper) SafeEnqueueFeeTimeout(ctx sdk.Context, vault *types.VaultAccount) error
- func (k Keeper) SafeEnqueuePayoutTimeout(ctx sdk.Context, vault *types.VaultAccount) error
- func (k *Keeper) SetMaxInterestRate(ctx sdk.Context, vault *types.VaultAccount, maxRate string) error
- func (k *Keeper) SetMaxSwapInValue(ctx sdk.Context, vault *types.VaultAccount, maxSwapIn string, authority string) error
- func (k *Keeper) SetMaxSwapOutValue(ctx sdk.Context, vault *types.VaultAccount, maxSwapOut string, ...) error
- func (k *Keeper) SetMinInterestRate(ctx sdk.Context, vault *types.VaultAccount, minRate string) error
- func (k *Keeper) SetMinSwapInValue(ctx sdk.Context, vault *types.VaultAccount, minSwapIn string, authority string) error
- func (k *Keeper) SetMinSwapOutValue(ctx sdk.Context, vault *types.VaultAccount, minSwapOut string, ...) error
- func (k *Keeper) SetSwapInEnable(ctx sdk.Context, vault *types.VaultAccount, enabled bool) error
- func (k *Keeper) SetSwapOutEnable(ctx sdk.Context, vault *types.VaultAccount, enabled bool) error
- func (k *Keeper) SetVaultAccount(ctx sdk.Context, vault *types.VaultAccount) error
- func (k *Keeper) SetVaultLookup(ctx context.Context, vault *types.VaultAccount) error
- func (k *Keeper) SetWithdrawalDelay(ctx sdk.Context, vault *types.VaultAccount, delaySeconds uint64, ...) error
- func (k *Keeper) SwapIn(ctx sdk.Context, vaultAddr, recipient sdk.AccAddress, asset sdk.Coin) (*sdk.Coin, error)
- func (k *Keeper) SwapOut(ctx sdk.Context, vaultAddr, owner sdk.AccAddress, shares sdk.Coin, ...) (uint64, error)
- func (k Keeper) ToUnderlyingAssetAmount(ctx sdk.Context, vault types.VaultAccount, in sdk.Coin) (math.Int, error)
- func (k Keeper) UnitPriceFraction(ctx sdk.Context, srcDenom string, vault types.VaultAccount) (num, den math.Int, err error)
- func (k Keeper) UpdateInterestRates(ctx sdk.Context, vault *types.VaultAccount, currentRate, desiredRate string) error
- func (k *Keeper) UpdateVaultAUMFeeBips(ctx sdk.Context, vault *types.VaultAccount, bips uint32, authority string) error
- func (k Keeper) ValidateInterestRateLimits(minRateStr, maxRateStr string) error
- type VaultAttributer
Constants ¶
const ( Supply = 0 NoFixedSupply = false NoForceTransfer = false NoGovControl = false )
const ( // AutoReconcilePayoutDuration is the time period (in seconds) used to forecast if a vault has // sufficient funds to cover future interest payments. AutoReconcilePayoutDuration = 24 * interest.SecondsPerHour )
const ( // AutoReconcileTimeout is the duration (in seconds) that a vault is considered // recently reconciled and is exempt from automatic interest checks. AutoReconcileTimeout = 20 * interest.SecondsPerHour )
const ( // MaxSwapOutBatchSize is the maximum number of pending swap-out requests // to process in a single EndBlocker invocation. This prevents a large queue // from consuming excessive block time and memory. This is a temporary value // and we will need to do more analysis on a proper batch size. // See https://github.com/ProvLabs/vault/issues/75. MaxSwapOutBatchSize = 100 )
Variables ¶
This section is empty.
Functions ¶
func NewMsgServer ¶
NewMsgServer creates a new MsgServer for the module.
func NewQueryServer ¶
func NewQueryServer(keeper *Keeper) types.QueryServer
Types ¶
type Keeper ¶
type Keeper struct {
AddressCodec address.Codec
AuthKeeper types.AccountKeeper
MarkerKeeper types.MarkerKeeper
BankKeeper types.BankKeeper
NameKeeper types.NameKeeper
AttrKeeper types.AttributeKeeper
Params collections.Item[types.Params]
Vaults collections.Map[sdk.AccAddress, []byte]
PayoutVerificationSet collections.KeySet[sdk.AccAddress]
PayoutTimeoutQueue *queue.PayoutTimeoutQueue
FeeTimeoutQueue *queue.FeeTimeoutQueue
PendingSwapOutQueue *queue.PendingSwapOutQueue
// contains filtered or unexported fields
}
func NewKeeper ¶
func NewKeeper( cdc codec.Codec, storeService store.KVStoreService, eventService event.Service, addressCodec address.Codec, authority []byte, authKeeper types.AccountKeeper, markerkeeper types.MarkerKeeper, bankkeeper types.BankKeeper, namekeeper types.NameKeeper, attributekeeper types.AttributeKeeper, ) *Keeper
NewMsgServer creates a new Keeper for the module.
func (*Keeper) AllowSwapInAmount ¶ added in v1.1.0
func (k *Keeper) AllowSwapInAmount(ctx sdk.Context, swapInAsset sdk.Coin, vault types.VaultAccount) (bool, string, error)
AllowSwapInAmount checks whether a swap-in amount meets the minimum and maximum value requirements for a vault.
func (*Keeper) AllowSwapOutAmount ¶ added in v1.1.0
func (k *Keeper) AllowSwapOutAmount(ctx sdk.Context, assets sdk.Coin, vault types.VaultAccount) (bool, string, error)
AllowSwapOutAmount checks whether a swap-out amount meets the minimum and maximum value requirements for a vault.
func (*Keeper) BeginBlocker ¶
BeginBlocker is a hook that is called at the beginning of every block.
func (Keeper) CalculateAccruedAUMFee ¶ added in v1.1.0
func (k Keeper) CalculateAccruedAUMFee(ctx sdk.Context, vault types.VaultAccount, totalAssets sdkmath.Int) (sdkmath.Int, error)
CalculateAccruedAUMFee calculates the AUM fees that would have accrued for the vault from its FeePeriodStart to the current block time, based on the provided total assets. It returns the fee amount in the underlying asset and does not mutate state.
func (Keeper) CalculateAccruedAUMFeePayment ¶ added in v1.1.0
func (k Keeper) CalculateAccruedAUMFeePayment(ctx sdk.Context, vault types.VaultAccount, totalAssets sdkmath.Int) (sdk.Coin, error)
CalculateAccruedAUMFeePayment calculates the AUM fees that would have accrued for the vault from its FeePeriodStart to the current block time, converted to the vault's PaymentDenom.
func (Keeper) CalculateAccruedInterest ¶ added in v1.1.0
func (k Keeper) CalculateAccruedInterest(ctx sdk.Context, vault types.VaultAccount, principal sdk.Coin) (sdkmath.Int, error)
CalculateAccruedInterest calculates the interest that would have accrued for the vault from its PeriodStart to the current block time, based on the provided principal. It returns the interest amount (which can be negative) and does not mutate state.
func (Keeper) CalculateOutstandingFeeUnderlying ¶ added in v1.1.0
func (k Keeper) CalculateOutstandingFeeUnderlying(ctx sdk.Context, vault types.VaultAccount) (sdkmath.Int, error)
CalculateOutstandingFeeUnderlying converts the vault's outstanding AUM fees into the equivalent amount of the underlying asset.
func (Keeper) CalculateVaultTotalAssets ¶
func (k Keeper) CalculateVaultTotalAssets(ctx sdk.Context, vault *types.VaultAccount, principal sdk.Coin) (sdkmath.Int, error)
CalculateVaultTotalAssets returns the total value of the vault's assets, including the interest that would have accrued from PeriodStart to the current block time, and subtracting the AUM fees accrued since FeePeriodStart, without mutating state.
VALUATION LOGIC (Net TVV): This method subtracts the **OutstandingAumFee** from the gross total to ensure share pricing (NAV) reflects the actual equity owned by shareholders, excluding vault liabilities.
If no rate is set or accrual has not started, it returns the provided principal unchanged.
func (Keeper) CanPayInterestDuration ¶ added in v1.1.0
func (k Keeper) CanPayInterestDuration(ctx sdk.Context, vault *types.VaultAccount, duration int64) (bool, error)
CanPayInterestDuration determines whether the vault can fulfill the projected interest payment/refund over the given duration based on current reserves and principal TVV.
Interest is checked against vault reserves (positive interest) or principal marker underlying balance (negative interest).
It returns true only if interest checks pass.
func (Keeper) ConvertDepositToSharesInUnderlyingAsset ¶
func (k Keeper) ConvertDepositToSharesInUnderlyingAsset(ctx sdk.Context, vault types.VaultAccount, in sdk.Coin) (sdk.Coin, error)
ConvertSharesToRedeemCoin converts a share amount into a payout coin in redeemDenom using the current TVV and total share supply (pro-rata, single-floor arithmetic).
Steps:
- Look up the unit price fraction for redeemDenom → underlying via UnitPriceFraction.
- Compute the payout in one step using CalculateRedeemProRataFraction(shares, totalShares, TVV, priceNum, priceDen) where TVV is from principal (marker) balances.
Returns a coin in redeemDenom. This function performs calculation only; callers must enforce liquidity/policy. If shares <= 0, returns a zero-amount coin.
func (Keeper) ConvertSharesToRedeemCoin ¶
func (k Keeper) ConvertSharesToRedeemCoin(ctx sdk.Context, vault types.VaultAccount, shares math.Int, redeemDenom string) (sdk.Coin, error)
ConvertSharesToRedeemCoin converts a share amount into a payout coin in redeemDenom using the current TVV and total share supply (both pro-rata, floor arithmetic).
Steps:
- Convert shares → underlying via CalculateAssetsFromShares(shares, totalShares, TVV) where TVV is from principal (marker) balances.
- Convert the resulting underlying amount to redeemDenom via FromUnderlyingAssetAmount (identity fast-path if redeemDenom == vault.UnderlyingAsset).
Returns a coin in redeemDenom. This function performs calculation only; callers must enforce liquidity/policy. If shares <= 0, returns a zero-amount coin.
func (*Keeper) CreateVault ¶
func (k *Keeper) CreateVault(ctx sdk.Context, attributes VaultAttributer) (*types.VaultAccount, error)
CreateVault creates a new vault and its corresponding share marker atomically.
The process involves:
- Creating and persisting a new VaultAccount and its lookup entries.
- Initializing the fee timeout queue for the new vault.
- Creating, finalizing, and activating a restricted marker for the vault's shares.
- Performing a pre-flight check against the principal/payment path by calling SendRestrictionFn with vault.PrincipalMarkerAddress() to ensure the fee collection address is permissioned to receive the payment denomination.
All steps are performed within a cache context. If any step fails, including the pre-flight permission check, all state changes are discarded to prevent the creation of inconsistent or "orphan" vaults.
func (*Keeper) EndBlocker ¶
EndBlocker is a hook that is called at the end of every block.
func (Keeper) EstimateTotalVaultValue ¶ added in v1.0.9
func (k Keeper) EstimateTotalVaultValue(ctx sdk.Context, vault *types.VaultAccount) (sdk.Coin, error)
EstimateTotalVaultValue returns an estimated Total Vault Value (TVV) as a Coin denominated in the vault's underlying asset. It composes two steps without mutating state:
- Reads the current principal-only TVV from on-chain balances at the principal (marker) account (excludes reserves and unpaid interest).
- Applies the vault's interest model to estimate unpaid interest through CalculateVaultTotalAssets, producing a best-effort TVV as of the query block. The result is floor-rounded and suitable for pro-rata calculations.
If the vault is paused, the estimation honors the keeper’s paused logic inside GetTVVInUnderlyingAsset.
Returns an sdk.Coin { Denom: vault.UnderlyingAsset, Amount: ... }.
func (Keeper) ExportGenesis ¶
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState
ExportGenesis exports the current state of the vault module.
func (*Keeper) FindVaultAccount ¶
FindVaultAccount retrieves a vault by its address or share denomination.
func (Keeper) FromUnderlyingAssetAmount ¶ added in v1.1.0
func (k Keeper) FromUnderlyingAssetAmount(ctx sdk.Context, vault types.VaultAccount, inAmount math.Int, targetDenom string) (math.Int, error)
FromUnderlyingAssetAmount converts an amount of vault.UnderlyingAsset into the equivalent value in targetDenom using integer floor arithmetic.
Formula:
value_in_target = inAmount * priceDenominator / priceNumerator
where (priceNumerator, priceDenominator) are from UnitPriceFraction(targetDenom → underlying).
func (Keeper) GetAUMFeeAddress ¶ added in v1.1.0
GetAUMFeeAddress returns the address where AUM fees are collected.
func (Keeper) GetAuthority ¶
GetAuthority returns the module's authority.
func (Keeper) GetNAVPerShareInUnderlyingAsset ¶
func (k Keeper) GetNAVPerShareInUnderlyingAsset(ctx sdk.Context, vault types.VaultAccount) (math.Int, error)
GetNAVPerShareInUnderlyingAsset returns the floor NAV per share in units of vault.UnderlyingAsset.
Paused fast-path:
- If vault.Paused is true, this function short-circuits and returns vault.PausedBalance.Amount (ignores live TVV and share supply).
Computation (when not paused):
- TVV(underlying) is obtained from GetTVVInUnderlyingAsset (includes current vault holdings in underlying units).
- totalShareSupply is taken from vault.TotalShares.Amount (the recorded share supply).
- If total shares == 0, returns 0. Otherwise returns TVV / totalShareSupply (floor).
func (Keeper) GetTVVInUnderlyingAsset ¶
func (k Keeper) GetTVVInUnderlyingAsset(ctx sdk.Context, vault types.VaultAccount) (math.Int, error)
GetTVVInUnderlyingAsset returns the Total Vault Value (TVV) expressed in vault.UnderlyingAsset using floor arithmetic.
Paused fast-path:
- If vault.Paused is true, this function short-circuits and returns vault.PausedBalance.Amount (no balance iteration or NAV conversion).
Source of truth (when not paused):
- TVV sums the balances held at the vault’s *principal* account, i.e. the marker address for vault.PrincipalMarkerAddress().
- The vault account’s own balances are treated as *reserves* and are not included here.
Computation (when not paused):
- Iterate all non-share-denom balances at the marker (principal) account.
- Convert each balance to underlying units via ToUnderlyingAssetAmount.
- Sum the converted amounts (floor at each multiplication/division step).
func (Keeper) GetVault ¶
func (k Keeper) GetVault(ctx sdk.Context, address sdk.AccAddress) (*types.VaultAccount, error)
GetVault returns the vault account for the given address. This function will return nil if nothing exists at this address.
func (Keeper) InitGenesis ¶
func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState)
InitGenesis initializes the vault module state from genesis.
func (Keeper) MigrateVaultAccountPaymentDenomDefaults ¶ added in v1.0.14
MigrateVaultAccountPaymentDenomDefaults updates legacy VaultAccount state created prior to v1.0.13 by normalizing empty payment denom fields.
In versions <= v1.0.13, VaultAccount instances could be persisted with an empty PaymentDenom. Newer versions require a valid payment denom, which by default should be the vault’s underlying asset denom.
This migration iterates all accounts in the auth store, identifies VaultAccount instances, and for any vault with an empty PaymentDenom sets it to UnderlyingAsset. Updated vault accounts are validated and re-persisted using the auth keeper.
This function is intended to be executed once from an upgrade handler and is idempotent; running it multiple times will not modify already-migrated state.
func (Keeper) OpenKVStore ¶ added in v1.1.0
OpenKVStore returns a KVStore for the module.
func (Keeper) PerformVaultFeeTransfer ¶ added in v1.1.0
PerformVaultFeeTransfer computes and collects the AUM technology fee from the vault's principal marker account using its configured AumFeeBips.
The fee is calculated based on the **Gross TVV** (the literal sum of all assets in the marker) and collected in the vault's configured PaymentDenom.
This method implements a "collect-what-is-available" strategy: it attempts to transfer the total outstanding fee (accrued + previously unpaid), but caps the collection at the principal marker's current PaymentDenom balance. Any uncollected remainder is recorded in OutstandingAumFee to be retried during the next reconciliation.
An EventVaultFeeCollected is emitted upon success.
func (Keeper) PerformVaultInterestTransfer ¶
PerformVaultInterestTransfer applies accrued interest between the vault and the marker account if the current block time is beyond PeriodStart.
Interest is settled exclusively in the vault's defined UnderlyingAsset. Interest is calculated based on the **Gross TVV** (the literal sum of all assets in the marker).
- Positive Interest: Paid from vault reserves to the marker. Fails if reserves are insufficient.
- Negative Interest: Refunded from marker principal to the vault. This is bounded by the available balance of the UnderlyingAsset in the marker account.
IMPORTANT: If the vault utilizes composite reserves (holding multiple token types), secondary assets are NOT liquidated or transferred to satisfy interest obligations. If the marker owes negative interest but lacks sufficient liquidity in the UnderlyingAsset, the transfer is capped at the available underlying balance, potentially resulting in a partial payment.
An EventVaultReconcile is emitted upon success. This method does not modify PeriodStart.
func (Keeper) RescheduleFeeTimeout ¶ added in v1.1.0
func (k Keeper) RescheduleFeeTimeout(ctx sdk.Context, vault *types.VaultAccount, oldTimeout int64) error
RescheduleFeeTimeout updates a vault's fee timeout to the next window (now + AutoReconcileTimeout) without resetting the FeePeriodStart. This is used for transient reconciliation failures to preserve accrued fees while preventing block-to-block retry loops.
func (Keeper) ReschedulePayoutTimeout ¶ added in v1.1.0
func (k Keeper) ReschedulePayoutTimeout(ctx sdk.Context, vault *types.VaultAccount, oldTimeout int64) error
ReschedulePayoutTimeout updates a vault's payout timeout to the next window (now + AutoReconcileTimeout) without resetting the PeriodStart. This is used for transient reconciliation failures to preserve accrued interest while preventing block-to-block retry loops.
func (Keeper) SafeAddPayoutVerification ¶ added in v1.1.0
SafeAddPayoutVerification clears any existing timeout entry for the given vault (if any), sets the vault's period start to the current block time, clears the period timeout, persists the vault, and stores the vault in the PayoutVerificationSet.
This ensures a vault is not present in both the verification set and timeout queues at the same time. Typically called after enabling interest or completing a reconciliation so the next accrual cycle begins cleanly.
func (Keeper) SafeEnqueueFeeTimeout ¶ added in v1.1.0
SafeEnqueueFeeTimeout clears any existing fee timeout entry for the given vault (if any), sets the vault's fee period start to the current block time, sets a new fee period timeout at (now + AutoReconcileTimeout), persists the vault, and enqueues the timeout entry in the FeeTimeoutQueue.
func (Keeper) SafeEnqueuePayoutTimeout ¶ added in v1.1.0
SafeEnqueuePayoutTimeout clears any existing timeout entry for the given vault (if any), sets the vault's period start to the current block time, sets a new period timeout at (now + AutoReconcileTimeout), persists the vault, and enqueues the timeout entry in the PayoutTimeoutQueue.
This ensures a vault is not present in both the timeout and verification queues at the same time. Typically called after a vault has been marked as payable so it will be revisited after the auto-reconcile window.
func (*Keeper) SetMaxInterestRate ¶
func (k *Keeper) SetMaxInterestRate(ctx sdk.Context, vault *types.VaultAccount, maxRate string) error
SetMaxInterestRate sets the maximum interest rate for a vault. An empty string disables the maximum rate check.
func (*Keeper) SetMaxSwapInValue ¶ added in v1.1.0
func (k *Keeper) SetMaxSwapInValue(ctx sdk.Context, vault *types.VaultAccount, maxSwapIn string, authority string) error
SetMaxSwapInValue updates the maximum swap-in value for a vault.
func (*Keeper) SetMaxSwapOutValue ¶ added in v1.1.0
func (k *Keeper) SetMaxSwapOutValue(ctx sdk.Context, vault *types.VaultAccount, maxSwapOut string, authority string) error
SetMaxSwapOutValue updates the maximum swap-out value for a vault.
func (*Keeper) SetMinInterestRate ¶
func (k *Keeper) SetMinInterestRate(ctx sdk.Context, vault *types.VaultAccount, minRate string) error
SetMinInterestRate sets the minimum interest rate for a vault. An empty string disables the minimum rate check.
func (*Keeper) SetMinSwapInValue ¶ added in v1.1.0
func (k *Keeper) SetMinSwapInValue(ctx sdk.Context, vault *types.VaultAccount, minSwapIn string, authority string) error
SetMinSwapInValue updates the minimum swap-in value for a vault.
func (*Keeper) SetMinSwapOutValue ¶ added in v1.1.0
func (k *Keeper) SetMinSwapOutValue(ctx sdk.Context, vault *types.VaultAccount, minSwapOut string, authority string) error
SetMinSwapOutValue updates the minimum swap-out value for a vault.
func (*Keeper) SetSwapInEnable ¶
SetSwapInEnable updates the SwapInEnabled flag for a given vault. It updates the vault account in the state and emits an EventToggleSwapIn event.
func (*Keeper) SetSwapOutEnable ¶
SetSwapOutEnable updates the SwapOutEnabled flag for a given vault. It updates the vault account in the state and emits an EventToggleSwapOut event.
func (*Keeper) SetVaultAccount ¶
SetVaultAccount validates and persists a VaultAccount using the auth keeper. Returns an error if validation fails.
func (*Keeper) SetVaultLookup ¶
SetVaultLookup stores a vault in the Vaults collection, keyed by its bech32 address. NOTE: should only be called by genesis and at vault creation. Returns an error if the vault is nil or the address cannot be parsed.
func (*Keeper) SetWithdrawalDelay ¶ added in v1.0.14
func (*Keeper) SwapIn ¶
func (k *Keeper) SwapIn(ctx sdk.Context, vaultAddr, recipient sdk.AccAddress, asset sdk.Coin) (*sdk.Coin, error)
SwapIn handles the process of depositing underlying assets into a vault in exchange for newly minted vault shares.
It performs the following steps:
- Retrieves the vault configuration for the given vault address.
- Verifies that swap-in is enabled for the vault.
- Reconciles the vault (interest and AUM fees) if due.
- Resolves the vault share marker address.
- Validates that the provided underlying asset matches the vault’s configured underlying denom.
- Calculates the number of shares to mint based on the deposit, current supply, and vault balance.
- Mints the computed amount of shares under the vault’s admin authority.
- Withdraws the minted shares from the vault to the recipient address.
- Sends the underlying asset from the recipient to the vault’s marker account.
10. Emits a SwapIn event with metadata for indexing and audit.
Returns the minted share amount on success, or an error if any step fails.
func (*Keeper) SwapOut ¶
func (k *Keeper) SwapOut(ctx sdk.Context, vaultAddr, owner sdk.AccAddress, shares sdk.Coin, redeemDenom string) (uint64, error)
SwapOut validates a swap-out request, calculates the resulting assets, escrows the user's shares, and enqueues a pending withdrawal request to be processed by the EndBlocker. It returns the unique ID of the newly queued request.
func (Keeper) ToUnderlyingAssetAmount ¶
func (k Keeper) ToUnderlyingAssetAmount(ctx sdk.Context, vault types.VaultAccount, in sdk.Coin) (math.Int, error)
ToUnderlyingAssetAmount converts an input coin into its value expressed in vault.UnderlyingAsset using integer floor arithmetic.
Formula:
value_in_underlying = in.Amount * priceNumerator / priceDenominator
where (priceNumerator, priceDenominator) are from UnitPriceFraction(in.Denom → underlying). This performs a pure conversion based on NAV (or identity if denom==underlying). It does not enforce whether the denom is accepted by the vault; such policy checks are handled elsewhere.
func (Keeper) UnitPriceFraction ¶
func (k Keeper) UnitPriceFraction(ctx sdk.Context, srcDenom string, vault types.VaultAccount) (num, den math.Int, err error)
UnitPriceFraction returns the unit price of srcDenom expressed in underlyingAsset as an integer fraction (numerator, denominator) using marker Net Asset Value (NAV).
Semantics
- Forward NAV (srcDenom → underlyingAsset): NAV.Price is total underlying units for NAV.Volume units of srcDenom. 1 srcDenom = NAV.Price.Amount / NAV.Volume underlyingAsset → (num, den) = (NAV.Price.Amount, NAV.Volume).
- Reverse NAV (underlyingAsset → srcDenom): NAV.Price is total srcDenom units for NAV.Volume units of underlyingAsset. 1 srcDenom = NAV.Volume / NAV.Price.Amount underlyingAsset → (num, den) = (NAV.Volume, NAV.Price.Amount).
The result is integer (floor-safe) arithmetic.
Source selection - Identity/peg fast-paths return (1, 1):
- If srcDenom == underlyingAsset
- If underlyingAsset == "uylds.fcc" (temporary 1:1 peg; see https://github.com/ProvLabs/vault/issues/73)
- If vault.PaymentDenom == "uylds.fcc" (temporary 1:1 peg; see https://github.com/ProvLabs/vault/issues/73)
- Otherwise read both forward and reverse NAVs:
- If only one exists, use it.
- If both exist, choose the one with the greater UpdatedBlockHeight (newest).
Errors - If neither NAV exists, return the lookup error (if any) or "nav not found for src/underlying". - For the selected NAV direction:
- Forward: error if NAV.Volume == 0 or NAV.Price.Amount == 0.
- Reverse: error if NAV.Price.Amount == 0 or NAV.Volume == 0.
Returns - (num, den) as math.Int, suitable for floor(x * num / den).
func (Keeper) UpdateInterestRates ¶
func (k Keeper) UpdateInterestRates(ctx sdk.Context, vault *types.VaultAccount, currentRate, desiredRate string) error
UpdateInterestRates sets the vault's current and desired interest rates and emits an EventVaultInterestChange. The modified account is persisted via the auth keeper.
func (*Keeper) UpdateVaultAUMFeeBips ¶ added in v1.1.0
func (k *Keeper) UpdateVaultAUMFeeBips(ctx sdk.Context, vault *types.VaultAccount, bips uint32, authority string) error
UpdateVaultAUMFeeBips reconciles outstanding AUM fees for the provided VaultAccount before updating the stored fee rate (in basis points).
This method ensures that all fees accrued under the old rate are accounted for before applying the new rate to future periods. It returns an error if the new bips value exceeds 10,000 (100%) or if reconciliation fails.
func (Keeper) ValidateInterestRateLimits ¶
ValidateInterestRateLimits checks that the provided minimum and maximum interest rates are valid decimal values, that neither exceeds the MaxAbsInterestRate ceiling in magnitude, and that the minimum rate is not greater than the maximum rate. The magnitude ceiling stops an admin from configuring bounds large enough to overflow the e^(rt) interest math and panic inside the block hooks. Empty values are treated as unset and pass validation.
type VaultAttributer ¶
type VaultAttributer interface {
GetAdmin() string
GetUnderlyingAsset() string
GetPaymentDenom() string
GetWithdrawalDelaySeconds() uint64
GetMinSwapInValue() string
GetMinSwapOutValue() string
GetMaxSwapInValue() string
GetMaxSwapOutValue() string
}
VaultAttributer provides the attributes for creating a new vault.