Contract f7a5ec9acee4acbdec635a5d2ec5db4c13a7df7e8f308b0fd3d39c80a8177cd8

← Back to Index 📥 Download WASM

Meta

cliver 25.0.0#
rssdkver 23.4.1#e671b396f8bacf1370925f722df158b31c0baae5
rsver 1.91.0-nightly

Instances

  • CBHZTSJ2LJWD5YK6ZECITYS6GTCQHGBQNKDG2DDDW44Y352N6DGIZJRG

Interface

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>

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 authorized callers (admin or authorized contracts) 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 or authorized contract)
  • 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>

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

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 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

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 admin address.

Arguments

  • env - The execution environment

Returns

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

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>

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>

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

Imports

WebAssembly Text (WAT) ▶