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
17 changes: 0 additions & 17 deletions clients/js/.eslintrc.cjs

This file was deleted.

20 changes: 20 additions & 0 deletions clients/js/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import solanaConfig from '@solana-config/eslint';
import { defineConfig } from 'eslint/config';

export default defineConfig([
{ ignores: ['**/dist/**'] },
{ files: ['**/*.ts', '**/*.(c|m)?js'], extends: [solanaConfig] },
{
languageOptions: { parserOptions: { project: null } },
rules: {
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/sort-type-constituents': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'prefer-destructuring': 'off',
'simple-import-sort/imports': 'off',
'sort-keys-fix/sort-keys-fix': 'off',
'typescript-sort-keys/interface': 'off',
},
},
]);
12 changes: 7 additions & 5 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,25 @@
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"@solana-program/compute-budget": "^0.13.0",
"@solana-program/system": "^0.11.0",
"@solana-program/compute-budget": "^0.15.0",
"@solana-program/system": "^0.12.0",
"commander": "^13.0.0",
"pako": "^2.1.0",
"picocolors": "^1.1.1",
"yaml": "^2.7.0"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "^6.4.0",
"@solana-config/eslint": "^0.2.3",
"@solana/kit": "^6.9.0",
"@solana/kit-plugin-rpc": "^0.11.1",
"@solana/kit-plugin-signer": "^0.10.0",
"@types/node": "^24",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"ava": "^6.1.3",
"eslint": "^8.57.0",
"eslint": "^9.39.2",
"prettier": "^3.8.1",
"rimraf": "^5.0.5",
"tsup": "^8.1.2",
Expand Down
761 changes: 553 additions & 208 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions clients/js/src/cli/commands/create-buffer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { generateKeyPairSigner } from '@solana/kit';
import { getCreateBufferInstructionPlan } from '../../createBuffer';
import { getAccountSize } from '../../utils';
import { fileArgument } from '../arguments';
import { GlobalOptions, setWriteOptions, WriteOptions } from '../options';
import { CustomCommand, getClient, getWriteInput } from '../utils';
Expand All @@ -26,18 +25,14 @@ export async function doCreateBuffer(file: string | undefined, _: Options, cmd:
authority: client.authority.address,
});

const data = writeInput.buffer?.data.data ?? writeInput.data;
const rent = await client.rpc.getMinimumBalanceForRentExemption(getAccountSize(data.length)).send();

