Initializes the P2P marketplace contract with essential configuration. This function can only be called once and sets up the foundational parameters.
admin - The address that will have administrative privileges (pause, fees, disputes)usdc_token_id - The contract address of the USDC token to be tradedfee_collector - The address that will receive trading feesResult indicating success or failure of initialization
fn initialize(
env: soroban_sdk::Env,
admin: soroban_sdk::Address,
usdc_token_id: soroban_sdk::Address,
fee_collector: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Creates a new offer to sell USDC for KES with escrow protection. The seller must approve the contract to spend their USDC before calling this function.
seller - The address creating the offer (must sign transaction)usdc_amount - Amount of USDC to sell (with 6 decimals)kes_amount - Amount of KES expected in return (off-chain settlement)The unique ID of the created offer
fn create_offer(
env: soroban_sdk::Env,
seller: soroban_sdk::Address,
usdc_amount: i128,
kes_amount: i128,
) -> Result
Initiates a trade by a buyer against an existing offer. This begins the escrow process where USDC is held while payment confirmation occurs.
buyer - The address initiating the trade (must sign transaction)offer_id - The ID of the offer to trade againstThe unique ID of the created trade
fn initiate_trade(
env: soroban_sdk::Env,
buyer: soroban_sdk::Address,
offer_id: u64,
) -> Result
Allows trade participants to confirm payment completion. Both buyer and seller must confirm before USDC is released.
trade_id - The ID of the trade to confirm payment forparticipant - The address confirming (buyer or seller, must sign)fn confirm_payment(
env: soroban_sdk::Env,
trade_id: u64,
participant: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Allows trade participants to cancel an initiated trade. This returns the escrowed USDC to the seller.
trade_id - The ID of the trade to cancelparticipant - The address requesting cancellation (buyer or seller)fn cancel_trade(
env: soroban_sdk::Env,
trade_id: u64,
participant: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Resolves expired trades by returning escrowed USDC to sellers. Anyone can call this function to clean up expired trades.
trade_id - The ID of the expired trade to resolvefn resolve_expired_trade(
env: soroban_sdk::Env,
trade_id: u64,
) -> Result<(), soroban_sdk::Error>
Allows sellers to cancel their offers and recover escrowed USDC. Offers can only be cancelled if no active trade exists.
seller - The address that created the offer (must sign)offer_id - The ID of the offer to cancelfn cancel_offer(
env: soroban_sdk::Env,
seller: soroban_sdk::Address,
offer_id: u64,
) -> Result<(), soroban_sdk::Error>
Emergency function to pause all trading activities. Only admin can pause the contract for security or maintenance.
Result indicating success or failure of pause operation
fn pause(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>
Resumes trading activities after a pause. Only admin can unpause the contract.
Result indicating success or failure of unpause operation
fn unpause(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>
Raises a dispute for a trade when payment confirmation conflicts arise. This function allows trade participants to escalate issues that cannot be resolved through normal payment confirmation flow.
trade_id - The ID of the trade to disputecaller - The address raising the dispute (buyer or seller)Result indicating success or failure of dispute creation
fn raise_dispute(
env: soroban_sdk::Env,
trade_id: u64,
caller: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Resolves a disputed trade with admin intervention. Only the admin can resolve disputes by choosing to release USDC to buyer or refund to seller.
trade_id - The ID of the disputed trade to resolveresolution - The admin's decision (ReleaseToBuyer or RefundToSeller)Result indicating success or failure of dispute resolution
fn resolve_dispute(
env: soroban_sdk::Env,
trade_id: u64,
resolution: DisputeResolution,
) -> Result<(), soroban_sdk::Error>
Upgrades the contract to a new Wasm hash. This function can only be called by the contract admin.
new_wasm_hash - The hash of the new contract Wasm to upgrade to.fn upgrade(
env: soroban_sdk::Env,
new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), soroban_sdk::Error>
Updates the admin address to a new address. This is a critical security function that transfers administrative control.
new_admin - The new admin address (must sign transaction)Result indicating success or failure of admin update
fn update_admin(
env: soroban_sdk::Env,
new_admin: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Updates the fee collector address where trading fees are sent. This allows admin to change where marketplace fees are collected.
new_fee_collector - The new address to receive trading feesResult indicating success or failure of fee collector update
fn update_fee_collector(
env: soroban_sdk::Env,
new_fee_collector: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Updates the trading fee rate charged on completed trades. Fee rate is specified in basis points (1/100th of a percent).
new_fee_rate - New fee rate in basis points (max 1000 = 10%)Result indicating success or failure of fee rate update
fn update_fee_rate(
env: soroban_sdk::Env,
new_fee_rate: u32,
) -> Result<(), soroban_sdk::Error>
Updates the minimum and maximum trade amounts for USDC trades. These limits help prevent spam trades and excessive exposure.
min_amount - Minimum USDC amount for trades (with 6 decimals)max_amount - Maximum USDC amount for trades (with 6 decimals)Result indicating success or failure of limits update
fn update_trade_limits(
env: soroban_sdk::Env,
min_amount: i128,
max_amount: i128,
) -> Result<(), soroban_sdk::Error>
Updates the trade expiration time for new trades. This controls how long buyers have to confirm payment before trades expire.
expiration_seconds - New expiration time in seconds (60 to 86400)Result indicating success or failure of expiration update
fn update_trade_expiration(
env: soroban_sdk::Env,
expiration_seconds: u64,
) -> Result<(), soroban_sdk::Error>
Returns the current admin address.
The address of the current contract administrator
fn get_admin(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the USDC token contract address.
The address of the USDC token contract
fn get_usdc_token_id(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the fee collector address.
The address that receives trading fees
fn get_fee_collector(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the current trading fee rate in basis points.
Current fee rate in basis points (e.g., 25 = 0.25%)
fn get_fee_rate(env: soroban_sdk::Env) -> u32
Returns the current minimum and maximum trade amounts.
Tuple of (minimum_amount, maximum_amount) in USDC with 6 decimals
fn get_trade_limits(env: soroban_sdk::Env) -> (i128, i128)
Returns the current trade expiration time in seconds.
Trade expiration time in seconds
fn get_trade_expiration(env: soroban_sdk::Env) -> u64
Returns the next offer ID that will be assigned.
The next available offer ID
fn get_next_offer_id(env: soroban_sdk::Env) -> u64
Returns the next trade ID that will be assigned.
The next available trade ID
fn get_next_trade_id(env: soroban_sdk::Env) -> u64
Returns all offers in the marketplace. Warning: This function can be expensive for large datasets.
get_offer for specific lookupsMap of all offers keyed by offer ID
fn get_offers(env: soroban_sdk::Env) -> soroban_sdk::Map
Returns a specific offer by its ID.
offer_id - The ID of the offer to retrieveThe offer if it exists, None otherwise
fn get_offer(env: soroban_sdk::Env, offer_id: u64) -> Option
Returns all trades in the marketplace. Warning: This function can be expensive for large datasets.
get_trade for specific lookupsMap of all trades keyed by trade ID
fn get_trades(env: soroban_sdk::Env) -> soroban_sdk::Map
Returns a specific trade by its ID.
trade_id - The ID of the trade to retrieveThe trade if it exists, None otherwise
fn get_trade(env: soroban_sdk::Env, trade_id: u64) -> Option
Returns the mapping of sellers to their active offer IDs.
Map of seller addresses to their active offer IDs
fn get_active_offers(
env: soroban_sdk::Env,
) -> soroban_sdk::Map
Returns the active offer ID for a specific seller.
seller - The seller address to checkThe seller's active offer ID if they have one, None otherwise
fn get_seller_active_offer(
env: soroban_sdk::Env,
seller: soroban_sdk::Address,
) -> Option
Returns whether the contract is currently paused.
True if contract is paused, false if trading is active
fn is_paused(env: soroban_sdk::Env) -> bool
Returns comprehensive contract configuration and status. This is a convenience function that aggregates multiple config values.
Tuple containing: (admin, usdc_token, fee_collector, fee_rate, min_amount, max_amount, expiration, is_paused)
fn get_contract_info(
env: soroban_sdk::Env,
) -> (
soroban_sdk::Address,
soroban_sdk::Address,
soroban_sdk::Address,
u32,
i128,
i128,
u64,
bool,
)