Skip to main content

DomFiVault

DomFiVault

Collateral vault for Domination Finance perpetual exchange

Intertwined with DomFiPerp. Holds LP funds. Provides an ERC4626 interface for users to deposit and withdraw, and for future staking integrations.

Addresses

ChainAddress
Arbitrum Sepolia0xAa6Fcf5C24f4bE7B0f5148bfB68EFEAD9fE8Ee6b

Functions

constructor

constructor(contract IERC20Metadata token, string name, string symbol) public

deposit

Deposit amount collateral to user with pre-approval instead of a signature. See deposit(..., signature).

function deposit(uint256 amount, address user) public returns (Shares shares)

Parameters

NameTypeDescription
amountuint256Collateral to deposit from msg.sender
useraddressAddress credited with the deposit

Return Values

NameTypeDescription
sharesSharesDOMD amount sent to user in exchange for this collateral

deposit

Deposit amount collateral to user with pre-approval instead of a signature. See deposit(..., signature).

function deposit(uint256 amount, address user, Shares minShares) public returns (Shares shares)

Parameters

NameTypeDescription
amountuint256Collateral to deposit from msg.sender
useraddressAddress credited with the deposit
minSharesSharesRevert if the deposit does not produce at least minShares

Return Values

NameTypeDescription
sharesSharesDOMD amount sent to user in exchange for this collateral

deposit

Deposit amount collateral to user, calling ERC-2612 permit() using the attached signature and deadline. See EIP-4626.

function deposit(
uint256 amount,
address user,
uint256 deadline,
struct IVault.Signature signature,
Shares minShares
) public returns (
Shares shares
)

Parameters

NameTypeDescription
amountuint256Collateral to deposit from msg.sender
useraddressAddress credited with the deposit
deadlineuint256deadline for permit
signaturestruct IVault.Signaturepermit entitling DomFiVault to amount collateral
minSharesSharesSlippage control. Ignored if zero. If nonzero, revert if a deposit yields less than minShares

Return Values

NameTypeDescription
sharesSharesDOMD amount sent to user in exchange for this collateral

mint

function mint(Shares shares, address receiver) public returns (uint256)
Dev note

Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.

  • MUST emit the Deposit event.
  • MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint execution, and are accounted for during mint.
  • MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not approving enough underlying tokens to the Vault contract, etc).

NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.

mint

function mint(Shares shares, address receiver, uint256 maxAssets) public returns (uint256)

mint

Mint shares shares to receiver, calling ERC-2612 permit() using the attached signature and signatureAssets. See EIP-2626 mint.

function mint(
Shares shares,
address receiver,
uint256 deadline,
struct IVault.Signature signature,
uint256 signatureAssets,
uint256 maxAssets
) public returns (
uint256 assets
)

Parameters

NameTypeDescription
sharesSharesShares to mint
receiveraddressAccount credited with the deposit
deadlineuint256deadline for permit
signaturestruct IVault.Signaturepermit entitling DomFiVault to assets collateral
signatureAssetsuint256Assets permitted to DomFiVault. This should be the expected assets or higher, in case share price increases
maxAssetsuint256Slippage control. Ignored if zero. If nonzero, revert if more than maxAssets are required to mint shares.

Return Values

NameTypeDescription
assetsuint256Collateral sent to the vault in exchange for these shares

withdraw

Withdraw assets to receiver by burning shares from account. Reverts unless

  • instantWithdrawAvailable() == true

  • OR account has a WithdrawRequest with at least shares available.

    See EIP-4626 withdraw().

function withdraw(uint256 assets, address receiver, address account) public returns (Shares shares)

Parameters

NameTypeDescription
assetsuint256Collateral units to withdraw
receiveraddressSend withdrawn collateral to this address
accountaddressAddress from which to burn shares. msg.sender must be that address or its manager

Return Values

NameTypeDescription
sharesSharesDOMD burnt from account to make the withdrawal

withdraw

