Skip to content

Commit

Permalink
Oracle account type (#82)
Browse files Browse the repository at this point in the history
* Regenerate IDL and clients

* Add Oracle validation type

* Regenerate IDL and clients

* Update JS SDK for ValidationResultsOffset

* fix minor type issues

---------

Co-authored-by: Nhan Phan <[email protected]>
  • Loading branch information
danenbm and nhanphan authored Apr 24, 2024
1 parent 8ef4629 commit 6464c2a
Show file tree
Hide file tree
Showing 28 changed files with 493 additions and 16 deletions.
4 changes: 2 additions & 2 deletions clients/js/src/generated/types/baseExternalPluginInitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ export function baseExternalPluginInitInfo(
>['fields']
): GetDataEnumKind<BaseExternalPluginInitInfoArgs, 'DataStore'>;
export function baseExternalPluginInitInfo<
K extends BaseExternalPluginInitInfoArgs['__kind']
K extends BaseExternalPluginInitInfoArgs['__kind'],
>(kind: K, data?: any): Extract<BaseExternalPluginInitInfoArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
: { __kind: kind, ...(data ?? {}) };
}
export function isBaseExternalPluginInitInfo<
K extends BaseExternalPluginInitInfo['__kind']
K extends BaseExternalPluginInitInfo['__kind'],
>(
kind: K,
value: BaseExternalPluginInitInfo
Expand Down
4 changes: 2 additions & 2 deletions clients/js/src/generated/types/baseExternalPluginKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export function baseExternalPluginKey(
data: GetDataEnumKindContent<BaseExternalPluginKeyArgs, 'DataStore'>['fields']
): GetDataEnumKind<BaseExternalPluginKeyArgs, 'DataStore'>;
export function baseExternalPluginKey<
K extends BaseExternalPluginKeyArgs['__kind']
K extends BaseExternalPluginKeyArgs['__kind'],
>(kind: K, data?: any): Extract<BaseExternalPluginKeyArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
: { __kind: kind, ...(data ?? {}) };
}
export function isBaseExternalPluginKey<
K extends BaseExternalPluginKey['__kind']
K extends BaseExternalPluginKey['__kind'],
>(
kind: K,
value: BaseExternalPluginKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function baseExternalPluginUpdateInfo(
>['fields']
): GetDataEnumKind<BaseExternalPluginUpdateInfoArgs, 'DataStore'>;
export function baseExternalPluginUpdateInfo<
K extends BaseExternalPluginUpdateInfoArgs['__kind']
K extends BaseExternalPluginUpdateInfoArgs['__kind'],
>(
kind: K,
data?: any
Expand All @@ -101,7 +101,7 @@ export function baseExternalPluginUpdateInfo<
: { __kind: kind, ...(data ?? {}) };
}
export function isBaseExternalPluginUpdateInfo<
K extends BaseExternalPluginUpdateInfo['__kind']
K extends BaseExternalPluginUpdateInfo['__kind'],
>(
kind: K,
value: BaseExternalPluginUpdateInfo
Expand Down
6 changes: 6 additions & 0 deletions clients/js/src/generated/types/baseOracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ import {
import {
BaseExtraAccount,
BaseExtraAccountArgs,
BaseValidationResultsOffset,
BaseValidationResultsOffsetArgs,
getBaseExtraAccountSerializer,
getBaseValidationResultsOffsetSerializer,
} from '.';

export type BaseOracle = {
baseAddress: PublicKey;
pda: Option<BaseExtraAccount>;
resultsOffset: BaseValidationResultsOffset;
};

export type BaseOracleArgs = {
baseAddress: PublicKey;
pda: OptionOrNullable<BaseExtraAccountArgs>;
resultsOffset: BaseValidationResultsOffsetArgs;
};

export function getBaseOracleSerializer(): Serializer<
Expand All @@ -37,6 +42,7 @@ export function getBaseOracleSerializer(): Serializer<
[
['baseAddress', publicKeySerializer()],
['pda', option(getBaseExtraAccountSerializer())],
['resultsOffset', getBaseValidationResultsOffsetSerializer()],
],
{ description: 'BaseOracle' }
) as Serializer<BaseOracleArgs, BaseOracle>;
Expand Down
6 changes: 6 additions & 0 deletions clients/js/src/generated/types/baseOracleInitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import {
BaseExtraAccountArgs,
BasePluginAuthority,
BasePluginAuthorityArgs,
BaseValidationResultsOffset,
BaseValidationResultsOffsetArgs,
ExternalCheckResult,
ExternalCheckResultArgs,
HookableLifecycleEvent,
HookableLifecycleEventArgs,
getBaseExtraAccountSerializer,
getBasePluginAuthoritySerializer,
getBaseValidationResultsOffsetSerializer,
getExternalCheckResultSerializer,
getHookableLifecycleEventSerializer,
} from '.';
Expand All @@ -35,6 +38,7 @@ export type BaseOracleInitInfo = {
initPluginAuthority: Option<BasePluginAuthority>;
lifecycleChecks: Option<Array<[HookableLifecycleEvent, ExternalCheckResult]>>;
pda: Option<BaseExtraAccount>;
resultsOffset: Option<BaseValidationResultsOffset>;
};

export type BaseOracleInitInfoArgs = {
Expand All @@ -44,6 +48,7 @@ export type BaseOracleInitInfoArgs = {
Array<[HookableLifecycleEventArgs, ExternalCheckResultArgs]>
>;
pda: OptionOrNullable<BaseExtraAccountArgs>;
resultsOffset: OptionOrNullable<BaseValidationResultsOffsetArgs>;
};

export function getBaseOracleInitInfoSerializer(): Serializer<
Expand All @@ -66,6 +71,7 @@ export function getBaseOracleInitInfoSerializer(): Serializer<
),
],
['pda', option(getBaseExtraAccountSerializer())],
['resultsOffset', option(getBaseValidationResultsOffsetSerializer())],
],
{ description: 'BaseOracleInitInfo' }
) as Serializer<BaseOracleInitInfoArgs, BaseOracleInitInfo>;
Expand Down
6 changes: 6 additions & 0 deletions clients/js/src/generated/types/baseOracleUpdateInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,30 @@ import {
import {
BaseExtraAccount,
BaseExtraAccountArgs,
BaseValidationResultsOffset,
BaseValidationResultsOffsetArgs,
ExternalCheckResult,
ExternalCheckResultArgs,
HookableLifecycleEvent,
HookableLifecycleEventArgs,
getBaseExtraAccountSerializer,
getBaseValidationResultsOffsetSerializer,
getExternalCheckResultSerializer,
getHookableLifecycleEventSerializer,
} from '.';

export type BaseOracleUpdateInfo = {
lifecycleChecks: Option<Array<[HookableLifecycleEvent, ExternalCheckResult]>>;
pda: Option<BaseExtraAccount>;
resultsOffset: Option<BaseValidationResultsOffset>;
};

export type BaseOracleUpdateInfoArgs = {
lifecycleChecks: OptionOrNullable<
Array<[HookableLifecycleEventArgs, ExternalCheckResultArgs]>
>;
pda: OptionOrNullable<BaseExtraAccountArgs>;
resultsOffset: OptionOrNullable<BaseValidationResultsOffsetArgs>;
};

export function getBaseOracleUpdateInfoSerializer(): Serializer<
Expand All @@ -56,6 +61,7 @@ export function getBaseOracleUpdateInfoSerializer(): Serializer<
),
],
['pda', option(getBaseExtraAccountSerializer())],
['resultsOffset', option(getBaseValidationResultsOffsetSerializer())],
],
{ description: 'BaseOracleUpdateInfo' }
) as Serializer<BaseOracleUpdateInfoArgs, BaseOracleUpdateInfo>;
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/types/basePluginAuthority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function basePluginAuthority(
data: GetDataEnumKindContent<BasePluginAuthorityArgs, 'Address'>
): GetDataEnumKind<BasePluginAuthorityArgs, 'Address'>;
export function basePluginAuthority<
K extends BasePluginAuthorityArgs['__kind']
K extends BasePluginAuthorityArgs['__kind'],
>(kind: K, data?: any): Extract<BasePluginAuthorityArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/types/baseUpdateAuthority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function baseUpdateAuthority(
data: GetDataEnumKindContent<BaseUpdateAuthorityArgs, 'Collection'>['fields']
): GetDataEnumKind<BaseUpdateAuthorityArgs, 'Collection'>;
export function baseUpdateAuthority<
K extends BaseUpdateAuthorityArgs['__kind']
K extends BaseUpdateAuthorityArgs['__kind'],
>(kind: K, data?: any): Extract<BaseUpdateAuthorityArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
Expand Down
80 changes: 80 additions & 0 deletions clients/js/src/generated/types/baseValidationResultsOffset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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 {
GetDataEnumKind,
GetDataEnumKindContent,
Serializer,
dataEnum,
struct,
tuple,
u64,
unit,
} from '@metaplex-foundation/umi/serializers';

