Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

md0x
Copy link
Contributor

@md0x md0x commented Jan 16, 2025

Changes proposed in this PR:

  • Add @solana/web3.js v2 renamed as @solana/web3-v2.jsto support the previous version as well
  • Add codama-idl clients generation
  • Add functions to retrieve events using solana web3.js v2 and anchor decoders

Can be tested with:

anchor run queryEventsV2 --provider.cluster "XXX" -- --programId YVMQN27RnCNt23NRxzJPumXRd8iovEfKtzkqyMc5vDt --eventName ExecutedRelayerRefundRoot

md0x added 6 commits January 16, 2025 12:29
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
Copy link

socket-security bot commented Jan 16, 2025

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@solana/[email protected] None 0 167 kB lorisleiva
npm/@solana/[email protected] None 0 198 kB lorisleiva
npm/@solana/[email protected] None 0 51.4 kB lorisleiva
npm/@solana/[email protected] None 0 43.1 kB lorisleiva
npm/@solana/[email protected] None 0 33.1 kB lorisleiva
npm/@solana/[email protected] None 0 85.8 kB lorisleiva
npm/@solana/[email protected] None 0 118 kB lorisleiva
npm/@solana/[email protected] None 0 18.5 kB lorisleiva
npm/@solana/[email protected] None 0 59.6 kB lorisleiva
npm/@solana/[email protected] None 0 256 kB lorisleiva
npm/@solana/[email protected] None 0 21.9 kB lorisleiva
npm/@solana/[email protected] None 0 111 kB lorisleiva
npm/@solana/[email protected] None 0 72.1 kB lorisleiva
npm/@solana/[email protected] None 0 146 kB lorisleiva
npm/@solana/[email protected] None 0 82.5 kB lorisleiva
npm/@solana/[email protected] None 0 197 kB lorisleiva
npm/@solana/[email protected] None 0 263 kB lorisleiva
npm/@solana/[email protected] None 0 227 kB lorisleiva
npm/@solana/[email protected] environment, network 0 121 kB lorisleiva
npm/@solana/[email protected] None 0 170 kB lorisleiva
npm/@solana/[email protected] environment 0 129 kB lorisleiva
npm/@solana/[email protected] None 0 399 kB lorisleiva
npm/@solana/[email protected] environment 0 126 kB lorisleiva
npm/@solana/[email protected] None 0 340 kB lorisleiva
npm/@solana/[email protected] None 0 224 kB lorisleiva
npm/@solana/[email protected] None 0 735 kB lorisleiva
npm/@solana/[email protected] None 0 152 kB lorisleiva
npm/@solana/[email protected] None 0 0 B
npm/[email protected] None 0 83.7 kB matteo.collina

🚮 Removed packages: npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

@md0x md0x marked this pull request as ready for review January 16, 2025 15:41
@md0x md0x marked this pull request as draft January 16, 2025 15:45
Signed-off-by: Pablo Maldonado <[email protected]>
codama = createFromRoot(rootNodeFromAnchor(MulticallHandlerIdl as AnchorIdl));
codama.accept(renderJavaScriptVisitor(path.join(clientsPath, "MulticallHandler")));

// codama = createFromRoot(rootNodeFromAnchor(MessageTransmitterIdl as AnchorIdl));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending to fix.

@md0x md0x changed the title feat(svm): events solana web3 v2 feat(svm): web3 v2, Codama clients, and events retrieval Jan 16, 2025
@md0x md0x changed the title feat(svm): web3 v2, Codama clients, and events retrieval feat(svm): web3 v2, codama clients, and events retrieval Jan 16, 2025
Signed-off-by: Pablo Maldonado <[email protected]>
@md0x md0x marked this pull request as ready for review January 16, 2025 16:36
* Reads all events for a specific program.
*/
export async function readProgramEvents(
rpc: web3.Rpc<web3.SolanaRpcApiFromTransport<any>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe replace any with RpcTransport?


type GetTransactionReturnType = ReturnType<GetTransactionApi["getTransaction"]>;

type GetSignaturesForAddressConfig = Readonly<{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe can infer this type without replicating upstream:

type GetSignaturesForAddressConfig = Parameters<GetSignaturesForAddressApi["getSignaturesForAddress"]>[1]

until?: Signature;
}>;

type GetSignaturesForAddressTransaction = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe can also infer this:

type GetSignaturesForAddressTransaction = ReturnType<GetSignaturesForAddressApi["getSignaturesForAddress"]>[number];

* Reads events from a transaction.
*/
export async function readEvents(
rpc: web3.Rpc<web3.SolanaRpcApiFromTransport<any>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe replace any with RpcTransport?

const [pda] = await web3.getProgramDerivedAddress({ programAddress: programId, seeds: ["__event_authority"] });
eventAuthorities.set(programId, pda);

const messageAccountKeys = txResult.transaction.message.accountKeys;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested this with V0 transactions? does accountKeys also include loaded addresses from ALTs in web3-v2?

Copy link
Member

@chrismaree chrismaree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty cool! I agree with @Reinis-FRP that we can be stricter on the typing but overall this makes sense: there are two distinct categories of web3 providers and we want to be able to support both so splitting by directory is reasonable

/**
* Reads all events for a specific program.
*/
export async function readProgramEvents(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you test this?

md0x added 2 commits January 17, 2025 11:18
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
/**
* Reads all events for a specific program.
*/
export async function readProgramEventsV2(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to readProgramEventsV2 so they do not conflict with the v1 exports. I don't think this should be the final name as we want to prioritize V2 but for now I think it's fine until we start exposing this functions

@md0x md0x requested review from chrismaree and Reinis-FRP January 17, 2025 11:41
@@ -239,6 +239,8 @@ export function stringifyCpiEvent(obj: any): any {
return obj.toString();
} else if (BN.isBN(obj)) {
return obj.toString();
} else if (typeof obj === "bigint" && obj !== 0n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 0n is excluded?

Copy link
Contributor Author

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!

Signed-off-by: Pablo Maldonado <[email protected]>
@md0x md0x added the do not merge do not merge label Jan 17, 2025
Copy link
Contributor

@Reinis-FRP Reinis-FRP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge do not merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants