You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implements the management of the token in each currency for users.
This contract manages the following data related to tokens.
Deposited token amount as the collateral
Parameters related to the collateral
Margin Call Threshold Rate
Auto Liquidation Threshold Rate
Liquidation Price Rate
Min Collateral Rate
To address a currency as collateral, it must be registered using registerCurrency method in this contract.
onlyRegisteredCurrency
modifier onlyRegisteredCurrency(bytes32_ccy)
Modifier to check if currency hasn't been registered yet
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
initialize
function initialize(address_owner, address_resolver, uint256_liquidationThresholdRate, uint256_liquidationProtocolFeeRate, uint256_liquidatorFeeRate, address_uniswapRouter, address_uniswapQuoter, address_WETH9) public
Initializes the contract.
Function is invoked by the proxy contract when the contract is added to the ProxyController.
Name
Type
Description
_owner
address
The address of the contract owner
_resolver
address
The address of the Address Resolver contract
_liquidationThresholdRate
uint256
The liquidation threshold rate
_liquidationProtocolFeeRate
uint256
The liquidation fee rate received by protocol
_liquidatorFeeRate
uint256
The liquidation fee rate received by liquidators
_uniswapRouter
address
Uniswap router contract address
_uniswapQuoter
address
Uniswap quoter contract address
_WETH9
address
The address of WETH
requiredContracts
function requiredContracts() publicpurereturns (bytes32[] contracts)
Returns the contract names used in this contract.
The contract name list is in ./libraries/Contracts.sol.
acceptedContracts
function acceptedContracts() publicpurereturns (bytes32[] contracts)
Returns contract names that can call this contract.
The contact name listed in this method is also needed to be listed requiredContracts method.
receive
receive() externalpayable
isCovered
function isCovered(address_user, bytes32_unsettledOrderCcy, uint256_unsettledOrderAmount, enum ProtocolTypes.Side _unsettledOrderSide) externalviewreturns (bool)
Gets if the collateral has enough coverage.
Name
Type
Description
_user
address
User's address
_unsettledOrderCcy
bytes32
Additional unsettled order currency name in bytes32
_unsettledOrderAmount
uint256
Additional unsettled order amount
_unsettledOrderSide
enum ProtocolTypes.Side
Name
Type
Description
[0]
bool
The boolean if the collateral has sufficient coverage or not
isCovered
function isCovered(address_user) publicviewreturns (bool)
Gets if the collateral has enough coverage.
Name
Type
Description
_user
address
User's address
Name
Type
Description
[0]
bool
The boolean if the collateral has sufficient coverage or not
isCollateral
function isCollateral(bytes32_ccy) publicviewreturns (bool)
Gets if the currency is acceptable as collateral
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
Name
Type
Description
[0]
bool
The boolean if the currency has been registered or not
isCollateral
function isCollateral(bytes32[] _ccys) externalviewreturns (bool[] isCollateralCurrencies)
Gets if the currencies are acceptable as collateral
Name
Type
Description
_ccys
bytes32[]
Currency name list in bytes32
Name
Type
Description
isCollateralCurrencies
bool[]
Array of the boolean if the currency has been registered or not
isRegisteredCurrency
function isRegisteredCurrency(bytes32_ccy) publicviewreturns (bool)
Gets if the currency has been registered
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
Name
Type
Description
[0]
bool
The boolean if the currency has been registered or not
getTokenAddress
function getTokenAddress(bytes32_ccy) publicviewreturns (address)
Gets the token contract address
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
Name
Type
Description
[0]
address
The token contract address
getCollateralCurrencies
function getCollateralCurrencies() externalviewreturns (bytes32[])
Gets the currencies accepted as collateral
Name
Type
Description
[0]
bytes32[]
Array of the currency accepted as collateral
getWithdrawableCollateral
function getWithdrawableCollateral(address_user) externalviewreturns (uint256)
Gets the maximum amount of ETH that can be withdrawn from user collateral.
Name
Type
Description
_user
address
User's address
Name
Type
Description
[0]
uint256
Maximum amount of ETH that can be withdrawn
getCoverage
function getCoverage(address_user) externalviewreturns (uint256coverage)
Gets the rate of collateral used.
Name
Type
Description
_user
address
User's address
Name
Type
Description
coverage
uint256
The rate of collateral used
getUnusedCollateral
function getUnusedCollateral(address_user) externalviewreturns (uint256)
Gets the total amount of the unused collateral
Name
Type
Description
_user
address
User's address
Name
Type
Description
[0]
uint256
The total amount of unused collateral
getTotalCollateralAmount
function getTotalCollateralAmount(address_user) publicviewreturns (uint256totalCollateralAmount)
Gets the total collateral amount.
Name
Type
Description
_user
address
User's address
Name
Type
Description
totalCollateralAmount
uint256
The total collateral amount in ETH
getLiquidationAmount
function getLiquidationAmount(address_user) externalviewreturns (uint256liquidationAmount)
Gets the amount to be liquidated.
Name
Type
Description
_user
address
User's address
Name
Type
Description
liquidationAmount
uint256
The the amount to be liquidated
getTotalDepositAmount
function getTotalDepositAmount(bytes32_ccy) externalviewreturns (uint256)
Gets the total amount deposited of the selected currency
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
Name
Type
Description
[0]
uint256
The total deposited amount
getDepositAmount
function getDepositAmount(address_user, bytes32_ccy) externalviewreturns (uint256)
Gets the amount deposited in the user's collateral.
Name
Type
Description
_user
address
User's address
_ccy
bytes32
Currency name in bytes32
Name
Type
Description
[0]
uint256
The deposited amount
getUsedCurrencies
function getUsedCurrencies(address_user) publicviewreturns (bytes32[])
Gets the currencies that the user used as collateral.
Name
Type
Description
_user
address
User's address
Name
Type
Description
[0]
bytes32[]
The currency names in bytes32
getCollateralParameters
function getCollateralParameters() externalviewreturns (uint256liquidationThresholdRate, uint256liquidationProtocolFeeRate, uint256liquidatorFeeRate, addressuniswapRouter, addressuniswapQuoter)
Gets the collateral parameters
Name
Type
Description
liquidationThresholdRate
uint256
Auto liquidation threshold rate
liquidationProtocolFeeRate
uint256
Liquidation fee rate received by protocol
liquidatorFeeRate
uint256
Liquidation fee rate received by liquidators
uniswapRouter
address
Uniswap router contract address
uniswapQuoter
address
Uniswap quoter contract address
registerCurrency
function registerCurrency(bytes32_ccy, address_tokenAddress, bool_isCollateral) external
Registers new currency and sets if it is acceptable as collateral.
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
_tokenAddress
address
Token contract address of the selected currency
_isCollateral
bool
Boolean if the selected currency is acceptable as collateral.
updateCurrency
function updateCurrency(bytes32_ccy, bool_isCollateral) external
Updates the currency if it is acceptable as collateral.
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
_isCollateral
bool
Boolean if the selected currency is acceptable as collateral.
deposit
function deposit(bytes32_ccy, uint256_amount) externalpayable
Deposits funds by the caller into collateral.
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
_amount
uint256
Amount of funds to deposit
depositFrom
function depositFrom(address_from, bytes32_ccy, uint256_amount) externalpayable
Deposits funds by the from into collateral.
Name
Type
Description
_from
address
user's address
_ccy
bytes32
Currency name in bytes32
_amount
uint256
Amount of funds to deposit
withdraw
function withdraw(bytes32_ccy, uint256_amount) external
Withdraws funds by the caller from unused collateral.
Name
Type
Description
_ccy
bytes32
Currency name in bytes32
_amount
uint256
Amount of funds to withdraw.
addDepositAmount
function addDepositAmount(address_user, bytes32_ccy, uint256_amount) external
Adds deposit amount.
Name
Type
Description
_user
address
User's address
_ccy
bytes32
Currency name in bytes32
_amount
uint256
Amount of funds to deposit
removeDepositAmount
function removeDepositAmount(address_user, bytes32_ccy, uint256_amount) external
Removes deposit amount.
Name
Type
Description
_user
address
User's address
_ccy
bytes32
Currency name in bytes32
_amount
uint256
Amount of funds to withdraw.
swapDepositAmounts
function swapDepositAmounts(address_liquidator, address_user, bytes32_ccyFrom, bytes32_ccyTo, uint256_amountOut, uint24_poolFee, uint256_offsetAmount) externalreturns (uint256amountOut)
Swap the deposited amount to convert to a different currency using Uniswap for liquidation.
Name
Type
Description
_liquidator
address
Liquidator's address
_user
address
User's address
_ccyFrom
bytes32
Currency name to be converted from
_ccyTo
bytes32
Currency name to be converted to
_amountOut
uint256
Amount to be converted to
_poolFee
uint24
Uniswap pool fee
_offsetAmount
uint256
User's deposit amount to be offset against the reserve fund
setCollateralParameters
function setCollateralParameters(uint256_liquidationThresholdRate, uint256_liquidationProtocolFeeRate, uint256_liquidatorFeeRate, address_uniswapRouter, address_uniswapQuoter) external
Sets main collateral parameters this function
solves the issue of frontrunning during parameters tuning.
Triggers only be contract owner
Name
Type
Description
_liquidationThresholdRate
uint256
The auto liquidation threshold rate
_liquidationProtocolFeeRate
uint256
The liquidation fee rate received by protocol
_liquidatorFeeRate
uint256
The liquidation fee rate received by liquidators
_uniswapRouter
address
Uniswap router contract address
_uniswapQuoter
address
Uniswap quoter contract address
_deposit
function _deposit(address_user, bytes32_ccy, uint256_amount) internal
_withdraw
function _withdraw(address_user, bytes32_ccy, uint256_amount) internal