-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cpi guard instruction extension
- Loading branch information
1 parent
8aeeec3
commit 0533751
Showing
7 changed files
with
808 additions
and
0 deletions.
There are no files selected for viewing
213 changes: 213 additions & 0 deletions
213
clients/js/src/generated/instructions/disableCpiGuard.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,213 @@ | ||
/** | ||
* 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_CPI_GUARD_DISCRIMINATOR = 34; | ||
|
||
export function getDisableCpiGuardDiscriminatorBytes() { | ||
return getU8Encoder().encode(DISABLE_CPI_GUARD_DISCRIMINATOR); | ||
} | ||
|
||
export const DISABLE_CPI_GUARD_CPI_GUARD_DISCRIMINATOR = 1; | ||
|
||
export function getDisableCpiGuardCpiGuardDiscriminatorBytes() { | ||
return getU8Encoder().encode(DISABLE_CPI_GUARD_CPI_GUARD_DISCRIMINATOR); | ||
} | ||
|
||
export type DisableCpiGuardInstruction< | ||
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, | ||
TAccountToken extends string | IAccountMeta<string> = string, | ||
TAccountOwner extends string | IAccountMeta<string> = string, | ||
TRemainingAccounts extends readonly IAccountMeta<string>[] = [], | ||
> = IInstruction<TProgram> & | ||
IInstructionWithData<Uint8Array> & | ||
IInstructionWithAccounts< | ||
[ | ||
TAccountToken extends string | ||
? WritableAccount<TAccountToken> | ||
: TAccountToken, | ||
TAccountOwner extends string | ||
? ReadonlyAccount<TAccountOwner> | ||
: TAccountOwner, | ||
...TRemainingAccounts, | ||
] | ||
>; | ||
|
||
export type DisableCpiGuardInstructionData = { | ||
discriminator: number; | ||
cpiGuardDiscriminator: number; | ||
}; | ||
|
||
export type DisableCpiGuardInstructionDataArgs = {}; | ||
|
||
export function getDisableCpiGuardInstructionDataEncoder(): Encoder<DisableCpiGuardInstructionDataArgs> { | ||
return transformEncoder( | ||
getStructEncoder([ | ||
['discriminator', getU8Encoder()], | ||
['cpiGuardDiscriminator', getU8Encoder()], | ||
]), | ||
(value) => ({ | ||
...value, | ||
discriminator: DISABLE_CPI_GUARD_DISCRIMINATOR, | ||
cpiGuardDiscriminator: DISABLE_CPI_GUARD_CPI_GUARD_DISCRIMINATOR, | ||
}) | ||
); | ||
} | ||
|
||
export function getDisableCpiGuardInstructionDataDecoder(): Decoder<DisableCpiGuardInstructionData> { | ||
return getStructDecoder([ | ||
['discriminator', getU8Decoder()], | ||
['cpiGuardDiscriminator', getU8Decoder()], | ||
]); | ||
} | ||
|
||
export function getDisableCpiGuardInstructionDataCodec(): Codec< | ||
DisableCpiGuardInstructionDataArgs, | ||
DisableCpiGuardInstructionData | ||
> { | ||
return combineCodec( | ||
getDisableCpiGuardInstructionDataEncoder(), | ||
getDisableCpiGuardInstructionDataDecoder() | ||
); | ||
} | ||
|
||
export type DisableCpiGuardInput< | ||
TAccountToken extends string = string, | ||
TAccountOwner extends string = string, | ||
> = { | ||
/** The token account to update. */ | ||
token: Address<TAccountToken>; | ||
/** The account's owner/delegate or its multisignature account. */ | ||
owner: Address<TAccountOwner> | TransactionSigner<TAccountOwner>; | ||
multiSigners?: Array<TransactionSigner>; | ||
}; | ||
|
||
export function getDisableCpiGuardInstruction< | ||
TAccountToken extends string, | ||
TAccountOwner extends string, | ||
TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, | ||
>( | ||
input: DisableCpiGuardInput<TAccountToken, TAccountOwner>, | ||
config?: { programAddress?: TProgramAddress } | ||
): DisableCpiGuardInstruction< | ||
TProgramAddress, | ||
TAccountToken, | ||
(typeof input)['owner'] extends TransactionSigner<TAccountOwner> | ||
? ReadonlySignerAccount<TAccountOwner> & IAccountSignerMeta<TAccountOwner> | ||
: TAccountOwner | ||
> { | ||
// Program address. | ||
const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS; | ||
|
||
// Original accounts. | ||
const originalAccounts = { | ||
token: { value: input.token ?? null, isWritable: true }, | ||
owner: { value: input.owner ?? 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.token), | ||
getAccountMeta(accounts.owner), | ||
...remainingAccounts, | ||
], | ||
programAddress, | ||
data: getDisableCpiGuardInstructionDataEncoder().encode({}), | ||
} as DisableCpiGuardInstruction< | ||
TProgramAddress, | ||
TAccountToken, | ||
(typeof input)['owner'] extends TransactionSigner<TAccountOwner> | ||
? ReadonlySignerAccount<TAccountOwner> & IAccountSignerMeta<TAccountOwner> | ||
: TAccountOwner | ||
>; | ||
|
||
return instruction; | ||
} | ||
|
||
export type ParsedDisableCpiGuardInstruction< | ||
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, | ||
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], | ||
> = { | ||
programAddress: Address<TProgram>; | ||
accounts: { | ||
/** The token account to update. */ | ||
token: TAccountMetas[0]; | ||
/** The account's owner/delegate or its multisignature account. */ | ||
owner: TAccountMetas[1]; | ||
}; | ||
data: DisableCpiGuardInstructionData; | ||
}; | ||
|
||
export function parseDisableCpiGuardInstruction< | ||
TProgram extends string, | ||
TAccountMetas extends readonly IAccountMeta[], | ||
>( | ||
instruction: IInstruction<TProgram> & | ||
IInstructionWithAccounts<TAccountMetas> & | ||
IInstructionWithData<Uint8Array> | ||
): ParsedDisableCpiGuardInstruction<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: { | ||
token: getNextAccount(), | ||
owner: getNextAccount(), | ||
}, | ||
data: getDisableCpiGuardInstructionDataDecoder().decode(instruction.data), | ||
}; | ||
} |
Oops, something went wrong.