Treasury

The Treasury contract is the backbone of the Orbit Protocol, responsible for managing stablecoin minting, supply control, and flash loan operations. It interacts with stablecoins, Blend pools, and the Pegkeeper to maintain the stability of the protocol's stablecoins.

Core Functionality

Initialization

The Treasury contract is initialized with two key parameters:

  • admin: Address with administrative privileges

  • pegkeeper: Address of the Pegkeeper contract

fn initialize(e: Env, admin: Address, pegkeeper: Address)

Stablecoin Management

Adding Stablecoins

The add_stablecoin function enables the admin to register new stablecoins with their corresponding Blend pools:

fn add_stablecoin(e: Env, token: Address, blend_pool: Address)
  • Only callable by admin

  • Maps stablecoin token address to its Blend pool

  • Emits an event with token and pool addresses

Supply Control

The Treasury provides two functions for managing stablecoin supply:

Increase Supply

fn increase_supply(e: Env, token: Address, amount: i128)
  • Mints new stablecoins to the Treasury

  • Deposits minted tokens into the corresponding Blend pool

  • Requires positive amount

  • Only callable by admin

Decrease Supply

fn decrease_supply(e: Env, token: Address, amount: i128)
  • Withdraws tokens from Blend pool

  • Burns the withdrawn tokens

  • Requires positive amount

  • Verifies sufficient supply before burning

  • Only callable by admin

Peg Maintenance

The keep_peg function is the core mechanism for maintaining stablecoin pegs:

fn keep_peg(e: Env, name: Symbol, args: Vec<Val>)

Operation Flow:

  1. Validates token address and amount from arguments

  2. Mints requested tokens to Pegkeeper

  3. Executes specified operation (via name and args)

  4. Verifies flash loan repayment

  5. Burns repaid tokens

Safety Mechanisms:

  • Requires amount > 0

  • Validates flash loan repayment

  • Automatically burns repaid tokens

  • Reverts on failed operations

Administration

The Treasury includes administrative functions for protocol management:

fn set_pegkeeper(e: Env, pegkeeper: Address)
  • Updates Pegkeeper address

  • Only callable by admin

  • Emits event on change

fn upgrade(e: Env, new_wasm_hash: BytesN<32>)
  • Upgrades contract implementation

  • Only callable by admin

  • Uses Soroban contract upgrade mechanism

Events

The Treasury emits events for major operations:

  • initialize: Contract initialization

  • add_stablecoin: New stablecoin registration

  • increase_supply: Supply increase

  • decrease_supply: Supply decrease

  • keep_peg: Peg maintenance operation

  • set_pegkeeper: Pegkeeper address update

Error Handling

The contract includes several error conditions:

  • AlreadyInitializedError: Duplicate initialization

  • InvalidAmount: Zero or negative amount

  • NotEnoughSupplyError: Insufficient supply for burning

  • FlashloanFailedError: Failed flash loan repayment

Last updated