Withdraw assets to receiver by burning shares from account. Reverts unless

  • instantWithdrawAvailable() == true

  • OR account has a WithdrawRequest with at least shares available.

    See EIP-4626 withdraw().

function withdraw(
uint256 assets,
address receiver,
address account,
Shares maxShares
) public returns (
Shares shares
)

Parameters

NameTypeDescription
assetsuint256Collateral units to withdraw
receiveraddressSend withdrawn collateral to this address
accountaddressAddress from which to burn shares. msg.sender must be that address or its manager
maxSharesSharesSlippage control. Ignored if zero. If nonzero, revert if more than maxShares would be burnt to make this withdrawal

Return Values

NameTypeDescription
sharesSharesDOMD burnt from account to make the withdrawal

redeem

function redeem(Shares shares, address receiver, address account) public returns (uint256 assets)

redeem

Redeem shares from account, and send the resulting collateral to receiver. Reverts unless

  • instantWithdrawAvailable() == true

  • OR account has a WithdrawRequest with at least shares available.

    See EIP-4626 withdraw().

function redeem(
Shares shares,
address receiver,
address account,
uint256 minAssets
) public returns (
uint256 assets
)

Parameters

NameTypeDescription
sharesSharesDOMD to burn from account
receiveraddressSend collateral to this address
accountaddressAddress from which to burn shares. msg.sender must be that address or its manager
minAssetsuint256Slippage control. Ignored if zero. If nonzero, revert unless the redemption yields at least minAssets

Return Values

NameTypeDescription
assetsuint256collateral sent to receiver

requestable

Get max shares/assets that a user can request to withdraw

function requestable(address owner) external view returns (Shares shares, uint256 assets)

Parameters

NameTypeDescription
owneraddressaccount which will be redeeming shares

Return Values

NameTypeDescription
sharesSharesDOMD that owner can request to redeem
assetsuint256max assets that owner might receive by redeeming shares

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() internal returns (bool instantRedeemAvailable, FPSigned utilizationRatio)

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 pendingWithdraw_)

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.

makeRedeemRequest

Create or update a request to redeem shares from account. If instant redeems are available and receiver is set, immediately redeem shares from account.

function makeRedeemRequest(
Shares shares,
address account,
address receiver,
uint256 minAssets
) external returns (
uint64 duration,
uint64 beginsAt
)

Parameters

NameTypeDescription
sharesSharesrequest permission to redeem shares from account. If a request already exists, the new shares must be at least as large
accountaddressAddress from which to redeem shares. Sender must be this address or its manager.
receiveraddressInstantly redeem to this address if possible. If 0x00, do not instantly redeem. Ignored if instant redeems are unavailable.
minAssetsuint256Slippage parameter. If instant redeems are available, receiver is nonzero, and minAssets is nonzero, revert if the resulting instant redemption would yield less than minAssets. Ignored if instant redeems are unavailable.

availableFraction

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

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

Parameters

NameTypeDescription
owneraddressOwner of the withdraw request.

Return Values

NameTypeDescription
redeemFractionFPUnsignedAvailable fraction of request, from 0 to 1.

maxWithdraw

Compute the max withdrawable assets for a user, based on instant withdrawal (if available) or any available withdraw request. Inclusive of fees.

function maxWithdraw(address owner) public returns (uint256 maxAssets)

Parameters

NameTypeDescription
owneraddressAccount which will be making the withdrawal

Return Values

NameTypeDescription
maxAssetsuint256Max assets owner could withdraw right now

_maxWithdraw

function _maxWithdraw(
address owner
) internal returns (
uint256 maxAssets,
bool instantRedeemAvailable,
FPSigned utilizationRatio
)

maxRedeem

Compute the max redeemable shares for a user, based on instant redemption (if available) or any available redeem request.

function maxRedeem(address owner) public returns (Shares maxShares)

Parameters

NameTypeDescription
owneraddressAccount which will be making the withdrawal

Return Values

NameTypeDescription
maxSharesSharesMax shares owner could cash in right now

_maxRedeem

function _maxRedeem(
address owner
) internal returns (
Shares maxShares,
bool instantRedeemAvailable,
FPSigned utilizationRatio
)

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

addReferralFee

Deposit a referral fee from FeeDistributor.

function addReferralFee(uint256 amount, address user) external returns (Shares shares)
Dev note

Does not apply deposit fees; only can be called by feeDistributor.

Parameters

NameTypeDescription
amountuint256Referral fee to deposit on behalf of user
useraddressAddress to credit with this referral fee

transferRewardAmount

Donate collateral to the vault

function transferRewardAmount(uint256 rewardAmount) external
Dev note

Receives fees, rewards, etc. for distribution to depositors.

Parameters

NameTypeDescription
rewardAmountuint256collateral tokens to transfer from sender to vault

previewDeposit

Preview a deposit, with fees. See EIP-4626

function previewDeposit(uint256 assets) public view returns (Shares shares)

Parameters

NameTypeDescription
assetsuint256Collateral to deposit

Return Values

NameTypeDescription
sharesSharesDOMD that would be minted in exchange for assets

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
) internal 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

_convertInput

Compute the assets/shares received in exchange for the provided assets/shares

function _convertInput(
uint256 assets,
Shares shares,
uint256 rateAssets,
Shares rateShares
) internal view returns (
Shares sharesOut,
uint256 assetsOut,
uint256 fee
)
Dev note

Used for deposit() and redeem()

Parameters

NameTypeDescription
assetsuint256Assets to be deposited. Must be 0 if shares is set.
sharesSharesShares to be redeemed. Must be 0 if assets is set.
rateAssetsuint256Conversion rate: rateAssets are worth rateShares.
rateSharesSharesConversion rate: rateShares are worth rateAssets.

Return Values

NameTypeDescription
sharesOutSharesShares received in exchange for assets. Fee excluded.
assetsOutuint256Assets received in exchange for shares. Fee excluded.
feeuint256Deposit/withdraw fee applied to output, in collateral units.

_convertOutput

Compute the assets/shares required to obtain the requested assets/shares

function _convertOutput(
uint256 assets,
Shares shares,
uint256 rateAssets,
Shares rateShares
) internal view returns (
Shares sharesIn,
uint256 assetsIn,
uint256 fee
)
Dev note

Used for withdraw() and mint()

Parameters

NameTypeDescription
assetsuint256Assets to be withdrawn. Must be 0 if shares is set.
sharesSharesShares to be minted. Must be 0 if assets is set.
rateAssetsuint256Conversion rate: rateAssets are worth rateShares.
rateSharesSharesConversion rate: rateShares are worth rateAssets.

Return Values

NameTypeDescription
sharesInSharesShares required to withdraw assets. Fee included.
assetsInuint256Assets required to mint shares. Fee included.
feeuint256Deposit/withdraw fee that will be taken out of sharesIn / assetsIn, in collateral units.

_convertToShares

Convert assets to shares. See EIP-4626

function _convertToShares(uint256 assets, enum Math.Rounding rounding) internal view returns (Shares shares)

_convertToShares

Convert assets to shares. See EIP-4626

function _convertToShares(
uint256 assets,
enum Math.Rounding rounding,
Shares rateShares,
uint256 rateAssets
) internal view returns (
Shares shares
)
Dev note

ERC4626 reference impl modified to explicitly take a rate

Parameters

NameTypeDescription
assetsuint256
roundingenum Math.Rounding
rateSharesSharesConversion rate: rateShares are worth rateAssets.
rateAssetsuint256Conversion rate: rateAssets are worth rateShares.

_convertToAssets

Convert shares to assets. See EIP-4626

function _convertToAssets(Shares shares, enum Math.Rounding rounding) internal view returns (uint256 assets)

_convertToAssets

Convert shares to assets. See EIP-4626

