Sponsored transactions using Permit2
GPL-3.0 License
Simple sponsored transactions framework using Permit2 for batch token transfers and signature verification.
Users specify their sponsored execution using the following parameters:
struct Execution {
ISignatureTransfer.TokenPermissions[] tokens;
Operation[] operations;
Condition[] conditions;
address sender;
uint256 nonce;
uint256 deadline;
bytes signature;
}
tokens
The ERC20 tokens and amounts that will be used for the execution. These are transferred from the user using permit2 into the sponsor contract to be used for any operations.
operations
The operations that will be executed. These are made as external calls to the specified address with the specified data. I.e. user can specify simple transfers of tokens, swaps on AMMS, deposits into lending markets etc.
There are some built-in operations to simplify common flows:
conditions
Any conditions that the user wants to check after all operations are finished. I.e. check to ensure the user balances of a given token exceed a certain amount. A simple scripting language is used for defining conditions.
ex: assert(tokenA.balanceOf(user) >= 1000) would be defined as:
sender
The address of the signer
nonce
The nonce of the signer using the permit2 unordered nonce scheme
deadline
The timestamp deadline for the signature validity
signature
The sender signature in joined signature format, or EIP-1271 signature data
In order to submit executions through Sponsor, users must have first approved Permit2 for any tokens they wish to use.
Sponsor includes a "Permit2 setup" set of utility functions in base/Permit2Setup.sol which can be used to streamline this process. If the ERC20 token that is being onboarded supports native permit, these functions can be called in the same transaction as the execution itself to have a fully gasless onboarding experience.
Operators can use the built-in multicall function to batch the Permit2Setup call(s) with execution itself.
THIS IS EXPERIMENTAL, UNAUDITED CODE -- DO NOT USE IN PRODUCTION