Skip to content
Open
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
1 change: 1 addition & 0 deletions clients/js/src/generated/tools/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export * from './executionDelegateRecordV1';
export * from './executiveProfileV1';
export * from './x402EndpointV1';
208 changes: 208 additions & 0 deletions clients/js/src/generated/tools/accounts/x402EndpointV1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/**
* 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 {
Account,
Context,
Pda,
PublicKey,
RpcAccount,
RpcGetAccountOptions,
RpcGetAccountsOptions,
assertAccountExists,
deserializeAccount,
gpaBuilder,
publicKey as toPublicKey,
} from '@metaplex-foundation/umi';
import {
Serializer,
array,
mapSerializer,
publicKey as publicKeySerializer,
string,
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '../types';

export type X402EndpointV1 = Account<X402EndpointV1AccountData>;

export type X402EndpointV1AccountData = {
key: Key;
bump: number;
padding: Array<number>;
asset: PublicKey;
authority: PublicKey;
url: string;
};

export type X402EndpointV1AccountDataArgs = {
key: KeyArgs;
bump: number;
asset: PublicKey;
authority: PublicKey;
url: string;
};

export function getX402EndpointV1AccountDataSerializer(): Serializer<
X402EndpointV1AccountDataArgs,
X402EndpointV1AccountData
> {
return mapSerializer<
X402EndpointV1AccountDataArgs,
any,
X402EndpointV1AccountData
>(
struct<X402EndpointV1AccountData>(
[
['key', getKeySerializer()],
['bump', u8()],
['padding', array(u8(), { size: 6 })],
['asset', publicKeySerializer()],
['authority', publicKeySerializer()],
['url', string()],
],
{ description: 'X402EndpointV1AccountData' }
),
(value) => ({ ...value, padding: [0, 0, 0, 0, 0, 0] })
) as Serializer<X402EndpointV1AccountDataArgs, X402EndpointV1AccountData>;
}

export function deserializeX402EndpointV1(
rawAccount: RpcAccount
): X402EndpointV1 {
return deserializeAccount(
rawAccount,
getX402EndpointV1AccountDataSerializer()
);
}

export async function fetchX402EndpointV1(
context: Pick<Context, 'rpc'>,
publicKey: PublicKey | Pda,
options?: RpcGetAccountOptions
): Promise<X402EndpointV1> {
const maybeAccount = await context.rpc.getAccount(
toPublicKey(publicKey, false),
options
);
assertAccountExists(maybeAccount, 'X402EndpointV1');
return deserializeX402EndpointV1(maybeAccount);
}

export async function safeFetchX402EndpointV1(
context: Pick<Context, 'rpc'>,
publicKey: PublicKey | Pda,
options?: RpcGetAccountOptions
): Promise<X402EndpointV1 | null> {
const maybeAccount = await context.rpc.getAccount(
toPublicKey(publicKey, false),
options
);
return maybeAccount.exists ? deserializeX402EndpointV1(maybeAccount) : null;
}

export async function fetchAllX402EndpointV1(
context: Pick<Context, 'rpc'>,
publicKeys: Array<PublicKey | Pda>,
options?: RpcGetAccountsOptions
): Promise<X402EndpointV1[]> {
const maybeAccounts = await context.rpc.getAccounts(
publicKeys.map((key) => toPublicKey(key, false)),
options
);
return maybeAccounts.map((maybeAccount) => {
assertAccountExists(maybeAccount, 'X402EndpointV1');
return deserializeX402EndpointV1(maybeAccount);
});
}

export async function safeFetchAllX402EndpointV1(
context: Pick<Context, 'rpc'>,
publicKeys: Array<PublicKey | Pda>,
options?: RpcGetAccountsOptions
): Promise<X402EndpointV1[]> {
const maybeAccounts = await context.rpc.getAccounts(
publicKeys.map((key) => toPublicKey(key, false)),
options
);
return maybeAccounts
.filter((maybeAccount) => maybeAccount.exists)
.map((maybeAccount) =>
deserializeX402EndpointV1(maybeAccount as RpcAccount)
);
}

export function getX402EndpointV1GpaBuilder(
context: Pick<Context, 'rpc' | 'programs'>
) {
const programId = context.programs.getPublicKey(
'mplAgentTools',
'TLREGni9ZEyGC3vnPZtqUh95xQ8oPqJSvNjvB7FGK8S'
);
return gpaBuilder(context, programId)
.registerFields<{
key: KeyArgs;
bump: number;
padding: Array<number>;
asset: PublicKey;
authority: PublicKey;
url: string;
}>({
key: [0, getKeySerializer()],
bump: [1, u8()],
padding: [2, array(u8(), { size: 6 })],
asset: [8, publicKeySerializer()],
authority: [40, publicKeySerializer()],
url: [72, string()],
})
.deserializeUsing<X402EndpointV1>((account) =>
deserializeX402EndpointV1(account)
);
}

export function findX402EndpointV1Pda(
context: Pick<Context, 'eddsa' | 'programs'>,
seeds: {
/** The address of the agent asset */
asset: PublicKey;
}
): Pda {
const programId = context.programs.getPublicKey(
'mplAgentTools',
'TLREGni9ZEyGC3vnPZtqUh95xQ8oPqJSvNjvB7FGK8S'
);
return context.eddsa.findPda(programId, [
string({ size: 'variable' }).serialize('x402_endpoint'),
publicKeySerializer().serialize(seeds.asset),
]);
}

