View Source: contracts/connectors/loantoken/LoanToken.sol
↗ Extends: AdvancedTokenStorage
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).
Constants & Variables
//public members
address public sovrynContractAddress;
address public wrbtcTokenAddress;
address public admin;
//internal members
address internal target_;
- constructor(address _newOwner, address _newTarget, address _sovrynContractAddress, address _wrbtcTokenAddress)
- constructor()
- setTarget(address _newTarget)
- _setTarget(address _newTarget)
- _setSovrynContractAddress(address _sovrynContractAddress)
- _setWrbtcTokenAddress(address _wrbtcTokenAddress)
- initialize(address _loanTokenAddress, string _name, string _symbol)
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);
}
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)
}
}
}
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);
}
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;
}
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;
}
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;
}
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
}
- Address
- Administered
- AdminRole
- AdvancedToken
- AdvancedTokenStorage
- Affiliates
- AffiliatesEvents
- ApprovalReceiver
- BProPriceFeed
- CheckpointsShared
- Constants
- Context
- DevelopmentFund
- DummyContract
- EnumerableAddressSet
- EnumerableBytes32Set
- EnumerableBytes4Set
- ERC20
- ERC20Detailed
- ErrorDecoder
- Escrow
- EscrowReward
- FeedsLike
- FeesEvents
- FeeSharingCollector
- FeeSharingCollectorProxy
- FeeSharingCollectorStorage
- FeesHelper
- FourYearVesting
- FourYearVestingFactory
- FourYearVestingLogic
- FourYearVestingStorage
- GenericTokenSender
- GovernorAlpha
- GovernorVault
- IApproveAndCall
- IChai
- IContractRegistry
- IConverterAMM
- IERC1820Registry
- IERC20_
- IERC20
- IERC777
- IERC777Recipient
- IERC777Sender
- IFeeSharingCollector
- IFourYearVesting
- IFourYearVestingFactory
- IFunctionsList
- ILiquidityMining
- ILiquidityPoolV1Converter
- ILoanPool
- ILoanToken
- ILoanTokenLogicBeacon
- ILoanTokenLogicModules
- ILoanTokenLogicProxy
- ILoanTokenModules
- ILoanTokenWRBTC
- ILockedSOV
- IMoCState
- IModulesProxyRegistry
- Initializable
- InterestUser
- IPot
- IPriceFeeds
- IPriceFeedsExt
- IProtocol
- IRSKOracle
- ISovryn
- ISovrynSwapNetwork
- IStaking
- ISwapsImpl
- ITeamVesting
- ITimelock
- IV1PoolOracle
- IVesting
- IVestingFactory
- IVestingRegistry
- IWrbtc
- IWrbtcERC20
- LenderInterestStruct
- LiquidationHelper
- LiquidityMining
- LiquidityMiningConfigToken
- LiquidityMiningProxy
- LiquidityMiningStorage
- LoanClosingsEvents
- LoanClosingsLiquidation
- LoanClosingsRollover
- LoanClosingsShared
- LoanClosingsWith
- LoanClosingsWithoutInvariantCheck
- LoanInterestStruct
- LoanMaintenance
- LoanMaintenanceEvents
- LoanOpenings
- LoanOpeningsEvents
- LoanParamsStruct
- LoanSettings
- LoanSettingsEvents
- LoanStruct
- LoanToken
- LoanTokenBase
- LoanTokenLogicBeacon
- LoanTokenLogicLM
- LoanTokenLogicProxy
- LoanTokenLogicStandard
- LoanTokenLogicStorage
- LoanTokenLogicWrbtc
- LoanTokenSettingsLowerAdmin
- LockedSOV
- MarginTradeStructHelpers
- Medianizer
- ModuleCommonFunctionalities
- ModulesCommonEvents
- ModulesProxy
- ModulesProxyRegistry
- MultiSigKeyHolders
- MultiSigWallet
- Mutex
- Objects
- OrderStruct
- OrigingVestingCreator
- OriginInvestorsClaim
- Ownable
- Pausable
- PausableOz
- PreviousLoanToken
- PreviousLoanTokenSettingsLowerAdmin
- PriceFeedRSKOracle
- PriceFeeds
- PriceFeedsLocal
- PriceFeedsMoC
- PriceFeedV1PoolOracle
- ProtocolAffiliatesInterface
- ProtocolLike
- ProtocolSettings
- ProtocolSettingsEvents
- ProtocolSettingsLike
- ProtocolSwapExternalInterface
- ProtocolTokenUser
- Proxy
- ProxyOwnable
- ReentrancyGuard
- RewardHelper
- RSKAddrValidator
- SafeERC20
- SafeMath
- SafeMath96
- setGet
- SharedReentrancyGuard
- SignedSafeMath
- SOV
- sovrynProtocol
- StakingAdminModule
- StakingGovernanceModule
- StakingInterface
- StakingProxy
- StakingRewards
- StakingRewardsProxy
- StakingRewardsStorage
- StakingShared
- StakingStakeModule
- StakingStorageModule
- StakingStorageShared
- StakingVestingModule
- StakingWithdrawModule
- State
- SwapsEvents
- SwapsExternal
- SwapsImplLocal
- SwapsImplSovrynSwap
- SwapsUser
- TeamVesting
- Timelock
- TimelockHarness
- TimelockInterface
- TokenSender
- UpgradableProxy
- USDTPriceFeed
- Utils
- VaultController
- Vesting
- VestingCreator
- VestingFactory
- VestingLogic
- VestingRegistry
- VestingRegistry2
- VestingRegistry3
- VestingRegistryLogic
- VestingRegistryProxy
- VestingRegistryStorage
- VestingStorage
- WeightedStakingModule
- WRBTC