Skip to content
Ozone-chainPublic

About

Stake Your $OZO Earn passive rewards while securing the network.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

OzoneChain Staking

Stake OZO or supported ERC-20 assets and earn pool-based rewards

Application: https://staking.ozonechain.io/
Network: OzoneChain
Contract source: Staking.sol — Version 1.4.0

OzoneChain Staking is a smart-contract-based staking system that supports multiple staking pools. Each pool can accept either the OzoneChain native coin or an ERC-20 token and defines its own APR and lock duration.

Users can create stakes, request to unstake after the applicable lock period, and receive their principal and calculated rewards after an authorized manager processes the request.

Documentation scope: This README describes the behavior visible in the supplied Staking.sol version 1.4.0. The live application could not be independently inspected while preparing this document. Frontend-specific features, deployed contract addresses, network configuration and token details should be added only after verification.


Table of Contents


Overview

The staking contract supports multiple independently configured pools. A pool specifies:

  • Whether it accepts the OzoneChain native coin or an ERC-20 token.
  • The token address for ERC-20 pools.
  • The annual percentage rate (APR).
  • The pool's lock duration.
  • Whether the pool is active.

Users can stake in active pools and maintain multiple stake positions. Each stake has its own start time, amount, pool ID, lock duration, reward amount and status.

The contract uses a manager-operated unstaking workflow: users submit an unstake request, and an authorized manager completes the request and transfers the principal and reward to the user.


Features

  • Multiple staking pools: Create pools with different assets, APRs and lock durations.
  • Native and ERC-20 support: Pools can accept the native coin or an ERC-20 token.
  • Per-position tracking: Each user's stake is recorded separately.
  • Minimum stake controls: Managers can configure a minimum stake amount and minimum stake duration.
  • Time-based rewards: Rewards are calculated using the pool APR and staking duration.
  • Unstake requests: Users request withdrawal after the applicable lock period.
  • Manager-processed withdrawals: Authorized managers process individual or batched unstake requests.
  • Pool controls: Managers can activate or deactivate pools.
  • Paginated reads: Pool, user-stake and unstake-request data can be queried in pages.

How Staking Works

The typical lifecycle is:

  1. Choose a pool. The user selects an active pool and reviews its asset, APR and lock duration.
  2. Stake. The user submits the required native coin or approves and transfers the ERC-20 amount through the staking contract.
  3. Stake record is created. The contract stores the amount, start timestamp, pool ID, lock duration and status.
  4. Wait for the lock period. The user must satisfy the greater of the pool lock duration and the configured minimum stake duration.
  5. Request unstaking. The user calls requestUnstake for the relevant stake index. The contract calculates and records the reward and marks the stake as pending.
  6. Manager processes the request. An authorized manager calls completeUnstake or batchCompleteUnstake.
  7. Payout. The user receives the principal plus the recorded reward, and the stake is marked completed.

Stake status

The contract defines three statuses:

Status Meaning
Staked The position is active and accruing rewards according to the reward calculation.
Pending The user has requested unstaking and is waiting for manager processing.
Completed The unstake request has been processed.

Staking Pools

Pools are created by an authorized manager using:

createPool(
    bool _isNative,
    address _token,
    uint256 _apr,
    uint256 _lockDuration
)

Parameters:

Parameter Description
_isNative true for the native coin; false for an ERC-20 token.
_token Must be address(0) for a native pool and a token contract address for an ERC-20 pool.
_apr APR value used by the reward formula. The contract requires a value greater than 100.
_lockDuration Pool lock duration in seconds.

Pool IDs are assigned sequentially, starting at 0.

A manager can activate or deactivate an existing pool using:

updatePoolStatus(uint256 _poolId, bool _isActive)

Only active pools accept new stakes. Deactivating a pool does not, by itself, cancel existing stake records or pending unstake requests.

Pool data

The contract's Pool structure contains:

  • poolId
  • isNative
  • token
  • apr
  • lockDuration
  • isActive

Pool information can be retrieved using getAllPools(offset, limit) and the total pool count using getPoolCount().


Reward Calculation

The contract calculates rewards using the following formula:

Reward = (Staked Amount × APR × Staking Duration)
         / (10,000 × Seconds in a Year)

The contract uses 365 days as the number of seconds in a year.

