Skip to content

StackSave/SmartContract

Repository files navigation

StackSave Smart Contract

Multi-currency, multi-mode savings DApp with yield strategies on Base Sepolia testnet.

Live on Base Sepolia: 0x0b9B2aCbfd5E55C3122c738a76d932ca7a934532


Features

  • Multi-Currency: Save in USDC or IDRX (Indonesian Rupiah stablecoin)
  • Dual Modes:
    • Lite Mode: Simple 6% APY, perfect for beginners
    • Pro Mode: Choose your risk level (Low 8%, Medium 12.5%, High 17.5% APY)
  • Streak Bonuses: +2% APY for 7+ consecutive daily deposits
  • NFT Goals: Each savings goal is an ERC721 NFT with metadata
  • Auto-Yield: Interest compounds automatically via yield strategies

Deployed Contracts (Base Sepolia)

StackSaveV3:     0x0b9B2aCbfd5E55C3122c738a76d932ca7a934532
SavingsToken:    0xfFDB262BeEdE8bdD801AE5f091F80DDd6506C304
GoalNFT:         0xd95f64270Ca9Dc6c16aBE33E8CA76b6777286a07
MockUSDC:        0xE066B540995D9Ada821Db59Fa2FB5d01eEA093c6
MockIDRX:        0xc447e59AE845C18643e64aaCb7D52F697F0e7513
TokenFaucet:     (deploy separately using DeployFaucet.s.sol)

View on BaseScan


Quick Start

1. Deploy Your Own

See SIMPLE_DEPLOY.md for full step-by-step guide.

TL;DR:

# 1. Get testnet ETH from https://www.alchemy.com/faucets/base-sepolia
# 2. Copy .env.example to .env and fill in your private key
copy .env.example .env

# 3. Deploy
deploy.bat

2. Use Existing Deployment

Use the contract addresses above in your backend/mobile app.


Contract Architecture

┌─────────────────────────────────────────────┐
│           StackSaveV3 (Main)                │
│  - createGoal(currency, mode, risk)         │
│  - deposit(goalId, amount)                  │
│  - withdrawCompleted(goalId)                │
└─────────────┬───────────────────────────────┘
              │
      ┌───────┴────────┐
      │                │
┌─────▼─────┐    ┌────▼─────┐
│ Savings   │    │  Goal    │
│  Token    │    │   NFT    │
│ (sSAVE)   │    │ (ERC721) │
└───────────┘    └──────────┘
      │
┌─────▼──────────────────────┐
│   MockYieldStrategy        │
│   (6%, 8%, 12.5%, 17.5%)   │
└────────────────────────────┘

Usage Example

// 1. Create a goal
uint256 goalId = stackSave.createGoal(
    address(usdc),                    // Currency: USDC
    "New Laptop",                      // Goal name
    1000 * 1e6,                        // $1000 target
    90,                                // 90 days deadline
    StackSaveV3.GoalMode.Pro,         // Pro mode
    StackSaveV3.RiskTier.Medium       // Medium risk (12.5% APY)
);

// 2. Approve and deposit
usdc.approve(address(stackSave), amount);
stackSave.deposit(goalId, 100 * 1e6);  // $100 deposit

// 3. Check progress
(
    string memory name,
    uint256 targetAmount,
    uint256 currentAmount,
    uint256 deadline,
    // ...
) = stackSave.getGoalInfo(goalId);

// 4. Withdraw when completed
stackSave.withdrawCompleted(goalId);  // Get principal + interest

Development

Install Dependencies

forge install

Run Tests

test.bat
# Or: forge test -vv

Check Balance

check-balance.bat

Clean Build

clean.bat

Project Structure

src/
├── StackSaveV3.sol           # Main contract
├── SavingsToken.sol          # Interest-bearing ERC20
├── GoalNFT.sol               # Goal tracking NFT
├── MockUSDC.sol              # Test USDC token
├── MockIDRX.sol              # Test IDRX token
├── TokenFaucet.sol           # Get test tokens
├── strategies/
│   └── MockYieldStrategy.sol # Yield generation
└── interfaces/
    └── IYieldStrategy.sol    # Strategy interface

script/
├── DeployStackSaveV3.s.sol   # Main deployment
└── DeployFaucet.s.sol        # Faucet deployment

test/
├── StackSaveV3.t.sol         # Main contract tests
└── TokenFaucet.t.sol         # Faucet tests

Modes & APY

Mode Risk Tier APY (Base) Streak Bonus Total APY
Lite - 6.0% +2.0% 8.0%
Pro Low 8.0% +2.0% 10.0%
Pro Medium 12.5% +2.0% 14.5%
Pro High 17.5% +2.0% 19.5%

Streak Bonus: Deposit daily for 7+ days to unlock +2% APY


Helper Scripts

  • deploy.bat - Deploy all contracts to Base Sepolia
  • test.bat - Run full test suite
  • check-balance.bat - Check your Base Sepolia ETH balance
  • clean.bat - Clean build artifacts

Testing

All tests passing on Foundry:

forge test -vv

Running 2 test files...
✓ StackSaveV3.t.sol (20 tests)
✓ TokenFaucet.t.sol (5 tests)

Test result: ok. 25 passed

Security

  • ✅ ReentrancyGuard on all deposit/withdrawal functions
  • ✅ Ownable for admin functions
  • ✅ SafeERC20 for all token transfers
  • ✅ Comprehensive test coverage
  • ⚠️ Not audited - testnet only, use at your own risk

Get Test Tokens

Deploy the faucet to get test USDC/IDRX:

forge script script/DeployFaucet.s.sol:DeployFaucet \
  --rpc-url https://sepolia.base.org \
  --private-key $PRIVATE_KEY \
  --broadcast

Then call claimUsdc() or claimIdrx() to get 1000 test tokens.


Links


License

MIT


Built with ❤️ for the Base Sepolia testnet

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published