function _convertToAssets(
Shares shares,
enum Math.Rounding rounding,
Shares rateShares,
uint256 rateAssets
) internal view returns (
uint256 assets
)
Dev note

ERC4626 reference impl modified to explicitly take a rate

Parameters

NameTypeDescription
sharesShares
roundingenum Math.Rounding
rateSharesSharesConversion rate: rateShares are worth rateAssets.
rateAssetsuint256Conversion rate: rateAssets are worth rateShares.

previewWithdraw

Preview an instant withdrawal at the current rate, with fees. See EIP-4626

function previewWithdraw(uint256 assets) public view returns (Shares shares)

Parameters

NameTypeDescription
assetsuint256Collateral to withdraw

Return Values

NameTypeDescription
sharesSharesDOMD that would be burnt to withdraw assets

previewRedeem

Preview an instant redemption at the current rate, with fees. See EIP-4626

function previewRedeem(Shares shares) public view returns (uint256 assets)

Parameters

NameTypeDescription
sharesSharesDOMD to redeem

Return Values

NameTypeDescription
assetsuint256collateral yielded by burning shares

totalAssets

Total withdrawable assets: deposits + fees - trader PnL.

function totalAssets() public view returns (uint256 totalManagedAssets)
Dev note

Unlike balanceOf(vault), this does not include position margin, since LPs are not entitled to position margin until positions are liquidated or closed.

Return Values

NameTypeDescription
totalManagedAssetsuint256Total uncommitted assets in the vault

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

previewMint

Preview a mint, with fees. See EIP-4626

function previewMint(Shares shares) public view returns (uint256 assets)

Parameters

NameTypeDescription
sharesSharesDOMD to mint

Return Values

NameTypeDescription
assetsuint256collateral required to mint shares

_distributeFee

Send fee to FeeDistributor and trigger distribution

function _distributeFee(uint256 fee, address caller) internal

Parameters

NameTypeDescription
feeuint256Collateral units to be distributed
calleraddressAccount that paid the fee

enableUserDeposits

Enable or disable deposits by senders other than the owner.

function enableUserDeposits(bool allowDeposits) external

Parameters

NameTypeDescription
allowDepositsboolWhether users should be able to make additional deposits.

validateOIOnTransfer

Enable or disable calling DomFiPerp.validateOI on token transfer

function validateOIOnTransfer(bool validateOI_) external

Parameters

NameTypeDescription
validateOI_boolTrue if function should be called, false if not

setMaxCollateral

Reject deposits and donations that would raise totalAssets beyond a maximum. Trader losses and fees can still raise balance above the max.

function setMaxCollateral(uint256 _maxCollateral) external

Parameters

NameTypeDescription
_maxCollateraluint256New maximum collateral balance

setHealthyUtilizationRatio

Set the utilization ratio below which it's safe to let LPs withdraw immediately

function setHealthyUtilizationRatio(FPUnsigned healthyUtilizationRatio) external

Parameters

NameTypeDescription
healthyUtilizationRatioFPUnsignednew value for HEALTHY_UTILIZATION_RATIO

setMaxWithdrawDuration

Set the worst-case duration for collateral withdrawals, in seconds. Request durations will be capped to this duration.

function setMaxWithdrawDuration(uint256 maxWithdrawDuration) external

Parameters

NameTypeDescription
maxWithdrawDurationuint256New value for MAX_WITHDRAW_DURATION

setTotalDurationPerUtilizationRatio

Set TOTAL_DURATION_PER_UTILIZATION_RATIO, in seconds per (utilization % above healthy level) per (100% collateral withdrawal). To determine withdraw duration, we multiply this duration by the fraction of the vault being withdrawn, and then by the % utilization above the unhealthy utilization threshold.

With the default value of 100 days, withdrawing 10% of the vault would take 1 day for each 10% utilization ratio above the minimum.

function setTotalDurationPerUtilizationRatio(uint256 totalDurationPerUtilizationRatio) external

