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 13 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 <pablo@umaproject.org>
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
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/accounts@2.0.0 None 0 167 kB lorisleiva
npm/@solana/addresses@2.0.0 None 0 198 kB lorisleiva
npm/@solana/assertions@2.0.0 None 0 51.4 kB lorisleiva
npm/@solana/fast-stable-stringify@2.0.0 None 0 43.1 kB lorisleiva
npm/@solana/functional@2.0.0 None 0 33.1 kB lorisleiva
npm/@solana/instructions@2.0.0 None 0 85.8 kB lorisleiva
npm/@solana/keys@2.0.0 None 0 118 kB lorisleiva
npm/@solana/programs@2.0.0 None 0 18.5 kB lorisleiva
npm/@solana/promises@2.0.0 None 0 59.6 kB lorisleiva
npm/@solana/rpc-api@2.0.0 None 0 256 kB lorisleiva
npm/@solana/rpc-parsed-types@2.0.0 None 0 21.9 kB lorisleiva
npm/@solana/rpc-spec-types@2.0.0 None 0 111 kB lorisleiva
npm/@solana/rpc-spec@2.0.0 None 0 72.1 kB lorisleiva
npm/@solana/rpc-subscriptions-api@2.0.0 None 0 146 kB lorisleiva
npm/@solana/rpc-subscriptions-channel-websocket@2.0.0 None 0 82.5 kB lorisleiva
npm/@solana/rpc-subscriptions-spec@2.0.0 None 0 197 kB lorisleiva
npm/@solana/rpc-subscriptions@2.0.0 None 0 263 kB lorisleiva
npm/@solana/rpc-transformers@2.0.0 None 0 227 kB lorisleiva
npm/@solana/rpc-transport-http@2.0.0 environment, network 0 121 kB lorisleiva
npm/@solana/rpc-types@2.0.0 None 0 170 kB lorisleiva
npm/@solana/rpc@2.0.0 environment 0 129 kB lorisleiva
npm/@solana/signers@2.0.0 None 0 399 kB lorisleiva
npm/@solana/subscribable@2.0.0 environment 0 126 kB lorisleiva
npm/@solana/sysvars@2.0.0 None 0 340 kB lorisleiva
npm/@solana/transaction-confirmation@2.0.0 None 0 224 kB lorisleiva
npm/@solana/transaction-messages@2.0.0 None 0 735 kB lorisleiva
npm/@solana/transactions@2.0.0 None 0 152 kB lorisleiva
npm/@solana/web3-v2.js@2.0.0 None 0 0 B
npm/undici-types@6.21.0 None 0 83.7 kB matteo.collina

🚮 Removed packages: npm/any-signal@2.1.2, npm/color@3.2.1, npm/crypto-browserify@3.12.0, npm/eth-lib@0.1.29, npm/get-stream@4.1.0, npm/ipfs-core-types@0.3.1, npm/ipfs-core-utils@0.7.2, npm/ipfs-utils@6.0.8, npm/ipld-block@0.11.1, npm/ipld-dag-cbor@0.17.1, npm/ipld-dag-pb@0.20.0, npm/ipld-raw@6.0.0, npm/it-last@1.0.6, npm/it-map@1.0.6, npm/it-tar@1.2.2, npm/it-to-stream@0.1.2, npm/merge-options@3.0.4, npm/mkdirp-promise@5.0.1, npm/mock-fs@4.14.0, npm/multiaddr@8.1.2, npm/native-abort-controller@1.0.4, npm/p-cancelable@1.1.0, npm/tar@4.4.19, npm/text-hex@1.0.0, npm/to-readable-stream@1.0.0, npm/url-parse-lax@3.0.0, npm/util@0.12.4, npm/web3-providers-http@1.7.0, npm/web3-providers-ipc@1.7.0, npm/web3-providers-ws@1.7.0, npm/xhr-request@1.1.0

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 <pablo@umaproject.org>
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 <pablo@umaproject.org>
@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 <pablo@umaproject.org>
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
/**
* 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 <pablo@umaproject.org>
@md0x md0x added the do not merge do not merge label Jan 17, 2025
Reinis-FRP
Reinis-FRP previously approved these changes 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!

@md0x md0x marked this pull request as draft January 23, 2025 16:12
@md0x md0x marked this pull request as ready for review January 24, 2025 12:40
@md0x md0x requested a review from Reinis-FRP January 24, 2025 13:09
@md0x md0x removed the do not merge do not merge label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants