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
212 changes: 212 additions & 0 deletions clients/js/src/generated/instructions/createAccountAllowPrefund.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/

import {
BASE_ACCOUNT_SIZE,
combineCodec,
getAddressDecoder,
getAddressEncoder,
getStructDecoder,
getStructEncoder,
getU32Decoder,
getU32Encoder,
getU64Decoder,
getU64Encoder,
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
SolanaError,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
type Address,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type Instruction,
type InstructionWithAccounts,
type InstructionWithData,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableSignerAccount,
} from '@solana/kit';
import {
getAccountMetaFactory,
type InstructionWithByteDelta,
type ResolvedInstructionAccount,
} from '@solana/kit/program-client-core';
import { SYSTEM_PROGRAM_ADDRESS } from '../programs';

export const CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR = 13;

export function getCreateAccountAllowPrefundDiscriminatorBytes(): ReadonlyUint8Array {
return getU32Encoder().encode(CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR);
}

export type CreateAccountAllowPrefundInstruction<
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
TAccountNewAccount extends string | AccountMeta<string> = string,
TAccountPayer extends string | AccountMeta<string> | undefined = undefined,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountNewAccount extends string
? WritableSignerAccount<TAccountNewAccount> & AccountSignerMeta<TAccountNewAccount>
: TAccountNewAccount,
...(TAccountPayer extends undefined
? []
: [
TAccountPayer extends string
? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer>
: TAccountPayer,
]),
...TRemainingAccounts,
]
>;

export type CreateAccountAllowPrefundInstructionData = {
discriminator: number;
lamports: bigint;
space: bigint;
programAddress: Address;
};

export type CreateAccountAllowPrefundInstructionDataArgs = {
lamports?: number | bigint;
space: number | bigint;
programAddress: Address;
};

export function getCreateAccountAllowPrefundInstructionDataEncoder(): FixedSizeEncoder<CreateAccountAllowPrefundInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU32Encoder()],
['lamports', getU64Encoder()],
['space', getU64Encoder()],
['programAddress', getAddressEncoder()],
]),
value => ({
...value,
discriminator: CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR,
lamports: value.lamports ?? 0,
}),
);
}

export function getCreateAccountAllowPrefundInstructionDataDecoder(): FixedSizeDecoder<CreateAccountAllowPrefundInstructionData> {
return getStructDecoder([
['discriminator', getU32Decoder()],
['lamports', getU64Decoder()],
['space', getU64Decoder()],
['programAddress', getAddressDecoder()],
]);
}

export function getCreateAccountAllowPrefundInstructionDataCodec(): FixedSizeCodec<
CreateAccountAllowPrefundInstructionDataArgs,
CreateAccountAllowPrefundInstructionData
> {
return combineCodec(
getCreateAccountAllowPrefundInstructionDataEncoder(),
getCreateAccountAllowPrefundInstructionDataDecoder(),
);
}

export type CreateAccountAllowPrefundInput<
TAccountNewAccount extends string = string,
TAccountPayer extends string = string,
> = {
newAccount: TransactionSigner<TAccountNewAccount>;
payer?: TransactionSigner<TAccountPayer>;
lamports?: CreateAccountAllowPrefundInstructionDataArgs['lamports'];
space: CreateAccountAllowPrefundInstructionDataArgs['space'];
programAddress: CreateAccountAllowPrefundInstructionDataArgs['programAddress'];
};

export function getCreateAccountAllowPrefundInstruction<
TAccountNewAccount extends string,
TAccountPayer extends string,
TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
>(
input: CreateAccountAllowPrefundInput<TAccountNewAccount, TAccountPayer>,
config?: { programAddress?: TProgramAddress },
): CreateAccountAllowPrefundInstruction<TProgramAddress, TAccountNewAccount, TAccountPayer> & InstructionWithByteDelta {
// Program address.
const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
newAccount: { value: input.newAccount ?? null, isWritable: true },
payer: { value: input.payer ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;

// Original args.
const args = { ...input };

// Bytes created or reallocated by the instruction.
const byteDelta: number = [Number(args.space) + BASE_ACCOUNT_SIZE].reduce((a, b) => a + b, 0);

const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
return Object.freeze({
accounts: [getAccountMeta('newAccount', accounts.newAccount), getAccountMeta('payer', accounts.payer)].filter(
<T>(x: T | undefined): x is T => x !== undefined,
),
byteDelta,
data: getCreateAccountAllowPrefundInstructionDataEncoder().encode(
args as CreateAccountAllowPrefundInstructionDataArgs,
),
programAddress,
} as CreateAccountAllowPrefundInstruction<TProgramAddress, TAccountNewAccount, TAccountPayer> &
InstructionWithByteDelta);
}

export type ParsedCreateAccountAllowPrefundInstruction<
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
newAccount: TAccountMetas[0];
payer?: TAccountMetas[1] | undefined;
};
data: CreateAccountAllowPrefundInstructionData;
};

export function parseCreateAccountAllowPrefundInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedCreateAccountAllowPrefundInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 1) {
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 1,
});
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
accountIndex += 1;
return accountMeta;
};
let optionalAccountsRemaining = instruction.accounts.length - 1;
const getNextOptionalAccount = () => {
if (optionalAccountsRemaining === 0) return undefined;
optionalAccountsRemaining -= 1;
return getNextAccount();
};
return {
programAddress: instruction.programAddress,
accounts: { newAccount: getNextAccount(), payer: getNextOptionalAccount() },
data: getCreateAccountAllowPrefundInstructionDataDecoder().decode(instruction.data),
};
}
1 change: 1 addition & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './assign';
export * from './assignWithSeed';
export * from './authorizeNonceAccount';
export * from './createAccount';
export * from './createAccountAllowPrefund';
export * from './createAccountWithSeed';
export * from './initializeNonceAccount';
export * from './transferSol';
Expand Down
25 changes: 24 additions & 1 deletion clients/js/src/generated/programs/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getAssignInstruction,
getAssignWithSeedInstruction,
getAuthorizeNonceAccountInstruction,
getCreateAccountAllowPrefundInstruction,
getCreateAccountInstruction,
getCreateAccountWithSeedInstruction,
getInitializeNonceAccountInstruction,
Expand All @@ -52,6 +53,7 @@ import {
parseAssignInstruction,
parseAssignWithSeedInstruction,
parseAuthorizeNonceAccountInstruction,
parseCreateAccountAllowPrefundInstruction,
parseCreateAccountInstruction,
parseCreateAccountWithSeedInstruction,
parseInitializeNonceAccountInstruction,
Expand All @@ -65,6 +67,7 @@ import {
type AssignInput,
type AssignWithSeedInput,
type AuthorizeNonceAccountInput,
type CreateAccountAllowPrefundInput,
type CreateAccountInput,
type CreateAccountWithSeedInput,
type InitializeNonceAccountInput,
Expand All @@ -74,6 +77,7 @@ import {
type ParsedAssignInstruction,
type ParsedAssignWithSeedInstruction,
type ParsedAuthorizeNonceAccountInstruction,
type ParsedCreateAccountAllowPrefundInstruction,
type ParsedCreateAccountInstruction,
type ParsedCreateAccountWithSeedInstruction,
type ParsedInitializeNonceAccountInstruction,
Expand Down Expand Up @@ -107,6 +111,7 @@ export enum SystemInstruction {
AssignWithSeed,
TransferSolWithSeed,
UpgradeNonceAccount,
CreateAccountAllowPrefund,
}

export function identifySystemInstruction(
Expand Down Expand Up @@ -152,6 +157,9 @@ export function identifySystemInstruction(
if (containsBytes(data, getU32Encoder().encode(12), 0)) {
return SystemInstruction.UpgradeNonceAccount;
}
if (containsBytes(data, getU32Encoder().encode(13), 0)) {
return SystemInstruction.CreateAccountAllowPrefund;
}
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, {
instructionData: data,
programName: 'system',
Expand All @@ -173,7 +181,10 @@ export type ParsedSystemInstruction<TProgram extends string = '11111111111111111
| ({ instructionType: SystemInstruction.AllocateWithSeed } & ParsedAllocateWithSeedInstruction<TProgram>)
| ({ instructionType: SystemInstruction.AssignWithSeed } & ParsedAssignWithSeedInstruction<TProgram>)
| ({ instructionType: SystemInstruction.TransferSolWithSeed } & ParsedTransferSolWithSeedInstruction<TProgram>)
| ({ instructionType: SystemInstruction.UpgradeNonceAccount } & ParsedUpgradeNonceAccountInstruction<TProgram>);
| ({ instructionType: SystemInstruction.UpgradeNonceAccount } & ParsedUpgradeNonceAccountInstruction<TProgram>)
| ({
instructionType: SystemInstruction.CreateAccountAllowPrefund;
} & ParsedCreateAccountAllowPrefundInstruction<TProgram>);

export function parseSystemInstruction<TProgram extends string>(
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
Expand Down Expand Up @@ -259,6 +270,13 @@ export function parseSystemInstruction<TProgram extends string>(
...parseUpgradeNonceAccountInstruction(instruction),
};
}
case SystemInstruction.CreateAccountAllowPrefund: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: SystemInstruction.CreateAccountAllowPrefund,
...parseCreateAccountAllowPrefundInstruction(instruction),
};
}
default:
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, {
instructionType: instructionType as string,
Expand Down Expand Up @@ -305,6 +323,9 @@ export type SystemPluginInstructions = {
upgradeNonceAccount: (
input: UpgradeNonceAccountInput,
) => ReturnType<typeof getUpgradeNonceAccountInstruction> & SelfPlanAndSendFunctions;
createAccountAllowPrefund: (
input: CreateAccountAllowPrefundInput,
) => ReturnType<typeof getCreateAccountAllowPrefundInstruction> & SelfPlanAndSendFunctions;
};

export type SystemPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMultipleAccountsApi> &
Expand Down Expand Up @@ -346,6 +367,8 @@ export function systemProgram() {
addSelfPlanAndSendFunctions(client, getTransferSolWithSeedInstruction(input)),
upgradeNonceAccount: input =>
addSelfPlanAndSendFunctions(client, getUpgradeNonceAccountInstruction(input)),
createAccountAllowPrefund: input =>
addSelfPlanAndSendFunctions(client, getCreateAccountAllowPrefundInstruction(input)),
},
},
});
Expand Down
Loading