export type BaseValidationResultsOffset =
| { __kind: 'NoOffset' }
| { __kind: 'Anchor' }
| { __kind: 'Custom'; fields: [bigint] };

export type BaseValidationResultsOffsetArgs =
| { __kind: 'NoOffset' }
| { __kind: 'Anchor' }
| { __kind: 'Custom'; fields: [number | bigint] };

export function getBaseValidationResultsOffsetSerializer(): Serializer<
BaseValidationResultsOffsetArgs,
BaseValidationResultsOffset
> {
return dataEnum<BaseValidationResultsOffset>(
[
['NoOffset', unit()],
['Anchor', unit()],
[
'Custom',
struct<GetDataEnumKindContent<BaseValidationResultsOffset, 'Custom'>>([
['fields', tuple([u64()])],
]),
],
],
{ description: 'BaseValidationResultsOffset' }
) as Serializer<BaseValidationResultsOffsetArgs, BaseValidationResultsOffset>;
}

// Data Enum Helpers.
export function baseValidationResultsOffset(
kind: 'NoOffset'
): GetDataEnumKind<BaseValidationResultsOffsetArgs, 'NoOffset'>;
export function baseValidationResultsOffset(
kind: 'Anchor'
): GetDataEnumKind<BaseValidationResultsOffsetArgs, 'Anchor'>;
export function baseValidationResultsOffset(
kind: 'Custom',
data: GetDataEnumKindContent<
BaseValidationResultsOffsetArgs,
'Custom'
>['fields']
): GetDataEnumKind<BaseValidationResultsOffsetArgs, 'Custom'>;
export function baseValidationResultsOffset<
K extends BaseValidationResultsOffsetArgs['__kind'],
>(
kind: K,
data?: any
): Extract<BaseValidationResultsOffsetArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
: { __kind: kind, ...(data ?? {}) };
}
export function isBaseValidationResultsOffset<
K extends BaseValidationResultsOffset['__kind'],
>(
kind: K,
value: BaseValidationResultsOffset
): value is BaseValidationResultsOffset & { __kind: K } {
return value.__kind === kind;
}
26 changes: 26 additions & 0 deletions clients/js/src/generated/types/externalValidationResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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, scalarEnum } from '@metaplex-foundation/umi/serializers';

