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

Rename Oracle pda - stacked onto rename external plugin #121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clients/js/src/generated/types/baseOracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import {

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

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

Expand All @@ -41,7 +41,7 @@ export function getBaseOracleSerializer(): Serializer<
return struct<BaseOracle>(
[
['baseAddress', publicKeySerializer()],
['pda', option(getBaseExtraAccountSerializer())],
['baseAddressConfig', option(getBaseExtraAccountSerializer())],
['resultsOffset', getBaseValidationResultsOffsetSerializer()],
],
{ description: 'BaseOracle' }
Expand Down
6 changes: 3 additions & 3 deletions clients/js/src/generated/types/baseOracleInitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ export type BaseOracleInitInfo = {
baseAddress: PublicKey;
initPluginAuthority: Option<BasePluginAuthority>;
lifecycleChecks: Array<[HookableLifecycleEvent, AdapterCheckResult]>;
pda: Option<BaseExtraAccount>;
baseAddressConfig: Option<BaseExtraAccount>;
resultsOffset: Option<BaseValidationResultsOffset>;
};

export type BaseOracleInitInfoArgs = {
baseAddress: PublicKey;
initPluginAuthority: OptionOrNullable<BasePluginAuthorityArgs>;
lifecycleChecks: Array<[HookableLifecycleEventArgs, AdapterCheckResultArgs]>;
pda: OptionOrNullable<BaseExtraAccountArgs>;
baseAddressConfig: OptionOrNullable<BaseExtraAccountArgs>;
resultsOffset: OptionOrNullable<BaseValidationResultsOffsetArgs>;
};

Expand All @@ -66,7 +66,7 @@ export function getBaseOracleInitInfoSerializer(): Serializer<
])
),
],
['pda', option(getBaseExtraAccountSerializer())],
['baseAddressConfig', option(getBaseExtraAccountSerializer())],
['resultsOffset', option(getBaseValidationResultsOffsetSerializer())],
],
{ description: 'BaseOracleInitInfo' }
Expand Down
6 changes: 3 additions & 3 deletions clients/js/src/generated/types/baseOracleUpdateInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import {

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

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

Expand All @@ -60,7 +60,7 @@ export function getBaseOracleUpdateInfoSerializer(): Serializer<
)
),
],
['pda', option(getBaseExtraAccountSerializer())],
['baseAddressConfig', option(getBaseExtraAccountSerializer())],
['resultsOffset', option(getBaseValidationResultsOffsetSerializer())],
],
{ description: 'BaseOracleUpdateInfo' }
Expand Down
8 changes: 6 additions & 2 deletions clients/js/src/helpers/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,19 @@ export async function validateTransfer(
)
.filter((o) => {
// there's no PDA to derive, we can check the oracle account
if (!o.pda) {
if (!o.baseAddressConfig) {
return true;
}
// If there's a recipient in the inputs, we can try to check the oracle account
if (recipient) {
return true;
}

if (!getExtraAccountRequiredInputs(o.pda).includes('recipient')) {
if (
!getExtraAccountRequiredInputs(o.baseAddressConfig).includes(
'recipient'
)
) {
return true;
}
// we skip the check if there's a recipient required but no recipient provided
Expand Down
35 changes: 22 additions & 13 deletions clients/js/src/plugins/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
validationResultsOffsetToBase,
} from './validationResultsOffset';

export type Oracle = Omit<BaseOracle, 'pda' | 'resultsOffset'> & {
pda?: ExtraAccount;
export type Oracle = Omit<BaseOracle, 'baseAddressConfig' | 'resultsOffset'> & {
baseAddressConfig?: ExtraAccount;
resultsOffset: ValidationResultsOffset;
};

Expand All @@ -36,22 +36,25 @@ export type OraclePlugin = BasePluginAdapter &

export type OracleInitInfoArgs = Omit<
BaseOracleInitInfoArgs,
'initPluginAuthority' | 'lifecycleChecks' | 'pda' | 'resultsOffset'
| 'initPluginAuthority'
| 'lifecycleChecks'
| 'baseAddressConfig'
| 'resultsOffset'
> & {
type: 'Oracle';
initPluginAuthority?: PluginAuthority;
lifecycleChecks: LifecycleChecks;
pda?: ExtraAccount;
baseAddressConfig?: ExtraAccount;
resultsOffset?: ValidationResultsOffset;
};

export type OracleUpdateInfoArgs = Omit<
BaseOracleUpdateInfoArgs,
'lifecycleChecks' | 'pda' | 'resultsOffset'
'lifecycleChecks' | 'baseAddressConfig' | 'resultsOffset'
> & {
key: PluginAdapterKey;
lifecycleChecks?: LifecycleChecks;
pda?: ExtraAccount;
baseAddressConfig?: ExtraAccount;
resultsOffset?: ValidationResultsOffset;
};

Expand All @@ -60,7 +63,9 @@ export function oracleInitInfoArgsToBase(
): BaseOracleInitInfoArgs {
return {
baseAddress: o.baseAddress,
pda: o.pda ? extraAccountToBase(o.pda) : null,
baseAddressConfig: o.baseAddressConfig
? extraAccountToBase(o.baseAddressConfig)
: null,
lifecycleChecks: lifecycleChecksToBase(o.lifecycleChecks),
initPluginAuthority: o.initPluginAuthority
? pluginAuthorityToBase(o.initPluginAuthority)
Expand All @@ -75,7 +80,9 @@ export function oracleUpdateInfoArgsToBase(
o: OracleUpdateInfoArgs
): BaseOracleUpdateInfoArgs {
return {
pda: o.pda ? extraAccountToBase(o.pda) : null,
baseAddressConfig: o.baseAddressConfig
? extraAccountToBase(o.baseAddressConfig)
: null,
lifecycleChecks: o.lifecycleChecks
? lifecycleChecksToBase(o.lifecycleChecks)
: null,
Expand All @@ -92,27 +99,29 @@ export function oracleFromBase(
): Oracle {
return {
...s,
pda:
s.pda.__option === 'Some' ? extraAccountFromBase(s.pda.value) : undefined,
baseAddressConfig:
s.baseAddressConfig.__option === 'Some'
? extraAccountFromBase(s.baseAddressConfig.value)
: undefined,
resultsOffset: validationResultsOffsetFromBase(s.resultsOffset),
};
}

export function findOracleAccount(
context: Pick<Context, 'eddsa'>,
oracle: Pick<Oracle, 'baseAddress' | 'pda'>,
oracle: Pick<Oracle, 'baseAddress' | 'baseAddressConfig'>,
inputs: {
asset?: PublicKey;
collection?: PublicKey;
recipient?: PublicKey;
owner?: PublicKey;
}
): PublicKey {
if (!oracle.pda) {
if (!oracle.baseAddressConfig) {
return oracle.baseAddress;
}

return extraAccountToAccountMeta(context, oracle.pda, {
return extraAccountToAccountMeta(context, oracle.baseAddressConfig, {
...inputs,
program: oracle.baseAddress,
}).pubkey;
Expand Down
4 changes: 2 additions & 2 deletions clients/js/src/plugins/pluginAdapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ export const findExtraAccounts = (

pluginAdapters.oracles?.forEach((oracle) => {
if (oracle.lifecycleChecks?.[lifecycle]) {
if (oracle.pda) {
if (oracle.baseAddressConfig) {
accounts.push(
extraAccountToAccountMeta(context, oracle.pda, {
extraAccountToAccountMeta(context, oracle.baseAddressConfig, {
...inputs,
program: oracle.baseAddress,
})
Expand Down
Loading