Skip to content

Joewizy/Decentralized-Stablecoin-Contract

Repository files navigation

Foundry DEFI Stablecoin

This project aims to create a stablecoin where users can deposit WETH (Wrapped Ether) and WBTC (Wrapped Bitcoin) as collateral and receive a USD-pegged stablecoin in return.

Installation

To get started install both Git and Foundry

  • Git: After installation make sure to run git --version to confirm installation if you see a response like git version 2.34.1 then it was successful.

  • Foundry: After installation run forge --version if you see a response like forge 0.2.0 (8549aad 2024-08-19T00:21:29.325298874Z) then it was successful.

Clone the repository

git clone https://github.com/Joewizy/Decentralized-Stablecoin-Contract
cd Decentralized-Stablecoin-Contractfoundry-defi-stablecoin
forge build

Test

$ forge test

Test Coverage

$ forge coverage

To view detailed test coverage reports for your contracts

Usage

Start a local node

$ make anvil

Deploy

By default, your local node will be used here. For it to deploy, anvil must be running in a separate terminal.

$ make deploy

Deploy to a Testnet or Mainnet

By default, your local node will be used here. For it to deploy, it must be running in a separate terminal. All this varaibles should be added to your .env file.

  1. Setup your environment variables PRIVATE_KEY , ETHERSCAN_API_KEY and SEPOLIA_RPC_URL.
  • PRIVATE_KEY: Import your metamask private key. It is recommended you use a wallet with no funds or a burner wallet. Learn how to export private key HERE
  • SEPOLIA_RPC_URL: This is URL of the sepolia testnet node you're working with. You can get setup with one for free from Alchemy
  • ETHERSCAN_API_KEY: for verification of your contract on Etherscan. Learn how to get one HERE
  1. Get ETH testnet tokens by heading over to faucets.chain.link and claim some testnet ETH.
  2. Deploy
source .env
make deploy ARGS="--network sepolia"

Scripts

We can communicate with the contract directly with the cast command in place of scripts. For example, on Sepolia:

  • Get some WETH
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "deposit()" --value 0.1ether --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY

0xdd13E55209Fd76AfE204dBda4007C227904f0a81 = WETH address

  • Approve the WETH
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "approve(address,uint256)" 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 1000000000000000000 --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY
  • Deposit and Mint Decentralized Stablecoin (DSC)
cast send 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 "depositCollateralAndMintDsc(address,uint256,uint256)" 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 100000000000000000 10000000000000000 --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY

Gas Snapshots

You can estimate how much gas things cost by running:

$ forge snapshot

And you'll see an output file called .gas-snapshot

Help

$ forge --help
$ anvil --help
$ cast --help

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published