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.
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).
from: required.fn top_up(env: soroban_sdk::Env, amount: i128)
Returns the token address.
Callable by anyone.
None.
fn token(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the funder address.
Callable by anyone.
None.
fn from(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the recipient address.
Callable by anyone.
None.
fn to(env: soroban_sdk::Env) -> soroban_sdk::Address
Returns the refund waiting period in ledgers.
Callable by anyone.
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.
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.
None.
fn deposited(env: soroban_sdk::Env) -> i128
Returns the total amount already withdrawn by the recipient via
settle or close.
Callable by anyone.
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.
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).
to: required.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).
to: required.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).
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.
from: required.fn refund(env: soroban_sdk::Env) -> Result<(), soroban_sdk::Error>