Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { useWallet } from '@solana/wallet-adapter-react'
import { AccountMeta, Keypair, PublicKey, SystemProgram } from '@solana/web3.js'
import {
AccountMeta,
Keypair,
PublicKey,
SystemProgram,
TransactionInstruction,
} from '@solana/web3.js'
import { MultisigAccount, TransactionAccount } from '@sqds/mesh/lib/types'
import { useRouter } from 'next/router'
import { Fragment, useCallback, useContext, useEffect, useState } from 'react'
Expand Down Expand Up @@ -40,6 +46,12 @@ import {

import { getMappingCluster, isPubkey } from '../InstructionViews/utils'
import { getPythProgramKeyForCluster, PythCluster } from '@pythnetwork/client'
import {
DEFAULT_PRIORITY_FEE_CONFIG,
TransactionBuilder,
sendTransactions,
} from '@pythnetwork/solana-utils'
import { Wallet } from '@coral-xyz/anchor'
const ProposalRow = ({
proposal,
multisig,
Expand Down Expand Up @@ -369,13 +381,35 @@ const Proposal = ({
}, [cluster, proposal, squads, connection])

const handleClick = async (
handler: (squad: SquadsMesh, proposalKey: PublicKey) => any,
instructionGenerator: (
squad: SquadsMesh,
vaultKey: PublicKey,
proposalKey: PublicKey
) => Promise<TransactionInstruction>,
msg: string
) => {
if (proposal && squads) {
try {
setIsTransactionLoading(true)
await handler(squads, proposal.publicKey)
const instruction = await instructionGenerator(
squads,
proposal.ms,
proposal.publicKey
)
const builder = new TransactionBuilder(
squads.wallet.publicKey,
squads.connection
)
builder.addInstruction({ instruction, signers: [] })
const versionedTxs = await builder.getVersionedTransactions(
DEFAULT_PRIORITY_FEE_CONFIG
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth making this configurable right now

)
await sendTransactions(
versionedTxs,
squads.connection,
squads.wallet as Wallet
)

if (refreshData) await refreshData().fetchData()
toast.success(msg)
} catch (e: any) {
Expand All @@ -387,27 +421,55 @@ const Proposal = ({
}

const handleClickApprove = async () => {
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
await squad.approveTransaction(proposalKey)
}, `Approved proposal ${proposal?.publicKey.toBase58()}`)
await handleClick(
async (
squad: SquadsMesh,
vaultKey: PublicKey,
proposalKey: PublicKey
): Promise<TransactionInstruction> => {
return await squad.buildApproveTransaction(vaultKey, proposalKey)
},
`Approved proposal ${proposal?.publicKey.toBase58()}`
)
}

const handleClickReject = async () => {
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
await squad.rejectTransaction(proposalKey)
}, `Rejected proposal ${proposal?.publicKey.toBase58()}`)
await handleClick(
async (
squad: SquadsMesh,
vaultKey: PublicKey,
proposalKey: PublicKey
): Promise<TransactionInstruction> => {
return await squad.buildRejectTransaction(vaultKey, proposalKey)
},
`Rejected proposal ${proposal?.publicKey.toBase58()}`
)
}

const handleClickExecute = async () => {
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
await squad.executeTransaction(proposalKey)
}, `Executed proposal ${proposal?.publicKey.toBase58()}`)
await handleClick(
async (
squad: SquadsMesh,
vaultKey: PublicKey,
proposalKey: PublicKey
): Promise<TransactionInstruction> => {
return await squad.buildExecuteTransaction(proposalKey)
},
`Executed proposal ${proposal?.publicKey.toBase58()}`
)
}

const handleClickCancel = async () => {
await handleClick(async (squad: SquadsMesh, proposalKey: PublicKey) => {
await squad.cancelTransaction(proposalKey)
}, `Cancelled proposal ${proposal?.publicKey.toBase58()}`)
await handleClick(
async (
squad: SquadsMesh,
vaultKey: PublicKey,
proposalKey: PublicKey
): Promise<TransactionInstruction> => {
return await squad.buildCancelTransaction(vaultKey, proposalKey)
},
`Cancelled proposal ${proposal?.publicKey.toBase58()}`
)
}

return proposal !== undefined &&
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions target_chains/solana/sdk/js/solana_utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@solana/web3.js": "^1.90.0"
}
}
2 changes: 2 additions & 0 deletions target_chains/solana/sdk/js/solana_utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export {
InstructionWithEphemeralSigners,
PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET,
PriorityFeeConfig,
sendTransactions,
DEFAULT_PRIORITY_FEE_CONFIG,
} from "./transaction";
23 changes: 23 additions & 0 deletions target_chains/solana/sdk/js/solana_utils/src/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
import {
ComputeBudgetProgram,
ConfirmOptions,
Connection,
PACKET_DATA_SIZE,
PublicKey,
Expand All @@ -24,6 +26,10 @@ export type PriorityFeeConfig = {
computeUnitPriceMicroLamports?: number;
};

export const DEFAULT_PRIORITY_FEE_CONFIG: PriorityFeeConfig = {
computeUnitPriceMicroLamports: 50000,
};

/**
* Get the size of a transaction that would contain the provided array of instructions
*/
Expand Down Expand Up @@ -240,3 +246,20 @@ export class TransactionBuilder {
}
}
}

export async function sendTransactions(
transactions: {
tx: VersionedTransaction | Transaction;
signers?: Signer[] | undefined;
}[],
connection: Connection,
wallet: Wallet,
opts?: ConfirmOptions
) {
if (opts === undefined) {
opts = AnchorProvider.defaultOptions();
}

const provider = new AnchorProvider(connection, wallet, opts);
await provider.sendAll(transactions);
}