• Stars
    star
    186
  • Rank 200,794 (Top 5 %)
  • Language
    Solidity
  • Created about 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Foundry DeFi Stablecoin

This is a section of the Cyfrin Foundry Solidity Course.

DSCEngine Example Decentralized Stablecoin Example

About

This project is meant to be a stablecoin where users can deposit WETH and WBTC in exchange for a token that will be pegged to the USD.

Getting Started

Requirements

  • git
    • You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • foundry
    • You'll know you did it right if you can run forge --version and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)

Quickstart

git clone https://github.com/Cyfrin/foundry-defi-stablecoin-f23
cd foundry-defi-stablecoin-f23
forge build

Optional Gitpod

If you can't or don't want to run and install locally, you can work with this repo in Gitpod. If you do this, you can skip the clone this repo part.

Open in Gitpod

Updates

  • The latest version of openzeppelin-contracts has changes in the ERC20Mock file. To follow along with the course, you need to install version 4.8.3 which can be done by forge install openzeppelin/[email protected] --no-commit instead of forge install openzeppelin/openzeppelin-contracts --no-commit

Usage

Start a local node

make anvil

Deploy

This will default to your local node. You need to have it running in another terminal in order for it to deploy.

make deploy

Deploy - Other Network

See below

Testing

We talk about 4 test tiers in the video.

  1. Unit
  2. Integration
  3. Forked
  4. Staging

In this repo we cover #1 and Fuzzing.

forge test

Test Coverage

forge coverage

and for coverage based testing:

forge coverage --report debug

Deployment to a testnet or mainnet

  1. Setup environment variables

You'll want to set your SEPOLIA_RPC_URL and PRIVATE_KEY as environment variables. You can add them to a .env file, similar to what you see in .env.example.

  • PRIVATE_KEY: The private key of your account (like from metamask). NOTE: FOR DEVELOPMENT, PLEASE USE A KEY THAT DOESN'T HAVE ANY REAL FUNDS ASSOCIATED WITH IT.
  • 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

Optionally, add your ETHERSCAN_API_KEY if you want to verify your contract on Etherscan.

  1. Get testnet ETH

Head over to faucets.chain.link and get some testnet ETH. You should see the ETH show up in your metamask.

  1. Deploy
make deploy ARGS="--network sepolia"

Scripts

Instead of scripts, we can directly use the cast command to interact with the contract.

For example, on Sepolia:

  1. Get some WETH
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "deposit()" --value 0.1ether --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY
  1. Approve the WETH
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "approve(address,uint256)" 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 1000000000000000000 --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY
  1. Deposit and Mint DSC
cast send 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 "depositCollateralAndMintDsc(address,uint256,uint256)" 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 100000000000000000 10000000000000000 --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY

Estimate gas

You can estimate how much gas things cost by running:

forge snapshot

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

Formatting

To run code formatting:

forge fmt

Slither

slither :; slither . --config-file slither.config.json

Thank you!

If you appreciated this, feel free to follow me or donate!

ETH/Arbitrum/Optimism/Polygon/etc Address: 0x9680201d9c93d65a3603d2088d125e955c73BD65

Patrick Collins Twitter Patrick Collins YouTube Patrick Collins Linkedin Patrick Collins Medium

More Repositories

1

foundry-full-course-f23

2,321
star
2

security-and-auditing-full-course-s23

The ultimate, most advanced, security, DeFi, assembly, web3 auditor course ever created.
Solidity
908
star
3

aderyn

Aderyn 🦜 Rust-based Solidity AST analyzer.
Rust
272
star
4

foundry-devops

Solidity
267
star
5

audit-report-templating

211
star
6

sc-exploits-minimized

A repo to showcase web3 hacks
Solidity
177
star
7

cyfrin-audit-reports

A list of public audit reports conducted by the Cyfrin team
102
star
8

audit-checklist

Aggregated audit checklist
100
star
9

chainlink-lottery

A web3 implementation of a lottery using Chainlink VRF and Chainlink alarm clock to have a totally decentralized lottery
JavaScript
75
star
10

OpenPositions

