| 
 | 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 | +}  | 
0 commit comments