An overview of the IntentSource contract responsible for managing intent publishing, funding, and solver fulfillment.
IntentSource
contract.IntentSource
contract is responsible for managing the publishing of intents, the funding of intent vaults, and the withdrawal of intent rewards. This section describes the IntentSource
contract and the functions it contains, to give developers a reference for how to interact with the contract. Before reading this section, please refer to the Primary Data Structures section to understand the data structures used in the IntentSource
contract.
All code snippets in this section reference this specific commit.
publish
method, which calls _validateAndPublishIntent
to ensure the intent is valid and then emits an IntentCreated
event. Publishing an intent alerts all the participants on the network that the intent has been, or will be shortly, funded on the specified origin chain.
Publishing an Intent
as roughly analogous to posting calldata
in a rollup. The intent is posted to a single location that all participants in the network can index and react to.
fund
method, which calculates the deterministic intent hash, ensures the intent was not already funded, and then funds the intent.
publishAndFund
method, which is a convenience method that combines the functionality of the publish
and fund
methods.
IntentSource
contract uses the getIntentHash
method to calculate the deterministic intent hash, which is used to calculate the deterministic intent vault address. The intent hash is calculated by hashing the route and reward structs separately and then hashing the two hashes together. Because there is a salt in the route struct, this creates a unique hash for each intent.
intentVaultAddress
method can be used to calculate the deterministic intent vault address. This is possible because of the use of Create2, which allows for the deterministic creation of contracts at a specific address.
IntentSource
contract contains methods that also govern the behavior of refunds and rewards payments to solvers.
refund
method. This will send the intent collateral back to the user who published the intent by deploying a Vault
contract to the intent vault address which returns the collateral to the user.
withdrawRewards
method is used to withdraw rewards from an intent. This method checks that the intent is proven on the specified prover, has not been claimed or refunded, deploys a vault to the intent vault address, and then emits a Withdrawal
event. Solvers can also batch withdraw rewards by calling the batchWithdraw
method, which is a convenience method that combines the functionality of the withdrawRewards
method for multiple intents to save on gas / calldata.
Note that the method only accepts a route hash and reward struct, not an intent struct. This is because the intent hash is not needed to withdraw rewards, and is not required to be provided by the user, which saves on gas and calldata.
IntentSource
also supports gasless intent initiation, which allows users to initiate intents via signatures. Typically, these signatures are created and submitted directly by the solver who wants to fulfill the intent.
In order to gaslessly initiate an intent, the fundFor
and publishAndFundFor
methods are used. These methods use the permit
method to approve the intent source contract to spend the user’s tokens.
Open Quoting Client
to match solvers and users who have intents. Users should request quotes from the Open Quoting Client
to get matched with solvers before funding their intents, lest they be stuck without a solver and be locked out of their collateral for the duration of the intent.