-
Notifications
You must be signed in to change notification settings - Fork 58
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
feat(svm): web3 v2, codama clients, and events retrieval #866
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ebc0a98
feat(svm): add codama clients
md0x 703581e
fix: renaming
md0x 06316e6
fix: client exports
md0x e36e43d
feat(svm): web3 v2 events
md0x a105f91
feat(svm): web3 v2 events
md0x 98f5fa9
feat: delete idl
md0x 6aafec8
feat: version structure
md0x 0135718
fix: import
md0x f9216c3
feat: fixes and test script
md0x 9f09497
fix: infer types
md0x c0860cc
fix: remove 0n
md0x 312c95a
feat: remove solana web3 v1 related functions from exports
md0x 18e794c
Merge branch 'master' into pablo/events-v2
md0x 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 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 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,52 @@ | ||
// This script queries the events of the spoke pool and prints them in a human readable format. | ||
import { AnchorProvider } from "@coral-xyz/anchor"; | ||
import { address, createSolanaRpc } from "@solana/web3-v2.js"; | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { readProgramEventsV2, stringifyCpiEvent, SvmSpokeIdl } from "../../src/svm"; | ||
|
||
// Set up the provider | ||
const provider = AnchorProvider.env(); | ||
|
||
const argvPromise = yargs(hideBin(process.argv)) | ||
.option("eventName", { | ||
type: "string", | ||
demandOption: false, | ||
describe: "Name of the event to query", | ||
choices: [ | ||
"any", | ||
"FilledV3Relay", | ||
"V3FundsDeposited", | ||
"EnabledDepositRoute", | ||
"RelayedRootBundle", | ||
"ExecutedRelayerRefundRoot", | ||
"BridgedToHubPool", | ||
"PausedDeposits", | ||
"PausedFills", | ||
"SetXDomainAdmin", | ||
"EmergencyDeletedRootBundle", | ||
"RequestedV3SlowFill", | ||
"ClaimedRelayerRefund", | ||
"TokensBridged", | ||
], | ||
}) | ||
.option("programId", { | ||
type: "string", | ||
demandOption: true, | ||
describe: "SvmSpokeProgram ID to query events from", | ||
}).argv; | ||
|
||
async function queryEvents(): Promise<void> { | ||
const argv = await argvPromise; | ||
const eventName = argv.eventName || "any"; | ||
const programId = argv.programId; | ||
const rpc = createSolanaRpc(provider.connection.rpcEndpoint); | ||
const events = await readProgramEventsV2(rpc, address(programId), SvmSpokeIdl, "confirmed"); | ||
const filteredEvents = events.filter((event) => (eventName == "any" ? true : event.name == eventName)); | ||
const formattedEvents = filteredEvents.map((event) => stringifyCpiEvent(event)); | ||
|
||
console.log(JSON.stringify(formattedEvents, null, 2)); | ||
} | ||
|
||
// Run the queryEvents function | ||
queryEvents(); |
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./web3-v1"; | ||
export * from "./web3-v2"; | ||
export * from "./assets"; | ||
export * from "./clients"; |
This file contains 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 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 @@ | ||
export * from "./solanaProgramUtils"; |
This file contains 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 |
---|---|---|
|
@@ -2,37 +2,23 @@ import { BorshEventCoder, Idl, utils } from "@coral-xyz/anchor"; | |
import web3, { | ||
Address, | ||
Commitment, | ||
GetSignaturesForAddressApi, | ||
GetTransactionApi, | ||
RpcTransport, | ||
Signature, | ||
Slot, | ||
TransactionError, | ||
UnixTimestamp, | ||
} from "@solana/web3-v2.js"; | ||
|
||
type GetTransactionReturnType = ReturnType<GetTransactionApi["getTransaction"]>; | ||
|
||
type GetSignaturesForAddressConfig = Readonly<{ | ||
before?: Signature; | ||
commitment?: Exclude<Commitment, "processed">; | ||
limit?: number; | ||
minContextSlot?: Slot; | ||
until?: Signature; | ||
}>; | ||
|
||
type GetSignaturesForAddressTransaction = { | ||
blockTime: UnixTimestamp | null; | ||
confirmationStatus: Commitment | null; | ||
err: TransactionError | null; | ||
memo: string | null; | ||
signature: Signature; | ||
slot: Slot; | ||
}; | ||
type GetSignaturesForAddressConfig = Parameters<GetSignaturesForAddressApi["getSignaturesForAddress"]>[1]; | ||
|
||
type GetSignaturesForAddressTransaction = ReturnType<GetSignaturesForAddressApi["getSignaturesForAddress"]>[number]; | ||
|
||
/** | ||
* Reads all events for a specific program. | ||
*/ | ||
export async function readProgramEvents( | ||
rpc: web3.Rpc<web3.SolanaRpcApiFromTransport<any>>, | ||
export async function readProgramEventsV2( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||
rpc: web3.Rpc<web3.SolanaRpcApiFromTransport<RpcTransport>>, | ||
program: Address, | ||
anchorIdl: Idl, | ||
finality: Commitment = "confirmed", | ||
|
@@ -56,7 +42,7 @@ export async function readProgramEvents( | |
// Fetch events for all signatures in parallel | ||
const eventsWithSlots = await Promise.all( | ||
allSignatures.map(async (signatureTransaction) => { | ||
const events = await readEvents(rpc, signatureTransaction.signature, program, anchorIdl, finality); | ||
const events = await readEventsV2(rpc, signatureTransaction.signature, program, anchorIdl, finality); | ||
|
||
return events.map((event) => ({ | ||
...event, | ||
|
@@ -74,8 +60,8 @@ export async function readProgramEvents( | |
/** | ||
* Reads events from a transaction. | ||
*/ | ||
export async function readEvents( | ||
rpc: web3.Rpc<web3.SolanaRpcApiFromTransport<any>>, | ||
export async function readEventsV2( | ||
rpc: web3.Rpc<web3.SolanaRpcApiFromTransport<RpcTransport>>, | ||
txSignature: Signature, | ||
programId: Address, | ||
programIdl: Idl, | ||
|
@@ -102,7 +88,12 @@ async function processEventFromTx( | |
const [pda] = await web3.getProgramDerivedAddress({ programAddress: programId, seeds: ["__event_authority"] }); | ||
eventAuthorities.set(programId, pda); | ||
|
||
const messageAccountKeys = txResult.transaction.message.accountKeys; | ||
const accountKeys = txResult.transaction.message.accountKeys; | ||
const messageAccountKeys = [...accountKeys]; | ||
// Order matters here. writable accounts must be processed before readonly accounts. | ||
// See https://docs.anza.xyz/proposals/versioned-transactions#new-transaction-format | ||
messageAccountKeys.push(...(txResult?.meta?.loadedAddresses?.writable ?? [])); | ||
messageAccountKeys.push(...(txResult?.meta?.loadedAddresses?.readonly ?? [])); | ||
|
||
for (const ixBlock of txResult.meta?.innerInstructions ?? []) { | ||
for (const ix of ixBlock.instructions) { | ||
|
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.
why
0n
is excluded?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.
Big bad, i put that during some tests and forgot about it.
Thanks for catchinng!