Skip to content

Commit 405c42a

Browse files
committed
feat: add support for deserializing lazer instructions in xc-admin
1 parent 2faddf9 commit 405c42a

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
MultisigInstruction,
3+
MultisigInstructionProgram,
4+
UNRECOGNIZED_INSTRUCTION,
5+
} from "./index";
6+
import { AnchorAccounts, resolveAccountNames } from "./anchor";
7+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
8+
import { Idl, BorshInstructionCoder } from "@coral-xyz/anchor";
9+
import * as pythLazerSolanaContractIdl from "../../../../../../lazer/contracts/solana/target/idl/pyth_lazer_solana_contract.json";
10+
11+
export const LAZER_PROGRAM_ID = new PublicKey(
12+
"pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt"
13+
);
14+
15+
export class LazerMultisigInstruction implements MultisigInstruction {
16+
readonly program = MultisigInstructionProgram.Lazer;
17+
readonly name: string;
18+
readonly args: { [key: string]: any };
19+
readonly accounts: AnchorAccounts;
20+
21+
constructor(
22+
name: string,
23+
args: { [key: string]: any },
24+
accounts: AnchorAccounts
25+
) {
26+
this.name = name;
27+
this.args = args;
28+
this.accounts = accounts;
29+
}
30+
31+
static fromInstruction(
32+
instruction: TransactionInstruction
33+
): LazerMultisigInstruction {
34+
// TODO: This is a hack to transform the IDL to be compatible with the anchor version we are using, we can't upgrade anchor to 0.30.1 because then the existing idls will break
35+
const idl = {
36+
version: pythLazerSolanaContractIdl.metadata.version,
37+
name: pythLazerSolanaContractIdl.metadata.name,
38+
instructions: pythLazerSolanaContractIdl.instructions.map((ix) => ({
39+
...ix,
40+
accounts: ix.accounts.map((acc) => ({
41+
name: acc.name,
42+
isMut: acc.writable ?? false,
43+
isSigner: acc.signer ?? false,
44+
})),
45+
})),
46+
} as Idl;
47+
48+
const coder = new BorshInstructionCoder(idl);
49+
50+
const deserializedData = coder.decode(instruction.data);
51+
52+
if (deserializedData) {
53+
return new LazerMultisigInstruction(
54+
deserializedData.name,
55+
deserializedData.data,
56+
resolveAccountNames(idl, deserializedData.name, instruction)
57+
);
58+
} else {
59+
return new LazerMultisigInstruction(
60+
UNRECOGNIZED_INSTRUCTION,
61+
{ data: instruction.data },
62+
{ named: {}, remaining: instruction.keys }
63+
);
64+
}
65+
}
66+
}

governance/xc_admin/packages/xc_admin_common/src/multisig_transaction/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import {
2727
PRICE_STORE_PROGRAM_ID,
2828
PriceStoreMultisigInstruction,
2929
} from "../price_store";
30+
import {
31+
LazerMultisigInstruction,
32+
LAZER_PROGRAM_ID,
33+
} from "./LazerMultisigInstruction";
3034

3135
export const UNRECOGNIZED_INSTRUCTION = "unrecognizedInstruction";
3236
export enum MultisigInstructionProgram {
@@ -41,6 +45,7 @@ export enum MultisigInstructionProgram {
4145
SolanaReceiver,
4246
UnrecognizedProgram,
4347
PythPriceStore,
48+
Lazer,
4449
}
4550

4651
export function getProgramName(program: MultisigInstructionProgram) {
@@ -67,6 +72,8 @@ export function getProgramName(program: MultisigInstructionProgram) {
6772
return "Pyth Price Store";
6873
case MultisigInstructionProgram.UnrecognizedProgram:
6974
return "Unknown";
75+
case MultisigInstructionProgram.Lazer:
76+
return "Lazer";
7077
}
7178
}
7279

@@ -161,6 +168,8 @@ export class MultisigParser {
161168
return SolanaStakingMultisigInstruction.fromTransactionInstruction(
162169
instruction
163170
);
171+
} else if (instruction.programId.equals(LAZER_PROGRAM_ID)) {
172+
return LazerMultisigInstruction.fromInstruction(instruction);
164173
} else {
165174
return UnrecognizedProgram.fromTransactionInstruction(instruction);
166175
}

0 commit comments

Comments
 (0)