Skip to content

Commit

Permalink
Merging.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Feb 18, 2024
2 parents 230dcd9 + cc085c7 commit 99f16c6
Show file tree
Hide file tree
Showing 30 changed files with 526 additions and 162 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Check out the [Contributing Guide](./CONTRIBUTING.md) the learn more about how t

TODO:
Today: Functional Asset - utilities, transfer, burn + JS tests, stretch goal compress/decompress
Tomorrow: Migrate, Plugins (Collection and Delgate which contains Freeze) + JS tests, compress/decompress
Tomorrow: Migrate, Plugins (Collection and Delgate which contains Freeze) + JS tests, compress/decompress, royalties
Next day: Lifecycle hooks with Pick 3 PDAs + JS tests
26 changes: 26 additions & 0 deletions clients/js/src/generated/errors/mplAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ export class PluginNotFoundError extends ProgramError {
codeToErrorMap.set(0x4, PluginNotFoundError);
nameToErrorMap.set('PluginNotFound', PluginNotFoundError);

/** IncorrectAccount: Incorrect account */
export class IncorrectAccountError extends ProgramError {
readonly name: string = 'IncorrectAccount';

readonly code: number = 0x5; // 5

constructor(program: Program, cause?: Error) {
super('Incorrect account', program, cause);
}
}
codeToErrorMap.set(0x5, IncorrectAccountError);
nameToErrorMap.set('IncorrectAccount', IncorrectAccountError);

/** IncorrectAssetHash: Incorrect asset hash */
export class IncorrectAssetHashError extends ProgramError {
readonly name: string = 'IncorrectAssetHash';

readonly code: number = 0x6; // 6

constructor(program: Program, cause?: Error) {
super('Incorrect asset hash', program, cause);
}
}
codeToErrorMap.set(0x6, IncorrectAssetHashError);
nameToErrorMap.set('IncorrectAssetHash', IncorrectAssetHashError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
36 changes: 29 additions & 7 deletions clients/js/src/generated/instructions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
ResolvedAccountsWithIndices,
getAccountMetasAndSigners,
} from '../shared';
import {
CompressionProof,
CompressionProofArgs,
getCompressionProofSerializer,
} from '../types';

// Accounts.
export type TransferInstructionAccounts = {
Expand All @@ -43,9 +48,14 @@ export type TransferInstructionAccounts = {
};

// Data.
export type TransferInstructionData = { discriminator: number };
export type TransferInstructionData = {
discriminator: number;
compressionProof: CompressionProof;
};

export type TransferInstructionDataArgs = {};
export type TransferInstructionDataArgs = {
compressionProof: CompressionProofArgs;
};

export function getTransferInstructionDataSerializer(): Serializer<
TransferInstructionDataArgs,
Expand All @@ -56,17 +66,24 @@ export function getTransferInstructionDataSerializer(): Serializer<
any,
TransferInstructionData
>(
struct<TransferInstructionData>([['discriminator', u8()]], {
description: 'TransferInstructionData',
}),
struct<TransferInstructionData>(
[
['discriminator', u8()],
['compressionProof', getCompressionProofSerializer()],
],
{ description: 'TransferInstructionData' }
),
(value) => ({ ...value, discriminator: 4 })
) as Serializer<TransferInstructionDataArgs, TransferInstructionData>;
}

// Args.
export type TransferInstructionArgs = TransferInstructionDataArgs;

// Instruction.
export function transfer(
context: Pick<Context, 'identity' | 'programs'>,
input: TransferInstructionAccounts
input: TransferInstructionAccounts & TransferInstructionArgs
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -96,6 +113,9 @@ export function transfer(
},
};

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

// Default values.
if (!resolvedAccounts.authority.value) {
resolvedAccounts.authority.value = context.identity;
Expand All @@ -114,7 +134,9 @@ export function transfer(
);

// Data.
const data = getTransferInstructionDataSerializer().serialize({});
const data = getTransferInstructionDataSerializer().serialize(
resolvedArgs as TransferInstructionDataArgs
);

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;
Expand Down
38 changes: 32 additions & 6 deletions clients/js/src/generated/types/compressionProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,43 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import { Serializer, struct } from '@metaplex-foundation/umi/serializers';
import { PublicKey } from '@metaplex-foundation/umi';
import {
Serializer,
publicKey as publicKeySerializer,
string,
struct,
} from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '.';

export type CompressionProof = {};
export type CompressionProof = {
key: Key;
updateAuthority: PublicKey;
owner: PublicKey;
name: string;
uri: string;
};

export type CompressionProofArgs = CompressionProof;
export type CompressionProofArgs = {
key: KeyArgs;
updateAuthority: PublicKey;
owner: PublicKey;
name: string;
uri: string;
};

export function getCompressionProofSerializer(): Serializer<
CompressionProofArgs,
CompressionProof
> {
return struct<CompressionProof>([], {
description: 'CompressionProof',
}) as Serializer<CompressionProofArgs, CompressionProof>;
return struct<CompressionProof>(
[
['key', getKeySerializer()],
['updateAuthority', publicKeySerializer()],
['owner', publicKeySerializer()],
['name', string()],
['uri', string()],
],
{ description: 'CompressionProof' }
) as Serializer<CompressionProofArgs, CompressionProof>;
}
19 changes: 19 additions & 0 deletions clients/js/src/generated/types/delegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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 { Serializer, bool, struct } from '@metaplex-foundation/umi/serializers';

export type Delegate = { frozen: boolean };

export type DelegateArgs = Delegate;

export function getDelegateSerializer(): Serializer<DelegateArgs, Delegate> {
return struct<Delegate>([['frozen', bool()]], {
description: 'Delegate',
}) as Serializer<DelegateArgs, Delegate>;
}
1 change: 1 addition & 0 deletions clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './collection';
export * from './compressionProof';
export * from './creator';
export * from './dataState';
export * from './delegate';
export * from './extraAccounts';
export * from './key';
export * from './migrationLevel';
Expand Down
2 changes: 2 additions & 0 deletions clients/js/src/generated/types/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export enum Key {
HashedAsset,
Collection,
HashedCollection,
PluginHeader,
PluginRegistry,
}

export type KeyArgs = Key;
Expand Down
89 changes: 75 additions & 14 deletions clients/js/src/generated/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,83 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers';
import {
GetDataEnumKind,
GetDataEnumKindContent,
Serializer,
dataEnum,
struct,
tuple,
unit,
} from '@metaplex-foundation/umi/serializers';
import { Delegate, DelegateArgs, getDelegateSerializer } from '.';

export enum Plugin {
Reserved,
Royalties,
MasterEdition,
PrintEdition,
Delegate,
Inscription,
}
export type Plugin =
| { __kind: 'Reserved' }
| { __kind: 'Royalties' }
| { __kind: 'MasterEdition' }
| { __kind: 'PrintEdition' }
| { __kind: 'Delegate'; fields: [Delegate] }
| { __kind: 'Inscription' };

export type PluginArgs = Plugin;
export type PluginArgs =
| { __kind: 'Reserved' }
| { __kind: 'Royalties' }
| { __kind: 'MasterEdition' }
| { __kind: 'PrintEdition' }
| { __kind: 'Delegate'; fields: [DelegateArgs] }
| { __kind: 'Inscription' };

export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
return scalarEnum<Plugin>(Plugin, { description: 'Plugin' }) as Serializer<
PluginArgs,
Plugin
>;
return dataEnum<Plugin>(
[
['Reserved', unit()],
['Royalties', unit()],
['MasterEdition', unit()],
['PrintEdition', unit()],
[
'Delegate',
struct<GetDataEnumKindContent<Plugin, 'Delegate'>>([
['fields', tuple([getDelegateSerializer()])],
]),
],
['Inscription', unit()],
],
{ description: 'Plugin' }
) as Serializer<PluginArgs, Plugin>;
}

// Data Enum Helpers.
export function plugin(
kind: 'Reserved'
): GetDataEnumKind<PluginArgs, 'Reserved'>;
export function plugin(
kind: 'Royalties'
): GetDataEnumKind<PluginArgs, 'Royalties'>;
export function plugin(
kind: 'MasterEdition'
): GetDataEnumKind<PluginArgs, 'MasterEdition'>;
export function plugin(
kind: 'PrintEdition'
): GetDataEnumKind<PluginArgs, 'PrintEdition'>;
export function plugin(
kind: 'Delegate',
data: GetDataEnumKindContent<PluginArgs, 'Delegate'>['fields']
): GetDataEnumKind<PluginArgs, 'Delegate'>;
export function plugin(
kind: 'Inscription'
): GetDataEnumKind<PluginArgs, 'Inscription'>;
export function plugin<K extends PluginArgs['__kind']>(
kind: K,
data?: any
): Extract<PluginArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
: { __kind: kind, ...(data ?? {}) };
}
export function isPlugin<K extends Plugin['__kind']>(
kind: K,
value: Plugin
): value is Plugin & { __kind: K } {
return value.__kind === kind;
}
14 changes: 5 additions & 9 deletions clients/js/src/generated/types/pluginHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import {
Serializer,
struct,
u64,
u8,
} from '@metaplex-foundation/umi/serializers';
import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '.';