await client.planAndExecute(
getCreateBufferInstructionPlan({
await getCreateBufferInstructionPlan(client, {
newBuffer: buffer,
authority: client.authority,
payer: client.payer,
rent,
sourceBuffer: writeInput.buffer,
closeSourceBuffer: writeInput.closeBuffer,
data,
data: writeInput.buffer?.data.data ?? writeInput.data,
}),
);
}
4 changes: 1 addition & 3 deletions clients/js/src/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ export async function doCreate(seed: Seed, program: Address, file: string | unde
}

await client.planAndExecute(
await getCreateMetadataInstructionPlan({
...client,
await getCreateMetadataInstructionPlan(client, {
...writeInput,
payer: client.payer,
authority: client.authority,
program,
programData,
seed,
metadata,
planner: client.planner,
}),
);
}
9 changes: 2 additions & 7 deletions clients/js/src/cli/commands/update-buffer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, lamports } from '@solana/kit';
import { Address } from '@solana/kit';
import { fetchMaybeBuffer } from '../../generated';
import { getUpdateBufferInstructionPlan } from '../../updateBuffer';
import { bufferArgument, fileArgument } from '../arguments';
Expand Down Expand Up @@ -34,17 +34,12 @@ export async function doUpdateBuffer(buffer: Address, file: string | undefined,
const currentData = bufferAccount.data.data;
const newData = writeInput.buffer?.data.data ?? writeInput.data;
const sizeDifference = newData.length - currentData.length;
const extraRent =
sizeDifference > 0
? await client.rpc.getMinimumBalanceForRentExemption(BigInt(sizeDifference)).send()
: lamports(0n);

await client.planAndExecute(
getUpdateBufferInstructionPlan({
await getUpdateBufferInstructionPlan(client, {
buffer,
authority: client.authority,
payer: client.payer,
extraRent,
sizeDifference,
sourceBuffer: writeInput.buffer,
closeSourceBuffer: writeInput.closeBuffer,
Expand Down
4 changes: 1 addition & 3 deletions clients/js/src/cli/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ export async function doWrite(seed: Seed, program: Address, file: string | undef
}

await client.planAndExecute(
await getUpdateMetadataInstructionPlan({
...client,
await getUpdateMetadataInstructionPlan(client, {
...writeInput,
payer: client.payer,
authority: client.authority,
program,
programData,
metadata: metadataAccount,
planner: client.planner,
}),
);
}
4 changes: 1 addition & 3 deletions clients/js/src/cli/commands/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ export async function doWrite(seed: Seed, program: Address, file: string | undef
]);

await client.planAndExecute(
await getWriteMetadataInstructionPlan({
...client,
await getWriteMetadataInstructionPlan(client, {
...writeInput,
payer: client.payer,
authority: client.authority,
program,
programData,
seed,
metadata: metadataAccount,
planner: client.planner,
}),
);
}
2 changes: 1 addition & 1 deletion clients/js/src/cli/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function logTable(tabularData: unknown) {
});
const logger = new Console({ stdout: ts });
logger.table(tabularData);
const table: string = (ts.read() || '').toString();
const table: string = ((ts.read() as { toString: () => string } | null) || '').toString();
let result = '';
for (const row of table.split(/[\r\n]+/)) {
let r = row.replace(/[^┬]*┬/, '┌');
Expand Down
44 changes: 36 additions & 8 deletions clients/js/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ import {
AccountRole,
Address,
address,
BASE_ACCOUNT_SIZE,
ClientWithGetMinimumBalance,
ClientWithTransactionPlanning,
Commitment,
compileTransaction,
createKeyPairSignerFromBytes,
createNoopSigner,
createSolanaRpc,
createSolanaRpcSubscriptions,
flattenTransactionPlan,
GetMinimumBalanceConfig,
getTransactionEncoder,
InstructionPlan,
Lamports,
lamports,
MessageSigner,
pipe,
Rpc,
Expand Down Expand Up @@ -67,13 +73,15 @@ export class CustomCommand extends Command {
}
}

export type Client = ReadonlyClient & {
authority: TransactionSigner & MessageSigner;
executor: TransactionPlanExecutor;
payer: TransactionSigner & MessageSigner;
planAndExecute: (instructionPlan: InstructionPlan) => Promise<void>;
planner: TransactionPlanner;
};
export type Client = ReadonlyClient &
ClientWithGetMinimumBalance &
ClientWithTransactionPlanning & {
authority: TransactionSigner & MessageSigner;
executor: TransactionPlanExecutor;
payer: TransactionSigner & MessageSigner;
planAndExecute: (instructionPlan: InstructionPlan) => Promise<void>;
planner: TransactionPlanner;
};

export async function getClient(options: GlobalOptions): Promise<Client> {
const readonlyClient = getReadonlyClient(options);
Expand All @@ -93,13 +101,33 @@ export async function getClient(options: GlobalOptions): Promise<Client> {
await executeTransactionPlan(transactionPlan, executor);
}
};
const getMinimumBalance = async (space: number, config?: GetMinimumBalanceConfig): Promise<Lamports> => {
if (config?.withoutHeader) {
const headerBalance = await readonlyClient.rpc.getMinimumBalanceForRentExemption(0n).send();
const lamportsPerByte = BigInt(headerBalance) / BigInt(BASE_ACCOUNT_SIZE);
return lamports(lamportsPerByte * BigInt(space));
}
return await readonlyClient.rpc.getMinimumBalanceForRentExemption(BigInt(space)).send();
};
const planTransaction: ClientWithTransactionPlanning['planTransaction'] = async (input, config) => {
const transactionPlan = await planner(input as InstructionPlan, config);
if (transactionPlan.kind !== 'single') {
throw new Error('Expected a single transaction plan');
}
return transactionPlan.message;
};
const planTransactions: ClientWithTransactionPlanning['planTransactions'] = async (input, config) =>
await planner(input as InstructionPlan, config);
return {
...readonlyClient,
authority,
executor,
getMinimumBalance,
payer,
planAndExecute,
planner,
planTransaction,
planTransactions,
};
}

Expand Down Expand Up @@ -222,7 +250,7 @@ function getSolanaConfigs(): SolanaConfigs {
logWarning('Solana config file not found');
return {};
}
return parseYaml(fs.readFileSync(getSolanaConfigPath(), 'utf8'));
return parseYaml(fs.readFileSync(getSolanaConfigPath(), 'utf8')) as SolanaConfigs;
}

function getSolanaConfigPath(): string {
Expand Down
Loading
Loading