export async function fetchX402EndpointV1FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findX402EndpointV1Pda>[1],
options?: RpcGetAccountOptions
): Promise<X402EndpointV1> {
return fetchX402EndpointV1(
context,
findX402EndpointV1Pda(context, seeds),
options
);
}

export async function safeFetchX402EndpointV1FromSeeds(
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>,
seeds: Parameters<typeof findX402EndpointV1Pda>[1],
options?: RpcGetAccountOptions
): Promise<X402EndpointV1 | null> {
return safeFetchX402EndpointV1(
context,
findX402EndpointV1Pda(context, seeds),
options
);
}
61 changes: 61 additions & 0 deletions clients/js/src/generated/tools/errors/mplAgentTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,67 @@ export class UnauthorizedRevokeError extends ProgramError {
codeToErrorMap.set(0xd, UnauthorizedRevokeError);
nameToErrorMap.set('UnauthorizedRevoke', UnauthorizedRevokeError);

/** InvalidX402EndpointDerivation: Invalid x402 Endpoint Derivation */
export class InvalidX402EndpointDerivationError extends ProgramError {
override readonly name: string = 'InvalidX402EndpointDerivation';

readonly code: number = 0xe; // 14

constructor(program: Program, cause?: Error) {
super('Invalid x402 Endpoint Derivation', program, cause);
}
}
codeToErrorMap.set(0xe, InvalidX402EndpointDerivationError);
nameToErrorMap.set(
'InvalidX402EndpointDerivation',
InvalidX402EndpointDerivationError
);

/** X402EndpointMustBeUninitialized: x402 Endpoint must be uninitialized */
export class X402EndpointMustBeUninitializedError extends ProgramError {
override readonly name: string = 'X402EndpointMustBeUninitialized';

readonly code: number = 0xf; // 15

constructor(program: Program, cause?: Error) {
super('x402 Endpoint must be uninitialized', program, cause);
}
}
codeToErrorMap.set(0xf, X402EndpointMustBeUninitializedError);
nameToErrorMap.set(
'X402EndpointMustBeUninitialized',
X402EndpointMustBeUninitializedError
);

/** AssetOwnerMustRegisterX402: Asset owner must register x402 endpoint */
export class AssetOwnerMustRegisterX402Error extends ProgramError {
override readonly name: string = 'AssetOwnerMustRegisterX402';

readonly code: number = 0x10; // 16

constructor(program: Program, cause?: Error) {
super('Asset owner must register x402 endpoint', program, cause);
}
}
codeToErrorMap.set(0x10, AssetOwnerMustRegisterX402Error);
nameToErrorMap.set(
'AssetOwnerMustRegisterX402',
AssetOwnerMustRegisterX402Error
);

/** InvalidUrlLength: Invalid URL length */
export class InvalidUrlLengthError extends ProgramError {
override readonly name: string = 'InvalidUrlLength';

readonly code: number = 0x11; // 17

constructor(program: Program, cause?: Error) {
super('Invalid URL length', program, cause);
}
}
codeToErrorMap.set(0x11, InvalidUrlLengthError);
nameToErrorMap.set('InvalidUrlLength', InvalidUrlLengthError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/generated/tools/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

export * from './delegateExecutionV1';
export * from './registerExecutiveV1';
export * from './registerX402V1';
export * from './revokeExecutionV1';
Loading
Loading