export enum ExternalValidationResult {
Approved,
Rejected,
Pass,
}

export type ExternalValidationResultArgs = ExternalValidationResult;

export function getExternalValidationResultSerializer(): Serializer<
ExternalValidationResultArgs,
ExternalValidationResult
> {
return scalarEnum<ExternalValidationResult>(ExternalValidationResult, {
description: 'ExternalValidationResult',
}) as Serializer<ExternalValidationResultArgs, ExternalValidationResult>;
}
3 changes: 3 additions & 0 deletions clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from './baseRoyalties';
export * from './baseRuleSet';
export * from './baseSeed';
export * from './baseUpdateAuthority';
export * from './baseValidationResultsOffset';
export * from './burnDelegate';
export * from './compressionProof';
export * from './creator';
Expand All @@ -36,11 +37,13 @@ export * from './externalPlugin';
export * from './externalPluginSchema';
export * from './externalPluginType';
export * from './externalRegistryRecord';
export * from './externalValidationResult';
export * from './freezeDelegate';
export * from './hashablePluginSchema';
export * from './hashedAssetSchema';
export * from './hookableLifecycleEvent';
export * from './key';
export * from './oracleValidation';
export * from './permanentBurnDelegate';
export * from './permanentFreezeDelegate';
export * from './permanentTransferDelegate';
Expand Down
76 changes: 76 additions & 0 deletions clients/js/src/generated/types/oracleValidation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* 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 {
GetDataEnumKind,
GetDataEnumKindContent,
Serializer,
dataEnum,
struct,
} 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 OracleValidationArgs = {
__kind: 'V1';
create: ExternalValidationResultArgs;
transfer: ExternalValidationResultArgs;
burn: ExternalValidationResultArgs;
update: ExternalValidationResultArgs;
};

export function getOracleValidationSerializer(): Serializer<
OracleValidationArgs,
OracleValidation
> {
return dataEnum<OracleValidation>(
[
[
'V1',
struct<GetDataEnumKindContent<OracleValidation, 'V1'>>([
['create', getExternalValidationResultSerializer()],
['transfer', getExternalValidationResultSerializer()],
['burn', getExternalValidationResultSerializer()],
['update', getExternalValidationResultSerializer()],
]),
],
],
{ description: 'OracleValidation' }
) as Serializer<OracleValidationArgs, OracleValidation>;
}

// Data Enum Helpers.
export function oracleValidation(
kind: 'V1',
data: GetDataEnumKindContent<OracleValidationArgs, 'V1'>
): GetDataEnumKind<OracleValidationArgs, 'V1'>;
export function oracleValidation<K extends OracleValidationArgs['__kind']>(
kind: K,
data?: any
): Extract<OracleValidationArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
: { __kind: kind, ...(data ?? {}) };
}
export function isOracleValidation<K extends OracleValidation['__kind']>(
kind: K,
value: OracleValidation
): value is OracleValidation & { __kind: K } {
return value.__kind === kind;
}
1 change: 1 addition & 0 deletions clients/js/src/instructions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const create = (
case 'Oracle':
assetExternalPlugins.oracles?.push({
...plugin,
resultsOffset: plugin.resultsOffset || { type: 'NoOffset' },
baseAddress: plugin.baseAddress,
authority: plugin.initPluginAuthority || {
type: 'UpdateAuthority',
Expand Down
Loading

0 comments on commit 6464c2a

Please sign in to comment.