Skip to content

Commit

Permalink
Merge branch 'third-party-plugins-staging' into nhan/rename-external-…
Browse files Browse the repository at this point in the history
…plugin

* third-party-plugins-staging:
  bump version v1-alpha
  bump version v1-alpha
  Oracle uninitialized variant (#116)
  Improve Oracle account deserialization error handling (#115)
  • Loading branch information
nhanphan committed May 10, 2024
2 parents c8db7ff + dab9395 commit e3bc52e
Show file tree
Hide file tree
Showing 15 changed files with 499 additions and 45 deletions.
2 changes: 1 addition & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@ava/typescript": "^5.0.0",
"@metaplex-foundation/mpl-core-oracle-example": "^0.0.1",
"@metaplex-foundation/mpl-core-oracle-example": "^0.0.2",
"@metaplex-foundation/mpl-toolbox": "^0.8.0",
"@metaplex-foundation/umi": "^0.8.10",
"@metaplex-foundation/umi-bundle-tests": "^0.8.10",
Expand Down
16 changes: 8 additions & 8 deletions clients/js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions clients/js/src/generated/errors/mplCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,15 @@ export class RequiresLifecycleCheckError extends ProgramError {
codeToErrorMap.set(0x24, RequiresLifecycleCheckError);
nameToErrorMap.set('RequiresLifecycleCheck', RequiresLifecycleCheckError);

/** DuplicateLifecycleChecks: Duplicate lifecycle checks were provided for external plugin */
/** DuplicateLifecycleChecks: Duplicate lifecycle checks were provided for external plugin */
export class DuplicateLifecycleChecksError extends ProgramError {
override readonly name: string = 'DuplicateLifecycleChecks';

readonly code: number = 0x25; // 37

constructor(program: Program, cause?: Error) {
super(
'Duplicate lifecycle checks were provided for external plugin ',
'Duplicate lifecycle checks were provided for external plugin',
program,
cause
);
Expand All @@ -543,6 +543,35 @@ export class DuplicateLifecycleChecksError extends ProgramError {
codeToErrorMap.set(0x25, DuplicateLifecycleChecksError);
nameToErrorMap.set('DuplicateLifecycleChecks', DuplicateLifecycleChecksError);

/** InvalidOracleAccountData: Could not read from oracle account */
export class InvalidOracleAccountDataError extends ProgramError {
override readonly name: string = 'InvalidOracleAccountData';

readonly code: number = 0x26; // 38

constructor(program: Program, cause?: Error) {
super('Could not read from oracle account', program, cause);
}
}
codeToErrorMap.set(0x26, InvalidOracleAccountDataError);
nameToErrorMap.set('InvalidOracleAccountData', InvalidOracleAccountDataError);

/** UninitializedOracleAccount: Oracle account is uninitialized */
export class UninitializedOracleAccountError extends ProgramError {
override readonly name: string = 'UninitializedOracleAccount';

readonly code: number = 0x27; // 39

constructor(program: Program, cause?: Error) {
super('Oracle account is uninitialized', program, cause);
}
}
codeToErrorMap.set(0x27, UninitializedOracleAccountError);
nameToErrorMap.set(
'UninitializedOracleAccount',
UninitializedOracleAccountError
);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
6 changes: 5 additions & 1 deletion clients/js/src/generated/types/baseExtraAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import { PublicKey } from '@metaplex-foundation/umi';
import { Option, OptionOrNullable, PublicKey } from '@metaplex-foundation/umi';
import {
GetDataEnumKind,
GetDataEnumKindContent,
Serializer,
array,
bool,
dataEnum,
option,
publicKey as publicKeySerializer,
struct,
} from '@metaplex-foundation/umi/serializers';
Expand All @@ -32,6 +33,7 @@ export type BaseExtraAccount =
| {
__kind: 'CustomPda';
seeds: Array<BaseSeed>;
customProgramId: Option<PublicKey>;
isSigner: boolean;
isWritable: boolean;
}
Expand All @@ -55,6 +57,7 @@ export type BaseExtraAccountArgs =
| {
__kind: 'CustomPda';
seeds: Array<BaseSeedArgs>;
customProgramId: OptionOrNullable<PublicKey>;
isSigner: boolean;
isWritable: boolean;
}
Expand Down Expand Up @@ -116,6 +119,7 @@ export function getBaseExtraAccountSerializer(): Serializer<
'CustomPda',
struct<GetDataEnumKindContent<BaseExtraAccount, 'CustomPda'>>([
['seeds', array(getBaseSeedSerializer())],
['customProgramId', option(publicKeySerializer())],
['isSigner', bool()],
['isWritable', bool()],
]),
Expand Down
37 changes: 23 additions & 14 deletions clients/js/src/generated/types/oracleValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,41 @@ import {
Serializer,
dataEnum,
struct,
unit,
} from '@metaplex-foundation/umi/serializers';
import {
ExternalValidationResult,
ExternalValidationResultArgs,
getExternalValidationResultSerializer,
} from '.';

export type OracleValidation = {
__kind: 'V1';
create: ExternalValidationResult;
transfer: ExternalValidationResult;
burn: ExternalValidationResult;
update: ExternalValidationResult;
};
export type OracleValidation =
| { __kind: 'Uninitialized' }
| {
__kind: 'V1';
create: ExternalValidationResult;
transfer: ExternalValidationResult;
burn: ExternalValidationResult;
update: ExternalValidationResult;
};

export type OracleValidationArgs = {
__kind: 'V1';
create: ExternalValidationResultArgs;
transfer: ExternalValidationResultArgs;
burn: ExternalValidationResultArgs;
update: ExternalValidationResultArgs;
};
export type OracleValidationArgs =
| { __kind: 'Uninitialized' }
| {
__kind: 'V1';
create: ExternalValidationResultArgs;
transfer: ExternalValidationResultArgs;
burn: ExternalValidationResultArgs;
update: ExternalValidationResultArgs;
};

export function getOracleValidationSerializer(): Serializer<
OracleValidationArgs,
OracleValidation
> {
return dataEnum<OracleValidation>(
[
['Uninitialized', unit()],
[
'V1',
struct<GetDataEnumKindContent<OracleValidation, 'V1'>>([
Expand All @@ -56,6 +62,9 @@ export function getOracleValidationSerializer(): Serializer<
}

// Data Enum Helpers.
export function oracleValidation(
kind: 'Uninitialized'
): GetDataEnumKind<OracleValidationArgs, 'Uninitialized'>;
export function oracleValidation(
kind: 'V1',
data: GetDataEnumKindContent<OracleValidationArgs, 'V1'>
Expand Down
27 changes: 18 additions & 9 deletions clients/js/src/helpers/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ export async function validateTransfer(
return null;
});

const oraclePass = oracleValidations.every(
(v) => v?.transfer === ExternalValidationResult.Pass
);
const oraclePass = oracleValidations.every((v) => {
if (v?.__kind === 'Uninitialized') {
return false;
}
return v?.transfer === ExternalValidationResult.Pass;
});
if (!oraclePass) {
return LifecycleValidationError.OracleValidationFailed;
}
Expand Down Expand Up @@ -284,9 +287,12 @@ export async function validateBurn(
return null;
});

const oraclePass = oracleValidations.every(
(v) => v?.burn === ExternalValidationResult.Pass
);
const oraclePass = oracleValidations.every((v) => {
if (v?.__kind === 'Uninitialized') {
return false;
}
return v?.burn === ExternalValidationResult.Pass;
});
if (!oraclePass) {
return LifecycleValidationError.OracleValidationFailed;
}
Expand Down Expand Up @@ -373,9 +379,12 @@ export async function validateUpdate(
return null;
});

const oraclePass = oracleValidations.every(
(v) => v?.update === ExternalValidationResult.Pass
);
const oraclePass = oracleValidations.every((v) => {
if (v?.__kind === 'Uninitialized') {
return false;
}
return v?.update === ExternalValidationResult.Pass;
});
if (!oraclePass) {
return LifecycleValidationError.OracleValidationFailed;
}
Expand Down
7 changes: 5 additions & 2 deletions clients/js/src/plugins/extraAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@metaplex-foundation/umi/serializers';
import { BaseExtraAccount } from '../generated';
import { Seed, seedFromBase, seedToBase } from './seed';
import { RenameToType } from '../utils';
import { RenameToType, someOrNone, unwrapOption } from '../utils';

export const PRECONFIGURED_SEED = 'mpl-core';

Expand Down Expand Up @@ -33,6 +33,7 @@ export type ExtraAccount =
| {
type: 'CustomPda';
seeds: Array<Seed>;
customProgramId?: PublicKey;
isSigner?: boolean;
isWritable?: boolean;
}
Expand Down Expand Up @@ -120,7 +121,7 @@ export function extraAccountToAccountMeta(
case 'CustomPda':
return {
pubkey: context.eddsa.findPda(
inputs.program!,
e.customProgramId ? e.customProgramId : inputs.program!,
e.seeds.map((seed) => {
switch (seed.type) {
case 'Collection':
Expand Down Expand Up @@ -162,6 +163,7 @@ export function extraAccountToBase(s: ExtraAccount): BaseExtraAccount {
__kind: 'CustomPda',
...acccountMeta,
seeds: s.seeds.map(seedToBase),
customProgramId: someOrNone(s.customProgramId),
};
}
if (s.type === 'Address') {
Expand All @@ -185,6 +187,7 @@ export function extraAccountFromBase(s: BaseExtraAccount): ExtraAccount {
isSigner: s.isSigner,
isWritable: s.isWritable,
seeds: s.seeds.map(seedFromBase),
customProgramId: unwrapOption(s.customProgramId),
};
}
if (s.__kind === 'Address') {
Expand Down
Loading

0 comments on commit e3bc52e

Please sign in to comment.