A DeFi Stablecoin project using
- Foundry
- Chainlink Feeds
- Formal Verification with Branching Tree Technique (BTT): See Testing Overview for more details on Testing.
- DeFi: Indian Rupee Stablecoin
- Tasklist
- Getting Started
- Development
- Usage
- Deployment to a testnet or mainnet
- Foundry Project Dockerized Setup
- INRC ERC20 Contract
- INRCEngine
- Deposit & Minting
- Redeem Collateral
- Burn INRC
- Liquidate
- Helper Functions
- Scripts
- BaseScript
-
INRC(Not really needed) - INRCEngine
- Interactions (if needed)
- Testing: Formal Verification with BTT
-
BaseScript-
Broadcast(Requires rewriting to accomodate function params instead of environment variables update)
-
- INRCEngine
- Constructor
- Deposit Collateral
- Mint INRC
- Redeem Collateral
- Burn INRC
- Liquidate
- Helper Functions
- getINRValueOf
- getINRValueOfCollateralFor
- getTknCxEquivalentOfINRC
- Getters
- getCollateralDepositedBy
- getINRCMintedBy
- getHealthFactor
- INRC
-
- Makefile
- README
- Generalize to make it Any Currency stablecoin (Requires nomenclature update. Already works perfectly as JPY coin in Sepolia tests)
- Relative Stability: Pegged or Floating?
- Pegged to ₹ (INR) => 1.00 INRC = ₹ 1.00
- Stability Method: Governed or Algorithmic?
- Algorithmic (Decentralized)
- Collateral Type: Endogenous or Exogenous?
- Exogenous (Crypto)
- wETH
- wBTC
- Exogenous (Crypto)
- Chainlink Price Feeds are used to get us ETH & BTC equivalent of USD($) and subsequently INR(₹).
- Users with enough collateral can mint stablecoin.
- Users are incentivized to liquidate under-collateralized users.
In this project, we use Formal Verification using Branching Tree Technique (BTT)
The focus is on the following Foundry test categories:
- Unit Testing: Functions involving a single contract
- Integration Testing: Functions involving a multiple contracts
- Invariant Testing: Expressions that always hold true
- Fork Testing: Tests running against a production chain
using Foundry's test-subcategories:
- Concrete Testing: Standard deterministic tests the takes no inputs
- Fuzz Testing: Non-deterministic tests that takes fuzzed inputs
File | % Lines | % Statements | % Branches | % Funcs |
---|---|---|---|---|
src/INRC.sol | 100.00% (3/3) | 100.00% (3/3) | 100.00% (0/0) | 100.00% (2/2) |
src/INRCEngine.sol | 89.04% (65/73) | 92.31% (96/104) | 81.82% (18/22) | 89.47% (17/19) |
The test suites use JPY price feed on Sepolia Testnet as Chainlink doesn't offer INR Price Feeds on Sepolia.
Update the current currency rates (
WETH_JPY_PRICE
, etc.) inINRCEngine.t.sol
at the time of running forked tests. An update is likely to be good for a couple of hours. Tests have a built-in tolerance of handling upto 1% change in price and still pass.
- git
- You'll know you did it right if you can run
git --version
and you see a response likegit version x.x.x
- You'll know you did it right if you can run
- foundry
- You'll know you did it right if you can run
forge --version
and you see a response likeforge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
- You'll know you did it right if you can run
git clone https://github.com/shobhit-gupta/IndianRupeeStablecoin
cd IndianRupeeStablecoin
make build
To run code formatting:
make fmt
make anvil
If you're having a hard time installing the libraries, you can optionally run this command.
make install
This will default to your local node. You need to have it running in another terminal in order for it to deploy.
make deploy
Generally you'll want to set private keys for test users (ADMIN
, ALICE
, BOB
& EVE
) as environment variables. You can add them to a .env
file, similar to what you see in .env.example
. All of these users might not be used. For instance, this project doesn't make use of EVE
so far. NOTE: FOR DEVELOPMENT, PLEASE USE KEYS THAT DON'T HAVE ANY REAL FUNDS ASSOCIATED WITH THEM.
forge test -vvv
or
source .env
forge test -vvv --fork-url $SEPOLIA_RPC_URL
make coverage
- Setup environment variables
You'll want to set your SEPOLIA_RPC_URL
& MAINNET_RPC_URL
as environment variables. You can add them to a .env
file, similar to what you see in .env.example
.
SEPOLIA_RPC_URL
: This is url of the sepolia testnet node you're working with.MAINNET_RPC_URL
: This is url of the mainnet node you're working with.
You can get setup with these for free from Alchemy
Optionally, add your ETHERSCAN_API_KEY
if you want to verify your contract on Etherscan.
-
Get testnet ETH Head over to faucets.chain.link or sepoliafaucet.com and get some testnet ETH. You should see the ETH show up in your metamask.
-
Deploy
make deploy ARGS="--network sepolia"
You can estimate how much gas things cost by running:
make snapshot
And you'll see an output file called .gas-snapshot