add Spending Limit
Adds a spending limit policy to a context rule.
A spending limit policy restricts the total amount that can be spent within a rolling time window. The period is specified in ledgers (approximately 5 seconds per ledger, 720 per hour, 17,280 per day).
Converts the amount to stroops and delegates to addPolicy.
IMPORTANT: This operation requires the connected wallet to have authorization on the smart account. The user will be prompted for biometric authentication to sign the transaction.
Contract limits:
Maximum OZConstants.MAX_POLICIES policies per context rule
Policy address must be a valid C-address
Spending limit must be greater than zero
Period ledgers must be greater than zero
Return
TransactionResult indicating success or failure
Parameters
The context rule ID to add the policy to (0 for Default rule)
The policy contract address (C-address)
Maximum amount per period as a decimal string (e.g., "100" or "10.5"). Converted to stroops (7 decimal places) internally.
Period duration in ledgers (17,280 = approximately 1 day)
Optional list of signers for multi-signer authorization. When empty (default), uses single-signer auth with the connected passkey. When non-empty, coordinates signatures from all listed signers.
Optional submission method override. When null (default), uses the configured submission method (relayer if available, RPC otherwise).
Throws
if validation fails
if transaction submission fails
Example:
// Create a spending limit (1000 XLM per day)
val result = policyManager.addSpendingLimit(
contextRuleId = 0u,
policyAddress = "CBCD1234...",
spendingLimit = "1000",
periodLedgers = Util.LEDGERS_PER_DAY.toUInt()
)
if (result.success) {
println("Spending limit added: ${result.hash ?: ""}")
} else {
println("Failed to add policy: ${result.error ?: ""}")
}