This is a section of the Cyfrin Foundry Solidity course.
This project is a cross-chain rebase token where users can depost ETH in exchange for rebase tokens which accrue rewards over time.
- Foundry Cross Chain Rebase Token
- About
- Getting Started
- Updates
- Usage
- Deployment to a testnet or mainnet
- Formatting
- Thank you!
- 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
## Quickstart
git clone https://github.com/Cyfrin/foundry-cross-chain-rebase-token-cu
cd foundry-cross-chain-rebase-token-cu
forge build
make anvil
This will default to your local node. You need to have it running in another terminal in order for it to deploy.
make deploy
We talk about 4 test tiers on Updraft:
- Unit
- Integration
- Forked
- Staging
In this repo we cover #1 and Fuzzing.
forge test
forge coverage
and for coverage based testing:
forge coverage --report debug
- 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.- You can learn how to export it 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
Optionally, add your ETHERSCAN_API_KEY
if you want to verify your contract on Etherscan.
- Get testnet ETH
Head over to faucets.chain.link and get some testnet ETH. You should see the ETH show up in your metamask.
- Deploy
make deploy ARGS="--network sepolia"
Instead of scripts, we can directly use the cast
command to interact with the contract.
For example, on Sepolia:
- Get some RebaseTokens
cast send <vault-contract-address> "deposit()" --value 0.1ether --rpc-url $SEPOLIA_RPC_URL --wallet
- 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
To run code formatting:
forge fmt
## 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
- 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