diff --git a/.changeset/witty-dryers-beg.md b/.changeset/witty-dryers-beg.md new file mode 100644 index 000000000..8d46cc915 --- /dev/null +++ b/.changeset/witty-dryers-beg.md @@ -0,0 +1,5 @@ +--- +"@metaplex-foundation/kinobi": minor +--- + +Use account name directly for data types and codecs diff --git a/src/renderers/js-experimental/fragments/accountFetchHelpers.njk b/src/renderers/js-experimental/fragments/accountFetchHelpers.njk index 86ab9fbb8..30ba502b3 100644 --- a/src/renderers/js-experimental/fragments/accountFetchHelpers.njk +++ b/src/renderers/js-experimental/fragments/accountFetchHelpers.njk @@ -1,6 +1,6 @@ -export function {{ decodeFunction }}(encodedAccount: EncodedAccount): {{ accountType }}; -export function {{ decodeFunction }}(encodedAccount: MaybeEncodedAccount): {{ accountMaybeType }}; -export function {{ decodeFunction }}(encodedAccount: EncodedAccount | MaybeEncodedAccount): {{ accountType }} | {{ accountMaybeType }} { +export function {{ decodeFunction }}(encodedAccount: EncodedAccount): Account<{{ accountType }}, TAddress>; +export function {{ decodeFunction }}(encodedAccount: MaybeEncodedAccount): MaybeAccount<{{ accountType }}, TAddress>; +export function {{ decodeFunction }}(encodedAccount: EncodedAccount | MaybeEncodedAccount): Account<{{ accountType }}, TAddress> | MaybeAccount<{{ accountType }}, TAddress> { return decodeAccount(encodedAccount as MaybeEncodedAccount, {{ decoderFunction }}); } @@ -8,7 +8,7 @@ export async function {{ fetchFunction }}( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, -): Promise<{{ accountType }}> { +): Promise> { const maybeAccount = await {{ fetchMaybeFunction }}(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -18,7 +18,7 @@ export async function {{ fetchMaybeFunction }} rpc: Parameters[0], address: Address, config?: FetchAccountConfig, -): Promise<{{ accountMaybeType }}> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return {{ decodeFunction }}(maybeAccount); } @@ -27,7 +27,7 @@ export async function {{ fetchAllFunction }}( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, -): Promise<{{ accountType }}[]> { +): Promise[]> { const maybeAccounts = await {{ fetchAllMaybeFunction }}(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; @@ -37,7 +37,7 @@ export async function {{ fetchAllMaybeFunction }}( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, -): Promise<{{ accountMaybeType }}[]> { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => {{ decodeFunction }}(maybeAccount)); } diff --git a/src/renderers/js-experimental/fragments/accountFetchHelpers.ts b/src/renderers/js-experimental/fragments/accountFetchHelpers.ts index a88974fdc..68e5f6322 100644 --- a/src/renderers/js-experimental/fragments/accountFetchHelpers.ts +++ b/src/renderers/js-experimental/fragments/accountFetchHelpers.ts @@ -10,15 +10,17 @@ export function getAccountFetchHelpersFragment( } ): Fragment { const { accountNode, typeManifest, nameApi, customAccountData } = scope; - const accountDataName = nameApi.accountDataType(accountNode.name); - const decoderFunctionFragment = customAccountData.has(accountNode.name) + const hasCustomData = customAccountData.has(accountNode.name); + const accountTypeFragment = hasCustomData + ? typeManifest.strictType.clone() + : fragment(nameApi.dataType(accountNode.name)); + const decoderFunctionFragment = hasCustomData ? typeManifest.decoder.clone() - : fragment(`${nameApi.decoderFunction(accountDataName)}()`); + : fragment(`${nameApi.decoderFunction(accountNode.name)}()`); return fragmentFromTemplate('accountFetchHelpers.njk', { decoderFunction: decoderFunctionFragment.render, - accountType: nameApi.accountType(accountNode.name), - accountMaybeType: nameApi.accountMaybeType(accountNode.name), + accountType: accountTypeFragment.render, decodeFunction: nameApi.accountDecodeFunction(accountNode.name), fetchFunction: nameApi.accountFetchFunction(accountNode.name), fetchMaybeFunction: nameApi.accountFetchMaybeFunction(accountNode.name), @@ -27,9 +29,10 @@ export function getAccountFetchHelpersFragment( accountNode.name ), }) - .mergeImportsWith(decoderFunctionFragment) + .mergeImportsWith(accountTypeFragment, decoderFunctionFragment) .addImports('solanaAddresses', ['Address']) .addImports('solanaAccounts', [ + 'Account', 'assertAccountExists', 'assertAccountsExist', 'decodeAccount', @@ -38,6 +41,7 @@ export function getAccountFetchHelpersFragment( 'fetchEncodedAccounts', 'FetchAccountConfig', 'FetchAccountsConfig', + 'MaybeAccount', 'MaybeEncodedAccount', ]); } diff --git a/src/renderers/js-experimental/fragments/accountPdaHelpers.njk b/src/renderers/js-experimental/fragments/accountPdaHelpers.njk index 0cbc77bf2..f8e276886 100644 --- a/src/renderers/js-experimental/fragments/accountPdaHelpers.njk +++ b/src/renderers/js-experimental/fragments/accountPdaHelpers.njk @@ -6,7 +6,7 @@ export async function {{ fetchFromSeedsFunction }}( seeds: {{ pdaSeedsType }}, {% endif %} config: FetchAccountConfig & { programAddress?: Address } = {}, -): Promise<{{ accountType }}> { +): Promise> { const maybeAccount = await {{ fetchMaybeFromSeedsFunction }}(rpc, {% if hasVariableSeeds %}seeds, {% endif %}config); assertAccountExists(maybeAccount); return maybeAccount; @@ -18,7 +18,7 @@ export async function {{ fetchMaybeFromSeedsFunction }}( seeds: {{ pdaSeedsType }}, {% endif %} config: FetchAccountConfig & { programAddress?: Address } = {}, -): Promise<{{ accountMaybeType }}> { +): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await {{ findPdaFunction }}({% if hasVariableSeeds %}seeds, {% endif %}{ programAddress }); return await {{ fetchMaybeFunction }}(rpc, address, fetchConfig); diff --git a/src/renderers/js-experimental/fragments/accountPdaHelpers.ts b/src/renderers/js-experimental/fragments/accountPdaHelpers.ts index 04702720b..cce7be70d 100644 --- a/src/renderers/js-experimental/fragments/accountPdaHelpers.ts +++ b/src/renderers/js-experimental/fragments/accountPdaHelpers.ts @@ -1,19 +1,35 @@ import { AccountNode, ProgramNode, isNodeFilter } from '../../../nodes'; +import type { TypeManifest } from '../TypeManifest'; import type { GlobalFragmentScope } from '../getRenderMapVisitor'; import { Fragment, fragment, fragmentFromTemplate } from './common'; export function getAccountPdaHelpersFragment( - scope: Pick & { + scope: Pick< + GlobalFragmentScope, + 'nameApi' | 'linkables' | 'customAccountData' + > & { accountNode: AccountNode; programNode: ProgramNode; + typeManifest: TypeManifest; } ): Fragment { - const { accountNode, programNode, nameApi, linkables } = scope; + const { + accountNode, + programNode, + nameApi, + linkables, + customAccountData, + typeManifest, + } = scope; const pdaNode = accountNode.pda ? linkables.get(accountNode.pda) : undefined; if (!pdaNode) { return fragment(''); } + const accountTypeFragment = customAccountData.has(accountNode.name) + ? typeManifest.strictType.clone() + : fragment(nameApi.dataType(accountNode.name)); + const importFrom = 'generatedPdas'; const pdaSeedsType = nameApi.pdaSeedsType(pdaNode.name); const findPdaFunction = nameApi.pdaFindFunction(pdaNode.name); @@ -21,8 +37,7 @@ export function getAccountPdaHelpersFragment( pdaNode.seeds.filter(isNodeFilter('variablePdaSeedNode')).length > 0; return fragmentFromTemplate('accountPdaHelpers.njk', { - accountType: nameApi.accountType(accountNode.name), - accountMaybeType: nameApi.accountMaybeType(accountNode.name), + accountType: accountTypeFragment.render, pdaSeedsType, findPdaFunction, fetchFunction: nameApi.accountFetchFunction(accountNode.name), @@ -36,13 +51,16 @@ export function getAccountPdaHelpersFragment( program: programNode, hasVariableSeeds, }) + .mergeImportsWith(accountTypeFragment) .addImports( importFrom, hasVariableSeeds ? [pdaSeedsType, findPdaFunction] : [findPdaFunction] ) .addImports('solanaAddresses', ['Address']) .addImports('solanaAccounts', [ + 'Account', 'assertAccountExists', 'FetchAccountConfig', + 'MaybeAccount', ]); } diff --git a/src/renderers/js-experimental/fragments/accountType.njk b/src/renderers/js-experimental/fragments/accountType.njk deleted file mode 100644 index bb113a95d..000000000 --- a/src/renderers/js-experimental/fragments/accountType.njk +++ /dev/null @@ -1,8 +0,0 @@ -{% import "templates/macros.njk" as macros %} - -{{ macros.docblock(docs) }} -export type {{ accountType }} = Account<{{ dataName }}, TAddress>; - -export type {{ accountMaybeType }} = MaybeAccount<{{ dataName }}, TAddress>; - -{{ typeWithCodec }} diff --git a/src/renderers/js-experimental/fragments/accountType.ts b/src/renderers/js-experimental/fragments/accountType.ts index 2ac91aca2..5d6d6a1bf 100644 --- a/src/renderers/js-experimental/fragments/accountType.ts +++ b/src/renderers/js-experimental/fragments/accountType.ts @@ -1,7 +1,7 @@ import { AccountNode } from '../../../nodes'; import { TypeManifest } from '../TypeManifest'; import type { GlobalFragmentScope } from '../getRenderMapVisitor'; -import { Fragment, fragment, fragmentFromTemplate } from './common'; +import { Fragment, fragment } from './common'; import { getTypeWithCodecFragment } from './typeWithCodec'; export function getAccountTypeFragment( @@ -11,26 +11,14 @@ export function getAccountTypeFragment( } ): Fragment { const { accountNode, typeManifest, nameApi, customAccountData } = scope; - const customData = customAccountData.get(accountNode.name); - const accountDataName = nameApi.accountDataType(accountNode.name); - const typeWithCodecFragment = customData - ? fragment('') - : getTypeWithCodecFragment({ - name: accountDataName, - manifest: typeManifest, - nameApi, - }); - const dataNameFragment = customData - ? typeManifest.strictType.clone() - : fragment(nameApi.dataType(accountDataName)); + if (customAccountData.has(accountNode.name)) { + return fragment(''); + } - return fragmentFromTemplate('accountType.njk', { - accountType: nameApi.accountType(accountNode.name), - accountMaybeType: nameApi.accountMaybeType(accountNode.name), - dataName: dataNameFragment.render, - typeWithCodec: typeWithCodecFragment, - }) - .mergeImportsWith(dataNameFragment, typeWithCodecFragment) - .addImports('solanaAccounts', ['Account', 'MaybeAccount']); + return getTypeWithCodecFragment({ + name: accountNode.name, + manifest: typeManifest, + nameApi, + }); } diff --git a/src/renderers/js-experimental/fragments/pdaFunction.ts b/src/renderers/js-experimental/fragments/pdaFunction.ts index 81cb4a1d2..7d5ca6120 100644 --- a/src/renderers/js-experimental/fragments/pdaFunction.ts +++ b/src/renderers/js-experimental/fragments/pdaFunction.ts @@ -36,7 +36,6 @@ export function getPdaFunctionFragment( pdaNode.seeds.filter(isNodeFilter('variablePdaSeedNode')).length > 0; return fragmentFromTemplate('pdaFunction.njk', { - accountType: nameApi.accountType(pdaNode.name), pdaSeedsType: nameApi.pdaSeedsType(pdaNode.name), findPdaFunction: nameApi.pdaFindFunction(pdaNode.name), program: programNode, diff --git a/src/renderers/js-experimental/getTypeManifestVisitor.ts b/src/renderers/js-experimental/getTypeManifestVisitor.ts index 820b10093..f7807289f 100644 --- a/src/renderers/js-experimental/getTypeManifestVisitor.ts +++ b/src/renderers/js-experimental/getTypeManifestVisitor.ts @@ -68,10 +68,9 @@ export function getTypeManifestVisitor(input: { (visitor) => extendVisitor(visitor, { visitAccount(account, { self }) { - const accountDataName = nameApi.accountDataType(account.name); parentName = { - strict: nameApi.dataType(accountDataName), - loose: nameApi.dataArgsType(accountDataName), + strict: nameApi.dataType(account.name), + loose: nameApi.dataArgsType(account.name), }; const link = customAccountData.get(account.name)?.linkNode; const manifest = link ? visit(link, self) : visit(account.data, self); diff --git a/src/renderers/js-experimental/nameTransformers.ts b/src/renderers/js-experimental/nameTransformers.ts index 2f1a193c5..fa5e2d2d5 100644 --- a/src/renderers/js-experimental/nameTransformers.ts +++ b/src/renderers/js-experimental/nameTransformers.ts @@ -29,9 +29,6 @@ export type NameTransformerKey = | 'codecFunction' | 'pdaSeedsType' | 'pdaFindFunction' - | 'accountType' - | 'accountMaybeType' - | 'accountDataType' | 'accountDecodeFunction' | 'accountFetchFunction' | 'accountFetchAllFunction' @@ -99,9 +96,6 @@ export const DEFAULT_NAME_TRANSFORMERS: NameTransformers = { codecFunction: (name) => `get${pascalCase(name)}Codec`, pdaSeedsType: (name) => `${pascalCase(name)}Seeds`, pdaFindFunction: (name) => `find${pascalCase(name)}Pda`, - accountType: (name) => `${pascalCase(name)}`, - accountMaybeType: (name) => `Maybe${pascalCase(name)}`, - accountDataType: (name) => `${pascalCase(name)}AccountData`, accountDecodeFunction: (name) => `decode${pascalCase(name)}`, accountFetchFunction: (name) => `fetch${pascalCase(name)}`, accountFetchAllFunction: (name) => `fetchAll${pascalCase(name)}`, diff --git a/test/packages/js-experimental/src/generated/accounts/candyMachine.ts b/test/packages/js-experimental/src/generated/accounts/candyMachine.ts index 9a47e7b9b..710bca808 100644 --- a/test/packages/js-experimental/src/generated/accounts/candyMachine.ts +++ b/test/packages/js-experimental/src/generated/accounts/candyMachine.ts @@ -46,17 +46,7 @@ import { getCandyMachineDataEncoder, } from '../types'; -export type CandyMachine = Account< - CandyMachineAccountData, - TAddress ->; - -export type MaybeCandyMachine = MaybeAccount< - CandyMachineAccountData, - TAddress ->; - -export type CandyMachineAccountData = { +export type CandyMachine = { discriminator: Array; /** Features versioning flags. */ features: bigint; @@ -72,7 +62,7 @@ export type CandyMachineAccountData = { data: CandyMachineData; }; -export type CandyMachineAccountDataArgs = { +export type CandyMachineArgs = { /** Features versioning flags. */ features: number | bigint; /** Authority address. */ @@ -87,7 +77,7 @@ export type CandyMachineAccountDataArgs = { data: CandyMachineDataArgs; }; -export function getCandyMachineAccountDataEncoder(): Encoder { +export function getCandyMachineEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', getArrayEncoder(getU8Encoder(), { size: 8 })], @@ -105,7 +95,7 @@ export function getCandyMachineAccountDataEncoder(): Encoder { +export function getCandyMachineDecoder(): Decoder { return getStructDecoder([ ['discriminator', getArrayDecoder(getU8Decoder(), { size: 8 })], ['features', getU64Decoder()], @@ -117,28 +107,22 @@ export function getCandyMachineAccountDataDecoder(): Decoder { - return combineCodec( - getCandyMachineAccountDataEncoder(), - getCandyMachineAccountDataDecoder() - ); +export function getCandyMachineCodec(): Codec { + return combineCodec(getCandyMachineEncoder(), getCandyMachineDecoder()); } export function decodeCandyMachine( encodedAccount: EncodedAccount -): CandyMachine; +): Account; export function decodeCandyMachine( encodedAccount: MaybeEncodedAccount -): MaybeCandyMachine; +): MaybeAccount; export function decodeCandyMachine( encodedAccount: EncodedAccount | MaybeEncodedAccount -): CandyMachine | MaybeCandyMachine { +): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getCandyMachineAccountDataDecoder() + getCandyMachineDecoder() ); } @@ -146,7 +130,7 @@ export async function fetchCandyMachine( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeCandyMachine(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -156,7 +140,7 @@ export async function fetchMaybeCandyMachine( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCandyMachine(maybeAccount); } @@ -165,7 +149,7 @@ export async function fetchAllCandyMachine( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeCandyMachine(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; @@ -175,7 +159,7 @@ export async function fetchAllMaybeCandyMachine( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCandyMachine(maybeAccount)); } diff --git a/test/packages/js-experimental/src/generated/accounts/collectionAuthorityRecord.ts b/test/packages/js-experimental/src/generated/accounts/collectionAuthorityRecord.ts index 8c6082497..cf71a0698 100644 --- a/test/packages/js-experimental/src/generated/accounts/collectionAuthorityRecord.ts +++ b/test/packages/js-experimental/src/generated/accounts/collectionAuthorityRecord.ts @@ -41,24 +41,18 @@ import { } from '@solana/codecs'; import { TmKey, getTmKeyDecoder, getTmKeyEncoder } from '../types'; -export type CollectionAuthorityRecord = - Account; - -export type MaybeCollectionAuthorityRecord = - MaybeAccount; - -export type CollectionAuthorityRecordAccountData = { +export type CollectionAuthorityRecord = { key: TmKey; bump: number; updateAuthority: Option
; }; -export type CollectionAuthorityRecordAccountDataArgs = { +export type CollectionAuthorityRecordArgs = { bump: number; updateAuthority: OptionOrNullable
; }; -export function getCollectionAuthorityRecordAccountDataEncoder(): Encoder { +export function getCollectionAuthorityRecordEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -69,7 +63,7 @@ export function getCollectionAuthorityRecordAccountDataEncoder(): Encoder { +export function getCollectionAuthorityRecordDecoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['bump', getU8Decoder()], @@ -77,13 +71,13 @@ export function getCollectionAuthorityRecordAccountDataDecoder(): Decoder { return combineCodec( - getCollectionAuthorityRecordAccountDataEncoder(), - getCollectionAuthorityRecordAccountDataDecoder() + getCollectionAuthorityRecordEncoder(), + getCollectionAuthorityRecordDecoder() ); } @@ -91,22 +85,22 @@ export function decodeCollectionAuthorityRecord< TAddress extends string = string, >( encodedAccount: EncodedAccount -): CollectionAuthorityRecord; +): Account; export function decodeCollectionAuthorityRecord< TAddress extends string = string, >( encodedAccount: MaybeEncodedAccount -): MaybeCollectionAuthorityRecord; +): MaybeAccount; export function decodeCollectionAuthorityRecord< TAddress extends string = string, >( encodedAccount: EncodedAccount | MaybeEncodedAccount ): - | CollectionAuthorityRecord - | MaybeCollectionAuthorityRecord { + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getCollectionAuthorityRecordAccountDataDecoder() + getCollectionAuthorityRecordDecoder() ); } @@ -116,7 +110,7 @@ export async function fetchCollectionAuthorityRecord< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeCollectionAuthorityRecord( rpc, address, @@ -132,7 +126,7 @@ export async function fetchMaybeCollectionAuthorityRecord< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCollectionAuthorityRecord(maybeAccount); } @@ -141,7 +135,7 @@ export async function fetchAllCollectionAuthorityRecord( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeCollectionAuthorityRecord( rpc, addresses, @@ -155,7 +149,7 @@ export async function fetchAllMaybeCollectionAuthorityRecord( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCollectionAuthorityRecord(maybeAccount) diff --git a/test/packages/js-experimental/src/generated/accounts/delegateRecord.ts b/test/packages/js-experimental/src/generated/accounts/delegateRecord.ts index 2c787f545..299febc89 100644 --- a/test/packages/js-experimental/src/generated/accounts/delegateRecord.ts +++ b/test/packages/js-experimental/src/generated/accounts/delegateRecord.ts @@ -42,26 +42,11 @@ import { getTmKeyEncoder, } from '../types'; -export type DelegateRecord = Account< - DelegateRecordAccountData, - TAddress ->; +export type DelegateRecord = { key: TmKey; role: DelegateRole; bump: number }; -export type MaybeDelegateRecord = - MaybeAccount; +export type DelegateRecordArgs = { role: DelegateRoleArgs; bump: number }; -export type DelegateRecordAccountData = { - key: TmKey; - role: DelegateRole; - bump: number; -}; - -export type DelegateRecordAccountDataArgs = { - role: DelegateRoleArgs; - bump: number; -}; - -export function getDelegateRecordAccountDataEncoder(): Encoder { +export function getDelegateRecordEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -72,7 +57,7 @@ export function getDelegateRecordAccountDataEncoder(): Encoder { +export function getDelegateRecordDecoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['role', getDelegateRoleDecoder()], @@ -80,28 +65,25 @@ export function getDelegateRecordAccountDataDecoder(): Decoder { - return combineCodec( - getDelegateRecordAccountDataEncoder(), - getDelegateRecordAccountDataDecoder() - ); + return combineCodec(getDelegateRecordEncoder(), getDelegateRecordDecoder()); } export function decodeDelegateRecord( encodedAccount: EncodedAccount -): DelegateRecord; +): Account; export function decodeDelegateRecord( encodedAccount: MaybeEncodedAccount -): MaybeDelegateRecord; +): MaybeAccount; export function decodeDelegateRecord( encodedAccount: EncodedAccount | MaybeEncodedAccount -): DelegateRecord | MaybeDelegateRecord { +): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getDelegateRecordAccountDataDecoder() + getDelegateRecordDecoder() ); } @@ -109,7 +91,7 @@ export async function fetchDelegateRecord( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeDelegateRecord(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -121,7 +103,7 @@ export async function fetchMaybeDelegateRecord< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeDelegateRecord(maybeAccount); } @@ -130,7 +112,7 @@ export async function fetchAllDelegateRecord( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeDelegateRecord( rpc, addresses, @@ -144,7 +126,7 @@ export async function fetchAllMaybeDelegateRecord( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeDelegateRecord(maybeAccount) @@ -159,7 +141,7 @@ export async function fetchDelegateRecordFromSeeds( rpc: Parameters[0], seeds: DelegateRecordSeeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const maybeAccount = await fetchMaybeDelegateRecordFromSeeds( rpc, seeds, @@ -173,7 +155,7 @@ export async function fetchMaybeDelegateRecordFromSeeds( rpc: Parameters[0], seeds: DelegateRecordSeeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findDelegateRecordPda(seeds, { programAddress }); return await fetchMaybeDelegateRecord(rpc, address, fetchConfig); diff --git a/test/packages/js-experimental/src/generated/accounts/edition.ts b/test/packages/js-experimental/src/generated/accounts/edition.ts index abc6db2da..ee8fdb35c 100644 --- a/test/packages/js-experimental/src/generated/accounts/edition.ts +++ b/test/packages/js-experimental/src/generated/accounts/edition.ts @@ -37,28 +37,11 @@ import { } from '@solana/codecs'; import { TmKey, getTmKeyDecoder, getTmKeyEncoder } from '../types'; -export type Edition = Account< - EditionAccountData, - TAddress ->; +export type Edition = { key: TmKey; parent: Address; edition: bigint }; -export type MaybeEdition = MaybeAccount< - EditionAccountData, - TAddress ->; +export type EditionArgs = { parent: Address; edition: number | bigint }; -export type EditionAccountData = { - key: TmKey; - parent: Address; - edition: bigint; -}; - -export type EditionAccountDataArgs = { - parent: Address; - edition: number | bigint; -}; - -export function getEditionAccountDataEncoder(): Encoder { +export function getEditionEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -69,7 +52,7 @@ export function getEditionAccountDataEncoder(): Encoder ); } -export function getEditionAccountDataDecoder(): Decoder { +export function getEditionDecoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['parent', getAddressDecoder()], @@ -77,28 +60,22 @@ export function getEditionAccountDataDecoder(): Decoder { ]); } -export function getEditionAccountDataCodec(): Codec< - EditionAccountDataArgs, - EditionAccountData -> { - return combineCodec( - getEditionAccountDataEncoder(), - getEditionAccountDataDecoder() - ); +export function getEditionCodec(): Codec { + return combineCodec(getEditionEncoder(), getEditionDecoder()); } export function decodeEdition( encodedAccount: EncodedAccount -): Edition; +): Account; export function decodeEdition( encodedAccount: MaybeEncodedAccount -): MaybeEdition; +): MaybeAccount; export function decodeEdition( encodedAccount: EncodedAccount | MaybeEncodedAccount -): Edition | MaybeEdition { +): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getEditionAccountDataDecoder() + getEditionDecoder() ); } @@ -106,7 +83,7 @@ export async function fetchEdition( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeEdition(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -116,7 +93,7 @@ export async function fetchMaybeEdition( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeEdition(maybeAccount); } @@ -125,7 +102,7 @@ export async function fetchAllEdition( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeEdition(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; @@ -135,7 +112,7 @@ export async function fetchAllMaybeEdition( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeEdition(maybeAccount)); } diff --git a/test/packages/js-experimental/src/generated/accounts/editionMarker.ts b/test/packages/js-experimental/src/generated/accounts/editionMarker.ts index 1cb848b55..9c3c00e56 100644 --- a/test/packages/js-experimental/src/generated/accounts/editionMarker.ts +++ b/test/packages/js-experimental/src/generated/accounts/editionMarker.ts @@ -35,21 +35,11 @@ import { } from '@solana/codecs'; import { TmKey, getTmKeyDecoder, getTmKeyEncoder } from '../types'; -export type EditionMarker = Account< - EditionMarkerAccountData, - TAddress ->; +export type EditionMarker = { key: TmKey; ledger: Array }; -export type MaybeEditionMarker = MaybeAccount< - EditionMarkerAccountData, - TAddress ->; +export type EditionMarkerArgs = { ledger: Array }; -export type EditionMarkerAccountData = { key: TmKey; ledger: Array }; - -export type EditionMarkerAccountDataArgs = { ledger: Array }; - -export function getEditionMarkerAccountDataEncoder(): Encoder { +export function getEditionMarkerEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -59,35 +49,32 @@ export function getEditionMarkerAccountDataEncoder(): Encoder { +export function getEditionMarkerDecoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['ledger', getArrayDecoder(getU8Decoder(), { size: 200 })], ]); } -export function getEditionMarkerAccountDataCodec(): Codec< - EditionMarkerAccountDataArgs, - EditionMarkerAccountData +export function getEditionMarkerCodec(): Codec< + EditionMarkerArgs, + EditionMarker > { - return combineCodec( - getEditionMarkerAccountDataEncoder(), - getEditionMarkerAccountDataDecoder() - ); + return combineCodec(getEditionMarkerEncoder(), getEditionMarkerDecoder()); } export function decodeEditionMarker( encodedAccount: EncodedAccount -): EditionMarker; +): Account; export function decodeEditionMarker( encodedAccount: MaybeEncodedAccount -): MaybeEditionMarker; +): MaybeAccount; export function decodeEditionMarker( encodedAccount: EncodedAccount | MaybeEncodedAccount -): EditionMarker | MaybeEditionMarker { +): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getEditionMarkerAccountDataDecoder() + getEditionMarkerDecoder() ); } @@ -95,7 +82,7 @@ export async function fetchEditionMarker( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeEditionMarker(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -105,7 +92,7 @@ export async function fetchMaybeEditionMarker( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeEditionMarker(maybeAccount); } @@ -114,7 +101,7 @@ export async function fetchAllEditionMarker( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeEditionMarker( rpc, addresses, @@ -128,7 +115,7 @@ export async function fetchAllMaybeEditionMarker( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeEditionMarker(maybeAccount)); } diff --git a/test/packages/js-experimental/src/generated/accounts/frequencyAccount.ts b/test/packages/js-experimental/src/generated/accounts/frequencyAccount.ts index ad694941d..94dc1a149 100644 --- a/test/packages/js-experimental/src/generated/accounts/frequencyAccount.ts +++ b/test/packages/js-experimental/src/generated/accounts/frequencyAccount.ts @@ -36,15 +36,7 @@ import { import { findFrequencyAccountPda } from '../pdas'; import { TaKey } from '../types'; -export type FrequencyAccount = Account< - FrequencyAccountAccountData, - TAddress ->; - -export type MaybeFrequencyAccount = - MaybeAccount; - -export type FrequencyAccountAccountData = { +export type FrequencyAccount = { /** Test with only one line. */ key: bigint; /** @@ -55,7 +47,7 @@ export type FrequencyAccountAccountData = { period: bigint; }; -export type FrequencyAccountAccountDataArgs = { +export type FrequencyAccountArgs = { /** * Test with multiple lines * and this is the second line. @@ -64,7 +56,7 @@ export type FrequencyAccountAccountDataArgs = { period: number | bigint; }; -export function getFrequencyAccountAccountDataEncoder(): Encoder { +export function getFrequencyAccountEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getU64Encoder()], @@ -75,7 +67,7 @@ export function getFrequencyAccountAccountDataEncoder(): Encoder { +export function getFrequencyAccountDecoder(): Decoder { return getStructDecoder([ ['key', getU64Decoder()], ['lastUpdate', getI64Decoder()], @@ -83,28 +75,30 @@ export function getFrequencyAccountAccountDataDecoder(): Decoder { return combineCodec( - getFrequencyAccountAccountDataEncoder(), - getFrequencyAccountAccountDataDecoder() + getFrequencyAccountEncoder(), + getFrequencyAccountDecoder() ); } export function decodeFrequencyAccount( encodedAccount: EncodedAccount -): FrequencyAccount; +): Account; export function decodeFrequencyAccount( encodedAccount: MaybeEncodedAccount -): MaybeFrequencyAccount; +): MaybeAccount; export function decodeFrequencyAccount( encodedAccount: EncodedAccount | MaybeEncodedAccount -): FrequencyAccount | MaybeFrequencyAccount { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getFrequencyAccountAccountDataDecoder() + getFrequencyAccountDecoder() ); } @@ -112,7 +106,7 @@ export async function fetchFrequencyAccount( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeFrequencyAccount(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -124,7 +118,7 @@ export async function fetchMaybeFrequencyAccount< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFrequencyAccount(maybeAccount); } @@ -133,7 +127,7 @@ export async function fetchAllFrequencyAccount( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeFrequencyAccount( rpc, addresses, @@ -147,7 +141,7 @@ export async function fetchAllMaybeFrequencyAccount( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFrequencyAccount(maybeAccount) @@ -161,7 +155,7 @@ export function getFrequencyAccountSize(): number { export async function fetchFrequencyAccountFromSeeds( rpc: Parameters[0], config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const maybeAccount = await fetchMaybeFrequencyAccountFromSeeds(rpc, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -170,7 +164,7 @@ export async function fetchFrequencyAccountFromSeeds( export async function fetchMaybeFrequencyAccountFromSeeds( rpc: Parameters[0], config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFrequencyAccountPda({ programAddress }); return await fetchMaybeFrequencyAccount(rpc, address, fetchConfig); diff --git a/test/packages/js-experimental/src/generated/accounts/masterEditionV1.ts b/test/packages/js-experimental/src/generated/accounts/masterEditionV1.ts index d14c211b8..385992397 100644 --- a/test/packages/js-experimental/src/generated/accounts/masterEditionV1.ts +++ b/test/packages/js-experimental/src/generated/accounts/masterEditionV1.ts @@ -42,15 +42,7 @@ import { import { MasterEditionV1Seeds, findMasterEditionV1Pda } from '../pdas'; import { TmKey, getTmKeyDecoder, getTmKeyEncoder } from '../types'; -export type MasterEditionV1 = Account< - MasterEditionV1AccountData, - TAddress ->; - -export type MaybeMasterEditionV1 = - MaybeAccount; - -export type MasterEditionV1AccountData = { +export type MasterEditionV1 = { key: TmKey; supply: bigint; maxSupply: Option; @@ -58,14 +50,14 @@ export type MasterEditionV1AccountData = { oneTimePrintingAuthorizationMint: Address; }; -export type MasterEditionV1AccountDataArgs = { +export type MasterEditionV1Args = { supply: number | bigint; maxSupply: OptionOrNullable; printingMint: Address; oneTimePrintingAuthorizationMint: Address; }; -export function getMasterEditionV1AccountDataEncoder(): Encoder { +export function getMasterEditionV1Encoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -78,7 +70,7 @@ export function getMasterEditionV1AccountDataEncoder(): Encoder { +export function getMasterEditionV1Decoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['supply', getU64Decoder()], @@ -88,28 +80,27 @@ export function getMasterEditionV1AccountDataDecoder(): Decoder { - return combineCodec( - getMasterEditionV1AccountDataEncoder(), - getMasterEditionV1AccountDataDecoder() - ); + return combineCodec(getMasterEditionV1Encoder(), getMasterEditionV1Decoder()); } export function decodeMasterEditionV1( encodedAccount: EncodedAccount -): MasterEditionV1; +): Account; export function decodeMasterEditionV1( encodedAccount: MaybeEncodedAccount -): MaybeMasterEditionV1; +): MaybeAccount; export function decodeMasterEditionV1( encodedAccount: EncodedAccount | MaybeEncodedAccount -): MasterEditionV1 | MaybeMasterEditionV1 { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getMasterEditionV1AccountDataDecoder() + getMasterEditionV1Decoder() ); } @@ -117,7 +108,7 @@ export async function fetchMasterEditionV1( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeMasterEditionV1(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -129,7 +120,7 @@ export async function fetchMaybeMasterEditionV1< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeMasterEditionV1(maybeAccount); } @@ -138,7 +129,7 @@ export async function fetchAllMasterEditionV1( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeMasterEditionV1( rpc, addresses, @@ -152,7 +143,7 @@ export async function fetchAllMaybeMasterEditionV1( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeMasterEditionV1(maybeAccount) @@ -163,7 +154,7 @@ export async function fetchMasterEditionV1FromSeeds( rpc: Parameters[0], seeds: MasterEditionV1Seeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const maybeAccount = await fetchMaybeMasterEditionV1FromSeeds( rpc, seeds, @@ -177,7 +168,7 @@ export async function fetchMaybeMasterEditionV1FromSeeds( rpc: Parameters[0], seeds: MasterEditionV1Seeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findMasterEditionV1Pda(seeds, { programAddress }); return await fetchMaybeMasterEditionV1(rpc, address, fetchConfig); diff --git a/test/packages/js-experimental/src/generated/accounts/masterEditionV2.ts b/test/packages/js-experimental/src/generated/accounts/masterEditionV2.ts index 7c386d459..648a75331 100644 --- a/test/packages/js-experimental/src/generated/accounts/masterEditionV2.ts +++ b/test/packages/js-experimental/src/generated/accounts/masterEditionV2.ts @@ -38,26 +38,18 @@ import { import { MasterEditionV2Seeds, findMasterEditionV2Pda } from '../pdas'; import { TmKey, getTmKeyDecoder, getTmKeyEncoder } from '../types'; -export type MasterEditionV2 = Account< - MasterEditionV2AccountData, - TAddress ->; - -export type MaybeMasterEditionV2 = - MaybeAccount; - -export type MasterEditionV2AccountData = { +export type MasterEditionV2 = { key: TmKey; supply: bigint; maxSupply: Option; }; -export type MasterEditionV2AccountDataArgs = { +export type MasterEditionV2Args = { supply: number | bigint; maxSupply: OptionOrNullable; }; -export function getMasterEditionV2AccountDataEncoder(): Encoder { +export function getMasterEditionV2Encoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -68,7 +60,7 @@ export function getMasterEditionV2AccountDataEncoder(): Encoder { +export function getMasterEditionV2Decoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['supply', getU64Decoder()], @@ -76,28 +68,27 @@ export function getMasterEditionV2AccountDataDecoder(): Decoder { - return combineCodec( - getMasterEditionV2AccountDataEncoder(), - getMasterEditionV2AccountDataDecoder() - ); + return combineCodec(getMasterEditionV2Encoder(), getMasterEditionV2Decoder()); } export function decodeMasterEditionV2( encodedAccount: EncodedAccount -): MasterEditionV2; +): Account; export function decodeMasterEditionV2( encodedAccount: MaybeEncodedAccount -): MaybeMasterEditionV2; +): MaybeAccount; export function decodeMasterEditionV2( encodedAccount: EncodedAccount | MaybeEncodedAccount -): MasterEditionV2 | MaybeMasterEditionV2 { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getMasterEditionV2AccountDataDecoder() + getMasterEditionV2Decoder() ); } @@ -105,7 +96,7 @@ export async function fetchMasterEditionV2( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeMasterEditionV2(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -117,7 +108,7 @@ export async function fetchMaybeMasterEditionV2< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeMasterEditionV2(maybeAccount); } @@ -126,7 +117,7 @@ export async function fetchAllMasterEditionV2( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeMasterEditionV2( rpc, addresses, @@ -140,7 +131,7 @@ export async function fetchAllMaybeMasterEditionV2( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeMasterEditionV2(maybeAccount) @@ -155,7 +146,7 @@ export async function fetchMasterEditionV2FromSeeds( rpc: Parameters[0], seeds: MasterEditionV2Seeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const maybeAccount = await fetchMaybeMasterEditionV2FromSeeds( rpc, seeds, @@ -169,7 +160,7 @@ export async function fetchMaybeMasterEditionV2FromSeeds( rpc: Parameters[0], seeds: MasterEditionV2Seeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findMasterEditionV2Pda(seeds, { programAddress }); return await fetchMaybeMasterEditionV2(rpc, address, fetchConfig); diff --git a/test/packages/js-experimental/src/generated/accounts/metadata.ts b/test/packages/js-experimental/src/generated/accounts/metadata.ts index a33129f35..f83694910 100644 --- a/test/packages/js-experimental/src/generated/accounts/metadata.ts +++ b/test/packages/js-experimental/src/generated/accounts/metadata.ts @@ -86,17 +86,7 @@ import { getUsesEncoder, } from '../types'; -export type Metadata = Account< - MetadataAccountData, - TAddress ->; - -export type MaybeMetadata = MaybeAccount< - MetadataAccountData, - TAddress ->; - -export type MetadataAccountData = { +export type Metadata = { key: TmKey; updateAuthority: Address; mint: Address; @@ -116,7 +106,7 @@ export type MetadataAccountData = { delegateState: Option; }; -export type MetadataAccountDataArgs = { +export type MetadataArgs = { updateAuthority: Address; mint: Address; name: string; @@ -135,7 +125,7 @@ export type MetadataAccountDataArgs = { delegateState: OptionOrNullable; }; -export function getMetadataAccountDataEncoder(): Encoder { +export function getMetadataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -160,7 +150,7 @@ export function getMetadataAccountDataEncoder(): Encoder { +export function getMetadataDecoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['updateAuthority', getAddressDecoder()], @@ -182,28 +172,22 @@ export function getMetadataAccountDataDecoder(): Decoder { ]); } -export function getMetadataAccountDataCodec(): Codec< - MetadataAccountDataArgs, - MetadataAccountData -> { - return combineCodec( - getMetadataAccountDataEncoder(), - getMetadataAccountDataDecoder() - ); +export function getMetadataCodec(): Codec { + return combineCodec(getMetadataEncoder(), getMetadataDecoder()); } export function decodeMetadata( encodedAccount: EncodedAccount -): Metadata; +): Account; export function decodeMetadata( encodedAccount: MaybeEncodedAccount -): MaybeMetadata; +): MaybeAccount; export function decodeMetadata( encodedAccount: EncodedAccount | MaybeEncodedAccount -): Metadata | MaybeMetadata { +): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getMetadataAccountDataDecoder() + getMetadataDecoder() ); } @@ -211,7 +195,7 @@ export async function fetchMetadata( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeMetadata(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -221,7 +205,7 @@ export async function fetchMaybeMetadata( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeMetadata(maybeAccount); } @@ -230,7 +214,7 @@ export async function fetchAllMetadata( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeMetadata(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; @@ -240,7 +224,7 @@ export async function fetchAllMaybeMetadata( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeMetadata(maybeAccount)); } @@ -253,7 +237,7 @@ export async function fetchMetadataFromSeeds( rpc: Parameters[0], seeds: MetadataSeeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const maybeAccount = await fetchMaybeMetadataFromSeeds(rpc, seeds, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -263,7 +247,7 @@ export async function fetchMaybeMetadataFromSeeds( rpc: Parameters[0], seeds: MetadataSeeds, config: FetchAccountConfig & { programAddress?: Address } = {} -): Promise { +): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findMetadataPda(seeds, { programAddress }); return await fetchMaybeMetadata(rpc, address, fetchConfig); diff --git a/test/packages/js-experimental/src/generated/accounts/reservationListV1.ts b/test/packages/js-experimental/src/generated/accounts/reservationListV1.ts index 93f07e846..2b3dc7adf 100644 --- a/test/packages/js-experimental/src/generated/accounts/reservationListV1.ts +++ b/test/packages/js-experimental/src/generated/accounts/reservationListV1.ts @@ -25,23 +25,17 @@ import { getReservationListV1AccountDataDecoder, } from '../../hooked'; -export type ReservationListV1 = Account< - ReservationListV1AccountData, - TAddress ->; - -export type MaybeReservationListV1 = - MaybeAccount; - export function decodeReservationListV1( encodedAccount: EncodedAccount -): ReservationListV1; +): Account; export function decodeReservationListV1( encodedAccount: MaybeEncodedAccount -): MaybeReservationListV1; +): MaybeAccount; export function decodeReservationListV1( encodedAccount: EncodedAccount | MaybeEncodedAccount -): ReservationListV1 | MaybeReservationListV1 { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getReservationListV1AccountDataDecoder() @@ -52,7 +46,7 @@ export async function fetchReservationListV1( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeReservationListV1(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -64,7 +58,7 @@ export async function fetchMaybeReservationListV1< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeReservationListV1(maybeAccount); } @@ -73,7 +67,7 @@ export async function fetchAllReservationListV1( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeReservationListV1( rpc, addresses, @@ -87,7 +81,7 @@ export async function fetchAllMaybeReservationListV1( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeReservationListV1(maybeAccount) diff --git a/test/packages/js-experimental/src/generated/accounts/reservationListV2.ts b/test/packages/js-experimental/src/generated/accounts/reservationListV2.ts index 7d2b9bb8e..12ed224b5 100644 --- a/test/packages/js-experimental/src/generated/accounts/reservationListV2.ts +++ b/test/packages/js-experimental/src/generated/accounts/reservationListV2.ts @@ -51,15 +51,7 @@ import { getTmKeyEncoder, } from '../types'; -export type ReservationListV2 = Account< - ReservationListV2AccountData, - TAddress ->; - -export type MaybeReservationListV2 = - MaybeAccount; - -export type ReservationListV2AccountData = { +export type ReservationListV2 = { key: TmKey; masterEdition: Address; supplySnapshot: Option; @@ -68,7 +60,7 @@ export type ReservationListV2AccountData = { currentReservationSpots: bigint; }; -export type ReservationListV2AccountDataArgs = { +export type ReservationListV2Args = { masterEdition: Address; supplySnapshot: OptionOrNullable; reservations: Array; @@ -76,7 +68,7 @@ export type ReservationListV2AccountDataArgs = { currentReservationSpots: number | bigint; }; -export function getReservationListV2AccountDataEncoder(): Encoder { +export function getReservationListV2Encoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -90,7 +82,7 @@ export function getReservationListV2AccountDataEncoder(): Encoder { +export function getReservationListV2Decoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['masterEdition', getAddressDecoder()], @@ -101,28 +93,30 @@ export function getReservationListV2AccountDataDecoder(): Decoder { return combineCodec( - getReservationListV2AccountDataEncoder(), - getReservationListV2AccountDataDecoder() + getReservationListV2Encoder(), + getReservationListV2Decoder() ); } export function decodeReservationListV2( encodedAccount: EncodedAccount -): ReservationListV2; +): Account; export function decodeReservationListV2( encodedAccount: MaybeEncodedAccount -): MaybeReservationListV2; +): MaybeAccount; export function decodeReservationListV2( encodedAccount: EncodedAccount | MaybeEncodedAccount -): ReservationListV2 | MaybeReservationListV2 { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getReservationListV2AccountDataDecoder() + getReservationListV2Decoder() ); } @@ -130,7 +124,7 @@ export async function fetchReservationListV2( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeReservationListV2(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -142,7 +136,7 @@ export async function fetchMaybeReservationListV2< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeReservationListV2(maybeAccount); } @@ -151,7 +145,7 @@ export async function fetchAllReservationListV2( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeReservationListV2( rpc, addresses, @@ -165,7 +159,7 @@ export async function fetchAllMaybeReservationListV2( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeReservationListV2(maybeAccount) diff --git a/test/packages/js-experimental/src/generated/accounts/tokenOwnedEscrow.ts b/test/packages/js-experimental/src/generated/accounts/tokenOwnedEscrow.ts index 381c9b44c..1f1453b0a 100644 --- a/test/packages/js-experimental/src/generated/accounts/tokenOwnedEscrow.ts +++ b/test/packages/js-experimental/src/generated/accounts/tokenOwnedEscrow.ts @@ -45,28 +45,20 @@ import { getTmKeyEncoder, } from '../types'; -export type TokenOwnedEscrow = Account< - TokenOwnedEscrowAccountData, - TAddress ->; - -export type MaybeTokenOwnedEscrow = - MaybeAccount; - -export type TokenOwnedEscrowAccountData = { +export type TokenOwnedEscrow = { key: TmKey; baseToken: Address; authority: EscrowAuthority; bump: number; }; -export type TokenOwnedEscrowAccountDataArgs = { +export type TokenOwnedEscrowArgs = { baseToken: Address; authority: EscrowAuthorityArgs; bump: number; }; -export function getTokenOwnedEscrowAccountDataEncoder(): Encoder { +export function getTokenOwnedEscrowEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -78,7 +70,7 @@ export function getTokenOwnedEscrowAccountDataEncoder(): Encoder { +export function getTokenOwnedEscrowDecoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['baseToken', getAddressDecoder()], @@ -87,28 +79,30 @@ export function getTokenOwnedEscrowAccountDataDecoder(): Decoder { return combineCodec( - getTokenOwnedEscrowAccountDataEncoder(), - getTokenOwnedEscrowAccountDataDecoder() + getTokenOwnedEscrowEncoder(), + getTokenOwnedEscrowDecoder() ); } export function decodeTokenOwnedEscrow( encodedAccount: EncodedAccount -): TokenOwnedEscrow; +): Account; export function decodeTokenOwnedEscrow( encodedAccount: MaybeEncodedAccount -): MaybeTokenOwnedEscrow; +): MaybeAccount; export function decodeTokenOwnedEscrow( encodedAccount: EncodedAccount | MaybeEncodedAccount -): TokenOwnedEscrow | MaybeTokenOwnedEscrow { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getTokenOwnedEscrowAccountDataDecoder() + getTokenOwnedEscrowDecoder() ); } @@ -116,7 +110,7 @@ export async function fetchTokenOwnedEscrow( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeTokenOwnedEscrow(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -128,7 +122,7 @@ export async function fetchMaybeTokenOwnedEscrow< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeTokenOwnedEscrow(maybeAccount); } @@ -137,7 +131,7 @@ export async function fetchAllTokenOwnedEscrow( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeTokenOwnedEscrow( rpc, addresses, @@ -151,7 +145,7 @@ export async function fetchAllMaybeTokenOwnedEscrow( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeTokenOwnedEscrow(maybeAccount) diff --git a/test/packages/js-experimental/src/generated/accounts/useAuthorityRecord.ts b/test/packages/js-experimental/src/generated/accounts/useAuthorityRecord.ts index 584852a4d..20f299329 100644 --- a/test/packages/js-experimental/src/generated/accounts/useAuthorityRecord.ts +++ b/test/packages/js-experimental/src/generated/accounts/useAuthorityRecord.ts @@ -35,26 +35,18 @@ import { } from '@solana/codecs'; import { TmKey, getTmKeyDecoder, getTmKeyEncoder } from '../types'; -export type UseAuthorityRecord = Account< - UseAuthorityRecordAccountData, - TAddress ->; - -export type MaybeUseAuthorityRecord = - MaybeAccount; - -export type UseAuthorityRecordAccountData = { +export type UseAuthorityRecord = { key: TmKey; allowedUses: bigint; bump: number; }; -export type UseAuthorityRecordAccountDataArgs = { +export type UseAuthorityRecordArgs = { allowedUses: number | bigint; bump: number; }; -export function getUseAuthorityRecordAccountDataEncoder(): Encoder { +export function getUseAuthorityRecordEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['key', getTmKeyEncoder()], @@ -65,7 +57,7 @@ export function getUseAuthorityRecordAccountDataEncoder(): Encoder { +export function getUseAuthorityRecordDecoder(): Decoder { return getStructDecoder([ ['key', getTmKeyDecoder()], ['allowedUses', getU64Decoder()], @@ -73,28 +65,30 @@ export function getUseAuthorityRecordAccountDataDecoder(): Decoder { return combineCodec( - getUseAuthorityRecordAccountDataEncoder(), - getUseAuthorityRecordAccountDataDecoder() + getUseAuthorityRecordEncoder(), + getUseAuthorityRecordDecoder() ); } export function decodeUseAuthorityRecord( encodedAccount: EncodedAccount -): UseAuthorityRecord; +): Account; export function decodeUseAuthorityRecord( encodedAccount: MaybeEncodedAccount -): MaybeUseAuthorityRecord; +): MaybeAccount; export function decodeUseAuthorityRecord( encodedAccount: EncodedAccount | MaybeEncodedAccount -): UseAuthorityRecord | MaybeUseAuthorityRecord { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getUseAuthorityRecordAccountDataDecoder() + getUseAuthorityRecordDecoder() ); } @@ -102,7 +96,7 @@ export async function fetchUseAuthorityRecord( rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchMaybeUseAuthorityRecord(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; @@ -114,7 +108,7 @@ export async function fetchMaybeUseAuthorityRecord< rpc: Parameters[0], address: Address, config?: FetchAccountConfig -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeUseAuthorityRecord(maybeAccount); } @@ -123,7 +117,7 @@ export async function fetchAllUseAuthorityRecord( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchAllMaybeUseAuthorityRecord( rpc, addresses, @@ -137,7 +131,7 @@ export async function fetchAllMaybeUseAuthorityRecord( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig -): Promise { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeUseAuthorityRecord(maybeAccount)