Skip to content

Commit 7b01f2a

Browse files
authored
feat(xc_admin_frontend): add priority fees to approval/rejection (#1353)
* Make room for compute ixs * Continue * Fix syntax * Checkpoint * Cleanup * Cleanup * Go
1 parent 1b21a92 commit 7b01f2a

File tree

5 files changed

+105
-15
lines changed

5 files changed

+105
-15
lines changed

governance/xc_admin/packages/xc_admin_frontend/components/tabs/Proposals.tsx

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import * as Tooltip from '@radix-ui/react-tooltip'
22
import { useWallet } from '@solana/wallet-adapter-react'
3-
import { AccountMeta, Keypair, PublicKey, SystemProgram } from '@solana/web3.js'
3+
import {
4+
AccountMeta,
5+
Keypair,
6+
PublicKey,
7+
SystemProgram,
8+
TransactionInstruction,
9+
} from '@solana/web3.js'
410
import { MultisigAccount, TransactionAccount } from '@sqds/mesh/lib/types'
511
import { useRouter } from 'next/router'
612
import { Fragment, useCallback, useContext, useEffect, useState } from 'react'
@@ -40,6 +46,12 @@ import {
4046

4147
import { getMappingCluster, isPubkey } from '../InstructionViews/utils'
4248
import { getPythProgramKeyForCluster, PythCluster } from '@pythnetwork/client'
49+
import {
50+
DEFAULT_PRIORITY_FEE_CONFIG,
51+
TransactionBuilder,
52+
sendTransactions,
53+
} from '@pythnetwork/solana-utils'
54+
import { Wallet } from '@coral-xyz/anchor'
4355
const ProposalRow = ({
4456
proposal,
4557
multisig,
@@ -369,13 +381,35 @@ const Proposal = ({
369381
}, [cluster, proposal, squads, connection])
370382

371383
const handleClick = async (
372-
handler: (squad: SquadsMesh, proposalKey: PublicKey) => any,
384+
instructionGenerator: (
385+
squad: SquadsMesh,
386+
vaultKey: PublicKey,
387+
proposalKey: PublicKey
388+
) => Promise<TransactionInstruction>,
373389
msg: string
374390
) => {
375391
if (proposal && squads) {
376392
try {
377393
setIsTransactionLoading(true)
378-
await handler(squads, proposal.publicKey)
394+
const instruction = await instructionGenerator(
395+
squads,
396+
proposal.ms,
397+
proposal.publicKey
398+
)
399+
const builder = new TransactionBuilder(
400+
squads.wallet.publicKey,
401+
squads.connection
402+
)
403+
builder.addInstruction({ instruction, signers: [] })
404+
const versionedTxs = await builder.getVersionedTransactions(
405+
DEFAULT_PRIORITY_FEE_CONFIG
406+
)
407+
await sendTransactions(
408+
versionedTxs,
409+
squads.connection,
410+
squads.wallet as Wallet
411+
)
412+
379413
if (refreshData) await refreshData().fetchData()
380414
toast.success(msg)
381415
} catch (e: any) {
@@ -387,27 +421,55 @@ const Proposal = ({
387421
}
388422

389423
const handleClickApprove = async () => {
390-
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
391-
await squad.approveTransaction(proposalKey)
392-
}, `Approved proposal ${proposal?.publicKey.toBase58()}`)
424+
await handleClick(
425+
async (
426+
squad: SquadsMesh,
427+
vaultKey: PublicKey,
428+
proposalKey: PublicKey
429+
): Promise<TransactionInstruction> => {
430+
return await squad.buildApproveTransaction(vaultKey, proposalKey)
431+
},
432+
`Approved proposal ${proposal?.publicKey.toBase58()}`
433+
)
393434
}
394435

395436
const handleClickReject = async () => {
396-
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
397-
await squad.rejectTransaction(proposalKey)
398-
}, `Rejected proposal ${proposal?.publicKey.toBase58()}`)
437+
await handleClick(
438+
async (
439+
squad: SquadsMesh,
440+
vaultKey: PublicKey,
441+
proposalKey: PublicKey
442+
): Promise<TransactionInstruction> => {
443+
return await squad.buildRejectTransaction(vaultKey, proposalKey)
444+
},
445+
`Rejected proposal ${proposal?.publicKey.toBase58()}`
446+
)
399447
}
400448

401449
const handleClickExecute = async () => {
402-
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
403-
await squad.executeTransaction(proposalKey)
404-
}, `Executed proposal ${proposal?.publicKey.toBase58()}`)
450+
await handleClick(
451+
async (
452+
squad: SquadsMesh,
453+
vaultKey: PublicKey,
454+
proposalKey: PublicKey
455+
): Promise<TransactionInstruction> => {
456+
return await squad.buildExecuteTransaction(proposalKey)
457+
},
458+
`Executed proposal ${proposal?.publicKey.toBase58()}`
459+
)
405460
}
406461

407462
const handleClickCancel = async () => {
408-
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
409-
await squad.cancelTransaction(proposalKey)
410-
}, `Cancelled proposal ${proposal?.publicKey.toBase58()}`)
463+
await handleClick(
464+
async (
465+
squad: SquadsMesh,
466+
vaultKey: PublicKey,
467+
proposalKey: PublicKey
468+
): Promise<TransactionInstruction> => {
469+
return await squad.buildCancelTransaction(vaultKey, proposalKey)
470+
},
471+
`Cancelled proposal ${proposal?.publicKey.toBase58()}`
472+
)
411473
}
412474

413475
return proposal !== undefined &&

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

target_chains/solana/sdk/js/solana_utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"typescript": "^4.6.3"
4343
},
4444
"dependencies": {
45+
"@coral-xyz/anchor": "^0.29.0",
4546
"@solana/web3.js": "^1.90.0"
4647
}
4748
}

target_chains/solana/sdk/js/solana_utils/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export {
55
InstructionWithEphemeralSigners,
66
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET,
77
PriorityFeeConfig,
8+
sendTransactions,
9+
DEFAULT_PRIORITY_FEE_CONFIG,
810
} from "./transaction";

target_chains/solana/sdk/js/solana_utils/src/transaction.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
12
import {
23
ComputeBudgetProgram,
4+
ConfirmOptions,
35
Connection,
46
PACKET_DATA_SIZE,
57
PublicKey,
@@ -24,6 +26,10 @@ export type PriorityFeeConfig = {
2426
computeUnitPriceMicroLamports?: number;
2527
};
2628

29+
export const DEFAULT_PRIORITY_FEE_CONFIG: PriorityFeeConfig = {
30+
computeUnitPriceMicroLamports: 50000,
31+
};
32+
2733
/**
2834
* Get the size of a transaction that would contain the provided array of instructions
2935
*/
@@ -240,3 +246,20 @@ export class TransactionBuilder {
240246
}
241247
}
242248
}
249+
250+
export async function sendTransactions(
251+
transactions: {
252+
tx: VersionedTransaction | Transaction;
253+
signers?: Signer[] | undefined;
254+
}[],
255+
connection: Connection,
256+
wallet: Wallet,
257+
opts?: ConfirmOptions
258+
) {
259+
if (opts === undefined) {
260+
opts = AnchorProvider.defaultOptions();
261+
}
262+
263+
const provider = new AnchorProvider(connection, wallet, opts);
264+
await provider.sendAll(transactions);
265+
}

0 commit comments

Comments
 (0)