This project is a smart contract for interest calculation that runs on the Arbitrum Stylus network. The main purpose of this project is to demonstrate and test the performance improvements and optimizations between Stylus SDK versions v0.6.0 and v0.8.3.
This project serves as a benchmark to test and compare the improvements in the Stylus SDK from version v0.6.0 to v0.8.3. The key improvements tested include:
- Cache optimization for better performance
- Reduced gas consumption
- Improved execution time
- Enhanced calculation accuracy
- Better memory management
- Simple and compound interest calculation
- Principal, interest rate, and period configuration
- Cache-optimized calculations (v0.8.3)
- Interest accumulation tracking
Two versions are provided:
- v0.6.0: Basic interest calculation functionality
- v0.8.3: Improved version with cache optimization
- Install Rust (1.70.0 or higher recommended)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Install Docker
# For macOS
brew install docker
# For Ubuntu
sudo apt-get update
sudo apt-get install docker.io
- Install Stylus CLI
cargo install cargo-stylus
- Build the project
cd counter_v0_8_3 # or counter_v0_6_0
- Build and check the contract (requires Docker)
cargo stylus check --endpoint YOUR_RPC_ENDPOINT
- Export ABI
mkdir -p output
cargo stylus export-abi --json 2>/dev/null | grep -v "=======" | grep -v "Contract JSON ABI" | grep -v "^$" > output/abi.json
- Deploy the contract (requires Docker)
cargo stylus deploy --endpoint YOUR_RPC_ENDPOINT --private-key YOUR_PRIVATE_KEY
- Initialize the contract
calculator.initialize()
- Set principal amount
calculator.set_principal(amount)
- Set interest rate (default: 5.5% = 550)
calculator.set_rate(rate)
- Set period (in years)
calculator.set_period(period)
- Set compound/simple interest (1: compound, 0: simple)
calculator.set_compound(is_compound)
The v0.8.3 version provides the following improvements through cache optimization:
- Reduced gas consumption
- Faster execution time
- More accurate interest calculations
- Better memory efficiency
This project is licensed under the MIT License - see the LICENSE file for details.
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.