Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to versioned tx and LUTs #148

Merged
merged 1 commit into from
Apr 29, 2024
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
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
Loading