Skip to content

Commit c7af4a0

Browse files
authored
Crank changes (#588)
1 parent 6d806f7 commit c7af4a0

File tree

1 file changed

+23
-51
lines changed
  • governance/xc_admin/packages/crank_executor/src

1 file changed

+23
-51
lines changed

governance/xc_admin/packages/crank_executor/src/index.ts

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -110,57 +110,27 @@ async function run() {
110110
parsedInstruction instanceof PythMultisigInstruction &&
111111
parsedInstruction.name == "addProduct"
112112
) {
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+
})
122133
);
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-
}
164134
} else if (
165135
parsedInstruction instanceof PythMultisigInstruction &&
166136
parsedInstruction.name == "addPrice"
@@ -169,7 +139,7 @@ async function run() {
169139
const productAccount = await squad.connection.getAccountInfo(
170140
parsedInstruction.accounts.named.productAccount.pubkey
171141
);
172-
if (productAccount?.data) {
142+
if (productAccount) {
173143
const priceSeed =
174144
"price:" + parseProductData(productAccount.data).product.symbol;
175145
const priceAddress = await PublicKey.createWithSeed(
@@ -191,6 +161,8 @@ async function run() {
191161
programId: getPythProgramKeyForCluster(CLUSTER as PythCluster),
192162
})
193163
);
164+
} else {
165+
throw Error("Product account not found");
194166
}
195167
}
196168

0 commit comments

Comments
 (0)