Token Deposit Box
Prevents a contract from calling itself, directly or indirectly.
nonReentrant function from another
function is not supported. It is possible to prevent this from happening
by making the
nonReentrant function external, and make it call a
private function that does the actual work.
Designed to prevent a view-only method from being re-entered during a call to a
nonReentrant() state-changing method.
constructor(address _collateralAddress, address _finderAddress, bytes32 _priceIdentifier, address _timerAddress) public
Construct the DepositBox.
_collateralAddress: ERC20 token to be deposited.
_finderAddress: UMA protocol Finder used to discover other protocol contracts.
_priceIdentifier: registered in the DVM, used to price the ERC20 deposited. The price identifier consists of a "base" asset and a "quote" asset. The "base" asset corresponds to the collateral ERC20 currency deposited into this account, and it is denominated in the "quote" asset on withdrawals. An example price identifier would be "ETH-USD" which will resolve and return the USD price of ETH.
_timerAddress: Contract that stores the current time in a testing environment. Must be set to 0x0 for production environments that use live time.
This should be called after construction of the DepositBox and handles registration with the Registry, which is required to make price requests in production environments.
This contract must hold the
ContractCreator role with the Registry in order to register itself as a financial-template with the DVM.
_registerContract cannot be called from the constructor because this contract first needs to be given the
in order to register with the
Registry. But, its address is not known until after deployment.
collateralCurrency into caller’s deposit box.
This contract must be approved to spend at least
collateralAmount: total amount of collateral tokens to be sent to the sponsor’s position.
Starts a withdrawal request that allows the sponsor to withdraw
from their position denominated in the quote asset of the price identifier, following a DVM price resolution.
The request will be pending for the duration of the DVM vote and can be cancelled at any time. Only one withdrawal request can exist for the user.
denominatedCollateralAmount: the quote-asset denominated amount of collateral requested to withdraw.
After a passed withdrawal request (i.e., by a call to
requestWithdrawal and subsequent DVM price resolution),
depositBoxData.withdrawalRequestAmount of collateral currency denominated in the quote asset.
Might not withdraw the full requested amount in order to account for precision loss or if the full requested amount exceeds the collateral in the position (due to paying fees).
remargin are required to be implemented by all financial contracts and exposed to the DVM, but
because this is a minimal demo they will simply exit silently.
Same comment as
emergencyShutdown. For the sake of simplicity, this will simply exit silently.
Accessor method for a user’s collateral.
This is necessary because the struct returned by the depositBoxes() method shows rawCollateral, which isn’t a user-readable value.
user: address whose collateral amount is retrieved.
Accessor method for the total collateral stored within the entire contract.
Sets the current time.
Will revert if not running in test mode.
time: timestamp to set current Testable time to.
Gets the current time. Will return the last time set in
setCurrentTime if running in test mode.
Otherwise, it will return the block timestamp.