Sponsor jobs
In this guide we will take you through an example of sponsoring a job using ees-sdk, viem and Typescript. Going forward it is assumed that ees-sdk is installed and setup like shown here.
As a real example, we will in this guide show how to sponsor a Socialsub job for a recurring payment using execution module 0x00 RegularTimeInterval and fee module 0x01 LinearAuction on Base Sepolia. The Socialsub application is depoyed at address 0xe1efEA15fe277A360bd9bE3e8860Ce5c508Ca938
.
The execution module input values we wish to sponsor has the following values:
uint32
cooldown
2592000
uint40
initialExecutionTime
0
Similarly, the fee module input values we wish to sponsor:
address
executionFeeToken
0x7139F4601480d20d43Fa77780B67D295805aD31a
uint256
minExecutionFee
0
uint256
maxExecutionFee
10000
Finally, the application input values for the job we wish to sponsor has the values:
address
recipient
0x303cAE9641B868722194Bd9517eaC5ca2ad6e71a
uint256
amount
1000000
address
token
0x7139F4601480d20d43Fa77780B67D295805aD31a
uint96
tierId
0
First, we are going to import some functions and types from ees-sdk and viem:
To create a sponsor signature for the said specification, we are going to use the signJobSpecificationSponsor
function which takes an object of type JobSpecification
. Before creating the object, we have to specify a nonce and a deadline. If reusableNonce
in the JobSpecification
is true, then the signature can be reused to create multiple with this specification until the nonce is invalidated on-chain. Otherwise, the nonce will be consumed and the signature can only be used once. In the latter case, we should use a new nonce for each signature. The deadline specifies when the signature expires. In this example we will just use nonce 0 and the maximum uint256 value as deadline (no deadline in practice).
Now we can utilize the signJobSpecificationSponsor
function from ees-sdk:
And voila, now we have successfully generated an EIP-712 signature which can be used as input to creating a job through the JobManager
contract.
Tip: In practice you can uniformly sample a random number between 0
and 2^256 - 1
for the nonce. Because the sample space is so large, the probability of generating two signatures with the same nonce is vanishingly small.
Warning: Be careful handling ERC-20 token amounts. The signed amounts are using full integer precision according to the number of decimals of the token. In this example, the maxExecutionFee
of 10000
correspond to 0.01
in decimal form since the fee token uses 6 decimals in this example. Viem's parseUnits
and formatUnits
functions can be utilized to convert between the two formats.
Careful: Be sure to only sign job specifications with reusableNonce=true
if you intend an unlimited number of users to be able to create jobs with this specification using you as sponsor.
Last updated