A sophisticated DeFi protocol that implements an interest-bearing rebase token system with cross-chain capabilities using Chainlink CCIP. Users can deposit ETH into a vault and receive rebase tokens that automatically accrue interest over time.
This project consists of three main smart contracts and supporting deployment scripts:
An advanced ERC20 token that automatically increases holder balances over time based on individual interest rates:
- Automatic Interest Accrual: Balances grow continuously based on time elapsed
- Individual Interest Rates: Each user can have a custom interest rate set during minting
- Role-Based Access Control: Secure minting and burning operations via AccessControl
- High Precision Calculations: Uses 1e18 precision factor for accurate interest computation
- Owner Controls: Global interest rate management with decrease-only safeguards
- Max Amount Support: Special handling for
type(uint256).maxtransfers and burns
A Chainlink CCIP token pool that enables cross-chain transfers while preserving interest rates:
- Burn-and-Mint Mechanism: Secure cross-chain token transfers
- Interest Rate Preservation: Maintains user's individual interest rates across chains
- CCIP Integration: Full compatibility with Chainlink's Cross-Chain Interoperability Protocol
- Security Features: Rate limiting and allowlist support for enhanced protection
- Encoded Transfer Data: Smart encoding of interest rates in cross-chain messages
A secure vault contract that bridges ETH and RebaseTokens with automatic interest assignment:
- 1:1 Exchange Rate: Deposit ETH to receive equivalent RebaseTokens
- Interest-Bearing Deposits: Your tokens automatically grow while in your wallet
- Flexible Redemption: Redeem tokens back to ETH at any time including full balance
- Automatic Rate Assignment: New deposits inherit current global interest rate
- Secure ETH Handling: Robust error handling for failed ETH transfers
- โ Interest-Bearing Tokens: Balances automatically increase over time
- โ Flexible Interest Rates: Per-user customizable rates
- โ Secure Architecture: Role-based access control and ownership patterns
- โ Gas Optimized: Efficient interest calculations with precision factors
- โ Cross-Chain Ready: Built with Chainlink CCIP integration in mind
- โ 100% Test Coverage: Complete test suite with comprehensive edge case coverage
- Solidity ^0.8.24: Smart contract development
- Foundry: Development framework and testing
- OpenZeppelin: Security-audited contract libraries
- Chainlink CCIP: Cross-chain interoperability protocol
- Foundry
- Git
-
Clone the repository
git clone https://github.com/chauhan-varun/cross-chain-rebase-token.git cd cross-chain-rebase-token -
Install dependencies
forge install
-
Build the project
forge build
-
Run tests
forge test
forge buildforge testforge test -vvvforge fmtforge snapshotforge coverageGenerate detailed coverage report:
forge coverage --report lcov- Inherits: ERC20, Ownable, AccessControl
- Key State Variables:
s_interestRate: Global interest rate (default: 5e18 = 5% annually)s_userInterestRate: Mapping of user-specific interest ratess_userLastTimestamp: Mapping of user's last interaction timestamps
- Key Functions:
mint(address, uint256, uint256): Mint tokens with custom interest rateburn(address, uint256): Burn tokens from an address (supports max amount)setInterestRate(uint256): Update global interest rate (owner only, decrease-only)balanceOf(address): Returns current balance including accrued interestprincipleBalanceOf(address): Returns original minted amount without interesttransfer(address, uint256): Enhanced transfer with interest accrual and rate inheritancetransferFrom(address, address, uint256): Enhanced transferFrom with same features
- Inherits: TokenPool (Chainlink CCIP)
- Key Features:
- Cross-chain burn-and-mint mechanism
- Interest rate preservation across chains
- Integration with CCIP router and RMN proxy
- Key Functions:
lockOrBurn(Pool.LockOrBurnInV1): Burns tokens and encodes interest rate for cross-chain transferreleaseOrMint(Pool.ReleaseOrMintInV1): Mints tokens with preserved interest rate on destination chain
- Key State Variables:
i_rebaseToken: Immutable reference to RebaseToken contract
- Key Functions:
deposit(): Deposit ETH, receive RebaseTokens with current global interest rateredeem(uint256): Redeem RebaseTokens for ETH (supports max amount redemption)getRebaseTokenAddress(): Returns RebaseToken contract addressgetCurrentInterestRate(): Returns current global interest ratereceive(): Fallback function for direct ETH deposits
The project includes comprehensive tests with 100% code coverage for all core contracts:
- RebaseToken.sol: 100% Lines, 100% Statements, 100% Branches, 100% Functions
- Vault.sol: 100% Lines, 100% Statements, 100% Branches, 100% Functions
- RebaseTokenPool.sol: 100% Lines, 100% Statements, 100% Branches, 100% Functions
- โ RebaseTokenTest: Core token functionality and interest mechanics (9 tests)
- โ AdditionalCoverageTest: Edge cases, max amounts, and error scenarios (11 tests)
- โ CrossChainTest: Cross-chain bridging and CCIP functionality (3 tests)
- โ Total: 23 tests with comprehensive coverage
- โ Token Operations: Minting, burning, transfers with interest rate handling
- โ Interest Mechanics: Time-based interest accrual and rate calculations
- โ Vault Operations: ETH deposits, token redemptions, and exchange flows
- โ Access Control: Role-based permissions and ownership management
- โ Edge Cases: Zero balances, max transfers, failed transactions, different interest rates
- โ Cross-chain Features: CCIP bridging, interest rate preservation across chains
- โ Error Handling: Revert scenarios and comprehensive error condition testing
Run specific test files:
forge test --match-contract RebaseTokenTest
forge test --match-contract AdditionalCoverageTest
forge test --match-contract CrossChainTest- Access Control: Role-based permissions for critical functions
- Integer Overflow: SafeMath patterns and Solidity 0.8+ built-in protection
- Reentrancy: Proper state updates before external calls
- Precision: High-precision arithmetic for accurate interest calculations
- 100% Test Coverage: All code paths tested including edge cases and error conditions
- Failed Transaction Handling: Comprehensive error handling for ETH transfers and edge cases
anvilsrc/
โโโ RebaseToken.sol # Main rebasing ERC20 token contract
โโโ RebaseTokenPool.sol # CCIP token pool for cross-chain transfers
โโโ Vault.sol # ETH โท RebaseToken exchange vault
โโโ interface/
โโโ IRebaseToken.sol # RebaseToken interface for external integrations
script/
โโโ Deployer.s.sol # Deploys RebaseToken and RebaseTokenPool contracts
โโโ ConfigurePool.s.sol # Configures token pool settings and permissions
โโโ BridgeTokens.s.sol # Handles cross-chain token bridging operations
โโโ Interactions.s.sol # Utility script for contract interactions
test/
โโโ RebaseTokenTest.t.sol # Core RebaseToken functionality tests
โโโ AdditionalCoverageTest.t.sol # Edge cases and comprehensive coverage tests
โโโ CrossChainTest.t.sol # Cross-chain bridging tests
- Deployer.s.sol: Comprehensive deployment script that sets up RebaseToken and RebaseTokenPool contracts with proper CCIP infrastructure including router and RMN proxy configuration
- ConfigurePool.s.sol: Post-deployment configuration script for setting up token pool parameters, allowlists, and admin permissions
- BridgeTokens.s.sol: Cross-chain bridging utility that handles CCIP message construction and token transfers between chains
- Interactions.s.sol: General purpose interaction script for testing and managing deployed contracts
The project uses Foundry with the following configuration (foundry.toml):
- Source directory:
src/ - Test directory:
test/ - Libraries:
lib/ - OpenZeppelin remapping for imports
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- ๐ฎ Cross-Chain Integration: Full Chainlink CCIP implementation
- ๐ฆ Multi-Asset Support: Support for other ERC20 tokens
- ๐ Yield Farming: Additional DeFi yield strategies
- ๐ Multi-Sig Support: Enhanced security for vault operations
This project is licensed under the MIT License - see the LICENSE file for details.
- Foundry - Ethereum development toolkit
- OpenZeppelin - Secure smart contract library
- Chainlink - Cross-chain infrastructure