@@ -21,6 +21,7 @@ import { OPS_KEY } from "./multisig";
21
21
22
22
export const MAX_EXECUTOR_PAYLOAD_SIZE = PACKET_DATA_SIZE - 687 ; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
23
23
export const SIZE_OF_SIGNED_BATCH = 30 ;
24
+ export const MAX_INSTRUCTIONS_PER_PROPOSAL = 256 - 1 ;
24
25
25
26
type SquadInstruction = {
26
27
instruction : TransactionInstruction ;
@@ -45,72 +46,105 @@ export async function proposeInstructions(
45
46
wormholeAddress ?: PublicKey
46
47
) : Promise < PublicKey > {
47
48
const msAccount = await squad . getMultisig ( vault ) ;
48
- let ixToSend : TransactionInstruction [ ] = [ ] ;
49
- ixToSend . push (
50
- await squad . buildCreateTransaction (
51
- msAccount . publicKey ,
52
- msAccount . authorityIndex ,
53
- msAccount . transactionIndex + 1
54
- )
55
- ) ;
56
- const newProposalAddress = getTxPDA (
57
- vault ,
58
- new BN ( msAccount . transactionIndex + 1 ) ,
59
- squad . multisigProgramId
60
- ) [ 0 ] ;
49
+ const newProposals = [ ] ;
61
50
51
+ let ixToSend : TransactionInstruction [ ] = [ ] ;
62
52
if ( remote ) {
63
53
if ( ! wormholeAddress ) {
64
54
throw new Error ( "Need wormhole address" ) ;
65
55
}
66
-
67
56
const batches = batchIntoExecutorPayload ( instructions ) ;
68
- if ( 255 <= batches . length ) {
69
- throw new Error ( "A proposal can only support 255 instructions" ) ;
70
- }
71
- for ( const [ i , batch ] of batches . entries ( ) ) {
72
- const squadIx = await wrapAsRemoteInstruction (
73
- squad ,
74
- vault ,
75
- newProposalAddress ,
76
- batch ,
77
- i + 1 ,
78
- wormholeAddress
79
- ) ;
57
+
58
+ for ( let j = 0 ; j < batches . length ; j += MAX_INSTRUCTIONS_PER_PROPOSAL ) {
59
+ const proposalIndex =
60
+ msAccount . transactionIndex + 1 + j / MAX_INSTRUCTIONS_PER_PROPOSAL ;
80
61
ixToSend . push (
81
- await squad . buildAddInstruction (
62
+ await squad . buildCreateTransaction (
63
+ msAccount . publicKey ,
64
+ msAccount . authorityIndex ,
65
+ proposalIndex
66
+ )
67
+ ) ;
68
+ const newProposalAddress = getTxPDA (
69
+ vault ,
70
+ new BN ( proposalIndex ) ,
71
+ squad . multisigProgramId
72
+ ) [ 0 ] ;
73
+ newProposals . push ( newProposalAddress ) ;
74
+
75
+ for ( const [ i , batch ] of batches
76
+ . slice ( j , j + MAX_INSTRUCTIONS_PER_PROPOSAL )
77
+ . entries ( ) ) {
78
+ const squadIx = await wrapAsRemoteInstruction (
79
+ squad ,
82
80
vault ,
83
81
newProposalAddress ,
84
- squadIx . instruction ,
82
+ batch ,
85
83
i + 1 ,
86
- squadIx . authorityIndex ,
87
- squadIx . authorityBump ,
88
- squadIx . authorityType
89
- )
84
+ wormholeAddress
85
+ ) ;
86
+ ixToSend . push (
87
+ await squad . buildAddInstruction (
88
+ vault ,
89
+ newProposalAddress ,
90
+ squadIx . instruction ,
91
+ i + 1 ,
92
+ squadIx . authorityIndex ,
93
+ squadIx . authorityBump ,
94
+ squadIx . authorityType
95
+ )
96
+ ) ;
97
+ }
98
+ ixToSend . push (
99
+ await squad . buildActivateTransaction ( vault , newProposalAddress )
100
+ ) ;
101
+ ixToSend . push (
102
+ await squad . buildApproveTransaction ( vault , newProposalAddress )
90
103
) ;
91
104
}
92
105
} else {
93
- if ( 255 <= instructions . length ) {
94
- throw new Error ( "A proposal can only support 255 instructions" ) ;
95
- }
96
- for ( let i = 0 ; i < instructions . length ; i ++ ) {
106
+ for (
107
+ let j = 0 ;
108
+ j < instructions . length ;
109
+ j += MAX_INSTRUCTIONS_PER_PROPOSAL
110
+ ) {
111
+ const proposalIndex =
112
+ msAccount . transactionIndex + 1 + j / MAX_INSTRUCTIONS_PER_PROPOSAL ;
97
113
ixToSend . push (
98
- await squad . buildAddInstruction (
99
- vault ,
100
- newProposalAddress ,
101
- instructions [ i ] ,
102
- i + 1
114
+ await squad . buildCreateTransaction (
115
+ msAccount . publicKey ,
116
+ msAccount . authorityIndex ,
117
+ proposalIndex
103
118
)
104
119
) ;
120
+ const newProposalAddress = getTxPDA (
121
+ vault ,
122
+ new BN ( proposalIndex ) ,
123
+ squad . multisigProgramId
124
+ ) [ 0 ] ;
125
+ newProposals . push ( newProposalAddress ) ;
126
+
127
+ for ( let [ i , instruction ] of instructions
128
+ . slice ( j , j + MAX_INSTRUCTIONS_PER_PROPOSAL )
129
+ . entries ( ) ) {
130
+ ixToSend . push (
131
+ await squad . buildAddInstruction (
132
+ vault ,
133
+ newProposalAddress ,
134
+ instruction ,
135
+ i + 1
136
+ )
137
+ ) ;
138
+ }
139
+ ixToSend . push (
140
+ await squad . buildActivateTransaction ( vault , newProposalAddress )
141
+ ) ;
142
+ ixToSend . push (
143
+ await squad . buildApproveTransaction ( vault , newProposalAddress )
144
+ ) ;
105
145
}
106
146
}
107
147
108
- ixToSend . push (
109
- await squad . buildActivateTransaction ( vault , newProposalAddress )
110
- ) ;
111
-
112
- ixToSend . push ( await squad . buildApproveTransaction ( vault , newProposalAddress ) ) ;
113
-
114
148
const txToSend = batchIntoTransactions ( ixToSend ) ;
115
149
116
150
for ( let i = 0 ; i < txToSend . length ; i += SIZE_OF_SIGNED_BATCH ) {
@@ -124,7 +158,7 @@ export async function proposeInstructions(
124
158
} )
125
159
) ;
126
160
}
127
- return newProposalAddress ;
161
+ return newProposals [ 0 ] ;
128
162
}
129
163
130
164
/**
0 commit comments