The TransferScheduler is a public-good smart contract to facilitate scheduled ERC20 token transfers on Ethereum blockchains. It allows users to queue transfers that will be executed at a specified future time, ensuring that transactions occur automatically without the need for manual intervention. This offers:
- Better Capital Efficiency: Users retain control of their ERC20 tokens until the scheduled transaction date, allowing them to accrue interest and rewards or utilize funds for other purposes in the interim.
- Onchain Transparency: Senders and Recipients can view upcoming transfers directly on the blockchain, enhancing financial transparency.
- Convenience: This allows users to plan and automate payments, improving convenience. Ideal for routine payments, such as remittances, DAO disbursements, and small business payroll.
- Non-Monotonic Nonces: Allows for non-sequential scheduling of transactions at arbitrary points in time, independent of previous transactions.
- Transfer Restrictions:
notBeforeDate
andnotAfterDate
dates ensure that transfers are only executed within the valid time frame.block.timestamp
is used for comparison. - Relayer Gas Compensation: The contract compensates relayers for their ETH gas spend in WETH. An additional gas percentage commission is added to compensate relayers for their
MaxPriorityFeePerGas
tip, compute costs, and opportunity costs.- The gas compensation is calculated as
block.basefee * 380000 (gas usage) * (100 + relayGasCommissionPercentage) / 100
. relayGasCommissionPercentage
is initialized at contract deployment for each chain (50% by default).- The WETH payment to the relayer is included automatically as part of the contract transfer.
- If insufficient WETH is available, the relayer will not broadcast the transaction.
- The gas compensation is calculated as
- Gas Price Threshold: Transfers will not execute if the network gas price
block.basefee
is higher than the user specified thresholdmaxBaseFee
. - Offchain queuing: ScheduledTransfer signed messages can be provided directly to recipients or third party relays for offchain queuing, thereby avoid onchain queueing gas cost (70k gas).
The core functionality is implemented in the TransferScheduler smart contract, which includes methods for:
- Queuing signed scheduled transfers (address, nonce, nonce status) - 70k gas
- Verifies the user EIP712 ScheduledTransfer typed message signature
- Executing scheduled transfers
- Base: 130k gas with EOA | 380k gas with Smart Account
- Arbitrum: 700k gas with EOA | 800k gas with Smart Account
- Retrieving the relay gas token
- Retrieving the relay gas usage
- Retrieving the relay gas commission percentage
The frontend provides an example user interface for:
- Creating, signing and queuing scheduled transfers
- Increasing allowance for the transfer token and relay gas token
- Watching for TransferScheduled events
- Listing historical completed or future uncompleted transfers
An demo example is published at https://mnrgreg.github.io/TransferScheduler/ which uses Arbitrum Mainnet and Base Mainnet with WETH
as the relay gas token and Polygon Mainnet with WPOL
.
The client SDK provides a JavaScript library for interacting with the TransferScheduler contract. It includes functions for:
- Queuing a signed scheduled transfer.
- Watching for TransferScheduled events.
- Types for creating and signing scheduled transfers.
A basic reference implementation that is responsible for:
- Listening for events.
- Persisting event entries to a local queue.
- Evaluating all transfer restrictions before executing.
- Executing the transfer with a pre-signed signature.
// EIP712 Typed Message for Scheduled Transfers
primaryType: 'ScheduledTransfer',
domain: {
name: 'TransferScheduler',
version: '1',
chainId: chainId,
verifyingContract: TransferSchedulerContractAddress
},
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" }
],
ScheduledTransfer: [
{ name: 'owner', type: 'address' },
{ name: 'nonce', type: 'uint96' },
{ name: 'token', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint128' },
{ name: 'spender', type: 'address' },
{ name: 'notBeforeDate', type: 'uint40' },
{ name: 'notAfterDate', type: 'uint40' },
{ name: 'maxBaseFee', type: 'uint40' },
]
}
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.