diff --git a/clients/js/src/generated/instructions/allocate.ts b/clients/js/src/generated/instructions/allocate.ts index d3493e6..a300d37 100644 --- a/clients/js/src/generated/instructions/allocate.ts +++ b/clients/js/src/generated/instructions/allocate.ts @@ -52,9 +52,16 @@ export type AllocateInstruction< ] >; -export type AllocateInstructionData = { discriminator: number; space: bigint }; +export type AllocateInstructionData = { + discriminator: number; + /** The number of bytes to allocate */ + space: bigint; +}; -export type AllocateInstructionDataArgs = { space: number | bigint }; +export type AllocateInstructionDataArgs = { + /** The number of bytes to allocate */ + space: number | bigint; +}; export function getAllocateInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( @@ -81,6 +88,7 @@ export function getAllocateInstructionDataCodec(): FixedSizeCodec< } export type AllocateInput = { + /** The account to allocate space for */ newAccount: TransactionSigner; space: AllocateInstructionDataArgs['space']; }; @@ -116,6 +124,7 @@ export type ParsedAllocateInstruction< > = { programAddress: Address; accounts: { + /** The account to allocate space for */ newAccount: TAccountMetas[0]; }; data: AllocateInstructionData; diff --git a/clients/js/src/generated/instructions/createAccount.ts b/clients/js/src/generated/instructions/createAccount.ts index be3340d..cbf33c2 100644 --- a/clients/js/src/generated/instructions/createAccount.ts +++ b/clients/js/src/generated/instructions/createAccount.ts @@ -61,14 +61,20 @@ export type CreateAccountInstruction< export type CreateAccountInstructionData = { discriminator: number; + /** The amount of lamports to transfer to the new account */ lamports: bigint; + /** The number of bytes to allocate for the new account */ space: bigint; + /** The address of the program that will own the new account */ programAddress: Address; }; export type CreateAccountInstructionDataArgs = { + /** The amount of lamports to transfer to the new account */ lamports: number | bigint; + /** The number of bytes to allocate for the new account */ space: number | bigint; + /** The address of the program that will own the new account */ programAddress: Address; }; @@ -101,7 +107,9 @@ export function getCreateAccountInstructionDataCodec(): FixedSizeCodec< } export type CreateAccountInput = { + /** The account that will pay for the new account */ payer: TransactionSigner; + /** The account to create */ newAccount: TransactionSigner; lamports: CreateAccountInstructionDataArgs['lamports']; space: CreateAccountInstructionDataArgs['space']; @@ -147,7 +155,9 @@ export type ParsedCreateAccountInstruction< > = { programAddress: Address; accounts: { + /** The account that will pay for the new account */ payer: TAccountMetas[0]; + /** The account to create */ newAccount: TAccountMetas[1]; }; data: CreateAccountInstructionData; diff --git a/clients/js/src/generated/instructions/transferSol.ts b/clients/js/src/generated/instructions/transferSol.ts index df60340..42a0b0b 100644 --- a/clients/js/src/generated/instructions/transferSol.ts +++ b/clients/js/src/generated/instructions/transferSol.ts @@ -55,9 +55,16 @@ export type TransferSolInstruction< ] >; -export type TransferSolInstructionData = { discriminator: number; amount: bigint }; +export type TransferSolInstructionData = { + discriminator: number; + /** The amount of lamports to transfer */ + amount: bigint; +}; -export type TransferSolInstructionDataArgs = { amount: number | bigint }; +export type TransferSolInstructionDataArgs = { + /** The amount of lamports to transfer */ + amount: number | bigint; +}; export function getTransferSolInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( @@ -84,7 +91,9 @@ export function getTransferSolInstructionDataCodec(): FixedSizeCodec< } export type TransferSolInput = { + /** The account referencing the source of the transfer */ source: TransactionSigner; + /** The account referencing the destination of the transfer */ destination: Address; amount: TransferSolInstructionDataArgs['amount']; }; @@ -124,7 +133,9 @@ export type ParsedTransferSolInstruction< > = { programAddress: Address; accounts: { + /** The account referencing the source of the transfer */ source: TAccountMetas[0]; + /** The account referencing the destination of the transfer */ destination: TAccountMetas[1]; }; data: TransferSolInstructionData; diff --git a/clients/js/test/allocate.test.ts b/clients/js/test/allocate.test.ts new file mode 100644 index 0000000..cf56c2b --- /dev/null +++ b/clients/js/test/allocate.test.ts @@ -0,0 +1,60 @@ +import { + appendTransactionMessageInstruction, + fetchEncodedAccount, + generateKeyPairSigner, + pipe, + airdropFactory, + lamports, +} from '@solana/kit'; +import { it, expect } from 'vitest'; +import { getAllocateInstruction } from '../src'; +import { + createDefaultSolanaClient, + createDefaultTransaction, + generateKeyPairSignerWithSol, + signAndSendTransaction, +} from './_setup'; + +it('allocates space for an account', async () => { + // 1. Setup client and payer. + const client = createDefaultSolanaClient(); + const [payer, accountToAllocate] = await Promise.all([ + generateKeyPairSignerWithSol(client), + generateKeyPairSigner(), + ]); + + // 2. Airdrop lamports to the account so it exists (system owned, 0 data). + await airdropFactory(client)({ + recipientAddress: accountToAllocate.address, + lamports: lamports(await client.rpc.getMinimumBalanceForRentExemption(100n).send()), + commitment: 'confirmed', + }); + + // Verify initial state + let fetchedAccount = await fetchEncodedAccount(client.rpc, accountToAllocate.address); + expect(fetchedAccount.exists).toBe(true); + if (fetchedAccount.exists) { + expect(fetchedAccount.data.length).toBe(0); + } + + // 3. Use getAllocateInstruction to allocate 100 bytes. + const newSpace = 100n; + const allocate = getAllocateInstruction({ + newAccount: accountToAllocate, + space: newSpace, + }); + + // 4. Send transaction + await pipe( + await createDefaultTransaction(client, payer), + tx => appendTransactionMessageInstruction(allocate, tx), + tx => signAndSendTransaction(client, tx), + ); + + // 5. Verify the account's data length is exactly 100 bytes. + fetchedAccount = await fetchEncodedAccount(client.rpc, accountToAllocate.address); + expect(fetchedAccount.exists).toBe(true); + if (fetchedAccount.exists) { + expect(fetchedAccount.data.length).toBe(100); + } +});