|
| 1 | +/** |
| 2 | + * This code was AUTOGENERATED using the codama library. |
| 3 | + * Please DO NOT EDIT THIS FILE, instead use visitors |
| 4 | + * to add features, then rerun codama to update it. |
| 5 | + * |
| 6 | + * @see https://github.com/codama-idl/codama |
| 7 | + */ |
| 8 | + |
| 9 | +import { |
| 10 | + combineCodec, |
| 11 | + fixDecoderSize, |
| 12 | + fixEncoderSize, |
| 13 | + getBytesDecoder, |
| 14 | + getBytesEncoder, |
| 15 | + getStructDecoder, |
| 16 | + getStructEncoder, |
| 17 | + transformEncoder, |
| 18 | + type Address, |
| 19 | + type Codec, |
| 20 | + type Decoder, |
| 21 | + type Encoder, |
| 22 | + type IAccountMeta, |
| 23 | + type IAccountSignerMeta, |
| 24 | + type IInstruction, |
| 25 | + type IInstructionWithAccounts, |
| 26 | + type IInstructionWithData, |
| 27 | + type ReadonlySignerAccount, |
| 28 | + type ReadonlyUint8Array, |
| 29 | + type TransactionSigner, |
| 30 | + type WritableAccount, |
| 31 | +} from '@solana/kit'; |
| 32 | +import { BRIDGE_PROGRAM_ADDRESS } from '../programs'; |
| 33 | +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; |
| 34 | +import { |
| 35 | + getPartnerOracleConfigDecoder, |
| 36 | + getPartnerOracleConfigEncoder, |
| 37 | + type PartnerOracleConfig, |
| 38 | + type PartnerOracleConfigArgs, |
| 39 | +} from '../types'; |
| 40 | + |
| 41 | +export const SET_PARTNER_ORACLE_CONFIG_DISCRIMINATOR = new Uint8Array([ |
| 42 | + 34, 48, 231, 135, 42, 113, 217, 157, |
| 43 | +]); |
| 44 | + |
| 45 | +export function getSetPartnerOracleConfigDiscriminatorBytes() { |
| 46 | + return fixEncoderSize(getBytesEncoder(), 8).encode( |
| 47 | + SET_PARTNER_ORACLE_CONFIG_DISCRIMINATOR |
| 48 | + ); |
| 49 | +} |
| 50 | + |
| 51 | +export type SetPartnerOracleConfigInstruction< |
| 52 | + TProgram extends string = typeof BRIDGE_PROGRAM_ADDRESS, |
| 53 | + TAccountBridge extends string | IAccountMeta<string> = string, |
| 54 | + TAccountGuardian extends string | IAccountMeta<string> = string, |
| 55 | + TRemainingAccounts extends readonly IAccountMeta<string>[] = [], |
| 56 | +> = IInstruction<TProgram> & |
| 57 | + IInstructionWithData<Uint8Array> & |
| 58 | + IInstructionWithAccounts< |
| 59 | + [ |
| 60 | + TAccountBridge extends string |
| 61 | + ? WritableAccount<TAccountBridge> |
| 62 | + : TAccountBridge, |
| 63 | + TAccountGuardian extends string |
| 64 | + ? ReadonlySignerAccount<TAccountGuardian> & |
| 65 | + IAccountSignerMeta<TAccountGuardian> |
| 66 | + : TAccountGuardian, |
| 67 | + ...TRemainingAccounts, |
| 68 | + ] |
| 69 | + >; |
| 70 | + |
| 71 | +export type SetPartnerOracleConfigInstructionData = { |
| 72 | + discriminator: ReadonlyUint8Array; |
| 73 | + newConfig: PartnerOracleConfig; |
| 74 | +}; |
| 75 | + |
| 76 | +export type SetPartnerOracleConfigInstructionDataArgs = { |
| 77 | + newConfig: PartnerOracleConfigArgs; |
| 78 | +}; |
| 79 | + |
| 80 | +export function getSetPartnerOracleConfigInstructionDataEncoder(): Encoder<SetPartnerOracleConfigInstructionDataArgs> { |
| 81 | + return transformEncoder( |
| 82 | + getStructEncoder([ |
| 83 | + ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], |
| 84 | + ['newConfig', getPartnerOracleConfigEncoder()], |
| 85 | + ]), |
| 86 | + (value) => ({ |
| 87 | + ...value, |
| 88 | + discriminator: SET_PARTNER_ORACLE_CONFIG_DISCRIMINATOR, |
| 89 | + }) |
| 90 | + ); |
| 91 | +} |
| 92 | + |
| 93 | +export function getSetPartnerOracleConfigInstructionDataDecoder(): Decoder<SetPartnerOracleConfigInstructionData> { |
| 94 | + return getStructDecoder([ |
| 95 | + ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], |
| 96 | + ['newConfig', getPartnerOracleConfigDecoder()], |
| 97 | + ]); |
| 98 | +} |
| 99 | + |
| 100 | +export function getSetPartnerOracleConfigInstructionDataCodec(): Codec< |
| 101 | + SetPartnerOracleConfigInstructionDataArgs, |
| 102 | + SetPartnerOracleConfigInstructionData |
| 103 | +> { |
| 104 | + return combineCodec( |
| 105 | + getSetPartnerOracleConfigInstructionDataEncoder(), |
| 106 | + getSetPartnerOracleConfigInstructionDataDecoder() |
| 107 | + ); |
| 108 | +} |
| 109 | + |
| 110 | +export type SetPartnerOracleConfigInput< |
| 111 | + TAccountBridge extends string = string, |
| 112 | + TAccountGuardian extends string = string, |
| 113 | +> = { |
| 114 | + /** The bridge account containing configuration */ |
| 115 | + bridge: Address<TAccountBridge>; |
| 116 | + /** The guardian account authorized to update configuration */ |
| 117 | + guardian: TransactionSigner<TAccountGuardian>; |
| 118 | + newConfig: SetPartnerOracleConfigInstructionDataArgs['newConfig']; |
| 119 | +}; |
| 120 | + |
| 121 | +export function getSetPartnerOracleConfigInstruction< |
| 122 | + TAccountBridge extends string, |
| 123 | + TAccountGuardian extends string, |
| 124 | + TProgramAddress extends Address = typeof BRIDGE_PROGRAM_ADDRESS, |
| 125 | +>( |
| 126 | + input: SetPartnerOracleConfigInput<TAccountBridge, TAccountGuardian>, |
| 127 | + config?: { programAddress?: TProgramAddress } |
| 128 | +): SetPartnerOracleConfigInstruction< |
| 129 | + TProgramAddress, |
| 130 | + TAccountBridge, |
| 131 | + TAccountGuardian |
| 132 | +> { |
| 133 | + // Program address. |
| 134 | + const programAddress = config?.programAddress ?? BRIDGE_PROGRAM_ADDRESS; |
| 135 | + |
| 136 | + // Original accounts. |
| 137 | + const originalAccounts = { |
| 138 | + bridge: { value: input.bridge ?? null, isWritable: true }, |
| 139 | + guardian: { value: input.guardian ?? null, isWritable: false }, |
| 140 | + }; |
| 141 | + const accounts = originalAccounts as Record< |
| 142 | + keyof typeof originalAccounts, |
| 143 | + ResolvedAccount |
| 144 | + >; |
| 145 | + |
| 146 | + // Original args. |
| 147 | + const args = { ...input }; |
| 148 | + |
| 149 | + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); |
| 150 | + const instruction = { |
| 151 | + accounts: [ |
| 152 | + getAccountMeta(accounts.bridge), |
| 153 | + getAccountMeta(accounts.guardian), |
| 154 | + ], |
| 155 | + programAddress, |
| 156 | + data: getSetPartnerOracleConfigInstructionDataEncoder().encode( |
| 157 | + args as SetPartnerOracleConfigInstructionDataArgs |
| 158 | + ), |
| 159 | + } as SetPartnerOracleConfigInstruction< |
| 160 | + TProgramAddress, |
| 161 | + TAccountBridge, |
| 162 | + TAccountGuardian |
| 163 | + >; |
| 164 | + |
| 165 | + return instruction; |
| 166 | +} |
| 167 | + |
| 168 | +export type ParsedSetPartnerOracleConfigInstruction< |
| 169 | + TProgram extends string = typeof BRIDGE_PROGRAM_ADDRESS, |
| 170 | + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], |
| 171 | +> = { |
| 172 | + programAddress: Address<TProgram>; |
| 173 | + accounts: { |
| 174 | + /** The bridge account containing configuration */ |
| 175 | + bridge: TAccountMetas[0]; |
| 176 | + /** The guardian account authorized to update configuration */ |
| 177 | + guardian: TAccountMetas[1]; |
| 178 | + }; |
| 179 | + data: SetPartnerOracleConfigInstructionData; |
| 180 | +}; |
| 181 | + |
| 182 | +export function parseSetPartnerOracleConfigInstruction< |
| 183 | + TProgram extends string, |
| 184 | + TAccountMetas extends readonly IAccountMeta[], |
| 185 | +>( |
| 186 | + instruction: IInstruction<TProgram> & |
| 187 | + IInstructionWithAccounts<TAccountMetas> & |
| 188 | + IInstructionWithData<Uint8Array> |
| 189 | +): ParsedSetPartnerOracleConfigInstruction<TProgram, TAccountMetas> { |
| 190 | + if (instruction.accounts.length < 2) { |
| 191 | + // TODO: Coded error. |
| 192 | + throw new Error('Not enough accounts'); |
| 193 | + } |
| 194 | + let accountIndex = 0; |
| 195 | + const getNextAccount = () => { |
| 196 | + const accountMeta = instruction.accounts![accountIndex]!; |
| 197 | + accountIndex += 1; |
| 198 | + return accountMeta; |
| 199 | + }; |
| 200 | + return { |
| 201 | + programAddress: instruction.programAddress, |
| 202 | + accounts: { |
| 203 | + bridge: getNextAccount(), |
| 204 | + guardian: getNextAccount(), |
| 205 | + }, |
| 206 | + data: getSetPartnerOracleConfigInstructionDataDecoder().decode( |
| 207 | + instruction.data |
| 208 | + ), |
| 209 | + }; |
| 210 | +} |
0 commit comments