Skip to main content

Overview

The Treasury contract manages the economic pools of the Nexis Network. It receives inflows from agent slashing and early withdrawal penalties, distributes them across three pools (treasury, insurance, rewards), and enables authorized distribution of rewards to agents. Contract Address (Testnet): 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 Key Features:
  • Three-pool system: Treasury, Insurance, Rewards
  • Configurable distribution ratios
  • Handles slashed stakes and early exit penalties
  • Reward distribution to agents with REWARDS_ROLE authorization
  • Pool withdrawal with WITHDRAW_ROLE authorization
  • Multi-asset support (ETH and ERC20 tokens)
  • Upgradeable UUPS proxy pattern

Contract Constants

Data Structures

DistributionConfig

Default Distribution:
  • Treasury: 40% (4,000 bps)
  • Insurance: 30% (3,000 bps)
  • Rewards: 30% (3,000 bps)

PoolBalances


Pool Management

poolBalances

Query pool balances for a specific asset.
asset
address
required
Asset address (address(0) for ETH, token address for ERC20)
Returns:
  • PoolBalances - Struct containing balances for all three pools
Example:

rewardsBalance

Query available rewards balance for a specific asset.
asset
address
required
Asset address
Returns:
  • uint256 - Available rewards balance
Example:
JavaScript
Solidity

Inflow Handling

These methods are called automatically by the Agents contract when stakes are slashed or early exit penalties are collected.

handleSlash

Process slashed stake from an agent. Only callable by addresses with INFLOW_ROLE (typically the Agents contract).
agentId
uint256
required
Agent ID that was slashed
asset
address
required
Asset address
amount
uint256
required
Amount slashed
msg.value
uint256
For ETH, must equal amount; for ERC20, must be 0
Distribution: Splits amount according to configured distribution ratios across three pools. Events Emitted:
Example:
JavaScript
Solidity

handleEarlyExitPenalty

Process early withdrawal penalty from an agent. Only callable by INFLOW_ROLE.
agentId
uint256
required
Agent ID that paid penalty
asset
address
required
Asset address
amount
uint256
required
Penalty amount
Events Emitted:
Example:
JavaScript
Solidity

recordRewardDeposit

Record a direct deposit to the rewards pool (e.g., from Tasks contract or external contributions).
asset
address
required
Asset address
amount
uint256
required
Amount deposited
msg.value
uint256
For ETH, must equal amount; for ERC20, tokens must be transferred before calling
Events Emitted:
Example:

Reward Distribution

distributeReward

Distribute rewards from rewards pool to an agent. Only callable by REWARDS_ROLE.
agentId
uint256
required
Agent ID to reward
asset
address
required
Asset to distribute
amount
uint256
required
Amount to distribute (must be ≤ rewards balance)
recipient
address
required
Address to send rewards (address(0) = agent owner)
reason
string
required
Human-readable reason for distribution
Requirements:
  • Agent must be registered
  • Sufficient balance in rewards pool
  • Caller must have REWARDS_ROLE
Events Emitted:
Errors:
  • AgentNotKnown(uint256) - Agent not registered
  • InsufficientRewards(address asset, uint256 requested, uint256 available) - Not enough rewards
Example:

Pool Withdrawals

withdrawTreasury

Withdraw from treasury pool. Only callable by WITHDRAW_ROLE.
asset
address
required
Asset to withdraw
amount
uint256
required
Amount to withdraw (must be ≤ treasury balance)
to
address
required
Recipient address (cannot be zero address)
Events Emitted:
Example:
JavaScript
Solidity

withdrawInsurance

Withdraw from insurance pool. Only callable by WITHDRAW_ROLE.
asset
address
required
Asset to withdraw
amount
uint256
required
Amount to withdraw (must be ≤ insurance balance)
to
address
required
Recipient address
Events Emitted:
Example:
JavaScript
Solidity

Configuration

setDistribution

Update pool distribution ratios. Only callable by DEFAULT_ADMIN_ROLE.
treasuryBps
uint16
required
Treasury share in basis points (0-10000)
insuranceBps
uint16
required
Insurance share in basis points (0-10000)
rewardsBps
uint16
required
Rewards share in basis points (0-10000)
Requirements:
  • Sum must equal 10,000 (100%)
Events Emitted:
Errors:
  • InvalidBps() - Sum does not equal 10,000
Example:

setAgents

Update Agents contract address. Only callable by DEFAULT_ADMIN_ROLE.
newAgents
address
required
New Agents contract address (cannot be zero)
Example:
JavaScript
Solidity

Query Methods

distribution

Get current distribution configuration. Example:
JavaScript

agents

Get Agents contract address.

Complete Example: Reward Distribution Campaign

Here’s a complete example of distributing rewards to top-performing agents:

Events Reference


Error Reference


Treasury Economics

Pool Purpose

Treasury Pool

Protocol development, operations, grants, and strategic initiatives

Insurance Pool

Coverage for black swan events, protocol bugs, or agent failures

Rewards Pool

Performance incentives, bounties, and community rewards

Inflow Sources

Best Practices

  • Adjust based on protocol needs and growth stage
  • Early stage: Higher rewards % for agent adoption
  • Mature stage: Higher treasury % for sustainability
  • Always maintain adequate insurance reserves
  • Document clear criteria for rewards
  • Use transparent, objective metrics (reputation, tasks completed)
  • Consider time-based campaigns (monthly, quarterly)
  • Batch distributions to save gas costs
  • Monitor pool balances regularly
  • Set thresholds for pool withdrawals
  • Use multi-sig for WITHDRAW_ROLE
  • Document all withdrawal purposes

Integration with Other Contracts

The Treasury contract is called by:
  1. Agents Contract:
    • handleSlash() - When stakes are slashed
    • handleEarlyExitPenalty() - When early withdrawals occur
  2. Tasks Contract:
    • recordRewardDeposit() - When disputed tasks are resolved without refund
  3. External Contributors:
    • recordRewardDeposit() - For direct reward contributions