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

Require passing in oracle lifecycle checks Vec #101

Merged
merged 15 commits into from
May 3, 2024
32 changes: 26 additions & 6 deletions clients/js/src/generated/errors/mplCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,22 +492,42 @@ export class MissingExternalAccountError extends ProgramError {
codeToErrorMap.set(0x22, MissingExternalAccountError);
nameToErrorMap.set('MissingExternalAccount', MissingExternalAccountError);

/** OracleCanDenyOnly: Oracle external plugin can only be configured to deny */
export class OracleCanDenyOnlyError extends ProgramError {
override readonly name: string = 'OracleCanDenyOnly';
/** OracleCanRejectOnly: Oracle external plugin can only be configured to reject */
export class OracleCanRejectOnlyError extends ProgramError {
override readonly name: string = 'OracleCanRejectOnly';

readonly code: number = 0x23; // 35

constructor(program: Program, cause?: Error) {
super(
'Oracle external plugin can only be configured to deny',
'Oracle external plugin can only be configured to reject',
program,
cause
);
}
}
codeToErrorMap.set(0x23, OracleCanDenyOnlyError);
nameToErrorMap.set('OracleCanDenyOnly', OracleCanDenyOnlyError);
codeToErrorMap.set(0x23, OracleCanRejectOnlyError);
nameToErrorMap.set('OracleCanRejectOnly', OracleCanRejectOnlyError);

/** OracleRequiresLifecycleCheck: Oracle external plugin must have at least one lifecycle check */
export class OracleRequiresLifecycleCheckError extends ProgramError {
override readonly name: string = 'OracleRequiresLifecycleCheck';

readonly code: number = 0x24; // 36

constructor(program: Program, cause?: Error) {
super(
'Oracle external plugin must have at least one lifecycle check',
program,
cause
);
}
}
codeToErrorMap.set(0x24, OracleRequiresLifecycleCheckError);
nameToErrorMap.set(
'OracleRequiresLifecycleCheck',
OracleRequiresLifecycleCheckError
);

/**
* Attempts to resolve a custom program error from the provided error code.
Expand Down
18 changes: 7 additions & 11 deletions clients/js/src/generated/types/baseOracleInitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ import {
export type BaseOracleInitInfo = {
baseAddress: PublicKey;
initPluginAuthority: Option<BasePluginAuthority>;
lifecycleChecks: Option<Array<[HookableLifecycleEvent, ExternalCheckResult]>>;
lifecycleChecks: Array<[HookableLifecycleEvent, ExternalCheckResult]>;
pda: Option<BaseExtraAccount>;
resultsOffset: Option<BaseValidationResultsOffset>;
};

export type BaseOracleInitInfoArgs = {
baseAddress: PublicKey;
initPluginAuthority: OptionOrNullable<BasePluginAuthorityArgs>;
lifecycleChecks: OptionOrNullable<
Array<[HookableLifecycleEventArgs, ExternalCheckResultArgs]>
>;
lifecycleChecks: Array<[HookableLifecycleEventArgs, ExternalCheckResultArgs]>;
pda: OptionOrNullable<BaseExtraAccountArgs>;
resultsOffset: OptionOrNullable<BaseValidationResultsOffsetArgs>;
};
Expand All @@ -61,13 +59,11 @@ export function getBaseOracleInitInfoSerializer(): Serializer<
['initPluginAuthority', option(getBasePluginAuthoritySerializer())],
[
'lifecycleChecks',
option(
array(
tuple([
getHookableLifecycleEventSerializer(),
getExternalCheckResultSerializer(),
])
)
array(
tuple([
getHookableLifecycleEventSerializer(),
getExternalCheckResultSerializer(),
])
),
],
['pda', option(getBaseExtraAccountSerializer())],
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/helpers/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function validateTransfer(
}

if (isFrozen(asset, collection)) {
return LifecycleValidationError.AssetFrozen
return LifecycleValidationError.AssetFrozen;
}

if (dAsset.oracles?.length) {
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/plugins/lifecycleChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function lifecycleChecksToBase(
})
.filter((x) => x !== null) as [
HookableLifecycleEvent,
ExternalCheckResult
ExternalCheckResult,
][];
}

Expand Down
6 changes: 2 additions & 4 deletions clients/js/src/plugins/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type OracleInitInfoArgs = Omit<
> & {
type: 'Oracle';
initPluginAuthority?: PluginAuthority;
lifecycleChecks?: LifecycleChecks;
lifecycleChecks: LifecycleChecks;
pda?: ExtraAccount;
resultsOffset?: ValidationResultsOffset;
};
Expand All @@ -61,9 +61,7 @@ export function oracleInitInfoArgsToBase(
return {
baseAddress: o.baseAddress,
pda: o.pda ? extraAccountToBase(o.pda) : null,
lifecycleChecks: o.lifecycleChecks
? lifecycleChecksToBase(o.lifecycleChecks)
: null,
lifecycleChecks: lifecycleChecksToBase(o.lifecycleChecks),
initPluginAuthority: o.initPluginAuthority
? pluginAuthorityToBase(o.initPluginAuthority)
: null,
Expand Down
Loading