44
star
11

foundry-fund-me-f23

Solidity
35
star
12

assembly-evm-opcodes-and-formal-verification-course

28
star
13

2023-07-foundry-defi-stablecoin

Solidity
27
star
14

foundry-simple-storage-f23

Solidity
25
star
15

4-puppy-raffle-audit

Solidity
25
star
16

Updraft

23
star
17

remix-simple-storage-f23

Solidity
22
star
18

ctf

A minimal repo to create EVM/solidity capture the flags
Solidity
21
star
19

foundry-smart-contract-lottery-f23

Solidity
21
star
20

alchemy_sdk_py

An SDK to use the Alchemy API
Python
19
star
21

2023-07-escrow

Solidity
17
star
22

remix-fund-me-f23

Solidity
17
star
23

trello_to_audit_report

Python
17
star
24

foundry-upgrades-f23

Solidity
16
star
25

1-horse-store-s23

C++
15
star
26

remix-storage-factory-f23

Solidity
13
star
27

2023-09-ditto

Solidity
13
star
28

codehawks-docs

🦅 CodeHawks documentation
13
star
29

chainlink_feeds

This gets the data from the Chainlink Price feeds in an easy way. Can use either an RPC_URL or the Chainlink Subgraph.
Python
13
star
30

foundry-nft-f23

Solidity
11
star
31

audit-repo-cloner

A Python package to clone a repo and automatically prepare it for audit report generation
Python
11
star
32

foundry-erc20-f23

Solidity
10
star
33

2023-10-PasswordStore

Solidity
10
star
34

5-t-swap-audit

Solidity
10
star
35

2023-07-beedle

Solidity
9
star
36

brownie-stablecoin-v23

Python
9
star
37

2023-08-sparkn

Solidity
9
star
38

evm-wallet-and-post-deployment-course

9
star
39

2023-11-Thunder-Loan

Solidity
8
star
40

8-vault-guardians-audit

Solidity
8
star
41

6-thunder-loan-audit

Solidity
8
star
42

js-backend-engineer

7
star
43

html-fund-me-f23

JavaScript
7
star
44

2023-09-vyper-compiler

Vyper Compiler Audit competition
Python
7
star
45

3-passwordstore-audit

Makefile
7
star
46

diverge-converge-audit

TeX
7
star
47

2023-10-SteadeFi

Solidity
7
star
48

2023-10-Puppy-Raffle

Solidity
6
star
49

flux-link

View and withdraw your LINK in one command
Python
5
star
50

7-boss-bridge-audit

Solidity
5
star
51

demo_code

Python
4
star
52

foundry-dao-f23

Solidity
4
star
53

3-gas-bad-nft-marketplace-audit

Solidity
4
star
54

2023-12-stake-link

TypeScript
4
star
55

2024-01-Morpheus

TypeScript
4
star
56

2023-12-the-standard

JavaScript
3
star
57

2024-03-Moonwell

Solidity
3
star
58

2024-02-one-shot

Solidity
3
star
59

2023-12-Voting-Booth

Solidity
3
star
60

2024-02-Beanstalk-1

TypeScript
3
star
61

chainlink-gmx-automation

High Frequency Price Automation for GMX, Using Chainlink Keeper Data Streams
Solidity
2
star
62

gas-optimization-tips

Contracts and Test for Gas optimization Article
Solidity
2
star
63

dup-hawk

AI Triage Bot - Groups and labels issues submitted to a CodeHawks audits
Python
2
star
64

2024-02-soulmate

Solidity
2
star
65

2023-11-Santas-List

Solidity
2
star
66

2024-01-horse-store

Solidity
2
star
67

2024-01-math-master

Solidity
2
star
68

zksync-contracts

Solidity
2
star
69

.github

1
star
70

alphachain-cl-ea

JavaScript
1
star
71

nyth-by-example

An Example Nyth repo
Rust
1
star
72

2023-11-Boss-Bridge

Solidity
1
star
73

2-math-master-audit

Solidity
1
star
74

aderyn-vscode

TypeScript
1
star
75

2024-03-snek-raffle

Python
1
star