Skip to content

Commit

Permalink
Merge branch 'main' into gib-bounty-tok956851
Browse files Browse the repository at this point in the history
  • Loading branch information
DogukanGun committed Nov 13, 2024
2 parents 33b2e06 + c32ee07 commit 51aa029
Show file tree
Hide file tree
Showing 10 changed files with 1,128 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ export * from './initializeMintCloseAuthority';
export * from './initializeMultisig';
export * from './initializeMultisig2';
export * from './initializeNonTransferableMint';
export * from './initializePermanentDelegate';
export * from './initializeTokenGroup';
export * from './initializeTokenGroupMember';
export * from './initializeTokenMetadata';
export * from './initializeTransferFeeConfig';
export * from './initializeTransferHook';
export * from './mintTo';
export * from './mintToChecked';
export * from './reallocate';
Expand All @@ -76,6 +78,7 @@ export * from './updateTokenGroupMaxSize';
export * from './updateTokenGroupUpdateAuthority';
export * from './updateTokenMetadataField';
export * from './updateTokenMetadataUpdateAuthority';
export * from './updateTransferHook';
export * from './withdrawExcessLamports';
export * from './withdrawWithheldTokensFromAccounts';
export * from './withdrawWithheldTokensFromMint';
174 changes: 174 additions & 0 deletions clients/js/src/generated/instructions/initializePermanentDelegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/**
* 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,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type WritableAccount,
} from '@solana/web3.js';
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const INITIALIZE_PERMANENT_DELEGATE_DISCRIMINATOR = 35;

export function getInitializePermanentDelegateDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_PERMANENT_DELEGATE_DISCRIMINATOR);
}

export type InitializePermanentDelegateInstruction<
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 InitializePermanentDelegateInstructionData = {
discriminator: number;
/** Authority that may sign for `Transfer`s and `Burn`s on any account */
delegate: Address;
};

export type InitializePermanentDelegateInstructionDataArgs = {
/** Authority that may sign for `Transfer`s and `Burn`s on any account */
delegate: Address;
};

export function getInitializePermanentDelegateInstructionDataEncoder(): Encoder<InitializePermanentDelegateInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['delegate', getAddressEncoder()],
]),
(value) => ({
...value,
discriminator: INITIALIZE_PERMANENT_DELEGATE_DISCRIMINATOR,
})
);
}

export function getInitializePermanentDelegateInstructionDataDecoder(): Decoder<InitializePermanentDelegateInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['delegate', getAddressDecoder()],
]);
}

export function getInitializePermanentDelegateInstructionDataCodec(): Codec<
InitializePermanentDelegateInstructionDataArgs,
InitializePermanentDelegateInstructionData
> {
return combineCodec(
getInitializePermanentDelegateInstructionDataEncoder(),
getInitializePermanentDelegateInstructionDataDecoder()
);
}

export type InitializePermanentDelegateInput<
TAccountMint extends string = string,
> = {
/** The mint to initialize. */
mint: Address<TAccountMint>;
delegate: InitializePermanentDelegateInstructionDataArgs['delegate'];
};

export function getInitializePermanentDelegateInstruction<
TAccountMint extends string,
TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS,
>(
input: InitializePermanentDelegateInput<TAccountMint>,
config?: { programAddress?: TProgramAddress }
): InitializePermanentDelegateInstruction<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: getInitializePermanentDelegateInstructionDataEncoder().encode(
args as InitializePermanentDelegateInstructionDataArgs
),
} as InitializePermanentDelegateInstruction<TProgramAddress, TAccountMint>;

return instruction;
}

export type ParsedInitializePermanentDelegateInstruction<
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: InitializePermanentDelegateInstructionData;
};

export function parseInitializePermanentDelegateInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedInitializePermanentDelegateInstruction<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: getInitializePermanentDelegateInstructionDataDecoder().decode(
instruction.data
),
};
}
Loading

0 comments on commit 51aa029

Please sign in to comment.