From 7afaa08a894ca91b1fa6775616017799e1b16c0b Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Wed, 2 Apr 2025 14:46:17 +0100 Subject: [PATCH 1/2] Simplify update with buffer instruction plan TransferSol + multiple Extend instructions can be replaced with CreateAccount for non-PDA accounts. --- clients/js/src/updateMetadata.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/clients/js/src/updateMetadata.ts b/clients/js/src/updateMetadata.ts index 528a58e..49dcb0e 100644 --- a/clients/js/src/updateMetadata.ts +++ b/clients/js/src/updateMetadata.ts @@ -1,4 +1,7 @@ -import { getTransferSolInstruction } from '@solana-program/system'; +import { + getCreateAccountInstruction, + getTransferSolInstruction, +} from '@solana-program/system'; import { CompilableTransactionMessage, generateKeyPairSigner, @@ -16,6 +19,7 @@ import { getSetAuthorityInstruction, getSetDataInstruction, getTrimInstruction, + PROGRAM_METADATA_PROGRAM_ADDRESS, } from './generated'; import { calculateMaxChunkSize, @@ -191,10 +195,12 @@ export function getUpdateMetadataInstructionPlanUsingBuffer( } initialMessage.instructions.push( - getTransferSolInstruction({ - source: input.payer, - destination: input.buffer.address, - amount: input.bufferRent, + getCreateAccountInstruction({ + payer: input.payer, + newAccount: input.buffer, + lamports: input.bufferRent, + space: getAccountSize(input.data.length), + programAddress: PROGRAM_METADATA_PROGRAM_ADDRESS, }), getAllocateInstruction({ buffer: input.buffer.address, @@ -221,17 +227,6 @@ export function getUpdateMetadataInstructionPlanUsingBuffer( ); } - if (input.data.length > REALLOC_LIMIT) { - mainPlan.plans.push( - getExtendInstructionPlan({ - account: input.buffer.address, - authority: input.authority, - extraLength: input.data.length, - priorityFees: input.priorityFees, - }) - ); - } - let offset = 0; const writePlan: InstructionPlan = { kind: 'parallel', plans: [] }; while (offset < input.data.length) { From 0a8f48e044513aef79b259fa5636ecc3790a1a7b Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Wed, 2 Apr 2025 15:09:26 +0100 Subject: [PATCH 2/2] Change --third-party option to --non-canonical --- clients/js/src/cli.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/clients/js/src/cli.ts b/clients/js/src/cli.ts index 115af59..0b81f40 100644 --- a/clients/js/src/cli.ts +++ b/clients/js/src/cli.ts @@ -86,7 +86,7 @@ program // Upload metadata command. type UploadOptions = GlobalOptions & { - thirdParty: boolean; + nonCanonical: boolean; file?: string; url?: string; account?: string; @@ -111,7 +111,7 @@ program ) .description('Upload metadata') .option( - '--third-party', + '--non-canonical', 'When provided, a non-canonical metadata account will be uploaded using the active keypair as the authority.', false ) @@ -170,9 +170,9 @@ program client.rpc, program ); - if (!options.thirdParty && keypair.address !== programAuthority) { + if (!options.nonCanonical && keypair.address !== programAuthority) { logErrorAndExit( - 'You must be the program authority to upload a canonical metadata account. Use `--third-party` option to upload as a third party.' + 'You must be the program authority to upload a canonical metadata account. Use `--non-canonical` option to upload as a third party.' ); } const { lastTransaction } = await uploadMetadata({ @@ -211,7 +211,7 @@ program // Download metadata command. type DownloadOptions = GlobalOptions & { output?: string; - thirdParty?: string | true; + nonCanonical?: string | true; }; program .command('download') @@ -224,7 +224,7 @@ program ) .option('-o, --output ', 'Path to save the IDL file') .option( - '--third-party [address]', + '--non-canonical [address]', 'When provided, a non-canonical metadata account will be downloaded using the provided address or the active keypair as the authority.', false ) @@ -232,10 +232,10 @@ program const options = cmd.optsWithGlobals() as DownloadOptions; const client = getClient(options); const authority = - options.thirdParty === true + options.nonCanonical === true ? (await getKeyPairSigners(options, client.configs))[0].address - : options.thirdParty - ? address(options.thirdParty) + : options.nonCanonical + ? address(options.nonCanonical) : undefined; try { const content = await downloadMetadata( @@ -349,7 +349,7 @@ program }); type SetImmutableOptions = GlobalOptions & { - thirdParty: boolean; + nonCanonical: boolean; }; program .command('set-immutable') @@ -363,7 +363,7 @@ program address ) .option( - '--third-party', + '--non-canonical', 'When provided, a non-canonical metadata account will be updated using the active keypair as the authority.', false ) @@ -375,9 +375,9 @@ program client.rpc, program ); - if (!options.thirdParty && keypair.address !== programAuthority) { + if (!options.nonCanonical && keypair.address !== programAuthority) { logErrorAndExit( - 'You must be the program authority to update a canonical metadata account. Use `--third-party` option to update as a third party.' + 'You must be the program authority to update a canonical metadata account. Use `--non-canonical` option to update as a third party.' ); } const { metadata, programData } = await getPdaDetails({ @@ -406,7 +406,7 @@ program }); type CloseOptions = GlobalOptions & { - thirdParty: boolean; + nonCanonical: boolean; }; program .command('close') @@ -418,7 +418,7 @@ program address ) .option( - '--third-party', + '--non-canonical', 'When provided, a non-canonical metadata account will be closed using the active keypair as the authority.', false ) @@ -430,9 +430,9 @@ program client.rpc, program ); - if (!options.thirdParty && keypair.address !== programAuthority) { + if (!options.nonCanonical && keypair.address !== programAuthority) { logErrorAndExit( - 'You must be the program authority to close a canonical metadata account. Use `--third-party` option to close as a third party.' + 'You must be the program authority to close a canonical metadata account. Use `--non-canonical` option to close as a third party.' ); } const { metadata, programData } = await getPdaDetails({