Parameters

NameTypeDescription
totalDurationPerUtilizationRatiouint256new value for TOTAL_DURATION_PER_UTILIZATION_RATIO

setWithdrawWindow

Set WITHDRAW_WINDOW, in seconds. After request.duration has elapsed, users have this long to execute a request before it expires.

function setWithdrawWindow(uint64 withdrawWindow) external

Parameters

NameTypeDescription
withdrawWindowuint64new value for WITHDRAW_WINDOW

setPenaltyDurationMultiplier

Set a new value for PENALTY_DURATION_MULTIPLIER

Penalty length is determined by multiplying duration by a scaling factor, PENALTY_DURATION_MULTIPLIER. At a 1x multiplier, repeatedly letting a request expire will result in a penalty of X, then a duration of X, then a penalty of X, etc. If a bank run occurs at a random time, the expected withdraw delay ([duration + penalty]/2) of the continuous withdraw attempts is exactly the same as that of a naive user who makes a withdraw request once the bank run begins: duration. However, this continuous withdraw strategy results in some tokens being immediately available, whereas the naive user starts from 0. It is not clear how to value this availability, so the contract owner should increase PENALTY_DURATION_MULTIPLIER if they notice users using continuous withdrawal strategies.

function setPenaltyDurationMultiplier(FPUnsigned penaltyDurationMultiplier) external

Parameters

NameTypeDescription
penaltyDurationMultiplierFPUnsignedNew value of PENALTY_DURATION_MULTIPLIER

_initialConvertToShares

function _initialConvertToShares(uint256 assets, enum Math.Rounding) internal pure returns (Shares shares)
Dev note

Internal conversion function (from assets to shares) to apply when the vault is empty. Scale by 1e18 to mitigate inflation attacks: github.com/OpenZeppelin/openzeppelin-contracts/issues/3706

_initialConvertToAssets

function _initialConvertToAssets(Shares shares, enum Math.Rounding) internal pure returns (uint256)
Dev note

Internal conversion function (from shares to assets) to apply when the vault is empty.

_beforeTokenTransfer

function _beforeTokenTransfer(address from, address to, uint256) internal

_afterTokenTransfer

Prevent gamesmanship by applying cooldown periods after unexecuted requests. After an expired request, the next one is given a cooldown period. But it would be easy to work around that by transfering shares to a fresh account to make a request with no penalty

So,

  • Prevent transfering tokens "reserved" by an ongoing request
  • If next request will receive a penalty, revert until best-case penalty would have finished
function _afterTokenTransfer(address from, address to, uint256 amount) internal

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) internal view returns (PerShare nextRate, uint64 remainingSeconds)

computePenalty

Apply a given penalty rate to a shares quantity

function computePenalty(
Shares shares,
PerShare penaltyRate,
uint64 maxPenaltySeconds
) internal 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

decrementPenalty

After (partially) filling a request, decrease or clear the user's stored penalty.

function decrementPenalty(address user, Shares shares) internal

Parameters

NameTypeDescription
useraddressOwner of (partially) filled request
sharesSharesNumber of shares that have just been withdrawn or redeemed

clearPenalty

function clearPenalty(address user) internal

clearRequestAndPenalty

Clear a user's request and penalty rate, since immediate withdraws have become available

function clearRequestAndPenalty(address account) internal

Parameters

NameTypeDescription
accountaddressAddress of request holder

setAddresses

Set contract addresses, or update everything but DomFiPerp.

function setAddresses(
contract IFeeCalculator _feeCalculator,
contract IRewardDistributor _rewardDistributor,
contract IFeeDistributor _feeDistributor,
contract IDomFiPerp _domFiPerp
) external

Parameters

NameTypeDescription
_feeCalculatorcontract IFeeCalculatorUpdated FeeCalculator address
_rewardDistributorcontract IRewardDistributorUpdated RewardDistributor address
_feeDistributorcontract IFeeDistributorUpdated FeeDistributor address
_domFiPerpcontract IDomFiPerpDomFiPerp address. Ignored if DomFiPerp has already been set.

