Skip to content

Commit

Permalink
Switch to versioned tx and LUTs (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass authored Apr 29, 2024
1 parent fbf82bd commit 33800c0
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 106 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@helium/account-fetch-cache": "^0.6.38",
"@helium/account-fetch-cache-hooks": "^0.6.38",
"@helium/helium-react-hooks": "^0.6.38",
"@helium/account-fetch-cache": "^0.7.11",
"@helium/account-fetch-cache-hooks": "^0.7.11",
"@helium/helium-react-hooks": "^0.7.11",
"@helium/modular-governance-hooks": "^0.0.8",
"@helium/modular-governance-idls": "^0.0.8-next",
"@helium/organization-sdk": "^0.0.8",
"@helium/spl-utils": "^0.6.38",
"@helium/spl-utils": "^0.7.11",
"@helium/state-controller-sdk": "^0.0.8",
"@helium/voter-stake-registry-hooks": "^0.6.38",
"@helium/voter-stake-registry-sdk": "^0.6.38",
"@helium/voter-stake-registry-hooks": "^0.7.11",
"@helium/voter-stake-registry-sdk": "^0.7.11",
"@hookform/resolvers": "^3.3.4",
"@metaplex-foundation/mpl-token-metadata": "2.10.0",
"@project-serum/anchor": "^0.26.0",
Expand Down Expand Up @@ -62,11 +62,11 @@
},
"resolutions": {
"@solana/web3.js": "^1.90.0",
"@helium/account-fetch-cache": "^0.6.38",
"@helium/account-fetch-cache-hooks": "^0.6.38",
"@helium/helium-react-hooks": "^0.6.38",
"@helium/voter-stake-registry-hooks": "^0.6.38",
"@helium/spl-utils": "^0.6.38",
"@helium/account-fetch-cache": "^0.7.11",
"@helium/account-fetch-cache-hooks": "^0.7.11",
"@helium/helium-react-hooks": "^0.7.11",
"@helium/voter-stake-registry-hooks": "^0.7.11",
"@helium/spl-utils": "^0.7.11",
"@helium/modular-governance-hooks": "^0.0.8",
"@solana/wallet-adapter-react": "^0.15.35"
},
Expand Down
12 changes: 2 additions & 10 deletions scripts/resolve-proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { init as initState } from "@helium/state-controller-sdk";
import { init as initProposal } from "@helium/proposal-sdk";
import { AccountFetchCache, chunks } from "@helium/account-fetch-cache";
import { Transaction } from "@solana/web3.js";
import { bulkSendTransactions } from "@helium/spl-utils";
import { batchInstructionsToTxsWithPriorityFee, bulkSendTransactions } from "@helium/spl-utils";

export async function run(args: any = process.argv) {
const yarg = yargs(args).options({
Expand Down Expand Up @@ -61,15 +61,7 @@ export async function run(args: any = process.argv) {
})
.instruction()
}))

const txs = chunks(resolveIxs, 10).map((ixs) => {
const tx = new Transaction({
feePayer: provider.wallet.publicKey
})
tx.add(...ixs)
return tx
})

const txs = await batchInstructionsToTxsWithPriorityFee(provider, resolveIxs)
await bulkSendTransactions(provider, txs)
console.log("Done")
}
10 changes: 8 additions & 2 deletions src/components/VoteOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import React, { FC, useState } from "react";
import { VoteOption } from "./VoteOption";
import { toast } from "sonner";
import { WalletSignTransactionError } from "@solana/wallet-adapter-base";
import { onInstructions } from "@/lib/utils";
import { useAnchorProvider } from "@helium/helium-react-hooks";

export const VoteOptions: FC<{
choices?: VoteChoiceWithMeta[];
Expand All @@ -21,12 +23,16 @@ export const VoteOptions: FC<{
relinquishVote,
loading: relinquishing,
} = useRelinquishVote(proposalKey);
const provider = useAnchorProvider();

const handleVote = (choice: VoteChoiceWithMeta) => async () => {
if (canVote(choice.index)) {
if (canVote(choice.index) && provider) {
try {
setCurrVote(choice.index);
await vote({ choice: choice.index });
await vote({
choice: choice.index,
onInstructions: onInstructions(provider),
});
toast("Vote submitted");
} catch (e: any) {
if (!(e instanceof WalletSignTransactionError)) {
Expand Down
48 changes: 40 additions & 8 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { AnchorProvider } from "@coral-xyz/anchor";
import { init as initProp } from "@helium/proposal-sdk";
import {
HELIUM_COMMON_LUT,
HELIUM_COMMON_LUT_DEVNET,
batchInstructionsToTxsWithPriorityFee,
batchParallelInstructionsWithPriorityFee,
bulkSendTransactions,
sendAndConfirmWithRetry,
toVersionedTx,
} from "@helium/spl-utils";
import { PositionWithMeta } from "@helium/voter-stake-registry-hooks";
import { Mint } from "@solana/spl-token";
Expand Down Expand Up @@ -292,31 +296,59 @@ export const onInstructions =
instructions,
{
basePriorityFee: 2,
extraSigners: sigs,
addressLookupTableAddresses: [
provider.connection.rpcEndpoint.includes("test")
? HELIUM_COMMON_LUT_DEVNET
: HELIUM_COMMON_LUT,
],
}
);
const asVersionedTx = transactions.map(toVersionedTx);
let i = 0;
for (const tx of await provider.wallet.signAllTransactions(
transactions
asVersionedTx
)) {
const draft = transactions[i];
sigs.forEach((sig) => {
if (tx.signatures.some((s) => s.publicKey.equals(sig.publicKey))) {
tx.partialSign(sig);
if (draft.signers?.some((s) => s.publicKey.equals(sig.publicKey))) {
tx.sign([sig]);
}
});

await sendAndConfirmWithRetry(
provider.connection,
tx.serialize(),
Buffer.from(tx.serialize()),
{
skipPreflight: true,
},
"confirmed"
);
i++;
}
} else {
await batchParallelInstructionsWithPriorityFee(provider, instructions, {
basePriorityFee: 2,
maxSignatureBatch: MAX_TRANSACTIONS_PER_SIGNATURE_BATCH,
});
const transactions = await batchInstructionsToTxsWithPriorityFee(
provider,
instructions,
{
basePriorityFee: 2,
addressLookupTableAddresses: [
provider.connection.rpcEndpoint.includes("test")
? HELIUM_COMMON_LUT_DEVNET
: HELIUM_COMMON_LUT,
],
}
);
console.log("hehe")

await bulkSendTransactions(
provider,
transactions,
undefined,
5,
sigs,
MAX_TRANSACTIONS_PER_SIGNATURE_BATCH
);
}
}
};
Expand Down
Loading

0 comments on commit 33800c0

Please sign in to comment.