-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define IDL instructions for the confidential transfer fee extension (#51
- Loading branch information
1 parent
e46b8ea
commit 8dbae66
Showing
11 changed files
with
2,318 additions
and
0 deletions.
There are no files selected for viewing
220 changes: 220 additions & 0 deletions
220
clients/js/src/generated/instructions/disableHarvestToMint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
/** | ||
* 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 { | ||
AccountRole, | ||
combineCodec, | ||
getStructDecoder, | ||
getStructEncoder, | ||
getU8Decoder, | ||
getU8Encoder, | ||
transformEncoder, | ||
type Address, | ||
type Codec, | ||
type Decoder, | ||
type Encoder, | ||
type IAccountMeta, | ||
type IAccountSignerMeta, | ||
type IInstruction, | ||
type IInstructionWithAccounts, | ||
type IInstructionWithData, | ||
type ReadonlyAccount, | ||
type ReadonlySignerAccount, | ||
type TransactionSigner, | ||
type WritableAccount, | ||
} from '@solana/web3.js'; | ||
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; | ||
import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; | ||
|
||
export const DISABLE_HARVEST_TO_MINT_DISCRIMINATOR = 37; | ||
|
||
export function getDisableHarvestToMintDiscriminatorBytes() { | ||
return getU8Encoder().encode(DISABLE_HARVEST_TO_MINT_DISCRIMINATOR); | ||
} | ||
|
||
export const DISABLE_HARVEST_TO_MINT_CONFIDENTIAL_TRANSFER_FEE_DISCRIMINATOR = 5; | ||
|
||
export function getDisableHarvestToMintConfidentialTransferFeeDiscriminatorBytes() { | ||
return getU8Encoder().encode( | ||
DISABLE_HARVEST_TO_MINT_CONFIDENTIAL_TRANSFER_FEE_DISCRIMINATOR | ||
); | ||
} | ||
|
||
export type DisableHarvestToMintInstruction< | ||
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, | ||
TAccountMint extends string | IAccountMeta<string> = string, | ||
TAccountAuthority extends string | IAccountMeta<string> = string, | ||
TRemainingAccounts extends readonly IAccountMeta<string>[] = [], | ||
> = IInstruction<TProgram> & | ||
IInstructionWithData<Uint8Array> & | ||
IInstructionWithAccounts< | ||
[ | ||
TAccountMint extends string | ||
? WritableAccount<TAccountMint> | ||
: TAccountMint, | ||
TAccountAuthority extends string | ||
? ReadonlyAccount<TAccountAuthority> | ||
: TAccountAuthority, | ||
...TRemainingAccounts, | ||
] | ||
>; | ||
|
||
export type DisableHarvestToMintInstructionData = { | ||
discriminator: number; | ||
confidentialTransferFeeDiscriminator: number; | ||
}; | ||
|
||
export type DisableHarvestToMintInstructionDataArgs = {}; | ||
|
||
export function getDisableHarvestToMintInstructionDataEncoder(): Encoder<DisableHarvestToMintInstructionDataArgs> { | ||
return transformEncoder( | ||
getStructEncoder([ | ||
['discriminator', getU8Encoder()], | ||
['confidentialTransferFeeDiscriminator', getU8Encoder()], | ||
]), | ||
(value) => ({ | ||
...value, | ||
discriminator: DISABLE_HARVEST_TO_MINT_DISCRIMINATOR, | ||
confidentialTransferFeeDiscriminator: | ||
DISABLE_HARVEST_TO_MINT_CONFIDENTIAL_TRANSFER_FEE_DISCRIMINATOR, | ||
}) | ||
); | ||
} | ||
|
||
export function getDisableHarvestToMintInstructionDataDecoder(): Decoder<DisableHarvestToMintInstructionData> { | ||
return getStructDecoder([ | ||
['discriminator', getU8Decoder()], | ||
['confidentialTransferFeeDiscriminator', getU8Decoder()], | ||
]); | ||
} | ||
|
||
export function getDisableHarvestToMintInstructionDataCodec(): Codec< | ||
DisableHarvestToMintInstructionDataArgs, | ||
DisableHarvestToMintInstructionData | ||
> { | ||
return combineCodec( | ||
getDisableHarvestToMintInstructionDataEncoder(), | ||
getDisableHarvestToMintInstructionDataDecoder() | ||
); | ||
} | ||
|
||
export type DisableHarvestToMintInput< | ||
TAccountMint extends string = string, | ||
TAccountAuthority extends string = string, | ||
> = { | ||
/** The token mint. */ | ||
mint: Address<TAccountMint>; | ||
/** The confidential transfer fee authority */ | ||
authority: Address<TAccountAuthority> | TransactionSigner<TAccountAuthority>; | ||
multiSigners?: Array<TransactionSigner>; | ||
}; | ||
|
||
export function getDisableHarvestToMintInstruction< | ||
TAccountMint extends string, | ||
TAccountAuthority extends string, | ||
TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, | ||
>( | ||
input: DisableHarvestToMintInput<TAccountMint, TAccountAuthority>, | ||
config?: { programAddress?: TProgramAddress } | ||
): DisableHarvestToMintInstruction< | ||
TProgramAddress, | ||
TAccountMint, | ||
(typeof input)['authority'] extends TransactionSigner<TAccountAuthority> | ||
? ReadonlySignerAccount<TAccountAuthority> & | ||
IAccountSignerMeta<TAccountAuthority> | ||
: TAccountAuthority | ||
> { | ||
// Program address. | ||
const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS; | ||
|
||
// Original accounts. | ||
const originalAccounts = { | ||
mint: { value: input.mint ?? null, isWritable: true }, | ||
authority: { value: input.authority ?? null, isWritable: false }, | ||
}; | ||
const accounts = originalAccounts as Record< | ||
keyof typeof originalAccounts, | ||
ResolvedAccount | ||
>; | ||
|
||
// Original args. | ||
const args = { ...input }; | ||
|
||
// Remaining accounts. | ||
const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( | ||
(signer) => ({ | ||
address: signer.address, | ||
role: AccountRole.READONLY_SIGNER, | ||
signer, | ||
}) | ||
); | ||
|
||
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); | ||
const instruction = { | ||
accounts: [ | ||
getAccountMeta(accounts.mint), | ||
getAccountMeta(accounts.authority), | ||
...remainingAccounts, | ||
], | ||
programAddress, | ||
data: getDisableHarvestToMintInstructionDataEncoder().encode({}), | ||
} as DisableHarvestToMintInstruction< | ||
TProgramAddress, | ||
TAccountMint, | ||
(typeof input)['authority'] extends TransactionSigner<TAccountAuthority> | ||
? ReadonlySignerAccount<TAccountAuthority> & | ||
IAccountSignerMeta<TAccountAuthority> | ||
: TAccountAuthority | ||
>; | ||
|
||
return instruction; | ||
} | ||
|
||
export type ParsedDisableHarvestToMintInstruction< | ||
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, | ||
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], | ||
> = { | ||
programAddress: Address<TProgram>; | ||
accounts: { | ||
/** The token mint. */ | ||
mint: TAccountMetas[0]; | ||
/** The confidential transfer fee authority */ | ||
authority: TAccountMetas[1]; | ||
}; | ||
data: DisableHarvestToMintInstructionData; | ||
}; | ||
|
||
export function parseDisableHarvestToMintInstruction< | ||
TProgram extends string, | ||
TAccountMetas extends readonly IAccountMeta[], | ||
>( | ||
instruction: IInstruction<TProgram> & | ||
IInstructionWithAccounts<TAccountMetas> & | ||
IInstructionWithData<Uint8Array> | ||
): ParsedDisableHarvestToMintInstruction<TProgram, TAccountMetas> { | ||
if (instruction.accounts.length < 2) { | ||
// 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(), | ||
authority: getNextAccount(), | ||
}, | ||
data: getDisableHarvestToMintInstructionDataDecoder().decode( | ||
instruction.data | ||
), | ||
}; | ||
} |
Oops, something went wrong.