distributeDecrease

Pay out any claimed PnL, and distribute trade fee, when a position is decreased.

function distributeDecrease(
uint256 margin,
address owner,
address recipient,
uint256 totalFee,
int256 netPnl
) external
Dev note

Only callable by DomFiPerp. Decreases balance by PnL.

Parameters

NameTypeDescription
marginuint256Margin amount being decreased
owneraddressOwner of position being decreased; for fee redirect.
recipientaddressAddress to receive any realized positive PnL
totalFeeuint256Fee amount paid by the position's owner
netPnlint256PnL, with fee already applied, realized by decrease

withdrawWithoutFee

Remove collateral from the Vault and send it to recipient.

function withdrawWithoutFee(address recipient, uint256 amount) external
Dev note

Only callable by DomFiPerp. Does not update balance; this is for adjusting position margin (which does not contribute to balance).

Parameters

NameTypeDescription
recipientaddressAddress to receive collateral
amountuint256Collateral amount to remove

approveAndUpdateLiquidatorReward

Process a liquidation

function approveAndUpdateLiquidatorReward(
uint256 remainingReward,
uint256 liquidatorReward,
uint256 increaseBalance,
address liquidator
) external
Dev note

Only callable by DomFiPerp

Parameters

NameTypeDescription
remainingRewarduint256Leftover margin after liquidator reward and PnL
liquidatorRewarduint256Collateral amount paid out to liquidator
increaseBalanceuint256Increase vault balance by this much
liquidatoraddressAddress which will be approved for liquidatorReward

Events

VaultUpdated

event VaultUpdated(uint256 maxCollateral, uint256 balance)

AddressesSet

event AddressesSet(
contract IFeeCalculator feeCalculator,
contract IRewardDistributor rewardDistributor,
contract IFeeDistributor feeDistributor,
contract IDomFiPerp domFiPerp
)

WithdrawRequested

event WithdrawRequested(address caller, address owner, struct IVault.WithdrawRequest withdrawRequest)

WithdrawCleared

event WithdrawCleared(address caller, address owner, struct IVault.WithdrawRequest withdrawRequest)

WithdrawCompleted

event WithdrawCompleted(address caller, address owner, struct IVault.WithdrawRequest withdrawRequest)

Modifiers

onlyDomFiPerp

modifier onlyDomFiPerp()

onlyManager

modifier onlyManager(address account)

Errors

ERC4626ExceededMaxDeposit

Attempted to deposit more assets than the max amount for receiver.

error ERC4626ExceededMaxDeposit(address receiver, uint256 assets, uint256 max)

ERC4626ExceededMaxMint

Attempted to mint more shares than the max amount for receiver.

error ERC4626ExceededMaxMint(address receiver, Shares shares, Shares max)

ERC4626ExceededMaxWithdraw

Attempted to withdraw more assets than the max amount for receiver.

error ERC4626ExceededMaxWithdraw(address owner, uint256 assets, uint256 max)

ERC4626ExceededMaxRedeem

Attempted to redeem more shares than the max amount for receiver.

error ERC4626ExceededMaxRedeem(address owner, Shares shares, Shares max)

MintRateExceeded

Attempted to mint, but more than maxAssets would have been required ($/LP price too high).

error MintRateExceeded(Shares shares, uint256 assetsRequired, uint256 maxAssets)

Parameters

NameTypeDescription
sharesSharesRequested shares to mint
assetsRequireduint256Assets that were actually required to mint shares
maxAssetsuint256Maximum assets user was willing to spend

DepositRateExceeded

Attempted to deposit, but less than minShares would have been yielded ($/LP price too high).

error DepositRateExceeded(uint256 assets, Shares sharesMinted, Shares minShares)

Parameters

NameTypeDescription
assetsuint256Requested collateral to deposit
sharesMintedSharesShares that actually would have been minted
minSharesSharesMinimum acceptable shares to mint in exchange for assets

