|
| 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 | + addDecoderSizePrefix, |
| 11 | + addEncoderSizePrefix, |
| 12 | + combineCodec, |
| 13 | + fixDecoderSize, |
| 14 | + fixEncoderSize, |
| 15 | + getBytesDecoder, |
| 16 | + getBytesEncoder, |
| 17 | + getStructDecoder, |
| 18 | + getStructEncoder, |
| 19 | + getU32Decoder, |
| 20 | + getU32Encoder, |
| 21 | + getUtf8Decoder, |
| 22 | + getUtf8Encoder, |
| 23 | + transformEncoder, |
| 24 | + type AccountMeta, |
| 25 | + type AccountSignerMeta, |
| 26 | + type Address, |
| 27 | + type Codec, |
| 28 | + type Decoder, |
| 29 | + type Encoder, |
| 30 | + type Instruction, |
| 31 | + type InstructionWithAccounts, |
| 32 | + type InstructionWithData, |
| 33 | + type ReadonlyAccount, |
| 34 | + type ReadonlyUint8Array, |
| 35 | + type TransactionSigner, |
| 36 | + type WritableAccount, |
| 37 | + type WritableSignerAccount, |
| 38 | +} from '@solana/kit'; |
| 39 | +import { BRIDGE_PROGRAM_ADDRESS } from '../programs'; |
| 40 | +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; |
| 41 | + |
| 42 | +export const SET_WRAPPED_TOKEN_URI_DISCRIMINATOR = new Uint8Array([ |
| 43 | + 248, 70, 157, 26, 216, 32, 48, 11, |
| 44 | +]); |
| 45 | + |
| 46 | +export function getSetWrappedTokenUriDiscriminatorBytes() { |
| 47 | + return fixEncoderSize(getBytesEncoder(), 8).encode( |
| 48 | + SET_WRAPPED_TOKEN_URI_DISCRIMINATOR |
| 49 | + ); |
| 50 | +} |
| 51 | + |
| 52 | +export type SetWrappedTokenUriInstruction< |
| 53 | + TProgram extends string = typeof BRIDGE_PROGRAM_ADDRESS, |
| 54 | + TAccountPayer extends string | AccountMeta<string> = string, |
| 55 | + TAccountMint extends string | AccountMeta<string> = string, |
| 56 | + TAccountBridge extends string | AccountMeta<string> = string, |
| 57 | + TAccountTokenProgram extends |
| 58 | + | string |
| 59 | + | AccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', |
| 60 | + TAccountSystemProgram extends |
| 61 | + | string |
| 62 | + | AccountMeta<string> = '11111111111111111111111111111111', |
| 63 | + TRemainingAccounts extends readonly AccountMeta<string>[] = [], |
| 64 | +> = Instruction<TProgram> & |
| 65 | + InstructionWithData<ReadonlyUint8Array> & |
| 66 | + InstructionWithAccounts< |
| 67 | + [ |
| 68 | + TAccountPayer extends string |
| 69 | + ? WritableSignerAccount<TAccountPayer> & |
| 70 | + AccountSignerMeta<TAccountPayer> |
| 71 | + : TAccountPayer, |
| 72 | + TAccountMint extends string |
| 73 | + ? WritableAccount<TAccountMint> |
| 74 | + : TAccountMint, |
| 75 | + TAccountBridge extends string |
| 76 | + ? ReadonlyAccount<TAccountBridge> |
| 77 | + : TAccountBridge, |
| 78 | + TAccountTokenProgram extends string |
| 79 | + ? ReadonlyAccount<TAccountTokenProgram> |
| 80 | + : TAccountTokenProgram, |
| 81 | + TAccountSystemProgram extends string |
| 82 | + ? ReadonlyAccount<TAccountSystemProgram> |
| 83 | + : TAccountSystemProgram, |
| 84 | + ...TRemainingAccounts, |
| 85 | + ] |
| 86 | + >; |
| 87 | + |
| 88 | +export type SetWrappedTokenUriInstructionData = { |
| 89 | + discriminator: ReadonlyUint8Array; |
| 90 | + uri: string; |
| 91 | +}; |
| 92 | + |
| 93 | +export type SetWrappedTokenUriInstructionDataArgs = { uri: string }; |
| 94 | + |
| 95 | +export function getSetWrappedTokenUriInstructionDataEncoder(): Encoder<SetWrappedTokenUriInstructionDataArgs> { |
| 96 | + return transformEncoder( |
| 97 | + getStructEncoder([ |
| 98 | + ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], |
| 99 | + ['uri', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], |
| 100 | + ]), |
| 101 | + (value) => ({ |
| 102 | + ...value, |
| 103 | + discriminator: SET_WRAPPED_TOKEN_URI_DISCRIMINATOR, |
| 104 | + }) |
| 105 | + ); |
| 106 | +} |
| 107 | + |
| 108 | +export function getSetWrappedTokenUriInstructionDataDecoder(): Decoder<SetWrappedTokenUriInstructionData> { |
| 109 | + return getStructDecoder([ |
| 110 | + ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], |
| 111 | + ['uri', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], |
| 112 | + ]); |
| 113 | +} |
| 114 | + |
| 115 | +export function getSetWrappedTokenUriInstructionDataCodec(): Codec< |
| 116 | + SetWrappedTokenUriInstructionDataArgs, |
| 117 | + SetWrappedTokenUriInstructionData |
| 118 | +> { |
| 119 | + return combineCodec( |
| 120 | + getSetWrappedTokenUriInstructionDataEncoder(), |
| 121 | + getSetWrappedTokenUriInstructionDataDecoder() |
| 122 | + ); |
| 123 | +} |
| 124 | + |
| 125 | +export type SetWrappedTokenUriInput< |
| 126 | + TAccountPayer extends string = string, |
| 127 | + TAccountMint extends string = string, |
| 128 | + TAccountBridge extends string = string, |
| 129 | + TAccountTokenProgram extends string = string, |
| 130 | + TAccountSystemProgram extends string = string, |
| 131 | +> = { |
| 132 | + /** The account that pays for the mint account's rent increase. */ |
| 133 | + payer: TransactionSigner<TAccountPayer>; |
| 134 | + /** |
| 135 | + * The wrapped token mint whose uri is being filled in. Validated to be a wrapped token PDA of |
| 136 | + * this program by recomputing its metadata hash, which is what makes the mint's own signature |
| 137 | + * available for the metadata update below. |
| 138 | + */ |
| 139 | + mint: Address<TAccountMint>; |
| 140 | + /** The main bridge state account, read to honor the pause switch. */ |
| 141 | + bridge: Address<TAccountBridge>; |
| 142 | + /** SPL Token-2022 program that owns the mint's metadata extension. */ |
| 143 | + tokenProgram?: Address<TAccountTokenProgram>; |
| 144 | + /** System program used to top up the mint's rent before its metadata grows. */ |
| 145 | + systemProgram?: Address<TAccountSystemProgram>; |
| 146 | + uri: SetWrappedTokenUriInstructionDataArgs['uri']; |
| 147 | +}; |
| 148 | + |
| 149 | +export function getSetWrappedTokenUriInstruction< |
| 150 | + TAccountPayer extends string, |
| 151 | + TAccountMint extends string, |
| 152 | + TAccountBridge extends string, |
| 153 | + TAccountTokenProgram extends string, |
| 154 | + TAccountSystemProgram extends string, |
| 155 | + TProgramAddress extends Address = typeof BRIDGE_PROGRAM_ADDRESS, |
| 156 | +>( |
| 157 | + input: SetWrappedTokenUriInput< |
| 158 | + TAccountPayer, |
| 159 | + TAccountMint, |
| 160 | + TAccountBridge, |
| 161 | + TAccountTokenProgram, |
| 162 | + TAccountSystemProgram |
| 163 | + >, |
| 164 | + config?: { programAddress?: TProgramAddress } |
| 165 | +): SetWrappedTokenUriInstruction< |
| 166 | + TProgramAddress, |
| 167 | + TAccountPayer, |
| 168 | + TAccountMint, |
| 169 | + TAccountBridge, |
| 170 | + TAccountTokenProgram, |
| 171 | + TAccountSystemProgram |
| 172 | +> { |
| 173 | + // Program address. |
| 174 | + const programAddress = config?.programAddress ?? BRIDGE_PROGRAM_ADDRESS; |
| 175 | + |
| 176 | + // Original accounts. |
| 177 | + const originalAccounts = { |
| 178 | + payer: { value: input.payer ?? null, isWritable: true }, |
| 179 | + mint: { value: input.mint ?? null, isWritable: true }, |
| 180 | + bridge: { value: input.bridge ?? null, isWritable: false }, |
| 181 | + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, |
| 182 | + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, |
| 183 | + }; |
| 184 | + const accounts = originalAccounts as Record< |
| 185 | + keyof typeof originalAccounts, |
| 186 | + ResolvedAccount |
| 187 | + >; |
| 188 | + |
| 189 | + // Original args. |
| 190 | + const args = { ...input }; |
| 191 | + |
| 192 | + // Resolve default values. |
| 193 | + if (!accounts.tokenProgram.value) { |
| 194 | + accounts.tokenProgram.value = |
| 195 | + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; |
| 196 | + } |
| 197 | + if (!accounts.systemProgram.value) { |
| 198 | + accounts.systemProgram.value = |
| 199 | + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; |
| 200 | + } |
| 201 | + |
| 202 | + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); |
| 203 | + return Object.freeze({ |
| 204 | + accounts: [ |
| 205 | + getAccountMeta(accounts.payer), |
| 206 | + getAccountMeta(accounts.mint), |
| 207 | + getAccountMeta(accounts.bridge), |
| 208 | + getAccountMeta(accounts.tokenProgram), |
| 209 | + getAccountMeta(accounts.systemProgram), |
| 210 | + ], |
| 211 | + data: getSetWrappedTokenUriInstructionDataEncoder().encode( |
| 212 | + args as SetWrappedTokenUriInstructionDataArgs |
| 213 | + ), |
| 214 | + programAddress, |
| 215 | + } as SetWrappedTokenUriInstruction< |
| 216 | + TProgramAddress, |
| 217 | + TAccountPayer, |
| 218 | + TAccountMint, |
| 219 | + TAccountBridge, |
| 220 | + TAccountTokenProgram, |
| 221 | + TAccountSystemProgram |
| 222 | + >); |
| 223 | +} |
| 224 | + |
| 225 | +export type ParsedSetWrappedTokenUriInstruction< |
| 226 | + TProgram extends string = typeof BRIDGE_PROGRAM_ADDRESS, |
| 227 | + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], |
| 228 | +> = { |
| 229 | + programAddress: Address<TProgram>; |
| 230 | + accounts: { |
| 231 | + /** The account that pays for the mint account's rent increase. */ |
| 232 | + payer: TAccountMetas[0]; |
| 233 | + /** |
| 234 | + * The wrapped token mint whose uri is being filled in. Validated to be a wrapped token PDA of |
| 235 | + * this program by recomputing its metadata hash, which is what makes the mint's own signature |
| 236 | + * available for the metadata update below. |
| 237 | + */ |
| 238 | + mint: TAccountMetas[1]; |
| 239 | + /** The main bridge state account, read to honor the pause switch. */ |
| 240 | + bridge: TAccountMetas[2]; |
| 241 | + /** SPL Token-2022 program that owns the mint's metadata extension. */ |
| 242 | + tokenProgram: TAccountMetas[3]; |
| 243 | + /** System program used to top up the mint's rent before its metadata grows. */ |
| 244 | + systemProgram: TAccountMetas[4]; |
| 245 | + }; |
| 246 | + data: SetWrappedTokenUriInstructionData; |
| 247 | +}; |
| 248 | + |
| 249 | +export function parseSetWrappedTokenUriInstruction< |
| 250 | + TProgram extends string, |
| 251 | + TAccountMetas extends readonly AccountMeta[], |
| 252 | +>( |
| 253 | + instruction: Instruction<TProgram> & |
| 254 | + InstructionWithAccounts<TAccountMetas> & |
| 255 | + InstructionWithData<ReadonlyUint8Array> |
| 256 | +): ParsedSetWrappedTokenUriInstruction<TProgram, TAccountMetas> { |
| 257 | + if (instruction.accounts.length < 5) { |
| 258 | + // TODO: Coded error. |
| 259 | + throw new Error('Not enough accounts'); |
| 260 | + } |
| 261 | + let accountIndex = 0; |
| 262 | + const getNextAccount = () => { |
| 263 | + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; |
| 264 | + accountIndex += 1; |
| 265 | + return accountMeta; |
| 266 | + }; |
| 267 | + return { |
| 268 | + programAddress: instruction.programAddress, |
| 269 | + accounts: { |
| 270 | + payer: getNextAccount(), |
| 271 | + mint: getNextAccount(), |
| 272 | + bridge: getNextAccount(), |
| 273 | + tokenProgram: getNextAccount(), |
| 274 | + systemProgram: getNextAccount(), |
| 275 | + }, |
| 276 | + data: getSetWrappedTokenUriInstructionDataDecoder().decode( |
| 277 | + instruction.data |
| 278 | + ), |
| 279 | + }; |
| 280 | +} |
0 commit comments