Skip to content

johndamson/Dual-Stacking-Yield-Optimizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Dual Stacking Yield Optimizer

A robust Clarity smart contract for the Stacks blockchain that enables dual-pool staking with optimized yield distribution and comprehensive reward management.

Overview

The Dual Stacking Yield Optimizer allows users to stake STX tokens in two independent pools (Pool A and Pool B) and earn rewards based on configurable reward rates. The contract features:

  • Dual Pool Architecture: Separate staking pools with independent reward rates
  • Block-Based Rewards: Rewards calculated per block staked
  • Fee System: Configurable fee percentage on claimed rewards
  • Admin Controls: Owner-only functions for pool management
  • Safe Arithmetic: All operations use Clarity's safe math functions

Contract Architecture

Constants

  • CONTRACT-OWNER: Set to contract deployer
  • Error codes for comprehensive error handling (401-404)

Data Variables

  • pool-a-active / pool-b-active: Pool activation status
  • total-staked-a / total-staked-b: Total staked amounts per pool
  • reward-rate-a / reward-rate-b: Reward rates (basis points, 0-10000)
  • fee-percentage: Claim fee percentage (0-100)

Maps

  • user-stake-a / user-stake-b: User stake amounts
  • user-rewards-a / user-rewards-b: Total rewards claimed
  • user-last-claim: Last claim block height per user

Public Functions

Staking Functions

stake-pool-a (amount: uint) → (ok uint) | (err uint)

Deposit STX into Pool A. ``` (contract-call? .dual-stacking-optimizer stake-pool-a u1000000) ```

stake-pool-b (amount: uint) → (ok uint) | (err uint)

Deposit STX into Pool B.

unstake-pool-a (amount: uint) → (ok uint) | (err uint)

Withdraw STX from Pool A.

unstake-pool-b (amount: uint) → (ok uint) | (err uint)

Withdraw STX from Pool B.

Reward Functions

claim-rewards-a () → (ok uint) | (err uint)

Claim accumulated rewards from Pool A (minus fee).

  • Calculates rewards based on blocks since last claim
  • Deducts fee percentage
  • Updates claim timestamp

claim-rewards-b () → (ok uint) | (err uint)

Claim accumulated rewards from Pool B (minus fee).

Query Functions

get-stake-a (user: principal) → uint

Get user's current stake in Pool A.

get-stake-b (user: principal) → uint

Get user's current stake in Pool B.

get-total-rewards-a (user: principal) → uint

Get total rewards claimed from Pool A.

get-total-rewards-b (user: principal) → uint

Get total rewards claimed from Pool B.

get-pool-stats () → (ok {total-staked-a, total-staked-b, reward-rate-a, reward-rate-b, pool-a-active, pool-b-active})

Get comprehensive pool statistics.

Admin Functions

update-reward-rate-a (new-rate: uint) → (ok uint) | (err uint)

Update reward rate for Pool A (0-10000 basis points).

  • Only callable by contract owner
  • 100 = 1% APY equivalent

update-reward-rate-b (new-rate: uint) → (ok uint) | (err uint)

Update reward rate for Pool B.

toggle-pool-a () → (ok bool) | (err uint)

Enable/disable Pool A staking.

toggle-pool-b () → (ok bool) | (err uint)

Enable/disable Pool B staking.

update-fee (new-fee: uint) → (ok uint) | (err uint)

Update claim fee percentage (0-100).

Error Codes

Code Constant Description
400 ERR-INVALID-AMOUNT Amount is zero or invalid
401 ERR-UNAUTHORIZED Caller is not contract owner
402 ERR-INSUFFICIENT-BALANCE User doesn't have enough staked
403 ERR-POOL-INACTIVE Pool is currently disabled
404 ERR-ZERO-SUPPLY No rewards available to claim

Usage Examples

Stake 1 STX in Pool A

(contract-call? .dual-stacking-optimizer stake-pool-a u1000000)

About

The Dual Stacking Yield Optimizer is a Clarity smart contract designed for the Stacks blockchain that enables users to stake STX tokens across two independent liquidity pools and earn yield rewards. It provides a flexible, dual-pool staking mechanism with configurable reward rates, fee management, and comprehensive pool statistics.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors