Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for setMint IX for backfilling #9

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions clients/js/src/generated/accounts/inscriptionMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type InscriptionMetadataAccountData = {
inscriptionBump: Option<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscription>;
mint: Option<PublicKey>;
padding: Array<number>;
};

Expand All @@ -66,6 +67,7 @@ export type InscriptionMetadataAccountDataArgs = {
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscriptionArgs>;
mint: OptionOrNullable<PublicKey>;
padding: Array<number>;
};

Expand All @@ -83,7 +85,8 @@ export function getInscriptionMetadataAccountDataSerializer(): Serializer<
['inscriptionBump', option(u8())],
['updateAuthorities', array(publicKeySerializer())],
['associatedInscriptions', array(getAssociatedInscriptionSerializer())],
['padding', array(u8(), { size: 8 })],
['mint', option(publicKeySerializer())],
['padding', array(u8(), { size: 7 })],
],
{ description: 'InscriptionMetadataAccountData' }
) as Serializer<
Expand Down Expand Up @@ -176,6 +179,7 @@ export function getInscriptionMetadataGpaBuilder(
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscriptionArgs>;
mint: OptionOrNullable<PublicKey>;
padding: Array<number>;
}>({
key: [0, getKeySerializer()],
Expand All @@ -189,7 +193,8 @@ export function getInscriptionMetadataGpaBuilder(
null,
array(getAssociatedInscriptionSerializer()),
],
padding: [null, array(u8(), { size: 8 })],
mint: [null, option(publicKeySerializer())],
padding: [null, array(u8(), { size: 7 })],
})
.deserializeUsing<InscriptionMetadata>((account) =>
deserializeInscriptionMetadata(account)
Expand Down
36 changes: 36 additions & 0 deletions clients/js/src/generated/errors/mplInscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,42 @@ export class AuthorityAlreadyExistsError extends ProgramError {
codeToErrorMap.set(0x10, AuthorityAlreadyExistsError);
nameToErrorMap.set('AuthorityAlreadyExists', AuthorityAlreadyExistsError);

/** RemainingAssociatedInscriptionAccounts: Cannot close Inscription accounts until all Associated Inscriptions are closed. */
export class RemainingAssociatedInscriptionAccountsError extends ProgramError {
readonly name: string = 'RemainingAssociatedInscriptionAccounts';

readonly code: number = 0x11; // 17

constructor(program: Program, cause?: Error) {
super(
'Cannot close Inscription accounts until all Associated Inscriptions are closed.',
program,
cause
);
}
}
codeToErrorMap.set(0x11, RemainingAssociatedInscriptionAccountsError);
nameToErrorMap.set(
'RemainingAssociatedInscriptionAccounts',
RemainingAssociatedInscriptionAccountsError
);

/** InvalidInscriptionMetadataAccount: The inscription metadata account is invalid. */
export class InvalidInscriptionMetadataAccountError extends ProgramError {
readonly name: string = 'InvalidInscriptionMetadataAccount';

readonly code: number = 0x12; // 18

constructor(program: Program, cause?: Error) {
super('The inscription metadata account is invalid.', program, cause);
}
}
codeToErrorMap.set(0x12, InvalidInscriptionMetadataAccountError);
nameToErrorMap.set(
'InvalidInscriptionMetadataAccount',
InvalidInscriptionMetadataAccountError
);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export * from './close';
export * from './createShard';
export * from './initializeAssociatedInscription';
export * from './removeAuthority';
export * from './setMint';
export * from './writeData';
129 changes: 129 additions & 0 deletions clients/js/src/generated/instructions/setMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/metaplex-foundation/kinobi
*/

import {
Context,
Pda,
PublicKey,
Signer,
TransactionBuilder,
transactionBuilder,
} from '@metaplex-foundation/umi';
import {
Serializer,
mapSerializer,
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
getAccountMetasAndSigners,
} from '../shared';

// Accounts.
export type SetMintInstructionAccounts = {
/** The account where data is stored. */
mintInscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
/** The mint that will be used to derive the PDA. */
mintAccount: PublicKey | Pda;
/** The account that will pay for the transaction and rent. */
payer?: Signer;
/** System program */
systemProgram?: PublicKey | Pda;
};

// Data.
export type SetMintInstructionData = { discriminator: number };

export type SetMintInstructionDataArgs = {};

export function getSetMintInstructionDataSerializer(): Serializer<
SetMintInstructionDataArgs,
SetMintInstructionData
> {
return mapSerializer<SetMintInstructionDataArgs, any, SetMintInstructionData>(
struct<SetMintInstructionData>([['discriminator', u8()]], {
description: 'SetMintInstructionData',
}),
(value) => ({ ...value, discriminator: 10 })
) as Serializer<SetMintInstructionDataArgs, SetMintInstructionData>;
}

// Instruction.
export function setMint(
context: Pick<Context, 'payer' | 'programs'>,
input: SetMintInstructionAccounts
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
'mplInscription',
'1NSCRfGeyo7wPUazGbaPBUsTM49e1k2aXewHGARfzSo'
);

// Accounts.
const resolvedAccounts: ResolvedAccountsWithIndices = {
mintInscriptionAccount: {
index: 0,
isWritable: false,
value: input.mintInscriptionAccount ?? null,
},
inscriptionMetadataAccount: {
index: 1,
isWritable: true,
value: input.inscriptionMetadataAccount ?? null,
},
mintAccount: {
index: 2,
isWritable: false,
value: input.mintAccount ?? null,
},
payer: { index: 3, isWritable: true, value: input.payer ?? null },
systemProgram: {
index: 4,
isWritable: false,
value: input.systemProgram ?? null,
},
};

// Default values.
if (!resolvedAccounts.payer.value) {
resolvedAccounts.payer.value = context.payer;
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
'splSystem',
'11111111111111111111111111111111'
);
resolvedAccounts.systemProgram.isWritable = false;
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
resolvedAccounts
).sort((a, b) => a.index - b.index);

// Keys and Signers.
const [keys, signers] = getAccountMetasAndSigners(
orderedAccounts,
'programId',
programId
);

// Data.
const data = getSetMintInstructionDataSerializer().serialize({});

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;

return transactionBuilder([
{ instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
]);
}
5 changes: 4 additions & 1 deletion clients/js/test/initialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */
import { generateSigner } from '@metaplex-foundation/umi';
import { generateSigner, none } from '@metaplex-foundation/umi';
import test from 'ava';
import {
AssociatedInscription,
Expand Down Expand Up @@ -59,6 +59,7 @@ test('it can initialize an Inscription account', async (t) => {
shardDataBefore.count * BigInt(32) + BigInt(shardDataBefore.shardNumber),
updateAuthorities: [umi.identity.publicKey],
associatedInscriptions: [] as AssociatedInscription[],
mint: none(),
});

const jsonData = await umi.rpc.getAccount(inscriptionAccount.publicKey);
Expand Down Expand Up @@ -120,6 +121,7 @@ test('it can initialize multiple Inscription accounts', async (t) => {
BigInt(shardDataBefore.shardNumber),
updateAuthorities: [umi.identity.publicKey],
associatedInscriptions: [] as AssociatedInscription[],
mint: none(),
});

const jsonData = await umi.rpc.getAccount(inscriptionAccount[i].publicKey);
Expand Down Expand Up @@ -178,6 +180,7 @@ test('it can initialize an Inscription account with separate authority', async (
shardDataBefore.count * BigInt(32) + BigInt(shardDataBefore.shardNumber),
updateAuthorities: [authority.publicKey],
associatedInscriptions: [] as AssociatedInscription[],
mint: none(),
});

const jsonData = await umi.rpc.getAccount(inscriptionAccount.publicKey);
Expand Down
4 changes: 3 additions & 1 deletion clients/js/test/initializeFromMint.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateSigner, percentAmount } from '@metaplex-foundation/umi';
import { generateSigner, percentAmount, some } from '@metaplex-foundation/umi';
import test from 'ava';
import {
TokenStandard,
Expand Down Expand Up @@ -84,6 +84,7 @@ test('it can initialize a Mint Inscription account', async (t) => {
shardDataBefore.count * BigInt(32) + BigInt(shardDataBefore.shardNumber),
updateAuthorities: [umi.identity.publicKey],
associatedInscriptions: [] as AssociatedInscription[],
mint: some(mint.publicKey),
});

const jsonData = await umi.rpc.getAccount(inscriptionAccount[0]);
Expand Down Expand Up @@ -208,6 +209,7 @@ test('it can initialize a Mint Inscription account with separate authority', asy
shardDataBefore.count * BigInt(32) + BigInt(shardDataBefore.shardNumber),
updateAuthorities: [authority.publicKey],
associatedInscriptions: [] as AssociatedInscription[],
mint: some(mint.publicKey),
});

const jsonData = await umi.rpc.getAccount(inscriptionAccount[0]);
Expand Down
Loading
Loading