Contract ab3bb0da02d07610872b4a2f5dbbe9cf0a40e0544f63981097604f9d08d2a164

← Back to Index 📥 Download WASM

Meta

rssdkver 25.3.0#dcbea44513feb7734af6b6c4aced2c4a7a2715d0
rsver 1.90.0

Instances

  • CAKFNEXGJPBVQF3HIBVIEFJQMDYLDMHKE65EDF43WWILH7QBRHGV2WQH
  • CAQGTDOJKLWMLPY7BXP3TTCQONGME2JK3JE6MLII24XUDQQXZPX6HVWC
  • CATF3JJXBQOP3XRHBNUWKDG4AILH2MQVPSQBQKINKKGKK7B4ZNLRPQ3A
  • CAYS2LBUNO4STPRWVJ6H4LOCSWGQCFINAWIHID2GX67UDK3EJ4JJN6UW
  • CBU7WVLNGE6RKL5WLSR7TRM2Y63JD4DVMYNB3UANQQZB4SBHU2EOSSQM
  • CCMIWJE7M4SC4OOE6UOHF7YFG4K5Y2ELKRRF2I2MFY6AW3BQSE77S5CW
  • CCOEJVCW5QUBJ7JIXD4VPNEWQCDHHUD3VBCTG7ACXVRIRHAMBVWPTHPM
  • CDCZ3TTZMANVAPPDIAFFE3J4HDSRUTWJ2XKXU2VCC6YABNTGVKAXHW3B

Interface

Open a channel by depositing tokens from the funder to the contract.

  • token: The SEP-41 token used for payments.
  • from: The funder who deposits tokens into the channel.
  • commitment_key: The ed25519 public key used to verify commitment signatures. See prepare_commitment for details on commitments.
  • to: The recipient who can settle or close the channel using signed commitments.
  • amount: The initial deposit amount.
  • refund_waiting_period: The number of ledgers the recipient has to close after close_start is called, before refund becomes available. This value should be large enough to give the recipient time to observe a close event and submit a close, otherwise the recipient may not accept the channel. However, it should not be so large that the funder cannot reclaim funds in a timely manner. Setting zero or a very low number results in near-immediate refunds, which is almost certainly not useful for either participant.

Callable by the deployer.

Auth

  • from: required if amount > 0.
fn __constructor(
    env: soroban_sdk::Env,
    token: soroban_sdk::Address,
    from: soroban_sdk::Address,
    commitment_key: soroban_sdk::BytesN<32>,
    to: soroban_sdk::Address,
    amount: i128,
    refund_waiting_period: u32,
)

Top up the channel by transferring the amount of the channels token from the funder (from address).

Note: The funder can also top up the channel by transferring tokens directly to the channel contract address outside of this function.

Callable by funder (from).

Auth

  • from: required.
fn top_up(env: soroban_sdk::Env, amount: i128)

Returns the token address.

Callable by anyone.

Auth

None.

fn token(env: soroban_sdk::Env) -> soroban_sdk::Address

Returns the funder address.

Callable by anyone.

Auth

None.

fn from(env: soroban_sdk::Env) -> soroban_sdk::Address

Returns the recipient address.

Callable by anyone.

Auth

None.

fn to(env: soroban_sdk::Env) -> soroban_sdk::Address

Returns the refund waiting period in ledgers.

Callable by anyone.

Auth

None.

fn refund_waiting_period(env: soroban_sdk::Env) -> u32

Returns the balance of the channel. This is the deposited amount minus any amount already withdrawn.

Callable by anyone.

Auth

None.

fn balance(env: soroban_sdk::Env) -> i128

Returns the total amount deposited into the channel.

This is the balance plus the amount already withdrawn. Refunded amounts are considered no longer deposited.

Callable by anyone.

Auth

None.

fn deposited(env: soroban_sdk::Env) -> i128

Returns the total amount already withdrawn by the recipient via settle or close.

Callable by anyone.

Auth

None.

fn withdrawn(env: soroban_sdk::Env) -> i128

Returns the XDR serialized bytes of a commitment for the given amount.

The returned bytes must be signed by the ed25519 key corresponding to the commitment_key stored in the channel. The resulting signature, along with the amount, can be passed to settle or close by the recipient.

Commitments are typically prepared off-chain. This function is provided as a convenience.

Callable by anyone.

Auth

None.

fn prepare_commitment(env: soroban_sdk::Env, amount: i128) -> soroban_sdk::Bytes

Settle funds to the recipient using a signed commitment without closing the channel. The amount is the cumulative total the recipient is entitled to. Only the difference between the amount and what has already been withdrawn is transferred.

The recipient does not need to settle after every commitment. They can accumulate multiple commitments and settle using only the latest (highest amount) commitment.

If an older commitment with a lower amount is used after a higher amount has already been withdrawn, no funds are transferred.

Can be called even after the channel is closed, up until the funder calls [Contract::refund] and the balance is drained.

Callable by the recipient (to).

Auth

  • to: required.
  • Commitment signature serves as commitment_key authorization.
fn settle(env: soroban_sdk::Env, amount: i128, sig: soroban_sdk::BytesN<64>)

Close the channel using a signed commitment, withdrawing funds to the recipient. The amount is the cumulative total the recipient is entitled to. Only the difference between the amount and what has already been withdrawn is transferred.

After transferring, this function automatically attempts to refund the remaining balance to the funder using try_transfer. This refund attempt will silently succeed or fail without affecting the withdrawal. If the automatic refund fails, the funder can call [Contract::refund] to reclaim the remaining balance.

Can be called even after the channel is closed, up until the funder calls [Contract::refund] and the balance is drained.

Callable by the recipient (to).

Auth

  • to: required.
  • Commitment signature serves as commitment_key authorization.
fn close(env: soroban_sdk::Env, amount: i128, sig: soroban_sdk::BytesN<64>)

Begin closing the channel, effective after a waiting period. The recipient can still settle or close during and after the waiting period. After the close is effective, the funder can call refund to reclaim the remaining balance.

Important: The recipient should settle or close whenever they see a [event::Close], before the funder calls refund.

Callable by the funder (from).

Auth

  • from: required.
fn close_start(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>

Refund the remaining balance to the funder after the close is effective.

Can be called multiple times. This is useful if the funder accidentally deposits additional funds after closing — they can call refund again to reclaim the additional balance.

Callable by the funder (from), after the close effective_at_ledger has been reached.

Auth

  • from: required.
fn refund(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>

Imports

WebAssembly Text (WAT) ▶