The APR value uses a scale in which 100 represents 1% in the formula. For example, an APR value of 500 represents 5%.

Reward duration behavior

  • For a pool with a non-zero lock duration, the reward duration is capped at that pool lock duration.
  • For a pool with a zero lock duration, the reward duration runs until the user requests unstaking.
  • The minimum stake duration is used to determine when a user may request unstaking. It does not change the pool's reward-duration cap.

Rewards are calculated when requestUnstake is called and stored with the pending request. The contract does not continuously transfer rewards to the user's wallet.

Example (illustrative):

For a stake of 1,000 tokens, an APR value of 500 (5%), and a reward duration of 365 days:

Reward = (1,000 × 500 × 365 days)
         / (10,000 × 365 days)

Reward = 50 tokens

Actual token units and displayed APR formatting depend on the token decimals and application presentation.


Unstaking Process

1. Request unstaking

The user calls:

requestUnstake(uint256 _stakeIndex)

The contract:

  • Checks that the stake index belongs to the caller.
  • Checks that the stake is currently active.
  • Checks that the applicable lock period has elapsed.
  • Calculates the reward.
  • Changes the stake status to Pending.
  • Creates an unstake request.
  • Updates the pool's tracked active stake totals.
  • Emits UnstakeRequested.

The request ID is assigned sequentially using unstakeRequestCount.

2. Complete an individual request

An authorized manager calls:

completeUnstake(
    uint256 _poolId,
    uint256 _requestIndex
)

The manager must provide the payout funding:

  • For a native-coin pool, the transaction must include at least the principal plus reward in native coin.
  • For an ERC-20 pool, the manager must have sufficient token balance and approve the staking contract to transfer the payout.

The contract transfers the principal plus recorded reward to the user and marks the stake and request as completed.

3. Complete requests in a batch

An authorized manager can process multiple request IDs using:

batchCompleteUnstake(uint256[] calldata _requestIndices)

The function processes pending requests in the supplied list and emits BatchUnstakeProcessed.

The supplied implementation declares MAX_BATCH_SIZE = 50, but the shown batch-processing function does not enforce that constant. Integrators and operators should confirm practical transaction gas limits before choosing batch sizes.

Important payout distinction

The supplied contract forwards deposited native coin and ERC-20 stake assets to the configured treasury when a user stakes. It does not retain those deposits in the staking contract as a conventional custody balance.

When an unstake request is completed, the manager supplies the principal and reward payout. The payout therefore depends on the manager having sufficient native coin or ERC-20 funds and, for ERC-20 payouts, sufficient allowance to the staking contract.


Manager Operations

The contract maintains a manager set. The deployer is added as a manager during construction.

Manager-authorized functions include:

Function Purpose
createPool Create a staking pool.
updatePoolStatus Activate or deactivate a pool.
completeUnstake Process one pending unstake request.
batchCompleteUnstake Process multiple pending requests.
setMinimumStakeDuration Update the minimum staking duration.
setMinimumStakeAmount Update the minimum stake amount.
updateManager Add or remove a manager.
setTreasury Update the treasury address.
withdrawExcessFunds Withdraw the staking contract's native-coin balance.

Manager membership can be checked with verifyManager(address) and queried with getManagers().

The treasury address is initialized in the constructor and can be changed by an authorized manager.

Manager permissions are controlled by the contract's manager set. The supplied source also inherits OpenZeppelin Ownable; do not assume that every manager-only operation is restricted to the Ownable owner.


Contract Interface

The following functions are available in the supplied Staking.sol source.

Pool functions

createPool(bool _isNative, address _token, uint256 _apr, uint256 _lockDuration)

updatePoolStatus(uint256 _poolId, bool _isActive)

getAllPools(uint256 offset, uint256 limit)

getPoolCount()

User staking functions

stake(uint256 _poolId, uint256 _amount)

requestUnstake(uint256 _stakeIndex)

getUserStakes(address _user, uint256 offset, uint256 limit)

getUserTotalStakes(address _user)

For a native-coin pool, stake is payable and the transaction's msg.value must equal _amount.

For an ERC-20 pool, the user must approve the staking contract first. The transaction must not include native coin.

Unstake processing functions

completeUnstake(uint256 _poolId, uint256 _requestIndex)

