Skip to main content

Module sui::funds_accumulator

A module for accumulating funds, i.e. Balance-like types.

use std::ascii;
use std::bcs;
use std::internal;
use std::option;
use std::string;
use std::vector;
use sui::accumulator;
use sui::address;
use sui::dynamic_field;
use sui::hex;
use sui::object;
use sui::party;
use sui::protocol_config;
use sui::transfer;
use sui::tx_context;
use sui::vec_map;

Struct Withdrawal

Allows for withdrawing funds from a given address. The Withdrawal can be created in PTBs for the transaction sender, or dynamically from an object via withdraw_from_object.
The redemption of the funds must be initiated from the module that defines T.

public struct Withdrawal<phantom T: store> has drop
Click to open
Fields
owner: address
The owner of the funds, either an object or a transaction sender
limit: u256
At signing we check the limit <= balance when taking this as a call arg.
If this was generated from an object, we cannot check this until redemption.

Constants

Attempted to withdraw more than the maximum value of the underlying integer type.

const EOverflow: u64 = 0;

Attempt to split more than the current limit of a Withdrawal.

#[error]
const EInvalidSubLimit: vector<u8> = b"Sub-limit exceeds current withdrawal limit";

Attempted to join two withdrawals with different owners.

#[error]
const EOwnerMismatch: vector<u8> = b"Withdrawal owners do not match";

Attempted to withdraw funds from an object when the feature flag is not enabled.

#[error]
const EObjectFundsWithdrawNotEnabled: vector<u8> = b"Object funds withdraw is not enabled";

Function withdrawal_owner

Returns the owner, either a sender's address or an object, of the withdrawal.

public fun withdrawal_owner<T: store>(withdrawal: &sui::funds_accumulator::Withdrawal<T>): address

Function withdrawal_limit

Returns the remaining limit of the withdrawal.

public fun withdrawal_limit<T: store>(withdrawal: &sui::funds_accumulator::Withdrawal<T>): u256

Function withdrawal_split

Split a Withdrawal and take a sub-withdrawal from it with the specified sub-limit.

public fun withdrawal_split<T: store>(withdrawal: &mut sui::funds_accumulator::Withdrawal<T>, sub_limit: u256): sui::funds_accumulator::Withdrawal<T>

Function withdrawal_join

Join two withdrawals together, increasing the limit of self by the limit of other.
Aborts with EOwnerMismatch if the owners are not equal.
Aborts with EOverflow if the resulting limit would overflow u256.

public fun withdrawal_join<T: store>(withdrawal: &mut sui::funds_accumulator::Withdrawal<T>, other: sui::funds_accumulator::Withdrawal<T>)

Function redeem

public(package) fun redeem<T: store>(withdrawal: sui::funds_accumulator::Withdrawal<T>, _: std::internal::Permit<T>): T

Function withdraw_from_object

public(package) fun withdraw_from_object<T: store>(obj: &mut sui::object::UID, limit: u256): sui::funds_accumulator::Withdrawal<T>

Function add_impl

public(package) fun add_impl<T: store>(value: T, recipient: address)

Function withdraw_impl

fun withdraw_impl<T: store>(owner: address, value: u256): T

Function add_to_accumulator_address

fun add_to_accumulator_address<T: store>(accumulator: address, recipient: address, value: T)

Function withdraw_from_accumulator_address

fun withdraw_from_accumulator_address<T: store>(accumulator: address, owner: address, value: u256): T

Function create_withdrawal

public(package) fun create_withdrawal<T: store>(owner: address, limit: u256): sui::funds_accumulator::Withdrawal<T>