Skip to content

Commit

Permalink
Adding basic collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Feb 27, 2024
1 parent c98251c commit 5dd5cba
Show file tree
Hide file tree
Showing 44 changed files with 1,597 additions and 77 deletions.
159 changes: 159 additions & 0 deletions clients/js/src/generated/accounts/collectionData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* 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 {
Account,
Context,
Pda,
PublicKey,
RpcAccount,
RpcGetAccountOptions,
RpcGetAccountsOptions,
assertAccountExists,
deserializeAccount,
gpaBuilder,
publicKey as toPublicKey,
} from '@metaplex-foundation/umi';
import {
Serializer,
publicKey as publicKeySerializer,
string,
struct,
u32,
} from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '../types';

export type CollectionData = Account<CollectionDataAccountData>;

export type CollectionDataAccountData = {
key: Key;
updateAuthority: PublicKey;
name: string;
uri: string;
numMinted: number;
currentSize: number;
};

export type CollectionDataAccountDataArgs = {
key: KeyArgs;
updateAuthority: PublicKey;
name: string;
uri: string;
numMinted: number;
currentSize: number;
};

export function getCollectionDataAccountDataSerializer(): Serializer<
CollectionDataAccountDataArgs,
CollectionDataAccountData
> {
return struct<CollectionDataAccountData>(
[
['key', getKeySerializer()],
['updateAuthority', publicKeySerializer()],
['name', string()],
['uri', string()],
['numMinted', u32()],
['currentSize', u32()],
],
{ description: 'CollectionDataAccountData' }
) as Serializer<CollectionDataAccountDataArgs, CollectionDataAccountData>;
}

export function deserializeCollectionData(
rawAccount: RpcAccount
): CollectionData {
return deserializeAccount(
rawAccount,
getCollectionDataAccountDataSerializer()
);
}

export async function fetchCollectionData(
context: Pick<Context, 'rpc'>,
publicKey: PublicKey | Pda,
options?: RpcGetAccountOptions
): Promise<CollectionData> {
const maybeAccount = await context.rpc.getAccount(
toPublicKey(publicKey, false),
options
);
assertAccountExists(maybeAccount, 'CollectionData');
return deserializeCollectionData(maybeAccount);
}

export async function safeFetchCollectionData(
context: Pick<Context, 'rpc'>,
publicKey: PublicKey | Pda,
options?: RpcGetAccountOptions
): Promise<CollectionData | null> {
const maybeAccount = await context.rpc.getAccount(
toPublicKey(publicKey, false),
options
);
return maybeAccount.exists ? deserializeCollectionData(maybeAccount) : null;
}

export async function fetchAllCollectionData(
context: Pick<Context, 'rpc'>,
publicKeys: Array<PublicKey | Pda>,
options?: RpcGetAccountsOptions
): Promise<CollectionData[]> {
const maybeAccounts = await context.rpc.getAccounts(
publicKeys.map((key) => toPublicKey(key, false)),
options
);
return maybeAccounts.map((maybeAccount) => {
assertAccountExists(maybeAccount, 'CollectionData');
return deserializeCollectionData(maybeAccount);
});
}

export async function safeFetchAllCollectionData(
context: Pick<Context, 'rpc'>,
publicKeys: Array<PublicKey | Pda>,
options?: RpcGetAccountsOptions
): Promise<CollectionData[]> {
const maybeAccounts = await context.rpc.getAccounts(
publicKeys.map((key) => toPublicKey(key, false)),
options
);
return maybeAccounts
.filter((maybeAccount) => maybeAccount.exists)
.map((maybeAccount) =>
deserializeCollectionData(maybeAccount as RpcAccount)
);
}

export function getCollectionDataGpaBuilder(
context: Pick<Context, 'rpc' | 'programs'>
) {
const programId = context.programs.getPublicKey(
'mplCoreProgram',
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL'
);
return gpaBuilder(context, programId)
.registerFields<{
key: KeyArgs;
updateAuthority: PublicKey;
name: string;
uri: string;
numMinted: number;
currentSize: number;
}>({
key: [0, getKeySerializer()],
updateAuthority: [1, publicKeySerializer()],
name: [33, string()],
uri: [null, string()],
numMinted: [null, u32()],
currentSize: [null, u32()],
})
.deserializeUsing<CollectionData>((account) =>
deserializeCollectionData(account)
);
}
1 change: 1 addition & 0 deletions clients/js/src/generated/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

