@@ -110,57 +110,27 @@ async function run() {
110
110
parsedInstruction instanceof PythMultisigInstruction &&
111
111
parsedInstruction . name == "addProduct"
112
112
) {
113
- /// Add product, fetch the symbol from updProduct to get the address
114
- i += 1 ;
115
- const nextInstructionPda = getIxPDA (
116
- proposal . publicKey ,
117
- new BN ( i ) ,
118
- squad . multisigProgramId
119
- ) [ 0 ] ;
120
- const nextInstruction = await squad . getInstruction (
121
- nextInstructionPda
113
+ /// Add product, fetch the symbol from the instruction
114
+ const productSeed = "product:" + parsedInstruction . args . symbol ;
115
+ const productAddress = await PublicKey . createWithSeed (
116
+ squad . wallet . publicKey ,
117
+ productSeed ,
118
+ getPythProgramKeyForCluster ( CLUSTER as PythCluster )
119
+ ) ;
120
+ transaction . add (
121
+ SystemProgram . createAccountWithSeed ( {
122
+ fromPubkey : squad . wallet . publicKey ,
123
+ basePubkey : squad . wallet . publicKey ,
124
+ newAccountPubkey : productAddress ,
125
+ seed : productSeed ,
126
+ space : PRODUCT_ACCOUNT_SIZE ,
127
+ lamports :
128
+ await squad . connection . getMinimumBalanceForRentExemption (
129
+ PRODUCT_ACCOUNT_SIZE
130
+ ) ,
131
+ programId : getPythProgramKeyForCluster ( CLUSTER as PythCluster ) ,
132
+ } )
122
133
) ;
123
- const nextParsedInstruction = multisigParser . parseInstruction ( {
124
- programId : nextInstruction . programId ,
125
- data : nextInstruction . data as Buffer ,
126
- keys : nextInstruction . keys as AccountMeta [ ] ,
127
- } ) ;
128
-
129
- if (
130
- nextParsedInstruction instanceof PythMultisigInstruction &&
131
- nextParsedInstruction . name == "updProduct"
132
- ) {
133
- const productSeed = "product:" + nextParsedInstruction . args . symbol ;
134
- const productAddress = await PublicKey . createWithSeed (
135
- squad . wallet . publicKey ,
136
- productSeed ,
137
- getPythProgramKeyForCluster ( CLUSTER as PythCluster )
138
- ) ;
139
- transaction . add (
140
- SystemProgram . createAccountWithSeed ( {
141
- fromPubkey : squad . wallet . publicKey ,
142
- basePubkey : squad . wallet . publicKey ,
143
- newAccountPubkey : productAddress ,
144
- seed : productSeed ,
145
- space : PRODUCT_ACCOUNT_SIZE ,
146
- lamports :
147
- await squad . connection . getMinimumBalanceForRentExemption (
148
- PRODUCT_ACCOUNT_SIZE
149
- ) ,
150
- programId : getPythProgramKeyForCluster ( CLUSTER as PythCluster ) ,
151
- } )
152
- ) ;
153
- transaction . add (
154
- await squad . buildExecuteInstruction (
155
- proposal . publicKey ,
156
- getIxPDA (
157
- proposal . publicKey ,
158
- new BN ( i - 1 ) ,
159
- squad . multisigProgramId
160
- ) [ 0 ]
161
- )
162
- ) ;
163
- }
164
134
} else if (
165
135
parsedInstruction instanceof PythMultisigInstruction &&
166
136
parsedInstruction . name == "addPrice"
@@ -169,7 +139,7 @@ async function run() {
169
139
const productAccount = await squad . connection . getAccountInfo (
170
140
parsedInstruction . accounts . named . productAccount . pubkey
171
141
) ;
172
- if ( productAccount ?. data ) {
142
+ if ( productAccount ) {
173
143
const priceSeed =
174
144
"price:" + parseProductData ( productAccount . data ) . product . symbol ;
175
145
const priceAddress = await PublicKey . createWithSeed (
@@ -191,6 +161,8 @@ async function run() {
191
161
programId : getPythProgramKeyForCluster ( CLUSTER as PythCluster ) ,
192
162
} )
193
163
) ;
164
+ } else {
165
+ throw Error ( "Product account not found" ) ;
194
166
}
195
167
}
196
168
0 commit comments