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

Define IDL instructions for group member pointer extension #18

Merged
merged 2 commits into from
Oct 10, 2024
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
2 changes: 2 additions & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from './initializeAccount2';
export * from './initializeAccount3';
export * from './initializeConfidentialTransferMint';
export * from './initializeDefaultAccountState';
export * from './initializeGroupMemberPointer';
export * from './initializeGroupPointer';
export * from './initializeImmutableOwner';
export * from './initializeMetadataPointer';
Expand All @@ -60,6 +61,7 @@ export * from './transferCheckedWithFee';
export * from './uiAmountToAmount';
export * from './updateConfidentialTransferMint';
export * from './updateDefaultAccountState';
export * from './updateGroupMemberPointer';
export * from './updateGroupPointer';
export * from './updateMetadataPointer';
export * from './withdrawWithheldTokensFromAccounts';
Expand Down
222 changes: 222 additions & 0 deletions clients/js/src/generated/instructions/initializeGroupMemberPointer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
/**
* This code was AUTOGENERATED using the codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun codama to update it.
*
* @see https://github.com/codama-idl/codama
*/

import {
combineCodec,
getAddressDecoder,
getAddressEncoder,
getOptionDecoder,
getOptionEncoder,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type Option,
type OptionOrNullable,
type WritableAccount,
} from '@solana/web3.js';
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const INITIALIZE_GROUP_MEMBER_POINTER_DISCRIMINATOR = 41;

export function getInitializeGroupMemberPointerDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_GROUP_MEMBER_POINTER_DISCRIMINATOR);
}

export const INITIALIZE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR = 0;

export function getInitializeGroupMemberPointerGroupMemberPointerDiscriminatorBytes() {
return getU8Encoder().encode(
INITIALIZE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR
);
}

export type InitializeGroupMemberPointerInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountMint extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
[
TAccountMint extends string
? WritableAccount<TAccountMint>
: TAccountMint,
...TRemainingAccounts,
]
>;

export type InitializeGroupMemberPointerInstructionData = {
discriminator: number;
groupMemberPointerDiscriminator: number;
/** The public key for the account that can update the group member address. */
authority: Option<Address>;
/** The account address that holds the member. */
memberAddress: Option<Address>;
};

export type InitializeGroupMemberPointerInstructionDataArgs = {
/** The public key for the account that can update the group member address. */
authority: OptionOrNullable<Address>;
/** The account address that holds the member. */
memberAddress: OptionOrNullable<Address>;
};

export function getInitializeGroupMemberPointerInstructionDataEncoder(): Encoder<InitializeGroupMemberPointerInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['groupMemberPointerDiscriminator', getU8Encoder()],
[
'authority',
getOptionEncoder(getAddressEncoder(), {
prefix: null,
noneValue: 'zeroes',
}),
],
[
'memberAddress',
getOptionEncoder(getAddressEncoder(), {
prefix: null,
noneValue: 'zeroes',
}),
],
]),
(value) => ({
...value,
discriminator: INITIALIZE_GROUP_MEMBER_POINTER_DISCRIMINATOR,
groupMemberPointerDiscriminator:
INITIALIZE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR,
})
);
}

export function getInitializeGroupMemberPointerInstructionDataDecoder(): Decoder<InitializeGroupMemberPointerInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['groupMemberPointerDiscriminator', getU8Decoder()],
[
'authority',
getOptionDecoder(getAddressDecoder(), {
prefix: null,
noneValue: 'zeroes',
}),
],
[
'memberAddress',
getOptionDecoder(getAddressDecoder(), {
prefix: null,
noneValue: 'zeroes',
}),
],
]);
}

export function getInitializeGroupMemberPointerInstructionDataCodec(): Codec<
InitializeGroupMemberPointerInstructionDataArgs,
InitializeGroupMemberPointerInstructionData
> {
return combineCodec(
getInitializeGroupMemberPointerInstructionDataEncoder(),
getInitializeGroupMemberPointerInstructionDataDecoder()
);
}

export type InitializeGroupMemberPointerInput<
TAccountMint extends string = string,
> = {
/** The mint to initialize. */
mint: Address<TAccountMint>;
authority: InitializeGroupMemberPointerInstructionDataArgs['authority'];
memberAddress: InitializeGroupMemberPointerInstructionDataArgs['memberAddress'];
};

export function getInitializeGroupMemberPointerInstruction<
TAccountMint extends string,
TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS,
>(
input: InitializeGroupMemberPointerInput<TAccountMint>,
config?: { programAddress?: TProgramAddress }
): InitializeGroupMemberPointerInstruction<TProgramAddress, TAccountMint> {
// Program address.
const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
mint: { value: input.mint ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedAccount
>;

// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [getAccountMeta(accounts.mint)],
programAddress,
data: getInitializeGroupMemberPointerInstructionDataEncoder().encode(
args as InitializeGroupMemberPointerInstructionDataArgs
),
} as InitializeGroupMemberPointerInstruction<TProgramAddress, TAccountMint>;

return instruction;
}

export type ParsedInitializeGroupMemberPointerInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
/** The mint to initialize. */
mint: TAccountMetas[0];
};
data: InitializeGroupMemberPointerInstructionData;
};

export function parseInitializeGroupMemberPointerInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedInitializeGroupMemberPointerInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 1) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts![accountIndex]!;
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
mint: getNextAccount(),
},
data: getInitializeGroupMemberPointerInstructionDataDecoder().decode(
instruction.data
),
};
}
Loading