Skip to content

Commit 0fe047f

Browse files
authored
Upgrade JS client to Kit v3 (#23)
1 parent d9aba43 commit 0fe047f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1111
-4379
lines changed

clients/js/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,23 @@
4545
"homepage": "https://github.com/solana-program/program-metadata#readme",
4646
"license": "MIT",
4747
"peerDependencies": {
48-
"@solana/kit": "^2.1.0"
48+
"@solana/kit": "^3.0"
4949
},
5050
"dependencies": {
5151
"@iarna/toml": "^2.2.5",
52-
"@solana-program/compute-budget": "^0.7.0",
53-
"@solana-program/system": "^0.7.0",
52+
"@solana-program/compute-budget": "^0.9.0",
53+
"@solana-program/system": "^0.8.0",
5454
"commander": "^13.0.0",
55+
"p-limit": "^7.1.1",
5556
"pako": "^2.1.0",
5657
"picocolors": "^1.1.1",
5758
"yaml": "^2.7.0"
5859
},
5960
"devDependencies": {
6061
"@ava/typescript": "^4.1.0",
6162
"@solana/eslint-config-solana": "^3.0.3",
62-
"@solana/kit": "^2.1.0",
63-
"@types/node": "^22",
63+
"@solana/kit": "^3.0",
64+
"@types/node": "^24",
6465
"@types/pako": "^2.0.3",
6566
"@typescript-eslint/eslint-plugin": "^7.16.1",
6667
"@typescript-eslint/parser": "^7.16.1",

clients/js/pnpm-lock.yaml

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

clients/js/src/cli/commands/close-buffer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Address } from '@solana/kit';
1+
import { Address, sequentialInstructionPlan } from '@solana/kit';
22
import { fetchMaybeBuffer, getCloseInstruction } from '../../generated';
3-
import { sequentialInstructionPlan } from '../../instructionPlans';
43
import { bufferArgument } from '../arguments';
54
import { logCommand, logErrorAndExit } from '../logs';
65
import { GlobalOptions } from '../options';

clients/js/src/cli/commands/close.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Address } from '@solana/kit';
1+
import { Address, sequentialInstructionPlan } from '@solana/kit';
22
import { getCloseInstruction, Seed } from '../../generated';
3-
import { sequentialInstructionPlan } from '../../instructionPlans';
43
import { programArgument, seedArgument } from '../arguments';
54
import {
65
GlobalOptions,

clients/js/src/cli/commands/list-buffers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Address,
3+
Base64EncodedBytes,
34
getAddressEncoder,
45
getBase64Decoder,
56
GetProgramAccountsMemcmpFilter,
@@ -74,7 +75,7 @@ function getDiscriminatorFilter(): GetProgramAccountsMemcmpFilter {
7475
AccountDiscriminator.Buffer,
7576
getAccountDiscriminatorEncoder().encode,
7677
getBase64Decoder().decode
77-
),
78+
) as Base64EncodedBytes,
7879
encoding: 'base64',
7980
offset: DISCRIMINATOR_OFFSET,
8081
},
@@ -90,7 +91,7 @@ function getAuthorityFilter(
9091
authority,
9192
getAddressEncoder().encode,
9293
getBase64Decoder().decode
93-
),
94+
) as Base64EncodedBytes,
9495
encoding: 'base64',
9596
offset: AUTHORITY_OFFSET,
9697
},

clients/js/src/cli/commands/remove-authority.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Address } from '@solana/kit';
1+
import { Address, sequentialInstructionPlan } from '@solana/kit';
22
import { getSetAuthorityInstruction, Seed } from '../../generated';
3-
import { sequentialInstructionPlan } from '../../instructionPlans';
43
import { getPdaDetails } from '../../internals';
54
import { programArgument, seedArgument } from '../arguments';
65
import { GlobalOptions } from '../options';

clients/js/src/cli/commands/set-authority.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Address } from '@solana/kit';
1+
import { Address, sequentialInstructionPlan } from '@solana/kit';
22
import { getSetAuthorityInstruction, Seed } from '../../generated';
3-
import { sequentialInstructionPlan } from '../../instructionPlans';
43
import { getPdaDetails } from '../../internals';
54
import { programArgument, seedArgument } from '../arguments';
65
import { logCommand } from '../logs';

