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.
- Gets deposit/withdraw fee amounts from FeeCalculator and sends them to FeeDistributor.
- Optionally, triggers a RewardDistributor.
Addresses
Chain | Address |
---|---|
Arbitrum Sepolia | 0xAa6Fcf5C24f4bE7B0f5148bfB68EFEAD9fE8Ee6b |
Zircuit | 0xf2ac54fed5e65069C43b75E9888294915925B311 |
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
Name | Type | Description |
---|---|---|
amount | uint256 | Collateral to deposit from msg.sender |
user | address | Address credited with the deposit |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD 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
Name | Type | Description |
---|---|---|
amount | uint256 | Collateral to deposit from msg.sender |
user | address | Address credited with the deposit |
minShares | Shares | Revert if the deposit does not produce at least minShares |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD 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
Name | Type | Description |
---|---|---|
amount | uint256 | Collateral to deposit from msg.sender |
user | address | Address credited with the deposit |
deadline | uint256 | deadline for permit |
signature | struct IVault.Signature | permit entitling DomFiVault to amount collateral |
minShares | Shares | Slippage control. Ignored if zero. If nonzero, revert if a deposit yields less than minShares |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD amount sent to user in exchange for this collateral |
mint
function mint(Shares shares, address receiver) public returns (uint256)
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
Name | Type | Description |
---|---|---|
shares | Shares | Shares to mint |
receiver | address | Account credited with the deposit |
deadline | uint256 | deadline for permit |
signature | struct IVault.Signature | permit entitling DomFiVault to assets collateral |
signatureAssets | uint256 | Assets permitted to DomFiVault. This should be the expected assets or higher, in case share price increases |
maxAssets | uint256 | Slippage control. Ignored if zero. If nonzero, revert if more than maxAssets are required to mint shares . |
Return Values
Name | Type | Description |
---|---|---|
assets | uint256 | Collateral 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 leastshares
available.See EIP-4626 withdraw().
function withdraw(uint256 assets, address receiver, address account) public returns (Shares shares)
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | Collateral units to withdraw |
receiver | address | Send withdrawn collateral to this address |
account | address | Address from which to burn shares. msg.sender must be that address or its manager |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD 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 leastshares
available.See EIP-4626 withdraw().
function withdraw(
uint256 assets,
address receiver,
address account,
Shares maxShares
) public returns (
Shares shares
)
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | Collateral units to withdraw |
receiver | address | Send withdrawn collateral to this address |
account | address | Address from which to burn shares. msg.sender must be that address or its manager |
maxShares | Shares | Slippage control. Ignored if zero. If nonzero, revert if more than maxShares would be burnt to make this withdrawal |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD 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 leastshares
available.See EIP-4626 withdraw().
function redeem(
Shares shares,
address receiver,
address account,
uint256 minAssets
) public returns (
uint256 assets
)
Parameters
Name | Type | Description |
---|---|---|
shares | Shares | DOMD to burn from account |
receiver | address | Send collateral to this address |
account | address | Address from which to burn shares. msg.sender must be that address or its manager |
minAssets | uint256 | Slippage control. Ignored if zero. If nonzero, revert unless the redemption yields at least minAssets |
Return Values
Name | Type | Description |
---|---|---|
assets | uint256 | collateral 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
Name | Type | Description |
---|---|---|
owner | address | account which will be redeeming shares |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD that owner can request to redeem |
assets | uint256 | max 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)
DomFiPerp.getTotalPnL()
is extremely expensive, call
_computeUtilizationRatio()
and save results if reuse is necessary.
Return Values
Name | Type | Description |
---|---|---|
available | bool | Whether 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
Name | Type | Description |
---|---|---|
utilizationRatio | FPSigned | Current 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
Name | Type | Description |
---|---|---|
shares | Shares | Shares that would be requested |
account | address | Account for which to preview the request |
Return Values
Name | Type | Description |
---|---|---|
duration | uint64 | Duration of the resulting WithdrawRequest |
offset | int64 | Time 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
Name | Type | Description |
---|---|---|
shares | Shares | request permission to redeem shares from account . If a request already exists, the new shares must be at least as large |
account | address | Address from which to redeem shares. Sender must be this address or its manager. |
receiver | address | Instantly redeem to this address if possible. If 0x00, do not instantly redeem. Ignored if instant redeems are unavailable. |
minAssets | uint256 | Slippage 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
Name | Type | Description |
---|---|---|
owner | address | Owner of the withdraw request. |
Return Values
Name | Type | Description |
---|---|---|
redeemFraction | FPUnsigned | Available 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
Name | Type | Description |
---|---|---|
owner | address | Account which will be making the withdrawal |
Return Values
Name | Type | Description |
---|---|---|
maxAssets | uint256 | Max 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
Name | Type | Description |
---|---|---|
owner | address | Account which will be making the withdrawal |
Return Values
Name | Type | Description |
---|---|---|
maxShares | Shares | Max 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
Name | Type | Description |
---|---|---|
owner | address | Address for which to check request |
Return Values
Name | Type | Description |
---|---|---|
status | bool | false 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
Name | Type | Description |
---|---|---|
owner | address | Address for which to check request |
Return Values
Name | Type | Description |
---|---|---|
status | bool | true 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)
Does not apply deposit fees; only can be called by feeDistributor
.
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | Referral fee to deposit on behalf of user |
user | address | Address to credit with this referral fee |
transferRewardAmount
Donate collateral to the vault
function transferRewardAmount(uint256 rewardAmount) external
Receives fees, rewards, etc. for distribution to depositors.
Parameters
Name | Type | Description |
---|---|---|
rewardAmount | uint256 | collateral 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
Name | Type | Description |
---|---|---|
assets | uint256 | Collateral to deposit |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD 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
)
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
Name | Type | Description |
---|---|---|
assetsA | uint256 | Assets of rate A |
sharesA | Shares | Shares of rate A |
assetsB | uint256 | Assets of rate B |
sharesB | Shares | Shares of rate B |
Return Values
Name | Type | Description |
---|---|---|
assets | uint256 | Assets of lesser rate |
shares | Shares | Shares 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
)
Used for deposit()
and redeem()
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | Assets to be deposited. Must be 0 if shares is set. |
shares | Shares | Shares to be redeemed. Must be 0 if assets is set. |
rateAssets | uint256 | Conversion rate: rateAssets are worth rateShares . |
rateShares | Shares | Conversion rate: rateShares are worth rateAssets . |
Return Values
Name | Type | Description |
---|---|---|
sharesOut | Shares | Shares received in exchange for assets . Fee excluded. |
assetsOut | uint256 | Assets received in exchange for shares . Fee excluded. |
fee | uint256 | Deposit/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
)
Used for withdraw()
and mint()
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | Assets to be withdrawn. Must be 0 if shares is set. |
shares | Shares | Shares to be minted. Must be 0 if assets is set. |
rateAssets | uint256 | Conversion rate: rateAssets are worth rateShares . |
rateShares | Shares | Conversion rate: rateShares are worth rateAssets . |
Return Values
Name | Type | Description |
---|---|---|
sharesIn | Shares | Shares required to withdraw assets . Fee included. |
assetsIn | uint256 | Assets required to mint shares . Fee included. |
fee | uint256 | Deposit/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
)
ERC4626 reference impl modified to explicitly take a rate
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | |
rounding | enum Math.Rounding | |
rateShares | Shares | Conversion rate: rateShares are worth rateAssets . |
rateAssets | uint256 | Conversion 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
)
ERC4626 reference impl modified to explicitly take a rate
Parameters
Name | Type | Description |
---|---|---|
shares | Shares | |
rounding | enum Math.Rounding | |
rateShares | Shares | Conversion rate: rateShares are worth rateAssets . |
rateAssets | uint256 | Conversion 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
Name | Type | Description |
---|---|---|
assets | uint256 | Collateral to withdraw |
Return Values
Name | Type | Description |
---|---|---|
shares | Shares | DOMD 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
Name | Type | Description |
---|---|---|
shares | Shares | DOMD to redeem |
Return Values
Name | Type | Description |
---|---|---|
assets | uint256 | collateral yielded by burning shares |
totalAssets
Total withdrawable assets: deposits + fees - trader PnL.
function totalAssets() public view returns (uint256 totalManagedAssets)
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
Name | Type | Description |
---|---|---|
totalManagedAssets | uint256 | Total 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
Name | Type | Description |
---|---|---|
receiver | address | address that will be receiving the deposit |
Return Values
Name | Type | Description |
---|---|---|
maxAssets | uint256 | Maximum 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
Name | Type | Description |
---|---|---|
receiver | address | address that will be receiving the minted shares |
Return Values
Name | Type | Description |
---|---|---|
maxShares | Shares | Maximum 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
Name | Type | Description |
---|---|---|
shares | Shares | DOMD to mint |
Return Values
Name | Type | Description |
---|---|---|
assets | uint256 | collateral required to mint shares |
_distributeFee
Send fee
to FeeDistributor and trigger distribution
function _distributeFee(uint256 fee, address caller) internal
Parameters
Name | Type | Description |
---|---|---|
fee | uint256 | Collateral units to be distributed |
caller | address | Account that paid the fee |
enableUserDeposits
Enable or disable deposits by senders other than the owner.
function enableUserDeposits(bool allowDeposits) external
Parameters
Name | Type | Description |
---|---|---|
allowDeposits | bool | Whether users should be able to make additional deposits. |
validateOIOnTransfer
Enable or disable calling DomFiPerp.validateOI on token transfer
function validateOIOnTransfer(bool validateOI_) external
Parameters
Name | Type | Description |
---|---|---|
validateOI_ | bool | True 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
Name | Type | Description |
---|---|---|
_maxCollateral | uint256 | New maximum collateral balance |
setHealthyUtilizationRatio
Set the utilization ratio below which it's safe to let LPs withdraw immediately
function setHealthyUtilizationRatio(FPUnsigned healthyUtilizationRatio) external
Parameters
Name | Type | Description |
---|---|---|
healthyUtilizationRatio | FPUnsigned | new 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
Name | Type | Description |
---|---|---|
maxWithdrawDuration | uint256 | New 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
Name | Type | Description |
---|---|---|
totalDurationPerUtilizationRatio | uint256 | new 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
Name | Type | Description |
---|---|---|
withdrawWindow | uint64 | new 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
Name | Type | Description |
---|---|---|
penaltyDurationMultiplier | FPUnsigned | New value of PENALTY_DURATION_MULTIPLIER |
_initialConvertToShares
function _initialConvertToShares(uint256 assets, enum Math.Rounding) internal pure returns (Shares shares)
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)
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
Name | Type | Description |
---|---|---|
shares | Shares | Request quantity |
penaltyRate | PerShare | Rate to apply |
maxPenaltySeconds | uint64 | Maximum penalty returned |
Return Values
Name | Type | Description |
---|---|---|
penalty | uint64 | Seconds 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
Name | Type | Description |
---|---|---|
user | address | Owner of (partially) filled request |
shares | Shares | Number 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
Name | Type | Description |
---|---|---|
account | address | Address 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
Name | Type | Description |
---|---|---|
_feeCalculator | contract IFeeCalculator | Updated FeeCalculator address |
_rewardDistributor | contract IRewardDistributor | Updated RewardDistributor address |
_feeDistributor | contract IFeeDistributor | Updated FeeDistributor address |
_domFiPerp | contract IDomFiPerp | DomFiPerp 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
Only callable by DomFiPerp. Decreases balance
by PnL.
Parameters
Name | Type | Description |
---|---|---|
margin | uint256 | Margin amount being decreased |
owner | address | Owner of position being decreased; for fee redirect. |
recipient | address | Address to receive any realized positive PnL |
totalFee | uint256 | Fee amount paid by the position's owner |
netPnl | int256 | PnL, 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
Only callable by DomFiPerp. Does not update balance
; this is for
adjusting position margin (which does not contribute to balance
).
Parameters
Name | Type | Description |
---|---|---|
recipient | address | Address to receive collateral |
amount | uint256 | Collateral amount to remove |
approveAndUpdateLiquidatorReward
Process a liquidation
function approveAndUpdateLiquidatorReward(
uint256 remainingReward,
uint256 liquidatorReward,
uint256 increaseBalance,
address liquidator
) external
Only callable by DomFiPerp
Parameters
Name | Type | Description |
---|---|---|
remainingReward | uint256 | Leftover margin after liquidator reward and PnL |
liquidatorReward | uint256 | Collateral amount paid out to liquidator |
increaseBalance | uint256 | Increase vault balance by this much |
liquidator | address | Address 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
Name | Type | Description |
---|---|---|
shares | Shares | Requested shares to mint |
assetsRequired | uint256 | Assets that were actually required to mint shares |
maxAssets | uint256 | Maximum 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
Name | Type | Description |
---|---|---|
assets | uint256 | Requested collateral to deposit |
sharesMinted | Shares | Shares that actually would have been minted |
minShares | Shares | Minimum 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
Name | Type | Description |
---|---|---|
assets | uint256 | Requested collateral to withdraw |
shares | Shares | Shares that actually would have to have been burnt |
maxShares | Shares | Maximum 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
Name | Type | Description |
---|---|---|
shares | Shares | Requested shares to redeem |
assets | uint256 | Assets that were actually offered in exchange for shares |
minAssets | uint256 | Minimum 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
Name | Type | Description |
---|---|---|
from | address | Address from which transfer would be made |
lockedShares | Shares | shares still "locked" by the withdraw request |
newBalance | Shares | The 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)
see _afterTokenTransfer
.
Parameters
Name | Type | Description |
---|---|---|
from | address | Address from which transfer would be made |
amount | Shares | Share size of attempted transfer |
penalty | uint64 | Total 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. |
penaltyStart | uint64 | The 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
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