Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
MultisigInstruction,
MultisigInstructionProgram,
UNRECOGNIZED_INSTRUCTION,
} from "./index";
import { AnchorAccounts, resolveAccountNames } from "./anchor";
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import { Idl, BorshInstructionCoder } from "@coral-xyz/anchor";
import lazerIdl from "./idl/lazer.json";

export const LAZER_PROGRAM_ID = new PublicKey(
"pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt"
);

export class LazerMultisigInstruction implements MultisigInstruction {
readonly program = MultisigInstructionProgram.Lazer;
readonly name: string;
readonly args: { [key: string]: any };
readonly accounts: AnchorAccounts;

constructor(
name: string,
args: { [key: string]: any },
accounts: AnchorAccounts
) {
this.name = name;
this.args = args;
this.accounts = accounts;
}

static fromInstruction(
instruction: TransactionInstruction
): LazerMultisigInstruction {
// 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
const idl = {
version: lazerIdl.metadata.version,
name: lazerIdl.metadata.name,
instructions: lazerIdl.instructions.map((ix) => ({
...ix,
accounts: ix.accounts.map((acc) => ({
name: acc.name,
isMut: acc.writable ?? false,
isSigner: acc.signer ?? false,
})),
})),
} as Idl;

const coder = new BorshInstructionCoder(idl);

const deserializedData = coder.decode(instruction.data);

if (deserializedData) {
return new LazerMultisigInstruction(
deserializedData.name,
deserializedData.data,
resolveAccountNames(idl, deserializedData.name, instruction)
);
} else {
return new LazerMultisigInstruction(
UNRECOGNIZED_INSTRUCTION,
{ data: instruction.data },
{ named: {}, remaining: instruction.keys }
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
{
"address": "",
"metadata": {
"name": "pyth_lazer_solana_contract",
"version": "0.2.0",
"spec": "0.1.0",
"description": "Pyth Lazer Solana contract and SDK.",
"repository": "https://github.com/pyth-network/pyth-crosschain"
},
"instructions": [
{
"name": "initialize",
"discriminator": [175, 175, 109, 31, 13, 152, 155, 237],
"accounts": [
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "storage",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [115, 116, 111, 114, 97, 103, 101]
}
]
}
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": [
{
"name": "top_authority",
"type": "pubkey"
},
{
"name": "treasury",
"type": "pubkey"
}
]
},
{
"name": "migrate_from_0_1_0",
"discriminator": [25, 185, 91, 207, 130, 36, 0, 255],
"accounts": [
{
"name": "top_authority",
"signer": true
},
{
"name": "storage",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [115, 116, 111, 114, 97, 103, 101]
}
]
}
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": [
{
"name": "treasury",
"type": "pubkey"
}
]
},
{
"name": "update",
"discriminator": [219, 200, 88, 176, 158, 63, 253, 127],
"accounts": [
{
"name": "top_authority",
"signer": true,
"relations": ["storage"]
},
{
"name": "storage",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [115, 116, 111, 114, 97, 103, 101]
}
]
}
}
],
"args": [
{
"name": "trusted_signer",
"type": "pubkey"
},
{
"name": "expires_at",
"type": "i64"
}
]
},
{
"name": "verify_message",
"docs": [
"Verifies a ed25519 signature on Solana by checking that the transaction contains",
"a correct call to the built-in `ed25519_program`.",
"",
"- `message_data` is the signed message that is being verified.",
"- `ed25519_instruction_index` is the index of the `ed25519_program` instruction",
"within the transaction. This instruction must precede the current instruction.",
"- `signature_index` is the index of the signature within the inputs to the `ed25519_program`.",
"- `message_offset` is the offset of the signed message within the",
"input data for the current instruction."
],
"discriminator": [180, 193, 120, 55, 189, 135, 203, 83],
"accounts": [
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "storage",
"pda": {
"seeds": [
{
"kind": "const",
"value": [115, 116, 111, 114, 97, 103, 101]
}
]
}
},
{
"name": "treasury",
"relations": ["storage"]
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
},
{
"name": "instructions_sysvar",
"docs": [
"(e.g. in `sysvar::instructions::load_instruction_at_checked`).",
"This account is not usable with anchor's `Program` account type because it's not executable."
]
}
],
"args": [
{
"name": "message_data",
"type": "bytes"
},
{
"name": "ed25519_instruction_index",
"type": "u16"
},
{
"name": "signature_index",
"type": "u8"
},
{
"name": "message_offset",
"type": "u16"
}
],
"returns": {
"defined": {
"name": "VerifiedMessage"
}
}
}
],
"accounts": [
{
"name": "Storage",
"discriminator": [209, 117, 255, 185, 196, 175, 68, 9]
}
],
"types": [
{
"name": "Storage",
"type": {
"kind": "struct",
"fields": [
{
"name": "top_authority",
"type": "pubkey"
},
{
"name": "treasury",
"type": "pubkey"
},
{
"name": "single_update_fee_in_lamports",
"type": "u64"
},
{
"name": "num_trusted_signers",
"type": "u8"
},
{
"name": "trusted_signers",
"type": {
"array": [
{
"defined": {
"name": "TrustedSignerInfo"
}
},
5
]
}
},
{
"name": "_extra_space",
"type": {
"array": ["u8", 100]
}
}
]
}
},
{
"name": "TrustedSignerInfo",
"type": {
"kind": "struct",
"fields": [
{
"name": "pubkey",
"type": "pubkey"
},
{
"name": "expires_at",
"type": "i64"
}
]
}
},
{
"name": "VerifiedMessage",
"docs": ["A message with a verified ed25519 signature."],
"type": {
"kind": "struct",
"fields": [
{
"name": "public_key",
"docs": ["Public key that signed the message."],
"type": "pubkey"
},
{
"name": "payload",
"docs": ["Signed message payload."],
"type": "bytes"
}
]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import {
PRICE_STORE_PROGRAM_ID,
PriceStoreMultisigInstruction,
} from "../price_store";
import {
LazerMultisigInstruction,
LAZER_PROGRAM_ID,
} from "./LazerMultisigInstruction";

export const UNRECOGNIZED_INSTRUCTION = "unrecognizedInstruction";
export enum MultisigInstructionProgram {
Expand All @@ -41,6 +45,7 @@ export enum MultisigInstructionProgram {
SolanaReceiver,
UnrecognizedProgram,
PythPriceStore,
Lazer,
}

export function getProgramName(program: MultisigInstructionProgram) {
Expand All @@ -67,6 +72,8 @@ export function getProgramName(program: MultisigInstructionProgram) {
return "Pyth Price Store";
case MultisigInstructionProgram.UnrecognizedProgram:
return "Unknown";
case MultisigInstructionProgram.Lazer:
return "Lazer";
}
}

Expand Down Expand Up @@ -161,6 +168,8 @@ export class MultisigParser {
return SolanaStakingMultisigInstruction.fromTransactionInstruction(
instruction
);
} else if (instruction.programId.equals(LAZER_PROGRAM_ID)) {
return LazerMultisigInstruction.fromInstruction(instruction);
} else {
return UnrecognizedProgram.fromTransactionInstruction(instruction);
}
Expand Down
Loading