Skip to content

Rahber-1/CCIP_Rebase_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RebaseToken & Vault Contract

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.

Table of Contents

Overview

The main components of this project are:

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

  2. Vault: A contract that allows users to deposit ETH, mint corresponding RebaseToken in 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.

Features

  • 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 RebaseToken to 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 RebaseToken between each other.
  • Security: Only the owner can set the interest rate or mint/burn tokens.

Contracts

1. RebaseToken.sol

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.

Functions:

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

2. Vault.sol

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.

Functions:

  • depositAndMint(): Deposits ETH and mints corresponding RebaseToken.
  • redeem(uint256 amount): Redeems a specified amount of RebaseToken for ETH.
  • getRebaseTokenAddress(): Returns the address of the associated RebaseToken.

Installation

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_Project

Make sure you have Foundry installed. If you don’t have it, you can install it by following the instructions on the Foundry GitHub page.

Testing

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 test

This will compile the contracts and run the tests using the Foundry framework.

Test Cases Included:

  • testRebaseTokenAddress: Verifies that the vault stores the correct RebaseToken address.
  • testDepositLinear: Simulates a deposit of ETH into the vault and checks the linear increase in RebaseToken balance over time.
  • testRedeemWithoutInterestAccrued: Ensures users can redeem their tokens without interest.
  • testRedeemWithInterestAccrued: Simulates the redemption of tokens with interest.
  • testTransfer: Verifies the transfer of RebaseToken between 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.

Usage

  1. Deploy the Contracts: Deploy the RebaseToken and Vault contracts on your Ethereum-compatible blockchain.
  2. Deposit ETH: Users can deposit ETH into the vault using the depositAndMint function. In return, they will receive RebaseToken.
  3. Track Interest: Over time, the balance of RebaseToken will increase based on the current interest rate.
  4. Redeem Tokens: Users can redeem their RebaseToken for their original deposit plus any accrued interest using the redeem function.
  5. Transfer Tokens: Users can transfer their RebaseToken to other users using the transfer function.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published