Vault

Keeps track of all token reserves for all market

Methods

DEFAULT_ADMIN_ROLE

function DEFAULT_ADMIN_ROLE() external view returns (bytes32)

Returns

EMERGENCY_ADMIN

function EMERGENCY_ADMIN() external view returns (bytes32)

Returns

GOVERNANCE

function GOVERNANCE() external view returns (bytes32)

Returns

UA

function UA() external view returns (contract IERC20Metadata)

Returns

UA_IDX

function UA_IDX() external view returns (uint256)

Returns

addWhiteListedCollateral

function addWhiteListedCollateral(contract IERC20Metadata asset, uint256 weight, uint256 maxAmount) external nonpayable

Add a new token to the list of whitelisted ERC20 which can be used as collaterals

Parameters

changeCollateralMaxAmount

function changeCollateralMaxAmount(contract IERC20Metadata asset, uint256 newMaxAmount) external nonpayable

Change max amount of a whitelisted collateral Useful as a risk mitigation measure in case one collateral drops in value

Parameters

changeCollateralWeight

function changeCollateralWeight(contract IERC20Metadata asset, uint256 newWeight) external nonpayable

Change weight of a whitelisted collateral Useful as a risk mitigation measure in case one collateral drops in value

Parameters

clearingHouse

function clearingHouse() external view returns (contract IClearingHouse)

Returns

decreaseAllowance

function decreaseAllowance(address user, address receiver, uint256 subtractedAmount, contract IERC20Metadata token) external nonpayable

Decrease the approval of another account to withdraw a user's tokens

Parameters

deposit

function deposit(address sender, address user, uint256 amount, contract IERC20Metadata depositToken) external nonpayable

Add an amount of a whitelisted token to the balance of a user

Parameters

getAllowance

function getAllowance(address user, address receiver, uint256 tokenIdx) external view returns (uint256)

Get the Allowance that a user has given a receiver for a specified token

Parameters

Returns

getBalance

function getBalance(address user, uint256 tokenIdx) external view returns (int256)

Get the balance of a user of a given token

Parameters

Returns

getNumberOfCollaterals

function getNumberOfCollaterals() external view returns (uint256)

Get number of whitelisted tokens

Returns

getReserveValue

function getReserveValue(address user, bool isDiscounted) external view returns (int256)

Get the balance of a user, accounted for in USD. 18 decimals

Parameters

Returns

getRoleAdmin

function getRoleAdmin(bytes32 role) external view returns (bytes32)

Returns the admin role that controls role. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.

Parameters

Returns

getTotalValueLocked

function getTotalValueLocked() external view returns (int256)

Get total value of all tokens deposited in the vault, in USD. 18 decimals

Returns

getWhiteListedCollateral

function getWhiteListedCollateral(uint256 idx) external view returns (struct IVault.Collateral)

Get details of a whitelisted collateral token

Parameters

Returns

grantRole

function grantRole(bytes32 role, address account) external nonpayable

Grants role to account. If account had not been already granted role, emits a {RoleGranted} event. Requirements: - the caller must have role's admin role. May emit a {RoleGranted} event.

Parameters

hasRole

function hasRole(bytes32 role, address account) external view returns (bool)

Returns true if account has been granted role.

Parameters

Returns

increaseAllowance

function increaseAllowance(address user, address receiver, uint256 addedAmount, contract IERC20Metadata token) external nonpayable

Increase the approval of another account to withdraw a user's tokens

Parameters

insurance

function insurance() external view returns (contract IInsurance)

Returns

isEmergencyAdmin

function isEmergencyAdmin(address account) external view returns (bool)

Parameters

Returns

isGovernor

function isGovernor(address account) external view returns (bool)

Parameters

Returns

oracle

function oracle() external view returns (contract IOracle)

Returns

renounceRole

function renounceRole(bytes32 role, address account) external nonpayable

Revokes role from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked role, emits a {RoleRevoked} event. Requirements: - the caller must be account. May emit a {RoleRevoked} event.

Parameters

revokeRole

function revokeRole(bytes32 role, address account) external nonpayable

Revokes role from account. If account had been granted role, emits a {RoleRevoked} event. Requirements: - the caller must have role's admin role. May emit a {RoleRevoked} event.

Parameters

setClearingHouse

function setClearingHouse(contract IClearingHouse newClearingHouse) external nonpayable

Update the ClearingHouse address

Parameters

setInsurance

function setInsurance(contract IInsurance newInsurance) external nonpayable

Update the Insurance address

Parameters

setOracle

function setOracle(contract IOracle newOracle) external nonpayable

Update the Oracle address

Parameters

settleLiquidationOnCollaterals

function settleLiquidationOnCollaterals(address liquidator, address liquidatee) external nonpayable

Allow liquidator to buy back non-UA collateral(s) of liquidated user at a discounted price whereby settling the latter debt

The liquidator buys just as much non-UA collaterals to cover the liquidatee's debt, not moreIf the USD value of all the non-UA collaterals of the liquidatee < his UA debt, Increment insurance steps in to cover the remainder of the UA debt

Parameters

settlePnL

function settlePnL(address user, int256 amount) external nonpayable

Settle PnL for user in UA

Parameters

supportsInterface

function supportsInterface(bytes4 interfaceId) external view returns (bool)

See {IERC165-supportsInterface}.

Parameters

Returns

tokenToCollateralIdx

function tokenToCollateralIdx(contract IERC20Metadata) external view returns (uint256)

Map whitelisted collateral tokens to their whiteListedCollaterals indices

Parameters

Returns

transferUa

function transferUa(address user, uint256 amount) external nonpayable

Transfer UA tokens from the vault

Important: the balance of the user from whom the UA tokens are being withdrawn must be updated separately

