|
| 1 | +/** |
| 2 | + * This code was AUTOGENERATED using the kinobi library. |
| 3 | + * Please DO NOT EDIT THIS FILE, instead use visitors |
| 4 | + * to add features, then rerun kinobi to update it. |
| 5 | + * |
| 6 | + * @see https://github.com/kinobi-so/kinobi |
| 7 | + */ |
| 8 | + |
| 9 | +import { |
| 10 | + combineCodec, |
| 11 | + getStructDecoder, |
| 12 | + getStructEncoder, |
| 13 | + getU8Decoder, |
| 14 | + getU8Encoder, |
| 15 | + transformEncoder, |
| 16 | + type Address, |
| 17 | + type Codec, |
| 18 | + type Decoder, |
| 19 | + type Encoder, |
| 20 | + type IAccountMeta, |
| 21 | + type IAccountSignerMeta, |
| 22 | + type IInstruction, |
| 23 | + type IInstructionWithAccounts, |
| 24 | + type IInstructionWithData, |
| 25 | + type ReadonlySignerAccount, |
| 26 | + type TransactionSigner, |
| 27 | + type WritableAccount, |
| 28 | +} from '@solana/web3.js'; |
| 29 | +import { JITO_RESTAKING_PROGRAM_ADDRESS } from '../programs'; |
| 30 | +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; |
| 31 | + |
| 32 | +export const SET_CONFIG_ADMIN_DISCRIMINATOR = 24; |
| 33 | + |
| 34 | +export function getSetConfigAdminDiscriminatorBytes() { |
| 35 | + return getU8Encoder().encode(SET_CONFIG_ADMIN_DISCRIMINATOR); |
| 36 | +} |
| 37 | + |
| 38 | +export type SetConfigAdminInstruction< |
| 39 | + TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS, |
| 40 | + TAccountConfig extends string | IAccountMeta<string> = string, |
| 41 | + TAccountOldAdmin extends string | IAccountMeta<string> = string, |
| 42 | + TAccountNewAdmin extends string | IAccountMeta<string> = string, |
| 43 | + TRemainingAccounts extends readonly IAccountMeta<string>[] = [], |
| 44 | +> = IInstruction<TProgram> & |
| 45 | + IInstructionWithData<Uint8Array> & |
| 46 | + IInstructionWithAccounts< |
| 47 | + [ |
| 48 | + TAccountConfig extends string |
| 49 | + ? WritableAccount<TAccountConfig> |
| 50 | + : TAccountConfig, |
| 51 | + TAccountOldAdmin extends string |
| 52 | + ? ReadonlySignerAccount<TAccountOldAdmin> & |
| 53 | + IAccountSignerMeta<TAccountOldAdmin> |
| 54 | + : TAccountOldAdmin, |
| 55 | + TAccountNewAdmin extends string |
| 56 | + ? ReadonlySignerAccount<TAccountNewAdmin> & |
| 57 | + IAccountSignerMeta<TAccountNewAdmin> |
| 58 | + : TAccountNewAdmin, |
| 59 | + ...TRemainingAccounts, |
| 60 | + ] |
| 61 | + >; |
| 62 | + |
| 63 | +export type SetConfigAdminInstructionData = { discriminator: number }; |
| 64 | + |
| 65 | +export type SetConfigAdminInstructionDataArgs = {}; |
| 66 | + |
| 67 | +export function getSetConfigAdminInstructionDataEncoder(): Encoder<SetConfigAdminInstructionDataArgs> { |
| 68 | + return transformEncoder( |
| 69 | + getStructEncoder([['discriminator', getU8Encoder()]]), |
| 70 | + (value) => ({ ...value, discriminator: SET_CONFIG_ADMIN_DISCRIMINATOR }) |
| 71 | + ); |
| 72 | +} |
| 73 | + |
| 74 | +export function getSetConfigAdminInstructionDataDecoder(): Decoder<SetConfigAdminInstructionData> { |
| 75 | + return getStructDecoder([['discriminator', getU8Decoder()]]); |
| 76 | +} |
| 77 | + |
| 78 | +export function getSetConfigAdminInstructionDataCodec(): Codec< |
| 79 | + SetConfigAdminInstructionDataArgs, |
| 80 | + SetConfigAdminInstructionData |
| 81 | +> { |
| 82 | + return combineCodec( |
| 83 | + getSetConfigAdminInstructionDataEncoder(), |
| 84 | + getSetConfigAdminInstructionDataDecoder() |
| 85 | + ); |
| 86 | +} |
| 87 | + |
| 88 | +export type SetConfigAdminInput< |
| 89 | + TAccountConfig extends string = string, |
| 90 | + TAccountOldAdmin extends string = string, |
| 91 | + TAccountNewAdmin extends string = string, |
| 92 | +> = { |
| 93 | + config: Address<TAccountConfig>; |
| 94 | + oldAdmin: TransactionSigner<TAccountOldAdmin>; |
| 95 | + newAdmin: TransactionSigner<TAccountNewAdmin>; |
| 96 | +}; |
| 97 | + |
| 98 | +export function getSetConfigAdminInstruction< |
| 99 | + TAccountConfig extends string, |
| 100 | + TAccountOldAdmin extends string, |
| 101 | + TAccountNewAdmin extends string, |
| 102 | +>( |
| 103 | + input: SetConfigAdminInput<TAccountConfig, TAccountOldAdmin, TAccountNewAdmin> |
| 104 | +): SetConfigAdminInstruction< |
| 105 | + typeof JITO_RESTAKING_PROGRAM_ADDRESS, |
| 106 | + TAccountConfig, |
| 107 | + TAccountOldAdmin, |
| 108 | + TAccountNewAdmin |
| 109 | +> { |
| 110 | + // Program address. |
| 111 | + const programAddress = JITO_RESTAKING_PROGRAM_ADDRESS; |
| 112 | + |
| 113 | + // Original accounts. |
| 114 | + const originalAccounts = { |
| 115 | + config: { value: input.config ?? null, isWritable: true }, |
| 116 | + oldAdmin: { value: input.oldAdmin ?? null, isWritable: false }, |
| 117 | + newAdmin: { value: input.newAdmin ?? null, isWritable: false }, |
| 118 | + }; |
| 119 | + const accounts = originalAccounts as Record< |
| 120 | + keyof typeof originalAccounts, |
| 121 | + ResolvedAccount |
| 122 | + >; |
| 123 | + |
| 124 | + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); |
| 125 | + const instruction = { |
| 126 | + accounts: [ |
| 127 | + getAccountMeta(accounts.config), |
| 128 | + getAccountMeta(accounts.oldAdmin), |
| 129 | + getAccountMeta(accounts.newAdmin), |
| 130 | + ], |
| 131 | + programAddress, |
| 132 | + data: getSetConfigAdminInstructionDataEncoder().encode({}), |
| 133 | + } as SetConfigAdminInstruction< |
| 134 | + typeof JITO_RESTAKING_PROGRAM_ADDRESS, |
| 135 | + TAccountConfig, |
| 136 | + TAccountOldAdmin, |
| 137 | + TAccountNewAdmin |
| 138 | + >; |
| 139 | + |
| 140 | + return instruction; |
| 141 | +} |
| 142 | + |
| 143 | +export type ParsedSetConfigAdminInstruction< |
| 144 | + TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS, |
| 145 | + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], |
| 146 | +> = { |
| 147 | + programAddress: Address<TProgram>; |
| 148 | + accounts: { |
| 149 | + config: TAccountMetas[0]; |
| 150 | + oldAdmin: TAccountMetas[1]; |
| 151 | + newAdmin: TAccountMetas[2]; |
| 152 | + }; |
| 153 | + data: SetConfigAdminInstructionData; |
| 154 | +}; |
| 155 | + |
| 156 | +export function parseSetConfigAdminInstruction< |
| 157 | + TProgram extends string, |
| 158 | + TAccountMetas extends readonly IAccountMeta[], |
| 159 | +>( |
| 160 | + instruction: IInstruction<TProgram> & |
| 161 | + IInstructionWithAccounts<TAccountMetas> & |
| 162 | + IInstructionWithData<Uint8Array> |
| 163 | +): ParsedSetConfigAdminInstruction<TProgram, TAccountMetas> { |
| 164 | + if (instruction.accounts.length < 3) { |
| 165 | + // TODO: Coded error. |
| 166 | + throw new Error('Not enough accounts'); |
| 167 | + } |
| 168 | + let accountIndex = 0; |
| 169 | + const getNextAccount = () => { |
| 170 | + const accountMeta = instruction.accounts![accountIndex]!; |
| 171 | + accountIndex += 1; |
| 172 | + return accountMeta; |
| 173 | + }; |
| 174 | + return { |
| 175 | + programAddress: instruction.programAddress, |
| 176 | + accounts: { |
| 177 | + config: getNextAccount(), |
| 178 | + oldAdmin: getNextAccount(), |
| 179 | + newAdmin: getNextAccount(), |
| 180 | + }, |
| 181 | + data: getSetConfigAdminInstructionDataDecoder().decode(instruction.data), |
| 182 | + }; |
| 183 | +} |
0 commit comments