feat(xc-admin): add priority fees support to xc-admin (#1344)
* refactor * add priority fees to proposal creation * style fix
This commit is contained in:
parent
a63cf91cd1
commit
a27eb9a026
|
@ -15,6 +15,10 @@ const KEYPAIR: Keypair = Keypair.fromSecretKey(
|
|||
);
|
||||
const COMMITMENT: Commitment =
|
||||
(process.env.COMMITMENT as Commitment) ?? "confirmed";
|
||||
const COMPUTE_UNIT_PRICE_MICROLAMPORTS: number | undefined = process.env
|
||||
.COMPUTE_UNIT_PRICE_MICROLAMPORTS
|
||||
? Number(process.env.COMPUTE_UNIT_PRICE_MICROLAMPORTS)
|
||||
: undefined;
|
||||
|
||||
async function run() {
|
||||
const squad = new SquadsMesh({
|
||||
|
@ -29,7 +33,13 @@ async function run() {
|
|||
console.log("Trying to execute: ", proposal.publicKey.toBase58());
|
||||
// If we have previously cancelled because the proposal was failing, don't attempt
|
||||
if (proposal.cancelled.length == 0) {
|
||||
await executeProposal(proposal, squad, CLUSTER, COMMITMENT);
|
||||
await executeProposal(
|
||||
proposal,
|
||||
squad,
|
||||
CLUSTER,
|
||||
COMMITMENT,
|
||||
COMPUTE_UNIT_PRICE_MICROLAMPORTS
|
||||
);
|
||||
} else {
|
||||
console.log("Skipping: ", proposal.publicKey.toBase58());
|
||||
}
|
||||
|
|
|
@ -38,6 +38,11 @@ const RPC_URLS: Record<Cluster | "localnet", string> = {
|
|||
localnet: LOCALNET_RPC,
|
||||
};
|
||||
|
||||
const COMPUTE_UNIT_PRICE_MICROLAMPORTS: number | undefined = process.env
|
||||
.COMPUTE_UNIT_PRICE_MICROLAMPORTS
|
||||
? Number(process.env.COMPUTE_UNIT_PRICE_MICROLAMPORTS)
|
||||
: undefined;
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
|
@ -78,7 +83,11 @@ app.post("/api/propose", async (req: Request, res: Response) => {
|
|||
|
||||
// preserve the existing API by returning only the first pubkey
|
||||
const proposalPubkey = (
|
||||
await vault.proposeInstructions(instructions, cluster)
|
||||
await vault.proposeInstructions(
|
||||
instructions,
|
||||
cluster,
|
||||
COMPUTE_UNIT_PRICE_MICROLAMPORTS
|
||||
)
|
||||
)[0];
|
||||
res.status(200).json({ proposalPubkey: proposalPubkey });
|
||||
} catch (error) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import { PythCluster } from "@pythnetwork/client/lib/cluster";
|
|||
import {
|
||||
AccountMeta,
|
||||
Commitment,
|
||||
ComputeBudgetProgram,
|
||||
PublicKey,
|
||||
SystemProgram,
|
||||
Transaction,
|
||||
|
@ -62,7 +63,8 @@ export async function executeProposal(
|
|||
proposal: TransactionAccount,
|
||||
squad: SquadsMesh,
|
||||
cluster: PythCluster,
|
||||
commitment: Commitment = "confirmed"
|
||||
commitment: Commitment = "confirmed",
|
||||
computeUnitPriceMicroLamports?: number
|
||||
) {
|
||||
const multisigParser = MultisigParser.fromCluster(cluster);
|
||||
const signatures: string[] = [];
|
||||
|
@ -131,6 +133,14 @@ export async function executeProposal(
|
|||
}
|
||||
}
|
||||
|
||||
if (computeUnitPriceMicroLamports !== undefined) {
|
||||
const params = {
|
||||
microLamports: computeUnitPriceMicroLamports,
|
||||
};
|
||||
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
|
||||
transaction.add(ix);
|
||||
}
|
||||
|
||||
transaction.add(
|
||||
await squad.buildExecuteInstruction(
|
||||
proposal.publicKey,
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
PACKET_DATA_SIZE,
|
||||
ConfirmOptions,
|
||||
sendAndConfirmRawTransaction,
|
||||
ComputeBudgetProgram,
|
||||
} from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
import { AnchorProvider } from "@coral-xyz/anchor";
|
||||
|
@ -275,7 +276,8 @@ export class MultisigVault {
|
|||
*/
|
||||
public async proposeInstructions(
|
||||
instructions: TransactionInstruction[],
|
||||
targetCluster?: PythCluster
|
||||
targetCluster?: PythCluster,
|
||||
computeUnitPriceMicroLamports?: number
|
||||
): Promise<PublicKey[]> {
|
||||
const msAccount = await this.getMultisigAccount();
|
||||
const newProposals = [];
|
||||
|
@ -367,11 +369,14 @@ export class MultisigVault {
|
|||
|
||||
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(ixToSend);
|
||||
|
||||
await this.sendAllTransactions(txToSend);
|
||||
await this.sendAllTransactions(txToSend, computeUnitPriceMicroLamports);
|
||||
return newProposals;
|
||||
}
|
||||
|
||||
async sendAllTransactions(transactions: Transaction[]) {
|
||||
async sendAllTransactions(
|
||||
transactions: Transaction[],
|
||||
computeUnitPriceMicroLamports?: number
|
||||
) {
|
||||
const provider = this.getAnchorProvider({
|
||||
preflightCommitment: "processed",
|
||||
commitment: "processed",
|
||||
|
@ -380,7 +385,18 @@ export class MultisigVault {
|
|||
let needToFetchBlockhash = true; // We don't fetch blockhash everytime to save time
|
||||
let blockhash: string = "";
|
||||
for (let [index, tx] of transactions.entries()) {
|
||||
console.log("Trying to send transaction : " + index);
|
||||
if (computeUnitPriceMicroLamports !== undefined) {
|
||||
console.log(
|
||||
`Setting compute unit price: ${computeUnitPriceMicroLamports} microLamports`
|
||||
);
|
||||
const params = {
|
||||
microLamports: computeUnitPriceMicroLamports,
|
||||
};
|
||||
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
|
||||
tx.add(ix);
|
||||
}
|
||||
|
||||
console.log("Trying to send transaction: " + index);
|
||||
let numberOfRetries = 0;
|
||||
let txHasLanded = false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue