Add staking program and mesh program to xc-admin UI (#1157)

* Do it

* Small bug

* Fix CI

* Address comments
This commit is contained in:
guibescos 2023-12-04 07:37:34 +00:00 committed by GitHub
parent 21a4ec8277
commit 5de008fb92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 2002 additions and 30 deletions

View File

@ -5,7 +5,7 @@ import {
} from "@pythnetwork/client/lib/cluster"; } from "@pythnetwork/client/lib/cluster";
import { Connection, Keypair, PublicKey } from "@solana/web3.js"; import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { import {
MessageBufferMultisigInstruction, AnchorMultisigInstruction,
MESSAGE_BUFFER_PROGRAM_ID, MESSAGE_BUFFER_PROGRAM_ID,
MultisigInstructionProgram, MultisigInstructionProgram,
MultisigParser, MultisigParser,
@ -50,7 +50,7 @@ test("Message buffer multisig instruction parse: create buffer", (done) => {
.then((instruction) => { .then((instruction) => {
const parsedInstruction = parser.parseInstruction(instruction); const parsedInstruction = parser.parseInstruction(instruction);
if (parsedInstruction instanceof MessageBufferMultisigInstruction) { if (parsedInstruction instanceof AnchorMultisigInstruction) {
expect(parsedInstruction.program).toBe( expect(parsedInstruction.program).toBe(
MultisigInstructionProgram.MessageBuffer MultisigInstructionProgram.MessageBuffer
); );
@ -164,7 +164,7 @@ test("Message buffer multisig instruction parse: delete buffer", (done) => {
.then((instruction) => { .then((instruction) => {
const parsedInstruction = parser.parseInstruction(instruction); const parsedInstruction = parser.parseInstruction(instruction);
if (parsedInstruction instanceof MessageBufferMultisigInstruction) { if (parsedInstruction instanceof AnchorMultisigInstruction) {
expect(parsedInstruction.program).toBe( expect(parsedInstruction.program).toBe(
MultisigInstructionProgram.MessageBuffer MultisigInstructionProgram.MessageBuffer
); );

View File

@ -2,23 +2,36 @@ import {
MultisigInstruction, MultisigInstruction,
MultisigInstructionProgram, MultisigInstructionProgram,
UNRECOGNIZED_INSTRUCTION, UNRECOGNIZED_INSTRUCTION,
UnrecognizedProgram,
} from "."; } from ".";
import { AnchorAccounts, resolveAccountNames } from "./anchor"; import { AnchorAccounts, resolveAccountNames } from "./anchor";
import messageBuffer from "message_buffer/idl/message_buffer.json"; import messageBufferIdl from "message_buffer/idl/message_buffer.json";
import { TransactionInstruction } from "@solana/web3.js"; import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import { Idl, BorshCoder } from "@coral-xyz/anchor"; import { Idl, BorshCoder } from "@coral-xyz/anchor";
import { MESSAGE_BUFFER_PROGRAM_ID } from "../message_buffer";
import meshIdl from "@sqds/mesh/lib/mesh-idl/mesh.json";
import stakingIdl from "./idl/staking.json";
export class MessageBufferMultisigInstruction implements MultisigInstruction { export const MESH_PROGRAM_ID = new PublicKey(
readonly program = MultisigInstructionProgram.MessageBuffer; "SMPLVC8MxZ5Bf5EfF7PaMiTCxoBAcmkbM2vkrvMK8ho"
);
export const STAKING_PROGRAM_ID = new PublicKey(
"pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ"
);
export class AnchorMultisigInstruction implements MultisigInstruction {
readonly program: MultisigInstructionProgram;
readonly name: string; readonly name: string;
readonly args: { [key: string]: any }; readonly args: { [key: string]: any };
readonly accounts: AnchorAccounts; readonly accounts: AnchorAccounts;
constructor( constructor(
program: MultisigInstructionProgram,
name: string, name: string,
args: { [key: string]: any }, args: { [key: string]: any },
accounts: AnchorAccounts accounts: AnchorAccounts
) { ) {
this.program = program;
this.name = name; this.name = name;
this.args = args; this.args = args;
this.accounts = accounts; this.accounts = accounts;
@ -26,26 +39,39 @@ export class MessageBufferMultisigInstruction implements MultisigInstruction {
static fromTransactionInstruction( static fromTransactionInstruction(
instruction: TransactionInstruction instruction: TransactionInstruction
): MessageBufferMultisigInstruction { ): MultisigInstruction {
const messageBufferInstructionCoder = new BorshCoder(messageBuffer as Idl) let idl: Idl;
.instruction; let program: MultisigInstructionProgram;
switch (instruction.programId.toBase58()) {
case MESSAGE_BUFFER_PROGRAM_ID.toBase58():
idl = messageBufferIdl as Idl;
program = MultisigInstructionProgram.MessageBuffer;
break;
case MESH_PROGRAM_ID.toBase58():
idl = meshIdl as Idl;
program = MultisigInstructionProgram.Mesh;
break;
case STAKING_PROGRAM_ID.toBase58():
idl = stakingIdl as Idl;
program = MultisigInstructionProgram.Staking;
break;
default:
return UnrecognizedProgram.fromTransactionInstruction(instruction);
}
const instructionCoder = new BorshCoder(idl).instruction;
const deserializedData = messageBufferInstructionCoder.decode( const deserializedData = instructionCoder.decode(instruction.data);
instruction.data
);
if (deserializedData) { if (deserializedData) {
return new MessageBufferMultisigInstruction( return new AnchorMultisigInstruction(
program,
deserializedData.name, deserializedData.name,
deserializedData.data, deserializedData.data,
resolveAccountNames( resolveAccountNames(idl, deserializedData.name, instruction)
messageBuffer as Idl,
deserializedData.name,
instruction
)
); );
} else { } else {
return new MessageBufferMultisigInstruction( return new AnchorMultisigInstruction(
program,
UNRECOGNIZED_INSTRUCTION, UNRECOGNIZED_INSTRUCTION,
{ data: instruction.data }, { data: instruction.data },
{ named: {}, remaining: instruction.keys } { named: {}, remaining: instruction.keys }

View File

@ -10,7 +10,11 @@ import {
} from "@solana/web3.js"; } from "@solana/web3.js";
import { MESSAGE_BUFFER_PROGRAM_ID } from "../message_buffer"; import { MESSAGE_BUFFER_PROGRAM_ID } from "../message_buffer";
import { WORMHOLE_ADDRESS } from "../wormhole"; import { WORMHOLE_ADDRESS } from "../wormhole";
import { MessageBufferMultisigInstruction } from "./MessageBufferMultisigInstruction"; import {
MESH_PROGRAM_ID,
AnchorMultisigInstruction,
STAKING_PROGRAM_ID,
} from "./MessageBufferMultisigInstruction";
import { PythMultisigInstruction } from "./PythMultisigInstruction"; import { PythMultisigInstruction } from "./PythMultisigInstruction";
import { WormholeMultisigInstruction } from "./WormholeMultisigInstruction"; import { WormholeMultisigInstruction } from "./WormholeMultisigInstruction";
import { SystemProgramMultisigInstruction } from "./SystemProgramInstruction"; import { SystemProgramMultisigInstruction } from "./SystemProgramInstruction";
@ -24,6 +28,8 @@ export enum MultisigInstructionProgram {
PythOracle, PythOracle,
WormholeBridge, WormholeBridge,
MessageBuffer, MessageBuffer,
Staking,
Mesh,
SystemProgram, SystemProgram,
BpfUpgradableLoader, BpfUpgradableLoader,
SolanaStakingProgram, SolanaStakingProgram,
@ -110,10 +116,12 @@ export class MultisigParser {
); );
} else if (instruction.programId.equals(this.pythOracleAddress)) { } else if (instruction.programId.equals(this.pythOracleAddress)) {
return PythMultisigInstruction.fromTransactionInstruction(instruction); return PythMultisigInstruction.fromTransactionInstruction(instruction);
} else if (instruction.programId.equals(MESSAGE_BUFFER_PROGRAM_ID)) { } else if (
return MessageBufferMultisigInstruction.fromTransactionInstruction( instruction.programId.equals(MESSAGE_BUFFER_PROGRAM_ID) ||
instruction instruction.programId.equals(MESH_PROGRAM_ID) ||
); instruction.programId.equals(STAKING_PROGRAM_ID)
) {
return AnchorMultisigInstruction.fromTransactionInstruction(instruction);
} else if (instruction.programId.equals(SystemProgram.programId)) { } else if (instruction.programId.equals(SystemProgram.programId)) {
return SystemProgramMultisigInstruction.fromTransactionInstruction( return SystemProgramMultisigInstruction.fromTransactionInstruction(
instruction instruction
@ -134,7 +142,7 @@ export class MultisigParser {
export { WormholeMultisigInstruction } from "./WormholeMultisigInstruction"; export { WormholeMultisigInstruction } from "./WormholeMultisigInstruction";
export { PythMultisigInstruction } from "./PythMultisigInstruction"; export { PythMultisigInstruction } from "./PythMultisigInstruction";
export { MessageBufferMultisigInstruction } from "./MessageBufferMultisigInstruction"; export { AnchorMultisigInstruction } from "./MessageBufferMultisigInstruction";
export { SystemProgramMultisigInstruction } from "./SystemProgramInstruction"; export { SystemProgramMultisigInstruction } from "./SystemProgramInstruction";
export { BpfUpgradableLoaderInstruction } from "./BpfUpgradableLoaderMultisigInstruction"; export { BpfUpgradableLoaderInstruction } from "./BpfUpgradableLoaderMultisigInstruction";
export { SolanaStakingMultisigInstruction } from "./SolanaStakingMultisigInstruction"; export { SolanaStakingMultisigInstruction } from "./SolanaStakingMultisigInstruction";

View File

@ -1,6 +1,6 @@
{ {
"extends": "../../../../tsconfig.base.json", "extends": "../../../../tsconfig.base.json",
"include": ["src"], "include": ["./src/**/*.ts", "./src/**/*.json"],
"exclude": ["node_modules", "**/__tests__/*"], "exclude": ["node_modules", "**/__tests__/*"],
"compilerOptions": { "compilerOptions": {
"rootDir": "src/", "rootDir": "src/",

View File

@ -11,7 +11,7 @@ import {
MultisigInstruction, MultisigInstruction,
MultisigParser, MultisigParser,
PythMultisigInstruction, PythMultisigInstruction,
MessageBufferMultisigInstruction, AnchorMultisigInstruction,
WormholeMultisigInstruction, WormholeMultisigInstruction,
getManyProposalsInstructions, getManyProposalsInstructions,
getProgramName, getProgramName,
@ -317,8 +317,7 @@ const Proposal = ({
}) })
return ( return (
parsedRemoteInstruction instanceof PythMultisigInstruction || parsedRemoteInstruction instanceof PythMultisigInstruction ||
parsedRemoteInstruction instanceof parsedRemoteInstruction instanceof AnchorMultisigInstruction
MessageBufferMultisigInstruction
) )
}) && }) &&
ix.governanceAction.targetChainId === 'pythnet') ix.governanceAction.targetChainId === 'pythnet')