-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebridge-parser.ts
More file actions
64 lines (54 loc) · 1.88 KB
/
debridge-parser.ts
File metadata and controls
64 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Example: Using solana-idls with @debridge-finance/solana-transaction-parser
*
* This example shows clean, type-safe integration with the debridge parser.
* No type casting needed - IDLs are properly typed as Idl from @coral-xyz/anchor.
*/
import { Connection } from "@solana/web3.js";
import {
SolanaParser,
convertLegacyIdlToV30,
} from "@debridge-finance/solana-transaction-parser";
import {
JUPITER_IDL,
JUPITER_PROGRAM_ID,
ORCA_WHIRLPOOLS_IDL,
ORCA_WHIRLPOOLS_PROGRAM_ID,
} from "solana-idls";
// Initialize parser with IDLs - fully type-safe!
const parser = new SolanaParser([
{
idl: convertLegacyIdlToV30(JUPITER_IDL, JUPITER_PROGRAM_ID),
programId: JUPITER_PROGRAM_ID,
},
{
idl: convertLegacyIdlToV30(ORCA_WHIRLPOOLS_IDL, ORCA_WHIRLPOOLS_PROGRAM_ID),
programId: ORCA_WHIRLPOOLS_PROGRAM_ID,
},
]);
const connection = new Connection("https://api.mainnet-beta.solana.com");
// Example Jupiter swap transaction
const signature =
"4ZidatPKRyKPYHaEG9gLMBWu7pWPYpV42SSD5hEpEA3GUXPcph8o9Gdu3SYjRuzFC6cCK43GziuK2rJkMPVPac1";
async function main() {
const parsed = await parser.parseTransactionByHash(connection, signature);
if (!parsed) {
console.log("Transaction not found");
return;
}
console.log(`\nParsed ${parsed.length} instructions:\n`);
parsed.forEach((ix, i) => {
console.log(
`${i + 1}. ${ix.name.padEnd(32)} ${ix.programId.toString().slice(0, 12)}...`
);
});
// Show Jupiter route details
// Note: Even with typed IDLs, parser returns generic types
const jupiterRoute = parsed.find((ix) => ix.name === "route");
if (jupiterRoute && "args" in jupiterRoute) {
// Cast to specific shape for field name checking (better than 'as any')
const args = jupiterRoute.args as { route_plan: unknown[] };
console.log(`\nJupiter route: ${args.route_plan.length} swap step(s)`);
}
}
main().catch(console.error);