clients/js/src/cli/commands/set-buffer-authority.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Address } from '@solana/kit';
1+
import { Address, sequentialInstructionPlan } from '@solana/kit';
22
import { getSetAuthorityInstruction } from '../../generated';
3-
import { sequentialInstructionPlan } from '../../instructionPlans';
43
import { bufferArgument } from '../arguments';
54
import { logCommand } from '../logs';
65
import {

clients/js/src/cli/commands/set-immutable.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Address } from '@solana/kit';
1+
import { Address, sequentialInstructionPlan } from '@solana/kit';
22
import { getSetImmutableInstruction, Seed } from '../../generated';
3-
import { sequentialInstructionPlan } from '../../instructionPlans';
43
import { programArgument, seedArgument } from '../arguments';
54
import { logCommand } from '../logs';
65
import {

clients/js/src/cli/utils.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@ import {
66
Account,
77
Address,
88
address,
9+
BaseTransactionMessage,
910
Commitment,
10-
CompilableTransactionMessage,
1111
compileTransaction,
1212
createKeyPairSignerFromBytes,
1313
createNoopSigner,
1414
createSolanaRpc,
1515
createSolanaRpcSubscriptions,
16+
getAllSingleTransactionPlans,
1617
getTransactionEncoder,
18+
InstructionPlan,
1719
MessageSigner,
1820
pipe,
1921
Rpc,
2022
RpcSubscriptions,
2123
setTransactionMessageLifetimeUsingBlockhash,
2224
SolanaRpcApi,
2325
SolanaRpcSubscriptionsApi,
26+
TransactionMessageWithFeePayer,
27+
TransactionPlan,
28+
TransactionPlanExecutor,
29+
TransactionPlanner,
2430
TransactionSigner,
2531
} from '@solana/kit';
2632
import { Command } from 'commander';
2733
import picocolors from 'picocolors';
2834
import { parse as parseYaml } from 'yaml';
2935
import { Buffer, DataSource, fetchBuffer, Format, Seed } from '../generated';
3036
import {
31-
createDefaultTransactionPlanExecutor,
32-
createDefaultTransactionPlanner,
33-
getAllSingleTransactionPlans,
34-
getSetComputeUnitLimitInstructionIndex,
35-
InstructionPlan,
36-
TransactionPlan,
37-
TransactionPlanExecutor,
38-
TransactionPlanner,
39-
} from '../instructionPlans';
40-
import { getPdaDetails, PdaDetails } from '../internals';
37+
createDefaultTransactionPlannerAndExecutor,
38+
getPdaDetails,
39+
PdaDetails,
40+
} from '../internals';
4141
import {
4242
decodeData,
4343
packDirectData,
@@ -55,6 +55,11 @@ import {
5555
RpcOption,
5656
WriteOptions,
5757
} from './options';
58+
import {
59+
COMPUTE_BUDGET_PROGRAM_ADDRESS,
60+
ComputeBudgetInstruction,
61+
identifyComputeBudgetInstruction,
62+
} from '@solana-program/compute-budget';
5863

5964
const LOCALHOST_URL = 'http://127.0.0.1:8899';
6065
const DATA_SOURCE_OPTIONS =
@@ -85,14 +90,12 @@ export async function getClient(options: GlobalOptions): Promise<Client> {
8590
options,
8691
readonlyClient.configs
8792
);
88-
const planner = createDefaultTransactionPlanner({
89-
feePayer: payer,
90-
computeUnitPrice: options.priorityFees,
91-
});
92-
const executor = createDefaultTransactionPlanExecutor({
93+
const { planner, executor } = createDefaultTransactionPlannerAndExecutor({
94+
priorityFees: options.priorityFees,
95+
payer,
9396
rpc: readonlyClient.rpc,
9497
rpcSubscriptions: readonlyClient.rpcSubscriptions,
95-
parallelChunkSize: 5,
98+
concurrency: 5,
9699
});
97100
const planAndExecute = async (instructionPlan: InstructionPlan) => {
98101
const transactionPlan = await planner(instructionPlan);
@@ -129,8 +132,8 @@ async function exportTransactionPlan(
129132
for (let i = 0; i < singleTransactions.length; i++) {
130133
const transaction = pipe(
131134
singleTransactions[i].message,
132-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
133-
removeComputeUnitLimitInstruction,
135+
(m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
136+
(m) => removeComputeUnitLimitInstruction(m),
134137
compileTransaction
135138
);
136139
const encodedTransaction = decodeData(
@@ -143,7 +146,8 @@ async function exportTransactionPlan(
143146
}
144147

145148
function removeComputeUnitLimitInstruction<
146-
TTransactionMessage extends CompilableTransactionMessage,
149+
TTransactionMessage extends BaseTransactionMessage &
150+
TransactionMessageWithFeePayer,
147151
>(message: TTransactionMessage): TTransactionMessage {
148152
const index = getSetComputeUnitLimitInstructionIndex(message);
149153
if (index === -1) return message;
@@ -153,6 +157,18 @@ function removeComputeUnitLimitInstruction<
153157
};
154158
}
155159

160+
export function getSetComputeUnitLimitInstructionIndex(
161+
transactionMessage: BaseTransactionMessage
162+
) {
163+
return transactionMessage.instructions.findIndex((ix) => {
164+
return (
165+
ix.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS &&
166+
identifyComputeBudgetInstruction(ix.data as Uint8Array) ===
167+
ComputeBudgetInstruction.SetComputeUnitLimit
168+
);
169+
});
170+
}
171+
156172
async function executeTransactionPlan(
157173
transactionPlan: TransactionPlan,
158174
executor: TransactionPlanExecutor

0 commit comments

Comments
 (0)