Skip to content

Commit 5de008f

Browse files
authored
Add staking program and mesh program to xc-admin UI (#1157)
* Do it * Small bug * Fix CI * Address comments
1 parent 21a4ec8 commit 5de008f

File tree

6 files changed

+2002
-30
lines changed

6 files changed

+2002
-30
lines changed

governance/xc_admin/packages/xc_admin_common/src/__tests__/MessageBufferMultisigInstruction.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "@pythnetwork/client/lib/cluster";
66
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
77
import {
8-
MessageBufferMultisigInstruction,
8+
AnchorMultisigInstruction,
99
MESSAGE_BUFFER_PROGRAM_ID,
1010
MultisigInstructionProgram,
1111
MultisigParser,
@@ -50,7 +50,7 @@ test("Message buffer multisig instruction parse: create buffer", (done) => {
5050
.then((instruction) => {
5151
const parsedInstruction = parser.parseInstruction(instruction);
5252

53-
if (parsedInstruction instanceof MessageBufferMultisigInstruction) {
53+
if (parsedInstruction instanceof AnchorMultisigInstruction) {
5454
expect(parsedInstruction.program).toBe(
5555
MultisigInstructionProgram.MessageBuffer
5656
);
@@ -164,7 +164,7 @@ test("Message buffer multisig instruction parse: delete buffer", (done) => {
164164
.then((instruction) => {
165165
const parsedInstruction = parser.parseInstruction(instruction);
166166

167-
if (parsedInstruction instanceof MessageBufferMultisigInstruction) {
167+
if (parsedInstruction instanceof AnchorMultisigInstruction) {
168168
expect(parsedInstruction.program).toBe(
169169
MultisigInstructionProgram.MessageBuffer
170170
);

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

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,76 @@ import {
22
MultisigInstruction,
33
MultisigInstructionProgram,
44
UNRECOGNIZED_INSTRUCTION,
5+
UnrecognizedProgram,
56
} from ".";
67
import { AnchorAccounts, resolveAccountNames } from "./anchor";
7-
import messageBuffer from "message_buffer/idl/message_buffer.json";
8-
import { TransactionInstruction } from "@solana/web3.js";
8+
import messageBufferIdl from "message_buffer/idl/message_buffer.json";
9+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
910
import { Idl, BorshCoder } from "@coral-xyz/anchor";
11+
import { MESSAGE_BUFFER_PROGRAM_ID } from "../message_buffer";
12+
import meshIdl from "@sqds/mesh/lib/mesh-idl/mesh.json";
13+
import stakingIdl from "./idl/staking.json";
1014

11-
export class MessageBufferMultisigInstruction implements MultisigInstruction {
12-
readonly program = MultisigInstructionProgram.MessageBuffer;
15+
export const MESH_PROGRAM_ID = new PublicKey(
16+
"SMPLVC8MxZ5Bf5EfF7PaMiTCxoBAcmkbM2vkrvMK8ho"
17+
);
18+
export const STAKING_PROGRAM_ID = new PublicKey(
19+
"pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ"
20+
);
21+
22+
export class AnchorMultisigInstruction implements MultisigInstruction {
23+
readonly program: MultisigInstructionProgram;
1324
readonly name: string;
1425
readonly args: { [key: string]: any };
1526
readonly accounts: AnchorAccounts;
1627

1728
constructor(
29+
program: MultisigInstructionProgram,
1830
name: string,
1931
args: { [key: string]: any },
2032
accounts: AnchorAccounts
2133
) {
34+
this.program = program;
2235
this.name = name;
2336
this.args = args;
2437
this.accounts = accounts;
2538
}
2639

2740
static fromTransactionInstruction(
2841
instruction: TransactionInstruction
29-
): MessageBufferMultisigInstruction {
30-
const messageBufferInstructionCoder = new BorshCoder(messageBuffer as Idl)
31-
.instruction;
42+
): MultisigInstruction {
43+
let idl: Idl;
44+
let program: MultisigInstructionProgram;
45+
switch (instruction.programId.toBase58()) {
46+
case MESSAGE_BUFFER_PROGRAM_ID.toBase58():
47+
idl = messageBufferIdl as Idl;
48+
program = MultisigInstructionProgram.MessageBuffer;
49+
break;
50+
case MESH_PROGRAM_ID.toBase58():
51+
idl = meshIdl as Idl;
52+
program = MultisigInstructionProgram.Mesh;
53+
break;
54+
case STAKING_PROGRAM_ID.toBase58():
55+
idl = stakingIdl as Idl;
56+
program = MultisigInstructionProgram.Staking;
57+
break;
58+
default:
59+
return UnrecognizedProgram.fromTransactionInstruction(instruction);
60+
}
61+
const instructionCoder = new BorshCoder(idl).instruction;
3262

33-
const deserializedData = messageBufferInstructionCoder.decode(
34-
instruction.data
35-
);
63+
const deserializedData = instructionCoder.decode(instruction.data);
3664

3765
if (deserializedData) {
38-
return new MessageBufferMultisigInstruction(
66+
return new AnchorMultisigInstruction(
67+
program,
3968
deserializedData.name,
4069
deserializedData.data,
41-
resolveAccountNames(
42-
messageBuffer as Idl,
43-
deserializedData.name,
44-
instruction
45-
)
70+
resolveAccountNames(idl, deserializedData.name, instruction)
4671
);
4772
} else {
48-
return new MessageBufferMultisigInstruction(
73+
return new AnchorMultisigInstruction(
74+
program,
4975
UNRECOGNIZED_INSTRUCTION,
5076
{ data: instruction.data },
5177
{ named: {}, remaining: instruction.keys }

0 commit comments

Comments
 (0)