batchCompleteUnstake(uint256[] calldata _requestIndices)

getUnstakeRequests(uint256 offset, uint256 limit)

Configuration and manager functions

setMinimumStakeDuration(uint256 _minDuration)

setMinimumStakeAmount(uint256 _minAmount)

updateManager(address _manager, bool status)

getManagers()

verifyManager(address _manager)

setTreasury(address _treasury)

withdrawExcessFunds()

Events

The contract emits the following events:

Event When it is emitted
Staked A user creates a stake.
UnstakeRequested A user requests to unstake.
RequestCompleted An individual or batch unstake request is completed.
PoolCreated A new pool is created.
PoolUpdated A pool's active status changes.
BatchUnstakeProcessed A batch-processing transaction finishes.
MinimumStakeDurationUpdated The minimum stake duration changes.
MinimumStakeAmountUpdated The minimum stake amount changes.
ManagerUpdated A manager is added or removed.
TreasuryUpdated The treasury address changes.

These events can be used by applications and indexers to track staking activity and configuration changes.


Technical Details

Item Value
Contract name Staking
Source version comment 1.4.0
Solidity pragma ^0.8.0
Blockchain OzoneChain
Execution environment EVM
Native asset support Yes
ERC-20 support Yes
Reentrancy protection OpenZeppelin ReentrancyGuard
ERC-20 transfer handling OpenZeppelin SafeERC20
Manager collection OpenZeppelin EnumerableSet
Maximum query limit 100
Declared maximum batch size 50 (not enforced in the supplied batch function)

The supplied source imports OpenZeppelin Ownable, SafeERC20, ReentrancyGuard and EnumerableSet.


Development Setup

The following is a generic setup for a Hardhat project using this contract. Adapt the commands and configuration to the repository.

Prerequisites

  • Node.js and npm
  • Hardhat
  • OzoneChain RPC endpoint
  • A development wallet funded with test-network native coin

Install dependencies

npm install

Configure environment

Create a .env file:

OZONECHAIN_RPC_URL=your_rpc_endpoint
PRIVATE_KEY=your_development_private_key

Keep private keys out of source control. Use a development-only key and a secrets manager for deployment environments.

Compile

npx hardhat compile

Test

npx hardhat test

Deploy

If the repository contains a deployment script and an ozonechain network entry in hardhat.config.js, deploy with:

npx hardhat run scripts/deploy.js --network ozonechain

The supplied Solidity file alone does not establish the project's exact dependency versions, Hardhat configuration, deployment script or deployed contract address. Verify those details in the project repository before running deployment commands.


Security and Operational Notes

The following behaviors are important for users, integrators and operators to understand:

  1. Manager-controlled payouts: Unstaking is a two-stage process. A user requests unstaking, then a manager completes the request.
  2. Treasury forwarding: Staked assets are transferred to the configured treasury when deposited. The contract does not retain the principal as a pool custody balance.
  3. Reward funding: Managers must provide the principal and reward when completing unstake requests. ERC-20 payouts also require sufficient allowance.
  4. Manager permissions: Managers can change pool status, manager membership, minimum staking parameters and the treasury address.
  5. Pool deactivation: Deactivating a pool prevents new stakes through the active-pool check. Existing positions remain recorded and can proceed through the unstaking flow.
  6. Reward cap: For pools with a non-zero lock duration, rewards are capped at that pool lock duration, even if the configured minimum stake duration is longer.
  7. Batch processing: The batch function should be tested with realistic request counts and gas limits. The source declares a maximum batch size constant but does not apply it in the batch function.
  8. Native-coin excess: The individual and batch completion functions require at least the calculated native-coin payout. The supplied implementation does not refund excess msg.value.
  9. Token compatibility: ERC-20 pools depend on the token's transfer and allowance behavior. Fee-on-transfer, rebasing or non-standard tokens should not be assumed compatible without testing.

This README is technical documentation, not a security audit or investment recommendation. Review the deployed bytecode, contract configuration and operational controls before relying on any deployment-specific behavior.


Resources


License

The supplied Solidity source declares the MIT License. Refer to the repository's LICENSE file for the complete license text.


OzoneChain Staking — Stake, earn rewards, and participate in the OzoneChain ecosystem.

About

Stake Your $OZO Earn passive rewards while securing the network.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages