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 an EES Pay job for a recurring payment using execution module RegularTimeInterval and fee module 0x00 LinearAuction on Base Sepolia. The EES Pay application is depoyed at address 0x7d337f7452fb892D7DAdfb4f7c02249DDAc41d4E.

The execution module input values we wish to sponsor has the following values:

Solidity typeNameValue

uint32

cooldown

2592000

uint40

initialExecutionTime

0

Similarly, the fee module input values we wish to sponsor:

Solidity TypeNameValue

address

executionFeeToken

0x7139F4601480d20d43Fa77780B67D295805aD31a

uint256

minExecutionFee

0

uint256

maxExecutionFee

10000

Finally, the application input values for the job we wish to sponsor has the values:

Solidity typeNameValue

address

recipient

0x303cAE9641B868722194Bd9517eaC5ca2ad6e71a

uint256

amount

1000000

address

token

0x7139F4601480d20d43Fa77780B67D295805aD31a

uint16

initialPayments

1

First, we are going to import some functions and types from ees-sdk and viem:

import { JobSpecification } from 'ees-sdk';
import { encodeAbiParameters } from 'viem';

To create a sponsor signature for the said specification, we are going to use the generateSponsorSignature function which takes an object of type JobSpecification. Before creating the object, we have to specify a nonce and a deadline. Each nonce can only be consumed through a signature once, so we should use a different 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).

const jobSpecification: JobSpecification = {
    nonce: 0n,
    deadline: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
    application: "0x7d337f7452fb892D7DAdfb4f7c02249DDAc41d4E",
    executionWindow: 1800,
    executionModule: "0x01",
    feeModule: "0x00",
    executionModuleInput: encodeAbiParameters(
      [
          {name: 'cooldown', type: 'uint32'},
          { name: 'initialExecutionTime', type: 'uint40' }
      ],
      [2592000, 0]
    ),
    feeModuleInput: encodeAbiParameters(
       [
          { name: 'executionFeeToken', type: 'address' },
          { name: 'minExecutionFee', type: 'uint256' },
          { name: 'maxExecutionFee', type: 'uint256' }
      ],
      ["0x7139F4601480d20d43Fa77780B67D295805aD31a", 0n, 10000n]
    ),
    applicationInput: encodeAbiParameters(
      [
          { name: 'recipient', type: 'address' },
          { name: 'amount', type: 'uint256' },
          { name: 'token', type: 'address' },
          { name: 'initialPayments', type: 'uint16' }
      ],
      ["0x303cAE9641B868722194Bd9517eaC5ca2ad6e71a", 1000000n, "0x7139F4601480d20d43Fa77780B67D295805aD31a", 1]
    )
  }

Now we can utilize the generateSponsorSignature function from ees-sdk:

const signature: `0x${string}` = await eesSdk.generateSponsorSignature(jobSpecification);

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. Becasue 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. Viem's parseUnits and formatUnits functions can be utilized to convert between the two formats.

Last updated