diff --git a/.changeset/six-gorillas-battle.md b/.changeset/six-gorillas-battle.md new file mode 100644 index 000000000..de06a0120 --- /dev/null +++ b/.changeset/six-gorillas-battle.md @@ -0,0 +1,5 @@ +--- +"@metaplex-foundation/kinobi": minor +--- + +Remove non-signer function overloads in JS experimental renderer diff --git a/.changeset/tough-bags-dress.md b/.changeset/tough-bags-dress.md new file mode 100644 index 000000000..5bb8e1943 --- /dev/null +++ b/.changeset/tough-bags-dress.md @@ -0,0 +1,5 @@ +--- +"@metaplex-foundation/kinobi": patch +--- + +Use generated address constant in instruction pages of JS experimental renderer diff --git a/src/renderers/js-experimental/fragments/index.ts b/src/renderers/js-experimental/fragments/index.ts index 99fb3f2d6..fdcf2c36c 100644 --- a/src/renderers/js-experimental/fragments/index.ts +++ b/src/renderers/js-experimental/fragments/index.ts @@ -9,8 +9,7 @@ export * from './instructionAccountTypeParam'; export * from './instructionByteDelta'; export * from './instructionData'; export * from './instructionExtraArgs'; -export * from './instructionFunctionHighLevel'; -export * from './instructionFunctionLowLevel'; +export * from './instructionFunction'; export * from './instructionInputDefault'; export * from './instructionInputResolved'; export * from './instructionInputType'; diff --git a/src/renderers/js-experimental/fragments/instructionAccountMeta.ts b/src/renderers/js-experimental/fragments/instructionAccountMeta.ts index cb2009045..d68112e03 100644 --- a/src/renderers/js-experimental/fragments/instructionAccountMeta.ts +++ b/src/renderers/js-experimental/fragments/instructionAccountMeta.ts @@ -3,8 +3,7 @@ import { pascalCase } from '../../../shared'; import { Fragment, fragment } from './common'; export function getInstructionAccountMetaFragment( - instructionAccountNode: InstructionAccountNode, - withSigners: boolean + instructionAccountNode: InstructionAccountNode ): Fragment { const typeParam = `TAccount${pascalCase(instructionAccountNode.name)}`; @@ -14,23 +13,19 @@ export function getInstructionAccountMetaFragment( instructionAccountNode.isWritable ) { return fragment( - withSigners - ? `WritableSignerAccount<${typeParam}> & IAccountSignerMeta<${typeParam}>` - : `WritableSignerAccount<${typeParam}>` + `WritableSignerAccount<${typeParam}> & IAccountSignerMeta<${typeParam}>` ) .addImports('solanaInstructions', ['WritableSignerAccount']) - .addImports('solanaSigners', withSigners ? ['IAccountSignerMeta'] : []); + .addImports('solanaSigners', ['IAccountSignerMeta']); } // Readonly, signer. if (instructionAccountNode.isSigner === true) { return fragment( - withSigners - ? `ReadonlySignerAccount<${typeParam}> & IAccountSignerMeta<${typeParam}>` - : `ReadonlySignerAccount<${typeParam}>` + `ReadonlySignerAccount<${typeParam}> & IAccountSignerMeta<${typeParam}>` ) .addImports('solanaInstructions', ['ReadonlySignerAccount']) - .addImports('solanaSigners', withSigners ? ['IAccountSignerMeta'] : []); + .addImports('solanaSigners', ['IAccountSignerMeta']); } // Writable, non-signer or optional signer. diff --git a/src/renderers/js-experimental/fragments/instructionFunction.njk b/src/renderers/js-experimental/fragments/instructionFunction.njk new file mode 100644 index 000000000..8c38927e9 --- /dev/null +++ b/src/renderers/js-experimental/fragments/instructionFunction.njk @@ -0,0 +1,62 @@ +{{ inputTypeFragment }} + +export {{ 'async' if useAsync }} function {{ functionName }}<{{ typeParamsFragment }}>(input: {{ inputTypeCallFragment }}): {{ getReturnType(instructionTypeFragment) }} { + // Program address. + const programAddress = {{ programAddressConstant }}; + + {% if hasAccounts %} + // Original accounts. + const originalAccounts = { + {% for account in instruction.accounts %} + {{ account.name | camelCase }}: { value: input.{{ account.name | camelCase }} ?? null, isWritable: {{ "true" if account.isWritable else "false" }} }, + {% endfor %} + }; + const accounts = originalAccounts as Record; + {% endif %} + + {% if hasAnyArgs %} + // Original args. + const args = { ...input, {{ renamedArgs }} }; + {% endif %} + + {% if hasResolver %} + // Resolver scope. + const resolverScope = { programAddress{{ ', accounts' if hasAccounts }}{{ ', args' if hasAnyArgs }} }; + {% endif %} + + {{ resolvedFragment }} + + {% if hasAccounts %} + const getAccountMeta = getAccountMetaFactory(programAddress, '{{ 'omitted' if instruction.optionalAccountStrategy === 'omitted' else 'programId' }}'); + {% endif %} + const instruction = { + {%- if hasAccounts -%} + accounts: [ + {% for account in instruction.accounts %} + getAccountMeta(accounts.{{ account.name | camelCase }}), + {% endfor %} + {% if hasRemainingAccounts %} + ...remainingAccounts, + {% endif %} + ] + {%- if hasLegacyOptionalAccounts -%} + .filter((x: T | undefined): x is T => x !== undefined) + {% endif %} + , + {%- elif hasRemainingAccounts -%} + accounts: remainingAccounts, + {% endif %} + programAddress, + {% if hasDataArgs %} + data: {{ encoderFunction }}.encode(args as {{ argsTypeFragment }}), + {% elif hasData %} + data: {{ encoderFunction }}.encode({}), + {% endif %} + } as {{ instructionTypeFragment }}; + + {% if hasByteDeltas %} + return Object.freeze({ ...instruction, byteDelta }); + {% else %} + return instruction; + {% endif %} +} diff --git a/src/renderers/js-experimental/fragments/instructionFunctionHighLevel.ts b/src/renderers/js-experimental/fragments/instructionFunction.ts similarity index 64% rename from src/renderers/js-experimental/fragments/instructionFunctionHighLevel.ts rename to src/renderers/js-experimental/fragments/instructionFunction.ts index 30263dd4b..ee0593fa0 100644 --- a/src/renderers/js-experimental/fragments/instructionFunctionHighLevel.ts +++ b/src/renderers/js-experimental/fragments/instructionFunction.ts @@ -16,7 +16,7 @@ import { getInstructionInputResolvedFragment } from './instructionInputResolved' import { getInstructionInputTypeFragment } from './instructionInputType'; import { getInstructionRemainingAccountsFragment } from './instructionRemainingAccounts'; -export function getInstructionFunctionHighLevelFragment( +export function getInstructionFunctionFragment( scope: Pick< GlobalFragmentScope, 'nameApi' | 'asyncResolvers' | 'valueNodeVisitor' | 'customInstructionData' @@ -50,6 +50,10 @@ export function getInstructionFunctionHighLevelFragment( const customData = customInstructionData.get(instructionNode.name); const hasAccounts = instructionNode.accounts.length > 0; + const hasLegacyOptionalAccounts = + instructionNode.optionalAccountStrategy === 'omitted' && + instructionNode.accounts.some((account) => account.isOptional); + const hasData = !!customData || instructionNode.arguments.length > 0; const hasDataArgs = !!customData || instructionNode.arguments.filter( @@ -61,49 +65,34 @@ export function getInstructionFunctionHighLevelFragment( ).length > 0; const hasAnyArgs = hasDataArgs || hasExtraArgs; const instructionDataName = nameApi.instructionDataType(instructionNode.name); + const programAddressConstant = nameApi.programAddressConstant( + programNode.name + ); + const encoderFunction = customData + ? dataArgsManifest.encoder.render + : `${nameApi.encoderFunction(instructionDataName)}()`; const argsTypeFragment = fragment( customData ? dataArgsManifest.looseType.render : nameApi.dataArgsType(instructionDataName) ); if (customData) { - argsTypeFragment.mergeImportsWith(dataArgsManifest.looseType); + argsTypeFragment.mergeImportsWith( + dataArgsManifest.looseType, + dataArgsManifest.encoder + ); } const functionName = useAsync ? nameApi.instructionAsyncFunction(instructionNode.name) : nameApi.instructionSyncFunction(instructionNode.name); - const lowLevelFunctionName = nameApi.instructionRawFunction( - instructionNode.name - ); - const typeParamsFragment = getTypeParams(instructionNode, programNode); - const instructionTypeFragment = getInstructionType({ - ...scope, - withSigners: false, - }); - const instructionTypeWithSignersFragment = getInstructionType({ - ...scope, - withSigners: true, - }); + const typeParamsFragment = getTypeParams(instructionNode); + const instructionTypeFragment = getInstructionType(scope); // Input. - const inputTypeFragment = getInstructionInputTypeFragment({ - ...scope, - withSigners: false, - }); - const inputTypeWithSignersFragment = getInstructionInputTypeFragment({ - ...scope, - withSigners: true, - }); - const inputTypeCallFragment = getInputTypeCall({ - ...scope, - withSigners: false, - }); - const inputTypeCallWithSignersFragment = getInputTypeCall({ - ...scope, - withSigners: true, - }); + const inputTypeFragment = getInstructionInputTypeFragment(scope); + const inputTypeCallFragment = getInputTypeCall(scope); const renamedArgsText = [...renamedArgs.entries()] .map(([k, v]) => `${k}: input.${v}`) .join(', '); @@ -129,51 +118,45 @@ export function getInstructionFunctionHighLevelFragment( return useAsync ? `Promise<${returnType}>` : returnType; }; - const functionFragment = fragmentFromTemplate( - 'instructionFunctionHighLevel.njk', - { - instruction: instructionNode, - program: programNode, - hasAccounts, - hasDataArgs, - hasExtraArgs, - hasAnyArgs, - argsTypeFragment, - functionName, - lowLevelFunctionName, - typeParamsFragment, - instructionTypeFragment, - instructionTypeWithSignersFragment, - inputTypeFragment, - inputTypeWithSignersFragment, - inputTypeCallFragment, - inputTypeCallWithSignersFragment, - renamedArgs: renamedArgsText, - resolvedFragment, - hasRemainingAccounts, - hasByteDeltas, - hasResolver, - useAsync, - getReturnType, - } - ) + const functionFragment = fragmentFromTemplate('instructionFunction.njk', { + instruction: instructionNode, + programAddressConstant, + hasAccounts, + hasLegacyOptionalAccounts, + hasData, + hasDataArgs, + hasExtraArgs, + hasAnyArgs, + encoderFunction, + argsTypeFragment, + functionName, + typeParamsFragment, + instructionTypeFragment, + inputTypeFragment, + inputTypeCallFragment, + renamedArgs: renamedArgsText, + resolvedFragment, + hasRemainingAccounts, + hasByteDeltas, + hasResolver, + useAsync, + getReturnType, + }) .mergeImportsWith( typeParamsFragment, instructionTypeFragment, - instructionTypeWithSignersFragment, inputTypeFragment, - inputTypeWithSignersFragment, inputTypeCallFragment, - inputTypeCallWithSignersFragment, resolvedFragment, argsTypeFragment ) + .addImports('generatedPrograms', [programAddressConstant]) .addImports('solanaAddresses', ['Address']); if (hasAccounts) { functionFragment .addImports('solanaInstructions', ['IAccountMeta']) - .addImports('shared', ['getAccountMetasWithSigners', 'ResolvedAccount']); + .addImports('shared', ['getAccountMetaFactory', 'ResolvedAccount']); } if (hasByteDeltas) { @@ -183,33 +166,31 @@ export function getInstructionFunctionHighLevelFragment( return functionFragment; } -function getTypeParams( - instructionNode: InstructionNode, - programNode: ProgramNode -): Fragment { - const typeParams = [ - ...instructionNode.accounts.map( - (account) => `TAccount${pascalCase(account.name)} extends string` - ), - `TProgram extends string = "${programNode.publicKey}"`, - ]; +function getTypeParams(instructionNode: InstructionNode): Fragment { + const typeParams = instructionNode.accounts.map( + (account) => `TAccount${pascalCase(account.name)} extends string` + ); return fragment(typeParams.filter((x) => !!x).join(', ')); } function getInstructionType(scope: { instructionNode: InstructionNode; - withSigners: boolean; + programNode: ProgramNode; nameApi: NameApi; }): Fragment { - const { instructionNode, withSigners, nameApi } = scope; - const instructionTypeName = withSigners - ? nameApi.instructionWithSignersType(instructionNode.name) - : nameApi.instructionType(instructionNode.name); + const { instructionNode, programNode, nameApi } = scope; + const instructionTypeName = nameApi.instructionType(instructionNode.name); + const programAddressConstant = nameApi.programAddressConstant( + programNode.name + ); + const programAddressFragment = fragment( + `typeof ${programAddressConstant}` + ).addImports('generatedPrograms', [programAddressConstant]); const accountTypeParamsFragments = instructionNode.accounts.map((account) => { const typeParam = `TAccount${pascalCase(account.name)}`; const camelName = camelCase(account.name); - if (account.isSigner === 'either' && withSigners) { + if (account.isSigner === 'either') { const signerRole = account.isWritable ? 'WritableSignerAccount' : 'ReadonlySignerAccount'; @@ -226,25 +207,20 @@ function getInstructionType(scope: { }); return mergeFragments( - [fragment('TProgram'), ...accountTypeParamsFragments], + [programAddressFragment, ...accountTypeParamsFragments], (renders) => renders.join(', ') ).mapRender((r) => `${instructionTypeName}<${r}>`); } function getInputTypeCall(scope: { instructionNode: InstructionNode; - withSigners: boolean; useAsync: boolean; nameApi: NameApi; }): Fragment { - const { instructionNode, withSigners, useAsync, nameApi } = scope; - const syncInputTypeName = withSigners - ? nameApi.instructionSyncInputWithSignersType(instructionNode.name) + const { instructionNode, useAsync, nameApi } = scope; + const inputTypeName = useAsync + ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name); - const asyncInputTypeName = withSigners - ? nameApi.instructionAsyncInputWithSignersType(instructionNode.name) - : nameApi.instructionAsyncInputType(instructionNode.name); - const inputTypeName = useAsync ? asyncInputTypeName : syncInputTypeName; if (instructionNode.accounts.length === 0) return fragment(inputTypeName); const accountTypeParams = instructionNode.accounts .map((account) => `TAccount${pascalCase(account.name)}`) diff --git a/src/renderers/js-experimental/fragments/instructionFunctionHighLevel.njk b/src/renderers/js-experimental/fragments/instructionFunctionHighLevel.njk deleted file mode 100644 index cb64c7516..000000000 --- a/src/renderers/js-experimental/fragments/instructionFunctionHighLevel.njk +++ /dev/null @@ -1,60 +0,0 @@ -{{ inputTypeFragment }} -{{ inputTypeWithSignersFragment }} - -export {{ 'async' if useAsync }} function {{ functionName }}<{{ typeParamsFragment }}>(input: {{ inputTypeCallWithSignersFragment }}): {{ getReturnType(instructionTypeWithSignersFragment) }}; -export {{ 'async' if useAsync }} function {{ functionName }}<{{ typeParamsFragment }}>(input: {{ inputTypeCallFragment }}): {{ getReturnType(instructionTypeFragment) }}; -export {{ 'async' if useAsync }} function {{ functionName }}<{{ typeParamsFragment }}>(input: {{ inputTypeCallFragment }}): {{ getReturnType('IInstruction') }} { - // Program address. - const programAddress = "{{ program.publicKey }}" as Address<"{{ program.publicKey }}">; - - {% if hasAccounts %} - // Original accounts. - type AccountMetas = Parameters>[0]; - const accounts: Record = { - {% for account in instruction.accounts %} - {{ account.name | camelCase }}: { value: input.{{ account.name | camelCase }} ?? null, isWritable: {{ "true" if account.isWritable else "false" }} }, - {% endfor %} - }; - {% endif %} - - {% if hasAnyArgs %} - // Original args. - const args = { ...input, {{ renamedArgs }} }; - {% endif %} - - {% if hasResolver %} - // Resolver scope. - const resolverScope = { programAddress{{ ', accounts' if hasAccounts }}{{ ', args' if hasAnyArgs }} }; - {% endif %} - - {{ resolvedFragment }} - - {% if hasAccounts %} - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners(accounts, 'programId', programAddress); - {% endif %} - - const instruction = {{ lowLevelFunctionName }}( - {%- if hasAccounts -%} - accountMetas as Record, - {% endif %} - {%- if hasDataArgs -%} - args as {{ argsTypeFragment }}, - {% endif %} - programAddress, - {%- if hasRemainingAccounts -%} - remainingAccounts, - {% endif %} - ); - - {% if hasByteDeltas %} - return Object.freeze({ ...instruction, byteDelta }); - {% else %} - return instruction; - {% endif %} -} diff --git a/src/renderers/js-experimental/fragments/instructionFunctionLowLevel.njk b/src/renderers/js-experimental/fragments/instructionFunctionLowLevel.njk deleted file mode 100644 index eb07c249a..000000000 --- a/src/renderers/js-experimental/fragments/instructionFunctionLowLevel.njk +++ /dev/null @@ -1,49 +0,0 @@ -export function {{ functionName }}< - TProgram extends string = "{{ program.publicKey }}", - {% if hasAccounts %} - {{ accountTypeParams }}, - {% endif %} - TRemainingAccounts extends Array> = [], ->( - {% if hasAccounts %} - accounts: { - {% for account in accounts %} - {{ account.name | camelCase }}{{ "?" if account.isOptionalOrHasLowLevelDefaultValues }}: {{ account.typeParam }} extends string ? Address<{{ account.typeParam }}> : {{ account.typeParam }}; - {% endfor %} - }, - {% endif %} - {% if hasArgs %} - args: {{ argsType }}, - {% endif %} - programAddress: Address = "{{ program.publicKey }}" as Address, - remainingAccounts?: TRemainingAccounts -) { - return { - {% if hasAccounts %} - accounts: [ - {% for account in accounts %} - accountMetaWithDefault(accounts.{{ account.name | camelCase }}{{ " ?? " + account.defaultValue if account.defaultValue }}, {{ account.defaultRole }}), - {% endfor %} - ...(remainingAccounts ?? []), - ] - {%- if hasLegacyOptionalAccounts -%} - .filter((x: T | undefined): x is T => x !== undefined) - {% endif %} - , - {% else %} - accounts: remainingAccounts ?? [], - {% endif %} - {% if hasData and hasArgs %} - data: {{ encoderFunction }}.encode(args), - {% elif hasData %} - data: {{ encoderFunction }}.encode({}), - {% endif %} - programAddress, - } as {{ instructionType }}< - TProgram, - {% for account in accounts %} - {{ account.typeParam }}, - {% endfor %} - TRemainingAccounts, - >; -} diff --git a/src/renderers/js-experimental/fragments/instructionFunctionLowLevel.ts b/src/renderers/js-experimental/fragments/instructionFunctionLowLevel.ts deleted file mode 100644 index f4878b0d5..000000000 --- a/src/renderers/js-experimental/fragments/instructionFunctionLowLevel.ts +++ /dev/null @@ -1,155 +0,0 @@ -import { - InstructionAccountNode, - InstructionNode, - ProgramNode, - isNode, -} from '../../../nodes'; -import { pascalCase } from '../../../shared'; -import { ImportMap } from '../ImportMap'; -import { TypeManifest } from '../TypeManifest'; -import type { GlobalFragmentScope } from '../getRenderMapVisitor'; -import { NameApi } from '../nameTransformers'; -import { - Fragment, - fragment, - fragmentFromTemplate, - mergeFragments, -} from './common'; -import { getInstructionAccountTypeParamFragment } from './instructionAccountTypeParam'; - -export function getInstructionFunctionLowLevelFragment( - scope: Pick< - GlobalFragmentScope, - 'nameApi' | 'linkables' | 'customInstructionData' - > & { - instructionNode: InstructionNode; - programNode: ProgramNode; - dataArgsManifest: TypeManifest; - } -): Fragment { - const { - instructionNode, - programNode, - dataArgsManifest, - nameApi, - customInstructionData, - } = scope; - const imports = new ImportMap(); - const hasAccounts = instructionNode.accounts.length > 0; - const hasLegacyOptionalAccounts = - instructionNode.optionalAccountStrategy === 'omitted' && - instructionNode.accounts.some((account) => account.isOptional); - const customData = customInstructionData.get(instructionNode.name); - const hasData = !!customData || instructionNode.arguments.length > 0; - const hasArgs = - !!customData || - instructionNode.arguments.filter( - (field) => !field.defaultValue || field.defaultValueStrategy !== 'omitted' - ).length > 0; - const instructionDataName = nameApi.instructionDataType(instructionNode.name); - const argsType = customData - ? dataArgsManifest.looseType.render - : nameApi.dataArgsType(instructionDataName); - const encoderFunction = customData - ? dataArgsManifest.encoder.render - : `${nameApi.encoderFunction(instructionDataName)}()`; - if (customData) { - imports.mergeWith(dataArgsManifest.looseType, dataArgsManifest.encoder); - } - - const accountTypeParamsFragment = mergeFragments( - instructionNode.accounts.map((account) => - getInstructionAccountTypeParamFragment({ - ...scope, - instructionAccountNode: account, - allowAccountMeta: true, - }) - ), - (renders) => renders.join(', ') - ); - - const accounts = instructionNode.accounts.map((account) => { - const typeParam = `TAccount${pascalCase(account.name)}`; - const defaultValueFragment = getDefaultValue( - account, - programNode, - nameApi, - instructionNode.optionalAccountStrategy === 'omitted' - ); - imports.mergeWith(defaultValueFragment); - const defaultValue = defaultValueFragment.render || null; - const isOptionalOrHasLowLevelDefaultValues = - account.isOptional || defaultValue !== null; - - return { - ...account, - typeParam, - defaultRole: getDefaultRole(account), - defaultValue, - isOptionalOrHasLowLevelDefaultValues, - }; - }); - - return fragmentFromTemplate('instructionFunctionLowLevel.njk', { - instruction: instructionNode, - program: programNode, - functionName: nameApi.instructionRawFunction(instructionNode.name), - instructionType: nameApi.instructionType(instructionNode.name), - hasAccounts, - hasLegacyOptionalAccounts, - accounts, - hasData, - hasArgs, - argsType, - encoderFunction, - accountTypeParams: accountTypeParamsFragment.render, - }) - .mergeImportsWith(imports, accountTypeParamsFragment) - .addImports('solanaAddresses', ['Address']) - .addImports('solanaInstructions', ['IAccountMeta']) - .addImports('shared', hasAccounts ? ['accountMetaWithDefault'] : []) - .addImports('solanaInstructions', hasAccounts ? ['AccountRole'] : []); -} - -function getDefaultRole(account: InstructionAccountNode): string { - if (account.isSigner === true && account.isWritable) { - return 'AccountRole.WRITABLE_SIGNER'; - } - if (account.isSigner === true) { - return 'AccountRole.READONLY_SIGNER'; - } - if (account.isWritable) { - return 'AccountRole.WRITABLE'; - } - return 'AccountRole.READONLY'; -} - -function getDefaultValue( - account: InstructionAccountNode, - program: ProgramNode, - nameApi: NameApi, - usesLegacyOptionalAccounts: boolean -): Fragment { - if (account.isOptional && usesLegacyOptionalAccounts) { - return fragment(''); - } - const defaultValue = account.defaultValue ?? null; - if (account.isOptional || isNode(defaultValue, 'programIdValueNode')) { - return fragment( - `{ address: "${program.publicKey}" as Address<"${program.publicKey}">, role: AccountRole.READONLY }` - ); - } - if (isNode(defaultValue, 'publicKeyValueNode')) { - return fragment( - `"${defaultValue.publicKey}" as Address<"${defaultValue.publicKey}">` - ); - } - if (isNode(defaultValue, 'programLinkNode')) { - const programAddress = nameApi.programAddressConstant(defaultValue.name); - const importFrom = defaultValue.importFrom ?? 'generatedPrograms'; - return fragment( - `{ address: ${programAddress}, role: AccountRole.READONLY }` - ).addImports(importFrom, programAddress); - } - return fragment(''); -} diff --git a/src/renderers/js-experimental/fragments/instructionInputType.njk b/src/renderers/js-experimental/fragments/instructionInputType.njk index 42f970d78..271d1255d 100644 --- a/src/renderers/js-experimental/fragments/instructionInputType.njk +++ b/src/renderers/js-experimental/fragments/instructionInputType.njk @@ -4,7 +4,7 @@ export type {{ instructionInputType }} {%- if accounts.length > 0 -%} < {%- for account in accounts -%} - {{ account.typeParam }} extends string, + {{ account.typeParam }} extends string = string, {% endfor %} > {% endif %} diff --git a/src/renderers/js-experimental/fragments/instructionInputType.ts b/src/renderers/js-experimental/fragments/instructionInputType.ts index 1d45837a1..59195ba04 100644 --- a/src/renderers/js-experimental/fragments/instructionInputType.ts +++ b/src/renderers/js-experimental/fragments/instructionInputType.ts @@ -26,7 +26,6 @@ export function getInstructionInputTypeFragment( renamedArgs: Map; dataArgsManifest: TypeManifest; programNode: ProgramNode; - withSigners: boolean; useAsync: boolean; } ): Fragment { @@ -36,7 +35,6 @@ export function getInstructionInputTypeFragment( renamedArgs, dataArgsManifest, programNode, - withSigners, asyncResolvers, useAsync, nameApi, @@ -59,7 +57,7 @@ export function getInstructionInputTypeFragment( ]) && (useAsync || !isAsyncDefaultValue(resolvedAccount.defaultValue, asyncResolvers)); - const type = getAccountType(resolvedAccount, withSigners); + const type = getAccountType(resolvedAccount); accountImports.mergeWith(type); return { ...resolvedAccount, @@ -107,14 +105,9 @@ export function getInstructionInputTypeFragment( : instructionNode.arguments.flatMap(resolveArg); const extraArgsType = nameApi.dataArgsType(instructionExtraName); const extraArgs = (instructionNode.extraArguments ?? []).flatMap(resolveArg); - - const syncInputType = withSigners - ? nameApi.instructionSyncInputWithSignersType(instructionNode.name) + const instructionInputType = useAsync + ? nameApi.instructionAsyncInputType(instructionNode.name) : nameApi.instructionSyncInputType(instructionNode.name); - const asyncInputType = withSigners - ? nameApi.instructionAsyncInputWithSignersType(instructionNode.name) - : nameApi.instructionAsyncInputType(instructionNode.name); - const instructionInputType = useAsync ? asyncInputType : syncInputType; return fragmentFromTemplate('instructionInputType.njk', { instruction: instructionNode, @@ -130,46 +123,34 @@ export function getInstructionInputTypeFragment( .addImports('solanaAddresses', ['Address']); } -function getAccountType( - account: ResolvedInstructionAccount, - withSigners: boolean -): Fragment { +function getAccountType(account: ResolvedInstructionAccount): Fragment { const typeParam = `TAccount${pascalCase(account.name)}`; - if (withSigners) { - if (account.isPda && account.isSigner === false) { - return fragment(`ProgramDerivedAddress<${typeParam}>`).addImports( - 'solanaAddresses', - ['ProgramDerivedAddress'] - ); - } - - if (account.isPda && account.isSigner === 'either') { - return fragment( - `ProgramDerivedAddress<${typeParam}> | TransactionSigner<${typeParam}>` - ) - .addImports('solanaAddresses', ['ProgramDerivedAddress']) - .addImports('solanaSigners', ['TransactionSigner']); - } + if (account.isPda && account.isSigner === false) { + return fragment(`ProgramDerivedAddress<${typeParam}>`).addImports( + 'solanaAddresses', + ['ProgramDerivedAddress'] + ); + } - if (account.isSigner === 'either') { - return fragment(`Address<${typeParam}> | TransactionSigner<${typeParam}>`) - .addImports('solanaAddresses', ['Address']) - .addImports('solanaSigners', ['TransactionSigner']); - } + if (account.isPda && account.isSigner === 'either') { + return fragment( + `ProgramDerivedAddress<${typeParam}> | TransactionSigner<${typeParam}>` + ) + .addImports('solanaAddresses', ['ProgramDerivedAddress']) + .addImports('solanaSigners', ['TransactionSigner']); + } - if (account.isSigner) { - return fragment(`TransactionSigner<${typeParam}>`).addImports( - 'solanaSigners', - ['TransactionSigner'] - ); - } + if (account.isSigner === 'either') { + return fragment(`Address<${typeParam}> | TransactionSigner<${typeParam}>`) + .addImports('solanaAddresses', ['Address']) + .addImports('solanaSigners', ['TransactionSigner']); } - if (!withSigners && account.isPda) { - return fragment(`ProgramDerivedAddress<${typeParam}>`).addImports( - 'solanaAddresses', - ['ProgramDerivedAddress'] + if (account.isSigner) { + return fragment(`TransactionSigner<${typeParam}>`).addImports( + 'solanaSigners', + ['TransactionSigner'] ); } diff --git a/src/renderers/js-experimental/fragments/instructionParseFunction.njk b/src/renderers/js-experimental/fragments/instructionParseFunction.njk index c7c363bfc..05b3118a5 100644 --- a/src/renderers/js-experimental/fragments/instructionParseFunction.njk +++ b/src/renderers/js-experimental/fragments/instructionParseFunction.njk @@ -1,7 +1,7 @@ {% import "templates/macros.njk" as macros %} export type {{ instructionParsedType }}< - TProgram extends string = '{{ programAddress }}', + TProgram extends string = typeof {{ programAddressConstant }}, {% if hasAccounts %} TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], {% endif %} @@ -50,7 +50,7 @@ export function {{ instructionParseFunction }}< {% if hasOptionalAccounts and instruction.optionalAccountStrategy === 'programId' %} const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === '{{ programAddress }}' ? undefined : accountMeta; + return accountMeta.address === {{ programAddressConstant }} ? undefined : accountMeta; }; {% elif hasOptionalAccounts and instruction.optionalAccountStrategy === 'omitted' %} let optionalAccountsRemaining = instruction.accounts.length - {{ minimumNumberOfAccounts }}; diff --git a/src/renderers/js-experimental/fragments/instructionParseFunction.ts b/src/renderers/js-experimental/fragments/instructionParseFunction.ts index e51f85fe6..26b88ef92 100644 --- a/src/renderers/js-experimental/fragments/instructionParseFunction.ts +++ b/src/renderers/js-experimental/fragments/instructionParseFunction.ts @@ -33,6 +33,9 @@ export function getInstructionParseFunctionFragment( } const instructionDataName = nameApi.instructionDataType(instructionNode.name); + const programAddressConstant = nameApi.programAddressConstant( + programNode.name + ); const dataTypeFragment = fragment( customData ? dataArgsManifest.strictType.render @@ -50,7 +53,7 @@ export function getInstructionParseFunctionFragment( return fragmentFromTemplate('instructionParseFunction.njk', { instruction: instructionNode, - programAddress: programNode.publicKey, + programAddressConstant, instructionParsedType: nameApi.instructionParsedType(instructionNode.name), instructionParseFunction: nameApi.instructionParseFunction( instructionNode.name @@ -63,6 +66,7 @@ export function getInstructionParseFunctionFragment( hasData, }) .mergeImportsWith(dataTypeFragment) + .addImports('generatedPrograms', [programAddressConstant]) .addImports('solanaInstructions', ['IInstruction']) .addImports( 'solanaInstructions', diff --git a/src/renderers/js-experimental/fragments/instructionType.njk b/src/renderers/js-experimental/fragments/instructionType.njk index 9a134a711..e5c0e2713 100644 --- a/src/renderers/js-experimental/fragments/instructionType.njk +++ b/src/renderers/js-experimental/fragments/instructionType.njk @@ -1,11 +1,11 @@ {% import "templates/macros.njk" as macros %} export type {{ instructionType }}< - TProgram extends string = "{{ program.publicKey }}", + TProgram extends string = typeof {{ programAddressConstant }}, {% if hasAccounts %} {{ accountTypeParams }}, {% endif %} - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction {% if hasData %} & IInstructionWithData diff --git a/src/renderers/js-experimental/fragments/instructionType.ts b/src/renderers/js-experimental/fragments/instructionType.ts index 0a32b3173..240dc4831 100644 --- a/src/renderers/js-experimental/fragments/instructionType.ts +++ b/src/renderers/js-experimental/fragments/instructionType.ts @@ -12,20 +12,17 @@ export function getInstructionTypeFragment( > & { instructionNode: InstructionNode; programNode: ProgramNode; - withSigners: boolean; } ): Fragment { - const { - instructionNode, - programNode, - withSigners, - nameApi, - customInstructionData, - } = scope; + const { instructionNode, programNode, nameApi, customInstructionData } = + scope; const hasAccounts = instructionNode.accounts.length > 0; const customData = customInstructionData.get(instructionNode.name); const hasData = !!customData || instructionNode.arguments.length > 0; const instructionDataName = nameApi.instructionDataType(instructionNode.name); + const programAddressConstant = nameApi.programAddressConstant( + programNode.name + ); const dataType = customData ? pascalCase(customData.importAs) : pascalCase(instructionDataName); @@ -43,7 +40,7 @@ export function getInstructionTypeFragment( instructionNode.optionalAccountStrategy === 'omitted'; const accountMetasFragment = mergeFragments( instructionNode.accounts.map((account) => - getInstructionAccountMetaFragment(account, withSigners).mapRender((r) => { + getInstructionAccountMetaFragment(account).mapRender((r) => { const typeParam = `TAccount${pascalCase(account.name)}`; const isLegacyOptional = account.isOptional && usesLegacyOptionalAccounts; @@ -57,10 +54,8 @@ export function getInstructionTypeFragment( const fragment = fragmentFromTemplate('instructionType.njk', { instruction: instructionNode, - instructionType: withSigners - ? nameApi.instructionWithSignersType(instructionNode.name) - : nameApi.instructionType(instructionNode.name), - program: programNode, + instructionType: nameApi.instructionType(instructionNode.name), + programAddressConstant, hasData, hasAccounts, dataType, @@ -68,6 +63,7 @@ export function getInstructionTypeFragment( accountMetas: accountMetasFragment.render, }) .mergeImportsWith(accountTypeParamsFragment, accountMetasFragment) + .addImports('generatedPrograms', [programAddressConstant]) .addImports('solanaInstructions', [ 'IAccountMeta', 'IInstruction', diff --git a/src/renderers/js-experimental/getRenderMapVisitor.ts b/src/renderers/js-experimental/getRenderMapVisitor.ts index f9093efe7..1a5d2d5bf 100644 --- a/src/renderers/js-experimental/getRenderMapVisitor.ts +++ b/src/renderers/js-experimental/getRenderMapVisitor.ts @@ -41,8 +41,7 @@ import { getAccountTypeFragment, getInstructionDataFragment, getInstructionExtraArgsFragment, - getInstructionFunctionHighLevelFragment, - getInstructionFunctionLowLevelFragment, + getInstructionFunctionFragment, getInstructionParseFunctionFragment, getInstructionTypeFragment, getPdaFunctionFragment, @@ -393,43 +392,30 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { }; // Fragments. - const instructionTypeFragment = getInstructionTypeFragment({ - ...scope, - withSigners: false, - }); - const instructionTypeWithSignersFragment = getInstructionTypeFragment( - { - ...scope, - withSigners: true, - } - ); + const instructionTypeFragment = getInstructionTypeFragment(scope); const instructionDataFragment = getInstructionDataFragment(scope); const instructionExtraArgsFragment = getInstructionExtraArgsFragment(scope); - const instructionFunctionHighLevelAsyncFragment = - getInstructionFunctionHighLevelFragment({ + const instructionFunctionAsyncFragment = + getInstructionFunctionFragment({ ...scope, useAsync: true, }); - const instructionFunctionHighLevelSyncFragment = - getInstructionFunctionHighLevelFragment({ + const instructionFunctionSyncFragment = + getInstructionFunctionFragment({ ...scope, useAsync: false, }); - const instructionFunctionLowLevelFragment = - getInstructionFunctionLowLevelFragment(scope); const instructionParseFunctionFragment = getInstructionParseFunctionFragment(scope); // Imports and interfaces. const imports = new ImportMap().mergeWith( instructionTypeFragment, - instructionTypeWithSignersFragment, instructionDataFragment, instructionExtraArgsFragment, - instructionFunctionHighLevelAsyncFragment, - instructionFunctionHighLevelSyncFragment, - instructionFunctionLowLevelFragment, + instructionFunctionAsyncFragment, + instructionFunctionSyncFragment, instructionParseFunctionFragment ); @@ -439,12 +425,10 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { instruction: node, imports: imports.toString(dependencyMap), instructionTypeFragment, - instructionTypeWithSignersFragment, instructionDataFragment, instructionExtraArgsFragment, - instructionFunctionHighLevelAsyncFragment, - instructionFunctionHighLevelSyncFragment, - instructionFunctionLowLevelFragment, + instructionFunctionAsyncFragment, + instructionFunctionSyncFragment, instructionParseFunctionFragment, }) ); diff --git a/src/renderers/js-experimental/nameTransformers.ts b/src/renderers/js-experimental/nameTransformers.ts index 87a656e31..a8679a318 100644 --- a/src/renderers/js-experimental/nameTransformers.ts +++ b/src/renderers/js-experimental/nameTransformers.ts @@ -46,16 +46,12 @@ export type NameTransformerKey = | 'dataEnumFunction' | 'isDataEnumFunction' | 'instructionAsyncInputType' - | 'instructionAsyncInputWithSignersType' | 'instructionSyncInputType' - | 'instructionSyncInputWithSignersType' | 'instructionType' - | 'instructionWithSignersType' | 'instructionDataType' | 'instructionExtraType' | 'instructionAsyncFunction' | 'instructionSyncFunction' - | 'instructionRawFunction' | 'instructionParsedType' | 'instructionParseFunction' | 'programType' @@ -121,19 +117,12 @@ export const DEFAULT_NAME_TRANSFORMERS: NameTransformers = { dataEnumFunction: (name) => `${camelCase(name)}`, isDataEnumFunction: (name) => `is${pascalCase(name)}`, instructionAsyncInputType: (name) => `${pascalCase(name)}AsyncInput`, - instructionAsyncInputWithSignersType: (name) => - `${pascalCase(name)}AsyncInputWithSigners`, instructionSyncInputType: (name) => `${pascalCase(name)}Input`, - instructionSyncInputWithSignersType: (name) => - `${pascalCase(name)}InputWithSigners`, instructionType: (name) => `${pascalCase(name)}Instruction`, - instructionWithSignersType: (name) => - `${pascalCase(name)}InstructionWithSigners`, instructionDataType: (name) => `${pascalCase(name)}InstructionData`, instructionExtraType: (name) => `${pascalCase(name)}InstructionExtra`, instructionAsyncFunction: (name) => `get${pascalCase(name)}InstructionAsync`, instructionSyncFunction: (name) => `get${pascalCase(name)}Instruction`, - instructionRawFunction: (name) => `get${pascalCase(name)}InstructionRaw`, instructionParsedType: (name) => `Parsed${pascalCase(name)}Instruction`, instructionParseFunction: (name) => `parse${pascalCase(name)}Instruction`, programType: (name) => `${pascalCase(name)}Program`, diff --git a/src/renderers/js-experimental/templates/instructionsPage.njk b/src/renderers/js-experimental/templates/instructionsPage.njk index 5163039a2..adc9d0de7 100644 --- a/src/renderers/js-experimental/templates/instructionsPage.njk +++ b/src/renderers/js-experimental/templates/instructionsPage.njk @@ -5,11 +5,9 @@ {{ imports }} {{ instructionTypeFragment }} -{{ instructionTypeWithSignersFragment }} {{ instructionDataFragment }} {{ instructionExtraArgsFragment }} -{{ instructionFunctionHighLevelAsyncFragment }} -{{ instructionFunctionHighLevelSyncFragment }} -{{ instructionFunctionLowLevelFragment }} +{{ instructionFunctionAsyncFragment }} +{{ instructionFunctionSyncFragment }} {{ instructionParseFunctionFragment }} {% endblock %} diff --git a/src/renderers/js-experimental/templates/sharedPage.njk b/src/renderers/js-experimental/templates/sharedPage.njk index 6514f2a1e..54b670eab 100644 --- a/src/renderers/js-experimental/templates/sharedPage.njk +++ b/src/renderers/js-experimental/templates/sharedPage.njk @@ -71,20 +71,6 @@ export type ResolvedAccount | Pr value: U; }; -/** - * Add an account meta with a default role if only an address is provided. - * @internal - */ - export function accountMetaWithDefault, TRole extends AccountRole>( - account: TAccount | undefined, - role: TRole - ) { - if (account === undefined) return undefined; - return ( - typeof account === 'string' ? { address: account, role } : account - ) as TAccount extends string ? { address: Address; role: TRole } : TAccount; - } - /** * Defines an instruction that stores additional bytes on-chain. * @internal @@ -97,37 +83,23 @@ export type IInstructionWithByteDelta = { * Get account metas and signers from resolved accounts. * @internal */ -export function getAccountMetasWithSigners( - accounts: Record, +export function getAccountMetaFactory( + programAddress: Address, optionalAccountStrategy: 'omitted' | 'programId', - programAddress: Address -): Record { - const accountMetas: Record = {}; - - Object.keys(accounts).forEach((key) => { - const account = accounts[key as TKey] as ResolvedAccount; +) { + return (account: ResolvedAccount): IAccountMeta | IAccountSignerMeta | undefined => { if (!account.value) { if (optionalAccountStrategy === 'omitted') return; - accountMetas[key] = { - address: programAddress, - role: AccountRole.READONLY, - }; - return; + return Object.freeze({ address: programAddress, role: AccountRole.READONLY }); } - const writableRole = account.isWritable - ? AccountRole.WRITABLE - : AccountRole.READONLY; - accountMetas[key] = Object.freeze({ + const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY; + return Object.freeze({ address: expectAddress(account.value), - role: isTransactionSigner(account.value) - ? upgradeRoleToSigner(writableRole) - : writableRole, + role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole, ...(isTransactionSigner(account.value) ? { signer: account.value } : {}) }); - }); - - return accountMetas; + }; } export function isTransactionSigner(value: Address | ProgramDerivedAddress | TransactionSigner): value is TransactionSigner { diff --git a/test/packages/js-experimental/src/generated/instructions/addConfigLines.ts b/test/packages/js-experimental/src/generated/instructions/addConfigLines.ts index b1d307019..89ffb1d51 100644 --- a/test/packages/js-experimental/src/generated/instructions/addConfigLines.ts +++ b/test/packages/js-experimental/src/generated/instructions/addConfigLines.ts @@ -25,7 +25,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -34,11 +33,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { ConfigLine, ConfigLineArgs, @@ -47,29 +43,10 @@ import { } from '../types'; export type AddConfigLinesInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - ...TRemainingAccounts, - ] - >; - -export type AddConfigLinesInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -141,19 +118,8 @@ export function getAddConfigLinesInstructionDataCodec(): Codec< } export type AddConfigLinesInput< - TAccountCandyMachine extends string, - TAccountAuthority extends string, -> = { - candyMachine: Address; - authority: Address; - index: AddConfigLinesInstructionDataArgs['index']; - configLines: AddConfigLinesInstructionDataArgs['configLines']; - moreLines: AddConfigLinesInstructionDataArgs['moreLines']; -}; - -export type AddConfigLinesInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthority extends string, + TAccountCandyMachine extends string = string, + TAccountAuthority extends string = string, > = { candyMachine: Address; authority: TransactionSigner; @@ -165,100 +131,50 @@ export type AddConfigLinesInputWithSigners< export function getAddConfigLinesInstruction< TAccountCandyMachine extends string, TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( - input: AddConfigLinesInputWithSigners -): AddConfigLinesInstructionWithSigners< - TProgram, + input: AddConfigLinesInput +): AddConfigLinesInstruction< + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority ->; -export function getAddConfigLinesInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: AddConfigLinesInput -): AddConfigLinesInstruction; -export function getAddConfigLinesInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: AddConfigLinesInput -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getAddConfigLinesInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getAddConfigLinesInstructionRaw( - accountMetas as Record, - args as AddConfigLinesInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getAddConfigLinesInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - }, - args: AddConfigLinesInstructionDataArgs, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authority), ], - data: getAddConfigLinesInstructionDataEncoder().encode(args), programAddress, + data: getAddConfigLinesInstructionDataEncoder().encode( + args as AddConfigLinesInstructionDataArgs + ), } as AddConfigLinesInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, - TAccountAuthority, - TRemainingAccounts + TAccountAuthority >; + + return instruction; } export type ParsedAddConfigLinesInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/approveCollectionAuthority.ts b/test/packages/js-experimental/src/generated/instructions/approveCollectionAuthority.ts index 9d63faea9..0940fa015 100644 --- a/test/packages/js-experimental/src/generated/instructions/approveCollectionAuthority.ts +++ b/test/packages/js-experimental/src/generated/instructions/approveCollectionAuthority.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,61 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type ApproveCollectionAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountNewCollectionAuthority extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCollectionAuthorityRecord extends string - ? WritableAccount - : TAccountCollectionAuthorityRecord, - TAccountNewCollectionAuthority extends string - ? ReadonlyAccount - : TAccountNewCollectionAuthority, - TAccountUpdateAuthority extends string - ? WritableSignerAccount - : TAccountUpdateAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type ApproveCollectionAuthorityInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, @@ -96,7 +45,7 @@ export type ApproveCollectionAuthorityInstructionWithSigners< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -159,42 +108,14 @@ export function getApproveCollectionAuthorityInstructionDataCodec(): Codec< } export type ApproveCollectionAuthorityInput< - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionAuthority extends string, - TAccountUpdateAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Collection Authority Record PDA */ - collectionAuthorityRecord: Address; - /** A Collection Authority */ - newCollectionAuthority: Address; - /** Update Authority of Collection NFT */ - updateAuthority: Address; - /** Payer */ - payer: Address; - /** Collection Metadata account */ - metadata: Address; - /** Mint of Collection Metadata */ - mint: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; -}; - -export type ApproveCollectionAuthorityInputWithSigners< - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionAuthority extends string, - TAccountUpdateAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountCollectionAuthorityRecord extends string = string, + TAccountNewCollectionAuthority extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountPayer extends string = string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Collection Authority Record PDA */ collectionAuthorityRecord: Address; @@ -223,39 +144,6 @@ export function getApproveCollectionAuthorityInstruction< TAccountMint extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ApproveCollectionAuthorityInputWithSigners< - TAccountCollectionAuthorityRecord, - TAccountNewCollectionAuthority, - TAccountUpdateAuthority, - TAccountPayer, - TAccountMetadata, - TAccountMint, - TAccountSystemProgram, - TAccountRent - > -): ApproveCollectionAuthorityInstructionWithSigners< - TProgram, - TAccountCollectionAuthorityRecord, - TAccountNewCollectionAuthority, - TAccountUpdateAuthority, - TAccountPayer, - TAccountMetadata, - TAccountMint, - TAccountSystemProgram, - TAccountRent ->; -export function getApproveCollectionAuthorityInstruction< - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionAuthority extends string, - TAccountUpdateAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: ApproveCollectionAuthorityInput< TAccountCollectionAuthorityRecord, @@ -268,7 +156,7 @@ export function getApproveCollectionAuthorityInstruction< TAccountRent > ): ApproveCollectionAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionAuthorityRecord, TAccountNewCollectionAuthority, TAccountUpdateAuthority, @@ -277,48 +165,12 @@ export function getApproveCollectionAuthorityInstruction< TAccountMint, TAccountSystemProgram, TAccountRent ->; -export function getApproveCollectionAuthorityInstruction< - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionAuthority extends string, - TAccountUpdateAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ApproveCollectionAuthorityInput< - TAccountCollectionAuthorityRecord, - TAccountNewCollectionAuthority, - TAccountUpdateAuthority, - TAccountPayer, - TAccountMetadata, - TAccountMint, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getApproveCollectionAuthorityInstructionRaw< - TProgram, - TAccountCollectionAuthorityRecord, - TAccountNewCollectionAuthority, - TAccountUpdateAuthority, - TAccountPayer, - TAccountMetadata, - TAccountMint, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { collectionAuthorityRecord: { value: input.collectionAuthorityRecord ?? null, isWritable: true, @@ -334,6 +186,10 @@ export function getApproveCollectionAuthorityInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.systemProgram.value) { @@ -341,98 +197,22 @@ export function getApproveCollectionAuthorityInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getApproveCollectionAuthorityInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getApproveCollectionAuthorityInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountNewCollectionAuthority extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - collectionAuthorityRecord: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - newCollectionAuthority: TAccountNewCollectionAuthority extends string - ? Address - : TAccountNewCollectionAuthority; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault( - accounts.collectionAuthorityRecord, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.newCollectionAuthority, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.collectionAuthorityRecord), + getAccountMeta(accounts.newCollectionAuthority), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getApproveCollectionAuthorityInstructionDataEncoder().encode({}), programAddress, + data: getApproveCollectionAuthorityInstructionDataEncoder().encode({}), } as ApproveCollectionAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionAuthorityRecord, TAccountNewCollectionAuthority, TAccountUpdateAuthority, @@ -440,13 +220,14 @@ export function getApproveCollectionAuthorityInstructionRaw< TAccountMetadata, TAccountMint, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedApproveCollectionAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -491,7 +272,7 @@ export function parseApproveCollectionAuthorityInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/approveUseAuthority.ts b/test/packages/js-experimental/src/generated/instructions/approveUseAuthority.ts index f4223fa40..853af3bee 100644 --- a/test/packages/js-experimental/src/generated/instructions/approveUseAuthority.ts +++ b/test/packages/js-experimental/src/generated/instructions/approveUseAuthority.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -31,14 +30,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type ApproveUseAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountUseAuthorityRecord extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -54,66 +50,7 @@ export type ApproveUseAuthorityInstruction< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountUseAuthorityRecord extends string - ? WritableAccount - : TAccountUseAuthorityRecord, - TAccountOwner extends string - ? WritableSignerAccount - : TAccountOwner, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUser extends string - ? ReadonlyAccount - : TAccountUser, - TAccountOwnerTokenAccount extends string - ? WritableAccount - : TAccountOwnerTokenAccount, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountBurner extends string - ? ReadonlyAccount - : TAccountBurner, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type ApproveUseAuthorityInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUser extends string | IAccountMeta = string, - TAccountOwnerTokenAccount extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountBurner extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -194,55 +131,17 @@ export function getApproveUseAuthorityInstructionDataCodec(): Codec< } export type ApproveUseAuthorityInput< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountPayer extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountBurner extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Use Authority Record PDA */ - useAuthorityRecord: Address; - /** Owner */ - owner: Address; - /** Payer */ - payer: Address; - /** A Use Authority */ - user: Address; - /** Owned Token Account Of Mint */ - ownerTokenAccount: Address; - /** Metadata account */ - metadata: Address; - /** Mint of Metadata */ - mint: Address; - /** Program As Signer (Burner) */ - burner: Address; - /** Token program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - numberOfUses: ApproveUseAuthorityInstructionDataArgs['numberOfUses']; -}; - -export type ApproveUseAuthorityInputWithSigners< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountPayer extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountBurner extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountUseAuthorityRecord extends string = string, + TAccountOwner extends string = string, + TAccountPayer extends string = string, + TAccountUser extends string = string, + TAccountOwnerTokenAccount extends string = string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountBurner extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Use Authority Record PDA */ useAuthorityRecord: Address; @@ -281,48 +180,6 @@ export function getApproveUseAuthorityInstruction< TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ApproveUseAuthorityInputWithSigners< - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountPayer, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMetadata, - TAccountMint, - TAccountBurner, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): ApproveUseAuthorityInstructionWithSigners< - TProgram, - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountPayer, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMetadata, - TAccountMint, - TAccountBurner, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent ->; -export function getApproveUseAuthorityInstruction< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountPayer extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountBurner extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: ApproveUseAuthorityInput< TAccountUseAuthorityRecord, @@ -338,7 +195,7 @@ export function getApproveUseAuthorityInstruction< TAccountRent > ): ApproveUseAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountUseAuthorityRecord, TAccountOwner, TAccountPayer, @@ -350,57 +207,12 @@ export function getApproveUseAuthorityInstruction< TAccountTokenProgram, TAccountSystemProgram, TAccountRent ->; -export function getApproveUseAuthorityInstruction< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountPayer extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountBurner extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ApproveUseAuthorityInput< - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountPayer, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMetadata, - TAccountMint, - TAccountBurner, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getApproveUseAuthorityInstructionRaw< - TProgram, - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountPayer, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMetadata, - TAccountMint, - TAccountBurner, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { useAuthorityRecord: { value: input.useAuthorityRecord ?? null, isWritable: true, @@ -419,6 +231,10 @@ export function getApproveUseAuthorityInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -433,108 +249,27 @@ export function getApproveUseAuthorityInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getApproveUseAuthorityInstructionRaw( - accountMetas as Record, - args as ApproveUseAuthorityInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getApproveUseAuthorityInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUser extends string | IAccountMeta = string, - TAccountOwnerTokenAccount extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountBurner extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - useAuthorityRecord: TAccountUseAuthorityRecord extends string - ? Address - : TAccountUseAuthorityRecord; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - user: TAccountUser extends string ? Address : TAccountUser; - ownerTokenAccount: TAccountOwnerTokenAccount extends string - ? Address - : TAccountOwnerTokenAccount; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - burner: TAccountBurner extends string - ? Address - : TAccountBurner; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: ApproveUseAuthorityInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.useAuthorityRecord, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.owner, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.user, AccountRole.READONLY), - accountMetaWithDefault(accounts.ownerTokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault(accounts.burner, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.useAuthorityRecord), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.user), + getAccountMeta(accounts.ownerTokenAccount), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.burner), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getApproveUseAuthorityInstructionDataEncoder().encode(args), programAddress, + data: getApproveUseAuthorityInstructionDataEncoder().encode( + args as ApproveUseAuthorityInstructionDataArgs + ), } as ApproveUseAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountUseAuthorityRecord, TAccountOwner, TAccountPayer, @@ -545,13 +280,14 @@ export function getApproveUseAuthorityInstructionRaw< TAccountBurner, TAccountTokenProgram, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedApproveUseAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -602,7 +338,7 @@ export function parseApproveUseAuthorityInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/bubblegumSetCollectionSize.ts b/test/packages/js-experimental/src/generated/instructions/bubblegumSetCollectionSize.ts index 30fa001e8..33df41059 100644 --- a/test/packages/js-experimental/src/generated/instructions/bubblegumSetCollectionSize.ts +++ b/test/packages/js-experimental/src/generated/instructions/bubblegumSetCollectionSize.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { SetCollectionSizeArgs, SetCollectionSizeArgsArgs, @@ -43,7 +39,7 @@ import { } from '../types'; export type BubblegumSetCollectionSizeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountCollectionMint extends string | IAccountMeta = string, @@ -51,40 +47,7 @@ export type BubblegumSetCollectionSizeInstruction< TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCollectionMetadata extends string - ? WritableAccount - : TAccountCollectionMetadata, - TAccountCollectionAuthority extends string - ? WritableSignerAccount - : TAccountCollectionAuthority, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountBubblegumSigner extends string - ? ReadonlySignerAccount - : TAccountBubblegumSigner, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - ...TRemainingAccounts, - ] - >; - -export type BubblegumSetCollectionSizeInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountBubblegumSigner extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -147,31 +110,11 @@ export function getBubblegumSetCollectionSizeInstructionDataCodec(): Codec< } export type BubblegumSetCollectionSizeInput< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountBubblegumSigner extends string, - TAccountCollectionAuthorityRecord extends string, -> = { - /** Collection Metadata account */ - collectionMetadata: Address; - /** Collection Update authority */ - collectionAuthority: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Signing PDA of Bubblegum program */ - bubblegumSigner: Address; - /** Collection Authority Record PDA */ - collectionAuthorityRecord?: Address; - setCollectionSizeArgs: BubblegumSetCollectionSizeInstructionDataArgs['setCollectionSizeArgs']; -}; - -export type BubblegumSetCollectionSizeInputWithSigners< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountBubblegumSigner extends string, - TAccountCollectionAuthorityRecord extends string, + TAccountCollectionMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountCollectionMint extends string = string, + TAccountBubblegumSigner extends string = string, + TAccountCollectionAuthorityRecord extends string = string, > = { /** Collection Metadata account */ collectionMetadata: Address; @@ -192,30 +135,6 @@ export function getBubblegumSetCollectionSizeInstruction< TAccountCollectionMint extends string, TAccountBubblegumSigner extends string, TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BubblegumSetCollectionSizeInputWithSigners< - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountBubblegumSigner, - TAccountCollectionAuthorityRecord - > -): BubblegumSetCollectionSizeInstructionWithSigners< - TProgram, - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountBubblegumSigner, - TAccountCollectionAuthorityRecord ->; -export function getBubblegumSetCollectionSizeInstruction< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountBubblegumSigner extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: BubblegumSetCollectionSizeInput< TAccountCollectionMetadata, @@ -225,45 +144,18 @@ export function getBubblegumSetCollectionSizeInstruction< TAccountCollectionAuthorityRecord > ): BubblegumSetCollectionSizeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionMetadata, TAccountCollectionAuthority, TAccountCollectionMint, TAccountBubblegumSigner, TAccountCollectionAuthorityRecord ->; -export function getBubblegumSetCollectionSizeInstruction< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountBubblegumSigner extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BubblegumSetCollectionSizeInput< - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountBubblegumSigner, - TAccountCollectionAuthorityRecord - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getBubblegumSetCollectionSizeInstructionRaw< - TProgram, - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountBubblegumSigner, - TAccountCollectionAuthorityRecord - > - >[0]; - const accounts: Record = { + const originalAccounts = { collectionMetadata: { value: input.collectionMetadata ?? null, isWritable: true, @@ -282,95 +174,41 @@ export function getBubblegumSetCollectionSizeInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getBubblegumSetCollectionSizeInstructionRaw( - accountMetas as Record, - args as BubblegumSetCollectionSizeInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getBubblegumSetCollectionSizeInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountBubblegumSigner extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - collectionMetadata: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - bubblegumSigner: TAccountBubblegumSigner extends string - ? Address - : TAccountBubblegumSigner; - collectionAuthorityRecord?: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - }, - args: BubblegumSetCollectionSizeInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.collectionMetadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.bubblegumSigner, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.collectionAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.collectionMetadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.bubblegumSigner), + getAccountMeta(accounts.collectionAuthorityRecord), ], - data: getBubblegumSetCollectionSizeInstructionDataEncoder().encode(args), programAddress, + data: getBubblegumSetCollectionSizeInstructionDataEncoder().encode( + args as BubblegumSetCollectionSizeInstructionDataArgs + ), } as BubblegumSetCollectionSizeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionMetadata, TAccountCollectionAuthority, TAccountCollectionMint, TAccountBubblegumSigner, - TAccountCollectionAuthorityRecord, - TRemainingAccounts + TAccountCollectionAuthorityRecord >; + + return instruction; } export type ParsedBubblegumSetCollectionSizeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -409,7 +247,7 @@ export function parseBubblegumSetCollectionSizeInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/burn.ts b/test/packages/js-experimental/src/generated/instructions/burn.ts index d76d5c758..f3862aece 100644 --- a/test/packages/js-experimental/src/generated/instructions/burn.ts +++ b/test/packages/js-experimental/src/generated/instructions/burn.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { BurnArgs, BurnArgsArgs, @@ -42,58 +38,7 @@ import { } from '../types'; export type BurnInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMasterEditionAccount extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountOwner extends string - ? WritableSignerAccount - : TAccountOwner, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountTokenAccount extends string - ? WritableAccount - : TAccountTokenAccount, - TAccountMasterEditionAccount extends string - ? WritableAccount - : TAccountMasterEditionAccount, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - TAccountCollectionMetadata extends string - ? WritableAccount - : TAccountCollectionMetadata, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - ...TRemainingAccounts, - ] - >; - -export type BurnInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -107,7 +52,7 @@ export type BurnInstructionWithSigners< TAccountAuthorizationRulesProgram extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -176,47 +121,15 @@ export function getBurnInstructionDataCodec(): Codec< } export type BurnInput< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, -> = { - /** Metadata (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Asset owner */ - owner: Address; - /** Mint of token asset */ - mint: Address; - /** Token account to close */ - tokenAccount: Address; - /** MasterEdition of the asset */ - masterEditionAccount: Address; - /** SPL Token Program */ - splTokenProgram?: Address; - /** Metadata of the Collection */ - collectionMetadata?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - burnArgs: BurnInstructionDataArgs['burnArgs']; -}; - -export type BurnInputWithSigners< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, + TAccountMetadata extends string = string, + TAccountOwner extends string = string, + TAccountMint extends string = string, + TAccountTokenAccount extends string = string, + TAccountMasterEditionAccount extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountCollectionMetadata extends string = string, + TAccountAuthorizationRules extends string = string, + TAccountAuthorizationRulesProgram extends string = string, > = { /** Metadata (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -249,42 +162,6 @@ export function getBurnInstruction< TAccountCollectionMetadata extends string, TAccountAuthorizationRules extends string, TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BurnInputWithSigners< - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > -): BurnInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram ->; -export function getBurnInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: BurnInput< TAccountMetadata, @@ -298,7 +175,7 @@ export function getBurnInstruction< TAccountAuthorizationRulesProgram > ): BurnInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, TAccountMint, @@ -308,51 +185,12 @@ export function getBurnInstruction< TAccountCollectionMetadata, TAccountAuthorizationRules, TAccountAuthorizationRulesProgram ->; -export function getBurnInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BurnInput< - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getBurnInstructionRaw< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, owner: { value: input.owner ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, @@ -378,6 +216,10 @@ export function getBurnInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -388,115 +230,25 @@ export function getBurnInstruction< 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getBurnInstructionRaw( - accountMetas as Record, - args as BurnInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getBurnInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMasterEditionAccount extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - mint: TAccountMint extends string ? Address : TAccountMint; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - masterEditionAccount: TAccountMasterEditionAccount extends string - ? Address - : TAccountMasterEditionAccount; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - collectionMetadata?: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - }, - args: BurnInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.owner, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEditionAccount, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionMetadata ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.masterEditionAccount), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.collectionMetadata), + getAccountMeta(accounts.authorizationRules), + getAccountMeta(accounts.authorizationRulesProgram), ], - data: getBurnInstructionDataEncoder().encode(args), programAddress, + data: getBurnInstructionDataEncoder().encode( + args as BurnInstructionDataArgs + ), } as BurnInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, TAccountMint, @@ -505,13 +257,14 @@ export function getBurnInstructionRaw< TAccountSplTokenProgram, TAccountCollectionMetadata, TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram, - TRemainingAccounts + TAccountAuthorizationRulesProgram >; + + return instruction; } export type ParsedBurnInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -558,7 +311,7 @@ export function parseBurnInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/burnEditionNft.ts b/test/packages/js-experimental/src/generated/instructions/burnEditionNft.ts index 1e316fab3..7c7d5e1a8 100644 --- a/test/packages/js-experimental/src/generated/instructions/burnEditionNft.ts +++ b/test/packages/js-experimental/src/generated/instructions/burnEditionNft.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,14 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type BurnEditionNftInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TAccountPrintEditionMint extends string | IAccountMeta = string, @@ -53,64 +49,7 @@ export type BurnEditionNftInstruction< TAccountSplTokenProgram extends | string | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountOwner extends string - ? WritableSignerAccount - : TAccountOwner, - TAccountPrintEditionMint extends string - ? WritableAccount - : TAccountPrintEditionMint, - TAccountMasterEditionMint extends string - ? ReadonlyAccount - : TAccountMasterEditionMint, - TAccountPrintEditionTokenAccount extends string - ? WritableAccount - : TAccountPrintEditionTokenAccount, - TAccountMasterEditionTokenAccount extends string - ? ReadonlyAccount - : TAccountMasterEditionTokenAccount, - TAccountMasterEditionAccount extends string - ? WritableAccount - : TAccountMasterEditionAccount, - TAccountPrintEditionAccount extends string - ? WritableAccount - : TAccountPrintEditionAccount, - TAccountEditionMarkerAccount extends string - ? WritableAccount - : TAccountEditionMarkerAccount, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - ...TRemainingAccounts, - ] - >; - -export type BurnEditionNftInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountPrintEditionMint extends string | IAccountMeta = string, - TAccountMasterEditionMint extends string | IAccountMeta = string, - TAccountPrintEditionTokenAccount extends - | string - | IAccountMeta = string, - TAccountMasterEditionTokenAccount extends - | string - | IAccountMeta = string, - TAccountMasterEditionAccount extends string | IAccountMeta = string, - TAccountPrintEditionAccount extends string | IAccountMeta = string, - TAccountEditionMarkerAccount extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -176,50 +115,16 @@ export function getBurnEditionNftInstructionDataCodec(): Codec< } export type BurnEditionNftInput< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountPrintEditionMint extends string, - TAccountMasterEditionMint extends string, - TAccountPrintEditionTokenAccount extends string, - TAccountMasterEditionTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountPrintEditionAccount extends string, - TAccountEditionMarkerAccount extends string, - TAccountSplTokenProgram extends string, -> = { - /** Metadata (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** NFT owner */ - owner: Address; - /** Mint of the print edition NFT */ - printEditionMint: Address; - /** Mint of the original/master NFT */ - masterEditionMint: Address; - /** Token account the print edition NFT is in */ - printEditionTokenAccount: Address; - /** Token account the Master Edition NFT is in */ - masterEditionTokenAccount: Address; - /** MasterEdition2 of the original NFT */ - masterEditionAccount: Address; - /** Print Edition account of the NFT */ - printEditionAccount: Address; - /** Edition Marker PDA of the NFT */ - editionMarkerAccount: Address; - /** SPL Token Program */ - splTokenProgram?: Address; -}; - -export type BurnEditionNftInputWithSigners< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountPrintEditionMint extends string, - TAccountMasterEditionMint extends string, - TAccountPrintEditionTokenAccount extends string, - TAccountMasterEditionTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountPrintEditionAccount extends string, - TAccountEditionMarkerAccount extends string, - TAccountSplTokenProgram extends string, + TAccountMetadata extends string = string, + TAccountOwner extends string = string, + TAccountPrintEditionMint extends string = string, + TAccountMasterEditionMint extends string = string, + TAccountPrintEditionTokenAccount extends string = string, + TAccountMasterEditionTokenAccount extends string = string, + TAccountMasterEditionAccount extends string = string, + TAccountPrintEditionAccount extends string = string, + TAccountEditionMarkerAccount extends string = string, + TAccountSplTokenProgram extends string = string, > = { /** Metadata (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -254,45 +159,6 @@ export function getBurnEditionNftInstruction< TAccountPrintEditionAccount extends string, TAccountEditionMarkerAccount extends string, TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BurnEditionNftInputWithSigners< - TAccountMetadata, - TAccountOwner, - TAccountPrintEditionMint, - TAccountMasterEditionMint, - TAccountPrintEditionTokenAccount, - TAccountMasterEditionTokenAccount, - TAccountMasterEditionAccount, - TAccountPrintEditionAccount, - TAccountEditionMarkerAccount, - TAccountSplTokenProgram - > -): BurnEditionNftInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountPrintEditionMint, - TAccountMasterEditionMint, - TAccountPrintEditionTokenAccount, - TAccountMasterEditionTokenAccount, - TAccountMasterEditionAccount, - TAccountPrintEditionAccount, - TAccountEditionMarkerAccount, - TAccountSplTokenProgram ->; -export function getBurnEditionNftInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountPrintEditionMint extends string, - TAccountMasterEditionMint extends string, - TAccountPrintEditionTokenAccount extends string, - TAccountMasterEditionTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountPrintEditionAccount extends string, - TAccountEditionMarkerAccount extends string, - TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: BurnEditionNftInput< TAccountMetadata, @@ -307,7 +173,7 @@ export function getBurnEditionNftInstruction< TAccountSplTokenProgram > ): BurnEditionNftInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, TAccountPrintEditionMint, @@ -318,54 +184,12 @@ export function getBurnEditionNftInstruction< TAccountPrintEditionAccount, TAccountEditionMarkerAccount, TAccountSplTokenProgram ->; -export function getBurnEditionNftInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountPrintEditionMint extends string, - TAccountMasterEditionMint extends string, - TAccountPrintEditionTokenAccount extends string, - TAccountMasterEditionTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountPrintEditionAccount extends string, - TAccountEditionMarkerAccount extends string, - TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BurnEditionNftInput< - TAccountMetadata, - TAccountOwner, - TAccountPrintEditionMint, - TAccountMasterEditionMint, - TAccountPrintEditionTokenAccount, - TAccountMasterEditionTokenAccount, - TAccountMasterEditionAccount, - TAccountPrintEditionAccount, - TAccountEditionMarkerAccount, - TAccountSplTokenProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getBurnEditionNftInstructionRaw< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountPrintEditionMint, - TAccountMasterEditionMint, - TAccountPrintEditionTokenAccount, - TAccountMasterEditionTokenAccount, - TAccountMasterEditionAccount, - TAccountPrintEditionAccount, - TAccountEditionMarkerAccount, - TAccountSplTokenProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, owner: { value: input.owner ?? null, isWritable: true }, printEditionMint: { @@ -401,6 +225,10 @@ export function getBurnEditionNftInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.splTokenProgram.value) { @@ -408,113 +236,24 @@ export function getBurnEditionNftInstruction< 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getBurnEditionNftInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getBurnEditionNftInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountPrintEditionMint extends string | IAccountMeta = string, - TAccountMasterEditionMint extends string | IAccountMeta = string, - TAccountPrintEditionTokenAccount extends - | string - | IAccountMeta = string, - TAccountMasterEditionTokenAccount extends - | string - | IAccountMeta = string, - TAccountMasterEditionAccount extends string | IAccountMeta = string, - TAccountPrintEditionAccount extends string | IAccountMeta = string, - TAccountEditionMarkerAccount extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - printEditionMint: TAccountPrintEditionMint extends string - ? Address - : TAccountPrintEditionMint; - masterEditionMint: TAccountMasterEditionMint extends string - ? Address - : TAccountMasterEditionMint; - printEditionTokenAccount: TAccountPrintEditionTokenAccount extends string - ? Address - : TAccountPrintEditionTokenAccount; - masterEditionTokenAccount: TAccountMasterEditionTokenAccount extends string - ? Address - : TAccountMasterEditionTokenAccount; - masterEditionAccount: TAccountMasterEditionAccount extends string - ? Address - : TAccountMasterEditionAccount; - printEditionAccount: TAccountPrintEditionAccount extends string - ? Address - : TAccountPrintEditionAccount; - editionMarkerAccount: TAccountEditionMarkerAccount extends string - ? Address - : TAccountEditionMarkerAccount; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.owner, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.printEditionMint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.masterEditionMint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.printEditionTokenAccount, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.masterEditionTokenAccount, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.masterEditionAccount, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.printEditionAccount, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.editionMarkerAccount, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.printEditionMint), + getAccountMeta(accounts.masterEditionMint), + getAccountMeta(accounts.printEditionTokenAccount), + getAccountMeta(accounts.masterEditionTokenAccount), + getAccountMeta(accounts.masterEditionAccount), + getAccountMeta(accounts.printEditionAccount), + getAccountMeta(accounts.editionMarkerAccount), + getAccountMeta(accounts.splTokenProgram), ], - data: getBurnEditionNftInstructionDataEncoder().encode({}), programAddress, + data: getBurnEditionNftInstructionDataEncoder().encode({}), } as BurnEditionNftInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, TAccountPrintEditionMint, @@ -524,13 +263,14 @@ export function getBurnEditionNftInstructionRaw< TAccountMasterEditionAccount, TAccountPrintEditionAccount, TAccountEditionMarkerAccount, - TAccountSplTokenProgram, - TRemainingAccounts + TAccountSplTokenProgram >; + + return instruction; } export type ParsedBurnEditionNftInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/burnNft.ts b/test/packages/js-experimental/src/generated/instructions/burnNft.ts index 496f9edc6..71d938dae 100644 --- a/test/packages/js-experimental/src/generated/instructions/burnNft.ts +++ b/test/packages/js-experimental/src/generated/instructions/burnNft.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,55 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type BurnNftInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMasterEditionAccount extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountOwner extends string - ? WritableSignerAccount - : TAccountOwner, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountTokenAccount extends string - ? WritableAccount - : TAccountTokenAccount, - TAccountMasterEditionAccount extends string - ? WritableAccount - : TAccountMasterEditionAccount, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - TAccountCollectionMetadata extends string - ? WritableAccount - : TAccountCollectionMetadata, - ...TRemainingAccounts, - ] - >; - -export type BurnNftInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -87,7 +42,7 @@ export type BurnNftInstructionWithSigners< | string | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', TAccountCollectionMetadata extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -144,38 +99,13 @@ export function getBurnNftInstructionDataCodec(): Codec< } export type BurnNftInput< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, -> = { - /** Metadata (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** NFT owner */ - owner: Address; - /** Mint of the NFT */ - mint: Address; - /** Token account to close */ - tokenAccount: Address; - /** MasterEdition2 of the NFT */ - masterEditionAccount: Address; - /** SPL Token Program */ - splTokenProgram?: Address; - /** Metadata of the Collection */ - collectionMetadata?: Address; -}; - -export type BurnNftInputWithSigners< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, + TAccountMetadata extends string = string, + TAccountOwner extends string = string, + TAccountMint extends string = string, + TAccountTokenAccount extends string = string, + TAccountMasterEditionAccount extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountCollectionMetadata extends string = string, > = { /** Metadata (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -201,36 +131,6 @@ export function getBurnNftInstruction< TAccountMasterEditionAccount extends string, TAccountSplTokenProgram extends string, TAccountCollectionMetadata extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BurnNftInputWithSigners< - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata - > -): BurnNftInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata ->; -export function getBurnNftInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: BurnNftInput< TAccountMetadata, @@ -242,7 +142,7 @@ export function getBurnNftInstruction< TAccountCollectionMetadata > ): BurnNftInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, TAccountMint, @@ -250,45 +150,12 @@ export function getBurnNftInstruction< TAccountMasterEditionAccount, TAccountSplTokenProgram, TAccountCollectionMetadata ->; -export function getBurnNftInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountMasterEditionAccount extends string, - TAccountSplTokenProgram extends string, - TAccountCollectionMetadata extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: BurnNftInput< - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getBurnNftInstructionRaw< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountMint, - TAccountTokenAccount, - TAccountMasterEditionAccount, - TAccountSplTokenProgram, - TAccountCollectionMetadata - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, owner: { value: input.owner ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, @@ -306,6 +173,10 @@ export function getBurnNftInstruction< isWritable: true, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.splTokenProgram.value) { @@ -313,100 +184,35 @@ export function getBurnNftInstruction< 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getBurnNftInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getBurnNftInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMasterEditionAccount extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - mint: TAccountMint extends string ? Address : TAccountMint; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - masterEditionAccount: TAccountMasterEditionAccount extends string - ? Address - : TAccountMasterEditionAccount; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - collectionMetadata?: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.owner, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEditionAccount, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionMetadata ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.masterEditionAccount), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.collectionMetadata), ], - data: getBurnNftInstructionDataEncoder().encode({}), programAddress, + data: getBurnNftInstructionDataEncoder().encode({}), } as BurnNftInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, TAccountMint, TAccountTokenAccount, TAccountMasterEditionAccount, TAccountSplTokenProgram, - TAccountCollectionMetadata, - TRemainingAccounts + TAccountCollectionMetadata >; + + return instruction; } export type ParsedBurnNftInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -449,7 +255,7 @@ export function parseBurnNftInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/closeEscrowAccount.ts b/test/packages/js-experimental/src/generated/instructions/closeEscrowAccount.ts index 2d30ffa59..8467bdec0 100644 --- a/test/packages/js-experimental/src/generated/instructions/closeEscrowAccount.ts +++ b/test/packages/js-experimental/src/generated/instructions/closeEscrowAccount.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,14 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type CloseEscrowAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -49,54 +45,7 @@ export type CloseEscrowAccountInstruction< TAccountSysvarInstructions extends | string | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountEscrow extends string - ? WritableAccount - : TAccountEscrow, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountTokenAccount extends string - ? ReadonlyAccount - : TAccountTokenAccount, - TAccountEdition extends string - ? ReadonlyAccount - : TAccountEdition, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - ...TRemainingAccounts, - ] - >; - -export type CloseEscrowAccountInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEscrow extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -156,42 +105,14 @@ export function getCloseEscrowAccountInstructionDataCodec(): Codec< } export type CloseEscrowAccountInput< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, -> = { - /** Escrow account */ - escrow: Address; - /** Metadata account */ - metadata: Address; - /** Mint account */ - mint: Address; - /** Token account */ - tokenAccount: Address; - /** Edition account */ - edition: Address; - /** Wallet paying for the transaction and new account */ - payer: Address; - /** System program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; -}; - -export type CloseEscrowAccountInputWithSigners< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, + TAccountEscrow extends string = string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountTokenAccount extends string = string, + TAccountEdition extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, > = { /** Escrow account */ escrow: Address; @@ -220,39 +141,6 @@ export function getCloseEscrowAccountInstruction< TAccountPayer extends string, TAccountSystemProgram extends string, TAccountSysvarInstructions extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CloseEscrowAccountInputWithSigners< - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions - > -): CloseEscrowAccountInstructionWithSigners< - TProgram, - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions ->; -export function getCloseEscrowAccountInstruction< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CloseEscrowAccountInput< TAccountEscrow, @@ -265,7 +153,7 @@ export function getCloseEscrowAccountInstruction< TAccountSysvarInstructions > ): CloseEscrowAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow, TAccountMetadata, TAccountMint, @@ -274,48 +162,12 @@ export function getCloseEscrowAccountInstruction< TAccountPayer, TAccountSystemProgram, TAccountSysvarInstructions ->; -export function getCloseEscrowAccountInstruction< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CloseEscrowAccountInput< - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCloseEscrowAccountInstructionRaw< - TProgram, - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions - > - >[0]; - const accounts: Record = { + const originalAccounts = { escrow: { value: input.escrow ?? null, isWritable: true }, metadata: { value: input.metadata ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, @@ -328,6 +180,10 @@ export function getCloseEscrowAccountInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.systemProgram.value) { @@ -339,88 +195,22 @@ export function getCloseEscrowAccountInstruction< 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCloseEscrowAccountInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getCloseEscrowAccountInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEscrow extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - escrow: TAccountEscrow extends string - ? Address - : TAccountEscrow; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.escrow, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.READONLY), - accountMetaWithDefault(accounts.edition, AccountRole.READONLY), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), ], - data: getCloseEscrowAccountInstructionDataEncoder().encode({}), programAddress, + data: getCloseEscrowAccountInstructionDataEncoder().encode({}), } as CloseEscrowAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow, TAccountMetadata, TAccountMint, @@ -428,13 +218,14 @@ export function getCloseEscrowAccountInstructionRaw< TAccountEdition, TAccountPayer, TAccountSystemProgram, - TAccountSysvarInstructions, - TRemainingAccounts + TAccountSysvarInstructions >; + + return instruction; } export type ParsedCloseEscrowAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/convertMasterEditionV1ToV2.ts b/test/packages/js-experimental/src/generated/instructions/convertMasterEditionV1ToV2.ts index e285b1f9b..a84af31b5 100644 --- a/test/packages/js-experimental/src/generated/instructions/convertMasterEditionV1ToV2.ts +++ b/test/packages/js-experimental/src/generated/instructions/convertMasterEditionV1ToV2.ts @@ -19,48 +19,21 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, IInstructionWithData, WritableAccount, } from '@solana/instructions'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type ConvertMasterEditionV1ToV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMasterEdition extends string | IAccountMeta = string, TAccountOneTimeAuth extends string | IAccountMeta = string, TAccountPrintingMint extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountOneTimeAuth extends string - ? WritableAccount - : TAccountOneTimeAuth, - TAccountPrintingMint extends string - ? WritableAccount - : TAccountPrintingMint, - ...TRemainingAccounts, - ] - >; - -export type ConvertMasterEditionV1ToV2InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountOneTimeAuth extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -106,9 +79,9 @@ export function getConvertMasterEditionV1ToV2InstructionDataCodec(): Codec< } export type ConvertMasterEditionV1ToV2Input< - TAccountMasterEdition extends string, - TAccountOneTimeAuth extends string, - TAccountPrintingMint extends string, + TAccountMasterEdition extends string = string, + TAccountOneTimeAuth extends string = string, + TAccountPrintingMint extends string = string, > = { /** Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition']) */ masterEdition: Address; @@ -118,41 +91,10 @@ export type ConvertMasterEditionV1ToV2Input< printingMint: Address; }; -export type ConvertMasterEditionV1ToV2InputWithSigners< - TAccountMasterEdition extends string, - TAccountOneTimeAuth extends string, - TAccountPrintingMint extends string, -> = { - /** Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition']) */ - masterEdition: Address; - /** One time authorization mint */ - oneTimeAuth: Address; - /** Printing mint */ - printingMint: Address; -}; - -export function getConvertMasterEditionV1ToV2Instruction< - TAccountMasterEdition extends string, - TAccountOneTimeAuth extends string, - TAccountPrintingMint extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ConvertMasterEditionV1ToV2InputWithSigners< - TAccountMasterEdition, - TAccountOneTimeAuth, - TAccountPrintingMint - > -): ConvertMasterEditionV1ToV2InstructionWithSigners< - TProgram, - TAccountMasterEdition, - TAccountOneTimeAuth, - TAccountPrintingMint ->; export function getConvertMasterEditionV1ToV2Instruction< TAccountMasterEdition extends string, TAccountOneTimeAuth extends string, TAccountPrintingMint extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: ConvertMasterEditionV1ToV2Input< TAccountMasterEdition, @@ -160,98 +102,46 @@ export function getConvertMasterEditionV1ToV2Instruction< TAccountPrintingMint > ): ConvertMasterEditionV1ToV2Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMasterEdition, TAccountOneTimeAuth, TAccountPrintingMint ->; -export function getConvertMasterEditionV1ToV2Instruction< - TAccountMasterEdition extends string, - TAccountOneTimeAuth extends string, - TAccountPrintingMint extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ConvertMasterEditionV1ToV2Input< - TAccountMasterEdition, - TAccountOneTimeAuth, - TAccountPrintingMint - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getConvertMasterEditionV1ToV2InstructionRaw< - TProgram, - TAccountMasterEdition, - TAccountOneTimeAuth, - TAccountPrintingMint - > - >[0]; - const accounts: Record = { + const originalAccounts = { masterEdition: { value: input.masterEdition ?? null, isWritable: true }, oneTimeAuth: { value: input.oneTimeAuth ?? null, isWritable: true }, printingMint: { value: input.printingMint ?? null, isWritable: true }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getConvertMasterEditionV1ToV2InstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getConvertMasterEditionV1ToV2InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountOneTimeAuth extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - oneTimeAuth: TAccountOneTimeAuth extends string - ? Address - : TAccountOneTimeAuth; - printingMint: TAccountPrintingMint extends string - ? Address - : TAccountPrintingMint; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.masterEdition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.oneTimeAuth, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.printingMint, AccountRole.WRITABLE), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.oneTimeAuth), + getAccountMeta(accounts.printingMint), ], - data: getConvertMasterEditionV1ToV2InstructionDataEncoder().encode({}), programAddress, + data: getConvertMasterEditionV1ToV2InstructionDataEncoder().encode({}), } as ConvertMasterEditionV1ToV2Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMasterEdition, TAccountOneTimeAuth, - TAccountPrintingMint, - TRemainingAccounts + TAccountPrintingMint >; + + return instruction; } export type ParsedConvertMasterEditionV1ToV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/createAccount.ts b/test/packages/js-experimental/src/generated/instructions/createAccount.ts index 3359a4dc0..8c0f81a6c 100644 --- a/test/packages/js-experimental/src/generated/instructions/createAccount.ts +++ b/test/packages/js-experimental/src/generated/instructions/createAccount.ts @@ -25,7 +25,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -33,36 +32,14 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { SPL_SYSTEM_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type CreateAccountInstruction< - TProgram extends string = '11111111111111111111111111111111', + TProgram extends string = typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountPayer extends string | IAccountMeta = string, TAccountNewAccount extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountNewAccount extends string - ? WritableSignerAccount - : TAccountNewAccount, - ...TRemainingAccounts, - ] - >; - -export type CreateAccountInstructionWithSigners< - TProgram extends string = '11111111111111111111111111111111', - TAccountPayer extends string | IAccountMeta = string, - TAccountNewAccount extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -124,19 +101,8 @@ export function getCreateAccountInstructionDataCodec(): Codec< } export type CreateAccountInput< - TAccountPayer extends string, - TAccountNewAccount extends string, -> = { - payer: Address; - newAccount: Address; - lamports: CreateAccountInstructionDataArgs['lamports']; - space: CreateAccountInstructionDataArgs['space']; - programId: CreateAccountInstructionDataArgs['programId']; -}; - -export type CreateAccountInputWithSigners< - TAccountPayer extends string, - TAccountNewAccount extends string, + TAccountPayer extends string = string, + TAccountNewAccount extends string = string, > = { payer: TransactionSigner; newAccount: TransactionSigner; @@ -148,98 +114,50 @@ export type CreateAccountInputWithSigners< export function getCreateAccountInstruction< TAccountPayer extends string, TAccountNewAccount extends string, - TProgram extends string = '11111111111111111111111111111111', >( - input: CreateAccountInputWithSigners -): CreateAccountInstructionWithSigners< - TProgram, + input: CreateAccountInput +): CreateAccountInstruction< + typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountPayer, TAccountNewAccount ->; -export function getCreateAccountInstruction< - TAccountPayer extends string, - TAccountNewAccount extends string, - TProgram extends string = '11111111111111111111111111111111', ->( - input: CreateAccountInput -): CreateAccountInstruction; -export function getCreateAccountInstruction< - TAccountPayer extends string, - TAccountNewAccount extends string, - TProgram extends string = '11111111111111111111111111111111', ->(input: CreateAccountInput): IInstruction { +> { // Program address. - const programAddress = - '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + const programAddress = SPL_SYSTEM_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateAccountInstructionRaw< - TProgram, - TAccountPayer, - TAccountNewAccount - > - >[0]; - const accounts: Record = { + const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, newAccount: { value: input.newAccount ?? null, isWritable: true }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateAccountInstructionRaw( - accountMetas as Record, - args as CreateAccountInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateAccountInstructionRaw< - TProgram extends string = '11111111111111111111111111111111', - TAccountPayer extends string | IAccountMeta = string, - TAccountNewAccount extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - newAccount: TAccountNewAccount extends string - ? Address - : TAccountNewAccount; - }, - args: CreateAccountInstructionDataArgs, - programAddress: Address = '11111111111111111111111111111111' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.newAccount), ], - data: getCreateAccountInstructionDataEncoder().encode(args), programAddress, + data: getCreateAccountInstructionDataEncoder().encode( + args as CreateAccountInstructionDataArgs + ), } as CreateAccountInstruction< - TProgram, + typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountPayer, - TAccountNewAccount, - TRemainingAccounts + TAccountNewAccount >; + + return instruction; } export type ParsedCreateAccountInstruction< - TProgram extends string = '11111111111111111111111111111111', + TProgram extends string = typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/createEscrowAccount.ts b/test/packages/js-experimental/src/generated/instructions/createEscrowAccount.ts index e079756fc..77bff5e9b 100644 --- a/test/packages/js-experimental/src/generated/instructions/createEscrowAccount.ts +++ b/test/packages/js-experimental/src/generated/instructions/createEscrowAccount.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,14 +29,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type CreateEscrowAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -51,58 +47,7 @@ export type CreateEscrowAccountInstruction< | string | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountEscrow extends string - ? WritableAccount - : TAccountEscrow, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountTokenAccount extends string - ? ReadonlyAccount - : TAccountTokenAccount, - TAccountEdition extends string - ? ReadonlyAccount - : TAccountEdition, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - ...TRemainingAccounts, - ] - >; - -export type CreateEscrowAccountInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEscrow extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -166,46 +111,15 @@ export function getCreateEscrowAccountInstructionDataCodec(): Codec< } export type CreateEscrowAccountInput< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, -> = { - /** Escrow account */ - escrow: Address; - /** Metadata account */ - metadata: Address; - /** Mint account */ - mint: Address; - /** Token account of the token */ - tokenAccount: Address; - /** Edition account */ - edition: Address; - /** Wallet paying for the transaction and new account */ - payer: Address; - /** System program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** Authority/creator of the escrow account */ - authority?: Address; -}; - -export type CreateEscrowAccountInputWithSigners< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, + TAccountEscrow extends string = string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountTokenAccount extends string = string, + TAccountEdition extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountAuthority extends string = string, > = { /** Escrow account */ escrow: Address; @@ -237,42 +151,6 @@ export function getCreateEscrowAccountInstruction< TAccountSystemProgram extends string, TAccountSysvarInstructions extends string, TAccountAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateEscrowAccountInputWithSigners< - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthority - > -): CreateEscrowAccountInstructionWithSigners< - TProgram, - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthority ->; -export function getCreateEscrowAccountInstruction< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateEscrowAccountInput< TAccountEscrow, @@ -286,7 +164,7 @@ export function getCreateEscrowAccountInstruction< TAccountAuthority > ): CreateEscrowAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow, TAccountMetadata, TAccountMint, @@ -296,51 +174,12 @@ export function getCreateEscrowAccountInstruction< TAccountSystemProgram, TAccountSysvarInstructions, TAccountAuthority ->; -export function getCreateEscrowAccountInstruction< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateEscrowAccountInput< - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthority - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateEscrowAccountInstructionRaw< - TProgram, - TAccountEscrow, - TAccountMetadata, - TAccountMint, - TAccountTokenAccount, - TAccountEdition, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { escrow: { value: input.escrow ?? null, isWritable: true }, metadata: { value: input.metadata ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, @@ -354,6 +193,10 @@ export function getCreateEscrowAccountInstruction< }, authority: { value: input.authority ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.systemProgram.value) { @@ -365,100 +208,23 @@ export function getCreateEscrowAccountInstruction< 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateEscrowAccountInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getCreateEscrowAccountInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEscrow extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - escrow: TAccountEscrow extends string - ? Address - : TAccountEscrow; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - authority?: TAccountAuthority extends string - ? Address - : TAccountAuthority; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.escrow, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.READONLY), - accountMetaWithDefault(accounts.edition, AccountRole.READONLY), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authority ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY_SIGNER - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.authority), ], - data: getCreateEscrowAccountInstructionDataEncoder().encode({}), programAddress, + data: getCreateEscrowAccountInstructionDataEncoder().encode({}), } as CreateEscrowAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow, TAccountMetadata, TAccountMint, @@ -467,13 +233,14 @@ export function getCreateEscrowAccountInstructionRaw< TAccountPayer, TAccountSystemProgram, TAccountSysvarInstructions, - TAccountAuthority, - TRemainingAccounts + TAccountAuthority >; + + return instruction; } export type ParsedCreateEscrowAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -520,7 +287,7 @@ export function parseCreateEscrowAccountInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/createFrequencyRule.ts b/test/packages/js-experimental/src/generated/instructions/createFrequencyRule.ts index 4cbb4b5d5..faa853c7f 100644 --- a/test/packages/js-experimental/src/generated/instructions/createFrequencyRule.ts +++ b/test/packages/js-experimental/src/generated/instructions/createFrequencyRule.ts @@ -23,7 +23,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -33,45 +32,17 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type CreateFrequencyRuleInstruction< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', - TAccountPayer extends string | IAccountMeta = string, - TAccountFrequencyPda extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountFrequencyPda extends string - ? WritableAccount - : TAccountFrequencyPda, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - ...TRemainingAccounts, - ] - >; - -export type CreateFrequencyRuleInstructionWithSigners< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', + TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer extends string | IAccountMeta = string, TAccountFrequencyPda extends string | IAccountMeta = string, TAccountSystemProgram extends | string | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -139,26 +110,9 @@ export function getCreateFrequencyRuleInstructionDataCodec(): Codec< } export type CreateFrequencyRuleInput< - TAccountPayer extends string, - TAccountFrequencyPda extends string, - TAccountSystemProgram extends string, -> = { - /** Payer and creator of the Frequency Rule */ - payer: Address; - /** The PDA account where the Frequency Rule is stored */ - frequencyPda: Address; - /** System program */ - systemProgram?: Address; - ruleSetName: CreateFrequencyRuleInstructionDataArgs['ruleSetName']; - freqRuleName: CreateFrequencyRuleInstructionDataArgs['freqRuleName']; - lastUpdate: CreateFrequencyRuleInstructionDataArgs['lastUpdate']; - period: CreateFrequencyRuleInstructionDataArgs['period']; -}; - -export type CreateFrequencyRuleInputWithSigners< - TAccountPayer extends string, - TAccountFrequencyPda extends string, - TAccountSystemProgram extends string, + TAccountPayer extends string = string, + TAccountFrequencyPda extends string = string, + TAccountSystemProgram extends string = string, > = { /** Payer and creator of the Frequency Rule */ payer: TransactionSigner; @@ -176,24 +130,6 @@ export function getCreateFrequencyRuleInstruction< TAccountPayer extends string, TAccountFrequencyPda extends string, TAccountSystemProgram extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', ->( - input: CreateFrequencyRuleInputWithSigners< - TAccountPayer, - TAccountFrequencyPda, - TAccountSystemProgram - > -): CreateFrequencyRuleInstructionWithSigners< - TProgram, - TAccountPayer, - TAccountFrequencyPda, - TAccountSystemProgram ->; -export function getCreateFrequencyRuleInstruction< - TAccountPayer extends string, - TAccountFrequencyPda extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', >( input: CreateFrequencyRuleInput< TAccountPayer, @@ -201,41 +137,24 @@ export function getCreateFrequencyRuleInstruction< TAccountSystemProgram > ): CreateFrequencyRuleInstruction< - TProgram, + typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer, TAccountFrequencyPda, TAccountSystemProgram ->; -export function getCreateFrequencyRuleInstruction< - TAccountPayer extends string, - TAccountFrequencyPda extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', ->( - input: CreateFrequencyRuleInput< - TAccountPayer, - TAccountFrequencyPda, - TAccountSystemProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg' as Address<'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'>; + const programAddress = MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateFrequencyRuleInstructionRaw< - TProgram, - TAccountPayer, - TAccountFrequencyPda, - TAccountSystemProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, frequencyPda: { value: input.frequencyPda ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -246,70 +165,29 @@ export function getCreateFrequencyRuleInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateFrequencyRuleInstructionRaw( - accountMetas as Record, - args as CreateFrequencyRuleInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateFrequencyRuleInstructionRaw< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', - TAccountPayer extends string | IAccountMeta = string, - TAccountFrequencyPda extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - frequencyPda: TAccountFrequencyPda extends string - ? Address - : TAccountFrequencyPda; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - }, - args: CreateFrequencyRuleInstructionDataArgs, - programAddress: Address = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.frequencyPda, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.frequencyPda), + getAccountMeta(accounts.systemProgram), ], - data: getCreateFrequencyRuleInstructionDataEncoder().encode(args), programAddress, + data: getCreateFrequencyRuleInstructionDataEncoder().encode( + args as CreateFrequencyRuleInstructionDataArgs + ), } as CreateFrequencyRuleInstruction< - TProgram, + typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer, TAccountFrequencyPda, - TAccountSystemProgram, - TRemainingAccounts + TAccountSystemProgram >; + + return instruction; } export type ParsedCreateFrequencyRuleInstruction< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', + TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/createMasterEdition.ts b/test/packages/js-experimental/src/generated/instructions/createMasterEdition.ts index bbf906d12..3d25ab7f2 100644 --- a/test/packages/js-experimental/src/generated/instructions/createMasterEdition.ts +++ b/test/packages/js-experimental/src/generated/instructions/createMasterEdition.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { CreateMasterEditionArgs, CreateMasterEditionArgsArgs, @@ -43,60 +39,7 @@ import { } from '../types'; export type CreateMasterEditionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountEdition extends string - ? WritableAccount - : TAccountEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type CreateMasterEditionInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, @@ -112,7 +55,7 @@ export type CreateMasterEditionInstructionWithSigners< TAccountRent extends | string | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -188,47 +131,15 @@ export function getCreateMasterEditionInstructionDataCodec(): Codec< } export type CreateMasterEditionInput< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Unallocated edition V2 account with address as pda of ['metadata', program id, mint, 'edition'] */ - edition: Address; - /** Metadata mint */ - mint: Address; - /** Update authority */ - updateAuthority: Address; - /** Mint authority on the metadata's mint - THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY */ - mintAuthority: Address; - /** payer */ - payer: Address; - /** Metadata account */ - metadata: Address; - /** Token program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - createMasterEditionArgs: CreateMasterEditionInstructionDataArgs['createMasterEditionArgs']; -}; - -export type CreateMasterEditionInputWithSigners< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountEdition extends string = string, + TAccountMint extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountMetadata extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Unallocated edition V2 account with address as pda of ['metadata', program id, mint, 'edition'] */ edition: Address; @@ -261,42 +172,6 @@ export function getCreateMasterEditionInstruction< TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMasterEditionInputWithSigners< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): CreateMasterEditionInstructionWithSigners< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent ->; -export function getCreateMasterEditionInstruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateMasterEditionInput< TAccountEdition, @@ -310,7 +185,7 @@ export function getCreateMasterEditionInstruction< TAccountRent > ): CreateMasterEditionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountUpdateAuthority, @@ -320,51 +195,12 @@ export function getCreateMasterEditionInstruction< TAccountTokenProgram, TAccountSystemProgram, TAccountRent ->; -export function getCreateMasterEditionInstruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMasterEditionInput< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateMasterEditionInstructionRaw< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { edition: { value: input.edition ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, updateAuthority: { @@ -378,6 +214,10 @@ export function getCreateMasterEditionInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -396,105 +236,25 @@ export function getCreateMasterEditionInstruction< 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateMasterEditionInstructionRaw( - accountMetas as Record, - args as CreateMasterEditionInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateMasterEditionInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: CreateMasterEditionInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.edition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getCreateMasterEditionInstructionDataEncoder().encode(args), programAddress, + data: getCreateMasterEditionInstructionDataEncoder().encode( + args as CreateMasterEditionInstructionDataArgs + ), } as CreateMasterEditionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountUpdateAuthority, @@ -503,13 +263,14 @@ export function getCreateMasterEditionInstructionRaw< TAccountMetadata, TAccountTokenProgram, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedCreateMasterEditionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/createMasterEditionV3.ts b/test/packages/js-experimental/src/generated/instructions/createMasterEditionV3.ts index f11a48972..52fde2f00 100644 --- a/test/packages/js-experimental/src/generated/instructions/createMasterEditionV3.ts +++ b/test/packages/js-experimental/src/generated/instructions/createMasterEditionV3.ts @@ -20,7 +20,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -32,11 +31,11 @@ import { } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; import { getMasterEditionV2Size } from '../accounts'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; import { IInstructionWithByteDelta, ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, + getAccountMetaFactory, } from '../shared'; import { CreateMasterEditionArgs, @@ -46,7 +45,7 @@ import { } from '../types'; export type CreateMasterEditionV3Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, @@ -60,58 +59,7 @@ export type CreateMasterEditionV3Instruction< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountEdition extends string - ? WritableAccount - : TAccountEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type CreateMasterEditionV3InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -187,47 +135,15 @@ export function getCreateMasterEditionV3InstructionDataCodec(): Codec< } export type CreateMasterEditionV3Input< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Unallocated edition V2 account with address as pda of ['metadata', program id, mint, 'edition'] */ - edition: Address; - /** Metadata mint */ - mint: Address; - /** Update authority */ - updateAuthority: Address; - /** Mint authority on the metadata's mint - THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY */ - mintAuthority: Address; - /** payer */ - payer: Address; - /** Metadata account */ - metadata: Address; - /** Token program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - createMasterEditionArgs: CreateMasterEditionV3InstructionDataArgs['createMasterEditionArgs']; -}; - -export type CreateMasterEditionV3InputWithSigners< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountEdition extends string = string, + TAccountMint extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountMetadata extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Unallocated edition V2 account with address as pda of ['metadata', program id, mint, 'edition'] */ edition: Address; @@ -260,43 +176,6 @@ export function getCreateMasterEditionV3Instruction< TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMasterEditionV3InputWithSigners< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): CreateMasterEditionV3InstructionWithSigners< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent -> & - IInstructionWithByteDelta; -export function getCreateMasterEditionV3Instruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateMasterEditionV3Input< TAccountEdition, @@ -310,7 +189,7 @@ export function getCreateMasterEditionV3Instruction< TAccountRent > ): CreateMasterEditionV3Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountUpdateAuthority, @@ -321,51 +200,12 @@ export function getCreateMasterEditionV3Instruction< TAccountSystemProgram, TAccountRent > & - IInstructionWithByteDelta; -export function getCreateMasterEditionV3Instruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMasterEditionV3Input< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): IInstruction & IInstructionWithByteDelta { + IInstructionWithByteDelta { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateMasterEditionV3InstructionRaw< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { edition: { value: input.edition ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, updateAuthority: { @@ -379,6 +219,10 @@ export function getCreateMasterEditionV3Instruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -398,106 +242,25 @@ export function getCreateMasterEditionV3Instruction< getMasterEditionV2Size() + BASE_ACCOUNT_SIZE, ].reduce((a, b) => a + b, 0); - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateMasterEditionV3InstructionRaw( - accountMetas as Record, - args as CreateMasterEditionV3InstructionDataArgs, - programAddress - ); - - return Object.freeze({ ...instruction, byteDelta }); -} - -export function getCreateMasterEditionV3InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: CreateMasterEditionV3InstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.edition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getCreateMasterEditionV3InstructionDataEncoder().encode(args), programAddress, + data: getCreateMasterEditionV3InstructionDataEncoder().encode( + args as CreateMasterEditionV3InstructionDataArgs + ), } as CreateMasterEditionV3Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountUpdateAuthority, @@ -506,13 +269,14 @@ export function getCreateMasterEditionV3InstructionRaw< TAccountMetadata, TAccountTokenProgram, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return Object.freeze({ ...instruction, byteDelta }); } export type ParsedCreateMasterEditionV3Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -559,7 +323,7 @@ export function parseCreateMasterEditionV3Instruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/createMetadataAccount.ts b/test/packages/js-experimental/src/generated/instructions/createMetadataAccount.ts index 3c73f671b..d3bf28abe 100644 --- a/test/packages/js-experimental/src/generated/instructions/createMetadataAccount.ts +++ b/test/packages/js-experimental/src/generated/instructions/createMetadataAccount.ts @@ -32,7 +32,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -45,13 +44,13 @@ import { import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; import { getMetadataSize } from '../accounts'; import { findMetadataPda } from '../pdas'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; import { IInstructionWithByteDelta, ResolvedAccount, - accountMetaWithDefault, expectAddress, expectProgramDerivedAddress, - getAccountMetasWithSigners, + getAccountMetaFactory, } from '../shared'; import { Creator, @@ -61,7 +60,7 @@ import { } from '../types'; export type CreateMetadataAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountMintAuthority extends string | IAccountMeta = string, @@ -73,50 +72,7 @@ export type CreateMetadataAccountInstruction< TAccountRent extends | string | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlyAccount - : TAccountUpdateAuthority, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type CreateMetadataAccountInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -223,41 +179,13 @@ export function getCreateMetadataAccountInstructionDataCodec(): Codec< } export type CreateMetadataAccountAsyncInput< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata?: ProgramDerivedAddress; - /** Mint of token asset */ - mint: Address; - /** Mint authority */ - mintAuthority: Address; - /** payer */ - payer: Address; - /** update authority info */ - updateAuthority: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - data: CreateMetadataAccountInstructionDataArgs['data']; - isMutable: CreateMetadataAccountInstructionDataArgs['isMutable']; - metadataBump?: CreateMetadataAccountInstructionDataArgs['metadataBump']; -}; - -export type CreateMetadataAccountAsyncInputWithSigners< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Metadata key (pda of ['metadata', program id, mint id]) */ metadata?: ProgramDerivedAddress; @@ -286,39 +214,6 @@ export async function getCreateMetadataAccountInstructionAsync< TAccountUpdateAuthority extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountAsyncInputWithSigners< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): Promise< - CreateMetadataAccountInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > & - IInstructionWithByteDelta ->; -export async function getCreateMetadataAccountInstructionAsync< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateMetadataAccountAsyncInput< TAccountMetadata, @@ -331,7 +226,7 @@ export async function getCreateMetadataAccountInstructionAsync< > ): Promise< CreateMetadataAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, @@ -341,45 +236,12 @@ export async function getCreateMetadataAccountInstructionAsync< TAccountRent > & IInstructionWithByteDelta ->; -export async function getCreateMetadataAccountInstructionAsync< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountAsyncInput< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): Promise { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateMetadataAccountInstructionRaw< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, mintAuthority: { value: input.mintAuthority ?? null, isWritable: false }, @@ -391,6 +253,10 @@ export async function getCreateMetadataAccountInstructionAsync< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -419,58 +285,43 @@ export async function getCreateMetadataAccountInstructionAsync< 0 ); - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateMetadataAccountInstructionRaw( - accountMetas as Record, - args as CreateMetadataAccountInstructionDataArgs, - programAddress - ); + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + programAddress, + data: getCreateMetadataAccountInstructionDataEncoder().encode( + args as CreateMetadataAccountInstructionDataArgs + ), + } as CreateMetadataAccountInstruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, + TAccountMetadata, + TAccountMint, + TAccountMintAuthority, + TAccountPayer, + TAccountUpdateAuthority, + TAccountSystemProgram, + TAccountRent + >; return Object.freeze({ ...instruction, byteDelta }); } export type CreateMetadataAccountInput< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: ProgramDerivedAddress; - /** Mint of token asset */ - mint: Address; - /** Mint authority */ - mintAuthority: Address; - /** payer */ - payer: Address; - /** update authority info */ - updateAuthority: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - data: CreateMetadataAccountInstructionDataArgs['data']; - isMutable: CreateMetadataAccountInstructionDataArgs['isMutable']; - metadataBump?: CreateMetadataAccountInstructionDataArgs['metadataBump']; -}; - -export type CreateMetadataAccountInputWithSigners< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Metadata key (pda of ['metadata', program id, mint id]) */ metadata: ProgramDerivedAddress; @@ -499,37 +350,6 @@ export function getCreateMetadataAccountInstruction< TAccountUpdateAuthority extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountInputWithSigners< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): CreateMetadataAccountInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent -> & - IInstructionWithByteDelta; -export function getCreateMetadataAccountInstruction< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateMetadataAccountInput< TAccountMetadata, @@ -541,7 +361,7 @@ export function getCreateMetadataAccountInstruction< TAccountRent > ): CreateMetadataAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, @@ -550,45 +370,12 @@ export function getCreateMetadataAccountInstruction< TAccountSystemProgram, TAccountRent > & - IInstructionWithByteDelta; -export function getCreateMetadataAccountInstruction< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountInput< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): IInstruction & IInstructionWithByteDelta { + IInstructionWithByteDelta { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateMetadataAccountInstructionRaw< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, mintAuthority: { value: input.mintAuthority ?? null, isWritable: false }, @@ -600,6 +387,10 @@ export function getCreateMetadataAccountInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -623,99 +414,37 @@ export function getCreateMetadataAccountInstruction< 0 ); - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateMetadataAccountInstructionRaw( - accountMetas as Record, - args as CreateMetadataAccountInstructionDataArgs, - programAddress - ); - - return Object.freeze({ ...instruction, byteDelta }); -} - -export function getCreateMetadataAccountInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: CreateMetadataAccountInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.updateAuthority, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getCreateMetadataAccountInstructionDataEncoder().encode(args), programAddress, + data: getCreateMetadataAccountInstructionDataEncoder().encode( + args as CreateMetadataAccountInstructionDataArgs + ), } as CreateMetadataAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, TAccountPayer, TAccountUpdateAuthority, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return Object.freeze({ ...instruction, byteDelta }); } export type ParsedCreateMetadataAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV2.ts b/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV2.ts index 3851b635f..5e20936e5 100644 --- a/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV2.ts +++ b/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV2.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -32,11 +31,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { DataV2, DataV2Args, @@ -45,48 +41,7 @@ import { } from '../types'; export type CreateMetadataAccountV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlyAccount - : TAccountUpdateAuthority, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type CreateMetadataAccountV2InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountMintAuthority extends string | IAccountMeta = string, @@ -96,7 +51,7 @@ export type CreateMetadataAccountV2InstructionWithSigners< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -169,40 +124,13 @@ export function getCreateMetadataAccountV2InstructionDataCodec(): Codec< } export type CreateMetadataAccountV2Input< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Mint of token asset */ - mint: Address; - /** Mint authority */ - mintAuthority: Address; - /** payer */ - payer: Address; - /** update authority info */ - updateAuthority: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - data: CreateMetadataAccountV2InstructionDataArgs['data']; - isMutable: CreateMetadataAccountV2InstructionDataArgs['isMutable']; -}; - -export type CreateMetadataAccountV2InputWithSigners< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Metadata key (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -230,36 +158,6 @@ export function getCreateMetadataAccountV2Instruction< TAccountUpdateAuthority extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountV2InputWithSigners< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): CreateMetadataAccountV2InstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent ->; -export function getCreateMetadataAccountV2Instruction< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateMetadataAccountV2Input< TAccountMetadata, @@ -271,7 +169,7 @@ export function getCreateMetadataAccountV2Instruction< TAccountRent > ): CreateMetadataAccountV2Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, @@ -279,45 +177,12 @@ export function getCreateMetadataAccountV2Instruction< TAccountUpdateAuthority, TAccountSystemProgram, TAccountRent ->; -export function getCreateMetadataAccountV2Instruction< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountV2Input< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateMetadataAccountV2InstructionRaw< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, mintAuthority: { value: input.mintAuthority ?? null, isWritable: false }, @@ -329,6 +194,10 @@ export function getCreateMetadataAccountV2Instruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -339,100 +208,37 @@ export function getCreateMetadataAccountV2Instruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateMetadataAccountV2InstructionRaw( - accountMetas as Record, - args as CreateMetadataAccountV2InstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateMetadataAccountV2InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: CreateMetadataAccountV2InstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.updateAuthority, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getCreateMetadataAccountV2InstructionDataEncoder().encode(args), programAddress, + data: getCreateMetadataAccountV2InstructionDataEncoder().encode( + args as CreateMetadataAccountV2InstructionDataArgs + ), } as CreateMetadataAccountV2Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, TAccountPayer, TAccountUpdateAuthority, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedCreateMetadataAccountV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -475,7 +281,7 @@ export function parseCreateMetadataAccountV2Instruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV3.ts b/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV3.ts index 5d413ddd5..8382fa26d 100644 --- a/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV3.ts +++ b/test/packages/js-experimental/src/generated/instructions/createMetadataAccountV3.ts @@ -25,7 +25,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -37,11 +36,11 @@ import { } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; import { findMetadataPda } from '../pdas'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; import { ResolvedAccount, - accountMetaWithDefault, expectAddress, - getAccountMetasWithSigners, + getAccountMetaFactory, } from '../shared'; import { CollectionDetails, @@ -55,7 +54,7 @@ import { } from '../types'; export type CreateMetadataAccountV3Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountMintAuthority extends string | IAccountMeta = string, @@ -65,48 +64,7 @@ export type CreateMetadataAccountV3Instruction< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlyAccount - : TAccountUpdateAuthority, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type CreateMetadataAccountV3InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -183,41 +141,13 @@ export function getCreateMetadataAccountV3InstructionDataCodec(): Codec< } export type CreateMetadataAccountV3AsyncInput< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata?: Address; - /** Mint of token asset */ - mint: Address; - /** Mint authority */ - mintAuthority: Address; - /** payer */ - payer: Address; - /** update authority info */ - updateAuthority: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - data: CreateMetadataAccountV3InstructionDataArgs['data']; - isMutable: CreateMetadataAccountV3InstructionDataArgs['isMutable']; - collectionDetails: CreateMetadataAccountV3InstructionDataArgs['collectionDetails']; -}; - -export type CreateMetadataAccountV3AsyncInputWithSigners< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Metadata key (pda of ['metadata', program id, mint id]) */ metadata?: Address; @@ -246,38 +176,6 @@ export async function getCreateMetadataAccountV3InstructionAsync< TAccountUpdateAuthority extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountV3AsyncInputWithSigners< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): Promise< - CreateMetadataAccountV3InstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > ->; -export async function getCreateMetadataAccountV3InstructionAsync< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateMetadataAccountV3AsyncInput< TAccountMetadata, @@ -290,27 +188,7 @@ export async function getCreateMetadataAccountV3InstructionAsync< > ): Promise< CreateMetadataAccountV3Instruction< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > ->; -export async function getCreateMetadataAccountV3InstructionAsync< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountV3AsyncInput< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, @@ -319,25 +197,12 @@ export async function getCreateMetadataAccountV3InstructionAsync< TAccountSystemProgram, TAccountRent > -): Promise { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateMetadataAccountV3InstructionRaw< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, mintAuthority: { value: input.mintAuthority ?? null, isWritable: false }, @@ -349,6 +214,10 @@ export async function getCreateMetadataAccountV3InstructionAsync< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -364,58 +233,43 @@ export async function getCreateMetadataAccountV3InstructionAsync< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateMetadataAccountV3InstructionRaw( - accountMetas as Record, - args as CreateMetadataAccountV3InstructionDataArgs, - programAddress - ); + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + programAddress, + data: getCreateMetadataAccountV3InstructionDataEncoder().encode( + args as CreateMetadataAccountV3InstructionDataArgs + ), + } as CreateMetadataAccountV3Instruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, + TAccountMetadata, + TAccountMint, + TAccountMintAuthority, + TAccountPayer, + TAccountUpdateAuthority, + TAccountSystemProgram, + TAccountRent + >; return instruction; } export type CreateMetadataAccountV3Input< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Mint of token asset */ - mint: Address; - /** Mint authority */ - mintAuthority: Address; - /** payer */ - payer: Address; - /** update authority info */ - updateAuthority: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - data: CreateMetadataAccountV3InstructionDataArgs['data']; - isMutable: CreateMetadataAccountV3InstructionDataArgs['isMutable']; - collectionDetails: CreateMetadataAccountV3InstructionDataArgs['collectionDetails']; -}; - -export type CreateMetadataAccountV3InputWithSigners< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Metadata key (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -444,36 +298,6 @@ export function getCreateMetadataAccountV3Instruction< TAccountUpdateAuthority extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountV3InputWithSigners< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): CreateMetadataAccountV3InstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent ->; -export function getCreateMetadataAccountV3Instruction< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateMetadataAccountV3Input< TAccountMetadata, @@ -485,7 +309,7 @@ export function getCreateMetadataAccountV3Instruction< TAccountRent > ): CreateMetadataAccountV3Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, @@ -493,45 +317,12 @@ export function getCreateMetadataAccountV3Instruction< TAccountUpdateAuthority, TAccountSystemProgram, TAccountRent ->; -export function getCreateMetadataAccountV3Instruction< - TAccountMetadata extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateMetadataAccountV3Input< - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateMetadataAccountV3InstructionRaw< - TProgram, - TAccountMetadata, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, mintAuthority: { value: input.mintAuthority ?? null, isWritable: false }, @@ -543,6 +334,10 @@ export function getCreateMetadataAccountV3Instruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -553,100 +348,37 @@ export function getCreateMetadataAccountV3Instruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateMetadataAccountV3InstructionRaw( - accountMetas as Record, - args as CreateMetadataAccountV3InstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateMetadataAccountV3InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: CreateMetadataAccountV3InstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.updateAuthority, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getCreateMetadataAccountV3InstructionDataEncoder().encode(args), programAddress, + data: getCreateMetadataAccountV3InstructionDataEncoder().encode( + args as CreateMetadataAccountV3InstructionDataArgs + ), } as CreateMetadataAccountV3Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMint, TAccountMintAuthority, TAccountPayer, TAccountUpdateAuthority, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedCreateMetadataAccountV3Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -689,7 +421,7 @@ export function parseCreateMetadataAccountV3Instruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/createReservationList.ts b/test/packages/js-experimental/src/generated/instructions/createReservationList.ts index fc147cca7..0aed75e8a 100644 --- a/test/packages/js-experimental/src/generated/instructions/createReservationList.ts +++ b/test/packages/js-experimental/src/generated/instructions/createReservationList.ts @@ -8,7 +8,6 @@ import { Address } from '@solana/addresses'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -24,61 +23,11 @@ import { getCreateReservationListInstructionDataDecoder, getCreateReservationListInstructionDataEncoder, } from '../../hooked'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type CreateReservationListInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountReservationList extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountResource extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountReservationList extends string - ? WritableAccount - : TAccountReservationList, - TAccountPayer extends string - ? ReadonlySignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountResource extends string - ? ReadonlyAccount - : TAccountResource, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type CreateReservationListInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountReservationList extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, @@ -91,7 +40,7 @@ export type CreateReservationListInstructionWithSigners< TAccountRent extends | string | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -127,42 +76,14 @@ export type CreateReservationListInstructionWithSigners< >; export type CreateReservationListInput< - TAccountReservationList extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountMasterEdition extends string, - TAccountResource extends string, - TAccountMetadata extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** PDA for ReservationList of ['metadata', program id, master edition key, 'reservation', resource-key] */ - reservationList: Address; - /** Payer */ - payer: Address; - /** Update authority */ - updateAuthority: Address; - /** Master Edition V1 key (pda of ['metadata', program id, mint id, 'edition']) */ - masterEdition: Address; - /** A resource you wish to tie the reservation list to. This is so your later visitors who come to redeem can derive your reservation list PDA with something they can easily get at. You choose what this should be. */ - resource: Address; - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; -}; - -export type CreateReservationListInputWithSigners< - TAccountReservationList extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountMasterEdition extends string, - TAccountResource extends string, - TAccountMetadata extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountReservationList extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountMasterEdition extends string = string, + TAccountResource extends string = string, + TAccountMetadata extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** PDA for ReservationList of ['metadata', program id, master edition key, 'reservation', resource-key] */ reservationList: Address; @@ -191,39 +112,6 @@ export function getCreateReservationListInstruction< TAccountMetadata extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateReservationListInputWithSigners< - TAccountReservationList, - TAccountPayer, - TAccountUpdateAuthority, - TAccountMasterEdition, - TAccountResource, - TAccountMetadata, - TAccountSystemProgram, - TAccountRent - > -): CreateReservationListInstructionWithSigners< - TProgram, - TAccountReservationList, - TAccountPayer, - TAccountUpdateAuthority, - TAccountMasterEdition, - TAccountResource, - TAccountMetadata, - TAccountSystemProgram, - TAccountRent ->; -export function getCreateReservationListInstruction< - TAccountReservationList extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountMasterEdition extends string, - TAccountResource extends string, - TAccountMetadata extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: CreateReservationListInput< TAccountReservationList, @@ -236,7 +124,7 @@ export function getCreateReservationListInstruction< TAccountRent > ): CreateReservationListInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountReservationList, TAccountPayer, TAccountUpdateAuthority, @@ -245,48 +133,12 @@ export function getCreateReservationListInstruction< TAccountMetadata, TAccountSystemProgram, TAccountRent ->; -export function getCreateReservationListInstruction< - TAccountReservationList extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountMasterEdition extends string, - TAccountResource extends string, - TAccountMetadata extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateReservationListInput< - TAccountReservationList, - TAccountPayer, - TAccountUpdateAuthority, - TAccountMasterEdition, - TAccountResource, - TAccountMetadata, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateReservationListInstructionRaw< - TProgram, - TAccountReservationList, - TAccountPayer, - TAccountUpdateAuthority, - TAccountMasterEdition, - TAccountResource, - TAccountMetadata, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { reservationList: { value: input.reservationList ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: false }, updateAuthority: { @@ -299,6 +151,10 @@ export function getCreateReservationListInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -313,93 +169,24 @@ export function getCreateReservationListInstruction< 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateReservationListInstructionRaw( - accountMetas as Record, - args as CreateReservationListInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateReservationListInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountReservationList extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountResource extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - reservationList: TAccountReservationList extends string - ? Address - : TAccountReservationList; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - resource: TAccountResource extends string - ? Address - : TAccountResource; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: CreateReservationListInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.reservationList, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.payer, AccountRole.READONLY_SIGNER), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.masterEdition, AccountRole.READONLY), - accountMetaWithDefault(accounts.resource, AccountRole.READONLY), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.reservationList), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.resource), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getCreateReservationListInstructionDataEncoder().encode(args), programAddress, + data: getCreateReservationListInstructionDataEncoder().encode( + args as CreateReservationListInstructionDataArgs + ), } as CreateReservationListInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountReservationList, TAccountPayer, TAccountUpdateAuthority, @@ -407,13 +194,14 @@ export function getCreateReservationListInstructionRaw< TAccountResource, TAccountMetadata, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedCreateReservationListInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/createRuleSet.ts b/test/packages/js-experimental/src/generated/instructions/createRuleSet.ts index a9f0a7d78..c9e30e538 100644 --- a/test/packages/js-experimental/src/generated/instructions/createRuleSet.ts +++ b/test/packages/js-experimental/src/generated/instructions/createRuleSet.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; +import { MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS } from '../programs'; import { ResolvedAccount, - accountMetaWithDefault, expectProgramDerivedAddress, - getAccountMetasWithSigners, + getAccountMetaFactory, } from '../shared'; import { TaCreateArgs, @@ -43,38 +42,13 @@ import { } from '../types'; export type CreateRuleSetInstruction< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', + TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer extends string | IAccountMeta = string, TAccountRuleSetPda extends string | IAccountMeta = string, TAccountSystemProgram extends | string | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountRuleSetPda extends string - ? WritableAccount - : TAccountRuleSetPda, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - ...TRemainingAccounts, - ] - >; - -export type CreateRuleSetInstructionWithSigners< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', - TAccountPayer extends string | IAccountMeta = string, - TAccountRuleSetPda extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -134,24 +108,9 @@ export function getCreateRuleSetInstructionDataCodec(): Codec< } export type CreateRuleSetInput< - TAccountPayer extends string, - TAccountRuleSetPda extends string, - TAccountSystemProgram extends string, -> = { - /** Payer and creator of the RuleSet */ - payer: Address; - /** The PDA account where the RuleSet is stored */ - ruleSetPda: ProgramDerivedAddress; - /** System program */ - systemProgram?: Address; - createArgs: CreateRuleSetInstructionDataArgs['createArgs']; - ruleSetBump?: CreateRuleSetInstructionDataArgs['ruleSetBump']; -}; - -export type CreateRuleSetInputWithSigners< - TAccountPayer extends string, - TAccountRuleSetPda extends string, - TAccountSystemProgram extends string, + TAccountPayer extends string = string, + TAccountRuleSetPda extends string = string, + TAccountSystemProgram extends string = string, > = { /** Payer and creator of the RuleSet */ payer: TransactionSigner; @@ -167,24 +126,6 @@ export function getCreateRuleSetInstruction< TAccountPayer extends string, TAccountRuleSetPda extends string, TAccountSystemProgram extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', ->( - input: CreateRuleSetInputWithSigners< - TAccountPayer, - TAccountRuleSetPda, - TAccountSystemProgram - > -): CreateRuleSetInstructionWithSigners< - TProgram, - TAccountPayer, - TAccountRuleSetPda, - TAccountSystemProgram ->; -export function getCreateRuleSetInstruction< - TAccountPayer extends string, - TAccountRuleSetPda extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', >( input: CreateRuleSetInput< TAccountPayer, @@ -192,41 +133,24 @@ export function getCreateRuleSetInstruction< TAccountSystemProgram > ): CreateRuleSetInstruction< - TProgram, + typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer, TAccountRuleSetPda, TAccountSystemProgram ->; -export function getCreateRuleSetInstruction< - TAccountPayer extends string, - TAccountRuleSetPda extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', ->( - input: CreateRuleSetInput< - TAccountPayer, - TAccountRuleSetPda, - TAccountSystemProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg' as Address<'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'>; + const programAddress = MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateRuleSetInstructionRaw< - TProgram, - TAccountPayer, - TAccountRuleSetPda, - TAccountSystemProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, ruleSetPda: { value: input.ruleSetPda ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -242,70 +166,29 @@ export function getCreateRuleSetInstruction< )[1]; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateRuleSetInstructionRaw( - accountMetas as Record, - args as CreateRuleSetInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateRuleSetInstructionRaw< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', - TAccountPayer extends string | IAccountMeta = string, - TAccountRuleSetPda extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - ruleSetPda: TAccountRuleSetPda extends string - ? Address - : TAccountRuleSetPda; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - }, - args: CreateRuleSetInstructionDataArgs, - programAddress: Address = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.ruleSetPda, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.ruleSetPda), + getAccountMeta(accounts.systemProgram), ], - data: getCreateRuleSetInstructionDataEncoder().encode(args), programAddress, + data: getCreateRuleSetInstructionDataEncoder().encode( + args as CreateRuleSetInstructionDataArgs + ), } as CreateRuleSetInstruction< - TProgram, + typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer, TAccountRuleSetPda, - TAccountSystemProgram, - TRemainingAccounts + TAccountSystemProgram >; + + return instruction; } export type ParsedCreateRuleSetInstruction< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', + TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/createV1.ts b/test/packages/js-experimental/src/generated/instructions/createV1.ts index 99b757143..4c14d0ed7 100644 --- a/test/packages/js-experimental/src/generated/instructions/createV1.ts +++ b/test/packages/js-experimental/src/generated/instructions/createV1.ts @@ -25,7 +25,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -36,11 +35,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { AssetData, AssetDataArgs, @@ -49,7 +45,7 @@ import { } from '../types'; export type CreateV1Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -65,60 +61,7 @@ export type CreateV1Instruction< TAccountSplTokenProgram extends | string | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlyAccount - : TAccountUpdateAuthority, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - ...TRemainingAccounts, - ] - >; - -export type CreateV1InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -204,49 +147,15 @@ export function getCreateV1InstructionDataCodec(): Codec< } export type CreateV1Input< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, -> = { - /** Metadata account key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Unallocated edition account with address as pda of ['metadata', program id, mint, 'edition'] */ - masterEdition?: Address; - /** Mint of token asset */ - mint: Address; - /** Mint authority */ - mintAuthority: Address; - /** Payer */ - payer: Address; - /** update authority info */ - updateAuthority: Address; - /** System program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** SPL Token program */ - splTokenProgram?: Address; - assetData: CreateV1InstructionDataArgs['assetData']; - decimals: CreateV1InstructionDataArgs['decimals']; - maxSupply: CreateV1InstructionDataArgs['maxSupply']; -}; - -export type CreateV1InputWithSigners< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountSplTokenProgram extends string = string, > = { /** Metadata account key (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -281,9 +190,8 @@ export function getCreateV1Instruction< TAccountSystemProgram extends string, TAccountSysvarInstructions extends string, TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( - input: CreateV1InputWithSigners< + input: CreateV1Input< TAccountMetadata, TAccountMasterEdition, TAccountMint, @@ -294,8 +202,8 @@ export function getCreateV1Instruction< TAccountSysvarInstructions, TAccountSplTokenProgram > -): CreateV1InstructionWithSigners< - TProgram, +): CreateV1Instruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMasterEdition, (typeof input)['mint'] extends TransactionSigner @@ -307,86 +215,12 @@ export function getCreateV1Instruction< TAccountSystemProgram, TAccountSysvarInstructions, TAccountSplTokenProgram ->; -export function getCreateV1Instruction< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateV1Input< - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram - > -): CreateV1Instruction< - TProgram, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram ->; -export function getCreateV1Instruction< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateV1Input< - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateV1InstructionRaw< - TProgram, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, masterEdition: { value: input.masterEdition ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, @@ -406,6 +240,10 @@ export function getCreateV1Instruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -424,126 +262,43 @@ export function getCreateV1Instruction< 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateV1InstructionRaw( - accountMetas as Record, - args as CreateV1InstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateV1InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition?: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - }, - args: CreateV1InstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEdition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.updateAuthority, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.splTokenProgram), ], - data: getCreateV1InstructionDataEncoder().encode(args), programAddress, + data: getCreateV1InstructionDataEncoder().encode( + args as CreateV1InstructionDataArgs + ), } as CreateV1Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMasterEdition, - TAccountMint, + (typeof input)['mint'] extends TransactionSigner + ? WritableSignerAccount & IAccountSignerMeta + : TAccountMint, TAccountMintAuthority, TAccountPayer, TAccountUpdateAuthority, TAccountSystemProgram, TAccountSysvarInstructions, - TAccountSplTokenProgram, - TRemainingAccounts + TAccountSplTokenProgram >; + + return instruction; } export type ParsedCreateV1Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -590,7 +345,7 @@ export function parseCreateV1Instruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/createV2.ts b/test/packages/js-experimental/src/generated/instructions/createV2.ts index 5563a8dc2..82ec43ebf 100644 --- a/test/packages/js-experimental/src/generated/instructions/createV2.ts +++ b/test/packages/js-experimental/src/generated/instructions/createV2.ts @@ -25,7 +25,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -36,11 +35,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { AssetData, AssetDataArgs, @@ -49,7 +45,7 @@ import { } from '../types'; export type CreateV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -65,60 +61,7 @@ export type CreateV2Instruction< TAccountSplTokenProgram extends | string | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlyAccount - : TAccountUpdateAuthority, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - ...TRemainingAccounts, - ] - >; - -export type CreateV2InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -200,48 +143,15 @@ export function getCreateV2InstructionDataCodec(): Codec< } export type CreateV2Input< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, -> = { - /** Metadata account key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Unallocated edition account with address as pda of ['metadata', program id, mint, 'edition'] */ - masterEdition?: Address; - /** Mint of token asset */ - mint: Address; - /** Mint authority */ - mintAuthority: Address; - /** Payer */ - payer: Address; - /** update authority info */ - updateAuthority: Address; - /** System program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** SPL Token program */ - splTokenProgram?: Address; - assetData: CreateV2InstructionDataArgs['assetData']; - maxSupply: CreateV2InstructionDataArgs['maxSupply']; -}; - -export type CreateV2InputWithSigners< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountSplTokenProgram extends string = string, > = { /** Metadata account key (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -275,9 +185,8 @@ export function getCreateV2Instruction< TAccountSystemProgram extends string, TAccountSysvarInstructions extends string, TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( - input: CreateV2InputWithSigners< + input: CreateV2Input< TAccountMetadata, TAccountMasterEdition, TAccountMint, @@ -288,8 +197,8 @@ export function getCreateV2Instruction< TAccountSysvarInstructions, TAccountSplTokenProgram > -): CreateV2InstructionWithSigners< - TProgram, +): CreateV2Instruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMasterEdition, (typeof input)['mint'] extends TransactionSigner @@ -301,86 +210,12 @@ export function getCreateV2Instruction< TAccountSystemProgram, TAccountSysvarInstructions, TAccountSplTokenProgram ->; -export function getCreateV2Instruction< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateV2Input< - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram - > -): CreateV2Instruction< - TProgram, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram ->; -export function getCreateV2Instruction< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: CreateV2Input< - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getCreateV2InstructionRaw< - TProgram, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, masterEdition: { value: input.masterEdition ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, @@ -400,6 +235,10 @@ export function getCreateV2Instruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -418,126 +257,43 @@ export function getCreateV2Instruction< 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getCreateV2InstructionRaw( - accountMetas as Record, - args as CreateV2InstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getCreateV2InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition?: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - }, - args: CreateV2InstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEdition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.updateAuthority, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.splTokenProgram), ], - data: getCreateV2InstructionDataEncoder().encode(args), programAddress, + data: getCreateV2InstructionDataEncoder().encode( + args as CreateV2InstructionDataArgs + ), } as CreateV2Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMasterEdition, - TAccountMint, + (typeof input)['mint'] extends TransactionSigner + ? WritableSignerAccount & IAccountSignerMeta + : TAccountMint, TAccountMintAuthority, TAccountPayer, TAccountUpdateAuthority, TAccountSystemProgram, TAccountSysvarInstructions, - TAccountSplTokenProgram, - TRemainingAccounts + TAccountSplTokenProgram >; + + return instruction; } export type ParsedCreateV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -584,7 +340,7 @@ export function parseCreateV2Instruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/delegate.ts b/test/packages/js-experimental/src/generated/instructions/delegate.ts index 23cbace20..93716a967 100644 --- a/test/packages/js-experimental/src/generated/instructions/delegate.ts +++ b/test/packages/js-experimental/src/generated/instructions/delegate.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { DelegateArgs, DelegateArgsArgs, @@ -43,7 +39,7 @@ import { } from '../types'; export type DelegateInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegateRecord extends string | IAccountMeta = string, TAccountDelegate extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, @@ -63,76 +59,7 @@ export type DelegateInstruction< | string | IAccountMeta = string, TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountDelegateRecord extends string - ? WritableAccount - : TAccountDelegateRecord, - TAccountDelegate extends string - ? ReadonlyAccount - : TAccountDelegate, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountToken extends string - ? WritableAccount - : TAccountToken, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - ...TRemainingAccounts, - ] - >; - -export type DelegateInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountDelegate extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -217,63 +144,19 @@ export function getDelegateInstructionDataCodec(): Codec< } export type DelegateInput< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, -> = { - /** Delegate account key (pda of [mint id, delegate role, user id, authority id]) */ - delegateRecord: Address; - /** Owner of the delegated account */ - delegate: Address; - /** Metadata account */ - metadata: Address; - /** Master Edition account */ - masterEdition?: Address; - /** Mint of metadata */ - mint: Address; - /** Owned Token Account of mint */ - token?: Address; - /** Authority to approve the delegation */ - authority: Address; - /** Payer */ - payer: Address; - /** System Program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** SPL Token Program */ - splTokenProgram?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - delegateArgs: DelegateInstructionDataArgs['delegateArgs']; -}; - -export type DelegateInputWithSigners< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, + TAccountDelegateRecord extends string = string, + TAccountDelegate extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountMint extends string = string, + TAccountToken extends string = string, + TAccountAuthority extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountAuthorizationRulesProgram extends string = string, + TAccountAuthorizationRules extends string = string, > = { /** Delegate account key (pda of [mint id, delegate role, user id, authority id]) */ delegateRecord: Address; @@ -318,54 +201,6 @@ export function getDelegateInstruction< TAccountSplTokenProgram extends string, TAccountAuthorizationRulesProgram extends string, TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DelegateInputWithSigners< - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): DelegateInstructionWithSigners< - TProgram, - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules ->; -export function getDelegateInstruction< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: DelegateInput< TAccountDelegateRecord, @@ -383,7 +218,7 @@ export function getDelegateInstruction< TAccountAuthorizationRules > ): DelegateInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegateRecord, TAccountDelegate, TAccountMetadata, @@ -397,63 +232,12 @@ export function getDelegateInstruction< TAccountSplTokenProgram, TAccountAuthorizationRulesProgram, TAccountAuthorizationRules ->; -export function getDelegateInstruction< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DelegateInput< - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDelegateInstructionRaw< - TProgram, - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > - >[0]; - const accounts: Record = { + const originalAccounts = { delegateRecord: { value: input.delegateRecord ?? null, isWritable: true }, delegate: { value: input.delegate ?? null, isWritable: false }, metadata: { value: input.metadata ?? null, isWritable: true }, @@ -480,6 +264,10 @@ export function getDelegateInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -494,152 +282,29 @@ export function getDelegateInstruction< 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getDelegateInstructionRaw( - accountMetas as Record, - args as DelegateInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getDelegateInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountDelegate extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - delegateRecord: TAccountDelegateRecord extends string - ? Address - : TAccountDelegateRecord; - delegate: TAccountDelegate extends string - ? Address - : TAccountDelegate; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition?: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - token?: TAccountToken extends string - ? Address - : TAccountToken; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - }, - args: DelegateInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.delegateRecord, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.delegate, AccountRole.READONLY), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEdition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.token ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.delegateRecord), + getAccountMeta(accounts.delegate), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.token), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.authorizationRulesProgram), + getAccountMeta(accounts.authorizationRules), ], - data: getDelegateInstructionDataEncoder().encode(args), programAddress, + data: getDelegateInstructionDataEncoder().encode( + args as DelegateInstructionDataArgs + ), } as DelegateInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegateRecord, TAccountDelegate, TAccountMetadata, @@ -652,13 +317,14 @@ export function getDelegateInstructionRaw< TAccountSysvarInstructions, TAccountSplTokenProgram, TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules, - TRemainingAccounts + TAccountAuthorizationRules >; + + return instruction; } export type ParsedDelegateInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -713,7 +379,7 @@ export function parseDelegateInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/deprecatedCreateMasterEdition.ts b/test/packages/js-experimental/src/generated/instructions/deprecatedCreateMasterEdition.ts index 1f59bb2c7..533198307 100644 --- a/test/packages/js-experimental/src/generated/instructions/deprecatedCreateMasterEdition.ts +++ b/test/packages/js-experimental/src/generated/instructions/deprecatedCreateMasterEdition.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { CreateMasterEditionArgs, CreateMasterEditionArgsArgs, @@ -42,80 +38,7 @@ import { } from '../types'; export type DeprecatedCreateMasterEditionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountOneTimePrintingAuthorizationMint extends - | string - | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountPrintingMintAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TAccountOneTimePrintingAuthorizationMintAuthority extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountEdition extends string - ? WritableAccount - : TAccountEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountPrintingMint extends string - ? WritableAccount - : TAccountPrintingMint, - TAccountOneTimePrintingAuthorizationMint extends string - ? WritableAccount - : TAccountOneTimePrintingAuthorizationMint, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - TAccountPrintingMintAuthority extends string - ? ReadonlySignerAccount - : TAccountPrintingMintAuthority, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountPayer extends string - ? ReadonlySignerAccount - : TAccountPayer, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - TAccountOneTimePrintingAuthorizationMintAuthority extends string - ? ReadonlySignerAccount - : TAccountOneTimePrintingAuthorizationMintAuthority, - ...TRemainingAccounts, - ] - >; - -export type DeprecatedCreateMasterEditionInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountPrintingMint extends string | IAccountMeta = string, @@ -139,7 +62,7 @@ export type DeprecatedCreateMasterEditionInstructionWithSigners< TAccountOneTimePrintingAuthorizationMintAuthority extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -229,63 +152,19 @@ export function getDeprecatedCreateMasterEditionInstructionDataCodec(): Codec< } export type DeprecatedCreateMasterEditionInput< - TAccountEdition extends string, - TAccountMint extends string, - TAccountPrintingMint extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountUpdateAuthority extends string, - TAccountPrintingMintAuthority extends string, - TAccountMintAuthority extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountOneTimePrintingAuthorizationMintAuthority extends string, -> = { - /** Unallocated edition V1 account with address as pda of ['metadata', program id, mint, 'edition'] */ - edition: Address; - /** Metadata mint */ - mint: Address; - /** Printing mint - A mint you control that can mint tokens that can be exchanged for limited editions of your master edition via the MintNewEditionFromMasterEditionViaToken endpoint */ - printingMint: Address; - /** One time authorization printing mint - A mint you control that prints tokens that gives the bearer permission to mint any number of tokens from the printing mint one time via an endpoint with the token-metadata program for your metadata. Also burns the token. */ - oneTimePrintingAuthorizationMint: Address; - /** Current Update authority key */ - updateAuthority: Address; - /** Printing mint authority - THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY. */ - printingMintAuthority: Address; - /** Mint authority on the metadata's mint - THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY */ - mintAuthority: Address; - /** Metadata account */ - metadata: Address; - /** payer */ - payer: Address; - /** Token program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - /** One time authorization printing mint authority - must be provided if using max supply. THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY. */ - oneTimePrintingAuthorizationMintAuthority: Address; - createMasterEditionArgs: DeprecatedCreateMasterEditionInstructionDataArgs['createMasterEditionArgs']; -}; - -export type DeprecatedCreateMasterEditionInputWithSigners< - TAccountEdition extends string, - TAccountMint extends string, - TAccountPrintingMint extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountUpdateAuthority extends string, - TAccountPrintingMintAuthority extends string, - TAccountMintAuthority extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountOneTimePrintingAuthorizationMintAuthority extends string, + TAccountEdition extends string = string, + TAccountMint extends string = string, + TAccountPrintingMint extends string = string, + TAccountOneTimePrintingAuthorizationMint extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountPrintingMintAuthority extends string = string, + TAccountMintAuthority extends string = string, + TAccountMetadata extends string = string, + TAccountPayer extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, + TAccountOneTimePrintingAuthorizationMintAuthority extends string = string, > = { /** Unallocated edition V1 account with address as pda of ['metadata', program id, mint, 'edition'] */ edition: Address; @@ -330,54 +209,6 @@ export function getDeprecatedCreateMasterEditionInstruction< TAccountSystemProgram extends string, TAccountRent extends string, TAccountOneTimePrintingAuthorizationMintAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedCreateMasterEditionInputWithSigners< - TAccountEdition, - TAccountMint, - TAccountPrintingMint, - TAccountOneTimePrintingAuthorizationMint, - TAccountUpdateAuthority, - TAccountPrintingMintAuthority, - TAccountMintAuthority, - TAccountMetadata, - TAccountPayer, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountOneTimePrintingAuthorizationMintAuthority - > -): DeprecatedCreateMasterEditionInstructionWithSigners< - TProgram, - TAccountEdition, - TAccountMint, - TAccountPrintingMint, - TAccountOneTimePrintingAuthorizationMint, - TAccountUpdateAuthority, - TAccountPrintingMintAuthority, - TAccountMintAuthority, - TAccountMetadata, - TAccountPayer, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountOneTimePrintingAuthorizationMintAuthority ->; -export function getDeprecatedCreateMasterEditionInstruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountPrintingMint extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountUpdateAuthority extends string, - TAccountPrintingMintAuthority extends string, - TAccountMintAuthority extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountOneTimePrintingAuthorizationMintAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: DeprecatedCreateMasterEditionInput< TAccountEdition, @@ -395,7 +226,7 @@ export function getDeprecatedCreateMasterEditionInstruction< TAccountOneTimePrintingAuthorizationMintAuthority > ): DeprecatedCreateMasterEditionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountPrintingMint, @@ -409,63 +240,12 @@ export function getDeprecatedCreateMasterEditionInstruction< TAccountSystemProgram, TAccountRent, TAccountOneTimePrintingAuthorizationMintAuthority ->; -export function getDeprecatedCreateMasterEditionInstruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountPrintingMint extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountUpdateAuthority extends string, - TAccountPrintingMintAuthority extends string, - TAccountMintAuthority extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountOneTimePrintingAuthorizationMintAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedCreateMasterEditionInput< - TAccountEdition, - TAccountMint, - TAccountPrintingMint, - TAccountOneTimePrintingAuthorizationMint, - TAccountUpdateAuthority, - TAccountPrintingMintAuthority, - TAccountMintAuthority, - TAccountMetadata, - TAccountPayer, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountOneTimePrintingAuthorizationMintAuthority - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDeprecatedCreateMasterEditionInstructionRaw< - TProgram, - TAccountEdition, - TAccountMint, - TAccountPrintingMint, - TAccountOneTimePrintingAuthorizationMint, - TAccountUpdateAuthority, - TAccountPrintingMintAuthority, - TAccountMintAuthority, - TAccountMetadata, - TAccountPayer, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountOneTimePrintingAuthorizationMintAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { edition: { value: input.edition ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, printingMint: { value: input.printingMint ?? null, isWritable: true }, @@ -492,6 +272,10 @@ export function getDeprecatedCreateMasterEditionInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -510,138 +294,29 @@ export function getDeprecatedCreateMasterEditionInstruction< 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getDeprecatedCreateMasterEditionInstructionRaw( - accountMetas as Record, - args as DeprecatedCreateMasterEditionInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getDeprecatedCreateMasterEditionInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountOneTimePrintingAuthorizationMint extends - | string - | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountPrintingMintAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TAccountOneTimePrintingAuthorizationMintAuthority extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - printingMint: TAccountPrintingMint extends string - ? Address - : TAccountPrintingMint; - oneTimePrintingAuthorizationMint: TAccountOneTimePrintingAuthorizationMint extends string - ? Address - : TAccountOneTimePrintingAuthorizationMint; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - printingMintAuthority: TAccountPrintingMintAuthority extends string - ? Address - : TAccountPrintingMintAuthority; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - oneTimePrintingAuthorizationMintAuthority: TAccountOneTimePrintingAuthorizationMintAuthority extends string - ? Address - : TAccountOneTimePrintingAuthorizationMintAuthority; - }, - args: DeprecatedCreateMasterEditionInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.edition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.printingMint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.oneTimePrintingAuthorizationMint, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.printingMintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault(accounts.payer, AccountRole.READONLY_SIGNER), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.oneTimePrintingAuthorizationMintAuthority, - AccountRole.READONLY_SIGNER - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.printingMint), + getAccountMeta(accounts.oneTimePrintingAuthorizationMint), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.printingMintAuthority), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.oneTimePrintingAuthorizationMintAuthority), ], - data: getDeprecatedCreateMasterEditionInstructionDataEncoder().encode(args), programAddress, + data: getDeprecatedCreateMasterEditionInstructionDataEncoder().encode( + args as DeprecatedCreateMasterEditionInstructionDataArgs + ), } as DeprecatedCreateMasterEditionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountPrintingMint, @@ -654,13 +329,14 @@ export function getDeprecatedCreateMasterEditionInstructionRaw< TAccountTokenProgram, TAccountSystemProgram, TAccountRent, - TAccountOneTimePrintingAuthorizationMintAuthority, - TRemainingAccounts + TAccountOneTimePrintingAuthorizationMintAuthority >; + + return instruction; } export type ParsedDeprecatedCreateMasterEditionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/deprecatedMintNewEditionFromMasterEditionViaPrintingToken.ts b/test/packages/js-experimental/src/generated/instructions/deprecatedMintNewEditionFromMasterEditionViaPrintingToken.ts index 408bbb431..35b03f8d9 100644 --- a/test/packages/js-experimental/src/generated/instructions/deprecatedMintNewEditionFromMasterEditionViaPrintingToken.ts +++ b/test/packages/js-experimental/src/generated/instructions/deprecatedMintNewEditionFromMasterEditionViaPrintingToken.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,95 +28,11 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountMasterTokenAccount extends string | IAccountMeta = string, - TAccountEditionMarker extends string | IAccountMeta = string, - TAccountBurnAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMasterUpdateAuthority extends string | IAccountMeta = string, - TAccountMasterMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TAccountReservationList extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountEdition extends string - ? WritableAccount - : TAccountEdition, - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPrintingMint extends string - ? WritableAccount - : TAccountPrintingMint, - TAccountMasterTokenAccount extends string - ? WritableAccount - : TAccountMasterTokenAccount, - TAccountEditionMarker extends string - ? WritableAccount - : TAccountEditionMarker, - TAccountBurnAuthority extends string - ? ReadonlySignerAccount - : TAccountBurnAuthority, - TAccountPayer extends string - ? ReadonlySignerAccount - : TAccountPayer, - TAccountMasterUpdateAuthority extends string - ? ReadonlyAccount - : TAccountMasterUpdateAuthority, - TAccountMasterMetadata extends string - ? ReadonlyAccount - : TAccountMasterMetadata, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - TAccountReservationList extends string - ? WritableAccount - : TAccountReservationList, - ...TRemainingAccounts, - ] - >; - -export type DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountEdition extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, @@ -140,7 +55,7 @@ export type DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstruction | string | IAccountMeta = 'SysvarRent111111111111111111111111111111111', TAccountReservationList extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -228,74 +143,22 @@ export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInst } export type DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInput< - TAccountMetadata extends string, - TAccountEdition extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPrintingMint extends string, - TAccountMasterTokenAccount extends string, - TAccountEditionMarker extends string, - TAccountBurnAuthority extends string, - TAccountPayer extends string, - TAccountMasterUpdateAuthority extends string, - TAccountMasterMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountReservationList extends string, -> = { - /** New Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** New Edition V1 (pda of ['metadata', program id, mint id, 'edition']) */ - edition: Address; - /** Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition']) */ - masterEdition: Address; - /** Mint of new token - THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY */ - mint: Address; - /** Mint authority of new mint */ - mintAuthority: Address; - /** Printing Mint of master record edition */ - printingMint: Address; - /** Token account containing Printing mint token to be transferred */ - masterTokenAccount: Address; - /** Edition pda to mark creation - will be checked for pre-existence. (pda of ['metadata', program id, master mint id, edition_number]) */ - editionMarker: Address; - /** Burn authority for this token */ - burnAuthority: Address; - /** payer */ - payer: Address; - /** update authority info for new metadata account */ - masterUpdateAuthority: Address; - /** Master record metadata account */ - masterMetadata: Address; - /** Token program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - /** Reservation List - If present, and you are on this list, you can get an edition number given by your position on the list. */ - reservationList?: Address; -}; - -export type DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInputWithSigners< - TAccountMetadata extends string, - TAccountEdition extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPrintingMint extends string, - TAccountMasterTokenAccount extends string, - TAccountEditionMarker extends string, - TAccountBurnAuthority extends string, - TAccountPayer extends string, - TAccountMasterUpdateAuthority extends string, - TAccountMasterMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountReservationList extends string, + TAccountMetadata extends string = string, + TAccountEdition extends string = string, + TAccountMasterEdition extends string = string, + TAccountMint extends string = string, + TAccountMintAuthority extends string = string, + TAccountPrintingMint extends string = string, + TAccountMasterTokenAccount extends string = string, + TAccountEditionMarker extends string = string, + TAccountBurnAuthority extends string = string, + TAccountPayer extends string = string, + TAccountMasterUpdateAuthority extends string = string, + TAccountMasterMetadata extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, + TAccountReservationList extends string = string, > = { /** New Metadata key (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -348,63 +211,6 @@ export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInst TAccountSystemProgram extends string, TAccountRent extends string, TAccountReservationList extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInputWithSigners< - TAccountMetadata, - TAccountEdition, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPrintingMint, - TAccountMasterTokenAccount, - TAccountEditionMarker, - TAccountBurnAuthority, - TAccountPayer, - TAccountMasterUpdateAuthority, - TAccountMasterMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountReservationList - > -): DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountEdition, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPrintingMint, - TAccountMasterTokenAccount, - TAccountEditionMarker, - TAccountBurnAuthority, - TAccountPayer, - TAccountMasterUpdateAuthority, - TAccountMasterMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountReservationList ->; -export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstruction< - TAccountMetadata extends string, - TAccountEdition extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPrintingMint extends string, - TAccountMasterTokenAccount extends string, - TAccountEditionMarker extends string, - TAccountBurnAuthority extends string, - TAccountPayer extends string, - TAccountMasterUpdateAuthority extends string, - TAccountMasterMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountReservationList extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInput< TAccountMetadata, @@ -425,7 +231,7 @@ export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInst TAccountReservationList > ): DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountEdition, TAccountMasterEdition, @@ -442,72 +248,12 @@ export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInst TAccountSystemProgram, TAccountRent, TAccountReservationList ->; -export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstruction< - TAccountMetadata extends string, - TAccountEdition extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountMintAuthority extends string, - TAccountPrintingMint extends string, - TAccountMasterTokenAccount extends string, - TAccountEditionMarker extends string, - TAccountBurnAuthority extends string, - TAccountPayer extends string, - TAccountMasterUpdateAuthority extends string, - TAccountMasterMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountReservationList extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInput< - TAccountMetadata, - TAccountEdition, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPrintingMint, - TAccountMasterTokenAccount, - TAccountEditionMarker, - TAccountBurnAuthority, - TAccountPayer, - TAccountMasterUpdateAuthority, - TAccountMasterMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountReservationList - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstructionRaw< - TProgram, - TAccountMetadata, - TAccountEdition, - TAccountMasterEdition, - TAccountMint, - TAccountMintAuthority, - TAccountPrintingMint, - TAccountMasterTokenAccount, - TAccountEditionMarker, - TAccountBurnAuthority, - TAccountPayer, - TAccountMasterUpdateAuthority, - TAccountMasterMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent, - TAccountReservationList - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, edition: { value: input.edition ?? null, isWritable: true }, masterEdition: { value: input.masterEdition ?? null, isWritable: true }, @@ -531,6 +277,10 @@ export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInst rent: { value: input.rent ?? null, isWritable: false }, reservationList: { value: input.reservationList ?? null, isWritable: true }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.tokenProgram.value) { @@ -546,151 +296,32 @@ export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInst 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = - getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountMasterTokenAccount extends string | IAccountMeta = string, - TAccountEditionMarker extends string | IAccountMeta = string, - TAccountBurnAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountMasterUpdateAuthority extends string | IAccountMeta = string, - TAccountMasterMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TAccountReservationList extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - printingMint: TAccountPrintingMint extends string - ? Address - : TAccountPrintingMint; - masterTokenAccount: TAccountMasterTokenAccount extends string - ? Address - : TAccountMasterTokenAccount; - editionMarker: TAccountEditionMarker extends string - ? Address - : TAccountEditionMarker; - burnAuthority: TAccountBurnAuthority extends string - ? Address - : TAccountBurnAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - masterUpdateAuthority: TAccountMasterUpdateAuthority extends string - ? Address - : TAccountMasterUpdateAuthority; - masterMetadata: TAccountMasterMetadata extends string - ? Address - : TAccountMasterMetadata; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - reservationList?: TAccountReservationList extends string - ? Address - : TAccountReservationList; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.edition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.masterEdition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.printingMint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.masterTokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.editionMarker, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.burnAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.READONLY_SIGNER), - accountMetaWithDefault( - accounts.masterUpdateAuthority, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.masterMetadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.reservationList ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.printingMint), + getAccountMeta(accounts.masterTokenAccount), + getAccountMeta(accounts.editionMarker), + getAccountMeta(accounts.burnAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.masterUpdateAuthority), + getAccountMeta(accounts.masterMetadata), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.reservationList), ], + programAddress, data: getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstructionDataEncoder().encode( {} ), - programAddress, } as DeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountEdition, TAccountMasterEdition, @@ -706,13 +337,14 @@ export function getDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInst TAccountTokenProgram, TAccountSystemProgram, TAccountRent, - TAccountReservationList, - TRemainingAccounts + TAccountReservationList >; + + return instruction; } export type ParsedDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -776,7 +408,7 @@ export function parseDeprecatedMintNewEditionFromMasterEditionViaPrintingTokenIn }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokens.ts b/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokens.ts index 767a6d7fd..37e1adc02 100644 --- a/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokens.ts +++ b/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokens.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { MintPrintingTokensViaTokenArgs, MintPrintingTokensViaTokenArgsArgs, @@ -42,50 +38,7 @@ import { } from '../types'; export type DeprecatedMintPrintingTokensInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDestination extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountDestination extends string - ? WritableAccount - : TAccountDestination, - TAccountPrintingMint extends string - ? WritableAccount - : TAccountPrintingMint, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type DeprecatedMintPrintingTokensInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDestination extends string | IAccountMeta = string, TAccountPrintingMint extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, @@ -97,7 +50,7 @@ export type DeprecatedMintPrintingTokensInstructionWithSigners< TAccountRent extends | string | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -171,39 +124,13 @@ export function getDeprecatedMintPrintingTokensInstructionDataCodec(): Codec< } export type DeprecatedMintPrintingTokensInput< - TAccountDestination extends string, - TAccountPrintingMint extends string, - TAccountUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, -> = { - /** Destination account */ - destination: Address; - /** Printing mint */ - printingMint: Address; - /** Update authority */ - updateAuthority: Address; - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Master Edition V1 key (pda of ['metadata', program id, mint id, 'edition']) */ - masterEdition: Address; - /** Token program */ - tokenProgram?: Address; - /** Rent */ - rent?: Address; - mintPrintingTokensViaTokenArgs: DeprecatedMintPrintingTokensInstructionDataArgs['mintPrintingTokensViaTokenArgs']; -}; - -export type DeprecatedMintPrintingTokensInputWithSigners< - TAccountDestination extends string, - TAccountPrintingMint extends string, - TAccountUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, + TAccountDestination extends string = string, + TAccountPrintingMint extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountTokenProgram extends string = string, + TAccountRent extends string = string, > = { /** Destination account */ destination: Address; @@ -230,36 +157,6 @@ export function getDeprecatedMintPrintingTokensInstruction< TAccountMasterEdition extends string, TAccountTokenProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedMintPrintingTokensInputWithSigners< - TAccountDestination, - TAccountPrintingMint, - TAccountUpdateAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent - > -): DeprecatedMintPrintingTokensInstructionWithSigners< - TProgram, - TAccountDestination, - TAccountPrintingMint, - TAccountUpdateAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent ->; -export function getDeprecatedMintPrintingTokensInstruction< - TAccountDestination extends string, - TAccountPrintingMint extends string, - TAccountUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: DeprecatedMintPrintingTokensInput< TAccountDestination, @@ -271,7 +168,7 @@ export function getDeprecatedMintPrintingTokensInstruction< TAccountRent > ): DeprecatedMintPrintingTokensInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDestination, TAccountPrintingMint, TAccountUpdateAuthority, @@ -279,45 +176,12 @@ export function getDeprecatedMintPrintingTokensInstruction< TAccountMasterEdition, TAccountTokenProgram, TAccountRent ->; -export function getDeprecatedMintPrintingTokensInstruction< - TAccountDestination extends string, - TAccountPrintingMint extends string, - TAccountUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedMintPrintingTokensInput< - TAccountDestination, - TAccountPrintingMint, - TAccountUpdateAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDeprecatedMintPrintingTokensInstructionRaw< - TProgram, - TAccountDestination, - TAccountPrintingMint, - TAccountUpdateAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { destination: { value: input.destination ?? null, isWritable: true }, printingMint: { value: input.printingMint ?? null, isWritable: true }, updateAuthority: { @@ -329,6 +193,10 @@ export function getDeprecatedMintPrintingTokensInstruction< tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -343,101 +211,37 @@ export function getDeprecatedMintPrintingTokensInstruction< 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getDeprecatedMintPrintingTokensInstructionRaw( - accountMetas as Record, - args as DeprecatedMintPrintingTokensInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getDeprecatedMintPrintingTokensInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDestination extends string | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - destination: TAccountDestination extends string - ? Address - : TAccountDestination; - printingMint: TAccountPrintingMint extends string - ? Address - : TAccountPrintingMint; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: DeprecatedMintPrintingTokensInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.printingMint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault(accounts.masterEdition, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.destination), + getAccountMeta(accounts.printingMint), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.rent), ], - data: getDeprecatedMintPrintingTokensInstructionDataEncoder().encode(args), programAddress, + data: getDeprecatedMintPrintingTokensInstructionDataEncoder().encode( + args as DeprecatedMintPrintingTokensInstructionDataArgs + ), } as DeprecatedMintPrintingTokensInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDestination, TAccountPrintingMint, TAccountUpdateAuthority, TAccountMetadata, TAccountMasterEdition, TAccountTokenProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedDeprecatedMintPrintingTokensInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokensViaToken.ts b/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokensViaToken.ts index f52af52a7..e5d0b8499 100644 --- a/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokensViaToken.ts +++ b/test/packages/js-experimental/src/generated/instructions/deprecatedMintPrintingTokensViaToken.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { MintPrintingTokensViaTokenArgs, MintPrintingTokensViaTokenArgsArgs, @@ -42,60 +38,7 @@ import { } from '../types'; export type DeprecatedMintPrintingTokensViaTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDestination extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountOneTimePrintingAuthorizationMint extends - | string - | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountBurnAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountDestination extends string - ? WritableAccount - : TAccountDestination, - TAccountToken extends string - ? WritableAccount - : TAccountToken, - TAccountOneTimePrintingAuthorizationMint extends string - ? WritableAccount - : TAccountOneTimePrintingAuthorizationMint, - TAccountPrintingMint extends string - ? WritableAccount - : TAccountPrintingMint, - TAccountBurnAuthority extends string - ? ReadonlySignerAccount - : TAccountBurnAuthority, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type DeprecatedMintPrintingTokensViaTokenInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDestination extends string | IAccountMeta = string, TAccountToken extends string | IAccountMeta = string, TAccountOneTimePrintingAuthorizationMint extends @@ -111,7 +54,7 @@ export type DeprecatedMintPrintingTokensViaTokenInstructionWithSigners< TAccountRent extends | string | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -191,47 +134,15 @@ export function getDeprecatedMintPrintingTokensViaTokenInstructionDataCodec(): C } export type DeprecatedMintPrintingTokensViaTokenInput< - TAccountDestination extends string, - TAccountToken extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountPrintingMint extends string, - TAccountBurnAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, -> = { - /** Destination account */ - destination: Address; - /** Token account containing one time authorization token */ - token: Address; - /** One time authorization mint */ - oneTimePrintingAuthorizationMint: Address; - /** Printing mint */ - printingMint: Address; - /** Burn authority */ - burnAuthority: Address; - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Master Edition V1 key (pda of ['metadata', program id, mint id, 'edition']) */ - masterEdition: Address; - /** Token program */ - tokenProgram?: Address; - /** Rent */ - rent?: Address; - mintPrintingTokensViaTokenArgs: DeprecatedMintPrintingTokensViaTokenInstructionDataArgs['mintPrintingTokensViaTokenArgs']; -}; - -export type DeprecatedMintPrintingTokensViaTokenInputWithSigners< - TAccountDestination extends string, - TAccountToken extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountPrintingMint extends string, - TAccountBurnAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, + TAccountDestination extends string = string, + TAccountToken extends string = string, + TAccountOneTimePrintingAuthorizationMint extends string = string, + TAccountPrintingMint extends string = string, + TAccountBurnAuthority extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountTokenProgram extends string = string, + TAccountRent extends string = string, > = { /** Destination account */ destination: Address; @@ -264,42 +175,6 @@ export function getDeprecatedMintPrintingTokensViaTokenInstruction< TAccountMasterEdition extends string, TAccountTokenProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedMintPrintingTokensViaTokenInputWithSigners< - TAccountDestination, - TAccountToken, - TAccountOneTimePrintingAuthorizationMint, - TAccountPrintingMint, - TAccountBurnAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent - > -): DeprecatedMintPrintingTokensViaTokenInstructionWithSigners< - TProgram, - TAccountDestination, - TAccountToken, - TAccountOneTimePrintingAuthorizationMint, - TAccountPrintingMint, - TAccountBurnAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent ->; -export function getDeprecatedMintPrintingTokensViaTokenInstruction< - TAccountDestination extends string, - TAccountToken extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountPrintingMint extends string, - TAccountBurnAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: DeprecatedMintPrintingTokensViaTokenInput< TAccountDestination, @@ -313,7 +188,7 @@ export function getDeprecatedMintPrintingTokensViaTokenInstruction< TAccountRent > ): DeprecatedMintPrintingTokensViaTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDestination, TAccountToken, TAccountOneTimePrintingAuthorizationMint, @@ -323,51 +198,12 @@ export function getDeprecatedMintPrintingTokensViaTokenInstruction< TAccountMasterEdition, TAccountTokenProgram, TAccountRent ->; -export function getDeprecatedMintPrintingTokensViaTokenInstruction< - TAccountDestination extends string, - TAccountToken extends string, - TAccountOneTimePrintingAuthorizationMint extends string, - TAccountPrintingMint extends string, - TAccountBurnAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedMintPrintingTokensViaTokenInput< - TAccountDestination, - TAccountToken, - TAccountOneTimePrintingAuthorizationMint, - TAccountPrintingMint, - TAccountBurnAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDeprecatedMintPrintingTokensViaTokenInstructionRaw< - TProgram, - TAccountDestination, - TAccountToken, - TAccountOneTimePrintingAuthorizationMint, - TAccountPrintingMint, - TAccountBurnAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { destination: { value: input.destination ?? null, isWritable: true }, token: { value: input.token ?? null, isWritable: true }, oneTimePrintingAuthorizationMint: { @@ -381,6 +217,10 @@ export function getDeprecatedMintPrintingTokensViaTokenInstruction< tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -395,105 +235,25 @@ export function getDeprecatedMintPrintingTokensViaTokenInstruction< 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getDeprecatedMintPrintingTokensViaTokenInstructionRaw( - accountMetas as Record, - args as DeprecatedMintPrintingTokensViaTokenInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getDeprecatedMintPrintingTokensViaTokenInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDestination extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountOneTimePrintingAuthorizationMint extends - | string - | IAccountMeta = string, - TAccountPrintingMint extends string | IAccountMeta = string, - TAccountBurnAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - destination: TAccountDestination extends string - ? Address - : TAccountDestination; - token: TAccountToken extends string - ? Address - : TAccountToken; - oneTimePrintingAuthorizationMint: TAccountOneTimePrintingAuthorizationMint extends string - ? Address - : TAccountOneTimePrintingAuthorizationMint; - printingMint: TAccountPrintingMint extends string - ? Address - : TAccountPrintingMint; - burnAuthority: TAccountBurnAuthority extends string - ? Address - : TAccountBurnAuthority; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: DeprecatedMintPrintingTokensViaTokenInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.token, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.oneTimePrintingAuthorizationMint, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.printingMint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.burnAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault(accounts.masterEdition, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.destination), + getAccountMeta(accounts.token), + getAccountMeta(accounts.oneTimePrintingAuthorizationMint), + getAccountMeta(accounts.printingMint), + getAccountMeta(accounts.burnAuthority), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.rent), ], + programAddress, data: getDeprecatedMintPrintingTokensViaTokenInstructionDataEncoder().encode( - args + args as DeprecatedMintPrintingTokensViaTokenInstructionDataArgs ), - programAddress, } as DeprecatedMintPrintingTokensViaTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDestination, TAccountToken, TAccountOneTimePrintingAuthorizationMint, @@ -502,13 +262,14 @@ export function getDeprecatedMintPrintingTokensViaTokenInstructionRaw< TAccountMetadata, TAccountMasterEdition, TAccountTokenProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedDeprecatedMintPrintingTokensViaTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/deprecatedSetReservationList.ts b/test/packages/js-experimental/src/generated/instructions/deprecatedSetReservationList.ts index 4e8dc8245..62b73c799 100644 --- a/test/packages/js-experimental/src/generated/instructions/deprecatedSetReservationList.ts +++ b/test/packages/js-experimental/src/generated/instructions/deprecatedSetReservationList.ts @@ -27,7 +27,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -36,11 +35,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { Reservation, ReservationArgs, @@ -49,34 +45,11 @@ import { } from '../types'; export type DeprecatedSetReservationListInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountReservationList extends string | IAccountMeta = string, - TAccountResource extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountReservationList extends string - ? WritableAccount - : TAccountReservationList, - TAccountResource extends string - ? ReadonlySignerAccount - : TAccountResource, - ...TRemainingAccounts, - ] - >; - -export type DeprecatedSetReservationListInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMasterEdition extends string | IAccountMeta = string, TAccountReservationList extends string | IAccountMeta = string, TAccountResource extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -144,26 +117,9 @@ export function getDeprecatedSetReservationListInstructionDataCodec(): Codec< } export type DeprecatedSetReservationListInput< - TAccountMasterEdition extends string, - TAccountReservationList extends string, - TAccountResource extends string, -> = { - /** Master Edition V1 key (pda of ['metadata', program id, mint id, 'edition']) */ - masterEdition: Address; - /** PDA for ReservationList of ['metadata', program id, master edition key, 'reservation', resource-key] */ - reservationList: Address; - /** The resource you tied the reservation list too */ - resource: Address; - reservations: DeprecatedSetReservationListInstructionDataArgs['reservations']; - totalReservationSpots: DeprecatedSetReservationListInstructionDataArgs['totalReservationSpots']; - offset: DeprecatedSetReservationListInstructionDataArgs['offset']; - totalSpotOffset: DeprecatedSetReservationListInstructionDataArgs['totalSpotOffset']; -}; - -export type DeprecatedSetReservationListInputWithSigners< - TAccountMasterEdition extends string, - TAccountReservationList extends string, - TAccountResource extends string, + TAccountMasterEdition extends string = string, + TAccountReservationList extends string = string, + TAccountResource extends string = string, > = { /** Master Edition V1 key (pda of ['metadata', program id, mint id, 'edition']) */ masterEdition: Address; @@ -181,24 +137,6 @@ export function getDeprecatedSetReservationListInstruction< TAccountMasterEdition extends string, TAccountReservationList extends string, TAccountResource extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedSetReservationListInputWithSigners< - TAccountMasterEdition, - TAccountReservationList, - TAccountResource - > -): DeprecatedSetReservationListInstructionWithSigners< - TProgram, - TAccountMasterEdition, - TAccountReservationList, - TAccountResource ->; -export function getDeprecatedSetReservationListInstruction< - TAccountMasterEdition extends string, - TAccountReservationList extends string, - TAccountResource extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: DeprecatedSetReservationListInput< TAccountMasterEdition, @@ -206,103 +144,51 @@ export function getDeprecatedSetReservationListInstruction< TAccountResource > ): DeprecatedSetReservationListInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMasterEdition, TAccountReservationList, TAccountResource ->; -export function getDeprecatedSetReservationListInstruction< - TAccountMasterEdition extends string, - TAccountReservationList extends string, - TAccountResource extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: DeprecatedSetReservationListInput< - TAccountMasterEdition, - TAccountReservationList, - TAccountResource - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDeprecatedSetReservationListInstructionRaw< - TProgram, - TAccountMasterEdition, - TAccountReservationList, - TAccountResource - > - >[0]; - const accounts: Record = { + const originalAccounts = { masterEdition: { value: input.masterEdition ?? null, isWritable: true }, reservationList: { value: input.reservationList ?? null, isWritable: true }, resource: { value: input.resource ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getDeprecatedSetReservationListInstructionRaw( - accountMetas as Record, - args as DeprecatedSetReservationListInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getDeprecatedSetReservationListInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountReservationList extends string | IAccountMeta = string, - TAccountResource extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - reservationList: TAccountReservationList extends string - ? Address - : TAccountReservationList; - resource: TAccountResource extends string - ? Address - : TAccountResource; - }, - args: DeprecatedSetReservationListInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.masterEdition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.reservationList, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.resource, AccountRole.READONLY_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.reservationList), + getAccountMeta(accounts.resource), ], - data: getDeprecatedSetReservationListInstructionDataEncoder().encode(args), programAddress, + data: getDeprecatedSetReservationListInstructionDataEncoder().encode( + args as DeprecatedSetReservationListInstructionDataArgs + ), } as DeprecatedSetReservationListInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMasterEdition, TAccountReservationList, - TAccountResource, - TRemainingAccounts + TAccountResource >; + + return instruction; } export type ParsedDeprecatedSetReservationListInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/dummy.ts b/test/packages/js-experimental/src/generated/instructions/dummy.ts index cc64533d7..8d57917b0 100644 --- a/test/packages/js-experimental/src/generated/instructions/dummy.ts +++ b/test/packages/js-experimental/src/generated/instructions/dummy.ts @@ -34,17 +34,17 @@ import { import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; import { resolveTokenOrAta } from '../../hooked'; import { findDelegateRecordPda } from '../pdas'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; import { ResolvedAccount, - accountMetaWithDefault, expectSome, expectTransactionSigner, - getAccountMetasWithSigners, + getAccountMetaFactory, } from '../shared'; import { DelegateRole } from '../types'; export type DummyInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountEdition extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, @@ -57,58 +57,7 @@ export type DummyInstruction< TAccountDelegate extends string | IAccountMeta = string, TAccountDelegateRecord extends string | IAccountMeta = string, TAccountTokenOrAtaProgram extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountEdition extends string - ? WritableSignerAccount - : TAccountEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - TAccountMintAuthority extends string - ? WritableSignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountFoo extends string ? WritableAccount : TAccountFoo, - TAccountBar extends string - ? ReadonlySignerAccount - : TAccountBar, - TAccountDelegate extends string - ? ReadonlySignerAccount - : TAccountDelegate, - TAccountDelegateRecord extends string - ? WritableAccount - : TAccountDelegateRecord, - TAccountTokenOrAtaProgram extends string - ? ReadonlyAccount - : TAccountTokenOrAtaProgram, - ...TRemainingAccounts, - ] - >; - -export type DummyInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountFoo extends string | IAccountMeta = string, - TAccountBar extends - | string - | IAccountMeta = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountDelegate extends string | IAccountMeta = string, - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountTokenOrAtaProgram extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -188,42 +137,16 @@ export type DummyInstructionExtraArgs = { }; export type DummyAsyncInput< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, -> = { - edition?: Address; - mint?: Address; - updateAuthority: Address; - mintAuthority?: Address; - payer: Address; - foo?: Address; - bar?: Address; - delegate?: Address; - delegateRecord?: Address; - tokenOrAtaProgram?: Address; - identityArg?: DummyInstructionExtraArgs['identityArg']; - proof?: DummyInstructionExtraArgs['proof']; -}; - -export type DummyAsyncInputWithSigners< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, + TAccountEdition extends string = string, + TAccountMint extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountFoo extends string = string, + TAccountBar extends string = string, + TAccountDelegate extends string = string, + TAccountDelegateRecord extends string = string, + TAccountTokenOrAtaProgram extends string = string, > = { edition?: TransactionSigner; mint?: Address; @@ -250,47 +173,6 @@ export async function getDummyInstructionAsync< TAccountDelegate extends string, TAccountDelegateRecord extends string, TAccountTokenOrAtaProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: DummyAsyncInputWithSigners< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram - > -): Promise< - DummyInstructionWithSigners< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram - > ->; -export async function getDummyInstructionAsync< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( input: DummyAsyncInput< TAccountEdition, @@ -306,7 +188,7 @@ export async function getDummyInstructionAsync< > ): Promise< DummyInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountUpdateAuthority, @@ -318,54 +200,12 @@ export async function getDummyInstructionAsync< TAccountDelegateRecord, TAccountTokenOrAtaProgram > ->; -export async function getDummyInstructionAsync< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: DummyAsyncInput< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram - > -): Promise { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDummyInstructionRaw< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { edition: { value: input.edition ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, updateAuthority: { @@ -383,6 +223,10 @@ export async function getDummyInstructionAsync< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -425,59 +269,51 @@ export async function getDummyInstructionAsync< ...args.proof.map((address) => ({ address, role: AccountRole.READONLY })), ]; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getDummyInstructionRaw( - accountMetas as Record, + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.edition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.foo), + getAccountMeta(accounts.bar), + getAccountMeta(accounts.delegate), + getAccountMeta(accounts.delegateRecord), + getAccountMeta(accounts.tokenOrAtaProgram), + ...remainingAccounts, + ], programAddress, - remainingAccounts - ); + data: getDummyInstructionDataEncoder().encode({}), + } as DummyInstruction< + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, + TAccountEdition, + TAccountMint, + TAccountUpdateAuthority, + TAccountMintAuthority, + TAccountPayer, + TAccountFoo, + TAccountBar, + TAccountDelegate, + TAccountDelegateRecord, + TAccountTokenOrAtaProgram + >; return instruction; } export type DummyInput< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, -> = { - edition?: Address; - mint?: Address; - updateAuthority: Address; - mintAuthority?: Address; - payer: Address; - foo?: Address; - bar?: Address; - delegate?: Address; - delegateRecord?: Address; - tokenOrAtaProgram?: Address; - identityArg?: DummyInstructionExtraArgs['identityArg']; - proof?: DummyInstructionExtraArgs['proof']; -}; - -export type DummyInputWithSigners< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, + TAccountEdition extends string = string, + TAccountMint extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountFoo extends string = string, + TAccountBar extends string = string, + TAccountDelegate extends string = string, + TAccountDelegateRecord extends string = string, + TAccountTokenOrAtaProgram extends string = string, > = { edition?: TransactionSigner; mint?: Address; @@ -504,45 +340,6 @@ export function getDummyInstruction< TAccountDelegate extends string, TAccountDelegateRecord extends string, TAccountTokenOrAtaProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: DummyInputWithSigners< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram - > -): DummyInstructionWithSigners< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram ->; -export function getDummyInstruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( input: DummyInput< TAccountEdition, @@ -557,7 +354,7 @@ export function getDummyInstruction< TAccountTokenOrAtaProgram > ): DummyInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountUpdateAuthority, @@ -568,54 +365,12 @@ export function getDummyInstruction< TAccountDelegate, TAccountDelegateRecord, TAccountTokenOrAtaProgram ->; -export function getDummyInstruction< - TAccountEdition extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountFoo extends string, - TAccountBar extends string, - TAccountDelegate extends string, - TAccountDelegateRecord extends string, - TAccountTokenOrAtaProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: DummyInput< - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getDummyInstructionRaw< - TProgram, - TAccountEdition, - TAccountMint, - TAccountUpdateAuthority, - TAccountMintAuthority, - TAccountPayer, - TAccountFoo, - TAccountBar, - TAccountDelegate, - TAccountDelegateRecord, - TAccountTokenOrAtaProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { edition: { value: input.edition ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, updateAuthority: { @@ -633,6 +388,10 @@ export function getDummyInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -668,119 +427,25 @@ export function getDummyInstruction< ...args.proof.map((address) => ({ address, role: AccountRole.READONLY })), ]; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getDummyInstructionRaw( - accountMetas as Record, - programAddress, - remainingAccounts - ); - - return instruction; -} - -export function getDummyInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountFoo extends string | IAccountMeta = string, - TAccountBar extends - | string - | IAccountMeta = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountDelegate extends string | IAccountMeta = string, - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountTokenOrAtaProgram extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - mint?: TAccountMint extends string ? Address : TAccountMint; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - foo: TAccountFoo extends string ? Address : TAccountFoo; - bar?: TAccountBar extends string ? Address : TAccountBar; - delegate?: TAccountDelegate extends string - ? Address - : TAccountDelegate; - delegateRecord?: TAccountDelegateRecord extends string - ? Address - : TAccountDelegateRecord; - tokenOrAtaProgram: TAccountTokenOrAtaProgram extends string - ? Address - : TAccountTokenOrAtaProgram; - }, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.edition, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.mint ?? { - address: - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.foo, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.bar ?? { - address: - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.delegate ?? { - address: - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.delegateRecord ?? { - address: - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.tokenOrAtaProgram, AccountRole.READONLY), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.foo), + getAccountMeta(accounts.bar), + getAccountMeta(accounts.delegate), + getAccountMeta(accounts.delegateRecord), + getAccountMeta(accounts.tokenOrAtaProgram), + ...remainingAccounts, ], - data: getDummyInstructionDataEncoder().encode({}), programAddress, + data: getDummyInstructionDataEncoder().encode({}), } as DummyInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountEdition, TAccountMint, TAccountUpdateAuthority, @@ -790,13 +455,14 @@ export function getDummyInstructionRaw< TAccountBar, TAccountDelegate, TAccountDelegateRecord, - TAccountTokenOrAtaProgram, - TRemainingAccounts + TAccountTokenOrAtaProgram >; + + return instruction; } export type ParsedDummyInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -835,8 +501,7 @@ export function parseDummyInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' + return accountMeta.address === MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/freezeDelegatedAccount.ts b/test/packages/js-experimental/src/generated/instructions/freezeDelegatedAccount.ts index 1fbaac5fc..85a011465 100644 --- a/test/packages/js-experimental/src/generated/instructions/freezeDelegatedAccount.ts +++ b/test/packages/js-experimental/src/generated/instructions/freezeDelegatedAccount.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,47 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type FreezeDelegatedAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegate extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountDelegate extends string - ? WritableSignerAccount - : TAccountDelegate, - TAccountTokenAccount extends string - ? WritableAccount - : TAccountTokenAccount, - TAccountEdition extends string - ? ReadonlyAccount - : TAccountEdition, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - ...TRemainingAccounts, - ] - >; - -export type FreezeDelegatedAccountInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegate extends string | IAccountMeta = string, TAccountTokenAccount extends string | IAccountMeta = string, TAccountEdition extends string | IAccountMeta = string, @@ -77,7 +40,7 @@ export type FreezeDelegatedAccountInstructionWithSigners< TAccountTokenProgram extends | string | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -128,30 +91,11 @@ export function getFreezeDelegatedAccountInstructionDataCodec(): Codec< } export type FreezeDelegatedAccountInput< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, -> = { - /** Delegate */ - delegate: Address; - /** Token account to freeze */ - tokenAccount: Address; - /** Edition */ - edition: Address; - /** Token mint */ - mint: Address; - /** Token Program */ - tokenProgram?: Address; -}; - -export type FreezeDelegatedAccountInputWithSigners< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, + TAccountDelegate extends string = string, + TAccountTokenAccount extends string = string, + TAccountEdition extends string = string, + TAccountMint extends string = string, + TAccountTokenProgram extends string = string, > = { /** Delegate */ delegate: TransactionSigner; @@ -171,30 +115,6 @@ export function getFreezeDelegatedAccountInstruction< TAccountEdition extends string, TAccountMint extends string, TAccountTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: FreezeDelegatedAccountInputWithSigners< - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram - > -): FreezeDelegatedAccountInstructionWithSigners< - TProgram, - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram ->; -export function getFreezeDelegatedAccountInstruction< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: FreezeDelegatedAccountInput< TAccountDelegate, @@ -204,51 +124,28 @@ export function getFreezeDelegatedAccountInstruction< TAccountTokenProgram > ): FreezeDelegatedAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegate, TAccountTokenAccount, TAccountEdition, TAccountMint, TAccountTokenProgram ->; -export function getFreezeDelegatedAccountInstruction< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: FreezeDelegatedAccountInput< - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getFreezeDelegatedAccountInstructionRaw< - TProgram, - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { delegate: { value: input.delegate ?? null, isWritable: true }, tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, edition: { value: input.edition ?? null, isWritable: false }, mint: { value: input.mint ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.tokenProgram.value) { @@ -256,78 +153,31 @@ export function getFreezeDelegatedAccountInstruction< 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getFreezeDelegatedAccountInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getFreezeDelegatedAccountInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegate extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], ->( - accounts: { - delegate: TAccountDelegate extends string - ? Address - : TAccountDelegate; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.delegate, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.edition, AccountRole.READONLY), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.delegate), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenProgram), ], - data: getFreezeDelegatedAccountInstructionDataEncoder().encode({}), programAddress, + data: getFreezeDelegatedAccountInstructionDataEncoder().encode({}), } as FreezeDelegatedAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegate, TAccountTokenAccount, TAccountEdition, TAccountMint, - TAccountTokenProgram, - TRemainingAccounts + TAccountTokenProgram >; + + return instruction; } export type ParsedFreezeDelegatedAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/initialize.ts b/test/packages/js-experimental/src/generated/instructions/initialize.ts index c1f127f9a..cb1ff9446 100644 --- a/test/packages/js-experimental/src/generated/instructions/initialize.ts +++ b/test/packages/js-experimental/src/generated/instructions/initialize.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -32,11 +31,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { CandyMachineData, CandyMachineDataArgs, @@ -45,7 +41,7 @@ import { } from '../types'; export type InitializeInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthorityPda extends string | IAccountMeta = string, TAccountAuthority extends string | IAccountMeta = string, @@ -67,72 +63,7 @@ export type InitializeInstruction< TAccountSystemProgram extends | string | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthorityPda extends string - ? WritableAccount - : TAccountAuthorityPda, - TAccountAuthority extends string - ? ReadonlyAccount - : TAccountAuthority, - TAccountPayer extends string - ? ReadonlySignerAccount - : TAccountPayer, - TAccountCollectionMetadata extends string - ? ReadonlyAccount - : TAccountCollectionMetadata, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollectionMasterEdition extends string - ? ReadonlyAccount - : TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority extends string - ? WritableSignerAccount - : TAccountCollectionUpdateAuthority, - TAccountCollectionAuthorityRecord extends string - ? WritableAccount - : TAccountCollectionAuthorityRecord, - TAccountTokenMetadataProgram extends string - ? ReadonlyAccount - : TAccountTokenMetadataProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - ...TRemainingAccounts, - ] - >; - -export type InitializeInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthorityPda extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionMasterEdition extends - | string - | IAccountMeta = string, - TAccountCollectionUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountTokenMetadataProgram extends - | string - | IAccountMeta = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -214,44 +145,17 @@ export function getInitializeInstructionDataCodec(): Codec< } export type InitializeInput< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMint extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, -> = { - candyMachine: Address; - authorityPda: Address; - authority: Address; - payer: Address; - collectionMetadata: Address; - collectionMint: Address; - collectionMasterEdition: Address; - collectionUpdateAuthority: Address; - collectionAuthorityRecord: Address; - tokenMetadataProgram?: Address; - systemProgram?: Address; - data: InitializeInstructionDataArgs['data']; -}; - -export type InitializeInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMint extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, + TAccountCandyMachine extends string = string, + TAccountAuthorityPda extends string = string, + TAccountAuthority extends string = string, + TAccountPayer extends string = string, + TAccountCollectionMetadata extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollectionMasterEdition extends string = string, + TAccountCollectionUpdateAuthority extends string = string, + TAccountCollectionAuthorityRecord extends string = string, + TAccountTokenMetadataProgram extends string = string, + TAccountSystemProgram extends string = string, > = { candyMachine: Address; authorityPda: Address; @@ -279,48 +183,6 @@ export function getInitializeInstruction< TAccountCollectionAuthorityRecord extends string, TAccountTokenMetadataProgram extends string, TAccountSystemProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: InitializeInputWithSigners< - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountAuthority, - TAccountPayer, - TAccountCollectionMetadata, - TAccountCollectionMint, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram - > -): InitializeInstructionWithSigners< - TProgram, - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountAuthority, - TAccountPayer, - TAccountCollectionMetadata, - TAccountCollectionMint, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram ->; -export function getInitializeInstruction< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMint extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( input: InitializeInput< TAccountCandyMachine, @@ -336,7 +198,7 @@ export function getInitializeInstruction< TAccountSystemProgram > ): InitializeInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthorityPda, TAccountAuthority, @@ -348,57 +210,12 @@ export function getInitializeInstruction< TAccountCollectionAuthorityRecord, TAccountTokenMetadataProgram, TAccountSystemProgram ->; -export function getInitializeInstruction< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMint extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: InitializeInput< - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountAuthority, - TAccountPayer, - TAccountCollectionMetadata, - TAccountCollectionMint, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getInitializeInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountAuthority, - TAccountPayer, - TAccountCollectionMetadata, - TAccountCollectionMint, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authorityPda: { value: input.authorityPda ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, @@ -426,6 +243,10 @@ export function getInitializeInstruction< }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -440,122 +261,27 @@ export function getInitializeInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getInitializeInstructionRaw( - accountMetas as Record, - args as InitializeInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getInitializeInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthorityPda extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionMasterEdition extends - | string - | IAccountMeta = string, - TAccountCollectionUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountTokenMetadataProgram extends - | string - | IAccountMeta = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authorityPda: TAccountAuthorityPda extends string - ? Address - : TAccountAuthorityPda; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - collectionMetadata: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collectionMasterEdition: TAccountCollectionMasterEdition extends string - ? Address - : TAccountCollectionMasterEdition; - collectionUpdateAuthority: TAccountCollectionUpdateAuthority extends string - ? Address - : TAccountCollectionUpdateAuthority; - collectionAuthorityRecord: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - tokenMetadataProgram?: TAccountTokenMetadataProgram extends string - ? Address - : TAccountTokenMetadataProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - }, - args: InitializeInstructionDataArgs, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authorityPda, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY), - accountMetaWithDefault(accounts.payer, AccountRole.READONLY_SIGNER), - accountMetaWithDefault(accounts.collectionMetadata, AccountRole.READONLY), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.collectionMasterEdition, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionUpdateAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault( - accounts.collectionAuthorityRecord, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.tokenMetadataProgram ?? - ('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authorityPda), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.collectionMetadata), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collectionMasterEdition), + getAccountMeta(accounts.collectionUpdateAuthority), + getAccountMeta(accounts.collectionAuthorityRecord), + getAccountMeta(accounts.tokenMetadataProgram), + getAccountMeta(accounts.systemProgram), ], - data: getInitializeInstructionDataEncoder().encode(args), programAddress, + data: getInitializeInstructionDataEncoder().encode( + args as InitializeInstructionDataArgs + ), } as InitializeInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthorityPda, TAccountAuthority, @@ -566,13 +292,14 @@ export function getInitializeInstructionRaw< TAccountCollectionUpdateAuthority, TAccountCollectionAuthorityRecord, TAccountTokenMetadataProgram, - TAccountSystemProgram, - TRemainingAccounts + TAccountSystemProgram >; + + return instruction; } export type ParsedInitializeInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/migrate.ts b/test/packages/js-experimental/src/generated/instructions/migrate.ts index d011bc44d..62f4ca928 100644 --- a/test/packages/js-experimental/src/generated/instructions/migrate.ts +++ b/test/packages/js-experimental/src/generated/instructions/migrate.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { MigrateArgs, MigrateArgsArgs, @@ -42,7 +38,7 @@ import { } from '../types'; export type MigrateInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, TAccountTokenAccount extends string | IAccountMeta = string, @@ -59,64 +55,7 @@ export type MigrateInstruction< | string | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountTokenAccount extends string - ? WritableAccount - : TAccountTokenAccount, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - TAccountCollectionMetadata extends string - ? ReadonlyAccount - : TAccountCollectionMetadata, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - ...TRemainingAccounts, - ] - >; - -export type MigrateInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -191,51 +130,16 @@ export function getMigrateInstructionDataCodec(): Codec< } export type MigrateInput< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRules extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Master edition account */ - masterEdition: Address; - /** Token account */ - tokenAccount: Address; - /** Mint account */ - mint: Address; - /** Update authority */ - updateAuthority: Address; - /** Collection metadata account */ - collectionMetadata: Address; - /** Token Program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Instruction sysvar account */ - sysvarInstructions?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - migrateArgs: MigrateInstructionDataArgs['migrateArgs']; -}; - -export type MigrateInputWithSigners< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRules extends string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountTokenAccount extends string = string, + TAccountMint extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountCollectionMetadata extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountAuthorizationRules extends string = string, > = { /** Metadata account */ metadata: Address; @@ -271,45 +175,6 @@ export function getMigrateInstruction< TAccountSystemProgram extends string, TAccountSysvarInstructions extends string, TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MigrateInputWithSigners< - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenAccount, - TAccountMint, - TAccountUpdateAuthority, - TAccountCollectionMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRules - > -): MigrateInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenAccount, - TAccountMint, - TAccountUpdateAuthority, - TAccountCollectionMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRules ->; -export function getMigrateInstruction< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: MigrateInput< TAccountMetadata, @@ -324,7 +189,7 @@ export function getMigrateInstruction< TAccountAuthorizationRules > ): MigrateInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMasterEdition, TAccountTokenAccount, @@ -335,54 +200,12 @@ export function getMigrateInstruction< TAccountSystemProgram, TAccountSysvarInstructions, TAccountAuthorizationRules ->; -export function getMigrateInstruction< - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MigrateInput< - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenAccount, - TAccountMint, - TAccountUpdateAuthority, - TAccountCollectionMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRules - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getMigrateInstructionRaw< - TProgram, - TAccountMetadata, - TAccountMasterEdition, - TAccountTokenAccount, - TAccountMint, - TAccountUpdateAuthority, - TAccountCollectionMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRules - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, masterEdition: { value: input.masterEdition ?? null, isWritable: false }, tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, @@ -406,6 +229,10 @@ export function getMigrateInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -424,116 +251,26 @@ export function getMigrateInstruction< 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getMigrateInstructionRaw( - accountMetas as Record, - args as MigrateInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getMigrateInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - mint: TAccountMint extends string ? Address : TAccountMint; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - collectionMetadata: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - }, - args: MigrateInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.masterEdition, AccountRole.READONLY), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.collectionMetadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.collectionMetadata), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.authorizationRules), ], - data: getMigrateInstructionDataEncoder().encode(args), programAddress, + data: getMigrateInstructionDataEncoder().encode( + args as MigrateInstructionDataArgs + ), } as MigrateInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountMasterEdition, TAccountTokenAccount, @@ -543,13 +280,14 @@ export function getMigrateInstructionRaw< TAccountTokenProgram, TAccountSystemProgram, TAccountSysvarInstructions, - TAccountAuthorizationRules, - TRemainingAccounts + TAccountAuthorizationRules >; + + return instruction; } export type ParsedMigrateInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -598,7 +336,7 @@ export function parseMigrateInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/mint.ts b/test/packages/js-experimental/src/generated/instructions/mint.ts index 60f86bd2e..36b462eb0 100644 --- a/test/packages/js-experimental/src/generated/instructions/mint.ts +++ b/test/packages/js-experimental/src/generated/instructions/mint.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { MintArgs, MintArgsArgs, @@ -43,76 +39,7 @@ import { } from '../types'; export type MintInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountToken extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSplAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountToken extends string - ? WritableAccount - : TAccountToken, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - TAccountSplAtaProgram extends string - ? ReadonlyAccount - : TAccountSplAtaProgram, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - ...TRemainingAccounts, - ] - >; - -export type MintInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountToken extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, @@ -135,7 +62,7 @@ export type MintInstructionWithSigners< | string | IAccountMeta = string, TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -214,59 +141,18 @@ export function getMintInstructionDataCodec(): Codec< } export type MintInput< - TAccountToken extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountPayer extends string, - TAccountAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, -> = { - /** Token account */ - token: Address; - /** Metadata account key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Master Edition account */ - masterEdition?: Address; - /** Mint of token asset */ - mint: Address; - /** Payer */ - payer: Address; - /** (Mint or Update) authority */ - authority: Address; - /** System program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** SPL Token program */ - splTokenProgram?: Address; - /** SPL Associated Token Account program */ - splAtaProgram?: Address; - /** Token Authorization Rules program */ - authorizationRulesProgram?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - mintArgs: MintInstructionDataArgs['mintArgs']; -}; - -export type MintInputWithSigners< - TAccountToken extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountPayer extends string, - TAccountAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, + TAccountToken extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountMint extends string = string, + TAccountPayer extends string = string, + TAccountAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountSplAtaProgram extends string = string, + TAccountAuthorizationRulesProgram extends string = string, + TAccountAuthorizationRules extends string = string, > = { /** Token account */ token: Address; @@ -308,51 +194,6 @@ export function getMintInstruction< TAccountSplAtaProgram extends string, TAccountAuthorizationRulesProgram extends string, TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MintInputWithSigners< - TAccountToken, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountPayer, - TAccountAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): MintInstructionWithSigners< - TProgram, - TAccountToken, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountPayer, - TAccountAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules ->; -export function getMintInstruction< - TAccountToken extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountPayer extends string, - TAccountAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: MintInput< TAccountToken, @@ -369,7 +210,7 @@ export function getMintInstruction< TAccountAuthorizationRules > ): MintInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountToken, TAccountMetadata, TAccountMasterEdition, @@ -382,60 +223,12 @@ export function getMintInstruction< TAccountSplAtaProgram, TAccountAuthorizationRulesProgram, TAccountAuthorizationRules ->; -export function getMintInstruction< - TAccountToken extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountPayer extends string, - TAccountAuthority extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MintInput< - TAccountToken, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountPayer, - TAccountAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getMintInstructionRaw< - TProgram, - TAccountToken, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountPayer, - TAccountAuthority, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > - >[0]; - const accounts: Record = { + const originalAccounts = { token: { value: input.token ?? null, isWritable: true }, metadata: { value: input.metadata ?? null, isWritable: false }, masterEdition: { value: input.masterEdition ?? null, isWritable: false }, @@ -461,6 +254,10 @@ export function getMintInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -483,145 +280,28 @@ export function getMintInstruction< 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getMintInstructionRaw( - accountMetas as Record, - args as MintInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getMintInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountToken extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSplAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - token: TAccountToken extends string - ? Address - : TAccountToken; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition?: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - splAtaProgram?: TAccountSplAtaProgram extends string - ? Address - : TAccountSplAtaProgram; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - }, - args: MintInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.token, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.masterEdition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splAtaProgram ?? - ('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.token), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.splAtaProgram), + getAccountMeta(accounts.authorizationRulesProgram), + getAccountMeta(accounts.authorizationRules), ], - data: getMintInstructionDataEncoder().encode(args), programAddress, + data: getMintInstructionDataEncoder().encode( + args as MintInstructionDataArgs + ), } as MintInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountToken, TAccountMetadata, TAccountMasterEdition, @@ -633,13 +313,14 @@ export function getMintInstructionRaw< TAccountSplTokenProgram, TAccountSplAtaProgram, TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules, - TRemainingAccounts + TAccountAuthorizationRules >; + + return instruction; } export type ParsedMintInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -692,7 +373,7 @@ export function parseMintInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/mintFromCandyMachine.ts b/test/packages/js-experimental/src/generated/instructions/mintFromCandyMachine.ts index acf7cee05..3634e8812 100644 --- a/test/packages/js-experimental/src/generated/instructions/mintFromCandyMachine.ts +++ b/test/packages/js-experimental/src/generated/instructions/mintFromCandyMachine.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -32,105 +31,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type MintFromCandyMachineInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthorityPda extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountNftMint extends string | IAccountMeta = string, - TAccountNftMintAuthority extends string | IAccountMeta = string, - TAccountNftMetadata extends string | IAccountMeta = string, - TAccountNftMasterEdition extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionMasterEdition extends - | string - | IAccountMeta = string, - TAccountCollectionUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountTokenMetadataProgram extends - | string - | IAccountMeta = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRecentSlothashes extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthorityPda extends string - ? WritableAccount - : TAccountAuthorityPda, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountNftMint extends string - ? WritableAccount - : TAccountNftMint, - TAccountNftMintAuthority extends string - ? ReadonlySignerAccount - : TAccountNftMintAuthority, - TAccountNftMetadata extends string - ? WritableAccount - : TAccountNftMetadata, - TAccountNftMasterEdition extends string - ? WritableAccount - : TAccountNftMasterEdition, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollectionMetadata extends string - ? WritableAccount - : TAccountCollectionMetadata, - TAccountCollectionMasterEdition extends string - ? ReadonlyAccount - : TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority extends string - ? ReadonlyAccount - : TAccountCollectionUpdateAuthority, - TAccountTokenMetadataProgram extends string - ? ReadonlyAccount - : TAccountTokenMetadataProgram, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRecentSlothashes extends string - ? ReadonlyAccount - : TAccountRecentSlothashes, - ...TRemainingAccounts, - ] - >; - -export type MintFromCandyMachineInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthorityPda extends string | IAccountMeta = string, TAccountMintAuthority extends string | IAccountMeta = string, @@ -160,7 +65,7 @@ export type MintFromCandyMachineInstructionWithSigners< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRecentSlothashes extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -258,61 +163,23 @@ export function getMintFromCandyMachineInstructionDataCodec(): Codec< } export type MintFromCandyMachineInput< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountNftMint extends string, - TAccountNftMintAuthority extends string, - TAccountNftMetadata extends string, - TAccountNftMasterEdition extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountTokenMetadataProgram extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRecentSlothashes extends string, -> = { - candyMachine: Address; - authorityPda: Address; - mintAuthority: Address; - payer: Address; - nftMint: Address; - nftMintAuthority: Address; - nftMetadata: Address; - nftMasterEdition: Address; - collectionAuthorityRecord: Address; - collectionMint: Address; - collectionMetadata: Address; - collectionMasterEdition: Address; - collectionUpdateAuthority: Address; - tokenMetadataProgram?: Address; - tokenProgram?: Address; - systemProgram?: Address; - recentSlothashes: Address; -}; - -export type MintFromCandyMachineInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountNftMint extends string, - TAccountNftMintAuthority extends string, - TAccountNftMetadata extends string, - TAccountNftMasterEdition extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountTokenMetadataProgram extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRecentSlothashes extends string, + TAccountCandyMachine extends string = string, + TAccountAuthorityPda extends string = string, + TAccountMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountNftMint extends string = string, + TAccountNftMintAuthority extends string = string, + TAccountNftMetadata extends string = string, + TAccountNftMasterEdition extends string = string, + TAccountCollectionAuthorityRecord extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollectionMetadata extends string = string, + TAccountCollectionMasterEdition extends string = string, + TAccountCollectionUpdateAuthority extends string = string, + TAccountTokenMetadataProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRecentSlothashes extends string = string, > = { candyMachine: Address; authorityPda: Address; @@ -351,66 +218,6 @@ export function getMintFromCandyMachineInstruction< TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountRecentSlothashes extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: MintFromCandyMachineInputWithSigners< - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountMintAuthority, - TAccountPayer, - TAccountNftMint, - TAccountNftMintAuthority, - TAccountNftMetadata, - TAccountNftMasterEdition, - TAccountCollectionAuthorityRecord, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountTokenMetadataProgram, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRecentSlothashes - > -): MintFromCandyMachineInstructionWithSigners< - TProgram, - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountMintAuthority, - TAccountPayer, - TAccountNftMint, - TAccountNftMintAuthority, - TAccountNftMetadata, - TAccountNftMasterEdition, - TAccountCollectionAuthorityRecord, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountTokenMetadataProgram, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRecentSlothashes ->; -export function getMintFromCandyMachineInstruction< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountNftMint extends string, - TAccountNftMintAuthority extends string, - TAccountNftMetadata extends string, - TAccountNftMasterEdition extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountTokenMetadataProgram extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRecentSlothashes extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( input: MintFromCandyMachineInput< TAccountCandyMachine, @@ -432,7 +239,7 @@ export function getMintFromCandyMachineInstruction< TAccountRecentSlothashes > ): MintFromCandyMachineInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthorityPda, TAccountMintAuthority, @@ -450,75 +257,12 @@ export function getMintFromCandyMachineInstruction< TAccountTokenProgram, TAccountSystemProgram, TAccountRecentSlothashes ->; -export function getMintFromCandyMachineInstruction< - TAccountCandyMachine extends string, - TAccountAuthorityPda extends string, - TAccountMintAuthority extends string, - TAccountPayer extends string, - TAccountNftMint extends string, - TAccountNftMintAuthority extends string, - TAccountNftMetadata extends string, - TAccountNftMasterEdition extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionMasterEdition extends string, - TAccountCollectionUpdateAuthority extends string, - TAccountTokenMetadataProgram extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRecentSlothashes extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: MintFromCandyMachineInput< - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountMintAuthority, - TAccountPayer, - TAccountNftMint, - TAccountNftMintAuthority, - TAccountNftMetadata, - TAccountNftMasterEdition, - TAccountCollectionAuthorityRecord, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountTokenMetadataProgram, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRecentSlothashes - > -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getMintFromCandyMachineInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthorityPda, - TAccountMintAuthority, - TAccountPayer, - TAccountNftMint, - TAccountNftMintAuthority, - TAccountNftMetadata, - TAccountNftMasterEdition, - TAccountCollectionAuthorityRecord, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionMasterEdition, - TAccountCollectionUpdateAuthority, - TAccountTokenMetadataProgram, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRecentSlothashes - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authorityPda: { value: input.authorityPda ?? null, isWritable: true }, mintAuthority: { value: input.mintAuthority ?? null, isWritable: false }, @@ -561,6 +305,10 @@ export function getMintFromCandyMachineInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.tokenMetadataProgram.value) { @@ -576,162 +324,31 @@ export function getMintFromCandyMachineInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getMintFromCandyMachineInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getMintFromCandyMachineInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthorityPda extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountNftMint extends string | IAccountMeta = string, - TAccountNftMintAuthority extends string | IAccountMeta = string, - TAccountNftMetadata extends string | IAccountMeta = string, - TAccountNftMasterEdition extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionMasterEdition extends - | string - | IAccountMeta = string, - TAccountCollectionUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountTokenMetadataProgram extends - | string - | IAccountMeta = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRecentSlothashes extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authorityPda: TAccountAuthorityPda extends string - ? Address - : TAccountAuthorityPda; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - nftMint: TAccountNftMint extends string - ? Address - : TAccountNftMint; - nftMintAuthority: TAccountNftMintAuthority extends string - ? Address - : TAccountNftMintAuthority; - nftMetadata: TAccountNftMetadata extends string - ? Address - : TAccountNftMetadata; - nftMasterEdition: TAccountNftMasterEdition extends string - ? Address - : TAccountNftMasterEdition; - collectionAuthorityRecord: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collectionMetadata: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - collectionMasterEdition: TAccountCollectionMasterEdition extends string - ? Address - : TAccountCollectionMasterEdition; - collectionUpdateAuthority: TAccountCollectionUpdateAuthority extends string - ? Address - : TAccountCollectionUpdateAuthority; - tokenMetadataProgram?: TAccountTokenMetadataProgram extends string - ? Address - : TAccountTokenMetadataProgram; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - recentSlothashes: TAccountRecentSlothashes extends string - ? Address - : TAccountRecentSlothashes; - }, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authorityPda, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.nftMint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.nftMintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.nftMetadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.nftMasterEdition, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthorityRecord, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collectionMetadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionMasterEdition, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionUpdateAuthority, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.tokenMetadataProgram ?? - ('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.recentSlothashes, AccountRole.READONLY), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authorityPda), + getAccountMeta(accounts.mintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.nftMint), + getAccountMeta(accounts.nftMintAuthority), + getAccountMeta(accounts.nftMetadata), + getAccountMeta(accounts.nftMasterEdition), + getAccountMeta(accounts.collectionAuthorityRecord), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collectionMetadata), + getAccountMeta(accounts.collectionMasterEdition), + getAccountMeta(accounts.collectionUpdateAuthority), + getAccountMeta(accounts.tokenMetadataProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.recentSlothashes), ], - data: getMintFromCandyMachineInstructionDataEncoder().encode({}), programAddress, + data: getMintFromCandyMachineInstructionDataEncoder().encode({}), } as MintFromCandyMachineInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthorityPda, TAccountMintAuthority, @@ -748,13 +365,14 @@ export function getMintFromCandyMachineInstructionRaw< TAccountTokenMetadataProgram, TAccountTokenProgram, TAccountSystemProgram, - TAccountRecentSlothashes, - TRemainingAccounts + TAccountRecentSlothashes >; + + return instruction; } export type ParsedMintFromCandyMachineInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaToken.ts b/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaToken.ts index 8b5d33128..f33307681 100644 --- a/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaToken.ts +++ b/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaToken.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { MintNewEditionFromMasterEditionViaTokenArgs, MintNewEditionFromMasterEditionViaTokenArgsArgs, @@ -43,7 +39,7 @@ import { } from '../types'; export type MintNewEditionFromMasterEditionViaTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountNewMetadata extends string | IAccountMeta = string, TAccountNewEdition extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, @@ -64,80 +60,7 @@ export type MintNewEditionFromMasterEditionViaTokenInstruction< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountNewMetadata extends string - ? WritableAccount - : TAccountNewMetadata, - TAccountNewEdition extends string - ? WritableAccount - : TAccountNewEdition, - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountNewMint extends string - ? WritableAccount - : TAccountNewMint, - TAccountEditionMarkPda extends string - ? WritableAccount - : TAccountEditionMarkPda, - TAccountNewMintAuthority extends string - ? ReadonlySignerAccount - : TAccountNewMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountTokenAccountOwner extends string - ? ReadonlySignerAccount - : TAccountTokenAccountOwner, - TAccountTokenAccount extends string - ? ReadonlyAccount - : TAccountTokenAccount, - TAccountNewMetadataUpdateAuthority extends string - ? ReadonlyAccount - : TAccountNewMetadataUpdateAuthority, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type MintNewEditionFromMasterEditionViaTokenInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountNewMetadata extends string | IAccountMeta = string, - TAccountNewEdition extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountNewMint extends string | IAccountMeta = string, - TAccountEditionMarkPda extends string | IAccountMeta = string, - TAccountNewMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountTokenAccountOwner extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountNewMetadataUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -234,67 +157,20 @@ export function getMintNewEditionFromMasterEditionViaTokenInstructionDataCodec() } export type MintNewEditionFromMasterEditionViaTokenInput< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountTokenAccountOwner extends string, - TAccountTokenAccount extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** New Metadata key (pda of ['metadata', program id, mint id]) */ - newMetadata: Address; - /** New Edition (pda of ['metadata', program id, mint id, 'edition']) */ - newEdition: Address; - /** Master Record Edition V2 (pda of ['metadata', program id, master metadata mint id, 'edition']) */ - masterEdition: Address; - /** Mint of new token - THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY */ - newMint: Address; - /** Edition pda to mark creation - will be checked for pre-existence. (pda of ['metadata', program id, master metadata mint id, 'edition', edition_number]) where edition_number is NOT the edition number you pass in args but actually edition_number = floor(edition/EDITION_MARKER_BIT_SIZE). */ - editionMarkPda: Address; - /** Mint authority of new mint */ - newMintAuthority: Address; - /** payer */ - payer: Address; - /** owner of token account containing master token (#8) */ - tokenAccountOwner: Address; - /** token account containing token from master metadata mint */ - tokenAccount: Address; - /** Update authority info for new metadata */ - newMetadataUpdateAuthority: Address; - /** Master record metadata account */ - metadata: Address; - /** Token program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - mintNewEditionFromMasterEditionViaTokenArgs: MintNewEditionFromMasterEditionViaTokenInstructionDataArgs['mintNewEditionFromMasterEditionViaTokenArgs']; -}; - -export type MintNewEditionFromMasterEditionViaTokenInputWithSigners< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountTokenAccountOwner extends string, - TAccountTokenAccount extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountNewMetadata extends string = string, + TAccountNewEdition extends string = string, + TAccountMasterEdition extends string = string, + TAccountNewMint extends string = string, + TAccountEditionMarkPda extends string = string, + TAccountNewMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountTokenAccountOwner extends string = string, + TAccountTokenAccount extends string = string, + TAccountNewMetadataUpdateAuthority extends string = string, + TAccountMetadata extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** New Metadata key (pda of ['metadata', program id, mint id]) */ newMetadata: Address; @@ -342,57 +218,6 @@ export function getMintNewEditionFromMasterEditionViaTokenInstruction< TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MintNewEditionFromMasterEditionViaTokenInputWithSigners< - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountTokenAccountOwner, - TAccountTokenAccount, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): MintNewEditionFromMasterEditionViaTokenInstructionWithSigners< - TProgram, - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountTokenAccountOwner, - TAccountTokenAccount, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent ->; -export function getMintNewEditionFromMasterEditionViaTokenInstruction< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountTokenAccountOwner extends string, - TAccountTokenAccount extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: MintNewEditionFromMasterEditionViaTokenInput< TAccountNewMetadata, @@ -411,7 +236,7 @@ export function getMintNewEditionFromMasterEditionViaTokenInstruction< TAccountRent > ): MintNewEditionFromMasterEditionViaTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountNewMetadata, TAccountNewEdition, TAccountMasterEdition, @@ -426,66 +251,12 @@ export function getMintNewEditionFromMasterEditionViaTokenInstruction< TAccountTokenProgram, TAccountSystemProgram, TAccountRent ->; -export function getMintNewEditionFromMasterEditionViaTokenInstruction< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountTokenAccountOwner extends string, - TAccountTokenAccount extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MintNewEditionFromMasterEditionViaTokenInput< - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountTokenAccountOwner, - TAccountTokenAccount, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getMintNewEditionFromMasterEditionViaTokenInstructionRaw< - TProgram, - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountTokenAccountOwner, - TAccountTokenAccount, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { newMetadata: { value: input.newMetadata ?? null, isWritable: true }, newEdition: { value: input.newEdition ?? null, isWritable: true }, masterEdition: { value: input.masterEdition ?? null, isWritable: true }, @@ -510,6 +281,10 @@ export function getMintNewEditionFromMasterEditionViaTokenInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -524,140 +299,30 @@ export function getMintNewEditionFromMasterEditionViaTokenInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getMintNewEditionFromMasterEditionViaTokenInstructionRaw( - accountMetas as Record, - args as MintNewEditionFromMasterEditionViaTokenInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getMintNewEditionFromMasterEditionViaTokenInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountNewMetadata extends string | IAccountMeta = string, - TAccountNewEdition extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountNewMint extends string | IAccountMeta = string, - TAccountEditionMarkPda extends string | IAccountMeta = string, - TAccountNewMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountTokenAccountOwner extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountNewMetadataUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - newMetadata: TAccountNewMetadata extends string - ? Address - : TAccountNewMetadata; - newEdition: TAccountNewEdition extends string - ? Address - : TAccountNewEdition; - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - newMint: TAccountNewMint extends string - ? Address - : TAccountNewMint; - editionMarkPda: TAccountEditionMarkPda extends string - ? Address - : TAccountEditionMarkPda; - newMintAuthority: TAccountNewMintAuthority extends string - ? Address - : TAccountNewMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - tokenAccountOwner: TAccountTokenAccountOwner extends string - ? Address - : TAccountTokenAccountOwner; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - newMetadataUpdateAuthority: TAccountNewMetadataUpdateAuthority extends string - ? Address - : TAccountNewMetadataUpdateAuthority; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: MintNewEditionFromMasterEditionViaTokenInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.newMetadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.newEdition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.masterEdition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.newMint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.editionMarkPda, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.newMintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.tokenAccountOwner, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.READONLY), - accountMetaWithDefault( - accounts.newMetadataUpdateAuthority, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.newMetadata), + getAccountMeta(accounts.newEdition), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.newMint), + getAccountMeta(accounts.editionMarkPda), + getAccountMeta(accounts.newMintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.tokenAccountOwner), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.newMetadataUpdateAuthority), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], + programAddress, data: getMintNewEditionFromMasterEditionViaTokenInstructionDataEncoder().encode( - args + args as MintNewEditionFromMasterEditionViaTokenInstructionDataArgs ), - programAddress, } as MintNewEditionFromMasterEditionViaTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountNewMetadata, TAccountNewEdition, TAccountMasterEdition, @@ -671,13 +336,14 @@ export function getMintNewEditionFromMasterEditionViaTokenInstructionRaw< TAccountMetadata, TAccountTokenProgram, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedMintNewEditionFromMasterEditionViaTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -737,7 +403,7 @@ export function parseMintNewEditionFromMasterEditionViaTokenInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaVaultProxy.ts b/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaVaultProxy.ts index b1465f042..f0adb5b8e 100644 --- a/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaVaultProxy.ts +++ b/test/packages/js-experimental/src/generated/instructions/mintNewEditionFromMasterEditionViaVaultProxy.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { MintNewEditionFromMasterEditionViaTokenArgs, MintNewEditionFromMasterEditionViaTokenArgsArgs, @@ -43,7 +39,7 @@ import { } from '../types'; export type MintNewEditionFromMasterEditionViaVaultProxyInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountNewMetadata extends string | IAccountMeta = string, TAccountNewEdition extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, @@ -67,92 +63,7 @@ export type MintNewEditionFromMasterEditionViaVaultProxyInstruction< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountNewMetadata extends string - ? WritableAccount - : TAccountNewMetadata, - TAccountNewEdition extends string - ? WritableAccount - : TAccountNewEdition, - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountNewMint extends string - ? WritableAccount - : TAccountNewMint, - TAccountEditionMarkPda extends string - ? WritableAccount - : TAccountEditionMarkPda, - TAccountNewMintAuthority extends string - ? ReadonlySignerAccount - : TAccountNewMintAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountVaultAuthority extends string - ? ReadonlySignerAccount - : TAccountVaultAuthority, - TAccountSafetyDepositStore extends string - ? ReadonlyAccount - : TAccountSafetyDepositStore, - TAccountSafetyDepositBox extends string - ? ReadonlyAccount - : TAccountSafetyDepositBox, - TAccountVault extends string - ? ReadonlyAccount - : TAccountVault, - TAccountNewMetadataUpdateAuthority extends string - ? ReadonlyAccount - : TAccountNewMetadataUpdateAuthority, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountTokenVaultProgram extends string - ? ReadonlyAccount - : TAccountTokenVaultProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type MintNewEditionFromMasterEditionViaVaultProxyInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountNewMetadata extends string | IAccountMeta = string, - TAccountNewEdition extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountNewMint extends string | IAccountMeta = string, - TAccountEditionMarkPda extends string | IAccountMeta = string, - TAccountNewMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountVaultAuthority extends string | IAccountMeta = string, - TAccountSafetyDepositStore extends string | IAccountMeta = string, - TAccountSafetyDepositBox extends string | IAccountMeta = string, - TAccountVault extends string | IAccountMeta = string, - TAccountNewMetadataUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountTokenVaultProgram extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -258,79 +169,23 @@ export function getMintNewEditionFromMasterEditionViaVaultProxyInstructionDataCo } export type MintNewEditionFromMasterEditionViaVaultProxyInput< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountVaultAuthority extends string, - TAccountSafetyDepositStore extends string, - TAccountSafetyDepositBox extends string, - TAccountVault extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountTokenVaultProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** New Metadata key (pda of ['metadata', program id, mint id]) */ - newMetadata: Address; - /** New Edition (pda of ['metadata', program id, mint id, 'edition']) */ - newEdition: Address; - /** Master Record Edition V2 (pda of ['metadata', program id, master metadata mint id, 'edition'] */ - masterEdition: Address; - /** Mint of new token - THIS WILL TRANSFER AUTHORITY AWAY FROM THIS KEY */ - newMint: Address; - /** Edition pda to mark creation - will be checked for pre-existence. (pda of ['metadata', program id, master metadata mint id, 'edition', edition_number]) where edition_number is NOT the edition number you pass in args but actually edition_number = floor(edition/EDITION_MARKER_BIT_SIZE). */ - editionMarkPda: Address; - /** Mint authority of new mint */ - newMintAuthority: Address; - /** payer */ - payer: Address; - /** Vault authority */ - vaultAuthority: Address; - /** Safety deposit token store account */ - safetyDepositStore: Address; - /** Safety deposit box */ - safetyDepositBox: Address; - /** Vault */ - vault: Address; - /** Update authority info for new metadata */ - newMetadataUpdateAuthority: Address; - /** Master record metadata account */ - metadata: Address; - /** Token program */ - tokenProgram?: Address; - /** Token vault program */ - tokenVaultProgram: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - mintNewEditionFromMasterEditionViaTokenArgs: MintNewEditionFromMasterEditionViaVaultProxyInstructionDataArgs['mintNewEditionFromMasterEditionViaTokenArgs']; -}; - -export type MintNewEditionFromMasterEditionViaVaultProxyInputWithSigners< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountVaultAuthority extends string, - TAccountSafetyDepositStore extends string, - TAccountSafetyDepositBox extends string, - TAccountVault extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountTokenVaultProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountNewMetadata extends string = string, + TAccountNewEdition extends string = string, + TAccountMasterEdition extends string = string, + TAccountNewMint extends string = string, + TAccountEditionMarkPda extends string = string, + TAccountNewMintAuthority extends string = string, + TAccountPayer extends string = string, + TAccountVaultAuthority extends string = string, + TAccountSafetyDepositStore extends string = string, + TAccountSafetyDepositBox extends string = string, + TAccountVault extends string = string, + TAccountNewMetadataUpdateAuthority extends string = string, + TAccountMetadata extends string = string, + TAccountTokenProgram extends string = string, + TAccountTokenVaultProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** New Metadata key (pda of ['metadata', program id, mint id]) */ newMetadata: Address; @@ -387,66 +242,6 @@ export function getMintNewEditionFromMasterEditionViaVaultProxyInstruction< TAccountTokenVaultProgram extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MintNewEditionFromMasterEditionViaVaultProxyInputWithSigners< - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountVaultAuthority, - TAccountSafetyDepositStore, - TAccountSafetyDepositBox, - TAccountVault, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountTokenVaultProgram, - TAccountSystemProgram, - TAccountRent - > -): MintNewEditionFromMasterEditionViaVaultProxyInstructionWithSigners< - TProgram, - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountVaultAuthority, - TAccountSafetyDepositStore, - TAccountSafetyDepositBox, - TAccountVault, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountTokenVaultProgram, - TAccountSystemProgram, - TAccountRent ->; -export function getMintNewEditionFromMasterEditionViaVaultProxyInstruction< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountVaultAuthority extends string, - TAccountSafetyDepositStore extends string, - TAccountSafetyDepositBox extends string, - TAccountVault extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountTokenVaultProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: MintNewEditionFromMasterEditionViaVaultProxyInput< TAccountNewMetadata, @@ -468,7 +263,7 @@ export function getMintNewEditionFromMasterEditionViaVaultProxyInstruction< TAccountRent > ): MintNewEditionFromMasterEditionViaVaultProxyInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountNewMetadata, TAccountNewEdition, TAccountMasterEdition, @@ -486,75 +281,12 @@ export function getMintNewEditionFromMasterEditionViaVaultProxyInstruction< TAccountTokenVaultProgram, TAccountSystemProgram, TAccountRent ->; -export function getMintNewEditionFromMasterEditionViaVaultProxyInstruction< - TAccountNewMetadata extends string, - TAccountNewEdition extends string, - TAccountMasterEdition extends string, - TAccountNewMint extends string, - TAccountEditionMarkPda extends string, - TAccountNewMintAuthority extends string, - TAccountPayer extends string, - TAccountVaultAuthority extends string, - TAccountSafetyDepositStore extends string, - TAccountSafetyDepositBox extends string, - TAccountVault extends string, - TAccountNewMetadataUpdateAuthority extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountTokenVaultProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: MintNewEditionFromMasterEditionViaVaultProxyInput< - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountVaultAuthority, - TAccountSafetyDepositStore, - TAccountSafetyDepositBox, - TAccountVault, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountTokenVaultProgram, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getMintNewEditionFromMasterEditionViaVaultProxyInstructionRaw< - TProgram, - TAccountNewMetadata, - TAccountNewEdition, - TAccountMasterEdition, - TAccountNewMint, - TAccountEditionMarkPda, - TAccountNewMintAuthority, - TAccountPayer, - TAccountVaultAuthority, - TAccountSafetyDepositStore, - TAccountSafetyDepositBox, - TAccountVault, - TAccountNewMetadataUpdateAuthority, - TAccountMetadata, - TAccountTokenProgram, - TAccountTokenVaultProgram, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { newMetadata: { value: input.newMetadata ?? null, isWritable: true }, newEdition: { value: input.newEdition ?? null, isWritable: true }, masterEdition: { value: input.masterEdition ?? null, isWritable: true }, @@ -588,6 +320,10 @@ export function getMintNewEditionFromMasterEditionViaVaultProxyInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -602,156 +338,33 @@ export function getMintNewEditionFromMasterEditionViaVaultProxyInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = - getMintNewEditionFromMasterEditionViaVaultProxyInstructionRaw( - accountMetas as Record, - args as MintNewEditionFromMasterEditionViaVaultProxyInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getMintNewEditionFromMasterEditionViaVaultProxyInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountNewMetadata extends string | IAccountMeta = string, - TAccountNewEdition extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountNewMint extends string | IAccountMeta = string, - TAccountEditionMarkPda extends string | IAccountMeta = string, - TAccountNewMintAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountVaultAuthority extends string | IAccountMeta = string, - TAccountSafetyDepositStore extends string | IAccountMeta = string, - TAccountSafetyDepositBox extends string | IAccountMeta = string, - TAccountVault extends string | IAccountMeta = string, - TAccountNewMetadataUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountTokenVaultProgram extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - newMetadata: TAccountNewMetadata extends string - ? Address - : TAccountNewMetadata; - newEdition: TAccountNewEdition extends string - ? Address - : TAccountNewEdition; - masterEdition: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - newMint: TAccountNewMint extends string - ? Address - : TAccountNewMint; - editionMarkPda: TAccountEditionMarkPda extends string - ? Address - : TAccountEditionMarkPda; - newMintAuthority: TAccountNewMintAuthority extends string - ? Address - : TAccountNewMintAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - vaultAuthority: TAccountVaultAuthority extends string - ? Address - : TAccountVaultAuthority; - safetyDepositStore: TAccountSafetyDepositStore extends string - ? Address - : TAccountSafetyDepositStore; - safetyDepositBox: TAccountSafetyDepositBox extends string - ? Address - : TAccountSafetyDepositBox; - vault: TAccountVault extends string - ? Address - : TAccountVault; - newMetadataUpdateAuthority: TAccountNewMetadataUpdateAuthority extends string - ? Address - : TAccountNewMetadataUpdateAuthority; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - tokenVaultProgram: TAccountTokenVaultProgram extends string - ? Address - : TAccountTokenVaultProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - args: MintNewEditionFromMasterEditionViaVaultProxyInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.newMetadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.newEdition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.masterEdition, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.newMint, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.editionMarkPda, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.newMintAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.vaultAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.safetyDepositStore, AccountRole.READONLY), - accountMetaWithDefault(accounts.safetyDepositBox, AccountRole.READONLY), - accountMetaWithDefault(accounts.vault, AccountRole.READONLY), - accountMetaWithDefault( - accounts.newMetadataUpdateAuthority, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.tokenVaultProgram, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.newMetadata), + getAccountMeta(accounts.newEdition), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.newMint), + getAccountMeta(accounts.editionMarkPda), + getAccountMeta(accounts.newMintAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.vaultAuthority), + getAccountMeta(accounts.safetyDepositStore), + getAccountMeta(accounts.safetyDepositBox), + getAccountMeta(accounts.vault), + getAccountMeta(accounts.newMetadataUpdateAuthority), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.tokenVaultProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], + programAddress, data: getMintNewEditionFromMasterEditionViaVaultProxyInstructionDataEncoder().encode( - args + args as MintNewEditionFromMasterEditionViaVaultProxyInstructionDataArgs ), - programAddress, } as MintNewEditionFromMasterEditionViaVaultProxyInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountNewMetadata, TAccountNewEdition, TAccountMasterEdition, @@ -768,13 +381,14 @@ export function getMintNewEditionFromMasterEditionViaVaultProxyInstructionRaw< TAccountTokenProgram, TAccountTokenVaultProgram, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedMintNewEditionFromMasterEditionViaVaultProxyInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -840,7 +454,7 @@ export function parseMintNewEditionFromMasterEditionViaVaultProxyInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/puffMetadata.ts b/test/packages/js-experimental/src/generated/instructions/puffMetadata.ts index 4439a320b..f6441d67e 100644 --- a/test/packages/js-experimental/src/generated/instructions/puffMetadata.ts +++ b/test/packages/js-experimental/src/generated/instructions/puffMetadata.ts @@ -19,38 +19,19 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, IInstructionWithData, WritableAccount, } from '@solana/instructions'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type PuffMetadataInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - ...TRemainingAccounts, - ] - >; - -export type PuffMetadataInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -87,84 +68,44 @@ export function getPuffMetadataInstructionDataCodec(): Codec< ); } -export type PuffMetadataInput = { +export type PuffMetadataInput = { /** Metadata account */ metadata: Address; }; -export type PuffMetadataInputWithSigners = { - /** Metadata account */ - metadata: Address; -}; - -export function getPuffMetadataInstruction< - TAccountMetadata extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: PuffMetadataInputWithSigners -): PuffMetadataInstructionWithSigners; -export function getPuffMetadataInstruction< - TAccountMetadata extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( +export function getPuffMetadataInstruction( input: PuffMetadataInput -): PuffMetadataInstruction; -export function getPuffMetadataInstruction< - TAccountMetadata extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->(input: PuffMetadataInput): IInstruction { +): PuffMetadataInstruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, + TAccountMetadata +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getPuffMetadataInstructionRaw - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getPuffMetadataInstructionRaw( - accountMetas as Record, - programAddress - ); + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [getAccountMeta(accounts.metadata)], + programAddress, + data: getPuffMetadataInstructionDataEncoder().encode({}), + } as PuffMetadataInstruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, + TAccountMetadata + >; return instruction; } -export function getPuffMetadataInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { - accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - ...(remainingAccounts ?? []), - ], - data: getPuffMetadataInstructionDataEncoder().encode({}), - programAddress, - } as PuffMetadataInstruction; -} - export type ParsedPuffMetadataInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/removeCreatorVerification.ts b/test/packages/js-experimental/src/generated/instructions/removeCreatorVerification.ts index 15053aa9d..ec3229e1f 100644 --- a/test/packages/js-experimental/src/generated/instructions/removeCreatorVerification.ts +++ b/test/packages/js-experimental/src/generated/instructions/removeCreatorVerification.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -28,36 +27,14 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type RemoveCreatorVerificationInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCreator extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCreator extends string - ? ReadonlySignerAccount - : TAccountCreator, - ...TRemainingAccounts, - ] - >; - -export type RemoveCreatorVerificationInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCreator extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -101,18 +78,8 @@ export function getRemoveCreatorVerificationInstructionDataCodec(): Codec< } export type RemoveCreatorVerificationInput< - TAccountMetadata extends string, - TAccountCreator extends string, -> = { - /** Metadata (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Creator */ - creator: Address; -}; - -export type RemoveCreatorVerificationInputWithSigners< - TAccountMetadata extends string, - TAccountCreator extends string, + TAccountMetadata extends string = string, + TAccountCreator extends string = string, > = { /** Metadata (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -123,102 +90,45 @@ export type RemoveCreatorVerificationInputWithSigners< export function getRemoveCreatorVerificationInstruction< TAccountMetadata extends string, TAccountCreator extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RemoveCreatorVerificationInputWithSigners< - TAccountMetadata, - TAccountCreator - > -): RemoveCreatorVerificationInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCreator ->; -export function getRemoveCreatorVerificationInstruction< - TAccountMetadata extends string, - TAccountCreator extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: RemoveCreatorVerificationInput ): RemoveCreatorVerificationInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCreator ->; -export function getRemoveCreatorVerificationInstruction< - TAccountMetadata extends string, - TAccountCreator extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RemoveCreatorVerificationInput -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getRemoveCreatorVerificationInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCreator - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, creator: { value: input.creator ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getRemoveCreatorVerificationInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getRemoveCreatorVerificationInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCreator extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - creator: TAccountCreator extends string - ? Address - : TAccountCreator; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.creator, AccountRole.READONLY_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.creator), ], - data: getRemoveCreatorVerificationInstructionDataEncoder().encode({}), programAddress, + data: getRemoveCreatorVerificationInstructionDataEncoder().encode({}), } as RemoveCreatorVerificationInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, - TAccountCreator, - TRemainingAccounts + TAccountCreator >; + + return instruction; } export type ParsedRemoveCreatorVerificationInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/revoke.ts b/test/packages/js-experimental/src/generated/instructions/revoke.ts index 25544ab09..5d8b9b794 100644 --- a/test/packages/js-experimental/src/generated/instructions/revoke.ts +++ b/test/packages/js-experimental/src/generated/instructions/revoke.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { RevokeArgs, RevokeArgsArgs, @@ -43,7 +39,7 @@ import { } from '../types'; export type RevokeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegateRecord extends string | IAccountMeta = string, TAccountDelegate extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, @@ -63,76 +59,7 @@ export type RevokeInstruction< | string | IAccountMeta = string, TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountDelegateRecord extends string - ? WritableAccount - : TAccountDelegateRecord, - TAccountDelegate extends string - ? ReadonlyAccount - : TAccountDelegate, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountToken extends string - ? WritableAccount - : TAccountToken, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - ...TRemainingAccounts, - ] - >; - -export type RevokeInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountDelegate extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -217,63 +144,19 @@ export function getRevokeInstructionDataCodec(): Codec< } export type RevokeInput< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, -> = { - /** Delegate account key (pda of [mint id, delegate role, user id, authority id]) */ - delegateRecord: Address; - /** Owner of the delegated account */ - delegate: Address; - /** Metadata account */ - metadata: Address; - /** Master Edition account */ - masterEdition?: Address; - /** Mint of metadata */ - mint: Address; - /** Owned Token Account of mint */ - token?: Address; - /** Authority to approve the delegation */ - authority: Address; - /** Payer */ - payer: Address; - /** System Program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** SPL Token Program */ - splTokenProgram?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - revokeArgs: RevokeInstructionDataArgs['revokeArgs']; -}; - -export type RevokeInputWithSigners< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, + TAccountDelegateRecord extends string = string, + TAccountDelegate extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountMint extends string = string, + TAccountToken extends string = string, + TAccountAuthority extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountAuthorizationRulesProgram extends string = string, + TAccountAuthorizationRules extends string = string, > = { /** Delegate account key (pda of [mint id, delegate role, user id, authority id]) */ delegateRecord: Address; @@ -318,54 +201,6 @@ export function getRevokeInstruction< TAccountSplTokenProgram extends string, TAccountAuthorizationRulesProgram extends string, TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RevokeInputWithSigners< - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): RevokeInstructionWithSigners< - TProgram, - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules ->; -export function getRevokeInstruction< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: RevokeInput< TAccountDelegateRecord, @@ -383,7 +218,7 @@ export function getRevokeInstruction< TAccountAuthorizationRules > ): RevokeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegateRecord, TAccountDelegate, TAccountMetadata, @@ -397,63 +232,12 @@ export function getRevokeInstruction< TAccountSplTokenProgram, TAccountAuthorizationRulesProgram, TAccountAuthorizationRules ->; -export function getRevokeInstruction< - TAccountDelegateRecord extends string, - TAccountDelegate extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountToken extends string, - TAccountAuthority extends string, - TAccountPayer extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountSplTokenProgram extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RevokeInput< - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getRevokeInstructionRaw< - TProgram, - TAccountDelegateRecord, - TAccountDelegate, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountToken, - TAccountAuthority, - TAccountPayer, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountSplTokenProgram, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > - >[0]; - const accounts: Record = { + const originalAccounts = { delegateRecord: { value: input.delegateRecord ?? null, isWritable: true }, delegate: { value: input.delegate ?? null, isWritable: false }, metadata: { value: input.metadata ?? null, isWritable: true }, @@ -480,6 +264,10 @@ export function getRevokeInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -494,152 +282,29 @@ export function getRevokeInstruction< 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getRevokeInstructionRaw( - accountMetas as Record, - args as RevokeInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getRevokeInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountDelegate extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountSplTokenProgram extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - delegateRecord: TAccountDelegateRecord extends string - ? Address - : TAccountDelegateRecord; - delegate: TAccountDelegate extends string - ? Address - : TAccountDelegate; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition?: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - token?: TAccountToken extends string - ? Address - : TAccountToken; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - }, - args: RevokeInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.delegateRecord, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.delegate, AccountRole.READONLY), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEdition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.token ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.delegateRecord), + getAccountMeta(accounts.delegate), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.token), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.authorizationRulesProgram), + getAccountMeta(accounts.authorizationRules), ], - data: getRevokeInstructionDataEncoder().encode(args), programAddress, + data: getRevokeInstructionDataEncoder().encode( + args as RevokeInstructionDataArgs + ), } as RevokeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegateRecord, TAccountDelegate, TAccountMetadata, @@ -652,13 +317,14 @@ export function getRevokeInstructionRaw< TAccountSysvarInstructions, TAccountSplTokenProgram, TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules, - TRemainingAccounts + TAccountAuthorizationRules >; + + return instruction; } export type ParsedRevokeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -713,7 +379,7 @@ export function parseRevokeInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/revokeCollectionAuthority.ts b/test/packages/js-experimental/src/generated/instructions/revokeCollectionAuthority.ts index aa53e6eac..ba45b5d00 100644 --- a/test/packages/js-experimental/src/generated/instructions/revokeCollectionAuthority.ts +++ b/test/packages/js-experimental/src/generated/instructions/revokeCollectionAuthority.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,47 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type RevokeCollectionAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountDelegateAuthority extends string | IAccountMeta = string, - TAccountRevokeAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCollectionAuthorityRecord extends string - ? WritableAccount - : TAccountCollectionAuthorityRecord, - TAccountDelegateAuthority extends string - ? WritableAccount - : TAccountDelegateAuthority, - TAccountRevokeAuthority extends string - ? WritableSignerAccount - : TAccountRevokeAuthority, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - ...TRemainingAccounts, - ] - >; - -export type RevokeCollectionAuthorityInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, @@ -77,7 +40,7 @@ export type RevokeCollectionAuthorityInstructionWithSigners< TAccountRevokeAuthority extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -130,30 +93,11 @@ export function getRevokeCollectionAuthorityInstructionDataCodec(): Codec< } export type RevokeCollectionAuthorityInput< - TAccountCollectionAuthorityRecord extends string, - TAccountDelegateAuthority extends string, - TAccountRevokeAuthority extends string, - TAccountMetadata extends string, - TAccountMint extends string, -> = { - /** Collection Authority Record PDA */ - collectionAuthorityRecord: Address; - /** Delegated Collection Authority */ - delegateAuthority: Address; - /** Update Authority, or Delegated Authority, of Collection NFT */ - revokeAuthority: Address; - /** Metadata account */ - metadata: Address; - /** Mint of Metadata */ - mint: Address; -}; - -export type RevokeCollectionAuthorityInputWithSigners< - TAccountCollectionAuthorityRecord extends string, - TAccountDelegateAuthority extends string, - TAccountRevokeAuthority extends string, - TAccountMetadata extends string, - TAccountMint extends string, + TAccountCollectionAuthorityRecord extends string = string, + TAccountDelegateAuthority extends string = string, + TAccountRevokeAuthority extends string = string, + TAccountMetadata extends string = string, + TAccountMint extends string = string, > = { /** Collection Authority Record PDA */ collectionAuthorityRecord: Address; @@ -173,30 +117,6 @@ export function getRevokeCollectionAuthorityInstruction< TAccountRevokeAuthority extends string, TAccountMetadata extends string, TAccountMint extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RevokeCollectionAuthorityInputWithSigners< - TAccountCollectionAuthorityRecord, - TAccountDelegateAuthority, - TAccountRevokeAuthority, - TAccountMetadata, - TAccountMint - > -): RevokeCollectionAuthorityInstructionWithSigners< - TProgram, - TAccountCollectionAuthorityRecord, - TAccountDelegateAuthority, - TAccountRevokeAuthority, - TAccountMetadata, - TAccountMint ->; -export function getRevokeCollectionAuthorityInstruction< - TAccountCollectionAuthorityRecord extends string, - TAccountDelegateAuthority extends string, - TAccountRevokeAuthority extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: RevokeCollectionAuthorityInput< TAccountCollectionAuthorityRecord, @@ -206,45 +126,18 @@ export function getRevokeCollectionAuthorityInstruction< TAccountMint > ): RevokeCollectionAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionAuthorityRecord, TAccountDelegateAuthority, TAccountRevokeAuthority, TAccountMetadata, TAccountMint ->; -export function getRevokeCollectionAuthorityInstruction< - TAccountCollectionAuthorityRecord extends string, - TAccountDelegateAuthority extends string, - TAccountRevokeAuthority extends string, - TAccountMetadata extends string, - TAccountMint extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RevokeCollectionAuthorityInput< - TAccountCollectionAuthorityRecord, - TAccountDelegateAuthority, - TAccountRevokeAuthority, - TAccountMetadata, - TAccountMint - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getRevokeCollectionAuthorityInstructionRaw< - TProgram, - TAccountCollectionAuthorityRecord, - TAccountDelegateAuthority, - TAccountRevokeAuthority, - TAccountMetadata, - TAccountMint - > - >[0]; - const accounts: Record = { + const originalAccounts = { collectionAuthorityRecord: { value: input.collectionAuthorityRecord ?? null, isWritable: true, @@ -257,81 +150,36 @@ export function getRevokeCollectionAuthorityInstruction< metadata: { value: input.metadata ?? null, isWritable: false }, mint: { value: input.mint ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getRevokeCollectionAuthorityInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getRevokeCollectionAuthorityInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountDelegateAuthority extends string | IAccountMeta = string, - TAccountRevokeAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - collectionAuthorityRecord: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - delegateAuthority: TAccountDelegateAuthority extends string - ? Address - : TAccountDelegateAuthority; - revokeAuthority: TAccountRevokeAuthority extends string - ? Address - : TAccountRevokeAuthority; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - mint: TAccountMint extends string ? Address : TAccountMint; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault( - accounts.collectionAuthorityRecord, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.delegateAuthority, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.revokeAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.collectionAuthorityRecord), + getAccountMeta(accounts.delegateAuthority), + getAccountMeta(accounts.revokeAuthority), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.mint), ], - data: getRevokeCollectionAuthorityInstructionDataEncoder().encode({}), programAddress, + data: getRevokeCollectionAuthorityInstructionDataEncoder().encode({}), } as RevokeCollectionAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionAuthorityRecord, TAccountDelegateAuthority, TAccountRevokeAuthority, TAccountMetadata, - TAccountMint, - TRemainingAccounts + TAccountMint >; + + return instruction; } export type ParsedRevokeCollectionAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/revokeUseAuthority.ts b/test/packages/js-experimental/src/generated/instructions/revokeUseAuthority.ts index 09bc1fcd4..2605ffb7c 100644 --- a/test/packages/js-experimental/src/generated/instructions/revokeUseAuthority.ts +++ b/test/packages/js-experimental/src/generated/instructions/revokeUseAuthority.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,65 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type RevokeUseAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountUser extends string | IAccountMeta = string, - TAccountOwnerTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountUseAuthorityRecord extends string - ? WritableAccount - : TAccountUseAuthorityRecord, - TAccountOwner extends string - ? WritableSignerAccount - : TAccountOwner, - TAccountUser extends string - ? ReadonlyAccount - : TAccountUser, - TAccountOwnerTokenAccount extends string - ? WritableAccount - : TAccountOwnerTokenAccount, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountMetadata extends string - ? ReadonlyAccount - : TAccountMetadata, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - ...TRemainingAccounts, - ] - >; - -export type RevokeUseAuthorityInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountUseAuthorityRecord extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TAccountUser extends string | IAccountMeta = string, @@ -101,7 +46,7 @@ export type RevokeUseAuthorityInstructionWithSigners< | string | IAccountMeta = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -164,46 +109,15 @@ export function getRevokeUseAuthorityInstructionDataCodec(): Codec< } export type RevokeUseAuthorityInput< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, -> = { - /** Use Authority Record PDA */ - useAuthorityRecord: Address; - /** Owner */ - owner: Address; - /** A Use Authority */ - user: Address; - /** Owned Token Account Of Mint */ - ownerTokenAccount: Address; - /** Mint of Metadata */ - mint: Address; - /** Metadata account */ - metadata: Address; - /** Token program */ - tokenProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; -}; - -export type RevokeUseAuthorityInputWithSigners< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, + TAccountUseAuthorityRecord extends string = string, + TAccountOwner extends string = string, + TAccountUser extends string = string, + TAccountOwnerTokenAccount extends string = string, + TAccountMint extends string = string, + TAccountMetadata extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, > = { /** Use Authority Record PDA */ useAuthorityRecord: Address; @@ -235,42 +149,6 @@ export function getRevokeUseAuthorityInstruction< TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RevokeUseAuthorityInputWithSigners< - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMint, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): RevokeUseAuthorityInstructionWithSigners< - TProgram, - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMint, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent ->; -export function getRevokeUseAuthorityInstruction< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: RevokeUseAuthorityInput< TAccountUseAuthorityRecord, @@ -284,7 +162,7 @@ export function getRevokeUseAuthorityInstruction< TAccountRent > ): RevokeUseAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountUseAuthorityRecord, TAccountOwner, TAccountUser, @@ -294,51 +172,12 @@ export function getRevokeUseAuthorityInstruction< TAccountTokenProgram, TAccountSystemProgram, TAccountRent ->; -export function getRevokeUseAuthorityInstruction< - TAccountUseAuthorityRecord extends string, - TAccountOwner extends string, - TAccountUser extends string, - TAccountOwnerTokenAccount extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountTokenProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: RevokeUseAuthorityInput< - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMint, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getRevokeUseAuthorityInstructionRaw< - TProgram, - TAccountUseAuthorityRecord, - TAccountOwner, - TAccountUser, - TAccountOwnerTokenAccount, - TAccountMint, - TAccountMetadata, - TAccountTokenProgram, - TAccountSystemProgram, - TAccountRent - > - >[0]; - const accounts: Record = { + const originalAccounts = { useAuthorityRecord: { value: input.useAuthorityRecord ?? null, isWritable: true, @@ -355,6 +194,10 @@ export function getRevokeUseAuthorityInstruction< systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.tokenProgram.value) { @@ -366,96 +209,23 @@ export function getRevokeUseAuthorityInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getRevokeUseAuthorityInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getRevokeUseAuthorityInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountUser extends string | IAccountMeta = string, - TAccountOwnerTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - useAuthorityRecord: TAccountUseAuthorityRecord extends string - ? Address - : TAccountUseAuthorityRecord; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - user: TAccountUser extends string ? Address : TAccountUser; - ownerTokenAccount: TAccountOwnerTokenAccount extends string - ? Address - : TAccountOwnerTokenAccount; - mint: TAccountMint extends string ? Address : TAccountMint; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.useAuthorityRecord, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.owner, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.user, AccountRole.READONLY), - accountMetaWithDefault(accounts.ownerTokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault(accounts.metadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.useAuthorityRecord), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.user), + getAccountMeta(accounts.ownerTokenAccount), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), ], - data: getRevokeUseAuthorityInstructionDataEncoder().encode({}), programAddress, + data: getRevokeUseAuthorityInstructionDataEncoder().encode({}), } as RevokeUseAuthorityInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountUseAuthorityRecord, TAccountOwner, TAccountUser, @@ -464,13 +234,14 @@ export function getRevokeUseAuthorityInstructionRaw< TAccountMetadata, TAccountTokenProgram, TAccountSystemProgram, - TAccountRent, - TRemainingAccounts + TAccountRent >; + + return instruction; } export type ParsedRevokeUseAuthorityInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -517,7 +288,7 @@ export function parseRevokeUseAuthorityInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/setAndVerifyCollection.ts b/test/packages/js-experimental/src/generated/instructions/setAndVerifyCollection.ts index 8e25e57de..fa4dee2b4 100644 --- a/test/packages/js-experimental/src/generated/instructions/setAndVerifyCollection.ts +++ b/test/packages/js-experimental/src/generated/instructions/setAndVerifyCollection.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,61 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type SetAndVerifyCollectionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCollectionAuthority extends string - ? WritableSignerAccount - : TAccountCollectionAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlyAccount - : TAccountUpdateAuthority, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollection extends string - ? ReadonlyAccount - : TAccountCollection, - TAccountCollectionMasterEditionAccount extends string - ? ReadonlyAccount - : TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - ...TRemainingAccounts, - ] - >; - -export type SetAndVerifyCollectionInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -96,7 +45,7 @@ export type SetAndVerifyCollectionInstructionWithSigners< TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -157,42 +106,14 @@ export function getSetAndVerifyCollectionInstructionDataCodec(): Codec< } export type SetAndVerifyCollectionInput< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Collection Update authority */ - collectionAuthority: Address; - /** Payer */ - payer: Address; - /** Update Authority of Collection NFT and NFT */ - updateAuthority: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Metadata Account of the Collection */ - collection: Address; - /** MasterEdition2 Account of the Collection Token */ - collectionMasterEditionAccount: Address; - /** Collection Authority Record PDA */ - collectionAuthorityRecord?: Address; -}; - -export type SetAndVerifyCollectionInputWithSigners< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, + TAccountMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollection extends string = string, + TAccountCollectionMasterEditionAccount extends string = string, + TAccountCollectionAuthorityRecord extends string = string, > = { /** Metadata account */ metadata: Address; @@ -221,39 +142,6 @@ export function getSetAndVerifyCollectionInstruction< TAccountCollection extends string, TAccountCollectionMasterEditionAccount extends string, TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetAndVerifyCollectionInputWithSigners< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): SetAndVerifyCollectionInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord ->; -export function getSetAndVerifyCollectionInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: SetAndVerifyCollectionInput< TAccountMetadata, @@ -266,7 +154,7 @@ export function getSetAndVerifyCollectionInstruction< TAccountCollectionAuthorityRecord > ): SetAndVerifyCollectionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, @@ -275,48 +163,12 @@ export function getSetAndVerifyCollectionInstruction< TAccountCollection, TAccountCollectionMasterEditionAccount, TAccountCollectionAuthorityRecord ->; -export function getSetAndVerifyCollectionInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetAndVerifyCollectionInput< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSetAndVerifyCollectionInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, collectionAuthority: { value: input.collectionAuthority ?? null, @@ -338,96 +190,27 @@ export function getSetAndVerifyCollectionInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSetAndVerifyCollectionInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getSetAndVerifyCollectionInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collection: TAccountCollection extends string - ? Address - : TAccountCollection; - collectionMasterEditionAccount: TAccountCollectionMasterEditionAccount extends string - ? Address - : TAccountCollectionMasterEditionAccount; - collectionAuthorityRecord?: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.updateAuthority, AccountRole.READONLY), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collection, AccountRole.READONLY), - accountMetaWithDefault( - accounts.collectionMasterEditionAccount, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collection), + getAccountMeta(accounts.collectionMasterEditionAccount), + getAccountMeta(accounts.collectionAuthorityRecord), ], - data: getSetAndVerifyCollectionInstructionDataEncoder().encode({}), programAddress, + data: getSetAndVerifyCollectionInstructionDataEncoder().encode({}), } as SetAndVerifyCollectionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, @@ -435,13 +218,14 @@ export function getSetAndVerifyCollectionInstructionRaw< TAccountCollectionMint, TAccountCollection, TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord, - TRemainingAccounts + TAccountCollectionAuthorityRecord >; + + return instruction; } export type ParsedSetAndVerifyCollectionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -486,7 +270,7 @@ export function parseSetAndVerifyCollectionInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/setAndVerifySizedCollectionItem.ts b/test/packages/js-experimental/src/generated/instructions/setAndVerifySizedCollectionItem.ts index 49372688e..b9c8f4550 100644 --- a/test/packages/js-experimental/src/generated/instructions/setAndVerifySizedCollectionItem.ts +++ b/test/packages/js-experimental/src/generated/instructions/setAndVerifySizedCollectionItem.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,61 +29,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type SetAndVerifySizedCollectionItemInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCollectionAuthority extends string - ? ReadonlySignerAccount - : TAccountCollectionAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountUpdateAuthority extends string - ? ReadonlyAccount - : TAccountUpdateAuthority, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollection extends string - ? WritableAccount - : TAccountCollection, - TAccountCollectionMasterEditionAccount extends string - ? WritableAccount - : TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - ...TRemainingAccounts, - ] - >; - -export type SetAndVerifySizedCollectionItemInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -97,7 +46,7 @@ export type SetAndVerifySizedCollectionItemInstructionWithSigners< TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -160,42 +109,14 @@ export function getSetAndVerifySizedCollectionItemInstructionDataCodec(): Codec< } export type SetAndVerifySizedCollectionItemInput< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Collection Update authority */ - collectionAuthority: Address; - /** payer */ - payer: Address; - /** Update Authority of Collection NFT and NFT */ - updateAuthority: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Metadata Account of the Collection */ - collection: Address; - /** MasterEdition2 Account of the Collection Token */ - collectionMasterEditionAccount: Address; - /** Collection Authority Record PDA */ - collectionAuthorityRecord?: Address; -}; - -export type SetAndVerifySizedCollectionItemInputWithSigners< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, + TAccountMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountPayer extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollection extends string = string, + TAccountCollectionMasterEditionAccount extends string = string, + TAccountCollectionAuthorityRecord extends string = string, > = { /** Metadata account */ metadata: Address; @@ -224,39 +145,6 @@ export function getSetAndVerifySizedCollectionItemInstruction< TAccountCollection extends string, TAccountCollectionMasterEditionAccount extends string, TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetAndVerifySizedCollectionItemInputWithSigners< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): SetAndVerifySizedCollectionItemInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord ->; -export function getSetAndVerifySizedCollectionItemInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: SetAndVerifySizedCollectionItemInput< TAccountMetadata, @@ -269,7 +157,7 @@ export function getSetAndVerifySizedCollectionItemInstruction< TAccountCollectionAuthorityRecord > ): SetAndVerifySizedCollectionItemInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, @@ -278,48 +166,12 @@ export function getSetAndVerifySizedCollectionItemInstruction< TAccountCollection, TAccountCollectionMasterEditionAccount, TAccountCollectionAuthorityRecord ->; -export function getSetAndVerifySizedCollectionItemInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountUpdateAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetAndVerifySizedCollectionItemInput< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSetAndVerifySizedCollectionItemInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountUpdateAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, collectionAuthority: { value: input.collectionAuthority ?? null, @@ -341,96 +193,27 @@ export function getSetAndVerifySizedCollectionItemInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSetAndVerifySizedCollectionItemInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getSetAndVerifySizedCollectionItemInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collection: TAccountCollection extends string - ? Address - : TAccountCollection; - collectionMasterEditionAccount: TAccountCollectionMasterEditionAccount extends string - ? Address - : TAccountCollectionMasterEditionAccount; - collectionAuthorityRecord?: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.updateAuthority, AccountRole.READONLY), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collection, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionMasterEditionAccount, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.collectionAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collection), + getAccountMeta(accounts.collectionMasterEditionAccount), + getAccountMeta(accounts.collectionAuthorityRecord), ], - data: getSetAndVerifySizedCollectionItemInstructionDataEncoder().encode({}), programAddress, + data: getSetAndVerifySizedCollectionItemInstructionDataEncoder().encode({}), } as SetAndVerifySizedCollectionItemInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, @@ -438,13 +221,14 @@ export function getSetAndVerifySizedCollectionItemInstructionRaw< TAccountCollectionMint, TAccountCollection, TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord, - TRemainingAccounts + TAccountCollectionAuthorityRecord >; + + return instruction; } export type ParsedSetAndVerifySizedCollectionItemInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -489,7 +273,7 @@ export function parseSetAndVerifySizedCollectionItemInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/setAuthority.ts b/test/packages/js-experimental/src/generated/instructions/setAuthority.ts index 5594a056b..e21085198 100644 --- a/test/packages/js-experimental/src/generated/instructions/setAuthority.ts +++ b/test/packages/js-experimental/src/generated/instructions/setAuthority.ts @@ -25,7 +25,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -34,36 +33,14 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type SetAuthorityInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - ...TRemainingAccounts, - ] - >; - -export type SetAuthorityInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -117,17 +94,8 @@ export function getSetAuthorityInstructionDataCodec(): Codec< } export type SetAuthorityInput< - TAccountCandyMachine extends string, - TAccountAuthority extends string, -> = { - candyMachine: Address; - authority: Address; - newAuthority: SetAuthorityInstructionDataArgs['newAuthority']; -}; - -export type SetAuthorityInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthority extends string, + TAccountCandyMachine extends string = string, + TAccountAuthority extends string = string, > = { candyMachine: Address; authority: TransactionSigner; @@ -137,100 +105,50 @@ export type SetAuthorityInputWithSigners< export function getSetAuthorityInstruction< TAccountCandyMachine extends string, TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( - input: SetAuthorityInputWithSigners -): SetAuthorityInstructionWithSigners< - TProgram, + input: SetAuthorityInput +): SetAuthorityInstruction< + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority ->; -export function getSetAuthorityInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: SetAuthorityInput -): SetAuthorityInstruction; -export function getSetAuthorityInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: SetAuthorityInput -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSetAuthorityInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSetAuthorityInstructionRaw( - accountMetas as Record, - args as SetAuthorityInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getSetAuthorityInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - }, - args: SetAuthorityInstructionDataArgs, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authority), ], - data: getSetAuthorityInstructionDataEncoder().encode(args), programAddress, + data: getSetAuthorityInstructionDataEncoder().encode( + args as SetAuthorityInstructionDataArgs + ), } as SetAuthorityInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, - TAccountAuthority, - TRemainingAccounts + TAccountAuthority >; + + return instruction; } export type ParsedSetAuthorityInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/setCollection.ts b/test/packages/js-experimental/src/generated/instructions/setCollection.ts index 699774feb..c050e1812 100644 --- a/test/packages/js-experimental/src/generated/instructions/setCollection.ts +++ b/test/packages/js-experimental/src/generated/instructions/setCollection.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -32,93 +31,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type SetCollectionInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountAuthorityPda extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountNewCollectionUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountNewCollectionMetadata extends string | IAccountMeta = string, - TAccountNewCollectionMint extends string | IAccountMeta = string, - TAccountNewCollectionMasterEdition extends - | string - | IAccountMeta = string, - TAccountNewCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountTokenMetadataProgram extends - | string - | IAccountMeta = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - TAccountAuthorityPda extends string - ? WritableAccount - : TAccountAuthorityPda, - TAccountPayer extends string - ? ReadonlySignerAccount - : TAccountPayer, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollectionMetadata extends string - ? ReadonlyAccount - : TAccountCollectionMetadata, - TAccountCollectionAuthorityRecord extends string - ? WritableAccount - : TAccountCollectionAuthorityRecord, - TAccountNewCollectionUpdateAuthority extends string - ? WritableSignerAccount - : TAccountNewCollectionUpdateAuthority, - TAccountNewCollectionMetadata extends string - ? ReadonlyAccount - : TAccountNewCollectionMetadata, - TAccountNewCollectionMint extends string - ? ReadonlyAccount - : TAccountNewCollectionMint, - TAccountNewCollectionMasterEdition extends string - ? ReadonlyAccount - : TAccountNewCollectionMasterEdition, - TAccountNewCollectionAuthorityRecord extends string - ? WritableAccount - : TAccountNewCollectionAuthorityRecord, - TAccountTokenMetadataProgram extends string - ? ReadonlyAccount - : TAccountTokenMetadataProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - ...TRemainingAccounts, - ] - >; - -export type SetCollectionInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthority extends string | IAccountMeta = string, TAccountAuthorityPda extends string | IAccountMeta = string, @@ -145,7 +62,7 @@ export type SetCollectionInstructionWithSigners< TAccountSystemProgram extends | string | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -232,52 +149,20 @@ export function getSetCollectionInstructionDataCodec(): Codec< } export type SetCollectionInput< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountAuthorityPda extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionUpdateAuthority extends string, - TAccountNewCollectionMetadata extends string, - TAccountNewCollectionMint extends string, - TAccountNewCollectionMasterEdition extends string, - TAccountNewCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, -> = { - candyMachine: Address; - authority: Address; - authorityPda: Address; - payer: Address; - collectionMint: Address; - collectionMetadata: Address; - collectionAuthorityRecord: Address; - newCollectionUpdateAuthority: Address; - newCollectionMetadata: Address; - newCollectionMint: Address; - newCollectionMasterEdition: Address; - newCollectionAuthorityRecord: Address; - tokenMetadataProgram?: Address; - systemProgram?: Address; -}; - -export type SetCollectionInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountAuthorityPda extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionUpdateAuthority extends string, - TAccountNewCollectionMetadata extends string, - TAccountNewCollectionMint extends string, - TAccountNewCollectionMasterEdition extends string, - TAccountNewCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, + TAccountCandyMachine extends string = string, + TAccountAuthority extends string = string, + TAccountAuthorityPda extends string = string, + TAccountPayer extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollectionMetadata extends string = string, + TAccountCollectionAuthorityRecord extends string = string, + TAccountNewCollectionUpdateAuthority extends string = string, + TAccountNewCollectionMetadata extends string = string, + TAccountNewCollectionMint extends string = string, + TAccountNewCollectionMasterEdition extends string = string, + TAccountNewCollectionAuthorityRecord extends string = string, + TAccountTokenMetadataProgram extends string = string, + TAccountSystemProgram extends string = string, > = { candyMachine: Address; authority: TransactionSigner; @@ -310,57 +195,6 @@ export function getSetCollectionInstruction< TAccountNewCollectionAuthorityRecord extends string, TAccountTokenMetadataProgram extends string, TAccountSystemProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: SetCollectionInputWithSigners< - TAccountCandyMachine, - TAccountAuthority, - TAccountAuthorityPda, - TAccountPayer, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionAuthorityRecord, - TAccountNewCollectionUpdateAuthority, - TAccountNewCollectionMetadata, - TAccountNewCollectionMint, - TAccountNewCollectionMasterEdition, - TAccountNewCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram - > -): SetCollectionInstructionWithSigners< - TProgram, - TAccountCandyMachine, - TAccountAuthority, - TAccountAuthorityPda, - TAccountPayer, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionAuthorityRecord, - TAccountNewCollectionUpdateAuthority, - TAccountNewCollectionMetadata, - TAccountNewCollectionMint, - TAccountNewCollectionMasterEdition, - TAccountNewCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram ->; -export function getSetCollectionInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountAuthorityPda extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionUpdateAuthority extends string, - TAccountNewCollectionMetadata extends string, - TAccountNewCollectionMint extends string, - TAccountNewCollectionMasterEdition extends string, - TAccountNewCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( input: SetCollectionInput< TAccountCandyMachine, @@ -379,7 +213,7 @@ export function getSetCollectionInstruction< TAccountSystemProgram > ): SetCollectionInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority, TAccountAuthorityPda, @@ -394,66 +228,12 @@ export function getSetCollectionInstruction< TAccountNewCollectionAuthorityRecord, TAccountTokenMetadataProgram, TAccountSystemProgram ->; -export function getSetCollectionInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountAuthorityPda extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollectionMetadata extends string, - TAccountCollectionAuthorityRecord extends string, - TAccountNewCollectionUpdateAuthority extends string, - TAccountNewCollectionMetadata extends string, - TAccountNewCollectionMint extends string, - TAccountNewCollectionMasterEdition extends string, - TAccountNewCollectionAuthorityRecord extends string, - TAccountTokenMetadataProgram extends string, - TAccountSystemProgram extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: SetCollectionInput< - TAccountCandyMachine, - TAccountAuthority, - TAccountAuthorityPda, - TAccountPayer, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionAuthorityRecord, - TAccountNewCollectionUpdateAuthority, - TAccountNewCollectionMetadata, - TAccountNewCollectionMint, - TAccountNewCollectionMasterEdition, - TAccountNewCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSetCollectionInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthority, - TAccountAuthorityPda, - TAccountPayer, - TAccountCollectionMint, - TAccountCollectionMetadata, - TAccountCollectionAuthorityRecord, - TAccountNewCollectionUpdateAuthority, - TAccountNewCollectionMetadata, - TAccountNewCollectionMint, - TAccountNewCollectionMasterEdition, - TAccountNewCollectionAuthorityRecord, - TAccountTokenMetadataProgram, - TAccountSystemProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, authorityPda: { value: input.authorityPda ?? null, isWritable: true }, @@ -493,6 +273,10 @@ export function getSetCollectionInstruction< }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.tokenMetadataProgram.value) { @@ -504,143 +288,28 @@ export function getSetCollectionInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSetCollectionInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getSetCollectionInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountAuthorityPda extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountNewCollectionUpdateAuthority extends - | string - | IAccountMeta = string, - TAccountNewCollectionMetadata extends string | IAccountMeta = string, - TAccountNewCollectionMint extends string | IAccountMeta = string, - TAccountNewCollectionMasterEdition extends - | string - | IAccountMeta = string, - TAccountNewCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TAccountTokenMetadataProgram extends - | string - | IAccountMeta = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - authorityPda: TAccountAuthorityPda extends string - ? Address - : TAccountAuthorityPda; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collectionMetadata: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - collectionAuthorityRecord: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - newCollectionUpdateAuthority: TAccountNewCollectionUpdateAuthority extends string - ? Address - : TAccountNewCollectionUpdateAuthority; - newCollectionMetadata: TAccountNewCollectionMetadata extends string - ? Address - : TAccountNewCollectionMetadata; - newCollectionMint: TAccountNewCollectionMint extends string - ? Address - : TAccountNewCollectionMint; - newCollectionMasterEdition: TAccountNewCollectionMasterEdition extends string - ? Address - : TAccountNewCollectionMasterEdition; - newCollectionAuthorityRecord: TAccountNewCollectionAuthorityRecord extends string - ? Address - : TAccountNewCollectionAuthorityRecord; - tokenMetadataProgram?: TAccountTokenMetadataProgram extends string - ? Address - : TAccountTokenMetadataProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - }, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - accountMetaWithDefault(accounts.authorityPda, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.payer, AccountRole.READONLY_SIGNER), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collectionMetadata, AccountRole.READONLY), - accountMetaWithDefault( - accounts.collectionAuthorityRecord, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.newCollectionUpdateAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault( - accounts.newCollectionMetadata, - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.newCollectionMint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.newCollectionMasterEdition, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.newCollectionAuthorityRecord, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.tokenMetadataProgram ?? - ('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.authorityPda), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collectionMetadata), + getAccountMeta(accounts.collectionAuthorityRecord), + getAccountMeta(accounts.newCollectionUpdateAuthority), + getAccountMeta(accounts.newCollectionMetadata), + getAccountMeta(accounts.newCollectionMint), + getAccountMeta(accounts.newCollectionMasterEdition), + getAccountMeta(accounts.newCollectionAuthorityRecord), + getAccountMeta(accounts.tokenMetadataProgram), + getAccountMeta(accounts.systemProgram), ], - data: getSetCollectionInstructionDataEncoder().encode({}), programAddress, + data: getSetCollectionInstructionDataEncoder().encode({}), } as SetCollectionInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority, TAccountAuthorityPda, @@ -654,13 +323,14 @@ export function getSetCollectionInstructionRaw< TAccountNewCollectionMasterEdition, TAccountNewCollectionAuthorityRecord, TAccountTokenMetadataProgram, - TAccountSystemProgram, - TRemainingAccounts + TAccountSystemProgram >; + + return instruction; } export type ParsedSetCollectionInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/setCollectionSize.ts b/test/packages/js-experimental/src/generated/instructions/setCollectionSize.ts index b5bf30379..e6ef5a331 100644 --- a/test/packages/js-experimental/src/generated/instructions/setCollectionSize.ts +++ b/test/packages/js-experimental/src/generated/instructions/setCollectionSize.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { SetCollectionSizeArgs, SetCollectionSizeArgsArgs, @@ -42,43 +38,14 @@ import { } from '../types'; export type SetCollectionSizeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountCollectionMint extends string | IAccountMeta = string, TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCollectionMetadata extends string - ? WritableAccount - : TAccountCollectionMetadata, - TAccountCollectionAuthority extends string - ? WritableSignerAccount - : TAccountCollectionAuthority, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - ...TRemainingAccounts, - ] - >; - -export type SetCollectionSizeInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -137,27 +104,10 @@ export function getSetCollectionSizeInstructionDataCodec(): Codec< } export type SetCollectionSizeInput< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollectionAuthorityRecord extends string, -> = { - /** Collection Metadata account */ - collectionMetadata: Address; - /** Collection Update authority */ - collectionAuthority: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Collection Authority Record PDA */ - collectionAuthorityRecord?: Address; - setCollectionSizeArgs: SetCollectionSizeInstructionDataArgs['setCollectionSizeArgs']; -}; - -export type SetCollectionSizeInputWithSigners< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollectionAuthorityRecord extends string, + TAccountCollectionMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollectionAuthorityRecord extends string = string, > = { /** Collection Metadata account */ collectionMetadata: Address; @@ -175,27 +125,6 @@ export function getSetCollectionSizeInstruction< TAccountCollectionAuthority extends string, TAccountCollectionMint extends string, TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetCollectionSizeInputWithSigners< - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollectionAuthorityRecord - > -): SetCollectionSizeInstructionWithSigners< - TProgram, - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollectionAuthorityRecord ->; -export function getSetCollectionSizeInstruction< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: SetCollectionSizeInput< TAccountCollectionMetadata, @@ -204,41 +133,17 @@ export function getSetCollectionSizeInstruction< TAccountCollectionAuthorityRecord > ): SetCollectionSizeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionMetadata, TAccountCollectionAuthority, TAccountCollectionMint, TAccountCollectionAuthorityRecord ->; -export function getSetCollectionSizeInstruction< - TAccountCollectionMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetCollectionSizeInput< - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollectionAuthorityRecord - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSetCollectionSizeInstructionRaw< - TProgram, - TAccountCollectionMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollectionAuthorityRecord - > - >[0]; - const accounts: Record = { + const originalAccounts = { collectionMetadata: { value: input.collectionMetadata ?? null, isWritable: true, @@ -253,86 +158,39 @@ export function getSetCollectionSizeInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSetCollectionSizeInstructionRaw( - accountMetas as Record, - args as SetCollectionSizeInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getSetCollectionSizeInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountCollectionMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - collectionMetadata: TAccountCollectionMetadata extends string - ? Address - : TAccountCollectionMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collectionAuthorityRecord?: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - }, - args: SetCollectionSizeInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.collectionMetadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.collectionAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.collectionMetadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collectionAuthorityRecord), ], - data: getSetCollectionSizeInstructionDataEncoder().encode(args), programAddress, + data: getSetCollectionSizeInstructionDataEncoder().encode( + args as SetCollectionSizeInstructionDataArgs + ), } as SetCollectionSizeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountCollectionMetadata, TAccountCollectionAuthority, TAccountCollectionMint, - TAccountCollectionAuthorityRecord, - TRemainingAccounts + TAccountCollectionAuthorityRecord >; + + return instruction; } export type ParsedSetCollectionSizeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -369,7 +227,7 @@ export function parseSetCollectionSizeInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/setMintAuthority.ts b/test/packages/js-experimental/src/generated/instructions/setMintAuthority.ts index 4d38c2320..944bf3e76 100644 --- a/test/packages/js-experimental/src/generated/instructions/setMintAuthority.ts +++ b/test/packages/js-experimental/src/generated/instructions/setMintAuthority.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,41 +29,15 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type SetMintAuthorityInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - TAccountMintAuthority extends string - ? ReadonlySignerAccount - : TAccountMintAuthority, - ...TRemainingAccounts, - ] - >; - -export type SetMintAuthorityInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthority extends string | IAccountMeta = string, TAccountMintAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -117,19 +90,9 @@ export function getSetMintAuthorityInstructionDataCodec(): Codec< } export type SetMintAuthorityInput< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountMintAuthority extends string, -> = { - candyMachine: Address; - authority: Address; - mintAuthority: Address; -}; - -export type SetMintAuthorityInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountMintAuthority extends string, + TAccountCandyMachine extends string = string, + TAccountAuthority extends string = string, + TAccountMintAuthority extends string = string, > = { candyMachine: Address; authority: TransactionSigner; @@ -140,24 +103,6 @@ export function getSetMintAuthorityInstruction< TAccountCandyMachine extends string, TAccountAuthority extends string, TAccountMintAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: SetMintAuthorityInputWithSigners< - TAccountCandyMachine, - TAccountAuthority, - TAccountMintAuthority - > -): SetMintAuthorityInstructionWithSigners< - TProgram, - TAccountCandyMachine, - TAccountAuthority, - TAccountMintAuthority ->; -export function getSetMintAuthorityInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountMintAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( input: SetMintAuthorityInput< TAccountCandyMachine, @@ -165,101 +110,46 @@ export function getSetMintAuthorityInstruction< TAccountMintAuthority > ): SetMintAuthorityInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority, TAccountMintAuthority ->; -export function getSetMintAuthorityInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TAccountMintAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: SetMintAuthorityInput< - TAccountCandyMachine, - TAccountAuthority, - TAccountMintAuthority - > -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSetMintAuthorityInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthority, - TAccountMintAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, mintAuthority: { value: input.mintAuthority ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSetMintAuthorityInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getSetMintAuthorityInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TAccountMintAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - mintAuthority: TAccountMintAuthority extends string - ? Address - : TAccountMintAuthority; - }, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - accountMetaWithDefault( - accounts.mintAuthority, - AccountRole.READONLY_SIGNER - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.mintAuthority), ], - data: getSetMintAuthorityInstructionDataEncoder().encode({}), programAddress, + data: getSetMintAuthorityInstructionDataEncoder().encode({}), } as SetMintAuthorityInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority, - TAccountMintAuthority, - TRemainingAccounts + TAccountMintAuthority >; + + return instruction; } export type ParsedSetMintAuthorityInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/setTokenStandard.ts b/test/packages/js-experimental/src/generated/instructions/setTokenStandard.ts index 363fc8ffd..1e29a2717 100644 --- a/test/packages/js-experimental/src/generated/instructions/setTokenStandard.ts +++ b/test/packages/js-experimental/src/generated/instructions/setTokenStandard.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,46 +28,16 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type SetTokenStandardInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, TAccountEdition extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountUpdateAuthority extends string - ? WritableSignerAccount - : TAccountUpdateAuthority, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountEdition extends string - ? ReadonlyAccount - : TAccountEdition, - ...TRemainingAccounts, - ] - >; - -export type SetTokenStandardInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -116,26 +85,10 @@ export function getSetTokenStandardInstructionDataCodec(): Codec< } export type SetTokenStandardInput< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TAccountMint extends string, - TAccountEdition extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Metadata update authority */ - updateAuthority: Address; - /** Mint account */ - mint: Address; - /** Edition account */ - edition?: Address; -}; - -export type SetTokenStandardInputWithSigners< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TAccountMint extends string, - TAccountEdition extends string, + TAccountMetadata extends string = string, + TAccountUpdateAuthority extends string = string, + TAccountMint extends string = string, + TAccountEdition extends string = string, > = { /** Metadata account */ metadata: Address; @@ -152,27 +105,6 @@ export function getSetTokenStandardInstruction< TAccountUpdateAuthority extends string, TAccountMint extends string, TAccountEdition extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetTokenStandardInputWithSigners< - TAccountMetadata, - TAccountUpdateAuthority, - TAccountMint, - TAccountEdition - > -): SetTokenStandardInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountUpdateAuthority, - TAccountMint, - TAccountEdition ->; -export function getSetTokenStandardInstruction< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TAccountMint extends string, - TAccountEdition extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: SetTokenStandardInput< TAccountMetadata, @@ -181,117 +113,50 @@ export function getSetTokenStandardInstruction< TAccountEdition > ): SetTokenStandardInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountUpdateAuthority, TAccountMint, TAccountEdition ->; -export function getSetTokenStandardInstruction< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TAccountMint extends string, - TAccountEdition extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SetTokenStandardInput< - TAccountMetadata, - TAccountUpdateAuthority, - TAccountMint, - TAccountEdition - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSetTokenStandardInstructionRaw< - TProgram, - TAccountMetadata, - TAccountUpdateAuthority, - TAccountMint, - TAccountEdition - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, updateAuthority: { value: input.updateAuthority ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: false }, edition: { value: input.edition ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSetTokenStandardInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getSetTokenStandardInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - mint: TAccountMint extends string ? Address : TAccountMint; - edition?: TAccountEdition extends string - ? Address - : TAccountEdition; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.edition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.updateAuthority), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.edition), ], - data: getSetTokenStandardInstructionDataEncoder().encode({}), programAddress, + data: getSetTokenStandardInstructionDataEncoder().encode({}), } as SetTokenStandardInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountUpdateAuthority, TAccountMint, - TAccountEdition, - TRemainingAccounts + TAccountEdition >; + + return instruction; } export type ParsedSetTokenStandardInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -328,7 +193,7 @@ export function parseSetTokenStandardInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/signMetadata.ts b/test/packages/js-experimental/src/generated/instructions/signMetadata.ts index 260a9bc25..60e122ebb 100644 --- a/test/packages/js-experimental/src/generated/instructions/signMetadata.ts +++ b/test/packages/js-experimental/src/generated/instructions/signMetadata.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -28,36 +27,14 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type SignMetadataInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCreator extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCreator extends string - ? ReadonlySignerAccount - : TAccountCreator, - ...TRemainingAccounts, - ] - >; - -export type SignMetadataInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCreator extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -99,18 +76,8 @@ export function getSignMetadataInstructionDataCodec(): Codec< } export type SignMetadataInput< - TAccountMetadata extends string, - TAccountCreator extends string, -> = { - /** Metadata (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Creator */ - creator: Address; -}; - -export type SignMetadataInputWithSigners< - TAccountMetadata extends string, - TAccountCreator extends string, + TAccountMetadata extends string = string, + TAccountCreator extends string = string, > = { /** Metadata (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -121,93 +88,45 @@ export type SignMetadataInputWithSigners< export function getSignMetadataInstruction< TAccountMetadata extends string, TAccountCreator extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( - input: SignMetadataInputWithSigners -): SignMetadataInstructionWithSigners< - TProgram, + input: SignMetadataInput +): SignMetadataInstruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCreator ->; -export function getSignMetadataInstruction< - TAccountMetadata extends string, - TAccountCreator extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: SignMetadataInput -): SignMetadataInstruction; -export function getSignMetadataInstruction< - TAccountMetadata extends string, - TAccountCreator extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->(input: SignMetadataInput): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getSignMetadataInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCreator - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, creator: { value: input.creator ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getSignMetadataInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getSignMetadataInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCreator extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - creator: TAccountCreator extends string - ? Address - : TAccountCreator; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.creator, AccountRole.READONLY_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.creator), ], - data: getSignMetadataInstructionDataEncoder().encode({}), programAddress, + data: getSignMetadataInstructionDataEncoder().encode({}), } as SignMetadataInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, - TAccountCreator, - TRemainingAccounts + TAccountCreator >; + + return instruction; } export type ParsedSignMetadataInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/thawDelegatedAccount.ts b/test/packages/js-experimental/src/generated/instructions/thawDelegatedAccount.ts index 5c77a0761..933e6b968 100644 --- a/test/packages/js-experimental/src/generated/instructions/thawDelegatedAccount.ts +++ b/test/packages/js-experimental/src/generated/instructions/thawDelegatedAccount.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,47 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type ThawDelegatedAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegate extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountDelegate extends string - ? WritableSignerAccount - : TAccountDelegate, - TAccountTokenAccount extends string - ? WritableAccount - : TAccountTokenAccount, - TAccountEdition extends string - ? ReadonlyAccount - : TAccountEdition, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - ...TRemainingAccounts, - ] - >; - -export type ThawDelegatedAccountInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegate extends string | IAccountMeta = string, TAccountTokenAccount extends string | IAccountMeta = string, TAccountEdition extends string | IAccountMeta = string, @@ -77,7 +40,7 @@ export type ThawDelegatedAccountInstructionWithSigners< TAccountTokenProgram extends | string | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -128,30 +91,11 @@ export function getThawDelegatedAccountInstructionDataCodec(): Codec< } export type ThawDelegatedAccountInput< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, -> = { - /** Delegate */ - delegate: Address; - /** Token account to thaw */ - tokenAccount: Address; - /** Edition */ - edition: Address; - /** Token mint */ - mint: Address; - /** Token Program */ - tokenProgram?: Address; -}; - -export type ThawDelegatedAccountInputWithSigners< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, + TAccountDelegate extends string = string, + TAccountTokenAccount extends string = string, + TAccountEdition extends string = string, + TAccountMint extends string = string, + TAccountTokenProgram extends string = string, > = { /** Delegate */ delegate: TransactionSigner; @@ -171,30 +115,6 @@ export function getThawDelegatedAccountInstruction< TAccountEdition extends string, TAccountMint extends string, TAccountTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ThawDelegatedAccountInputWithSigners< - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram - > -): ThawDelegatedAccountInstructionWithSigners< - TProgram, - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram ->; -export function getThawDelegatedAccountInstruction< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: ThawDelegatedAccountInput< TAccountDelegate, @@ -204,51 +124,28 @@ export function getThawDelegatedAccountInstruction< TAccountTokenProgram > ): ThawDelegatedAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegate, TAccountTokenAccount, TAccountEdition, TAccountMint, TAccountTokenProgram ->; -export function getThawDelegatedAccountInstruction< - TAccountDelegate extends string, - TAccountTokenAccount extends string, - TAccountEdition extends string, - TAccountMint extends string, - TAccountTokenProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: ThawDelegatedAccountInput< - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getThawDelegatedAccountInstructionRaw< - TProgram, - TAccountDelegate, - TAccountTokenAccount, - TAccountEdition, - TAccountMint, - TAccountTokenProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { delegate: { value: input.delegate ?? null, isWritable: true }, tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, edition: { value: input.edition ?? null, isWritable: false }, mint: { value: input.mint ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Resolve default values. if (!accounts.tokenProgram.value) { @@ -256,78 +153,31 @@ export function getThawDelegatedAccountInstruction< 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getThawDelegatedAccountInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getThawDelegatedAccountInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountDelegate extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TRemainingAccounts extends Array> = [], ->( - accounts: { - delegate: TAccountDelegate extends string - ? Address - : TAccountDelegate; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - edition: TAccountEdition extends string - ? Address - : TAccountEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.delegate, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.edition, AccountRole.READONLY), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.delegate), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.edition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenProgram), ], - data: getThawDelegatedAccountInstructionDataEncoder().encode({}), programAddress, + data: getThawDelegatedAccountInstructionDataEncoder().encode({}), } as ThawDelegatedAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountDelegate, TAccountTokenAccount, TAccountEdition, TAccountMint, - TAccountTokenProgram, - TRemainingAccounts + TAccountTokenProgram >; + + return instruction; } export type ParsedThawDelegatedAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/transfer.ts b/test/packages/js-experimental/src/generated/instructions/transfer.ts index dbe6bd748..f5c5174c6 100644 --- a/test/packages/js-experimental/src/generated/instructions/transfer.ts +++ b/test/packages/js-experimental/src/generated/instructions/transfer.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; import { resolveMasterEditionFromTokenStandard } from '../../hooked'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { TokenStandard, TokenStandardArgs, @@ -45,88 +41,7 @@ import { } from '../types'; export type TransferInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountAuthority extends string | IAccountMeta = string, - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountTokenOwner extends string | IAccountMeta = string, - TAccountDestination extends string | IAccountMeta = string, - TAccountDestinationOwner extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSplAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountAuthority extends string - ? WritableSignerAccount - : TAccountAuthority, - TAccountDelegateRecord extends string - ? WritableAccount - : TAccountDelegateRecord, - TAccountToken extends string - ? WritableAccount - : TAccountToken, - TAccountTokenOwner extends string - ? ReadonlyAccount - : TAccountTokenOwner, - TAccountDestination extends string - ? WritableAccount - : TAccountDestination, - TAccountDestinationOwner extends string - ? ReadonlyAccount - : TAccountDestinationOwner, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? ReadonlyAccount - : TAccountMasterEdition, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - TAccountSplAtaProgram extends string - ? ReadonlyAccount - : TAccountSplAtaProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - ...TRemainingAccounts, - ] - >; - -export type TransferInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountAuthority extends string | IAccountMeta = string, TAccountDelegateRecord extends string | IAccountMeta = string, TAccountToken extends string | IAccountMeta = string, @@ -152,7 +67,7 @@ export type TransferInstructionWithSigners< | string | IAccountMeta = string, TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -246,72 +161,21 @@ export type TransferInstructionExtraArgs = { }; export type TransferAsyncInput< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, -> = { - /** Transfer authority (token or delegate owner) */ - authority: Address; - /** Delegate record PDA */ - delegateRecord?: Address; - /** Token account */ - token: Address; - /** Token account owner */ - tokenOwner: Address; - /** Destination token account */ - destination: Address; - /** Destination token account owner */ - destinationOwner: Address; - /** Mint of token asset */ - mint: Address; - /** Metadata (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Master Edition of token asset */ - masterEdition?: Address; - /** SPL Token Program */ - splTokenProgram?: Address; - /** SPL Associated Token Account program */ - splAtaProgram?: Address; - /** System Program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - transferArgs: TransferInstructionDataArgs['transferArgs']; - tokenStandard?: TransferInstructionExtraArgs['tokenStandard']; -}; - -export type TransferAsyncInputWithSigners< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, + TAccountAuthority extends string = string, + TAccountDelegateRecord extends string = string, + TAccountToken extends string = string, + TAccountTokenOwner extends string = string, + TAccountDestination extends string = string, + TAccountDestinationOwner extends string = string, + TAccountMint extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountSplAtaProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountAuthorizationRulesProgram extends string = string, + TAccountAuthorizationRules extends string = string, > = { /** Transfer authority (token or delegate owner) */ authority: TransactionSigner; @@ -363,62 +227,6 @@ export async function getTransferInstructionAsync< TAccountSysvarInstructions extends string, TAccountAuthorizationRulesProgram extends string, TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: TransferAsyncInputWithSigners< - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): Promise< - TransferInstructionWithSigners< - TProgram, - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > ->; -export async function getTransferInstructionAsync< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: TransferAsyncInput< TAccountAuthority, @@ -439,7 +247,7 @@ export async function getTransferInstructionAsync< > ): Promise< TransferInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountAuthority, TAccountDelegateRecord, TAccountToken, @@ -456,69 +264,12 @@ export async function getTransferInstructionAsync< TAccountAuthorizationRulesProgram, TAccountAuthorizationRules > ->; -export async function getTransferInstructionAsync< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: TransferAsyncInput< - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): Promise { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getTransferInstructionRaw< - TProgram, - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > - >[0]; - const accounts: Record = { + const originalAccounts = { authority: { value: input.authority ?? null, isWritable: true }, delegateRecord: { value: input.delegateRecord ?? null, isWritable: true }, token: { value: input.token ?? null, isWritable: true }, @@ -550,6 +301,10 @@ export async function getTransferInstructionAsync< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -584,89 +339,67 @@ export async function getTransferInstructionAsync< args.tokenStandard = TokenStandard.NonFungible; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getTransferInstructionRaw( - accountMetas as Record, - args as TransferInstructionDataArgs, - programAddress - ); + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.authority), + getAccountMeta(accounts.delegateRecord), + getAccountMeta(accounts.token), + getAccountMeta(accounts.tokenOwner), + getAccountMeta(accounts.destination), + getAccountMeta(accounts.destinationOwner), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.splAtaProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.authorizationRulesProgram), + getAccountMeta(accounts.authorizationRules), + ], + programAddress, + data: getTransferInstructionDataEncoder().encode( + args as TransferInstructionDataArgs + ), + } as TransferInstruction< + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, + TAccountAuthority, + TAccountDelegateRecord, + TAccountToken, + TAccountTokenOwner, + TAccountDestination, + TAccountDestinationOwner, + TAccountMint, + TAccountMetadata, + TAccountMasterEdition, + TAccountSplTokenProgram, + TAccountSplAtaProgram, + TAccountSystemProgram, + TAccountSysvarInstructions, + TAccountAuthorizationRulesProgram, + TAccountAuthorizationRules + >; return instruction; } export type TransferInput< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, -> = { - /** Transfer authority (token or delegate owner) */ - authority: Address; - /** Delegate record PDA */ - delegateRecord?: Address; - /** Token account */ - token: Address; - /** Token account owner */ - tokenOwner: Address; - /** Destination token account */ - destination: Address; - /** Destination token account owner */ - destinationOwner: Address; - /** Mint of token asset */ - mint: Address; - /** Metadata (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Master Edition of token asset */ - masterEdition?: Address; - /** SPL Token Program */ - splTokenProgram?: Address; - /** SPL Associated Token Account program */ - splAtaProgram?: Address; - /** System Program */ - systemProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - transferArgs: TransferInstructionDataArgs['transferArgs']; - tokenStandard?: TransferInstructionExtraArgs['tokenStandard']; -}; - -export type TransferInputWithSigners< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, + TAccountAuthority extends string = string, + TAccountDelegateRecord extends string = string, + TAccountToken extends string = string, + TAccountTokenOwner extends string = string, + TAccountDestination extends string = string, + TAccountDestinationOwner extends string = string, + TAccountMint extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountSplAtaProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountAuthorizationRulesProgram extends string = string, + TAccountAuthorizationRules extends string = string, > = { /** Transfer authority (token or delegate owner) */ authority: TransactionSigner; @@ -718,60 +451,6 @@ export function getTransferInstruction< TAccountSysvarInstructions extends string, TAccountAuthorizationRulesProgram extends string, TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: TransferInputWithSigners< - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): TransferInstructionWithSigners< - TProgram, - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules ->; -export function getTransferInstruction< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: TransferInput< TAccountAuthority, @@ -791,7 +470,7 @@ export function getTransferInstruction< TAccountAuthorizationRules > ): TransferInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountAuthority, TAccountDelegateRecord, TAccountToken, @@ -807,69 +486,12 @@ export function getTransferInstruction< TAccountSysvarInstructions, TAccountAuthorizationRulesProgram, TAccountAuthorizationRules ->; -export function getTransferInstruction< - TAccountAuthority extends string, - TAccountDelegateRecord extends string, - TAccountToken extends string, - TAccountTokenOwner extends string, - TAccountDestination extends string, - TAccountDestinationOwner extends string, - TAccountMint extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountSplTokenProgram extends string, - TAccountSplAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: TransferInput< - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getTransferInstructionRaw< - TProgram, - TAccountAuthority, - TAccountDelegateRecord, - TAccountToken, - TAccountTokenOwner, - TAccountDestination, - TAccountDestinationOwner, - TAccountMint, - TAccountMetadata, - TAccountMasterEdition, - TAccountSplTokenProgram, - TAccountSplAtaProgram, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > - >[0]; - const accounts: Record = { + const originalAccounts = { authority: { value: input.authority ?? null, isWritable: true }, delegateRecord: { value: input.delegateRecord ?? null, isWritable: true }, token: { value: input.token ?? null, isWritable: true }, @@ -901,6 +523,10 @@ export function getTransferInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -926,167 +552,31 @@ export function getTransferInstruction< args.tokenStandard = TokenStandard.NonFungible; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getTransferInstructionRaw( - accountMetas as Record, - args as TransferInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getTransferInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountAuthority extends string | IAccountMeta = string, - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TAccountTokenOwner extends string | IAccountMeta = string, - TAccountDestination extends string | IAccountMeta = string, - TAccountDestinationOwner extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSplAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - delegateRecord?: TAccountDelegateRecord extends string - ? Address - : TAccountDelegateRecord; - token: TAccountToken extends string - ? Address - : TAccountToken; - tokenOwner: TAccountTokenOwner extends string - ? Address - : TAccountTokenOwner; - destination: TAccountDestination extends string - ? Address - : TAccountDestination; - destinationOwner: TAccountDestinationOwner extends string - ? Address - : TAccountDestinationOwner; - mint: TAccountMint extends string ? Address : TAccountMint; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition?: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - splAtaProgram?: TAccountSplAtaProgram extends string - ? Address - : TAccountSplAtaProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - }, - args: TransferInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.authority, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.delegateRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.token, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.tokenOwner, AccountRole.READONLY), - accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.destinationOwner, AccountRole.READONLY), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEdition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.splAtaProgram ?? - ('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.delegateRecord), + getAccountMeta(accounts.token), + getAccountMeta(accounts.tokenOwner), + getAccountMeta(accounts.destination), + getAccountMeta(accounts.destinationOwner), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.splAtaProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.authorizationRulesProgram), + getAccountMeta(accounts.authorizationRules), ], - data: getTransferInstructionDataEncoder().encode(args), programAddress, + data: getTransferInstructionDataEncoder().encode( + args as TransferInstructionDataArgs + ), } as TransferInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountAuthority, TAccountDelegateRecord, TAccountToken, @@ -1101,13 +591,14 @@ export function getTransferInstructionRaw< TAccountSystemProgram, TAccountSysvarInstructions, TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules, - TRemainingAccounts + TAccountAuthorizationRules >; + + return instruction; } export type ParsedTransferInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -1166,7 +657,7 @@ export function parseTransferInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/transferOutOfEscrow.ts b/test/packages/js-experimental/src/generated/instructions/transferOutOfEscrow.ts index cf3689f01..63defe9db 100644 --- a/test/packages/js-experimental/src/generated/instructions/transferOutOfEscrow.ts +++ b/test/packages/js-experimental/src/generated/instructions/transferOutOfEscrow.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -32,14 +31,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type TransferOutOfEscrowInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -61,78 +57,7 @@ export type TransferOutOfEscrowInstruction< | string | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountEscrow extends string - ? ReadonlyAccount - : TAccountEscrow, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountAttributeMint extends string - ? ReadonlyAccount - : TAccountAttributeMint, - TAccountAttributeSrc extends string - ? WritableAccount - : TAccountAttributeSrc, - TAccountAttributeDst extends string - ? WritableAccount - : TAccountAttributeDst, - TAccountEscrowMint extends string - ? ReadonlyAccount - : TAccountEscrowMint, - TAccountEscrowAccount extends string - ? ReadonlyAccount - : TAccountEscrowAccount, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountAtaProgram extends string - ? ReadonlyAccount - : TAccountAtaProgram, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - ...TRemainingAccounts, - ] - >; - -export type TransferOutOfEscrowInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEscrow extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountAttributeMint extends string | IAccountMeta = string, - TAccountAttributeSrc extends string | IAccountMeta = string, - TAccountAttributeDst extends string | IAccountMeta = string, - TAccountEscrowMint extends string | IAccountMeta = string, - TAccountEscrowAccount extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -219,63 +144,19 @@ export function getTransferOutOfEscrowInstructionDataCodec(): Codec< } export type TransferOutOfEscrowInput< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountAttributeMint extends string, - TAccountAttributeSrc extends string, - TAccountAttributeDst extends string, - TAccountEscrowMint extends string, - TAccountEscrowAccount extends string, - TAccountSystemProgram extends string, - TAccountAtaProgram extends string, - TAccountTokenProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, -> = { - /** Escrow account */ - escrow: Address; - /** Metadata account */ - metadata: Address; - /** Wallet paying for the transaction and new account */ - payer: Address; - /** Mint account for the new attribute */ - attributeMint: Address; - /** Token account source for the new attribute */ - attributeSrc: Address; - /** Token account, owned by TM, destination for the new attribute */ - attributeDst: Address; - /** Mint account that the escrow is attached */ - escrowMint: Address; - /** Token account that holds the token the escrow is attached to */ - escrowAccount: Address; - /** System program */ - systemProgram?: Address; - /** Associated Token program */ - ataProgram?: Address; - /** Token program */ - tokenProgram?: Address; - /** Instructions sysvar account */ - sysvarInstructions?: Address; - /** Authority/creator of the escrow account */ - authority?: Address; - amount: TransferOutOfEscrowInstructionDataArgs['amount']; -}; - -export type TransferOutOfEscrowInputWithSigners< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountAttributeMint extends string, - TAccountAttributeSrc extends string, - TAccountAttributeDst extends string, - TAccountEscrowMint extends string, - TAccountEscrowAccount extends string, - TAccountSystemProgram extends string, - TAccountAtaProgram extends string, - TAccountTokenProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, + TAccountEscrow extends string = string, + TAccountMetadata extends string = string, + TAccountPayer extends string = string, + TAccountAttributeMint extends string = string, + TAccountAttributeSrc extends string = string, + TAccountAttributeDst extends string = string, + TAccountEscrowMint extends string = string, + TAccountEscrowAccount extends string = string, + TAccountSystemProgram extends string = string, + TAccountAtaProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountAuthority extends string = string, > = { /** Escrow account */ escrow: Address; @@ -320,54 +201,6 @@ export function getTransferOutOfEscrowInstruction< TAccountTokenProgram extends string, TAccountSysvarInstructions extends string, TAccountAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: TransferOutOfEscrowInputWithSigners< - TAccountEscrow, - TAccountMetadata, - TAccountPayer, - TAccountAttributeMint, - TAccountAttributeSrc, - TAccountAttributeDst, - TAccountEscrowMint, - TAccountEscrowAccount, - TAccountSystemProgram, - TAccountAtaProgram, - TAccountTokenProgram, - TAccountSysvarInstructions, - TAccountAuthority - > -): TransferOutOfEscrowInstructionWithSigners< - TProgram, - TAccountEscrow, - TAccountMetadata, - TAccountPayer, - TAccountAttributeMint, - TAccountAttributeSrc, - TAccountAttributeDst, - TAccountEscrowMint, - TAccountEscrowAccount, - TAccountSystemProgram, - TAccountAtaProgram, - TAccountTokenProgram, - TAccountSysvarInstructions, - TAccountAuthority ->; -export function getTransferOutOfEscrowInstruction< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountAttributeMint extends string, - TAccountAttributeSrc extends string, - TAccountAttributeDst extends string, - TAccountEscrowMint extends string, - TAccountEscrowAccount extends string, - TAccountSystemProgram extends string, - TAccountAtaProgram extends string, - TAccountTokenProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: TransferOutOfEscrowInput< TAccountEscrow, @@ -385,7 +218,7 @@ export function getTransferOutOfEscrowInstruction< TAccountAuthority > ): TransferOutOfEscrowInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow, TAccountMetadata, TAccountPayer, @@ -399,63 +232,12 @@ export function getTransferOutOfEscrowInstruction< TAccountTokenProgram, TAccountSysvarInstructions, TAccountAuthority ->; -export function getTransferOutOfEscrowInstruction< - TAccountEscrow extends string, - TAccountMetadata extends string, - TAccountPayer extends string, - TAccountAttributeMint extends string, - TAccountAttributeSrc extends string, - TAccountAttributeDst extends string, - TAccountEscrowMint extends string, - TAccountEscrowAccount extends string, - TAccountSystemProgram extends string, - TAccountAtaProgram extends string, - TAccountTokenProgram extends string, - TAccountSysvarInstructions extends string, - TAccountAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: TransferOutOfEscrowInput< - TAccountEscrow, - TAccountMetadata, - TAccountPayer, - TAccountAttributeMint, - TAccountAttributeSrc, - TAccountAttributeDst, - TAccountEscrowMint, - TAccountEscrowAccount, - TAccountSystemProgram, - TAccountAtaProgram, - TAccountTokenProgram, - TAccountSysvarInstructions, - TAccountAuthority - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getTransferOutOfEscrowInstructionRaw< - TProgram, - TAccountEscrow, - TAccountMetadata, - TAccountPayer, - TAccountAttributeMint, - TAccountAttributeSrc, - TAccountAttributeDst, - TAccountEscrowMint, - TAccountEscrowAccount, - TAccountSystemProgram, - TAccountAtaProgram, - TAccountTokenProgram, - TAccountSysvarInstructions, - TAccountAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { escrow: { value: input.escrow ?? null, isWritable: false }, metadata: { value: input.metadata ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, @@ -473,6 +255,10 @@ export function getTransferOutOfEscrowInstruction< }, authority: { value: input.authority ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -495,136 +281,29 @@ export function getTransferOutOfEscrowInstruction< 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getTransferOutOfEscrowInstructionRaw( - accountMetas as Record, - args as TransferOutOfEscrowInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getTransferOutOfEscrowInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountEscrow extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountAttributeMint extends string | IAccountMeta = string, - TAccountAttributeSrc extends string | IAccountMeta = string, - TAccountAttributeDst extends string | IAccountMeta = string, - TAccountEscrowMint extends string | IAccountMeta = string, - TAccountEscrowAccount extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - escrow: TAccountEscrow extends string - ? Address - : TAccountEscrow; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - attributeMint: TAccountAttributeMint extends string - ? Address - : TAccountAttributeMint; - attributeSrc: TAccountAttributeSrc extends string - ? Address - : TAccountAttributeSrc; - attributeDst: TAccountAttributeDst extends string - ? Address - : TAccountAttributeDst; - escrowMint: TAccountEscrowMint extends string - ? Address - : TAccountEscrowMint; - escrowAccount: TAccountEscrowAccount extends string - ? Address - : TAccountEscrowAccount; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - ataProgram?: TAccountAtaProgram extends string - ? Address - : TAccountAtaProgram; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - authority?: TAccountAuthority extends string - ? Address - : TAccountAuthority; - }, - args: TransferOutOfEscrowInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.escrow, AccountRole.READONLY), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.attributeMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.attributeSrc, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.attributeDst, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.escrowMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.escrowAccount, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.ataProgram ?? - ('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authority ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY_SIGNER - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.attributeMint), + getAccountMeta(accounts.attributeSrc), + getAccountMeta(accounts.attributeDst), + getAccountMeta(accounts.escrowMint), + getAccountMeta(accounts.escrowAccount), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.ataProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.authority), ], - data: getTransferOutOfEscrowInstructionDataEncoder().encode(args), programAddress, + data: getTransferOutOfEscrowInstructionDataEncoder().encode( + args as TransferOutOfEscrowInstructionDataArgs + ), } as TransferOutOfEscrowInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountEscrow, TAccountMetadata, TAccountPayer, @@ -637,13 +316,14 @@ export function getTransferOutOfEscrowInstructionRaw< TAccountAtaProgram, TAccountTokenProgram, TAccountSysvarInstructions, - TAccountAuthority, - TRemainingAccounts + TAccountAuthority >; + + return instruction; } export type ParsedTransferOutOfEscrowInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -698,7 +378,7 @@ export function parseTransferOutOfEscrowInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/transferSol.ts b/test/packages/js-experimental/src/generated/instructions/transferSol.ts index 806204e63..18b15f916 100644 --- a/test/packages/js-experimental/src/generated/instructions/transferSol.ts +++ b/test/packages/js-experimental/src/generated/instructions/transferSol.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,36 +29,14 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { SPL_SYSTEM_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type TransferSolInstruction< - TProgram extends string = '11111111111111111111111111111111', + TProgram extends string = typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountSource extends string | IAccountMeta = string, TAccountDestination extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountSource extends string - ? WritableSignerAccount - : TAccountSource, - TAccountDestination extends string - ? WritableAccount - : TAccountDestination, - ...TRemainingAccounts, - ] - >; - -export type TransferSolInstructionWithSigners< - TProgram extends string = '11111111111111111111111111111111', - TAccountSource extends string | IAccountMeta = string, - TAccountDestination extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -110,17 +87,8 @@ export function getTransferSolInstructionDataCodec(): Codec< } export type TransferSolInput< - TAccountSource extends string, - TAccountDestination extends string, -> = { - source: Address; - destination: Address; - amount: TransferSolInstructionDataArgs['amount']; -}; - -export type TransferSolInputWithSigners< - TAccountSource extends string, - TAccountDestination extends string, + TAccountSource extends string = string, + TAccountDestination extends string = string, > = { source: TransactionSigner; destination: Address; @@ -130,98 +98,50 @@ export type TransferSolInputWithSigners< export function getTransferSolInstruction< TAccountSource extends string, TAccountDestination extends string, - TProgram extends string = '11111111111111111111111111111111', >( - input: TransferSolInputWithSigners -): TransferSolInstructionWithSigners< - TProgram, + input: TransferSolInput +): TransferSolInstruction< + typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountSource, TAccountDestination ->; -export function getTransferSolInstruction< - TAccountSource extends string, - TAccountDestination extends string, - TProgram extends string = '11111111111111111111111111111111', ->( - input: TransferSolInput -): TransferSolInstruction; -export function getTransferSolInstruction< - TAccountSource extends string, - TAccountDestination extends string, - TProgram extends string = '11111111111111111111111111111111', ->(input: TransferSolInput): IInstruction { +> { // Program address. - const programAddress = - '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + const programAddress = SPL_SYSTEM_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getTransferSolInstructionRaw< - TProgram, - TAccountSource, - TAccountDestination - > - >[0]; - const accounts: Record = { + const originalAccounts = { source: { value: input.source ?? null, isWritable: true }, destination: { value: input.destination ?? null, isWritable: true }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getTransferSolInstructionRaw( - accountMetas as Record, - args as TransferSolInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getTransferSolInstructionRaw< - TProgram extends string = '11111111111111111111111111111111', - TAccountSource extends string | IAccountMeta = string, - TAccountDestination extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - source: TAccountSource extends string - ? Address - : TAccountSource; - destination: TAccountDestination extends string - ? Address - : TAccountDestination; - }, - args: TransferSolInstructionDataArgs, - programAddress: Address = '11111111111111111111111111111111' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.source, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.source), + getAccountMeta(accounts.destination), ], - data: getTransferSolInstructionDataEncoder().encode(args), programAddress, + data: getTransferSolInstructionDataEncoder().encode( + args as TransferSolInstructionDataArgs + ), } as TransferSolInstruction< - TProgram, + typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountSource, - TAccountDestination, - TRemainingAccounts + TAccountDestination >; + + return instruction; } export type ParsedTransferSolInstruction< - TProgram extends string = '11111111111111111111111111111111', + TProgram extends string = typeof SPL_SYSTEM_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/unverifyCollection.ts b/test/packages/js-experimental/src/generated/instructions/unverifyCollection.ts index 494b7ae7d..6c7abd24b 100644 --- a/test/packages/js-experimental/src/generated/instructions/unverifyCollection.ts +++ b/test/packages/js-experimental/src/generated/instructions/unverifyCollection.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,14 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type UnverifyCollectionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountCollectionMint extends string | IAccountMeta = string, @@ -47,46 +43,7 @@ export type UnverifyCollectionInstruction< TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCollectionAuthority extends string - ? WritableSignerAccount - : TAccountCollectionAuthority, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollection extends string - ? ReadonlyAccount - : TAccountCollection, - TAccountCollectionMasterEditionAccount extends string - ? ReadonlyAccount - : TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - ...TRemainingAccounts, - ] - >; - -export type UnverifyCollectionInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -140,34 +97,12 @@ export function getUnverifyCollectionInstructionDataCodec(): Codec< } export type UnverifyCollectionInput< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Collection Authority */ - collectionAuthority: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Metadata Account of the Collection */ - collection: Address; - /** MasterEdition2 Account of the Collection Token */ - collectionMasterEditionAccount: Address; - /** Collection Authority Record PDA */ - collectionAuthorityRecord?: Address; -}; - -export type UnverifyCollectionInputWithSigners< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, + TAccountMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollection extends string = string, + TAccountCollectionMasterEditionAccount extends string = string, + TAccountCollectionAuthorityRecord extends string = string, > = { /** Metadata account */ metadata: Address; @@ -190,33 +125,6 @@ export function getUnverifyCollectionInstruction< TAccountCollection extends string, TAccountCollectionMasterEditionAccount extends string, TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UnverifyCollectionInputWithSigners< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): UnverifyCollectionInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord ->; -export function getUnverifyCollectionInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UnverifyCollectionInput< TAccountMetadata, @@ -227,49 +135,19 @@ export function getUnverifyCollectionInstruction< TAccountCollectionAuthorityRecord > ): UnverifyCollectionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountCollectionMint, TAccountCollection, TAccountCollectionMasterEditionAccount, TAccountCollectionAuthorityRecord ->; -export function getUnverifyCollectionInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UnverifyCollectionInput< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUnverifyCollectionInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, collectionAuthority: { value: input.collectionAuthority ?? null, @@ -286,98 +164,38 @@ export function getUnverifyCollectionInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUnverifyCollectionInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getUnverifyCollectionInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collection: TAccountCollection extends string - ? Address - : TAccountCollection; - collectionMasterEditionAccount: TAccountCollectionMasterEditionAccount extends string - ? Address - : TAccountCollectionMasterEditionAccount; - collectionAuthorityRecord?: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collection, AccountRole.READONLY), - accountMetaWithDefault( - accounts.collectionMasterEditionAccount, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collection), + getAccountMeta(accounts.collectionMasterEditionAccount), + getAccountMeta(accounts.collectionAuthorityRecord), ], - data: getUnverifyCollectionInstructionDataEncoder().encode({}), programAddress, + data: getUnverifyCollectionInstructionDataEncoder().encode({}), } as UnverifyCollectionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountCollectionMint, TAccountCollection, TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord, - TRemainingAccounts + TAccountCollectionAuthorityRecord >; + + return instruction; } export type ParsedUnverifyCollectionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -418,7 +236,7 @@ export function parseUnverifyCollectionInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/unverifySizedCollectionItem.ts b/test/packages/js-experimental/src/generated/instructions/unverifySizedCollectionItem.ts index 5f567393c..d067f14c4 100644 --- a/test/packages/js-experimental/src/generated/instructions/unverifySizedCollectionItem.ts +++ b/test/packages/js-experimental/src/generated/instructions/unverifySizedCollectionItem.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,14 +29,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type UnverifySizedCollectionItemInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -49,50 +45,7 @@ export type UnverifySizedCollectionItemInstruction< TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCollectionAuthority extends string - ? ReadonlySignerAccount - : TAccountCollectionAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollection extends string - ? WritableAccount - : TAccountCollection, - TAccountCollectionMasterEditionAccount extends string - ? ReadonlyAccount - : TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - ...TRemainingAccounts, - ] - >; - -export type UnverifySizedCollectionItemInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -152,38 +105,13 @@ export function getUnverifySizedCollectionItemInstructionDataCodec(): Codec< } export type UnverifySizedCollectionItemInput< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Collection Authority */ - collectionAuthority: Address; - /** payer */ - payer: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Metadata Account of the Collection */ - collection: Address; - /** MasterEdition2 Account of the Collection Token */ - collectionMasterEditionAccount: Address; - /** Collection Authority Record PDA */ - collectionAuthorityRecord?: Address; -}; - -export type UnverifySizedCollectionItemInputWithSigners< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, + TAccountMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountPayer extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollection extends string = string, + TAccountCollectionMasterEditionAccount extends string = string, + TAccountCollectionAuthorityRecord extends string = string, > = { /** Metadata account */ metadata: Address; @@ -209,36 +137,6 @@ export function getUnverifySizedCollectionItemInstruction< TAccountCollection extends string, TAccountCollectionMasterEditionAccount extends string, TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UnverifySizedCollectionItemInputWithSigners< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): UnverifySizedCollectionItemInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord ->; -export function getUnverifySizedCollectionItemInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UnverifySizedCollectionItemInput< TAccountMetadata, @@ -250,7 +148,7 @@ export function getUnverifySizedCollectionItemInstruction< TAccountCollectionAuthorityRecord > ): UnverifySizedCollectionItemInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, @@ -258,45 +156,12 @@ export function getUnverifySizedCollectionItemInstruction< TAccountCollection, TAccountCollectionMasterEditionAccount, TAccountCollectionAuthorityRecord ->; -export function getUnverifySizedCollectionItemInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UnverifySizedCollectionItemInput< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUnverifySizedCollectionItemInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, collectionAuthority: { value: input.collectionAuthority ?? null, @@ -314,104 +179,40 @@ export function getUnverifySizedCollectionItemInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUnverifySizedCollectionItemInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getUnverifySizedCollectionItemInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collection: TAccountCollection extends string - ? Address - : TAccountCollection; - collectionMasterEditionAccount: TAccountCollectionMasterEditionAccount extends string - ? Address - : TAccountCollectionMasterEditionAccount; - collectionAuthorityRecord?: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collection, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionMasterEditionAccount, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collection), + getAccountMeta(accounts.collectionMasterEditionAccount), + getAccountMeta(accounts.collectionAuthorityRecord), ], - data: getUnverifySizedCollectionItemInstructionDataEncoder().encode({}), programAddress, + data: getUnverifySizedCollectionItemInstructionDataEncoder().encode({}), } as UnverifySizedCollectionItemInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, TAccountCollectionMint, TAccountCollection, TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord, - TRemainingAccounts + TAccountCollectionAuthorityRecord >; + + return instruction; } export type ParsedUnverifySizedCollectionItemInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -454,7 +255,7 @@ export function parseUnverifySizedCollectionItemInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/updateCandyMachine.ts b/test/packages/js-experimental/src/generated/instructions/updateCandyMachine.ts index 687fbfc9c..6d689315d 100644 --- a/test/packages/js-experimental/src/generated/instructions/updateCandyMachine.ts +++ b/test/packages/js-experimental/src/generated/instructions/updateCandyMachine.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,11 +29,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { CandyMachineData, CandyMachineDataArgs, @@ -43,29 +39,10 @@ import { } from '../types'; export type UpdateCandyMachineInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - ...TRemainingAccounts, - ] - >; - -export type UpdateCandyMachineInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -121,17 +98,8 @@ export function getUpdateCandyMachineInstructionDataCodec(): Codec< } export type UpdateCandyMachineInput< - TAccountCandyMachine extends string, - TAccountAuthority extends string, -> = { - candyMachine: Address; - authority: Address; - data: UpdateCandyMachineInstructionDataArgs['data']; -}; - -export type UpdateCandyMachineInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthority extends string, + TAccountCandyMachine extends string = string, + TAccountAuthority extends string = string, > = { candyMachine: Address; authority: TransactionSigner; @@ -141,107 +109,50 @@ export type UpdateCandyMachineInputWithSigners< export function getUpdateCandyMachineInstruction< TAccountCandyMachine extends string, TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: UpdateCandyMachineInputWithSigners< - TAccountCandyMachine, - TAccountAuthority - > -): UpdateCandyMachineInstructionWithSigners< - TProgram, - TAccountCandyMachine, - TAccountAuthority ->; -export function getUpdateCandyMachineInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( input: UpdateCandyMachineInput ): UpdateCandyMachineInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority ->; -export function getUpdateCandyMachineInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: UpdateCandyMachineInput -): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUpdateCandyMachineInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUpdateCandyMachineInstructionRaw( - accountMetas as Record, - args as UpdateCandyMachineInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getUpdateCandyMachineInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - }, - args: UpdateCandyMachineInstructionDataArgs, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authority), ], - data: getUpdateCandyMachineInstructionDataEncoder().encode(args), programAddress, + data: getUpdateCandyMachineInstructionDataEncoder().encode( + args as UpdateCandyMachineInstructionDataArgs + ), } as UpdateCandyMachineInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, - TAccountAuthority, - TRemainingAccounts + TAccountAuthority >; + + return instruction; } export type ParsedUpdateCandyMachineInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/updateMetadataAccount.ts b/test/packages/js-experimental/src/generated/instructions/updateMetadataAccount.ts index 68cbb701c..03c83b723 100644 --- a/test/packages/js-experimental/src/generated/instructions/updateMetadataAccount.ts +++ b/test/packages/js-experimental/src/generated/instructions/updateMetadataAccount.ts @@ -35,7 +35,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -44,11 +43,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { Creator, CreatorArgs, @@ -57,29 +53,10 @@ import { } from '../types'; export type UpdateMetadataAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - ...TRemainingAccounts, - ] - >; - -export type UpdateMetadataAccountInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -177,21 +154,8 @@ export function getUpdateMetadataAccountInstructionDataCodec(): Codec< } export type UpdateMetadataAccountInput< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Update authority key */ - updateAuthority: Address; - data: UpdateMetadataAccountInstructionDataArgs['data']; - updateAuthorityArg: UpdateMetadataAccountInstructionDataArgs['updateAuthority']; - primarySaleHappened: UpdateMetadataAccountInstructionDataArgs['primarySaleHappened']; -}; - -export type UpdateMetadataAccountInputWithSigners< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, + TAccountMetadata extends string = string, + TAccountUpdateAuthority extends string = string, > = { /** Metadata account */ metadata: Address; @@ -205,113 +169,53 @@ export type UpdateMetadataAccountInputWithSigners< export function getUpdateMetadataAccountInstruction< TAccountMetadata extends string, TAccountUpdateAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdateMetadataAccountInputWithSigners< - TAccountMetadata, - TAccountUpdateAuthority - > -): UpdateMetadataAccountInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountUpdateAuthority ->; -export function getUpdateMetadataAccountInstruction< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UpdateMetadataAccountInput ): UpdateMetadataAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountUpdateAuthority ->; -export function getUpdateMetadataAccountInstruction< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdateMetadataAccountInput -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUpdateMetadataAccountInstructionRaw< - TProgram, - TAccountMetadata, - TAccountUpdateAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, updateAuthority: { value: input.updateAuthority ?? null, isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input, updateAuthority: input.updateAuthorityArg }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUpdateMetadataAccountInstructionRaw( - accountMetas as Record, - args as UpdateMetadataAccountInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getUpdateMetadataAccountInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - }, - args: UpdateMetadataAccountInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.updateAuthority), ], - data: getUpdateMetadataAccountInstructionDataEncoder().encode(args), programAddress, + data: getUpdateMetadataAccountInstructionDataEncoder().encode( + args as UpdateMetadataAccountInstructionDataArgs + ), } as UpdateMetadataAccountInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, - TAccountUpdateAuthority, - TRemainingAccounts + TAccountUpdateAuthority >; + + return instruction; } export type ParsedUpdateMetadataAccountInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/updateMetadataAccountV2.ts b/test/packages/js-experimental/src/generated/instructions/updateMetadataAccountV2.ts index 4b1479511..486173a32 100644 --- a/test/packages/js-experimental/src/generated/instructions/updateMetadataAccountV2.ts +++ b/test/packages/js-experimental/src/generated/instructions/updateMetadataAccountV2.ts @@ -29,7 +29,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -38,11 +37,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { DataV2, DataV2Args, @@ -51,29 +47,10 @@ import { } from '../types'; export type UpdateMetadataAccountV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountUpdateAuthority extends string - ? ReadonlySignerAccount - : TAccountUpdateAuthority, - ...TRemainingAccounts, - ] - >; - -export type UpdateMetadataAccountV2InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountUpdateAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -138,22 +115,8 @@ export function getUpdateMetadataAccountV2InstructionDataCodec(): Codec< } export type UpdateMetadataAccountV2Input< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Update authority key */ - updateAuthority: Address; - data: UpdateMetadataAccountV2InstructionDataArgs['data']; - updateAuthorityArg: UpdateMetadataAccountV2InstructionDataArgs['updateAuthority']; - primarySaleHappened: UpdateMetadataAccountV2InstructionDataArgs['primarySaleHappened']; - isMutable: UpdateMetadataAccountV2InstructionDataArgs['isMutable']; -}; - -export type UpdateMetadataAccountV2InputWithSigners< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, + TAccountMetadata extends string = string, + TAccountUpdateAuthority extends string = string, > = { /** Metadata account */ metadata: Address; @@ -168,113 +131,53 @@ export type UpdateMetadataAccountV2InputWithSigners< export function getUpdateMetadataAccountV2Instruction< TAccountMetadata extends string, TAccountUpdateAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdateMetadataAccountV2InputWithSigners< - TAccountMetadata, - TAccountUpdateAuthority - > -): UpdateMetadataAccountV2InstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountUpdateAuthority ->; -export function getUpdateMetadataAccountV2Instruction< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UpdateMetadataAccountV2Input ): UpdateMetadataAccountV2Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountUpdateAuthority ->; -export function getUpdateMetadataAccountV2Instruction< - TAccountMetadata extends string, - TAccountUpdateAuthority extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdateMetadataAccountV2Input -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUpdateMetadataAccountV2InstructionRaw< - TProgram, - TAccountMetadata, - TAccountUpdateAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, updateAuthority: { value: input.updateAuthority ?? null, isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input, updateAuthority: input.updateAuthorityArg }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUpdateMetadataAccountV2InstructionRaw( - accountMetas as Record, - args as UpdateMetadataAccountV2InstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getUpdateMetadataAccountV2InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountUpdateAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - updateAuthority: TAccountUpdateAuthority extends string - ? Address - : TAccountUpdateAuthority; - }, - args: UpdateMetadataAccountV2InstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.updateAuthority, - AccountRole.READONLY_SIGNER - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.updateAuthority), ], - data: getUpdateMetadataAccountV2InstructionDataEncoder().encode(args), programAddress, + data: getUpdateMetadataAccountV2InstructionDataEncoder().encode( + args as UpdateMetadataAccountV2InstructionDataArgs + ), } as UpdateMetadataAccountV2Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, - TAccountUpdateAuthority, - TRemainingAccounts + TAccountUpdateAuthority >; + + return instruction; } export type ParsedUpdateMetadataAccountV2Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/updatePrimarySaleHappenedViaToken.ts b/test/packages/js-experimental/src/generated/instructions/updatePrimarySaleHappenedViaToken.ts index 8a3feff21..8003dafcc 100644 --- a/test/packages/js-experimental/src/generated/instructions/updatePrimarySaleHappenedViaToken.ts +++ b/test/packages/js-experimental/src/generated/instructions/updatePrimarySaleHappenedViaToken.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,41 +28,15 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type UpdatePrimarySaleHappenedViaTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountOwner extends string - ? ReadonlySignerAccount - : TAccountOwner, - TAccountToken extends string - ? ReadonlyAccount - : TAccountToken, - ...TRemainingAccounts, - ] - >; - -export type UpdatePrimarySaleHappenedViaTokenInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TAccountToken extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -110,22 +83,9 @@ export function getUpdatePrimarySaleHappenedViaTokenInstructionDataCodec(): Code } export type UpdatePrimarySaleHappenedViaTokenInput< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountToken extends string, -> = { - /** Metadata key (pda of ['metadata', program id, mint id]) */ - metadata: Address; - /** Owner on the token account */ - owner: Address; - /** Account containing tokens from the metadata's mint */ - token: Address; -}; - -export type UpdatePrimarySaleHappenedViaTokenInputWithSigners< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountToken extends string, + TAccountMetadata extends string = string, + TAccountOwner extends string = string, + TAccountToken extends string = string, > = { /** Metadata key (pda of ['metadata', program id, mint id]) */ metadata: Address; @@ -139,24 +99,6 @@ export function getUpdatePrimarySaleHappenedViaTokenInstruction< TAccountMetadata extends string, TAccountOwner extends string, TAccountToken extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdatePrimarySaleHappenedViaTokenInputWithSigners< - TAccountMetadata, - TAccountOwner, - TAccountToken - > -): UpdatePrimarySaleHappenedViaTokenInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountToken ->; -export function getUpdatePrimarySaleHappenedViaTokenInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountToken extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UpdatePrimarySaleHappenedViaTokenInput< TAccountMetadata, @@ -164,100 +106,48 @@ export function getUpdatePrimarySaleHappenedViaTokenInstruction< TAccountToken > ): UpdatePrimarySaleHappenedViaTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, TAccountToken ->; -export function getUpdatePrimarySaleHappenedViaTokenInstruction< - TAccountMetadata extends string, - TAccountOwner extends string, - TAccountToken extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdatePrimarySaleHappenedViaTokenInput< - TAccountMetadata, - TAccountOwner, - TAccountToken - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUpdatePrimarySaleHappenedViaTokenInstructionRaw< - TProgram, - TAccountMetadata, - TAccountOwner, - TAccountToken - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, owner: { value: input.owner ?? null, isWritable: false }, token: { value: input.token ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUpdatePrimarySaleHappenedViaTokenInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getUpdatePrimarySaleHappenedViaTokenInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountToken extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - token: TAccountToken extends string - ? Address - : TAccountToken; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.owner, AccountRole.READONLY_SIGNER), - accountMetaWithDefault(accounts.token, AccountRole.READONLY), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.token), ], + programAddress, data: getUpdatePrimarySaleHappenedViaTokenInstructionDataEncoder().encode( {} ), - programAddress, } as UpdatePrimarySaleHappenedViaTokenInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountOwner, - TAccountToken, - TRemainingAccounts + TAccountToken >; + + return instruction; } export type ParsedUpdatePrimarySaleHappenedViaTokenInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/updateV1.ts b/test/packages/js-experimental/src/generated/instructions/updateV1.ts index 329678658..9ceab35ed 100644 --- a/test/packages/js-experimental/src/generated/instructions/updateV1.ts +++ b/test/packages/js-experimental/src/generated/instructions/updateV1.ts @@ -36,7 +36,6 @@ import { some, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -46,11 +45,8 @@ import { WritableAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { AuthorityType, AuthorityTypeArgs, @@ -91,64 +87,7 @@ import { } from '../types'; export type UpdateV1Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountToken extends string | IAccountMeta = string, - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountAuthority extends string - ? ReadonlySignerAccount - : TAccountAuthority, - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountMasterEdition extends string - ? WritableAccount - : TAccountMasterEdition, - TAccountMint extends string - ? ReadonlyAccount - : TAccountMint, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountSysvarInstructions extends string - ? ReadonlyAccount - : TAccountSysvarInstructions, - TAccountToken extends string - ? ReadonlyAccount - : TAccountToken, - TAccountDelegateRecord extends string - ? ReadonlyAccount - : TAccountDelegateRecord, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - ...TRemainingAccounts, - ] - >; - -export type UpdateV1InstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountAuthority extends string | IAccountMeta = string, TAccountMetadata extends string | IAccountMeta = string, TAccountMasterEdition extends string | IAccountMeta = string, @@ -165,7 +104,7 @@ export type UpdateV1InstructionWithSigners< | string | IAccountMeta = string, TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -331,62 +270,16 @@ export function getUpdateV1InstructionDataCodec(): Codec< } export type UpdateV1Input< - TAccountAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountToken extends string, - TAccountDelegateRecord extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, -> = { - /** Update authority or delegate */ - authority: Address; - /** Metadata account */ - metadata: Address; - /** Master Edition account */ - masterEdition?: Address; - /** Mint account */ - mint: Address; - /** System program */ - systemProgram?: Address; - /** System program */ - sysvarInstructions?: Address; - /** Token account */ - token?: Address; - /** Delegate record PDA */ - delegateRecord?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - authorizationData: UpdateV1InstructionDataArgs['authorizationData']; - newUpdateAuthority: UpdateV1InstructionDataArgs['newUpdateAuthority']; - data: UpdateV1InstructionDataArgs['data']; - primarySaleHappened: UpdateV1InstructionDataArgs['primarySaleHappened']; - isMutable: UpdateV1InstructionDataArgs['isMutable']; - tokenStandard?: UpdateV1InstructionDataArgs['tokenStandard']; - collection: UpdateV1InstructionDataArgs['collection']; - uses: UpdateV1InstructionDataArgs['uses']; - collectionDetails: UpdateV1InstructionDataArgs['collectionDetails']; - programmableConfig: UpdateV1InstructionDataArgs['programmableConfig']; - delegateState: UpdateV1InstructionDataArgs['delegateState']; - authorityType: UpdateV1InstructionDataArgs['authorityType']; -}; - -export type UpdateV1InputWithSigners< - TAccountAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountToken extends string, - TAccountDelegateRecord extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, + TAccountAuthority extends string = string, + TAccountMetadata extends string = string, + TAccountMasterEdition extends string = string, + TAccountMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountSysvarInstructions extends string = string, + TAccountToken extends string = string, + TAccountDelegateRecord extends string = string, + TAccountAuthorizationRulesProgram extends string = string, + TAccountAuthorizationRules extends string = string, > = { /** Update authority or delegate */ authority: TransactionSigner; @@ -433,45 +326,6 @@ export function getUpdateV1Instruction< TAccountDelegateRecord extends string, TAccountAuthorizationRulesProgram extends string, TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdateV1InputWithSigners< - TAccountAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountToken, - TAccountDelegateRecord, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): UpdateV1InstructionWithSigners< - TProgram, - TAccountAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountToken, - TAccountDelegateRecord, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules ->; -export function getUpdateV1Instruction< - TAccountAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountToken extends string, - TAccountDelegateRecord extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UpdateV1Input< TAccountAuthority, @@ -486,7 +340,7 @@ export function getUpdateV1Instruction< TAccountAuthorizationRules > ): UpdateV1Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountAuthority, TAccountMetadata, TAccountMasterEdition, @@ -497,54 +351,12 @@ export function getUpdateV1Instruction< TAccountDelegateRecord, TAccountAuthorizationRulesProgram, TAccountAuthorizationRules ->; -export function getUpdateV1Instruction< - TAccountAuthority extends string, - TAccountMetadata extends string, - TAccountMasterEdition extends string, - TAccountMint extends string, - TAccountSystemProgram extends string, - TAccountSysvarInstructions extends string, - TAccountToken extends string, - TAccountDelegateRecord extends string, - TAccountAuthorizationRulesProgram extends string, - TAccountAuthorizationRules extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UpdateV1Input< - TAccountAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountToken, - TAccountDelegateRecord, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUpdateV1InstructionRaw< - TProgram, - TAccountAuthority, - TAccountMetadata, - TAccountMasterEdition, - TAccountMint, - TAccountSystemProgram, - TAccountSysvarInstructions, - TAccountToken, - TAccountDelegateRecord, - TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules - > - >[0]; - const accounts: Record = { + const originalAccounts = { authority: { value: input.authority ?? null, isWritable: false }, metadata: { value: input.metadata ?? null, isWritable: true }, masterEdition: { value: input.masterEdition ?? null, isWritable: true }, @@ -565,6 +377,10 @@ export function getUpdateV1Instruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -579,137 +395,26 @@ export function getUpdateV1Instruction< 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUpdateV1InstructionRaw( - accountMetas as Record, - args as UpdateV1InstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getUpdateV1InstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountAuthority extends string | IAccountMeta = string, - TAccountMetadata extends string | IAccountMeta = string, - TAccountMasterEdition extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountSysvarInstructions extends - | string - | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', - TAccountToken extends string | IAccountMeta = string, - TAccountDelegateRecord extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - masterEdition?: TAccountMasterEdition extends string - ? Address - : TAccountMasterEdition; - mint: TAccountMint extends string ? Address : TAccountMint; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - sysvarInstructions?: TAccountSysvarInstructions extends string - ? Address - : TAccountSysvarInstructions; - token?: TAccountToken extends string - ? Address - : TAccountToken; - delegateRecord?: TAccountDelegateRecord extends string - ? Address - : TAccountDelegateRecord; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - }, - args: UpdateV1InstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.authority, AccountRole.READONLY_SIGNER), - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.masterEdition ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault(accounts.mint, AccountRole.READONLY), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.sysvarInstructions ?? - ('Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.token ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.delegateRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.authority), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.masterEdition), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.sysvarInstructions), + getAccountMeta(accounts.token), + getAccountMeta(accounts.delegateRecord), + getAccountMeta(accounts.authorizationRulesProgram), + getAccountMeta(accounts.authorizationRules), ], - data: getUpdateV1InstructionDataEncoder().encode(args), programAddress, + data: getUpdateV1InstructionDataEncoder().encode( + args as UpdateV1InstructionDataArgs + ), } as UpdateV1Instruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountAuthority, TAccountMetadata, TAccountMasterEdition, @@ -719,13 +424,14 @@ export function getUpdateV1InstructionRaw< TAccountToken, TAccountDelegateRecord, TAccountAuthorizationRulesProgram, - TAccountAuthorizationRules, - TRemainingAccounts + TAccountAuthorizationRules >; + + return instruction; } export type ParsedUpdateV1Instruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -774,7 +480,7 @@ export function parseUpdateV1Instruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/useAsset.ts b/test/packages/js-experimental/src/generated/instructions/useAsset.ts index 7cdde7666..71e9c1c04 100644 --- a/test/packages/js-experimental/src/generated/instructions/useAsset.ts +++ b/test/packages/js-experimental/src/generated/instructions/useAsset.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { UseAssetArgs, UseAssetArgsArgs, @@ -42,70 +38,7 @@ import { } from '../types'; export type UseAssetInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUseAuthority extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountTokenAccount extends string - ? WritableAccount - : TAccountTokenAccount, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountUseAuthority extends string - ? WritableSignerAccount - : TAccountUseAuthority, - TAccountOwner extends string - ? ReadonlyAccount - : TAccountOwner, - TAccountSplTokenProgram extends string - ? ReadonlyAccount - : TAccountSplTokenProgram, - TAccountAtaProgram extends string - ? ReadonlyAccount - : TAccountAtaProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountUseAuthorityRecord extends string - ? WritableAccount - : TAccountUseAuthorityRecord, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - ...TRemainingAccounts, - ] - >; - -export type UseAssetInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountTokenAccount extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -125,7 +58,7 @@ export type UseAssetInstructionWithSigners< TAccountAuthorizationRulesProgram extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -203,55 +136,17 @@ export function getUseAssetInstructionDataCodec(): Codec< } export type UseAssetInput< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountSplTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountUseAuthorityRecord extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Token Account Of NFT */ - tokenAccount: Address; - /** Mint of the Metadata */ - mint: Address; - /** Use authority or current owner of the asset */ - useAuthority: Address; - /** Owner */ - owner: Address; - /** SPL Token program */ - splTokenProgram?: Address; - /** Associated Token program */ - ataProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Use Authority Record PDA (if present the program assumes a delegated use authority) */ - useAuthorityRecord?: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - useAssetArgs: UseAssetInstructionDataArgs['useAssetArgs']; -}; - -export type UseAssetInputWithSigners< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountSplTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountUseAuthorityRecord extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, + TAccountMetadata extends string = string, + TAccountTokenAccount extends string = string, + TAccountMint extends string = string, + TAccountUseAuthority extends string = string, + TAccountOwner extends string = string, + TAccountSplTokenProgram extends string = string, + TAccountAtaProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountUseAuthorityRecord extends string = string, + TAccountAuthorizationRules extends string = string, + TAccountAuthorizationRulesProgram extends string = string, > = { /** Metadata account */ metadata: Address; @@ -290,48 +185,6 @@ export function getUseAssetInstruction< TAccountUseAuthorityRecord extends string, TAccountAuthorizationRules extends string, TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UseAssetInputWithSigners< - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountSplTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountUseAuthorityRecord, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > -): UseAssetInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountSplTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountUseAuthorityRecord, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram ->; -export function getUseAssetInstruction< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountSplTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountUseAuthorityRecord extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UseAssetInput< TAccountMetadata, @@ -347,7 +200,7 @@ export function getUseAssetInstruction< TAccountAuthorizationRulesProgram > ): UseAssetInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountTokenAccount, TAccountMint, @@ -359,57 +212,12 @@ export function getUseAssetInstruction< TAccountUseAuthorityRecord, TAccountAuthorizationRules, TAccountAuthorizationRulesProgram ->; -export function getUseAssetInstruction< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountSplTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountUseAuthorityRecord extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UseAssetInput< - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountSplTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountUseAuthorityRecord, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUseAssetInstructionRaw< - TProgram, - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountSplTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountUseAuthorityRecord, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, @@ -434,6 +242,10 @@ export function getUseAssetInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -452,137 +264,27 @@ export function getUseAssetInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUseAssetInstructionRaw( - accountMetas as Record, - args as UseAssetInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getUseAssetInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUseAuthority extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountSplTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - mint: TAccountMint extends string ? Address : TAccountMint; - useAuthority: TAccountUseAuthority extends string - ? Address - : TAccountUseAuthority; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - splTokenProgram?: TAccountSplTokenProgram extends string - ? Address - : TAccountSplTokenProgram; - ataProgram?: TAccountAtaProgram extends string - ? Address - : TAccountAtaProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - useAuthorityRecord?: TAccountUseAuthorityRecord extends string - ? Address - : TAccountUseAuthorityRecord; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - }, - args: UseAssetInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.useAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.owner, AccountRole.READONLY), - accountMetaWithDefault( - accounts.splTokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.ataProgram ?? - ('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.useAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.useAuthority), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.splTokenProgram), + getAccountMeta(accounts.ataProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.useAuthorityRecord), + getAccountMeta(accounts.authorizationRules), + getAccountMeta(accounts.authorizationRulesProgram), ], - data: getUseAssetInstructionDataEncoder().encode(args), programAddress, + data: getUseAssetInstructionDataEncoder().encode( + args as UseAssetInstructionDataArgs + ), } as UseAssetInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountTokenAccount, TAccountMint, @@ -593,13 +295,14 @@ export function getUseAssetInstructionRaw< TAccountSystemProgram, TAccountUseAuthorityRecord, TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram, - TRemainingAccounts + TAccountAuthorizationRulesProgram >; + + return instruction; } export type ParsedUseAssetInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -650,7 +353,7 @@ export function parseUseAssetInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/utilize.ts b/test/packages/js-experimental/src/generated/instructions/utilize.ts index bc1e100ac..31176874f 100644 --- a/test/packages/js-experimental/src/generated/instructions/utilize.ts +++ b/test/packages/js-experimental/src/generated/instructions/utilize.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -31,77 +30,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type UtilizeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUseAuthority extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountBurner extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountTokenAccount extends string - ? WritableAccount - : TAccountTokenAccount, - TAccountMint extends string - ? WritableAccount - : TAccountMint, - TAccountUseAuthority extends string - ? WritableSignerAccount - : TAccountUseAuthority, - TAccountOwner extends string - ? ReadonlyAccount - : TAccountOwner, - TAccountTokenProgram extends string - ? ReadonlyAccount - : TAccountTokenProgram, - TAccountAtaProgram extends string - ? ReadonlyAccount - : TAccountAtaProgram, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - TAccountRent extends string - ? ReadonlyAccount - : TAccountRent, - TAccountUseAuthorityRecord extends string - ? WritableAccount - : TAccountUseAuthorityRecord, - TAccountBurner extends string - ? ReadonlyAccount - : TAccountBurner, - ...TRemainingAccounts, - ] - >; - -export type UtilizeInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountTokenAccount extends string | IAccountMeta = string, TAccountMint extends string | IAccountMeta = string, @@ -121,7 +54,7 @@ export type UtilizeInstructionWithSigners< | IAccountMeta = 'SysvarRent111111111111111111111111111111111', TAccountUseAuthorityRecord extends string | IAccountMeta = string, TAccountBurner extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -199,55 +132,17 @@ export function getUtilizeInstructionDataCodec(): Codec< } export type UtilizeInput< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountUseAuthorityRecord extends string, - TAccountBurner extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Token Account Of NFT */ - tokenAccount: Address; - /** Mint of the Metadata */ - mint: Address; - /** A Use Authority / Can be the current Owner of the NFT */ - useAuthority: Address; - /** Owner */ - owner: Address; - /** Token program */ - tokenProgram?: Address; - /** Associated Token program */ - ataProgram?: Address; - /** System program */ - systemProgram?: Address; - /** Rent info */ - rent?: Address; - /** Use Authority Record PDA If present the program Assumes a delegated use authority */ - useAuthorityRecord?: Address; - /** Program As Signer (Burner) */ - burner?: Address; - numberOfUses: UtilizeInstructionDataArgs['numberOfUses']; -}; - -export type UtilizeInputWithSigners< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountUseAuthorityRecord extends string, - TAccountBurner extends string, + TAccountMetadata extends string = string, + TAccountTokenAccount extends string = string, + TAccountMint extends string = string, + TAccountUseAuthority extends string = string, + TAccountOwner extends string = string, + TAccountTokenProgram extends string = string, + TAccountAtaProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, + TAccountUseAuthorityRecord extends string = string, + TAccountBurner extends string = string, > = { /** Metadata account */ metadata: Address; @@ -286,48 +181,6 @@ export function getUtilizeInstruction< TAccountRent extends string, TAccountUseAuthorityRecord extends string, TAccountBurner extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UtilizeInputWithSigners< - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountRent, - TAccountUseAuthorityRecord, - TAccountBurner - > -): UtilizeInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountRent, - TAccountUseAuthorityRecord, - TAccountBurner ->; -export function getUtilizeInstruction< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountUseAuthorityRecord extends string, - TAccountBurner extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: UtilizeInput< TAccountMetadata, @@ -343,7 +196,7 @@ export function getUtilizeInstruction< TAccountBurner > ): UtilizeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountTokenAccount, TAccountMint, @@ -355,57 +208,12 @@ export function getUtilizeInstruction< TAccountRent, TAccountUseAuthorityRecord, TAccountBurner ->; -export function getUtilizeInstruction< - TAccountMetadata extends string, - TAccountTokenAccount extends string, - TAccountMint extends string, - TAccountUseAuthority extends string, - TAccountOwner extends string, - TAccountTokenProgram extends string, - TAccountAtaProgram extends string, - TAccountSystemProgram extends string, - TAccountRent extends string, - TAccountUseAuthorityRecord extends string, - TAccountBurner extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: UtilizeInput< - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountRent, - TAccountUseAuthorityRecord, - TAccountBurner - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getUtilizeInstructionRaw< - TProgram, - TAccountMetadata, - TAccountTokenAccount, - TAccountMint, - TAccountUseAuthority, - TAccountOwner, - TAccountTokenProgram, - TAccountAtaProgram, - TAccountSystemProgram, - TAccountRent, - TAccountUseAuthorityRecord, - TAccountBurner - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, mint: { value: input.mint ?? null, isWritable: true }, @@ -421,6 +229,10 @@ export function getUtilizeInstruction< }, burner: { value: input.burner ?? null, isWritable: false }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -443,132 +255,27 @@ export function getUtilizeInstruction< 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getUtilizeInstructionRaw( - accountMetas as Record, - args as UtilizeInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getUtilizeInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountTokenAccount extends string | IAccountMeta = string, - TAccountMint extends string | IAccountMeta = string, - TAccountUseAuthority extends string | IAccountMeta = string, - TAccountOwner extends string | IAccountMeta = string, - TAccountTokenProgram extends - | string - | IAccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', - TAccountAtaProgram extends - | string - | IAccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountRent extends - | string - | IAccountMeta = 'SysvarRent111111111111111111111111111111111', - TAccountUseAuthorityRecord extends string | IAccountMeta = string, - TAccountBurner extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - tokenAccount: TAccountTokenAccount extends string - ? Address - : TAccountTokenAccount; - mint: TAccountMint extends string ? Address : TAccountMint; - useAuthority: TAccountUseAuthority extends string - ? Address - : TAccountUseAuthority; - owner: TAccountOwner extends string - ? Address - : TAccountOwner; - tokenProgram?: TAccountTokenProgram extends string - ? Address - : TAccountTokenProgram; - ataProgram?: TAccountAtaProgram extends string - ? Address - : TAccountAtaProgram; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - rent?: TAccountRent extends string ? Address : TAccountRent; - useAuthorityRecord?: TAccountUseAuthorityRecord extends string - ? Address - : TAccountUseAuthorityRecord; - burner?: TAccountBurner extends string - ? Address - : TAccountBurner; - }, - args: UtilizeInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.tokenAccount, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.mint, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.useAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.owner, AccountRole.READONLY), - accountMetaWithDefault( - accounts.tokenProgram ?? - ('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.ataProgram ?? - ('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.rent ?? - ('SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.useAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.WRITABLE - ), - accountMetaWithDefault( - accounts.burner ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.useAuthority), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.ataProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.useAuthorityRecord), + getAccountMeta(accounts.burner), ], - data: getUtilizeInstructionDataEncoder().encode(args), programAddress, + data: getUtilizeInstructionDataEncoder().encode( + args as UtilizeInstructionDataArgs + ), } as UtilizeInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountTokenAccount, TAccountMint, @@ -579,13 +286,14 @@ export function getUtilizeInstructionRaw< TAccountSystemProgram, TAccountRent, TAccountUseAuthorityRecord, - TAccountBurner, - TRemainingAccounts + TAccountBurner >; + + return instruction; } export type ParsedUtilizeInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -636,7 +344,7 @@ export function parseUtilizeInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/validate.ts b/test/packages/js-experimental/src/generated/instructions/validate.ts index 21e78283d..51ea69236 100644 --- a/test/packages/js-experimental/src/generated/instructions/validate.ts +++ b/test/packages/js-experimental/src/generated/instructions/validate.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -32,11 +31,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { Operation, OperationArgs, @@ -49,142 +45,7 @@ import { } from '../types'; export type ValidateInstruction< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', - TAccountPayer extends string | IAccountMeta = string, - TAccountRuleSet extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountOptRuleSigner1 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner2 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner3 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner4 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner5 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner1 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner2 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner3 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner4 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner5 extends - | string - | IAccountMeta - | undefined = undefined, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountRuleSet extends string - ? WritableAccount - : TAccountRuleSet, - TAccountSystemProgram extends string - ? ReadonlyAccount - : TAccountSystemProgram, - ...(TAccountOptRuleSigner1 extends undefined - ? [] - : [ - TAccountOptRuleSigner1 extends string - ? ReadonlyAccount - : TAccountOptRuleSigner1, - ]), - ...(TAccountOptRuleSigner2 extends undefined - ? [] - : [ - TAccountOptRuleSigner2 extends string - ? ReadonlySignerAccount - : TAccountOptRuleSigner2, - ]), - ...(TAccountOptRuleSigner3 extends undefined - ? [] - : [ - TAccountOptRuleSigner3 extends string - ? ReadonlySignerAccount - : TAccountOptRuleSigner3, - ]), - ...(TAccountOptRuleSigner4 extends undefined - ? [] - : [ - TAccountOptRuleSigner4 extends string - ? ReadonlySignerAccount - : TAccountOptRuleSigner4, - ]), - ...(TAccountOptRuleSigner5 extends undefined - ? [] - : [ - TAccountOptRuleSigner5 extends string - ? ReadonlySignerAccount - : TAccountOptRuleSigner5, - ]), - ...(TAccountOptRuleNonsigner1 extends undefined - ? [] - : [ - TAccountOptRuleNonsigner1 extends string - ? ReadonlyAccount - : TAccountOptRuleNonsigner1, - ]), - ...(TAccountOptRuleNonsigner2 extends undefined - ? [] - : [ - TAccountOptRuleNonsigner2 extends string - ? ReadonlyAccount - : TAccountOptRuleNonsigner2, - ]), - ...(TAccountOptRuleNonsigner3 extends undefined - ? [] - : [ - TAccountOptRuleNonsigner3 extends string - ? ReadonlyAccount - : TAccountOptRuleNonsigner3, - ]), - ...(TAccountOptRuleNonsigner4 extends undefined - ? [] - : [ - TAccountOptRuleNonsigner4 extends string - ? ReadonlyAccount - : TAccountOptRuleNonsigner4, - ]), - ...(TAccountOptRuleNonsigner5 extends undefined - ? [] - : [ - TAccountOptRuleNonsigner5 extends string - ? ReadonlyAccount - : TAccountOptRuleNonsigner5, - ]), - ...TRemainingAccounts, - ] - >; - -export type ValidateInstructionWithSigners< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', + TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer extends string | IAccountMeta = string, TAccountRuleSet extends string | IAccountMeta = string, TAccountSystemProgram extends @@ -230,7 +91,7 @@ export type ValidateInstructionWithSigners< | string | IAccountMeta | undefined = undefined, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -368,64 +229,19 @@ export function getValidateInstructionDataCodec(): Codec< } export type ValidateInput< - TAccountPayer extends string, - TAccountRuleSet extends string, - TAccountSystemProgram extends string, - TAccountOptRuleSigner1 extends string, - TAccountOptRuleSigner2 extends string, - TAccountOptRuleSigner3 extends string, - TAccountOptRuleSigner4 extends string, - TAccountOptRuleSigner5 extends string, - TAccountOptRuleNonsigner1 extends string, - TAccountOptRuleNonsigner2 extends string, - TAccountOptRuleNonsigner3 extends string, - TAccountOptRuleNonsigner4 extends string, - TAccountOptRuleNonsigner5 extends string, -> = { - /** Payer and creator of the RuleSet */ - payer: Address; - /** The PDA account where the RuleSet is stored */ - ruleSet: Address; - /** System program */ - systemProgram?: Address; - optRuleSigner1?: Address; - /** Optional rule validation signer 2 */ - optRuleSigner2?: Address; - /** Optional rule validation signer 3 */ - optRuleSigner3?: Address; - /** Optional rule validation signer 4 */ - optRuleSigner4?: Address; - /** Optional rule validation signer 5 */ - optRuleSigner5?: Address; - /** Optional rule validation non-signer 1 */ - optRuleNonsigner1?: Address; - /** Optional rule validation non-signer 2 */ - optRuleNonsigner2?: Address; - /** Optional rule validation non-signer 3 */ - optRuleNonsigner3?: Address; - /** Optional rule validation non-signer 4 */ - optRuleNonsigner4?: Address; - /** Optional rule validation non-signer 5 */ - optRuleNonsigner5?: Address; - ruleSetName: ValidateInstructionDataArgs['ruleSetName']; - operation: ValidateInstructionDataArgs['operation']; - payload: ValidateInstructionDataArgs['payload']; -}; - -export type ValidateInputWithSigners< - TAccountPayer extends string, - TAccountRuleSet extends string, - TAccountSystemProgram extends string, - TAccountOptRuleSigner1 extends string, - TAccountOptRuleSigner2 extends string, - TAccountOptRuleSigner3 extends string, - TAccountOptRuleSigner4 extends string, - TAccountOptRuleSigner5 extends string, - TAccountOptRuleNonsigner1 extends string, - TAccountOptRuleNonsigner2 extends string, - TAccountOptRuleNonsigner3 extends string, - TAccountOptRuleNonsigner4 extends string, - TAccountOptRuleNonsigner5 extends string, + TAccountPayer extends string = string, + TAccountRuleSet extends string = string, + TAccountSystemProgram extends string = string, + TAccountOptRuleSigner1 extends string = string, + TAccountOptRuleSigner2 extends string = string, + TAccountOptRuleSigner3 extends string = string, + TAccountOptRuleSigner4 extends string = string, + TAccountOptRuleSigner5 extends string = string, + TAccountOptRuleNonsigner1 extends string = string, + TAccountOptRuleNonsigner2 extends string = string, + TAccountOptRuleNonsigner3 extends string = string, + TAccountOptRuleNonsigner4 extends string = string, + TAccountOptRuleNonsigner5 extends string = string, > = { /** Payer and creator of the RuleSet */ payer: TransactionSigner; @@ -473,9 +289,8 @@ export function getValidateInstruction< TAccountOptRuleNonsigner3 extends string, TAccountOptRuleNonsigner4 extends string, TAccountOptRuleNonsigner5 extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', >( - input: ValidateInputWithSigners< + input: ValidateInput< TAccountPayer, TAccountRuleSet, TAccountSystemProgram, @@ -490,8 +305,8 @@ export function getValidateInstruction< TAccountOptRuleNonsigner4, TAccountOptRuleNonsigner5 > -): ValidateInstructionWithSigners< - TProgram, +): ValidateInstruction< + typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer, TAccountRuleSet, TAccountSystemProgram, @@ -508,110 +323,12 @@ export function getValidateInstruction< TAccountOptRuleNonsigner3, TAccountOptRuleNonsigner4, TAccountOptRuleNonsigner5 ->; -export function getValidateInstruction< - TAccountPayer extends string, - TAccountRuleSet extends string, - TAccountSystemProgram extends string, - TAccountOptRuleSigner1 extends string, - TAccountOptRuleSigner2 extends string, - TAccountOptRuleSigner3 extends string, - TAccountOptRuleSigner4 extends string, - TAccountOptRuleSigner5 extends string, - TAccountOptRuleNonsigner1 extends string, - TAccountOptRuleNonsigner2 extends string, - TAccountOptRuleNonsigner3 extends string, - TAccountOptRuleNonsigner4 extends string, - TAccountOptRuleNonsigner5 extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', ->( - input: ValidateInput< - TAccountPayer, - TAccountRuleSet, - TAccountSystemProgram, - TAccountOptRuleSigner1, - TAccountOptRuleSigner2, - TAccountOptRuleSigner3, - TAccountOptRuleSigner4, - TAccountOptRuleSigner5, - TAccountOptRuleNonsigner1, - TAccountOptRuleNonsigner2, - TAccountOptRuleNonsigner3, - TAccountOptRuleNonsigner4, - TAccountOptRuleNonsigner5 - > -): ValidateInstruction< - TProgram, - TAccountPayer, - TAccountRuleSet, - TAccountSystemProgram, - TAccountOptRuleSigner1, - TAccountOptRuleSigner2, - TAccountOptRuleSigner3, - TAccountOptRuleSigner4, - TAccountOptRuleSigner5, - TAccountOptRuleNonsigner1, - TAccountOptRuleNonsigner2, - TAccountOptRuleNonsigner3, - TAccountOptRuleNonsigner4, - TAccountOptRuleNonsigner5 ->; -export function getValidateInstruction< - TAccountPayer extends string, - TAccountRuleSet extends string, - TAccountSystemProgram extends string, - TAccountOptRuleSigner1 extends string, - TAccountOptRuleSigner2 extends string, - TAccountOptRuleSigner3 extends string, - TAccountOptRuleSigner4 extends string, - TAccountOptRuleSigner5 extends string, - TAccountOptRuleNonsigner1 extends string, - TAccountOptRuleNonsigner2 extends string, - TAccountOptRuleNonsigner3 extends string, - TAccountOptRuleNonsigner4 extends string, - TAccountOptRuleNonsigner5 extends string, - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', ->( - input: ValidateInput< - TAccountPayer, - TAccountRuleSet, - TAccountSystemProgram, - TAccountOptRuleSigner1, - TAccountOptRuleSigner2, - TAccountOptRuleSigner3, - TAccountOptRuleSigner4, - TAccountOptRuleSigner5, - TAccountOptRuleNonsigner1, - TAccountOptRuleNonsigner2, - TAccountOptRuleNonsigner3, - TAccountOptRuleNonsigner4, - TAccountOptRuleNonsigner5 - > -): IInstruction { +> { // Program address. - const programAddress = - 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg' as Address<'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg'>; + const programAddress = MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getValidateInstructionRaw< - TProgram, - TAccountPayer, - TAccountRuleSet, - TAccountSystemProgram, - TAccountOptRuleSigner1, - TAccountOptRuleSigner2, - TAccountOptRuleSigner3, - TAccountOptRuleSigner4, - TAccountOptRuleSigner5, - TAccountOptRuleNonsigner1, - TAccountOptRuleNonsigner2, - TAccountOptRuleNonsigner3, - TAccountOptRuleNonsigner4, - TAccountOptRuleNonsigner5 - > - >[0]; - const accounts: Record = { + const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, ruleSet: { value: input.ruleSet ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, @@ -641,6 +358,10 @@ export function getValidateInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; @@ -651,157 +372,36 @@ export function getValidateInstruction< '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getValidateInstructionRaw( - accountMetas as Record, - args as ValidateInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getValidateInstructionRaw< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', - TAccountPayer extends string | IAccountMeta = string, - TAccountRuleSet extends string | IAccountMeta = string, - TAccountSystemProgram extends - | string - | IAccountMeta = '11111111111111111111111111111111', - TAccountOptRuleSigner1 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner2 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner3 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner4 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleSigner5 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner1 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner2 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner3 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner4 extends - | string - | IAccountMeta - | undefined = undefined, - TAccountOptRuleNonsigner5 extends - | string - | IAccountMeta - | undefined = undefined, - TRemainingAccounts extends Array> = [], ->( - accounts: { - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - ruleSet: TAccountRuleSet extends string - ? Address - : TAccountRuleSet; - systemProgram?: TAccountSystemProgram extends string - ? Address - : TAccountSystemProgram; - optRuleSigner1?: TAccountOptRuleSigner1 extends string - ? Address - : TAccountOptRuleSigner1; - optRuleSigner2?: TAccountOptRuleSigner2 extends string - ? Address - : TAccountOptRuleSigner2; - optRuleSigner3?: TAccountOptRuleSigner3 extends string - ? Address - : TAccountOptRuleSigner3; - optRuleSigner4?: TAccountOptRuleSigner4 extends string - ? Address - : TAccountOptRuleSigner4; - optRuleSigner5?: TAccountOptRuleSigner5 extends string - ? Address - : TAccountOptRuleSigner5; - optRuleNonsigner1?: TAccountOptRuleNonsigner1 extends string - ? Address - : TAccountOptRuleNonsigner1; - optRuleNonsigner2?: TAccountOptRuleNonsigner2 extends string - ? Address - : TAccountOptRuleNonsigner2; - optRuleNonsigner3?: TAccountOptRuleNonsigner3 extends string - ? Address - : TAccountOptRuleNonsigner3; - optRuleNonsigner4?: TAccountOptRuleNonsigner4 extends string - ? Address - : TAccountOptRuleNonsigner4; - optRuleNonsigner5?: TAccountOptRuleNonsigner5 extends string - ? Address - : TAccountOptRuleNonsigner5; - }, - args: ValidateInstructionDataArgs, - programAddress: Address = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.ruleSet, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.systemProgram ?? - ('11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>), - AccountRole.READONLY - ), - accountMetaWithDefault(accounts.optRuleSigner1, AccountRole.READONLY), - accountMetaWithDefault( - accounts.optRuleSigner2, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.optRuleSigner3, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.optRuleSigner4, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault( - accounts.optRuleSigner5, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.optRuleNonsigner1, AccountRole.READONLY), - accountMetaWithDefault(accounts.optRuleNonsigner2, AccountRole.READONLY), - accountMetaWithDefault(accounts.optRuleNonsigner3, AccountRole.READONLY), - accountMetaWithDefault(accounts.optRuleNonsigner4, AccountRole.READONLY), - accountMetaWithDefault(accounts.optRuleNonsigner5, AccountRole.READONLY), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.ruleSet), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.optRuleSigner1), + getAccountMeta(accounts.optRuleSigner2), + getAccountMeta(accounts.optRuleSigner3), + getAccountMeta(accounts.optRuleSigner4), + getAccountMeta(accounts.optRuleSigner5), + getAccountMeta(accounts.optRuleNonsigner1), + getAccountMeta(accounts.optRuleNonsigner2), + getAccountMeta(accounts.optRuleNonsigner3), + getAccountMeta(accounts.optRuleNonsigner4), + getAccountMeta(accounts.optRuleNonsigner5), ].filter((x: T | undefined): x is T => x !== undefined), - data: getValidateInstructionDataEncoder().encode(args), programAddress, + data: getValidateInstructionDataEncoder().encode( + args as ValidateInstructionDataArgs + ), } as ValidateInstruction< - TProgram, + typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountPayer, TAccountRuleSet, TAccountSystemProgram, - TAccountOptRuleSigner1, + (typeof input)['optRuleSigner1'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountOptRuleSigner1, TAccountOptRuleSigner2, TAccountOptRuleSigner3, TAccountOptRuleSigner4, @@ -810,13 +410,14 @@ export function getValidateInstructionRaw< TAccountOptRuleNonsigner2, TAccountOptRuleNonsigner3, TAccountOptRuleNonsigner4, - TAccountOptRuleNonsigner5, - TRemainingAccounts + TAccountOptRuleNonsigner5 >; + + return instruction; } export type ParsedValidateInstruction< - TProgram extends string = 'auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg', + TProgram extends string = typeof MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/verify.ts b/test/packages/js-experimental/src/generated/instructions/verify.ts index 59eda2303..7946345ac 100644 --- a/test/packages/js-experimental/src/generated/instructions/verify.ts +++ b/test/packages/js-experimental/src/generated/instructions/verify.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,11 +28,8 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; import { VerifyArgs, VerifyArgsArgs, @@ -42,7 +38,7 @@ import { } from '../types'; export type VerifyInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -50,40 +46,7 @@ export type VerifyInstruction< TAccountAuthorizationRulesProgram extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCollectionAuthority extends string - ? WritableSignerAccount - : TAccountCollectionAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountAuthorizationRules extends string - ? ReadonlyAccount - : TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram extends string - ? ReadonlyAccount - : TAccountAuthorizationRulesProgram, - ...TRemainingAccounts, - ] - >; - -export type VerifyInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -144,31 +107,11 @@ export function getVerifyInstructionDataCodec(): Codec< } export type VerifyInput< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Collection Update authority */ - collectionAuthority: Address; - /** payer */ - payer: Address; - /** Token Authorization Rules account */ - authorizationRules?: Address; - /** Token Authorization Rules Program */ - authorizationRulesProgram?: Address; - verifyArgs: VerifyInstructionDataArgs['verifyArgs']; -}; - -export type VerifyInputWithSigners< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, + TAccountMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountPayer extends string = string, + TAccountAuthorizationRules extends string = string, + TAccountAuthorizationRulesProgram extends string = string, > = { /** Metadata account */ metadata: Address; @@ -189,30 +132,6 @@ export function getVerifyInstruction< TAccountPayer extends string, TAccountAuthorizationRules extends string, TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: VerifyInputWithSigners< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > -): VerifyInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram ->; -export function getVerifyInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: VerifyInput< TAccountMetadata, @@ -222,45 +141,18 @@ export function getVerifyInstruction< TAccountAuthorizationRulesProgram > ): VerifyInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, TAccountAuthorizationRules, TAccountAuthorizationRulesProgram ->; -export function getVerifyInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountAuthorizationRules extends string, - TAccountAuthorizationRulesProgram extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: VerifyInput< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getVerifyInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, collectionAuthority: { value: input.collectionAuthority ?? null, @@ -276,99 +168,41 @@ export function getVerifyInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; // Original args. const args = { ...input }; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getVerifyInstructionRaw( - accountMetas as Record, - args as VerifyInstructionDataArgs, - programAddress - ); - - return instruction; -} - -export function getVerifyInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountAuthorizationRules extends string | IAccountMeta = string, - TAccountAuthorizationRulesProgram extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - authorizationRules?: TAccountAuthorizationRules extends string - ? Address - : TAccountAuthorizationRules; - authorizationRulesProgram?: TAccountAuthorizationRulesProgram extends string - ? Address - : TAccountAuthorizationRulesProgram; - }, - args: VerifyInstructionDataArgs, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault( - accounts.authorizationRules ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.authorizationRulesProgram ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.authorizationRules), + getAccountMeta(accounts.authorizationRulesProgram), ], - data: getVerifyInstructionDataEncoder().encode(args), programAddress, + data: getVerifyInstructionDataEncoder().encode( + args as VerifyInstructionDataArgs + ), } as VerifyInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, TAccountAuthorizationRules, - TAccountAuthorizationRulesProgram, - TRemainingAccounts + TAccountAuthorizationRulesProgram >; + + return instruction; } export type ParsedVerifyInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -407,7 +241,7 @@ export function parseVerifyInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/verifyCollection.ts b/test/packages/js-experimental/src/generated/instructions/verifyCollection.ts index b0317e840..285e4be3d 100644 --- a/test/packages/js-experimental/src/generated/instructions/verifyCollection.ts +++ b/test/packages/js-experimental/src/generated/instructions/verifyCollection.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -29,51 +28,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type VerifyCollectionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCollectionAuthority extends string - ? WritableSignerAccount - : TAccountCollectionAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollection extends string - ? ReadonlyAccount - : TAccountCollection, - TAccountCollectionMasterEditionAccount extends string - ? ReadonlyAccount - : TAccountCollectionMasterEditionAccount, - ...TRemainingAccounts, - ] - >; - -export type VerifyCollectionInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -82,7 +41,7 @@ export type VerifyCollectionInstructionWithSigners< TAccountCollectionMasterEditionAccount extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -137,34 +96,12 @@ export function getVerifyCollectionInstructionDataCodec(): Codec< } export type VerifyCollectionInput< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Collection Update authority */ - collectionAuthority: Address; - /** payer */ - payer: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Metadata Account of the Collection */ - collection: Address; - /** MasterEdition2 Account of the Collection Token */ - collectionMasterEditionAccount: Address; -}; - -export type VerifyCollectionInputWithSigners< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, + TAccountMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountPayer extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollection extends string = string, + TAccountCollectionMasterEditionAccount extends string = string, > = { /** Metadata account */ metadata: Address; @@ -187,33 +124,6 @@ export function getVerifyCollectionInstruction< TAccountCollectionMint extends string, TAccountCollection extends string, TAccountCollectionMasterEditionAccount extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: VerifyCollectionInputWithSigners< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount - > -): VerifyCollectionInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount ->; -export function getVerifyCollectionInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: VerifyCollectionInput< TAccountMetadata, @@ -224,49 +134,19 @@ export function getVerifyCollectionInstruction< TAccountCollectionMasterEditionAccount > ): VerifyCollectionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, TAccountCollectionMint, TAccountCollection, TAccountCollectionMasterEditionAccount ->; -export function getVerifyCollectionInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: VerifyCollectionInput< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getVerifyCollectionInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, collectionAuthority: { value: input.collectionAuthority ?? null, @@ -280,89 +160,38 @@ export function getVerifyCollectionInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getVerifyCollectionInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getVerifyCollectionInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collection: TAccountCollection extends string - ? Address - : TAccountCollection; - collectionMasterEditionAccount: TAccountCollectionMasterEditionAccount extends string - ? Address - : TAccountCollectionMasterEditionAccount; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.WRITABLE_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collection, AccountRole.READONLY), - accountMetaWithDefault( - accounts.collectionMasterEditionAccount, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collection), + getAccountMeta(accounts.collectionMasterEditionAccount), ], - data: getVerifyCollectionInstructionDataEncoder().encode({}), programAddress, + data: getVerifyCollectionInstructionDataEncoder().encode({}), } as VerifyCollectionInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, TAccountCollectionMint, TAccountCollection, - TAccountCollectionMasterEditionAccount, - TRemainingAccounts + TAccountCollectionMasterEditionAccount >; + + return instruction; } export type ParsedVerifyCollectionInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/instructions/verifySizedCollectionItem.ts b/test/packages/js-experimental/src/generated/instructions/verifySizedCollectionItem.ts index f3a03c5ea..45b4b09eb 100644 --- a/test/packages/js-experimental/src/generated/instructions/verifySizedCollectionItem.ts +++ b/test/packages/js-experimental/src/generated/instructions/verifySizedCollectionItem.ts @@ -19,7 +19,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,14 +29,11 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_TOKEN_METADATA_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type VerifySizedCollectionItemInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata extends string | IAccountMeta = string, TAccountCollectionAuthority extends string | IAccountMeta = string, TAccountPayer extends string | IAccountMeta = string, @@ -49,50 +45,7 @@ export type VerifySizedCollectionItemInstruction< TAccountCollectionAuthorityRecord extends | string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountMetadata extends string - ? WritableAccount - : TAccountMetadata, - TAccountCollectionAuthority extends string - ? ReadonlySignerAccount - : TAccountCollectionAuthority, - TAccountPayer extends string - ? WritableSignerAccount - : TAccountPayer, - TAccountCollectionMint extends string - ? ReadonlyAccount - : TAccountCollectionMint, - TAccountCollection extends string - ? WritableAccount - : TAccountCollection, - TAccountCollectionMasterEditionAccount extends string - ? ReadonlyAccount - : TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord extends string - ? ReadonlyAccount - : TAccountCollectionAuthorityRecord, - ...TRemainingAccounts, - ] - >; - -export type VerifySizedCollectionItemInstructionWithSigners< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -152,38 +105,13 @@ export function getVerifySizedCollectionItemInstructionDataCodec(): Codec< } export type VerifySizedCollectionItemInput< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, -> = { - /** Metadata account */ - metadata: Address; - /** Collection Update authority */ - collectionAuthority: Address; - /** payer */ - payer: Address; - /** Mint of the Collection */ - collectionMint: Address; - /** Metadata Account of the Collection */ - collection: Address; - /** MasterEdition2 Account of the Collection Token */ - collectionMasterEditionAccount: Address; - /** Collection Authority Record PDA */ - collectionAuthorityRecord?: Address; -}; - -export type VerifySizedCollectionItemInputWithSigners< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, + TAccountMetadata extends string = string, + TAccountCollectionAuthority extends string = string, + TAccountPayer extends string = string, + TAccountCollectionMint extends string = string, + TAccountCollection extends string = string, + TAccountCollectionMasterEditionAccount extends string = string, + TAccountCollectionAuthorityRecord extends string = string, > = { /** Metadata account */ metadata: Address; @@ -209,36 +137,6 @@ export function getVerifySizedCollectionItemInstruction< TAccountCollection extends string, TAccountCollectionMasterEditionAccount extends string, TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: VerifySizedCollectionItemInputWithSigners< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): VerifySizedCollectionItemInstructionWithSigners< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord ->; -export function getVerifySizedCollectionItemInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', >( input: VerifySizedCollectionItemInput< TAccountMetadata, @@ -250,7 +148,7 @@ export function getVerifySizedCollectionItemInstruction< TAccountCollectionAuthorityRecord > ): VerifySizedCollectionItemInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, @@ -258,45 +156,12 @@ export function getVerifySizedCollectionItemInstruction< TAccountCollection, TAccountCollectionMasterEditionAccount, TAccountCollectionAuthorityRecord ->; -export function getVerifySizedCollectionItemInstruction< - TAccountMetadata extends string, - TAccountCollectionAuthority extends string, - TAccountPayer extends string, - TAccountCollectionMint extends string, - TAccountCollection extends string, - TAccountCollectionMasterEditionAccount extends string, - TAccountCollectionAuthorityRecord extends string, - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ->( - input: VerifySizedCollectionItemInput< - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > -): IInstruction { +> { // Program address. - const programAddress = - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>; + const programAddress = MPL_TOKEN_METADATA_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getVerifySizedCollectionItemInstructionRaw< - TProgram, - TAccountMetadata, - TAccountCollectionAuthority, - TAccountPayer, - TAccountCollectionMint, - TAccountCollection, - TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord - > - >[0]; - const accounts: Record = { + const originalAccounts = { metadata: { value: input.metadata ?? null, isWritable: true }, collectionAuthority: { value: input.collectionAuthority ?? null, @@ -314,104 +179,40 @@ export function getVerifySizedCollectionItemInstruction< isWritable: false, }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getVerifySizedCollectionItemInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getVerifySizedCollectionItemInstructionRaw< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', - TAccountMetadata extends string | IAccountMeta = string, - TAccountCollectionAuthority extends string | IAccountMeta = string, - TAccountPayer extends string | IAccountMeta = string, - TAccountCollectionMint extends string | IAccountMeta = string, - TAccountCollection extends string | IAccountMeta = string, - TAccountCollectionMasterEditionAccount extends - | string - | IAccountMeta = string, - TAccountCollectionAuthorityRecord extends - | string - | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - metadata: TAccountMetadata extends string - ? Address - : TAccountMetadata; - collectionAuthority: TAccountCollectionAuthority extends string - ? Address - : TAccountCollectionAuthority; - payer: TAccountPayer extends string - ? Address - : TAccountPayer; - collectionMint: TAccountCollectionMint extends string - ? Address - : TAccountCollectionMint; - collection: TAccountCollection extends string - ? Address - : TAccountCollection; - collectionMasterEditionAccount: TAccountCollectionMasterEditionAccount extends string - ? Address - : TAccountCollectionMasterEditionAccount; - collectionAuthorityRecord?: TAccountCollectionAuthorityRecord extends string - ? Address - : TAccountCollectionAuthorityRecord; - }, - programAddress: Address = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.metadata, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionAuthority, - AccountRole.READONLY_SIGNER - ), - accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER), - accountMetaWithDefault(accounts.collectionMint, AccountRole.READONLY), - accountMetaWithDefault(accounts.collection, AccountRole.WRITABLE), - accountMetaWithDefault( - accounts.collectionMasterEditionAccount, - AccountRole.READONLY - ), - accountMetaWithDefault( - accounts.collectionAuthorityRecord ?? { - address: - 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' as Address<'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'>, - role: AccountRole.READONLY, - }, - AccountRole.READONLY - ), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.metadata), + getAccountMeta(accounts.collectionAuthority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.collectionMint), + getAccountMeta(accounts.collection), + getAccountMeta(accounts.collectionMasterEditionAccount), + getAccountMeta(accounts.collectionAuthorityRecord), ], - data: getVerifySizedCollectionItemInstructionDataEncoder().encode({}), programAddress, + data: getVerifySizedCollectionItemInstructionDataEncoder().encode({}), } as VerifySizedCollectionItemInstruction< - TProgram, + typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetadata, TAccountCollectionAuthority, TAccountPayer, TAccountCollectionMint, TAccountCollection, TAccountCollectionMasterEditionAccount, - TAccountCollectionAuthorityRecord, - TRemainingAccounts + TAccountCollectionAuthorityRecord >; + + return instruction; } export type ParsedVerifySizedCollectionItemInstruction< - TProgram extends string = 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', + TProgram extends string = typeof MPL_TOKEN_METADATA_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; @@ -454,7 +255,7 @@ export function parseVerifySizedCollectionItemInstruction< }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); - return accountMeta.address === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' + return accountMeta.address === MPL_TOKEN_METADATA_PROGRAM_ADDRESS ? undefined : accountMeta; }; diff --git a/test/packages/js-experimental/src/generated/instructions/withdraw.ts b/test/packages/js-experimental/src/generated/instructions/withdraw.ts index c16a1b841..10cdf72d8 100644 --- a/test/packages/js-experimental/src/generated/instructions/withdraw.ts +++ b/test/packages/js-experimental/src/generated/instructions/withdraw.ts @@ -21,7 +21,6 @@ import { mapEncoder, } from '@solana/codecs'; import { - AccountRole, IAccountMeta, IInstruction, IInstructionWithAccounts, @@ -30,36 +29,14 @@ import { WritableSignerAccount, } from '@solana/instructions'; import { IAccountSignerMeta, TransactionSigner } from '@solana/signers'; -import { - ResolvedAccount, - accountMetaWithDefault, - getAccountMetasWithSigners, -} from '../shared'; +import { MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS } from '../programs'; +import { ResolvedAccount, getAccountMetaFactory } from '../shared'; export type WithdrawInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountCandyMachine extends string - ? WritableAccount - : TAccountCandyMachine, - TAccountAuthority extends string - ? WritableSignerAccount - : TAccountAuthority, - ...TRemainingAccounts, - ] - >; - -export type WithdrawInstructionWithSigners< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine extends string | IAccountMeta = string, TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], + TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< @@ -108,16 +85,8 @@ export function getWithdrawInstructionDataCodec(): Codec< } export type WithdrawInput< - TAccountCandyMachine extends string, - TAccountAuthority extends string, -> = { - candyMachine: Address; - authority: Address; -}; - -export type WithdrawInputWithSigners< - TAccountCandyMachine extends string, - TAccountAuthority extends string, + TAccountCandyMachine extends string = string, + TAccountAuthority extends string = string, > = { candyMachine: Address; authority: TransactionSigner; @@ -126,93 +95,45 @@ export type WithdrawInputWithSigners< export function getWithdrawInstruction< TAccountCandyMachine extends string, TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', >( - input: WithdrawInputWithSigners -): WithdrawInstructionWithSigners< - TProgram, + input: WithdrawInput +): WithdrawInstruction< + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, TAccountAuthority ->; -export function getWithdrawInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->( - input: WithdrawInput -): WithdrawInstruction; -export function getWithdrawInstruction< - TAccountCandyMachine extends string, - TAccountAuthority extends string, - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', ->(input: WithdrawInput): IInstruction { +> { // Program address. - const programAddress = - 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>; + const programAddress = MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS; // Original accounts. - type AccountMetas = Parameters< - typeof getWithdrawInstructionRaw< - TProgram, - TAccountCandyMachine, - TAccountAuthority - > - >[0]; - const accounts: Record = { + const originalAccounts = { candyMachine: { value: input.candyMachine ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: true }, }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; - // Get account metas and signers. - const accountMetas = getAccountMetasWithSigners( - accounts, - 'programId', - programAddress - ); - - const instruction = getWithdrawInstructionRaw( - accountMetas as Record, - programAddress - ); - - return instruction; -} - -export function getWithdrawInstructionRaw< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', - TAccountCandyMachine extends string | IAccountMeta = string, - TAccountAuthority extends string | IAccountMeta = string, - TRemainingAccounts extends Array> = [], ->( - accounts: { - candyMachine: TAccountCandyMachine extends string - ? Address - : TAccountCandyMachine; - authority: TAccountAuthority extends string - ? Address - : TAccountAuthority; - }, - programAddress: Address = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address, - remainingAccounts?: TRemainingAccounts -) { - return { + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { accounts: [ - accountMetaWithDefault(accounts.candyMachine, AccountRole.WRITABLE), - accountMetaWithDefault(accounts.authority, AccountRole.WRITABLE_SIGNER), - ...(remainingAccounts ?? []), + getAccountMeta(accounts.candyMachine), + getAccountMeta(accounts.authority), ], - data: getWithdrawInstructionDataEncoder().encode({}), programAddress, + data: getWithdrawInstructionDataEncoder().encode({}), } as WithdrawInstruction< - TProgram, + typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountCandyMachine, - TAccountAuthority, - TRemainingAccounts + TAccountAuthority >; + + return instruction; } export type ParsedWithdrawInstruction< - TProgram extends string = 'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR', + TProgram extends string = typeof MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; diff --git a/test/packages/js-experimental/src/generated/shared/index.ts b/test/packages/js-experimental/src/generated/shared/index.ts index 02250e9f8..bef879319 100644 --- a/test/packages/js-experimental/src/generated/shared/index.ts +++ b/test/packages/js-experimental/src/generated/shared/index.ts @@ -113,22 +113,6 @@ export type ResolvedAccount< value: U; }; -/** - * Add an account meta with a default role if only an address is provided. - * @internal - */ -export function accountMetaWithDefault< - TAccount extends string | IAccountMeta, - TRole extends AccountRole, ->(account: TAccount | undefined, role: TRole) { - if (account === undefined) return undefined; - return ( - typeof account === 'string' ? { address: account, role } : account - ) as TAccount extends string - ? { address: Address; role: TRole } - : TAccount; -} - /** * Defines an instruction that stores additional bytes on-chain. * @internal @@ -141,37 +125,32 @@ export type IInstructionWithByteDelta = { * Get account metas and signers from resolved accounts. * @internal */ -export function getAccountMetasWithSigners( - accounts: Record, - optionalAccountStrategy: 'omitted' | 'programId', - programAddress: Address -): Record { - const accountMetas: Record = {}; - - Object.keys(accounts).forEach((key) => { - const account = accounts[key as TKey] as ResolvedAccount; +export function getAccountMetaFactory( + programAddress: Address, + optionalAccountStrategy: 'omitted' | 'programId' +) { + return ( + account: ResolvedAccount + ): IAccountMeta | IAccountSignerMeta | undefined => { if (!account.value) { if (optionalAccountStrategy === 'omitted') return; - accountMetas[key] = { + return Object.freeze({ address: programAddress, role: AccountRole.READONLY, - }; - return; + }); } const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY; - accountMetas[key] = Object.freeze({ + return Object.freeze({ address: expectAddress(account.value), role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole, ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), }); - }); - - return accountMetas; + }; } export function isTransactionSigner( diff --git a/test/packages/js-experimental/src/transferSol.ts b/test/packages/js-experimental/src/transferSol.ts index 46bdaeb9f..fbb35f4dc 100644 --- a/test/packages/js-experimental/src/transferSol.ts +++ b/test/packages/js-experimental/src/transferSol.ts @@ -4,22 +4,11 @@ import { TransactionSigner } from '@solana/signers'; // Typetests. const instruction = getTransferSolInstruction({ - source: '1111' as Address<'1111'>, + source: {} as TransactionSigner<'1111'>, destination: '2222' as Address<'2222'>, amount: BigInt(100), }); -// @ts-expect-error instruction.accounts[0].signer; // @ts-expect-error instruction.accounts[1].signer; -export type T1 = typeof instruction; - -const instructionWithSigners = getTransferSolInstruction({ - source: {} as TransactionSigner<'1111'>, - destination: '2222' as Address<'2222'>, - amount: BigInt(100), -}); -instructionWithSigners.accounts[0].signer; -// @ts-expect-error -instructionWithSigners.accounts[1].signer; -export type T2 = typeof instructionWithSigners; +export type T2 = typeof instruction;