WithdrawRateUnmet

Attempted to withdraw, but more than maxShares would have been required ($/LP price too low).

error WithdrawRateUnmet(uint256 assets, Shares shares, Shares maxShares)

Parameters

NameTypeDescription
assetsuint256Requested collateral to withdraw
sharesSharesShares that actually would have to have been burnt
maxSharesSharesMaximum acceptable shares to burn in exchange for withdraw

RedeemRateUnmet

Attempted to redeem, but less than maxAssets would have been yielded ($/LP price too low).

error RedeemRateUnmet(Shares shares, uint256 assets, uint256 minAssets)

Parameters

NameTypeDescription
sharesSharesRequested shares to redeem
assetsuint256Assets that were actually offered in exchange for shares
minAssetsuint256Minimum acceptable assets to receive for shares

DepositsDisabled

This action cannot be performed because user deposits and withdraws are disabled

error DepositsDisabled()

AccountManagerOnly

This action is limited only to the recipient and its managers delegated with DomFiPerp.setAccountManager

error AccountManagerOnly()

ZeroSharesRequested

cannot redeem zero shares

error ZeroSharesRequested()

FeeDistributorOnly

error FeeDistributorOnly()

MaxCollateralExceeded

Attempted donation would have brought balance above maxCollateral

error MaxCollateralExceeded()

DomFiPerpOnly

error DomFiPerpOnly()

NoWithdrawAssets

This request could not be simulated or executed because it would yield 0 assets.

error NoWithdrawAssets()

Overspecified

Internal assertion, should not be encountered in the wild.

error Overspecified()

InsufficientVaultBalance

error InsufficientVaultBalance()

ActiveWithdrawRequest

Transfers are prohibited if they would lower the balance of an address below the remaining part of an active withdraw request.

error ActiveWithdrawRequest(address from, Shares lockedShares, Shares newBalance)

Parameters

NameTypeDescription
fromaddressAddress from which transfer would be made
lockedSharesSharesshares still "locked" by the withdraw request
newBalanceSharesThe share balance of from after the transfer attempt

PendingPenalty

Transfers are prohibited if the equivalent withdraw request would be blocked by a penalty. You'll have to wait until penalty + penaltyStart.

error PendingPenalty(address from, Shares amount, uint64 penalty, uint64 penaltyStart)
Dev note

see _afterTokenTransfer.

Parameters

NameTypeDescription
fromaddressAddress from which transfer would be made
amountSharesShare size of attempted transfer
penaltyuint64Total penalty that would have been applied to a request this size. That is, if from had made this request, they would have had to wait penalty seconds before beginning to withdraw.
penaltyStartuint64The timestamp at which the penalty would have started

Variables

balance

staked collateral plus trader losses

maxCollateral

see setMaxCollateral

validateOI

whether token transfers call DomFiPerp.validateOI

feeCalculator

Provides fee rates for trades, deposits and withdraws

rewardDistributor

if set, distributes external token reward to vault LPs

feeDistributor

distributes trade/liquidity fees to vault LPs

domFiPerp

perp instance for this vault. deployed after DomFiVault

HEALTHY_UTILIZATION_RATIO

see setHealthyUtilizationRatio

MAX_WITHDRAW_DURATION

see setMaxWithdrawDuration

TOTAL_DURATION_PER_UTILIZATION_RATIO

see setTotalDurationPerUtilizationRatio

WITHDRAW_WINDOW

time until an available WithdrawRequest expires

PENALTY_DURATION_MULTIPLIER

see setPenaltyDurationMultiplier

pendingWithdrawRequest

last WithdrawRequest of this user

nextPenaltyRate

seconds-per-share rate at which next penalty will be applied

remainingPenaltySeconds

total remaining penalty seconds

pendingWithdraw

sum of outstanding withdraw requests

pendingRedeem

sum of outstanding withdraw requests