Core
Last updated
Was this helpful?
Last updated
Was this helpful?
The BandoERC20Fulfillable
contract manages the escrow and distribution of ERC20 tokens for fulfillment services. It holds tokens in escrow until fulfillment results are registered, then manages the release of tokens to beneficiaries and fee accumulation.
The BandoERC20Fulfillable
is responsible for:
Accepting ERC20 tokens for fulfillment requests and holding them in escrow
Tracking fulfillment records and their statuses
Managing releaseable pools for successful fulfillments
Managing accumulated fees for service providers
In V1_2, supporting swapping of tokens to stablecoins using DEX aggregators
The contract follows a versioned inheritance pattern:
BandoERC20FulfillableV1
: Base functionality for ERC20 token escrow and fulfillment
BandoERC20FulfillableV1_1
: Enhanced functionality and optimizations
BandoERC20FulfillableV1_2
: Added support for stablecoin swapping via DEX aggregators
The BandoERC20Fulfillable
responsibilities can be broken down into the following concepts:
The following methods are used to manage the escrow of ERC20 tokens for fulfillment requests:
depositERC20
Deposits ERC20 tokens for a fulfillment request. The function validates the request, uses the provided fee amount, and transfers the tokens from the sender to the contract.
Effects:
Validates that the caller is the router
Creates a new fulfillment record with the request details
Transfers the tokens from the sender to the contract using SafeERC20.safeTransferFrom
Tracks the deposit amount for the payer
Emits ERC20DepositReceived
event with the record details
Requirements:
Caller MUST be the router
Sender MUST have approved the contract to transfer at least the required token amount
The following methods are used to register fulfillment results:
registerFulfillment
Registers a fulfillment result and updates the appropriate pools based on the result status.
Effects:
Validates the fulfillment record exists
Updates the fulfillment record status
If status is SUCCESS, adds the token amount to the releaseable pool and fee amount to accumulated fees
If status is FAILED, authorizes a refund to the payer
Requirements:
Caller MUST be the manager
Fulfillment record MUST exist
Fulfillment record status MUST be PENDING
The following methods are used to manage funds after fulfillment:
beneficiaryWithdraw
Withdraws the beneficiary's available token balance to release (fulfilled with success).
Effects:
Validates the caller is the manager
Retrieves the service details from the registry
Transfers the releaseable pool amount to the beneficiary
Resets the releaseable pool for the service and token
Requirements:
Caller MUST be the manager
Releaseable pool MUST have a non-zero balance
withdrawAccumulatedFees
Withdraws the accumulated token fees for a given service ID.
Effects:
Validates the caller is the manager
Retrieves the service details from the registry
Transfers the accumulated fees to the beneficiary
Resets the accumulated fees for the service and token
Emits ERC20FeesWithdrawn
event
Requirements:
Caller MUST be the manager
Accumulated fees MUST have a non-zero balance
The following methods are available in V1_2 for swapping ERC20 tokens to stablecoins:
swapPoolsToStable
Swaps both releaseable pool and accumulated fees to stablecoins in a single transaction using an off-chain generated DEX aggregator call.
Effects:
Retrieves the fulfillment record
Calls SwapLib.swapERC20ToStable
to perform the swap
Requirements:
Caller MUST be the manager
Fulfillment record MUST exist
subtractPoolsAndFees
Subtracts the releaseable pools and accumulated fees for a given service and token.
Effects:
Subtracts the specified amount from the releaseable pool
Subtracts the specified fees from the accumulated fees
Emits PoolsAndFeesSubtracted
event
Requirements:
Caller MUST be the manager
withdrawFulfillerPoolAndFees
Withdraws the fulfiller's pool and fees to the specified beneficiaries.
Effects:
Validates the token and beneficiary addresses
Transfers the specified amount to the beneficiary
Transfers the specified fees to the fees beneficiary
Emits FulfillerPoolAndFeesWithdrawn
event
Requirements:
Caller MUST be the manager
Token address MUST NOT be zero
Beneficiary and fees beneficiary addresses MUST NOT be zero
Contract MUST have sufficient token balance
Gets the releaseable pool for a service and token.
Gets the releaseable pools for a service and token (V1_2).
Gets the accumulated fees for a service and token.
Gets a fulfillment record by service ID and record ID.
Emitted when tokens are escrowed for a fulfillment request.
Emitted when a fulfillment result is registered.
Emitted when tokens are withdrawn to a beneficiary.
Emitted when fees are withdrawn.
Emitted when the caller is not the authorized manager.
Emitted when an invalid service ID is provided.
Emitted when insufficient token allowance is provided for escrow.
Emitted when a fulfillment result has an invalid status.
The contract uses a manager-based access control pattern:
onlyManager
modifier restricts functions to be called only by the authorized manager (BandoFulfillmentManager)
The manager is set during initialization and can be updated by the owner
Interacts with IFulfillableRegistry
to validate services and get fee information
Interacts with IERC20
to transfer tokens for escrow and withdrawals
Receives calls from BandoFulfillmentManager
to register fulfillments and manage withdrawals
In V1_2, interacts with DEX aggregators to swap tokens to stablecoins