Parameters

withdraw

function withdraw(address user, uint256 amount, contract IERC20Metadata withdrawToken) external nonpayable

Withdraw tokens stored by a user in the vault

Unlike deposit, withdraw treats withdrawals of UA differently than other collaterals

Parameters

withdrawAll

function withdrawAll(address user, contract IERC20Metadata withdrawToken) external nonpayable

Withdraw all tokens stored by a user in the vault

Parameters

withdrawFrom

function withdrawFrom(address user, address receiver, uint256 amount, contract IERC20Metadata withdrawToken) external nonpayable

Withdraw tokens from a user in the vault to a receiving account

Unlike deposit, withdraw treats withdrawals of UA differently than other collaterals

Parameters

Events

Approval

event Approval(address indexed user, address indexed receiver, uint256 tokenIdx, uint256 amount)

Emitted when a new approval value is set

Parameters

ClearingHouseChanged

event ClearingHouseChanged(contract IClearingHouse newClearingHouse)

Emitted when the ClearingHouse address is updated

Parameters

CollateralAdded

event CollateralAdded(contract IERC20Metadata asset, uint256 weight, uint256 maxAmount)

Emitted when a new collateral is added to the Vault

Parameters

CollateralMaxAmountChanged

event CollateralMaxAmountChanged(contract IERC20Metadata asset, uint256 newMaxAmount)

Emitted when a collateral max amount is updated

Parameters

CollateralWeightChanged

event CollateralWeightChanged(contract IERC20Metadata asset, uint256 newWeight)

Emitted when a collateral weight is updated

Parameters

Deposit

event Deposit(address indexed user, address indexed asset, uint256 amount)

Emitted when collateral is deposited into the vault

Parameters

InsuranceChanged

event InsuranceChanged(contract IInsurance newInsurance)

Emitted when the Insurance address is updated

Parameters

OracleChanged

event OracleChanged(contract IOracle newOracle)

Emitted when the Oracle address is updated

Parameters

RoleAdminChanged

event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole)

Parameters

RoleGranted

event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender)

Parameters

RoleRevoked

event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender)

Parameters

TraderBadDebtGenerated

event TraderBadDebtGenerated(address beneficiary, uint256 amount)

Emitted when bad debt is settled for by the insurance reserve

Parameters

Withdraw

event Withdraw(address indexed user, address indexed asset, uint256 amount)

Emitted when collateral is withdrawn from the vault

Parameters

Errors

PRBMathSD59x18__MulInputTooSmall

error PRBMathSD59x18__MulInputTooSmall()

Emitted when one of the inputs is MIN_SD59x18.

PRBMathSD59x18__MulOverflow

error PRBMathSD59x18__MulOverflow(uint256 rAbs)

Emitted when the intermediary absolute result overflows SD59x18.

Parameters

PRBMath__MulDivFixedPointOverflow

error PRBMath__MulDivFixedPointOverflow(uint256 prod1)

Emitted when the result overflows uint256.

Parameters

PRBMath__MulDivOverflow

error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator)

Emitted when the result overflows uint256.

Parameters

Vault_ApproveZeroAddress

error Vault_ApproveZeroAddress()

Emitted when a user attempts to approve the zero address

Vault_ClearingHouseAlreadySet

error Vault_ClearingHouseAlreadySet()

Emitted when the clearingHouse has already been set (one time call function)

Vault_ClearingHouseZeroAddress

error Vault_ClearingHouseZeroAddress()

Emitted when the proposed clearingHouse address is equal to the zero address

Vault_CollateralAlreadyWhiteListed

error Vault_CollateralAlreadyWhiteListed()

Emitted when owner tries to whitelist a collateral already whitelisted

Vault_ExcessiveCollateralWeight

error Vault_ExcessiveCollateralWeight()

Emitted when the proposed collateral weight is above the limit

Vault_InsufficientBalance

error Vault_InsufficientBalance()

Emitted when a user attempts to withdraw more collateral than available in vault

Vault_InsufficientCollateralWeight

error Vault_InsufficientCollateralWeight()

Emitted when the proposed collateral weight is under the limit

Vault_InsuranceAlreadySet

error Vault_InsuranceAlreadySet()

Emitted when the insurance has already been set (one time call function)

Vault_InsuranceZeroAddress

error Vault_InsuranceZeroAddress()

Emitted when the proposed insurance address is equal to the zero address

Vault_MaxCollateralAmountExceeded

error Vault_MaxCollateralAmountExceeded()

Emitted when a user attempts to withdraw more collateral than available in vault

Vault_OracleZeroAddress

error Vault_OracleZeroAddress()

Emitted when the proposed oracle address is equal to the zero address

Vault_SenderNotClearingHouse

error Vault_SenderNotClearingHouse()

Emitted when the sender is not the clearing house

Vault_SenderNotInsurance

error Vault_SenderNotInsurance()

Emitted when the sender is nor the insurance

Vault_UADebt

error Vault_UADebt()

Emitted when user tries to withdraw collateral while having a UA debt

Vault_UnsupportedCollateral

error Vault_UnsupportedCollateral()

Emitted when a user attempts to use a token which is not whitelisted as collateral

Vault_WithdrawExcessiveAmount

error Vault_WithdrawExcessiveAmount()

Emitted when a user attempts to withdraw more than their balance

Vault_WithdrawInsufficientAllowance

error Vault_WithdrawInsufficientAllowance()

Emitted when a user attempts to withdraw more than their allowance

Vault_ZeroAddressConstructor

error Vault_ZeroAddressConstructor(uint8 paramIndex)

Emitted when the zero address is provided as a parameter in the constructor

Parameters

Last updated