Skip to main content

VaultFormulas

VaultFormulas

Addresses

ChainAddress
Arbitrum Sepolia0x9454d1dfCDf41A32Ea25a05B70ebC54B05ACCfC1
Base Sepolia0x4F29Ae8f4F363B2ca5fb6ec10bA20705158E4A76
Base Mainnet0x5E31ee796Ff17c3BC5994A524F3969809Dd0cE8D

Functions

constructor

constructor(struct StorageInstance app_) public
Dev note

This contract is not designed to be upgradable and is strictly a logic contract. Hance, we are directly initializing the contract from the constructor.

balanceOf

function balanceOf(address account) public view returns (uint256)
Dev note

See {IERC20-balanceOf}.

totalSupply

function totalSupply() public view returns (uint256)
Dev note

See {IERC20-totalSupply}.

activeWithdrawRequest

Whether owner has an active withdraw request

function activeWithdrawRequest(address owner) public view returns (bool status)

Parameters

NameTypeDescription
owneraddressAddress for which to check request

Return Values

NameTypeDescription
statusboolfalse if request is nonexistent, complete, or expired, true otherwise

expiredWithdrawRequest

Whether owner has an expired withdraw request

function expiredWithdrawRequest(address owner) public view returns (bool status)

Parameters

NameTypeDescription
owneraddressAddress for which to check request

Return Values

NameTypeDescription
statusbooltrue if request expired, false if it's active, nonexistent, or completed

getInstantRedeemAvailable

Whether instant redeems are available. When true, ERC4626 methods will work without a pre-existing request, and attempting to increase a request will instantly execute it.

function getInstantRedeemAvailable() public returns (bool available)
Dev note

DomFiPerp.getTotalPnL() is extremely expensive, call _computeUtilizationRatio() and save results if reuse is necessary.

Return Values

NameTypeDescription
availableboolWhether instant redeems and withdraws are available

getUtilizationRatio

Compute current utilization ratio of the vault. Utilization ratio is the total size of all positions divided by the effective vault balance: the vault balance minus pending trader PnL, minus pending withdrawals.

function getUtilizationRatio() external returns (FPSigned utilizationRatio)

Return Values

NameTypeDescription
utilizationRatioFPSignedCurrent utilization ratio of the vault

_computeUtilizationRatio

function _computeUtilizationRatio() public returns (bool instantRedeemAvailable, FPSigned utilizationRatio)

previewRedeemRequest

Preview a withdraw request

function previewRedeemRequest(Shares shares, address account) external returns (uint64 duration, int64 offset)

Parameters

NameTypeDescription
sharesSharesShares that would be requested
accountaddressAccount for which to preview the request

Return Values

NameTypeDescription
durationuint64Duration of the resulting WithdrawRequest
offsetint64Time until the resulting request begins.

previewPenalty

Get the next penalty rate/max for a user, based on an existing expired request. User MUST have an expired request.

function previewPenalty(address user) public view returns (PerShare nextRate, uint64 remainingSeconds)

computePenalty

Apply a given penalty rate to a shares quantity

function computePenalty(
Shares shares,
PerShare penaltyRate,
uint64 maxPenaltySeconds
) public pure returns (
uint64 penalty
)

Parameters

NameTypeDescription
sharesSharesRequest quantity
penaltyRatePerShareRate to apply
maxPenaltySecondsuint64Maximum penalty returned

Return Values

NameTypeDescription
penaltyuint64Seconds that must be waited before request begins

getPendingWithdraw

Get the amount of collateral tied up in redeem requests. This is the lesser of pendingWithdraw and the current value of pendingRedeem.

function getPendingWithdraw() public view returns (uint256)

maxDeposit

Max deposit that receiver can receive. See EIP-4626.

function maxDeposit(address receiver) public view returns (uint256 maxAssets)

Parameters

NameTypeDescription
receiveraddressaddress that will be receiving the deposit

Return Values

NameTypeDescription
maxAssetsuint256Maximum collateral that can be deposited for receiver

maxMint

Max shares that can be minted to receiver. See EIP-4626.

function maxMint(address receiver) public view returns (Shares maxShares)

Parameters

NameTypeDescription
receiveraddressaddress that will be receiving the minted shares

Return Values

NameTypeDescription
maxSharesSharesMaximum collateral that can be minted for receiver

availableFraction

Compute the fraction of a request currently available to redeem or withdraw. Executing requests reduces the available fraction.

function availableFraction(address owner) public view returns (FPUnsigned redeemFraction)

Parameters

NameTypeDescription
owneraddressOwner of the withdraw request.

Return Values

NameTypeDescription
redeemFractionFPUnsignedAvailable fraction of request, from 0 to 1.

maxWithdraw

function maxWithdraw(
address owner
) external returns (
uint256 maxAssets,
bool instantRedeemAvailable,
FPSigned utilizationRatio
)

maxRedeem

function maxRedeem(
address owner
) public returns (
Shares maxShares,
bool instantRedeemAvailable,
FPSigned utilizationRatio
)

getLesserRate

Given two rates, where each rate expressed in collateral units per share (for instance, $/share), return the lesser rate.

function getLesserRate(
uint256 assetsA,
Shares sharesA,
uint256 assetsB,
Shares sharesB
) external pure returns (
uint256 assets,
Shares shares
)
Dev note

When a user is withdrawing a certain amount of collateral, we want to use the rate that would have them burn the greater amount of shares. When they're redeeming shares, we want them to get the lesser amount of collateral.

Parameters

NameTypeDescription
assetsAuint256Assets of rate A
sharesASharesShares of rate A
assetsBuint256Assets of rate B
sharesBSharesShares of rate B

Return Values

NameTypeDescription
assetsuint256Assets of lesser rate
sharesSharesShares of lesser rate