|
| 1 | +/** |
| 2 | + * This code was AUTOGENERATED using the kinobi library. |
| 3 | + * Please DO NOT EDIT THIS FILE, instead use visitors |
| 4 | + * to add features, then rerun kinobi to update it. |
| 5 | + * |
| 6 | + * @see https://github.com/metaplex-foundation/kinobi |
| 7 | + */ |
| 8 | + |
| 9 | +import { |
| 10 | + Context, |
| 11 | + Option, |
| 12 | + OptionOrNullable, |
| 13 | + Pda, |
| 14 | + PublicKey, |
| 15 | + Signer, |
| 16 | + TransactionBuilder, |
| 17 | + transactionBuilder, |
| 18 | +} from '@metaplex-foundation/umi'; |
| 19 | +import { |
| 20 | + Serializer, |
| 21 | + mapSerializer, |
| 22 | + option, |
| 23 | + struct, |
| 24 | + u8, |
| 25 | +} from '@metaplex-foundation/umi/serializers'; |
| 26 | +import { |
| 27 | + ResolvedAccount, |
| 28 | + ResolvedAccountsWithIndices, |
| 29 | + getAccountMetasAndSigners, |
| 30 | +} from '../shared'; |
| 31 | +import { Plugin, PluginArgs, getPluginSerializer } from '../types'; |
| 32 | + |
| 33 | +// Accounts. |
| 34 | +export type UpdatePluginV2InstructionAccounts = { |
| 35 | + /** The address of the asset */ |
| 36 | + asset: PublicKey | Pda; |
| 37 | + /** The collection to which the asset belongs */ |
| 38 | + collection?: PublicKey | Pda; |
| 39 | + /** The account paying for the storage fees */ |
| 40 | + payer?: Signer; |
| 41 | + /** The owner or delegate of the asset */ |
| 42 | + authority?: Signer; |
| 43 | + /** The system program */ |
| 44 | + systemProgram?: PublicKey | Pda; |
| 45 | + /** The SPL Noop Program */ |
| 46 | + logWrapper?: PublicKey | Pda; |
| 47 | + /** Optional buffer account containing plugin data */ |
| 48 | + bufferAccount?: PublicKey | Pda; |
| 49 | +}; |
| 50 | + |
| 51 | +// Data. |
| 52 | +export type UpdatePluginV2InstructionData = { |
| 53 | + discriminator: number; |
| 54 | + plugin: Option<Plugin>; |
| 55 | +}; |
| 56 | + |
| 57 | +export type UpdatePluginV2InstructionDataArgs = { |
| 58 | + plugin: OptionOrNullable<PluginArgs>; |
| 59 | +}; |
| 60 | + |
| 61 | +export function getUpdatePluginV2InstructionDataSerializer(): Serializer< |
| 62 | + UpdatePluginV2InstructionDataArgs, |
| 63 | + UpdatePluginV2InstructionData |
| 64 | +> { |
| 65 | + return mapSerializer< |
| 66 | + UpdatePluginV2InstructionDataArgs, |
| 67 | + any, |
| 68 | + UpdatePluginV2InstructionData |
| 69 | + >( |
| 70 | + struct<UpdatePluginV2InstructionData>( |
| 71 | + [ |
| 72 | + ['discriminator', u8()], |
| 73 | + ['plugin', option(getPluginSerializer())], |
| 74 | + ], |
| 75 | + { description: 'UpdatePluginV2InstructionData' } |
| 76 | + ), |
| 77 | + (value) => ({ ...value, discriminator: 20 }) |
| 78 | + ) as Serializer< |
| 79 | + UpdatePluginV2InstructionDataArgs, |
| 80 | + UpdatePluginV2InstructionData |
| 81 | + >; |
| 82 | +} |
| 83 | + |
| 84 | +// Args. |
| 85 | +export type UpdatePluginV2InstructionArgs = UpdatePluginV2InstructionDataArgs; |
| 86 | + |
| 87 | +// Instruction. |
| 88 | +export function updatePluginV2( |
| 89 | + context: Pick<Context, 'payer' | 'programs'>, |
| 90 | + input: UpdatePluginV2InstructionAccounts & UpdatePluginV2InstructionArgs |
| 91 | +): TransactionBuilder { |
| 92 | + // Program ID. |
| 93 | + const programId = context.programs.getPublicKey( |
| 94 | + 'mplCore', |
| 95 | + 'CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d' |
| 96 | + ); |
| 97 | + |
| 98 | + // Accounts. |
| 99 | + const resolvedAccounts = { |
| 100 | + asset: { |
| 101 | + index: 0, |
| 102 | + isWritable: true as boolean, |
| 103 | + value: input.asset ?? null, |
| 104 | + }, |
| 105 | + collection: { |
| 106 | + index: 1, |
| 107 | + isWritable: true as boolean, |
| 108 | + value: input.collection ?? null, |
| 109 | + }, |
| 110 | + payer: { |
| 111 | + index: 2, |
| 112 | + isWritable: true as boolean, |
| 113 | + value: input.payer ?? null, |
| 114 | + }, |
| 115 | + authority: { |
| 116 | + index: 3, |
| 117 | + isWritable: false as boolean, |
| 118 | + value: input.authority ?? null, |
| 119 | + }, |
| 120 | + systemProgram: { |
| 121 | + index: 4, |
| 122 | + isWritable: false as boolean, |
| 123 | + value: input.systemProgram ?? null, |
| 124 | + }, |
| 125 | + logWrapper: { |
| 126 | + index: 5, |
| 127 | + isWritable: false as boolean, |
| 128 | + value: input.logWrapper ?? null, |
| 129 | + }, |
| 130 | + bufferAccount: { |
| 131 | + index: 6, |
| 132 | + isWritable: false as boolean, |
| 133 | + value: input.bufferAccount ?? null, |
| 134 | + }, |
| 135 | + } satisfies ResolvedAccountsWithIndices; |
| 136 | + |
| 137 | + // Arguments. |
| 138 | + const resolvedArgs: UpdatePluginV2InstructionArgs = { ...input }; |
| 139 | + |
| 140 | + // Default values. |
| 141 | + if (!resolvedAccounts.payer.value) { |
| 142 | + resolvedAccounts.payer.value = context.payer; |
| 143 | + } |
| 144 | + if (!resolvedAccounts.systemProgram.value) { |
| 145 | + resolvedAccounts.systemProgram.value = context.programs.getPublicKey( |
| 146 | + 'splSystem', |
| 147 | + '11111111111111111111111111111111' |
| 148 | + ); |
| 149 | + resolvedAccounts.systemProgram.isWritable = false; |
| 150 | + } |
| 151 | + |
| 152 | + // Accounts in order. |
| 153 | + const orderedAccounts: ResolvedAccount[] = Object.values( |
| 154 | + resolvedAccounts |
| 155 | + ).sort((a, b) => a.index - b.index); |
| 156 | + |
| 157 | + // Keys and Signers. |
| 158 | + const [keys, signers] = getAccountMetasAndSigners( |
| 159 | + orderedAccounts, |
| 160 | + 'programId', |
| 161 | + programId |
| 162 | + ); |
| 163 | + |
| 164 | + // Data. |
| 165 | + const data = getUpdatePluginV2InstructionDataSerializer().serialize( |
| 166 | + resolvedArgs as UpdatePluginV2InstructionDataArgs |
| 167 | + ); |
| 168 | + |
| 169 | + // Bytes Created On Chain. |
| 170 | + const bytesCreatedOnChain = 0; |
| 171 | + |
| 172 | + return transactionBuilder([ |
| 173 | + { instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, |
| 174 | + ]); |
| 175 | +} |
0 commit comments