The Cross-Chain Rebase Token is an innovative DeFi solution that combines the linear interest mechanism of rebase mechanics with the flexibility of cross-chain functionality. Built on Foundry and powered by Chainlink CCIP, this token system is designed to maintain value stability while enabling seamless transfers across multiple blockchain networks.
By integrating dynamic interest calculations with secure cross-chain messaging, the project addresses key challenges in DeFi: maintaining consistent value across chains, ensuring liquidity, and providing user-friendly mechanisms for earning interest on holdings.
- Dynamic Interest Accrual: Automatic interest calculation based on customizable rates and time elapsed
- User-Specific Interest Rates: Flexible system allowing different interest rates for different users or use cases
- Rebasing Mechanism: Balance adjustment that reflects accurate interest accumulation in real-time
- High Precision: All calculations performed with 18 decimal places (1e18) for maximum accuracy
- Chainlink CCIP Support: Secure, reliable cross-chain transfers using Chainlink's Cross-Chain Interoperability Protocol
- Interest Preservation: User-specific interest rates maintained across different chains
- Transparent Messaging: All cross-chain operations can be verified and tracked
- Multi-Chain Compatibility: Works across all major EVM-compatible blockchains
- Managed Supply: Controlled token issuance through authorized minting and burning
- ETH Backing: Each token backed by ETH in the vault for inherent value stability
- Efficient Liquidity: Improved liquidity across chains through bridging mechanisms
- Inclusive Governance: Framework for community-driven interest rate adjustments (future enhancement)
- Role-Based Permissions: Clearly defined roles for various operations
- Chain Validation: Ensures token transfers only occur between authorized chains
- Rate Limiting: Prevents excessive tokens from being transferred in a short period
- Secure Vault Design: Protects user deposits with robust security measures
graph TD
A[RebaseToken.sol] --> B[Interest Calculation]
A --> C[ERC20 Functionality]
A --> D[Rebasing Logic]
E[Vault.sol] --> F[ETH Deposits]
E --> G[Token Minting]
E --> H[Token Redemption]
I[RebaseTokenPool.sol] --> J[CCIP Integration]
I --> K[Cross-Chain Transfer]
I --> L[Interest Preservation]
M[TokenPool.sol] --> N[Chain Validation]
M --> O[Rate Limiting]
A -.-> E
E -.-> A
A -.-> I
I -.-> M
The foundation of the system, implementing:
- ERC20 standard with dynamic interest accrual
- Custom balance calculation that includes accrued interest
- Mechanisms for tracking individual user interest rates
- Mint and burn functions with role-based access control
Enables interaction with the token:
- Accepts ETH deposits to mint RebaseTokens
- Manages redemption of RebaseTokens for ETH
- Maintains the ETH backing for all tokens in circulation
- Includes safety measures for secure operations
Specialized pool for cross-chain transfers:
- Custom implementation of Chainlink CCIP's TokenPool
- Handles burning on source chain and minting on destination chain
- Preserves user-specific interest data during transfers
- Maintains rate limits and chain validation
The project implements a linear interest model, with the formula:
Accrued Interest = Principal Γ Interest Rate Γ Time Elapsed
Where:
- Principal: The original amount of tokens
- Interest Rate: Annual interest rate (in basis points, 1 basis point = 0.01%)
- Time Elapsed: Time since the last interest calculation (in seconds)
The calculation is executed dynamically whenever:
- Balance information is requested
- Tokens are transferred
- Tokens are minted or burned
- Users interact with the vault
- Foundry installed
- Node.js (v14 or higher)
- Access to blockchain network RPC endpoints
- Chainlink CCIP supported network access
-
Clone the repository:
git clone https://github.com/your-username/rebase-token-project.git cd rebase-token-project
-
Install dependencies:
forge install
-
Configure environment variables in
.env
:PRIVATE_KEY=<your-private-key> RPC_URL_ETHEREUM=<ethereum-rpc-url> RPC_URL_POLYGON=<polygon-rpc-url> RPC_URL_ARBITRUM=<arbitrum-rpc-url> RPC_URL_OPTIMISM=<optimism-rpc-url> RPC_URL_AVALANCHE=<avalanche-rpc-url> ETHERSCAN_API_KEY=<etherscan-api-key> POLYGONSCAN_API_KEY=<polygonscan-api-key>
Start a local Anvil instance:
anvil
Deploy to local environment:
forge script scripts/Deploy.s.sol:Deploy --rpc-url http://localhost:8545 --private-key <local-private-key> --broadcast
Deploy to a specific network:
forge script scripts/Deploy.s.sol:Deploy --rpc-url $RPC_URL_ETHEREUM --private-key $PRIVATE_KEY --broadcast --verify
Configure the token pool for cross-chain transfers:
forge script scripts/ConfigurePool.s.sol:ConfigurePoolScript --rpc-url $RPC_URL_ETHEREUM --private-key $PRIVATE_KEY --broadcast --verify
// Mint tokens with custom interest rate
rebaseToken.mint(address recipient, uint256 amount, uint256 interestRate);
// Get current balance including accrued interest
uint256 balance = rebaseToken.balanceOf(address user);
// Transfer tokens with interest recalculation
rebaseToken.transfer(address recipient, uint256 amount);
// Admin function to adjust global interest rate
rebaseToken.setInterestRate(uint256 newInterestRate);
// Deposit ETH and receive RebaseTokens
vault.deposit{value: ethAmount}();
// Redeem RebaseTokens for ETH
vault.redeem(uint256 tokenAmount);
// Transfer tokens from one chain to another
IRouterClient router = IRouterClient(routerAddress);
Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({
receiver: abi.encode(receiverAddress),
data: abi.encode(userData),
tokenAmounts: tokenAmounts,
extraArgs: extraArgs,
feeToken: feeTokenAddress
});
uint256 fee = router.getFee(destinationChainSelector, message);
bytes32 messageId = router.ccipSend{value: fee}(destinationChainSelector, message);
The contracts are optimized for gas efficiency:
- Storage Optimization: Minimized storage reads and writes
- Efficient Calculations: Optimized interest calculations to reduce gas costs
- Batch Processing: Where applicable, operations are batched
- Assembly Usage: Strategic use of assembly for certain operations
The contracts have undergone the following security measures:
- Internal code review
- Static analysis with Slither
- Formal verification of critical functions
- Comprehensive test suite with high coverage
- Access Control: Strict role-based permissions for sensitive operations
- Rate Limiting: Prevents excessive token transfers
- Pause Mechanism: Ability to pause operations in case of emergency
- Input Validation: Thorough validation of all user inputs
- Reentrancy Protection: Guards against reentrancy attacks
- Core token functionality
- Basic cross-chain transfers
- ETH-backed vault
- Enhanced governance mechanisms
- Additional collateral types
- Integration with additional DEXs
- Advanced interest models
- Yield farming strategies
- Cross-chain liquidity pools
- Aditya - Developer & Architect
This project is licensed under the MIT License.
For inquiries or support:
- Email: adityakumar41205@gmail.com
- Twitter: @Aditya
Built with β€οΈ by Aditya