Skip to content

Latest commit

 

History

History
466 lines (397 loc) · 14.4 KB

LoanToken.md

File metadata and controls

466 lines (397 loc) · 14.4 KB

Loan Token contract. (LoanToken.sol)

View Source: contracts/connectors/loantoken/LoanToken.sol

↗ Extends: AdvancedTokenStorage

LoanToken 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.

  • A loan token (iToken) is created as a proxy to an upgradable token contract.
  • Examples of loan tokens on Sovryn are iRBTC, iDOC, iUSDT, iBPro, iSOV (near future).
  • Lenders receive iTokens that collect interest from the lending pool which they can redeem by withdrawing them. The i in iToken stands for interest.
  • Do not confuse iTokens with underlying tokens. iDOC is an iToken (loan token) whilest DOC is the underlying token (currency).

Contract Members

Constants & Variables

//public members
address public sovrynContractAddress;
address public wrbtcTokenAddress;
address public admin;

//internal members
address internal target_;

Functions


constructor

Deploy loan token proxy. Sets ERC20 parameters of the token. *

function (address _newOwner, address _newTarget, address _sovrynContractAddress, address _wrbtcTokenAddress) public nonpayable

Arguments

Name Type Description
_newOwner address The address of the new owner.
_newTarget address The address of the new target contract instance.
_sovrynContractAddress address The address of the new sovrynContract instance.
_wrbtcTokenAddress address The address of the new wrBTC instance.
Source Code
constructor(
        address _newOwner,
        address _newTarget,
        address _sovrynContractAddress,
        address _wrbtcTokenAddress
    ) public {
        transferOwnership(_newOwner);
        _setTarget(_newTarget);
        _setSovrynContractAddress(_sovrynContractAddress);
        _setWrbtcTokenAddress(_wrbtcTokenAddress);
    }

constructor

Fallback function performs a delegate call to the actual implementation address is pointing this proxy. Returns whatever the implementation call returns.

function () external payable
Source Code
function() external payable {
        if (gasleft() <= 2300) {
            return;
        }

        address target = target_;
        bytes memory data = msg.data;
        assembly {
            let result := delegatecall(gas, target, add(data, 0x20), mload(data), 0, 0)
            let size := returndatasize
            let ptr := mload(0x40)
            returndatacopy(ptr, 0, size)
            switch result
                case 0 {
                    revert(ptr, size)
                }
                default {
                    return(ptr, size)
                }
        }
    }

setTarget

Public owner setter for target address.

function setTarget(address _newTarget) public nonpayable onlyOwner 

Arguments

Name Type Description
_newTarget address The address of the new target contract instance.
Source Code
function setTarget(address _newTarget) public onlyOwner {
        _setTarget(_newTarget);
    }

_setTarget

Internal setter for target address.

function _setTarget(address _newTarget) internal nonpayable

Arguments

Name Type Description
_newTarget address The address of the new target contract instance.
Source Code
function _setTarget(address _newTarget) internal {
        require(Address.isContract(_newTarget), "target not a contract");
        target_ = _newTarget;
    }

_setSovrynContractAddress

Internal setter for sovrynContract address.

function _setSovrynContractAddress(address _sovrynContractAddress) internal nonpayable

Arguments

Name Type Description
_sovrynContractAddress address The address of the new sovrynContract instance.
Source Code
function _setSovrynContractAddress(address _sovrynContractAddress) internal {
        require(Address.isContract(_sovrynContractAddress), "sovryn not a contract");
        sovrynContractAddress = _sovrynContractAddress;
    }

_setWrbtcTokenAddress

Internal setter for wrBTC address.

function _setWrbtcTokenAddress(address _wrbtcTokenAddress) internal nonpayable

Arguments

Name Type Description
_wrbtcTokenAddress address The address of the new wrBTC instance.
Source Code
function _setWrbtcTokenAddress(address _wrbtcTokenAddress) internal {
        require(Address.isContract(_wrbtcTokenAddress), "wrbtc not a contract");
        wrbtcTokenAddress = _wrbtcTokenAddress;
    }

initialize

Public owner cloner for pointed loan token. Sets ERC20 parameters of the token. *

function initialize(address _loanTokenAddress, string _name, string _symbol) public nonpayable onlyOwner 

Arguments

Name Type Description
_loanTokenAddress address The address of the pointed loan token instance.
_name string The ERC20 token name.
_symbol string The ERC20 token symbol.
Source Code
function initialize(
        address _loanTokenAddress,
        string memory _name,
        string memory _symbol
    ) public onlyOwner {
        loanTokenAddress = _loanTokenAddress;

        name = _name;
        symbol = _symbol;
        decimals = IERC20(loanTokenAddress).decimals();

        initialPrice = 10**18; /// starting price of 1
    }

Contracts