Skip to content

Commit a27eb9a

Browse files
authored
feat(xc-admin): add priority fees support to xc-admin (#1344)
* refactor * add priority fees to proposal creation * style fix
1 parent a63cf91 commit a27eb9a

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const KEYPAIR: Keypair = Keypair.fromSecretKey(
1515
);
1616
const COMMITMENT: Commitment =
1717
(process.env.COMMITMENT as Commitment) ?? "confirmed";
18+
const COMPUTE_UNIT_PRICE_MICROLAMPORTS: number | undefined = process.env
19+
.COMPUTE_UNIT_PRICE_MICROLAMPORTS
20+
? Number(process.env.COMPUTE_UNIT_PRICE_MICROLAMPORTS)
21+
: undefined;
1822

1923
async function run() {
2024
const squad = new SquadsMesh({
@@ -29,7 +33,13 @@ async function run() {
2933
console.log("Trying to execute: ", proposal.publicKey.toBase58());
3034
// If we have previously cancelled because the proposal was failing, don't attempt
3135
if (proposal.cancelled.length == 0) {
32-
await executeProposal(proposal, squad, CLUSTER, COMMITMENT);
36+
await executeProposal(
37+
proposal,
38+
squad,
39+
CLUSTER,
40+
COMMITMENT,
41+
COMPUTE_UNIT_PRICE_MICROLAMPORTS
42+
);
3343
} else {
3444
console.log("Skipping: ", proposal.publicKey.toBase58());
3545
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const RPC_URLS: Record<Cluster | "localnet", string> = {
3838
localnet: LOCALNET_RPC,
3939
};
4040

41+
const COMPUTE_UNIT_PRICE_MICROLAMPORTS: number | undefined = process.env
42+
.COMPUTE_UNIT_PRICE_MICROLAMPORTS
43+
? Number(process.env.COMPUTE_UNIT_PRICE_MICROLAMPORTS)
44+
: undefined;
45+
4146
const app = express();
4247

4348
app.use(cors());
@@ -78,7 +83,11 @@ app.post("/api/propose", async (req: Request, res: Response) => {
7883

7984
// preserve the existing API by returning only the first pubkey
8085
const proposalPubkey = (
81-
await vault.proposeInstructions(instructions, cluster)
86+
await vault.proposeInstructions(
87+
instructions,
88+
cluster,
89+
COMPUTE_UNIT_PRICE_MICROLAMPORTS
90+
)
8291
)[0];
8392
res.status(200).json({ proposalPubkey: proposalPubkey });
8493
} catch (error) {

governance/xc_admin/packages/xc_admin_common/src/executor.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PythCluster } from "@pythnetwork/client/lib/cluster";
44
import {
55
AccountMeta,
66
Commitment,
7+
ComputeBudgetProgram,
78
PublicKey,
89
SystemProgram,
910
Transaction,
@@ -62,7 +63,8 @@ export async function executeProposal(
6263
proposal: TransactionAccount,
6364
squad: SquadsMesh,
6465
cluster: PythCluster,
65-
commitment: Commitment = "confirmed"
66+
commitment: Commitment = "confirmed",
67+
computeUnitPriceMicroLamports?: number
6668
) {
6769
const multisigParser = MultisigParser.fromCluster(cluster);
6870
const signatures: string[] = [];
@@ -131,6 +133,14 @@ export async function executeProposal(
131133
}
132134
}
133135

136+
if (computeUnitPriceMicroLamports !== undefined) {
137+
const params = {
138+
microLamports: computeUnitPriceMicroLamports,
139+
};
140+
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
141+
transaction.add(ix);
142+
}
143+
134144
transaction.add(
135145
await squad.buildExecuteInstruction(
136146
proposal.publicKey,

governance/xc_admin/packages/xc_admin_common/src/propose.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
PACKET_DATA_SIZE,
99
ConfirmOptions,
1010
sendAndConfirmRawTransaction,
11+
ComputeBudgetProgram,
1112
} from "@solana/web3.js";
1213
import { BN } from "bn.js";
1314
import { AnchorProvider } from "@coral-xyz/anchor";
@@ -275,7 +276,8 @@ export class MultisigVault {
275276
*/
276277
public async proposeInstructions(
277278
instructions: TransactionInstruction[],
278-
targetCluster?: PythCluster
279+
targetCluster?: PythCluster,
280+
computeUnitPriceMicroLamports?: number
279281
): Promise<PublicKey[]> {
280282
const msAccount = await this.getMultisigAccount();
281283
const newProposals = [];
@@ -367,11 +369,14 @@ export class MultisigVault {
367369

368370
const txToSend = TransactionBuilder.batchIntoLegacyTransactions(ixToSend);
369371

370-
await this.sendAllTransactions(txToSend);
372+
await this.sendAllTransactions(txToSend, computeUnitPriceMicroLamports);
371373
return newProposals;
372374
}
373375

374-
async sendAllTransactions(transactions: Transaction[]) {
376+
async sendAllTransactions(
377+
transactions: Transaction[],
378+
computeUnitPriceMicroLamports?: number
379+
) {
375380
const provider = this.getAnchorProvider({
376381
preflightCommitment: "processed",
377382
commitment: "processed",
@@ -380,7 +385,18 @@ export class MultisigVault {
380385
let needToFetchBlockhash = true; // We don't fetch blockhash everytime to save time
381386
let blockhash: string = "";
382387
for (let [index, tx] of transactions.entries()) {
383-
console.log("Trying to send transaction : " + index);
388+
if (computeUnitPriceMicroLamports !== undefined) {
389+
console.log(
390+
`Setting compute unit price: ${computeUnitPriceMicroLamports} microLamports`
391+
);
392+
const params = {
393+
microLamports: computeUnitPriceMicroLamports,
394+
};
395+
const ix = ComputeBudgetProgram.setComputeUnitPrice(params);
396+
tx.add(ix);
397+
}
398+
399+
console.log("Trying to send transaction: " + index);
384400
let numberOfRetries = 0;
385401
let txHasLanded = false;
386402

0 commit comments

Comments
 (0)