@@ -2,50 +2,76 @@ import {
2
2
MultisigInstruction ,
3
3
MultisigInstructionProgram ,
4
4
UNRECOGNIZED_INSTRUCTION ,
5
+ UnrecognizedProgram ,
5
6
} from "." ;
6
7
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" ;
9
10
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" ;
10
14
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 ;
13
24
readonly name : string ;
14
25
readonly args : { [ key : string ] : any } ;
15
26
readonly accounts : AnchorAccounts ;
16
27
17
28
constructor (
29
+ program : MultisigInstructionProgram ,
18
30
name : string ,
19
31
args : { [ key : string ] : any } ,
20
32
accounts : AnchorAccounts
21
33
) {
34
+ this . program = program ;
22
35
this . name = name ;
23
36
this . args = args ;
24
37
this . accounts = accounts ;
25
38
}
26
39
27
40
static fromTransactionInstruction (
28
41
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 ;
32
62
33
- const deserializedData = messageBufferInstructionCoder . decode (
34
- instruction . data
35
- ) ;
63
+ const deserializedData = instructionCoder . decode ( instruction . data ) ;
36
64
37
65
if ( deserializedData ) {
38
- return new MessageBufferMultisigInstruction (
66
+ return new AnchorMultisigInstruction (
67
+ program ,
39
68
deserializedData . name ,
40
69
deserializedData . data ,
41
- resolveAccountNames (
42
- messageBuffer as Idl ,
43
- deserializedData . name ,
44
- instruction
45
- )
70
+ resolveAccountNames ( idl , deserializedData . name , instruction )
46
71
) ;
47
72
} else {
48
- return new MessageBufferMultisigInstruction (
73
+ return new AnchorMultisigInstruction (
74
+ program ,
49
75
UNRECOGNIZED_INSTRUCTION ,
50
76
{ data : instruction . data } ,
51
77
{ named : { } , remaining : instruction . keys }
0 commit comments