Skip to content

Cyfrin/foundry-cross-chain-rebase-token-cu

Repository files navigation

Foundry Cross Chain Rebase Token

This is a section of the Cyfrin Foundry Solidity course.

About

This project is a cross-chain rebase token where users can depost ETH in exchange for rebase tokens which accrue rewards over time.

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-cross-chain-rebase-token-cu
cd foundry-cross-chain-rebase-token-cu
forge build

Updates

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 on Updraft:

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

In this repo we cover #1 and Fuzzing.

forge test

Testing 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 RebaseTokens
cast send <vault-contract-address> "deposit()" --value 0.1ether --rpc-url $SEPOLIA_RPC_URL --wallet
  1. Redeem RebaseTokens for ETH
cast send <vault-contractaddress> "redeem(uint256)" 10000000000000000 --rpc-url $SEPOLIA_RPC_URL --wallet

## 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

Thank you!

## Project design and assumptions

WHATEVER INTEREST THEY DEPOSIT WITH, THEY STICK WITH

This project is a cross-chain rebase token that integrates Chainlink CCIP to enable users to bridge their tokens cross-chain

NOTES

  • assumed rewards are in contract
  • Protocol rewards early users and users which bridge to the L2
    • The interest rate decreases discretely
    • The interest rate when a user bridges is bridges with them and stays static. So, by bridging you get to keep your high interest rate.
  • You can only deposit and withdraw on the L1.
  • You cannot earn interest in the time while bridging.

Don't forget to bridge back the amount of interest they accrued on the destination chain in that time

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published