import { TaskContext } from "compose";
export async function main({ evm, env }: TaskContext) {
const wallet = await evm.wallet();
const resultId = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
const payouts = [1000n, 2000n, 3000n];
// Replay on reorg
const { hash } = await wallet.writeContract(
evm.chains.polygon,
env.CONTRACT_ADDRESS as `0x${string}`,
"reportPayouts(bytes32,uint256[])",
[resultId, payouts],
{
confirmations: 5,
onReorg: {
action: {
// this will replay the transaction with a fresh nonce and gas if the transaction is reorged off chain after the 5 confirmations specified below
// it will then start watching again for the number of blocks specified in the "depth" property
type: "replay",
},
// we'll watch this transaction in the background for 200 blocks and replay it if the transaction receipt disappears
depth: 200,
},
},
{
max_attempts: 5,
initial_interval_ms: 1000,
backoff_factor: 2,
}
);
// Log on reorg
const { hash: hash2 } = await wallet.writeContract(
evm.chains.polygon,
env.CONTRACT_ADDRESS as `0x${string}`,
"reportPayouts(bytes32,uint256[])",
[resultId, payouts],
{
confirmations: 5,
onReorg: {
action: {
// this will just log in your normal app logs if the transaction is reorged off chain after the 5 confirmations specified below
type: "log",
logLevel: "warn", // defaults to "error"
},
// we'll watch this transaction in the background for 200 blocks and log if the transaction receipt disappears
depth: 200,
},
},
{
max_attempts: 5,
initial_interval_ms: 1000,
backoff_factor: 2,
}
);
// Custom task on reorg
const { hash: hash3 } = await wallet.writeContract(
evm.chains.polygon,
env.CONTRACT_ADDRESS as `0x${string}`,
"reportPayouts(bytes32,uint256[])",
[resultId, payouts],
{
confirmations: 5,
onReorg: {
action: {
// this will send the transaction as a payload to the specified task if the transaction is reorged off chain after the 5 confirmations specified below
type: "task",
task: "reorg-reconciler", // the name of your compose task with custom re-org handling logic
},
// we'll watch this transaction in the background for 200 blocks and call your "reorg-reconciler" if the transaction receipt disappears
depth: 200,
},
},
{
max_attempts: 5,
initial_interval_ms: 1000,
backoff_factor: 2,
}
);
}