Expand description
§Fee Abstraction Module
This module provides utilities for implementing fee abstraction in Stellar contracts, allowing users to pay transaction fees in tokens instead of native XLM.
§Core Features
- Target invocation and fee collection helper
- Fee Token Allowlist: Optional allowlist for accepted fee tokens
- Token Sweeping: Optional functions to collect accumulated fees
- Fee Validation: Utilities for validating fee amounts
- Approval strategies: utilities for collecting fee from users support
two approval semantics:
FeeAbstractionApproval::Eager: always approvemax_fee_amount(overwriting any existing allowance)FeeAbstractionApproval::Lazy: only approve if the current allowance is less thanmax_fee_amount
§Usage
This module provides storage functions and event helpers that can be integrated into a fee forwarding contract. The implementing contract is responsible for the authorization checks and who can manage fee tokens or sweep collected fees.
Structs§
- FeeCollected
- Event emitted when a fee is collected from a user.
- FeeToken
Allowlist Updated - Event emitted when a fee token is added or removed from the allowlist.
- Forward
Executed - Event emitted when a call is forwarded to a target contract.
- Tokens
Swept - Event emitted when tokens are swept from the contract.
Enums§
- FeeAbstraction
Approval - Approval strategy for fee collection helpers.
- FeeAbstraction
Error - Errors that can occur in fee abstraction operations.
- FeeAbstraction
Storage Key
Constants§
- FEE_
ABSTRACTION_ EXTEND_ AMOUNT - TTL threshold for extending storage entries (in ledgers)
- FEE_
ABSTRACTION_ TTL_ THRESHOLD - TTL extension amount for storage entries (in ledgers)
Statics§
- __
SPEC_ XDR_ EVENT_ FEECOLLECTED - __
SPEC_ XDR_ EVENT_ FEETOKENALLOWLISTUPDATED - __
SPEC_ XDR_ EVENT_ FORWARDEXECUTED - __
SPEC_ XDR_ EVENT_ TOKENSSWEPT - __
SPEC_ XDR_ TYPE_ FEEABSTRACTIONERROR
Functions§
- collect_
fee - Low-level helper to collect a fee from the user in a given token by checking whether the token is allowed when allow list is enabled.
- collect_
fee_ and_ invoke - Collect the fee and invoke the target contract (forward).
- emit_
fee_ collected - Emits an event when a fee is collected from a user.
- emit_
fee_ token_ allowlist_ updated - Emits an event when a fee token is added or removed from the allowlist.
- emit_
forward_ executed - Emits an event when a call is forwarded to a target contract.
- emit_
tokens_ swept - Emits an event when tokens are swept from the contract.
- is_
allowed_ fee_ token - Check if a token is allowed for fee payment.
- is_
fee_ token_ allowlist_ enabled - Check if the fee token allowlist is enabled. It is considered enabled if at least one fee token has been added to the allowlist.
- set_
allowed_ fee_ token - Allow or disallow a token for fee payment.
- sweep_
token - Sweep accumulated tokens from the contract to a recipient.
- validate_
expiration_ ledger - Validate the ledger is in the future.
- validate_
fee_ bounds - Validate that the fee amount does not exceed the maximum allowed or is <= 0.