Add staking program and mesh program to xc-admin UI (#1157)
* Do it * Small bug * Fix CI * Address comments
This commit is contained in:
parent
21a4ec8277
commit
5de008fb92
|
@ -5,7 +5,7 @@ import {
|
|||
} from "@pythnetwork/client/lib/cluster";
|
||||
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
||||
import {
|
||||
MessageBufferMultisigInstruction,
|
||||
AnchorMultisigInstruction,
|
||||
MESSAGE_BUFFER_PROGRAM_ID,
|
||||
MultisigInstructionProgram,
|
||||
MultisigParser,
|
||||
|
@ -50,7 +50,7 @@ test("Message buffer multisig instruction parse: create buffer", (done) => {
|
|||
.then((instruction) => {
|
||||
const parsedInstruction = parser.parseInstruction(instruction);
|
||||
|
||||
if (parsedInstruction instanceof MessageBufferMultisigInstruction) {
|
||||
if (parsedInstruction instanceof AnchorMultisigInstruction) {
|
||||
expect(parsedInstruction.program).toBe(
|
||||
MultisigInstructionProgram.MessageBuffer
|
||||
);
|
||||
|
@ -164,7 +164,7 @@ test("Message buffer multisig instruction parse: delete buffer", (done) => {
|
|||
.then((instruction) => {
|
||||
const parsedInstruction = parser.parseInstruction(instruction);
|
||||
|
||||
if (parsedInstruction instanceof MessageBufferMultisigInstruction) {
|
||||
if (parsedInstruction instanceof AnchorMultisigInstruction) {
|
||||
expect(parsedInstruction.program).toBe(
|
||||
MultisigInstructionProgram.MessageBuffer
|
||||
);
|
||||
|
|
|
@ -2,23 +2,36 @@ import {
|
|||
MultisigInstruction,
|
||||
MultisigInstructionProgram,
|
||||
UNRECOGNIZED_INSTRUCTION,
|
||||
UnrecognizedProgram,
|
||||
} from ".";
|
||||
import { AnchorAccounts, resolveAccountNames } from "./anchor";
|
||||
import messageBuffer from "message_buffer/idl/message_buffer.json";
|
||||
import { TransactionInstruction } from "@solana/web3.js";
|
||||
import messageBufferIdl from "message_buffer/idl/message_buffer.json";
|
||||
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
||||
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 {
|
||||
readonly program = MultisigInstructionProgram.MessageBuffer;
|
||||
export const MESH_PROGRAM_ID = new PublicKey(
|
||||
"SMPLVC8MxZ5Bf5EfF7PaMiTCxoBAcmkbM2vkrvMK8ho"
|
||||
);
|
||||
export const STAKING_PROGRAM_ID = new PublicKey(
|
||||
"pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ"
|
||||
);
|
||||
|
||||
export class AnchorMultisigInstruction implements MultisigInstruction {
|
||||
readonly program: MultisigInstructionProgram;
|
||||
readonly name: string;
|
||||
readonly args: { [key: string]: any };
|
||||
readonly accounts: AnchorAccounts;
|
||||
|
||||
constructor(
|
||||
program: MultisigInstructionProgram,
|
||||
name: string,
|
||||
args: { [key: string]: any },
|
||||
accounts: AnchorAccounts
|
||||
) {
|
||||
this.program = program;
|
||||
this.name = name;
|
||||
this.args = args;
|
||||
this.accounts = accounts;
|
||||
|
@ -26,26 +39,39 @@ export class MessageBufferMultisigInstruction implements MultisigInstruction {
|
|||
|
||||
static fromTransactionInstruction(
|
||||
instruction: TransactionInstruction
|
||||
): MessageBufferMultisigInstruction {
|
||||
const messageBufferInstructionCoder = new BorshCoder(messageBuffer as Idl)
|
||||
.instruction;
|
||||
): MultisigInstruction {
|
||||
let idl: Idl;
|
||||
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(
|
||||
instruction.data
|
||||
);
|
||||
const deserializedData = instructionCoder.decode(instruction.data);
|
||||
|
||||
if (deserializedData) {
|
||||
return new MessageBufferMultisigInstruction(
|
||||
return new AnchorMultisigInstruction(
|
||||
program,
|
||||
deserializedData.name,
|
||||
deserializedData.data,
|
||||
resolveAccountNames(
|
||||
messageBuffer as Idl,
|
||||
deserializedData.name,
|
||||
instruction
|
||||
)
|
||||
resolveAccountNames(idl, deserializedData.name, instruction)
|
||||
);
|
||||
} else {
|
||||
return new MessageBufferMultisigInstruction(
|
||||
return new AnchorMultisigInstruction(
|
||||
program,
|
||||
UNRECOGNIZED_INSTRUCTION,
|
||||
{ data: instruction.data },
|
||||
{ named: {}, remaining: instruction.keys }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,7 +10,11 @@ import {
|
|||
} from "@solana/web3.js";
|
||||
import { MESSAGE_BUFFER_PROGRAM_ID } from "../message_buffer";
|
||||
import { WORMHOLE_ADDRESS } from "../wormhole";
|
||||
import { MessageBufferMultisigInstruction } from "./MessageBufferMultisigInstruction";
|
||||
import {
|
||||
MESH_PROGRAM_ID,
|
||||
AnchorMultisigInstruction,
|
||||
STAKING_PROGRAM_ID,
|
||||
} from "./MessageBufferMultisigInstruction";
|
||||
import { PythMultisigInstruction } from "./PythMultisigInstruction";
|
||||
import { WormholeMultisigInstruction } from "./WormholeMultisigInstruction";
|
||||
import { SystemProgramMultisigInstruction } from "./SystemProgramInstruction";
|
||||
|
@ -24,6 +28,8 @@ export enum MultisigInstructionProgram {
|
|||
PythOracle,
|
||||
WormholeBridge,
|
||||
MessageBuffer,
|
||||
Staking,
|
||||
Mesh,
|
||||
SystemProgram,
|
||||
BpfUpgradableLoader,
|
||||
SolanaStakingProgram,
|
||||
|
@ -110,10 +116,12 @@ export class MultisigParser {
|
|||
);
|
||||
} else if (instruction.programId.equals(this.pythOracleAddress)) {
|
||||
return PythMultisigInstruction.fromTransactionInstruction(instruction);
|
||||
} else if (instruction.programId.equals(MESSAGE_BUFFER_PROGRAM_ID)) {
|
||||
return MessageBufferMultisigInstruction.fromTransactionInstruction(
|
||||
instruction
|
||||
);
|
||||
} else if (
|
||||
instruction.programId.equals(MESSAGE_BUFFER_PROGRAM_ID) ||
|
||||
instruction.programId.equals(MESH_PROGRAM_ID) ||
|
||||
instruction.programId.equals(STAKING_PROGRAM_ID)
|
||||
) {
|
||||
return AnchorMultisigInstruction.fromTransactionInstruction(instruction);
|
||||
} else if (instruction.programId.equals(SystemProgram.programId)) {
|
||||
return SystemProgramMultisigInstruction.fromTransactionInstruction(
|
||||
instruction
|
||||
|
@ -134,7 +142,7 @@ export class MultisigParser {
|
|||
|
||||
export { WormholeMultisigInstruction } from "./WormholeMultisigInstruction";
|
||||
export { PythMultisigInstruction } from "./PythMultisigInstruction";
|
||||
export { MessageBufferMultisigInstruction } from "./MessageBufferMultisigInstruction";
|
||||
export { AnchorMultisigInstruction } from "./MessageBufferMultisigInstruction";
|
||||
export { SystemProgramMultisigInstruction } from "./SystemProgramInstruction";
|
||||
export { BpfUpgradableLoaderInstruction } from "./BpfUpgradableLoaderMultisigInstruction";
|
||||
export { SolanaStakingMultisigInstruction } from "./SolanaStakingMultisigInstruction";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"extends": "../../../../tsconfig.base.json",
|
||||
"include": ["src"],
|
||||
"include": ["./src/**/*.ts", "./src/**/*.json"],
|
||||
"exclude": ["node_modules", "**/__tests__/*"],
|
||||
"compilerOptions": {
|
||||
"rootDir": "src/",
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
MultisigInstruction,
|
||||
MultisigParser,
|
||||
PythMultisigInstruction,
|
||||
MessageBufferMultisigInstruction,
|
||||
AnchorMultisigInstruction,
|
||||
WormholeMultisigInstruction,
|
||||
getManyProposalsInstructions,
|
||||
getProgramName,
|
||||
|
@ -317,8 +317,7 @@ const Proposal = ({
|
|||
})
|
||||
return (
|
||||
parsedRemoteInstruction instanceof PythMultisigInstruction ||
|
||||
parsedRemoteInstruction instanceof
|
||||
MessageBufferMultisigInstruction
|
||||
parsedRemoteInstruction instanceof AnchorMultisigInstruction
|
||||
)
|
||||
}) &&
|
||||
ix.governanceAction.targetChainId === 'pythnet')
|
||||
|
|
Loading…
Reference in New Issue