export type PluginHeader = { version: number; pluginMapOffset: bigint };
export type PluginHeader = { key: Key; pluginMapOffset: bigint };

export type PluginHeaderArgs = {
version: number;
key: KeyArgs;
pluginMapOffset: number | bigint;
};

Expand All @@ -26,7 +22,7 @@ export function getPluginHeaderSerializer(): Serializer<
> {
return struct<PluginHeader>(
[
['version', u8()],
['key', getKeySerializer()],
['pluginMapOffset', u64()],
],
{ description: 'PluginHeader' }
Expand Down
16 changes: 15 additions & 1 deletion clients/js/src/generated/types/pluginRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ import {
tuple,
} from '@metaplex-foundation/umi/serializers';
import {
Authority,
AuthorityArgs,
Key,
KeyArgs,
RegistryData,
RegistryDataArgs,
getAuthoritySerializer,
getKeySerializer,
getRegistryDataSerializer,
} from '.';

export type PluginRegistry = { registry: Array<[Key, RegistryData]> };
export type PluginRegistry = {
key: Key;
registry: Array<[Key, RegistryData]>;
externalPlugins: Array<[Authority, RegistryData]>;
};

export type PluginRegistryArgs = {
key: KeyArgs;
registry: Array<[KeyArgs, RegistryDataArgs]>;
externalPlugins: Array<[AuthorityArgs, RegistryDataArgs]>;
};

export function getPluginRegistrySerializer(): Serializer<
Expand All @@ -33,10 +42,15 @@ export function getPluginRegistrySerializer(): Serializer<
> {
return struct<PluginRegistry>(
[
['key', getKeySerializer()],
[
'registry',
array(tuple([getKeySerializer(), getRegistryDataSerializer()])),
],
[
'externalPlugins',
array(tuple([getAuthoritySerializer(), getRegistryDataSerializer()])),
],
],
{ description: 'PluginRegistry' }
) as Serializer<PluginRegistryArgs, PluginRegistry>;
Expand Down
6 changes: 6 additions & 0 deletions clients/rust/src/generated/errors/mpl_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub enum MplAssetError {
/// 4 (0x4) - Plugin not found
#[error("Plugin not found")]
PluginNotFound,
/// 5 (0x5) - Incorrect account
#[error("Incorrect account")]
IncorrectAccount,
/// 6 (0x6) - Incorrect asset hash
#[error("Incorrect asset hash")]
IncorrectAssetHash,
}

impl solana_program::program_error::PrintProgramError for MplAssetError {
Expand Down
Loading

0 comments on commit 99f16c6

Please sign in to comment.