๐Ÿ’Ž
Diamond Standard - Contract Upgradability
Diamond standard in ๐Ÿ— scaffold-eth

Branch Info

Author: Viraz Malhotra Source code: https://github.com/scaffold-eth/scaffold-eth-examples/tree/diamond-standard Intended audience: Beginners/Intermediate Topics: Scaffold-eth basics, Contract Deployment, Upgradability

๐Ÿƒโ€โ™€๏ธ Quick Start

1
git clone https://github.com/scaffold-eth/scaffold-eth-examples.git
2
โ€‹
3
cd scaffold-eth
Copied!
1
yarn install
Copied!
1
yarn start
Copied!
in a second terminal window:
1
cd scaffold-eth
2
yarn chain
Copied!
in a third terminal window:
1
cd scaffold-eth
2
yarn deploy
Copied!
You can interact with the initial version of the DeFi Facet which demonstrates 2x leverage through v1 Aave Uniswap Market.
A sample defi facet zap transaction on ropsten.

What is Diamond Standard ?

Basically it enables people to write contracts with virtually no size limit in a modular and gas-efficient way.
Diamonds can be upgraded on the fly without having to redeploy existing functionality.
Now in a real scenario a diamond has many faces known as facets so just like that facets here are contracts that you interact with, upgrade etc through the diamond contract.
Diamond Cut is a style guide used to shape diamonds just like that to add, remove, modify any facet. We have a Diamond Cut Facet used to do the same so you can upgrade facets without any hassle.
Before diving into the UI and contracts, I will recommend to go through the EIP to have a complete understanding of the same.
Facets
For demonstration purposes, the current Facet linked with the UI is a DeFi which uses Aave Uniswap Market to leverage 2x by just depositing ETH, and it can be upgraded by redeploying it again(go through deploy.js in detail) after changes and choosing the right upgrade action in UI.
The upgrades are done currently by directly calling the Diamond Cut Facet.
The leverage logic is as follows:
  1. 1.
    swap half of eth to stable coin
  2. 2.
    add liquidity to uniswap
  3. 3.
    deposit a-uni tokens to aave
  4. 4.
    safe borrow stable coin
  5. 5.
    swap half of stable coin to eth
  6. 6.
    add liquidity again to uniswap in same pool
  7. 7.
    deposit a-uni token again to aave