This repository contains a set of Solidity smart contracts for a RebaseToken and its associated Vault contract, built using Foundry testing framework. The project is designed to simulate a rebase mechanism where the token's balance grows over time based on an interest rate set by the owner. The vault allows users to deposit ETH and mint corresponding RebaseToken, which can later be redeemed for the original ETH plus accrued interest.
The main components of this project are:
-
RebaseToken: A token with an interest mechanism that rebase the token supply based on a set interest rate. The balance of tokens held by users increases over time.
-
Vault: A contract that allows users to deposit ETH, mint corresponding
RebaseTokenin return, and later redeem them for ETH and any accrued interest.
The vault allows for flexible and secure management of user deposits and token minting/burning, while also implementing rebase functionality to reward users with increasing token balances.
- Deposit ETH: Users can deposit ETH into the vault and receive corresponding
RebaseToken. - Accruing Interest: Token balances grow over time based on a configurable interest rate.
- Token Redemption: Users can redeem their
RebaseTokento get back the original amount of ETH plus any accrued interest. - Interest Rate Control: The owner can set and update the interest rate, but the rate can only decrease.
- Transfers: Users can transfer
RebaseTokenbetween each other. - Security: Only the owner can set the interest rate or mint/burn tokens.
The RebaseToken contract is a custom token that supports rebase functionality. The rebase mechanism allows the total supply of tokens to increase based on an interest rate, which is applied periodically.
mint(address to, uint256 amount): Mints new tokens to a specified address.burn(address from, uint256 amount): Burns tokens from a specified address.setInterestRate(uint256 rate): Sets the interest rate (owner only).getInterestRate(): Gets the current interest rate.balanceOf(address account): Returns the token balance of an address.principleBalanceOfUser(address user): Returns the initial principle balance of a user.
The Vault contract allows users to deposit ETH and mint RebaseToken in return. It also allows users to redeem their tokens later for the initial deposit plus any accrued interest.
depositAndMint(): Deposits ETH and mints correspondingRebaseToken.redeem(uint256 amount): Redeems a specified amount ofRebaseTokenfor ETH.getRebaseTokenAddress(): Returns the address of the associatedRebaseToken.
To get started, clone the repository and install the required dependencies.
git clone https://github.com/Rahber-1/CCIP_Rebase_Project.git
cd CCIP_Rebase_ProjectMake sure you have Foundry installed. If you don’t have it, you can install it by following the instructions on the Foundry GitHub page.
The project includes a comprehensive suite of tests that cover the primary functionalities of the RebaseToken and Vault contracts.
To run the tests, use the following command:
forge testThis will compile the contracts and run the tests using the Foundry framework.
- testRebaseTokenAddress: Verifies that the vault stores the correct
RebaseTokenaddress. - testDepositLinear: Simulates a deposit of ETH into the vault and checks the linear increase in
RebaseTokenbalance over time. - testRedeemWithoutInterestAccrued: Ensures users can redeem their tokens without interest.
- testRedeemWithInterestAccrued: Simulates the redemption of tokens with interest.
- testTransfer: Verifies the transfer of
RebaseTokenbetween users. - testCannotSetInterestRate: Ensures that only the owner can change the interest rate.
- testCannotMintTokens: Ensures unauthorized users cannot mint tokens.
- testCannotBurnTokens: Ensures unauthorized users cannot burn tokens.
- Deploy the Contracts: Deploy the
RebaseTokenandVaultcontracts on your Ethereum-compatible blockchain. - Deposit ETH: Users can deposit ETH into the vault using the
depositAndMintfunction. In return, they will receiveRebaseToken. - Track Interest: Over time, the balance of
RebaseTokenwill increase based on the current interest rate. - Redeem Tokens: Users can redeem their
RebaseTokenfor their original deposit plus any accrued interest using theredeemfunction. - Transfer Tokens: Users can transfer their
RebaseTokento other users using thetransferfunction.
This project is licensed under the MIT License - see the LICENSE file for details.