Skip to content

A smart contract for interest calculation that runs on the Arbitrum Stylus network.

License

Notifications You must be signed in to change notification settings

dsrvlabs/arbitrum-stylus-advance-feature

Repository files navigation

Stylus Interest Calculator

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.

Project Purpose

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

Features

  • Simple and compound interest calculation
  • Principal, interest rate, and period configuration
  • Cache-optimized calculations (v0.8.3)
  • Interest accumulation tracking

Versions

Two versions are provided:

  • v0.6.0: Basic interest calculation functionality
  • v0.8.3: Improved version with cache optimization

Installation

  1. Install Rust (1.70.0 or higher recommended)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install Docker
# For macOS
brew install docker

# For Ubuntu
sudo apt-get update
sudo apt-get install docker.io
  1. Install Stylus CLI
cargo install cargo-stylus
  1. Build the project
cd counter_v0_8_3  # or counter_v0_6_0

Usage

  1. Build and check the contract (requires Docker)
cargo stylus check --endpoint YOUR_RPC_ENDPOINT
  1. 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
  1. Deploy the contract (requires Docker)
cargo stylus deploy --endpoint YOUR_RPC_ENDPOINT --private-key YOUR_PRIVATE_KEY
  1. Initialize the contract
calculator.initialize()
  1. Set principal amount
calculator.set_principal(amount)
  1. Set interest rate (default: 5.5% = 550)
calculator.set_rate(rate)
  1. Set period (in years)
calculator.set_period(period)
  1. Set compound/simple interest (1: compound, 0: simple)
calculator.set_compound(is_compound)

Performance Comparison

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

License

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

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

About

A smart contract for interest calculation that runs on the Arbitrum Stylus network.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages