import { Address } from '@solana/addresses'; import { AccountRole } from './roles'; /** * Represents an account's address and metadata about its mutability and whether it must be a signer * of the transaction. * * Typically, you will use one of its subtypes. * * | | `role` | `isSigner` | `isWritable` | * | --------------------------------- | ----------------------------- | ---------- | ------------ | * | `ReadonlyAccount` | `AccountRole.READONLY` | No | No | * | `WritableAccount` | `AccountRole.WRITABLE` | No | Yes | * | `ReadonlySignerAccount` | `AccountRole.READONLY_SIGNER` | Yes | No | * | `WritableSignerAccount` | `AccountRole.WRITABLE_SIGNER` | Yes | Yes | * * @example A type for the Rent sysvar account * ```ts * type RentSysvar = ReadonlyAccount<'SysvarRent111111111111111111111111111111111'>; * ``` */ export interface AccountMeta { readonly address: Address; readonly role: AccountRole; } /** * @see {@link AccountMeta} */ export type ReadonlyAccount = AccountMeta & { readonly role: AccountRole.READONLY; }; /** * @see {@link AccountMeta} */ export type WritableAccount = AccountMeta & { role: AccountRole.WRITABLE }; /** * @see {@link AccountMeta} */ export type ReadonlySignerAccount = AccountMeta & { role: AccountRole.READONLY_SIGNER; }; /** * @see {@link AccountMeta} */ export type WritableSignerAccount = AccountMeta & { role: AccountRole.WRITABLE_SIGNER; }; /** * Represents a lookup of the account's address in an address lookup table. It specifies which * lookup table account in which to perform the lookup, the index of the desired account address in * that table, and metadata about its mutability. Notably, account addresses obtained via lookups * may not act as signers. * * Typically, you will use one of its subtypes. * * | | `role` | `isSigner` | `isWritable` | * | ------------------------------------------------------ | ---------------------- | ---------- | ------------ | * | `ReadonlyLookupAccount` | `AccountRole.READONLY` | No | No | * | `WritableLookupAccount` | `AccountRole.WRITABLE` | No | Yes | * * @example A type for the Rent sysvar account that you looked up in a lookup table * ```ts * type RentSysvar = ReadonlyLookupAccount< * 'SysvarRent111111111111111111111111111111111', * 'MyLookupTable111111111111111111111111111111' * >; * ``` */ export interface AccountLookupMeta { readonly address: Address; readonly addressIndex: number; readonly lookupTableAddress: Address; readonly role: AccountRole.READONLY | AccountRole.WRITABLE; } /** * @see {@link AccountLookupMeta} */ export type ReadonlyAccountLookup< TAddress extends string = string, TLookupTableAddress extends string = string, > = AccountLookupMeta & { readonly role: AccountRole.READONLY }; /** * @see {@link AccountLookupMeta} */ export type WritableAccountLookup< TAddress extends string = string, TLookupTableAddress extends string = string, > = AccountLookupMeta & { readonly role: AccountRole.WRITABLE };