This example will set up a
DepositBox contract which custodies a user’s ERC-20 token balance.
On a local testnet blockchain, the user will deposit ETH into the contract and withdraw ETH corresponding to a desired USD amount.
The user links the
DepositBox with one of the price identifiers enabled on the DVM.
In this example, the user will deposit ETH into the
DepositBox and register it with the "ETH-USD" price identifier.
The user can now withdraw a "USD"-denominated amount of "ETH" from their
DepositBox via smart contract calls.
The feature introduced by the DVM is on-chain pricing of the user's ERC-20 balance.
In this example, the user would not have been able to transfer "USD"-denominated amounts of "ETH" without referencing an off-chain "ETH-USD" price feed.
The DVM therefore enables the user to "pull" a reference price.
While the example below uses ETH as the currency for deposits to the
DepositBox and ETH/USD as the price identifier, the code supports use of any ERC-20 token as the currency for deposits.
The code can also be deployed with other price identifiers.
For example, if users wanted to denominate their withdrawals in BTC instead of USD, the price identifier could be set to ETH/BTC.
Note that this toy example would perform poorly as a mainnet product, given the long period of time it would take for the UMA DVM to return the corresponding amount of ETH. This example is intended to serve as a technical tutorial for how to integrate the DVM into a project. Moreover, the DepositBox user would be paying for the privilege of having the DVM help them withdraw USD denominated ETH deposits.
DepositBox contract will pay regular fees to the DVM proportional to the amount of collateral deposited into the contract. Additionally, whenever a user makes a withdrawal request, the contract will pay a fixed final fee to the DVM.
Details on these two fees are available here.
- Ensure that you have followed all the prerequisite setup steps here.
- Migrate the contracts by running the following command:
- To deploy the
DepositBoxcontract and go through a simple user flow, run the following script from the root of the repo:
You should see the following output: