-
Notifications
You must be signed in to change notification settings - Fork 75
feat: show how to find fill status Events and fill status by querying fill StatusPDA #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a39289a
WIP
chrismaree 133c982
WIP
chrismaree ef7a461
Discard changes to scripts/svm/closeRelayerPdas.ts
chrismaree 4aa1cfb
WIP
chrismaree 548c45a
WIP
chrismaree d0bb003
WIP
chrismaree 7072835
WIP
chrismaree 62b17c2
WIP
chrismaree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // This script finds the fillStatus (fillStatus + event) from a provided fillStatusPda. | ||
| import * as anchor from "@coral-xyz/anchor"; | ||
| import { AnchorProvider, BN, Program } from "@coral-xyz/anchor"; | ||
| import { address, createSolanaRpc } from "@solana/web3-v2.js"; | ||
| import yargs from "yargs"; | ||
| import { hideBin } from "yargs/helpers"; | ||
| import { SvmSpokeIdl } from "../../src/svm"; | ||
|
|
||
| import { readFillEventFromFillStatusPda } from "../../src/svm/web3-v2/solanaProgramUtils"; | ||
| import { program } from "@coral-xyz/anchor/dist/cjs/native/system"; | ||
| import { SvmSpoke } from "../../target/types/svm_spoke"; | ||
|
|
||
| // Set up the provider | ||
| const provider = AnchorProvider.env(); | ||
| anchor.setProvider(provider); | ||
|
|
||
| const argv = yargs(hideBin(process.argv)) | ||
| .option("fillStatusPda", { type: "string", demandOption: true, describe: "Fill Status PDA" }) | ||
| .option("programId", { type: "string", demandOption: true, describe: "SvmSpoke ID" }).argv; | ||
|
|
||
| async function findFillStatusFromFillStatusPda(): Promise<void> { | ||
| const resolvedArgv = await argv; | ||
| const fillStatusPda = address(resolvedArgv.fillStatusPda); | ||
|
|
||
| console.log(`Looking for Fill Event for Fill Status PDA: ${fillStatusPda.toString()}`); | ||
|
|
||
| const rpc = createSolanaRpc(provider.connection.rpcEndpoint); | ||
| const { event, slot } = await readFillEventFromFillStatusPda( | ||
| rpc, | ||
| fillStatusPda, | ||
| address(resolvedArgv.programId), | ||
| SvmSpokeIdl | ||
| ); | ||
| if (!event) { | ||
| console.log("No fill events found"); | ||
| return; | ||
| } | ||
|
|
||
| console.table( | ||
| Object.entries(event.data).map(([key, value]) => { | ||
| if (key === "relay_execution_info") { | ||
| const info = value as any; | ||
| return { Property: key, Value: `relayer: ${info.relayer}, executionTimestamp: ${info.executionTimestamp}` }; | ||
| } | ||
| return { Property: key, Value: (value as any).toString() }; | ||
| }) | ||
| ); | ||
|
|
||
| const program = anchor.workspace.SvmSpoke as Program<SvmSpoke>; | ||
| let fillStatus; | ||
| try { | ||
| const fillStatusResponse = await program.account.fillStatusAccount.fetch(fillStatusPda); | ||
| fillStatus = Object.keys(fillStatusResponse.status)[0]; | ||
| } catch (error) { | ||
| fillStatus = "filled"; | ||
| } | ||
|
|
||
| console.log("fillStatus", fillStatus); | ||
| console.log("slot", slot); | ||
| } | ||
|
|
||
| findFillStatusFromFillStatusPda(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // This script finds the associated Fill Status PDA from a fill OR deposit event by re-deriving it without doing any | ||
| // // on-chain calls. Note the props required are present in both deposit and fill events. | ||
| // Example usage: | ||
| // anchor run findFillStatusPdaFromFill -- \ | ||
| // --input_token "0x1c7d4b196cb0c7b01d743fbc6116a902379c7238" \ | ||
| // --output_token "wBeYLVBabtv4cyb7RyMmRxvRSkRsCP4PMBCJRw66kKC" \ | ||
| // --input_amount "1" \ | ||
| // --output_amount "1" \ | ||
| // --repayment_chain_id "133268194659241" \ | ||
| // --origin_chain_id "11155111" \ | ||
| // --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" \ | ||
| // --fill_deadline 1740569770 \ | ||
| // --exclusivity_deadline 1740569740 \ | ||
| // --exclusive_relayer "0x0000000000000000000000000000000000000000" \ | ||
| // --depositor "0x9a8f92a830a5cb89a3816e3d267cb7791c16b04d" \ | ||
| // --recipient "5HRmK3G6BzWAtF22dBgoTiPGVovSmG4rLvVQoUhum9FJ" \ | ||
| // --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" | ||
|
|
||
| import * as anchor from "@coral-xyz/anchor"; | ||
| import { PublicKey } from "@solana/web3.js"; | ||
| import { BN } from "@coral-xyz/anchor"; | ||
| import yargs from "yargs"; | ||
| import { hideBin } from "yargs/helpers"; | ||
| import { calculateRelayEventHashUint8Array, getSpokePoolProgram, evmAddressToPublicKey } from "../../src/svm/web3-v1"; | ||
|
|
||
| // Set up the provider | ||
| const provider = anchor.AnchorProvider.env(); | ||
| anchor.setProvider(provider); | ||
| const program = getSpokePoolProgram(provider); | ||
| const programId = program.programId; | ||
|
|
||
| // Parse arguments | ||
| const argv = yargs(hideBin(process.argv)) | ||
| .option("input_token", { type: "string", demandOption: true, describe: "Input token address" }) | ||
| .option("output_token", { type: "string", demandOption: true, describe: "Output token address" }) | ||
| .option("input_amount", { type: "string", demandOption: true, describe: "Input amount" }) | ||
| .option("output_amount", { type: "string", demandOption: true, describe: "Output amount" }) | ||
| .option("repayment_chain_id", { type: "string", demandOption: true, describe: "Repayment chain ID" }) | ||
| .option("origin_chain_id", { type: "string", demandOption: true, describe: "Origin chain ID" }) | ||
| .option("deposit_id", { type: "string", demandOption: true, describe: "Deposit ID" }) | ||
| .option("fill_deadline", { type: "number", demandOption: true, describe: "Fill deadline" }) | ||
| .option("exclusivity_deadline", { type: "number", demandOption: true, describe: "Exclusivity deadline" }) | ||
| .option("exclusive_relayer", { type: "string", demandOption: true, describe: "Exclusive relayer address" }) | ||
| .option("depositor", { type: "string", demandOption: true, describe: "Depositor address" }) | ||
| .option("recipient", { type: "string", demandOption: true, describe: "Recipient address" }) | ||
| .option("message_hash", { type: "string", demandOption: true, describe: "Message hash" }).argv; | ||
|
|
||
| async function findFillStatusPda() { | ||
| const resolvedArgv = await argv; | ||
| const relayEventData = { | ||
| depositor: convertAddress(resolvedArgv.depositor), | ||
| recipient: convertAddress(resolvedArgv.recipient), | ||
| exclusiveRelayer: convertAddress(resolvedArgv.exclusive_relayer), | ||
| inputToken: convertAddress(resolvedArgv.input_token), | ||
| outputToken: convertAddress(resolvedArgv.output_token), | ||
| inputAmount: new BN(resolvedArgv.input_amount), | ||
| outputAmount: new BN(resolvedArgv.output_amount), | ||
| originChainId: new BN(resolvedArgv.origin_chain_id), | ||
| depositId: parseStringToUint8Array(resolvedArgv.deposit_id), | ||
| fillDeadline: resolvedArgv.fill_deadline, | ||
| exclusivityDeadline: resolvedArgv.exclusivity_deadline, | ||
| messageHash: parseStringToUint8Array(resolvedArgv.message_hash), | ||
| }; | ||
|
|
||
| console.log("finding fill status pda for relay event data:"); | ||
| console.table(Object.entries(relayEventData).map(([key, value]) => ({ Property: key, Value: value.toString() }))); | ||
|
|
||
| const chainId = new BN(resolvedArgv.repayment_chain_id); | ||
| const relayHashUint8Array = calculateRelayEventHashUint8Array(relayEventData, chainId); | ||
| const [fillStatusPda] = PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], programId); | ||
| console.log("Fill Status PDA Address:", fillStatusPda.toString()); | ||
| } | ||
|
|
||
| findFillStatusPda().catch(console.error); | ||
|
|
||
| function convertAddress(address: string) { | ||
| if (address.startsWith("0x")) return evmAddressToPublicKey(address); | ||
| return new PublicKey(address); | ||
| } | ||
|
|
||
| function parseStringToUint8Array(inputString: string): Uint8Array { | ||
| const numberArray = inputString.split(",").map(Number); | ||
| return new Uint8Array(numberArray); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this only work on certain "archive"-ish rpc's?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this syntax as it's from web3-v2 (now just known as
kit) which is what the bots will be using. it's meant to be illustrative for how those clients can injest this data.