Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions contracts/privacy_pool/src/core/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use soroban_sdk::{Address, Env};
use crate::crypto::merkle;
use crate::storage::config;
use crate::types::errors::Error;
use crate::types::state::{Denomination, PoolConfig, VerifyingKey};
use crate::types::state::{Asset, Denomination, PoolConfig, VerifyingKey};

/// Initialize the privacy pool with configuration.
///
Expand All @@ -23,6 +23,8 @@ pub fn execute(
env: Env,
admin: Address,
token: Address,
asset: Asset,
asset_address: Option<Address>,
denomination: Denomination,
vk: VerifyingKey,
) -> Result<(), Error> {
Expand All @@ -31,10 +33,12 @@ pub fn execute(
return Err(Error::AlreadyInitialized);
}

// Create pool configuration
// Create pool configuration with asset type
let pool_config = PoolConfig {
admin,
token,
asset,
asset_address,
denomination,
tree_depth: merkle::TREE_DEPTH,
root_history_size: merkle::ROOT_HISTORY_SIZE,
Expand Down
4 changes: 4 additions & 0 deletions contracts/privacy_pool/src/types/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub enum Error {
/// Recipient address is invalid
InvalidRecipient = 45,

// ── Verifying Key ──────────────────────────────────
/// Unsupported asset type
UnsupportedAsset = 46,

// ── Verifying Key ──────────────────────────────────
/// Verifying key has not been set
NoVerifyingKey = 50,
Expand Down
41 changes: 39 additions & 2 deletions contracts/privacy_pool/src/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,40 @@
// Storage keys use the DataKey enum pattern recommended by soroban-sdk.
// ============================================================

use soroban_sdk::{contracttype, Address, BytesN};
use soroban_sdk::{contracttype, Address, BytesN, Symbol};

// ──────────────────────────────────────────────────────────────
// Asset Type
// ──────────────────────────────────────────────────────────────

/// Supported asset types for privacy pools.
/// Each asset type maps to a separate pool instance.
#[contracttype]
#[derive(Clone, Debug, PartialEq)]
pub enum Asset {
/// Native Stellar Lumens (XLM)
XLM,
/// USDC stablecoin (via Stellar Asset Contract)
USDC,
}

impl Asset {
/// Returns a unique storage key prefix for per-asset pool separation.
pub fn pool_prefix(&self) -> Symbol {
match self {
Asset::XLM => Symbol::new(&soroban_sdk::Env::default(), "pool_xlm"),
Asset::USDC => Symbol::new(&soroban_sdk::Env::default(), "pool_usdc"),
}
}

/// Returns the number of decimal places for this asset.
pub fn decimals(&self) -> u32 {
match self {
Asset::XLM => 7, // 1 XLM = 10^7 stroops
Asset::USDC => 6, // 1 USDC = 10^6 microunits
}
}
}

// ──────────────────────────────────────────────────────────────
// Storage Keys
Expand Down Expand Up @@ -72,8 +105,12 @@ impl Denomination {
pub struct PoolConfig {
/// Pool administrator (can pause, update verifying key)
pub admin: Address,
/// Token contract address (XLM native or USDC)
/// Token contract address (XLM native or USDC SAC)
pub token: Address,
/// Asset type for this pool (XLM or USDC)
pub asset: Asset,
/// USDC Stellar Asset Contract address (None for XLM native)
pub asset_address: Option<Address>,
/// Fixed deposit denomination enforced by the pool
pub denomination: Denomination,
/// Merkle tree depth (always 20)
Expand Down