|
| 1 | +// This script finds the associated Fill Status PDA from a fill OR deposit event by re-deriving it without doing any |
| 2 | +// // on-chain calls. Note the props required are present in both deposit and fill events. |
| 3 | +// Example usage: |
| 4 | +// anchor run findFillStatusPdaFromFill -- \ |
| 5 | +// --input_token "0x1c7d4b196cb0c7b01d743fbc6116a902379c7238" \ |
| 6 | +// --output_token "wBeYLVBabtv4cyb7RyMmRxvRSkRsCP4PMBCJRw66kKC" \ |
| 7 | +// --input_amount "1" \ |
| 8 | +// --output_amount "1" \ |
| 9 | +// --repayment_chain_id "133268194659241" \ |
| 10 | +// --origin_chain_id "11155111" \ |
| 11 | +// --deposit_id "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,98" \ |
| 12 | +// --fill_deadline 1740569770 \ |
| 13 | +// --exclusivity_deadline 1740569740 \ |
| 14 | +// --exclusive_relayer "0x0000000000000000000000000000000000000000" \ |
| 15 | +// --depositor "0x9a8f92a830a5cb89a3816e3d267cb7791c16b04d" \ |
| 16 | +// --recipient "5HRmK3G6BzWAtF22dBgoTiPGVovSmG4rLvVQoUhum9FJ" \ |
| 17 | +// --message_hash "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" |
| 18 | + |
| 19 | +import * as anchor from "@coral-xyz/anchor"; |
| 20 | +import { PublicKey } from "@solana/web3.js"; |
| 21 | +import { BN } from "@coral-xyz/anchor"; |
| 22 | +import yargs from "yargs"; |
| 23 | +import { hideBin } from "yargs/helpers"; |
| 24 | +import { calculateRelayEventHashUint8Array, getSpokePoolProgram, evmAddressToPublicKey } from "../../src/svm/web3-v1"; |
| 25 | + |
| 26 | +// Set up the provider |
| 27 | +const provider = anchor.AnchorProvider.env(); |
| 28 | +anchor.setProvider(provider); |
| 29 | +const program = getSpokePoolProgram(provider); |
| 30 | +const programId = program.programId; |
| 31 | + |
| 32 | +// Parse arguments |
| 33 | +const argv = yargs(hideBin(process.argv)) |
| 34 | + .option("input_token", { type: "string", demandOption: true, describe: "Input token address" }) |
| 35 | + .option("output_token", { type: "string", demandOption: true, describe: "Output token address" }) |
| 36 | + .option("input_amount", { type: "string", demandOption: true, describe: "Input amount" }) |
| 37 | + .option("output_amount", { type: "string", demandOption: true, describe: "Output amount" }) |
| 38 | + .option("repayment_chain_id", { type: "string", demandOption: true, describe: "Repayment chain ID" }) |
| 39 | + .option("origin_chain_id", { type: "string", demandOption: true, describe: "Origin chain ID" }) |
| 40 | + .option("deposit_id", { type: "string", demandOption: true, describe: "Deposit ID" }) |
| 41 | + .option("fill_deadline", { type: "number", demandOption: true, describe: "Fill deadline" }) |
| 42 | + .option("exclusivity_deadline", { type: "number", demandOption: true, describe: "Exclusivity deadline" }) |
| 43 | + .option("exclusive_relayer", { type: "string", demandOption: true, describe: "Exclusive relayer address" }) |
| 44 | + .option("depositor", { type: "string", demandOption: true, describe: "Depositor address" }) |
| 45 | + .option("recipient", { type: "string", demandOption: true, describe: "Recipient address" }) |
| 46 | + .option("message_hash", { type: "string", demandOption: true, describe: "Message hash" }).argv; |
| 47 | + |
| 48 | +async function findFillStatusPda() { |
| 49 | + const resolvedArgv = await argv; |
| 50 | + const relayEventData = { |
| 51 | + depositor: convertAddress(resolvedArgv.depositor), |
| 52 | + recipient: convertAddress(resolvedArgv.recipient), |
| 53 | + exclusiveRelayer: convertAddress(resolvedArgv.exclusive_relayer), |
| 54 | + inputToken: convertAddress(resolvedArgv.input_token), |
| 55 | + outputToken: convertAddress(resolvedArgv.output_token), |
| 56 | + inputAmount: new BN(resolvedArgv.input_amount), |
| 57 | + outputAmount: new BN(resolvedArgv.output_amount), |
| 58 | + originChainId: new BN(resolvedArgv.origin_chain_id), |
| 59 | + depositId: parseStringToUint8Array(resolvedArgv.deposit_id), |
| 60 | + fillDeadline: resolvedArgv.fill_deadline, |
| 61 | + exclusivityDeadline: resolvedArgv.exclusivity_deadline, |
| 62 | + messageHash: parseStringToUint8Array(resolvedArgv.message_hash), |
| 63 | + }; |
| 64 | + |
| 65 | + console.log("finding fill status pda for relay event data:"); |
| 66 | + console.table(Object.entries(relayEventData).map(([key, value]) => ({ Property: key, Value: value.toString() }))); |
| 67 | + |
| 68 | + const chainId = new BN(resolvedArgv.repayment_chain_id); |
| 69 | + const relayHashUint8Array = calculateRelayEventHashUint8Array(relayEventData, chainId); |
| 70 | + const [fillStatusPda] = PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], programId); |
| 71 | + console.log("Fill Status PDA Address:", fillStatusPda.toString()); |
| 72 | +} |
| 73 | + |
| 74 | +findFillStatusPda().catch(console.error); |
| 75 | + |
| 76 | +function convertAddress(address: string) { |
| 77 | + if (address.startsWith("0x")) return evmAddressToPublicKey(address); |
| 78 | + return new PublicKey(address); |
| 79 | +} |
| 80 | + |
| 81 | +function parseStringToUint8Array(inputString: string): Uint8Array { |
| 82 | + const numberArray = inputString.split(",").map(Number); |
| 83 | + return new Uint8Array(numberArray); |
| 84 | +} |
0 commit comments