Skip to main content

Treasury Functions

The EVVM contract includes specialized functions that can only be called by the authorized Treasury contract. These functions provide controlled access to user balance management for treasury operations such as deposits, withdrawals, and automated distributions.

Access Control

All treasury functions implement strict access control:

  • Treasury-Only: Functions can only be called by the authorized treasury contract address
  • Balance Management: Direct manipulation of user balances within the EVVM system
  • Automated Operations: Support for automated treasury operations and distributions
Treasury Authorization Required

These functions will revert with SenderIsNotTreasury() if called by any address other than the authorized treasury contract.


Balance Management Functions

addAmountToUser

Function Type: external
Function Signature: addAmountToUser(address,address,uint256)

Adds tokens to a user's balance in the EVVM system. This function is used by the treasury for deposit operations and reward distributions.

Input Parameters

ParameterTypeDescription
useraddressAddress of the user to receive the balance
tokenaddressAddress of the token contract
amountuint256Amount of tokens to add to the user's balance

Access Control

  • Treasury Only: Only the authorized treasury contract can call this function
  • Immediate Effect: Balance change takes effect immediately
  • No Validation: Treasury is responsible for amount validation

Use Cases

  • Deposit Processing: When users deposit tokens through the treasury
  • Reward Distribution: Automated reward distributions to users
  • Migration: Moving balances from external systems
  • Administrative Actions: Manual balance adjustments by treasury

Security Features

  • Single Caller: Only treasury contract has access
  • Direct Balance Update: Efficiently updates internal balance mapping
  • Error Handling: Reverts if called by unauthorized addresses

removeAmountFromUser

Function Type: external
Function Signature: removeAmountFromUser(address,address,uint256)

Removes tokens from a user's balance in the EVVM system. This function is used by the treasury for withdrawal operations and fee deductions.

Input Parameters

ParameterTypeDescription
useraddressAddress of the user to remove balance from
tokenaddressAddress of the token contract
amountuint256Amount of tokens to remove from the user's balance

Access Control

  • Treasury Only: Only the authorized treasury contract can call this function
  • Balance Validation: Treasury must ensure sufficient balance before calling
  • Immediate Effect: Balance change takes effect immediately

Use Cases

  • Withdrawal Processing: When users withdraw tokens through the treasury
  • Fee Deduction: Automated fee collection by treasury
  • System Maintenance: Balance corrections and system operations
  • Penalty Application: Automated penalty deductions if needed

Security Considerations

  • Overflow Protection: Solidity 0.8+ prevents underflow, will revert if insufficient balance
  • Treasury Responsibility: Treasury must validate sufficient balance
  • Atomic Operation: Balance update is atomic and immediate

Treasury Integration

Treasury Address Management

The treasury address is configured during the initial setup process:

// Treasury address is set during NameService setup
function _setupNameServiceAndTreasuryAddress(
address _nameServiceAddress,
address _treasuryAddress
) external

Integration Workflow

  1. Setup Phase: Treasury address is configured during contract initialization
  2. Authorization: Only the configured treasury address can call treasury functions
  3. Operation Phase: Treasury calls functions as needed for user operations
  4. Balance Synchronization: EVVM maintains internal balances synchronized with treasury operations

Error Handling

// Treasury functions check caller authorization
if (msg.sender != treasuryAddress) {
revert ErrorsLib.SenderIsNotTreasury();
}

Usage Examples

Treasury Deposit Operation

// Treasury processes user deposit
// 1. User deposits 100 MATE tokens to treasury
// 2. Treasury calls EVVM to credit user's internal balance
evvm.addAmountToUser(userAddress, mateTokenAddress, 100 * 10**18);

Treasury Withdrawal Operation

// Treasury processes user withdrawal
// 1. User requests withdrawal of 50 MATE tokens
// 2. Treasury calls EVVM to debit user's internal balance
evvm.removeAmountFromUser(userAddress, mateTokenAddress, 50 * 10**18);
// 3. Treasury transfers actual tokens to user

Security Considerations

Access Control Validation

  • Always validates caller is the authorized treasury contract
  • Reverts immediately if unauthorized access is attempted
  • No bypass mechanisms or admin overrides

Balance Integrity

  • Functions directly modify internal balance mappings
  • Treasury responsible for coordinating with external token transfers
  • No automatic token transfers - treasury handles actual token movement

State Consistency

  • Balance changes are immediate and atomic
  • Treasury must ensure consistency between internal balances and external token holdings
  • Proper error handling prevents inconsistent states