export * from './asset';
export * from './collectionData';
export * from './hashedAsset';
export * from './pluginHeader';
export * from './pluginRegistry';
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/addAuthority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function getAddAuthorityInstructionDataSerializer(): Serializer<
],
{ description: 'AddAuthorityInstructionData' }
),
(value) => ({ ...value, discriminator: 4 })
(value) => ({ ...value, discriminator: 5 })
) as Serializer<AddAuthorityInstructionDataArgs, AddAuthorityInstructionData>;
}

Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/addPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function getAddPluginInstructionDataSerializer(): Serializer<
],
{ description: 'AddPluginInstructionData' }
),
(value) => ({ ...value, discriminator: 1 })
(value) => ({ ...value, discriminator: 2 })
) as Serializer<AddPluginInstructionDataArgs, AddPluginInstructionData>;
}

Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function getBurnInstructionDataSerializer(): Serializer<
],
{ description: 'BurnInstructionData' }
),
(value) => ({ ...value, discriminator: 6 })
(value) => ({ ...value, discriminator: 7 })
) as Serializer<BurnInstructionDataArgs, BurnInstructionData>;
}

Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function getCompressInstructionDataSerializer(): Serializer<
struct<CompressInstructionData>([['discriminator', u8()]], {
description: 'CompressInstructionData',
}),
(value) => ({ ...value, discriminator: 9 })
(value) => ({ ...value, discriminator: 10 })
) as Serializer<CompressInstructionDataArgs, CompressInstructionData>;
}

Expand Down
159 changes: 159 additions & 0 deletions clients/js/src/generated/instructions/createCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* 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,
array,
mapSerializer,
string,
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
getAccountMetasAndSigners,
} from '../shared';
import { Plugin, PluginArgs, getPluginSerializer } from '../types';

// Accounts.
export type CreateCollectionInstructionAccounts = {
/** The address of the new asset */
collectionAddress: Signer;
/** The authority of the new asset */
updateAuthority?: PublicKey | Pda;
/** The account paying for the storage fees */
payer?: Signer;
/** The owner of the new asset. Defaults to the authority if not present. */
owner?: PublicKey | Pda;
/** The system program */
systemProgram?: PublicKey | Pda;
};

// Data.
export type CreateCollectionInstructionData = {
discriminator: number;
name: string;
uri: string;
plugins: Array<Plugin>;
};

export type CreateCollectionInstructionDataArgs = {
name: string;
uri: string;
plugins: Array<PluginArgs>;
};

export function getCreateCollectionInstructionDataSerializer(): Serializer<
CreateCollectionInstructionDataArgs,
CreateCollectionInstructionData
> {
return mapSerializer<
CreateCollectionInstructionDataArgs,
any,
CreateCollectionInstructionData
>(
struct<CreateCollectionInstructionData>(
[
['discriminator', u8()],
['name', string()],
['uri', string()],
['plugins', array(getPluginSerializer())],
],
{ description: 'CreateCollectionInstructionData' }
),
(value) => ({ ...value, discriminator: 1 })
) as Serializer<
CreateCollectionInstructionDataArgs,
CreateCollectionInstructionData
>;
}

// Args.
export type CreateCollectionInstructionArgs =
CreateCollectionInstructionDataArgs;

// Instruction.
export function createCollection(
context: Pick<Context, 'payer' | 'programs'>,
input: CreateCollectionInstructionAccounts & CreateCollectionInstructionArgs
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
'mplCoreProgram',
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL'
);

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

// Arguments.
const resolvedArgs: CreateCollectionInstructionArgs = { ...input };

// 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 = getCreateCollectionInstructionDataSerializer().serialize(
resolvedArgs as CreateCollectionInstructionDataArgs
);

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

return transactionBuilder([
{ instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
]);
}
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/decompress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function getDecompressInstructionDataSerializer(): Serializer<
],
{ description: 'DecompressInstructionData' }
),
(value) => ({ ...value, discriminator: 10 })
(value) => ({ ...value, discriminator: 11 })
) as Serializer<DecompressInstructionDataArgs, DecompressInstructionData>;
}

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 @@ -11,6 +11,7 @@ export * from './addPlugin';
export * from './burn';
export * from './compress';
export * from './create';
export * from './createCollection';
export * from './decompress';
export * from './removeAuthority';
export * from './removePlugin';
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/removeAuthority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function getRemoveAuthorityInstructionDataSerializer(): Serializer<
],
{ description: 'RemoveAuthorityInstructionData' }
),
(value) => ({ ...value, discriminator: 5 })
(value) => ({ ...value, discriminator: 6 })
) as Serializer<
RemoveAuthorityInstructionDataArgs,
RemoveAuthorityInstructionData
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/removePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function getRemovePluginInstructionDataSerializer(): Serializer<
],
{ description: 'RemovePluginInstructionData' }
),
(value) => ({ ...value, discriminator: 2 })
(value) => ({ ...value, discriminator: 3 })
) as Serializer<RemovePluginInstructionDataArgs, RemovePluginInstructionData>;
}

Expand Down
Loading

0 comments on commit 5dd5cba

Please sign in to comment.