Contract 4e2d2407db69c2c164efba6d4ca28870f3920b31df802b39b79299879b7b87ce

← Back to Index 📥 Download WASM

Meta

cliver 25.2.0#28484880988199233a7e8e87c97cb12dac323cb3
rssdkver 25.3.1#e50d95af029c83196dd122f0154bac3f1302394b
rsver 1.94.1

Instances

  • CCQ4J5VLQHM2ORP4K7GBVAJJPK5SGG23DH4RD7QEHAZDHTN7JNESNXKZ

Interface

Record a deposit of tokens to the treasury.

This function verifies that tokens have been transferred to the treasury contract address and updates internal balance tracking. Only the admin can call this function. The function verifies that the actual token balance is sufficient to support the claimed deposit amount to prevent fabricated balances.

Arguments

  • env - The execution environment
  • caller - Address of the caller (must be admin)
  • asset - Address of the token contract
  • amount - Amount of tokens being deposited (must be > 0)
  • from - Address that sent the tokens (for event tracking and audit trail)

Returns

  • Ok(()) - Deposit recorded successfully
  • Err(TreasuryError) - Deposit failed (unauthorized, not initialized, invalid amount, transfer not verified, or overflow)
fn deposit(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    asset: soroban_sdk::Address,
    amount: u128,
    from: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Upgrade the treasury contract WASM. Only the current admin can authorize an upgrade.

fn upgrade(
    env: soroban_sdk::Env,
    new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), TreasuryError>

Withdraw tokens from the treasury (admin only).

This function performs two critical operations atomically: it updates internal balance tracking and transfers tokens to the recipient. If the token transfer fails, the balance update is reverted, ensuring consistency. Only authorized admins (or multisig contract if configured) can perform withdrawals.

Arguments

  • env - The execution environment
  • caller - Admin address (must be authorized - regular admin or multisig contract)
  • asset - Address of the token contract to withdraw
  • amount - Amount of tokens to withdraw (must be > 0 and <= available balance)
  • to - Address to receive the tokens

Returns

  • Ok(()) - Withdrawal successful (balance updated and tokens transferred)
  • Err(TreasuryError) - Withdrawal failed (unauthorized, insufficient balance, or transfer failed)
fn withdraw(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    asset: soroban_sdk::Address,
    amount: u128,
    to: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Get the admin address.

Arguments

  • env - The execution environment

Returns

  • Result<Address, TreasuryError> - Admin address or error
fn get_admin(env: soroban_sdk::Env) -> Result

Initialize the treasury contract with an admin address.

The admin address is a single account. Once initialized, the contract cannot be reinitialized. This ensures the admin address remains consistent and prevents accidental reconfiguration.

Arguments

  • env - The execution environment
  • admin - Address of the admin (can be multisig contract for enhanced security)

Returns

  • Ok(()) - Treasury initialized successfully
  • Err(TreasuryError) - Initialization failed (e.g., already initialized)
fn initialize(
    env: soroban_sdk::Env,
    admin: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Get the balance of a specific asset in the treasury.

Returns the internally tracked balance for the given asset. This may differ from the actual token contract balance if sync_balance() hasn't been called after direct transfers to the treasury address.

Arguments

  • env - The execution environment
  • asset - Address of the token contract

Returns

  • u128 - Balance of the asset (0 if asset has never been deposited)
fn get_balance(env: soroban_sdk::Env, asset: soroban_sdk::Address) -> u128

Accept admin role (two-step transfer, step 2). Only the pending admin can call this to finalize the transfer.

Arguments

  • env - The execution environment
  • caller - Pending admin address (must be authorized)

Returns

  • Ok(()) - Admin transfer completed successfully
  • Err(TreasuryError) - Transfer failed (not initialized, no pending admin, or invalid caller)
fn accept_admin(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Sync balance from token contract and update internal tracking.

This function queries the token contract's balance function to reconcile the actual balance held by the treasury with internal tracking. Use this when tokens are transferred directly to the treasury address without calling deposit(), such as when protocol fees are collected automatically.

Arguments

  • env - The execution environment
  • asset - Address of the token contract

Returns

  • Ok(u128) - Current balance synced from token contract
  • Err(TreasuryError) - Sync failed (not initialized or token contract query failed)
fn sync_balance(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
) -> Result

Claim incentives accrued by the treasury contract.

The incentives contract requires the reward owner to authorize claims. Since rewards accrue to the treasury address, this admin-only proxy makes the treasury contract call claim_rewards for itself and records the claimed reward-token balance in treasury accounting.

fn claim_rewards(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    incentives: soroban_sdk::Address,
    assets: soroban_sdk::Vec,
    reward_token: soroban_sdk::Address,
    amount: u128,
) -> Result

Propose a new admin address (two-step transfer, step 1). Only the current admin can propose a new admin. The proposed admin must call accept_admin to complete the transfer.

Arguments

  • env - The execution environment
  • caller - Current admin address (must be authorized)
  • pending_admin - Proposed new admin address

Returns

  • Ok(()) - Admin proposal created successfully
  • Err(TreasuryError) - Proposal failed (unauthorized or not initialized)
fn propose_admin(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    pending_admin: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Get all balances in the treasury.

Returns a map of all assets that have been deposited to the treasury along with their tracked balances. Assets with zero balance are not included in the map.

Arguments

  • env - The execution environment

Returns

  • Map<Address, u128> - Map of asset addresses to their balances
fn get_all_balances(
    env: soroban_sdk::Env,
) -> Result, TreasuryError>

Get the pending admin address, if any.

Arguments

  • env - The execution environment

Returns

  • Ok(Address) - Pending admin address
  • Err(TreasuryError) - No pending admin proposal exists
fn get_pending_admin(
    env: soroban_sdk::Env,
) -> Result

Cancel a pending admin proposal. Only the current admin can cancel a pending proposal.

Arguments

  • env - The execution environment
  • caller - Current admin address (must be authorized)

Returns

  • Ok(()) - Proposal cancelled successfully
  • Err(TreasuryError) - Cancellation failed (unauthorized, not initialized, or no pending admin)
fn cancel_admin_proposal(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
) -> Result<(), TreasuryError>

Imports

WebAssembly Text (WAT) ▶