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 transfer fee extension #6

Merged
merged 7 commits into from
Oct 3, 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
187 changes: 187 additions & 0 deletions clients/js/src/generated/instructions/harvestWithheldTokensToMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/**
* 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/kinobi-so/kinobi
*/

import {
AccountRole,
combineCodec,
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 HARVEST_WITHHELD_TOKENS_TO_MINT_DISCRIMINATOR = 26;

export function getHarvestWithheldTokensToMintDiscriminatorBytes() {
return getU8Encoder().encode(HARVEST_WITHHELD_TOKENS_TO_MINT_DISCRIMINATOR);
}

export const HARVEST_WITHHELD_TOKENS_TO_MINT_TRANSFER_FEE_DISCRIMINATOR = 4;

export function getHarvestWithheldTokensToMintTransferFeeDiscriminatorBytes() {
return getU8Encoder().encode(
HARVEST_WITHHELD_TOKENS_TO_MINT_TRANSFER_FEE_DISCRIMINATOR
);
}

export type HarvestWithheldTokensToMintInstruction<
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 HarvestWithheldTokensToMintInstructionData = {
discriminator: number;
transferFeeDiscriminator: number;
};

export type HarvestWithheldTokensToMintInstructionDataArgs = {};

export function getHarvestWithheldTokensToMintInstructionDataEncoder(): Encoder<HarvestWithheldTokensToMintInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['transferFeeDiscriminator', getU8Encoder()],
]),
(value) => ({
...value,
discriminator: HARVEST_WITHHELD_TOKENS_TO_MINT_DISCRIMINATOR,
transferFeeDiscriminator:
HARVEST_WITHHELD_TOKENS_TO_MINT_TRANSFER_FEE_DISCRIMINATOR,
})
);
}

export function getHarvestWithheldTokensToMintInstructionDataDecoder(): Decoder<HarvestWithheldTokensToMintInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['transferFeeDiscriminator', getU8Decoder()],
]);
}

export function getHarvestWithheldTokensToMintInstructionDataCodec(): Codec<
HarvestWithheldTokensToMintInstructionDataArgs,
HarvestWithheldTokensToMintInstructionData
> {
return combineCodec(
getHarvestWithheldTokensToMintInstructionDataEncoder(),
getHarvestWithheldTokensToMintInstructionDataDecoder()
);
}

export type HarvestWithheldTokensToMintInput<
TAccountMint extends string = string,
> = {
/** The token mint. */
mint: Address<TAccountMint>;
sources: Array<Address>;
};

export function getHarvestWithheldTokensToMintInstruction<
TAccountMint extends string,
>(
input: HarvestWithheldTokensToMintInput<TAccountMint>
): HarvestWithheldTokensToMintInstruction<
typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountMint
> {
// Program address.
const 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 };

// Remaining accounts.
const remainingAccounts: IAccountMeta[] = args.sources.map((address) => ({
address,
role: AccountRole.WRITABLE,
}));

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [getAccountMeta(accounts.mint), ...remainingAccounts],
programAddress,
data: getHarvestWithheldTokensToMintInstructionDataEncoder().encode({}),
} as HarvestWithheldTokensToMintInstruction<
typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountMint
>;

return instruction;
}

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

export function parseHarvestWithheldTokensToMintInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedHarvestWithheldTokensToMintInstruction<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: getHarvestWithheldTokensToMintInstructionDataDecoder().decode(
instruction.data
),
};
}
5 changes: 5 additions & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './createAssociatedToken';
export * from './createAssociatedTokenIdempotent';
export * from './freezeAccount';
export * from './getAccountDataSize';
export * from './harvestWithheldTokensToMint';
export * from './initializeAccount';
export * from './initializeAccount2';
export * from './initializeAccount3';
Expand All @@ -31,8 +32,12 @@ export * from './mintToChecked';
export * from './recoverNestedAssociatedToken';
export * from './revoke';
export * from './setAuthority';
export * from './setTransferFee';
export * from './syncNative';
export * from './thawAccount';
export * from './transfer';
export * from './transferChecked';
export * from './transferCheckedWithFee';
export * from './uiAmountToAmount';
export * from './withdrawWithheldTokensFromAccounts';
export * from './withdrawWithheldTokensFromMint';
Loading