const INTENT_SOURCE_ABI = [
{
"inputs": [
{
"components": [
{
"components": [
{ "name": "salt", "type": "bytes32" },
{ "name": "source", "type": "uint256" },
{ "name": "destination", "type": "uint256" },
{ "name": "inbox", "type": "address" },
{
"components": [
{ "name": "token", "type": "address" },
{ "name": "amount", "type": "uint256" }
],
"name": "tokens",
"type": "tuple[]"
},
{
"components": [
{ "name": "target", "type": "address" },
{ "name": "callData", "type": "bytes" },
{ "name": "value", "type": "uint256" }
],
"name": "calls",
"type": "tuple[]"
}
],
"name": "route",
"type": "tuple"
},
{
"components": [
{ "name": "creator", "type": "address" },
{ "name": "prover", "type": "address" },
{ "name": "deadline", "type": "uint256" },
{ "name": "nativeValue", "type": "uint256" },
{
"components": [
{ "name": "token", "type": "address" },
{ "name": "amount", "type": "uint256" }
],
"name": "tokens",
"type": "tuple[]"
}
],
"name": "reward",
"type": "tuple"
}
],
"name": "intent",
"type": "tuple"
},
{ "name": "usePermit2", "type": "bool" }
],
"name": "publishAndFund",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "hash", "type": "bytes32" },
{ "indexed": false, "name": "salt", "type": "bytes32" },
{ "indexed": false, "name": "source", "type": "uint256" },
{ "indexed": false, "name": "destination", "type": "uint256" },
{ "indexed": false, "name": "inbox", "type": "address" },
{ "indexed": false, "name": "tokens", "type": "tuple[]" },
{ "indexed": false, "name": "calls", "type": "tuple[]" },
{ "indexed": false, "name": "creator", "type": "address" },
{ "indexed": false, "name": "prover", "type": "address" },
{ "indexed": false, "name": "deadline", "type": "uint256" },
{ "indexed": false, "name": "nativeValue", "type": "uint256" },
{ "indexed": false, "name": "rewardTokens", "type": "tuple[]" }
],
"name": "IntentCreated",
"type": "event"
}
];
async function publishIntent(intent: Intent, intentSourceAddress: string) {
const intentSource = new ethers.Contract(
intentSourceAddress,
INTENT_SOURCE_ABI,
signer
);
// Calculate gas estimate
const gasEstimate = await intentSource.estimateGas.publishAndFund(
intent,
false, // usePermit2
{ value: intent.reward.nativeValue }
);
// Publish with 20% gas buffer
const tx = await intentSource.publishAndFund(
intent,
false,
{
value: intent.reward.nativeValue,
gasLimit: gasEstimate.mul(120).div(100)
}
);
console.log(`Publishing intent: ${tx.hash}`);
const receipt = await tx.wait();
// Extract intent hash from event
const event = receipt.events?.find(e => e.event === 'IntentCreated');
const intentHash = event?.args?.hash;
console.log(`Intent published with hash: ${intentHash}`);
return { txHash: tx.hash, intentHash };
}