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
577 changes: 86 additions & 491 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
},
"license": "MIT",
"peerDependencies": {
"@solana/kit": "3.0.0"
"@solana/kit": "^6.4.0"
},
"devDependencies": {
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "3.0.0",
"@solana/kit": "^6.4.0",
"@solana/webcrypto-ed25519-polyfill": "3.0.3",
"@types/node": "^24",
"@typescript-eslint/eslint-plugin": "^7.16.1",
Expand Down
1,469 changes: 861 additions & 608 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions clients/js/src/generated/errors/solanaFeatureGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type SolanaFeatureGateError =
let solanaFeatureGateErrorMessages:
| Record<SolanaFeatureGateError, string>
| undefined;
if (process.env.NODE_ENV !== 'production') {
if (process.env['NODE_ENV'] !== 'production') {
solanaFeatureGateErrorMessages = {
[SOLANA_FEATURE_GATE_ERROR__FEATURE_ALREADY_ACTIVATED]: `Feature already activated`,
};
Expand All @@ -32,7 +32,7 @@ if (process.env.NODE_ENV !== 'production') {
export function getSolanaFeatureGateErrorMessage(
code: SolanaFeatureGateError
): string {
if (process.env.NODE_ENV !== 'production') {
if (process.env['NODE_ENV'] !== 'production') {
return (
solanaFeatureGateErrorMessages as Record<SolanaFeatureGateError, string>
)[code];
Expand Down
31 changes: 20 additions & 11 deletions clients/js/src/generated/instructions/revokePendingActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
getStructEncoder,
getU8Decoder,
getU8Encoder,
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
SolanaError,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
Expand All @@ -28,22 +30,24 @@ import {
type WritableAccount,
type WritableSignerAccount,
} from '@solana/kit';
import {
getAccountMetaFactory,
type ResolvedInstructionAccount,
} from '@solana/kit/program-client-core';
import { SOLANA_FEATURE_GATE_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const REVOKE_PENDING_ACTIVATION_DISCRIMINATOR = 0;

export function getRevokePendingActivationDiscriminatorBytes() {
export function getRevokePendingActivationDiscriminatorBytes(): ReadonlyUint8Array {
return getU8Encoder().encode(REVOKE_PENDING_ACTIVATION_DISCRIMINATOR);
}

export type RevokePendingActivationInstruction<
TProgram extends string = typeof SOLANA_FEATURE_GATE_PROGRAM_ADDRESS,
TAccountFeature extends string | AccountMeta<string> = string,
TAccountIncinerator extends string | AccountMeta<string> = string,
TAccountSystemProgram extends
| string
| AccountMeta<string> = '11111111111111111111111111111111',
TAccountSystemProgram extends string | AccountMeta<string> =
'11111111111111111111111111111111',
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
Expand Down Expand Up @@ -134,7 +138,7 @@ export function getRevokePendingActivationInstruction<
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedAccount
ResolvedInstructionAccount
>;

// Resolve default values.
Expand All @@ -146,9 +150,9 @@ export function getRevokePendingActivationInstruction<
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.feature),
getAccountMeta(accounts.incinerator),
getAccountMeta(accounts.systemProgram),
getAccountMeta('feature', accounts.feature),
getAccountMeta('incinerator', accounts.incinerator),
getAccountMeta('systemProgram', accounts.systemProgram),
],
data: getRevokePendingActivationInstructionDataEncoder().encode({}),
programAddress,
Expand Down Expand Up @@ -185,8 +189,13 @@ export function parseRevokePendingActivationInstruction<
InstructionWithData<ReadonlyUint8Array>
): ParsedRevokePendingActivationInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 3) {
// TODO: Coded error.
throw new Error('Not enough accounts');
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
{
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 3,
}
);
}
let accountIndex = 0;
const getNextAccount = () => {
Expand Down
82 changes: 79 additions & 3 deletions clients/js/src/generated/programs/solanaFeatureGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,30 @@
*/

import {
assertIsInstructionWithAccounts,
containsBytes,
extendClient,
getU8Encoder,
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
SolanaError,
type Address,
type ClientWithTransactionPlanning,
type ClientWithTransactionSending,
type Instruction,
type InstructionWithData,
type ReadonlyUint8Array,
} from '@solana/kit';
import { type ParsedRevokePendingActivationInstruction } from '../instructions';
import {
addSelfPlanAndSendFunctions,
type SelfPlanAndSendFunctions,
} from '@solana/kit/program-client-core';
import {
getRevokePendingActivationInstruction,
parseRevokePendingActivationInstruction,
type ParsedRevokePendingActivationInstruction,
type RevokePendingActivationInput,
} from '../instructions';

export const SOLANA_FEATURE_GATE_PROGRAM_ADDRESS =
'Feature111111111111111111111111111111111111' as Address<'Feature111111111111111111111111111111111111'>;
Expand All @@ -28,8 +46,9 @@ export function identifySolanaFeatureGateInstruction(
if (containsBytes(data, getU8Encoder().encode(0), 0)) {
return SolanaFeatureGateInstruction.RevokePendingActivation;
}
throw new Error(
'The provided instruction could not be identified as a solanaFeatureGate instruction.'
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
{ instructionData: data, programName: 'solanaFeatureGate' }
);
}

Expand All @@ -38,3 +57,60 @@ export type ParsedSolanaFeatureGateInstruction<
> = {
instructionType: SolanaFeatureGateInstruction.RevokePendingActivation;
} & ParsedRevokePendingActivationInstruction<TProgram>;

export function parseSolanaFeatureGateInstruction<TProgram extends string>(
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>
): ParsedSolanaFeatureGateInstruction<TProgram> {
const instructionType = identifySolanaFeatureGateInstruction(instruction);
switch (instructionType) {
case SolanaFeatureGateInstruction.RevokePendingActivation: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: SolanaFeatureGateInstruction.RevokePendingActivation,
...parseRevokePendingActivationInstruction(instruction),
};
}
default:
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
{
instructionType: instructionType as string,
programName: 'solanaFeatureGate',
}
);
}
}

export type SolanaFeatureGatePlugin = {
instructions: SolanaFeatureGatePluginInstructions;
};

export type SolanaFeatureGatePluginInstructions = {
revokePendingActivation: (
input: RevokePendingActivationInput
) => ReturnType<typeof getRevokePendingActivationInstruction> &
SelfPlanAndSendFunctions;
};

export type SolanaFeatureGatePluginRequirements =
ClientWithTransactionPlanning & ClientWithTransactionSending;

export function solanaFeatureGateProgram() {
return <T extends SolanaFeatureGatePluginRequirements>(
client: T
): Omit<T, 'solanaFeatureGate'> & {
solanaFeatureGate: SolanaFeatureGatePlugin;
} => {
return extendClient(client, {
solanaFeatureGate: <SolanaFeatureGatePlugin>{
instructions: {
revokePendingActivation: (input) =>
addSelfPlanAndSendFunctions(
client,
getRevokePendingActivationInstruction(input)
),
},
},
});
};
}
164 changes: 0 additions & 164 deletions clients/js/src/generated/shared/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion clients/js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
Loading
Loading