Xc admin/crank for creating accounts (#568)
* Crank can create accounts * Cleanup * Cleanup * Cleanup * Comment * Done
This commit is contained in:
parent
d331393c81
commit
747886a089
|
@ -4,7 +4,6 @@ import {
|
||||||
Connection,
|
Connection,
|
||||||
Keypair,
|
Keypair,
|
||||||
PublicKey,
|
PublicKey,
|
||||||
SendTransactionError,
|
|
||||||
SystemProgram,
|
SystemProgram,
|
||||||
Transaction,
|
Transaction,
|
||||||
} from "@solana/web3.js";
|
} from "@solana/web3.js";
|
||||||
|
@ -14,18 +13,21 @@ import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet";
|
||||||
import {
|
import {
|
||||||
getProposals,
|
getProposals,
|
||||||
MultisigParser,
|
MultisigParser,
|
||||||
|
PythMultisigInstruction,
|
||||||
WormholeMultisigInstruction,
|
WormholeMultisigInstruction,
|
||||||
} from "xc_admin_common";
|
} from "xc_admin_common";
|
||||||
import BN from "bn.js";
|
import BN from "bn.js";
|
||||||
import { AnchorProvider } from "@project-serum/anchor";
|
import { AnchorProvider } from "@project-serum/anchor";
|
||||||
import {
|
import {
|
||||||
getPythClusterApiUrl,
|
getPythClusterApiUrl,
|
||||||
|
getPythProgramKeyForCluster,
|
||||||
PythCluster,
|
PythCluster,
|
||||||
} from "@pythnetwork/client/lib/cluster";
|
} from "@pythnetwork/client/lib/cluster";
|
||||||
import {
|
import {
|
||||||
deriveFeeCollectorKey,
|
deriveFeeCollectorKey,
|
||||||
getWormholeBridgeData,
|
getWormholeBridgeData,
|
||||||
} from "@certusone/wormhole-sdk/lib/cjs/solana/wormhole";
|
} from "@certusone/wormhole-sdk/lib/cjs/solana/wormhole";
|
||||||
|
import { parseProductData } from "@pythnetwork/client";
|
||||||
|
|
||||||
export function envOrErr(env: string): string {
|
export function envOrErr(env: string): string {
|
||||||
const val = process.env[env];
|
const val = process.env[env];
|
||||||
|
@ -35,6 +37,9 @@ export function envOrErr(env: string): string {
|
||||||
return String(process.env[env]);
|
return String(process.env[env]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PRODUCT_ACCOUNT_SIZE = 512;
|
||||||
|
const PRICE_ACCOUNT_SIZE = 3312;
|
||||||
|
|
||||||
const CLUSTER: string = envOrErr("CLUSTER");
|
const CLUSTER: string = envOrErr("CLUSTER");
|
||||||
const COMMITMENT: Commitment =
|
const COMMITMENT: Commitment =
|
||||||
(process.env.COMMITMENT as Commitment) ?? "confirmed";
|
(process.env.COMMITMENT as Commitment) ?? "confirmed";
|
||||||
|
@ -65,6 +70,7 @@ async function run() {
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const proposals = await getProposals(squad, VAULT, undefined, "executeReady");
|
const proposals = await getProposals(squad, VAULT, undefined, "executeReady");
|
||||||
|
|
||||||
for (const proposal of proposals) {
|
for (const proposal of proposals) {
|
||||||
console.log("Trying to execute: ", proposal.publicKey.toBase58());
|
console.log("Trying to execute: ", proposal.publicKey.toBase58());
|
||||||
// If we have previously cancelled because the proposal was failing, don't attempt
|
// If we have previously cancelled because the proposal was failing, don't attempt
|
||||||
|
@ -100,6 +106,92 @@ async function run() {
|
||||||
fromPubkey: squad.wallet.publicKey,
|
fromPubkey: squad.wallet.publicKey,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
} else if (
|
||||||
|
parsedInstruction instanceof PythMultisigInstruction &&
|
||||||
|
parsedInstruction.name == "addProduct"
|
||||||
|
) {
|
||||||
|
/// Add product, fetch the symbol from updProduct to get the address
|
||||||
|
i += 1;
|
||||||
|
const nextInstructionPda = getIxPDA(
|
||||||
|
proposal.publicKey,
|
||||||
|
new BN(i),
|
||||||
|
squad.multisigProgramId
|
||||||
|
)[0];
|
||||||
|
const nextInstruction = await squad.getInstruction(
|
||||||
|
nextInstructionPda
|
||||||
|
);
|
||||||
|
const nextParsedInstruction = multisigParser.parseInstruction({
|
||||||
|
programId: nextInstruction.programId,
|
||||||
|
data: nextInstruction.data as Buffer,
|
||||||
|
keys: nextInstruction.keys as AccountMeta[],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
nextParsedInstruction instanceof PythMultisigInstruction &&
|
||||||
|
nextParsedInstruction.name == "updProduct"
|
||||||
|
) {
|
||||||
|
const productSeed = "product:" + nextParsedInstruction.args.symbol;
|
||||||
|
const productAddress = await PublicKey.createWithSeed(
|
||||||
|
squad.wallet.publicKey,
|
||||||
|
productSeed,
|
||||||
|
getPythProgramKeyForCluster(CLUSTER as PythCluster)
|
||||||
|
);
|
||||||
|
transaction.add(
|
||||||
|
SystemProgram.createAccountWithSeed({
|
||||||
|
fromPubkey: squad.wallet.publicKey,
|
||||||
|
basePubkey: squad.wallet.publicKey,
|
||||||
|
newAccountPubkey: productAddress,
|
||||||
|
seed: productSeed,
|
||||||
|
space: PRODUCT_ACCOUNT_SIZE,
|
||||||
|
lamports:
|
||||||
|
await squad.connection.getMinimumBalanceForRentExemption(
|
||||||
|
PRODUCT_ACCOUNT_SIZE
|
||||||
|
),
|
||||||
|
programId: getPythProgramKeyForCluster(CLUSTER as PythCluster),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
transaction.add(
|
||||||
|
await squad.buildExecuteInstruction(
|
||||||
|
proposal.publicKey,
|
||||||
|
getIxPDA(
|
||||||
|
proposal.publicKey,
|
||||||
|
new BN(i - 1),
|
||||||
|
squad.multisigProgramId
|
||||||
|
)[0]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
parsedInstruction instanceof PythMultisigInstruction &&
|
||||||
|
parsedInstruction.name == "addPrice"
|
||||||
|
) {
|
||||||
|
/// Add price, fetch the symbol from the product account
|
||||||
|
const productAccount = await squad.connection.getAccountInfo(
|
||||||
|
parsedInstruction.accounts.named.productAccount.pubkey
|
||||||
|
);
|
||||||
|
if (productAccount?.data) {
|
||||||
|
const priceSeed =
|
||||||
|
"price:" + parseProductData(productAccount.data).product.symbol;
|
||||||
|
const priceAddress = await PublicKey.createWithSeed(
|
||||||
|
squad.wallet.publicKey,
|
||||||
|
priceSeed,
|
||||||
|
getPythProgramKeyForCluster(CLUSTER as PythCluster)
|
||||||
|
);
|
||||||
|
transaction.add(
|
||||||
|
SystemProgram.createAccountWithSeed({
|
||||||
|
fromPubkey: squad.wallet.publicKey,
|
||||||
|
basePubkey: squad.wallet.publicKey,
|
||||||
|
newAccountPubkey: priceAddress,
|
||||||
|
seed: priceSeed,
|
||||||
|
space: PRICE_ACCOUNT_SIZE,
|
||||||
|
lamports:
|
||||||
|
await squad.connection.getMinimumBalanceForRentExemption(
|
||||||
|
PRICE_ACCOUNT_SIZE
|
||||||
|
),
|
||||||
|
programId: getPythProgramKeyForCluster(CLUSTER as PythCluster),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.add(
|
transaction.add(
|
||||||
|
@ -109,20 +201,10 @@ async function run() {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
await new AnchorProvider(squad.connection, squad.wallet, {
|
||||||
await new AnchorProvider(squad.connection, squad.wallet, {
|
commitment: COMMITMENT,
|
||||||
commitment: COMMITMENT,
|
preflightCommitment: COMMITMENT,
|
||||||
preflightCommitment: COMMITMENT,
|
}).sendAndConfirm(transaction, [], { skipPreflight: true });
|
||||||
}).sendAndConfirm(transaction, []);
|
|
||||||
} catch (error) {
|
|
||||||
// Mark the transaction as cancelled if we failed to run it
|
|
||||||
if (error instanceof SendTransactionError) {
|
|
||||||
console.error(error);
|
|
||||||
await squad.cancelTransaction(proposal.publicKey);
|
|
||||||
console.log("Cancelled: ", proposal.publicKey.toBase58());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Skipping: ", proposal.publicKey.toBase58());
|
console.log("Skipping: ", proposal.publicKey.toBase58());
|
||||||
|
|
Loading…
Reference in New Issue