A robust Clarity smart contract for the Stacks blockchain that enables dual-pool staking with optimized yield distribution and comprehensive reward management.
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-OWNER: Set to contract deployer- Error codes for comprehensive error handling (401-404)
pool-a-active/pool-b-active: Pool activation statustotal-staked-a/total-staked-b: Total staked amounts per poolreward-rate-a/reward-rate-b: Reward rates (basis points, 0-10000)fee-percentage: Claim fee percentage (0-100)
user-stake-a/user-stake-b: User stake amountsuser-rewards-a/user-rewards-b: Total rewards claimeduser-last-claim: Last claim block height per user
Deposit STX into Pool A. ``` (contract-call? .dual-stacking-optimizer stake-pool-a u1000000) ```
Deposit STX into Pool B.
Withdraw STX from Pool A.
Withdraw STX from Pool B.
Claim accumulated rewards from Pool A (minus fee).
- Calculates rewards based on blocks since last claim
- Deducts fee percentage
- Updates claim timestamp
Claim accumulated rewards from Pool B (minus fee).
Get user's current stake in Pool A.
Get user's current stake in Pool B.
Get total rewards claimed from Pool A.
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.
Update reward rate for Pool A (0-10000 basis points).
- Only callable by contract owner
- 100 = 1% APY equivalent
Update reward rate for Pool B.
Enable/disable Pool A staking.
Enable/disable Pool B staking.
Update claim fee percentage (0-100).
| 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 |
(contract-call? .dual-stacking-optimizer stake-pool-a u1000000)