Contract Methods
Protocol

Contract Methods

Exhaustive reference of all 14 public methods implemented in the contract.

Exhaustive technical reference of all public methods exposed by the SplitPayContract implementation.

initialize(env, admin: Address)Admin Only

Initializes the contract config with a designated administrator address.

  • Authorization: admin.require_auth()
  • Errors: Error::AlreadyInitialized (1) if previously called.
rust
pub fn initialize(env: Env, admin: Address) -> Result<(), Error>
create_pool(env, pool_id: u64, owner: Address, asset: Address)

Creates a new payment pool with an initial status of Active.

  • Authorization: owner.require_auth()
  • State Changes: Sets Pool in storage, initializes empty member address list, emits pool_created.
  • Errors: Error::NotInitialized (2), Error::PoolAlreadyExists (16).
rust
pub fn create_pool(env: Env, pool_id: u64, owner: Address, asset: Address) -> Result<(), Error>
add_member(env, pool_id: u64, address: Address, share_bps: u32)

Adds a member address and their allocation share in basis points (10,000 = 100%).

  • Authorization: Pool owner (pool.owner.require_auth())
  • Validation: share_bps > 0 && share_bps <= 10000; cumulative shares cannot exceed 10,000.
  • Errors: Error::PoolNotFound (3), Error::MemberAlreadyExists (6), Error::InvalidShare (9), Error::InvalidTotalShares (10).
rust
pub fn add_member(env: Env, pool_id: u64, address: Address, share_bps: u32) -> Result<(), Error>
remove_member(env, pool_id: u64, address: Address)

Removes an existing member from the pool.

  • Authorization: Pool owner (pool.owner.require_auth())
  • Errors: Error::PoolNotFound (3), Error::MemberNotFound (5).
rust
pub fn remove_member(env: Env, pool_id: u64, address: Address) -> Result<(), Error>
update_member_share(env, pool_id: u64, address: Address, share_bps: u32)

Updates the basis points allocation for an existing pool member.

  • Authorization: Pool owner (pool.owner.require_auth())
  • Validation: Total new shares across all members cannot exceed 10,000 BPS.
  • Errors: Error::MemberNotFound (5), Error::InvalidTotalShares (10).
rust
pub fn update_member_share(env: Env, pool_id: u64, address: Address, share_bps: u32) -> Result<(), Error>
set_pool_status(env, pool_id: u64, status: PoolStatus)

Toggles pool status between Active (1) and Inactive (2).

  • Authorization: Pool owner (pool.owner.require_auth())
  • Errors: Error::PoolNotFound (3).
rust
pub fn set_pool_status(env: Env, pool_id: u64, status: PoolStatus) -> Result<(), Error>
get_pool(env, pool_id: u64) -> Result<Pool, Error>Read Only

Retrieves details of a registered pool.

rust
pub fn get_pool(env: Env, pool_id: u64) -> Result<Pool, Error>
get_member(env, pool_id: u64, address: Address) -> Result<Member, Error>Read Only

Retrieves a specific member record within a pool.

rust
pub fn get_member(env: Env, pool_id: u64, address: Address) -> Result<Member, Error>
get_pool_members(env, pool_id: u64) -> Result<Vec<Member>, Error>Read Only

Returns an ordered vector of all configured members in a pool.

rust
pub fn get_pool_members(env: Env, pool_id: u64) -> Result<Vec<Member>, Error>
create_payment(env, payment_id: u64, pool_id: u64, payer: Address, amount: i128)

Records an unsettled payment targeting a pool. Verifies that total shares equal exactly 10,000 BPS before accepting.

  • Authorization: payer.require_auth()
  • Validation: amount > 0, pool must be Active, sum of shares must be 10,000.
  • Errors: Error::InvalidAmount (11), Error::PaymentAlreadyExists (13), Error::InvalidPoolStatus (8), Error::InvalidTotalShares (10).
rust
pub fn create_payment(env: Env, payment_id: u64, pool_id: u64, payer: Address, amount: i128) -> Result<(), Error>
settle_payment(env, payment_id: u64)Atomic Settlement

Atomically pulls funds from payer via SEP-41 token transfer, calculates exact distributions with deterministic remainder handling, and disburses tokens to all members.

  • Authorization: payment.payer.require_auth()
  • State Changes: Sets payment.status = PaymentStatus::Settled, persists Distribution structs, emits payment_settled.
  • Errors: Error::PaymentNotFound (4), Error::PaymentAlreadySettled (14), Error::InvalidPoolStatus (8), Error::InvalidTotalShares (10).
rust
pub fn settle_payment(env: Env, payment_id: u64) -> Result<(), Error>
get_payment(env, payment_id: u64) -> Result<Payment, Error>Read Only

Retrieves status and details of a payment.

rust
pub fn get_payment(env: Env, payment_id: u64) -> Result<Payment, Error>
get_distribution(env, payment_id: u64, recipient: Address) -> Result<Distribution, Error>Read Only

Retrieves the immutable distribution record for a specific recipient in a settled payment.

rust
pub fn get_distribution(env: Env, payment_id: u64, recipient: Address) -> Result<Distribution, Error>
get_distributions(env, payment_id: u64) -> Result<Vec<Distribution>, Error>Read Only

Returns all distributions for a settled payment.

rust
pub fn get_distributions(env: Env, payment_id: u64) -> Result<Vec<Distribution>, Error>