Skip to content

Latest commit

 

History

History
446 lines (384 loc) · 13.9 KB

VaultController.md

File metadata and controls

446 lines (384 loc) · 13.9 KB

The Vault Controller contract. (VaultController.sol)

View Source: contracts/mixins/VaultController.sol

↗ Extends: State ↘ Derived Contracts: InterestUser, LoanClosingsShared, LoanMaintenance, LoanOpenings, SwapsExternal

VaultController contract

This contract code comes from bZx. bZx is a protocol for tokenized margin trading and lending https://bzx.network similar to the dYdX protocol.

  • This contract implements functionality to deposit and withdraw wrBTC and other tokens from the vault.

Events

event VaultDeposit(address indexed asset, address indexed from, uint256  amount);
event VaultWithdraw(address indexed asset, address indexed to, uint256  amount);

Functions


vaultEtherDeposit

Deposit wrBTC into the vault. *

function vaultEtherDeposit(address from, uint256 value) internal nonpayable

Arguments

Name Type Description
from address The address of the account paying the deposit.
value uint256 The amount of wrBTC tokens to transfer.
Source Code
function vaultEtherDeposit(address from, uint256 value) internal {
        IWrbtcERC20 _wrbtcToken = wrbtcToken;
        _wrbtcToken.deposit.value(value)();

        emit VaultDeposit(address(_wrbtcToken), from, value);
    }

vaultEtherWithdraw

Withdraw wrBTC from the vault. *

function vaultEtherWithdraw(address to, uint256 value) internal nonpayable

Arguments

Name Type Description
to address The address of the recipient.
value uint256 The amount of wrBTC tokens to transfer.
Source Code
function vaultEtherWithdraw(address to, uint256 value) internal {
        if (value != 0) {
            IWrbtcERC20 _wrbtcToken = wrbtcToken;
            uint256 balance = address(this).balance;
            if (value > balance) {
                _wrbtcToken.withdraw(value - balance);
            }
            Address.sendValue(to, value);

            emit VaultWithdraw(address(_wrbtcToken), to, value);
        }
    }

vaultDeposit

Deposit tokens into the vault. *

function vaultDeposit(address token, address from, uint256 value) internal nonpayable

Arguments

Name Type Description
token address The address of the token instance.
from address The address of the account paying the deposit.
value uint256 The amount of tokens to transfer.
Source Code
function vaultDeposit(
        address token,
        address from,
        uint256 value
    ) internal {
        if (value != 0) {
            IERC20(token).safeTransferFrom(from, address(this), value);

            emit VaultDeposit(token, from, value);
        }
    }

vaultWithdraw

Withdraw tokens from the vault. *

function vaultWithdraw(address token, address to, uint256 value) internal nonpayable

Arguments

Name Type Description
token address The address of the token instance.
to address ken The address of the token instance.
value uint256 The amount of tokens to transfer.
Source Code
function vaultWithdraw(
        address token,
        address to,
        uint256 value
    ) internal {
        if (value != 0) {
            IERC20(token).safeTransfer(to, value);

            emit VaultWithdraw(token, to, value);
        }
    }

vaultTransfer

Transfer tokens from an account into another one. *

function vaultTransfer(address token, address from, address to, uint256 value) internal nonpayable

Arguments

Name Type Description
token address The address of the token instance.
from address The address of the account paying.
to address ken The address of the token instance.
value uint256 The amount of tokens to transfer.
Source Code
function vaultTransfer(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        if (value != 0) {
            if (from == address(this)) {
                IERC20(token).safeTransfer(to, value);
            } else {
                IERC20(token).safeTransferFrom(from, to, value);
            }
        }
    }

vaultApprove

Approve an allowance of tokens to be spent by an account. *

function vaultApprove(address token, address to, uint256 value) internal nonpayable

Arguments

Name Type Description
token address The address of the token instance.
to address ken The address of the token instance.
value uint256 The amount of tokens to allow.
Source Code
function vaultApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        if (value != 0 && IERC20(token).allowance(address(this), to) != 0) {
            IERC20(token).safeApprove(to, 0);
        }
        IERC20(token).safeApprove(to, value);
    }

Contracts