Skip to content

Jer-B/Foundry_Stablecoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English README Jump to Japanese Version

Preview

For an easy interaction with the contract use abi.ninja website. Here is a link to the contract loaded on it: Foundry Stablecoin contract

Click on function on the left to add them in the center of the page and interact with them.

  • Functions under the 'READ' category are for getting actual values.

  • Functions under the 'Write' category are for inserting new data.

  • NOTE: The above contract is deployed on the Sepolia Testnet, so testnet funds are required for interacting with it.

Foundry DeFi Stablecoin

Contract is deployed at 0xxxx View on Sepolia

  1. 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.

I used the 32 hours long video from Cyfrin Foundry Blockchain course to learn about Foundry.
Cyfrin Foundry

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/Jer-B/Foundry_Stablecoin
cd Foundry_Stablecoin
forge build

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

Testing

  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 alchemy_RPC_sepolia and PRIVATE_KEY_TESTNET as environment variables. You can add them to a .env file, similar to what you see in .env.example.

  • PRIVATE_KEY_TESTNET: 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.
  • alchemy_RPC_sepolia: 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 $alchemy_RPC_sepolia --private-key $PRIVATE_KEY_TESTNET
  1. Approve the WETH
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "approve(address,uint256)" 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 1000000000000000000 --rpc-url $alchemy_RPC_sepolia --private-key $PRIVATE_KEY_TESTNET
  1. Deposit and Mint DSC
cast send 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 "depositCollateralAndMintDsc(address,uint256,uint256)" 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 100000000000000000 10000000000000000 --rpc-url $alchemy_RPC_sepolia --private-key $PRIVATE_KEY_TESTNET

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

日本語版のREADME

プレビュー

コントラクトとの簡単な対話には abi.ninja ウェブサイトを使用してください。 以下は、それにロードされたコントラクトへのリンクです: Foundry Stablecoin contract

左側の関数をクリックして、それらをページの中央に追加し、それらと対話します。

  • READカテゴリーの下にある関数は実際の値を取得するためのものです。

  • Writeカテゴリーの下にある関数は新しいデータを挿入するためのものです。

  • 注意: 上記のコントラクトは Sepolia テストネット上にデプロイされており、それと対話するにはテストネット用の資金が必要です。

Foundry DeFi Stablecoin

このコントラクトは、0xxxx にデプロイされています。 View on Sepolia

  1. このプロジェクトは、ユーザーがWETHとWBTCを預け入れ、USDにペッグされたトークンと交換することができるステーブルコインを目指しています。

Foundryを学ぶために、Cyfrin Foundry Blockchainコースの32時間の長いビデオを使用しました。 Cyfrin Foundry

必要条件

  • git
    • git --version を実行して git version x.x.x のような応答が表示されれば成功です。
  • foundry
    • forge --version を実行して forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z) のような応答が表示されれば成功です

Quickstart

git clone https://github.com/Jer-B/Foundry_Stablecoin
cd Foundry_Stablecoin
forge build

パッケージのインストール

  • openzeppelin-contractsの最新バージョンではERC20Mockファイルに変更がありました。バージョン4.8.3をインストールするには、次の手順を実行してください: forge install openzeppelin/openzeppelin-contracts --no-commit の代わりにこのコマンドを使って⇨forge install openzeppelin/[email protected] --no-commit

ローカルノード(ブロックチェーン)を起動する

make anvil

使用方法

デプロイメント:

make deploy

テスト方法

  1. ユニットテスト
  2. 統合テスト
  3. フォークテスト
  4. ステージングテスト

このリポジトリではテスト番号1とファズテストをカバーしています。

forge test

Test Coverage

forge coverage

カバレッジベースのテストのコマンド:

forge coverage --report debug

テストネットまたはメインネットへのデプロイ

  1. 環境変数の設定

alchemy_RPC_sepoliaPRIVATE_KEY_TESTNET を環境変数として設定する必要があります。これらを .env ファイルに追加することができます。.env.example に示されているようなものです。

オプションで、 Etherscan で契約を検証したい場合は ETHERSCAN_API_KEY を追加してください。

  1. テストネットETHを取得

faucets.chain.link にアクセスし、テストネットETHを取得してください。MetamaskでETHが表示されるはずです。

  1. デプロイ
make deploy ARGS="--network sepolia"

Scripts

テストネットまたはローカルネットワークにデプロイした後、スクリプトを実行できます。

ローカルにデプロイされたcastを使用する例:

  1. WETHを取得する
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "deposit()" --value 0.1ether --rpc-url $alchemy_RPC_sepolia --private-key $PRIVATE_KEY_TESTNET
  1. WETHを承認する
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "approve(address,uint256)" 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 1000000000000000000 --rpc-url $alchemy_RPC_sepolia --private-key $PRIVATE_KEY_TESTNET
  1. WETHを預け入れてDSCをミントする
cast send 0x091EA0838eBD5b7ddA2F2A641B068d6D59639b98 "depositCollateralAndMintDsc(address,uint256,uint256)" 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 100000000000000000 10000000000000000 --rpc-url $alchemy_RPC_sepolia --private-key $PRIVATE_KEY_TESTNET

ガス代確認

forge snapshot

.gas-snapshot という名前の出力ファイルが表示されます

フォーマット

コードのフォーマットを実行するには:

forge fmt

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published