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

fix: svm ts issues #627

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Test evm-hardhat
shell: bash
run: yarn test-evm
- name: Test svm-anchor
- name: Test svm
shell: bash
run: yarn test-svm
forge:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@across-protocol/constants": "^3.1.15",
"@coral-xyz/anchor": "^0.30.0",
"@coral-xyz/anchor": "^0.30.1",
"@defi-wonderland/smock": "^2.3.4",
"@eth-optimism/contracts": "^0.5.40",
"@ethersproject/abstract-provider": "5.7.0",
Expand Down
24 changes: 12 additions & 12 deletions src/SvmUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Program } from "@coral-xyz/anchor";
import { ethers } from "ethers";
import { PublicKey, Connection, Finality, SignaturesForAddressOptions, Logs } from "@solana/web3.js";

export function findProgramAddress(label: string, program: PublicKey, extraSeeds = null) {
const seeds = [Buffer.from(anchor.utils.bytes.utf8.encode(label))];
export function findProgramAddress(label: string, program: PublicKey, extraSeeds?: string[]) {
const seeds: Buffer[] = [Buffer.from(anchor.utils.bytes.utf8.encode(label))];
if (extraSeeds) {
for (const extraSeed of extraSeeds) {
if (typeof extraSeed === "string") {
Expand All @@ -15,7 +15,7 @@ export function findProgramAddress(label: string, program: PublicKey, extraSeeds
} else if (Buffer.isBuffer(extraSeed)) {
seeds.push(extraSeed);
} else {
seeds.push(extraSeed.toBuffer());
seeds.push((extraSeed as any).toBuffer());
}
}
}
Expand All @@ -26,7 +26,7 @@ export function findProgramAddress(label: string, program: PublicKey, extraSeeds
export async function readEvents(
connection: Connection,
txSignature: string,
programs,
programs: Program<any>[],
commitment: Finality = "confirmed"
) {
const txResult = await connection.getTransaction(txSignature, {
Expand All @@ -38,16 +38,16 @@ export async function readEvents(
for (const program of programs) {
eventAuthorities.set(
program.programId.toString(),
findProgramAddress("__event_authority", program.programId, null).publicKey.toString()
findProgramAddress("__event_authority", program.programId).publicKey.toString()
);
}

let events = [];
let events: any[] = [];

// TODO: Add support for version 0 transactions.
if (txResult.transaction.message.version !== "legacy") return events;
if (!txResult || txResult.transaction.message.version !== "legacy") return events;

for (const ixBlock of txResult.meta.innerInstructions) {
for (const ixBlock of txResult.meta?.innerInstructions ?? []) {
for (const ix of ixBlock.instructions) {
for (const program of programs) {
const programStr = program.programId.toString();
Expand All @@ -62,8 +62,8 @@ export async function readEvents(
const event = program.coder.events.decode(eventData);
events.push({
program: program.programId,
data: event.data,
name: event.name,
data: event?.data,
name: event?.name,
});
}
}
Expand All @@ -73,7 +73,7 @@ export async function readEvents(
return events;
}

export function getEvent(events, program: PublicKey, eventName: string) {
export function getEvent(events: any[], program: PublicKey, eventName: string) {
for (const event of events) {
if (event.name === eventName && program.toString() === event.program.toString()) {
return event.data;
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function subscribeToCpiEventsForProgram(
callback: (events: any[]) => void
) {
const subscriptionId = connection.onLogs(
new PublicKey(findProgramAddress("__event_authority", program.programId, null).publicKey.toString()),
new PublicKey(findProgramAddress("__event_authority", program.programId).publicKey.toString()),
async (logs: Logs) => {
callback(await readEvents(connection, logs.signature, [program], "confirmed"));
},
Expand Down
Loading
Loading