dispersePay Function
Function Type: external
Function Signature: dispersePay(address,(uint256,address,string)[],address,uint256,uint256,uint256,bool,address,bytes)
Function Selector: 0xef83c1d6
Facilitates batch payments, enabling a single transaction to distribute a specified token from one sender (from
) to multiple recipients defined in toData
. This function supports both synchronous and asynchronous execution modes. The signature structure for these payments is detailed in the Disperse Payment Signature Structure section.
Parameters
Parameter | Type | Description |
---|---|---|
from | address | The address initiating the payment and whose funds will be dispersed. |
toData | DispersePayMetadata[] | An array detailing each recipient's address/identity and the amount they should receive. See struct below. |
token | address | The contract address of the token being dispersed. |
amount | uint256 | The total amount of token to be distributed across all recipients in toData . Must equal the sum of individual amounts in toData . |
priorityFee | uint256 | An additional fee paid in the specified token to the executor processing the transaction. |
nonce | uint256 | A user-specific nonce for replay protection. Usage depends on the priority flag (see Workflow. |
priority | bool | Determines execution mode: true for asynchronous (uses async nonce), false for synchronous (uses sync nonce). |
executor | address | The address authorized to submit this transaction to the contract. Can be address(0) for unrestricted execution. |
signature | bytes | A cryptographic signature (EIP-191) from the from address, authorizing the entire disperse operation. |
If you want to know more about the signature structure, refer to the Disperse Payment Signature Structure section.
DispersePayMetadata
Struct
Defines the payment details for a single recipient within the toData
array.
struct DispersePayMetadata {
uint256 amount;
address to_address;
string to_identity;
}
Field | Type | Description |
---|---|---|
amount | uint256 | The amount of token to be sent to this recipient. |
to_address | address | The recipient's direct address. Used if to_identity is empty. |
to_identity | string | An alternative identifier for the recipient. If provided, the contract will attempt to resolve it to an address. |
If to_identity
is an empty string (""
), the to_address
field will be used as the recipient's destination address. Otherwise, the contract attempts to resolve the to_identity
to its owner address.
Execution Methods
The function can be executed in two ways:
Fisher Execution
When the executor is the fisher:
- Multiple users send payment requests to the fishing spot
- The fisher captures these transactions and validates all parameters
- The fisher submits the consolidated transaction to the contract for processing
Direct Execution
When the executor is the user or a service:
- The user/service submits a set of transactions directly to the contract
If using a service as the direct executor, we recommend specifying the service's address as the executor
parameter.
Workflow
-
Signature Verification: Validates the provided
signature
against the reconstructed message hash and thefrom
address usingverifyMessageSignedForPay
. Ifpriority
isfalse
(synchronous), this verification also implicitly checks thenonce
against the expected synchronous nonce as part of the signed message. Reverts if the signature is invalid. -
Executor Validation: Checks if the
executor
parameter matches the transaction sender (msg.sender
). Ifexecutor
isaddress(0)
, this check is bypassed, allowing anyone to submit the transaction (provided the signature is valid). Reverts ifexecutor
is non-zero and doesn't matchmsg.sender
. -
Nonce Check (Asynchronous): If
priority
istrue
(asynchronous), checks if the providednonce
has already been used by consulting theasyncUsedNonce
mapping for thefrom
address. Reverts if the nonce is already marked as used. -
Balance Check: Verifies that the
from
address has a sufficient balance of thetoken
to cover theamount
plus thepriorityFee
. Reverts if balance is insufficient. -
Substract balance: Subtracts the
amount
andpriorityFee
from thefrom
address' balance. -
Payment Distribution Loop: Iterates through each
DispersePayMetadata
entry in thetoData
array:a. Initialize
accumulatedAmount
: A running total (accumulatedAmount
) is maintained, starting at zero.b. Resolve Recipient Address:
- If
to_identity
is provided (not empty), it attempts to resolve the identity to an owner address usingverifyStrictAndGetOwnerOfIdentity
from the MateNameService contract. - If
to_identity
is empty, it uses the providedto_address
.
c. Transfer to Recipient: Transfers the
amount
specified in the currentDispersePayMetadata
entry from this contract to the resolved recipient address.d. Update Accumulated Amount: Adds the recipient's
amount
to theaccumulatedAmount
tracker. - If
-
Total Amount Verification: After the loop, verifies that the final
accumulatedAmount
exactly equals theamount
parameter initially provided. Reverts if there is a mismatch. -
Executor Reward (Optional): If the
executor
(msg.sender
) holds sMATE tokens, the contract may trigger a reward distribution using_giveMateReward
, typically equivalent to onegetReward()
plus thepriorityFee
, the reward amount is given in MATE tokens and thepriorityFee
is given in the token specified in thetoken
parameter. -
Nonce Update: Marks the
nonce
as used for thefrom
address to prevent replays.- If
priority
wastrue
, updates the asynchronous nonce tracking (asyncUsedNonce
). - If
priority
wasfalse
, updates the synchronous nonce tracking adding one to thenextSyncUsedNonce
mapping for thefrom
address.
- If