|
| 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 | + assertAccountExists, |
| 11 | + assertAccountsExist, |
| 12 | + combineCodec, |
| 13 | + decodeAccount, |
| 14 | + fetchEncodedAccount, |
| 15 | + fetchEncodedAccounts, |
| 16 | + getAddressDecoder, |
| 17 | + getAddressEncoder, |
| 18 | + getArrayDecoder, |
| 19 | + getArrayEncoder, |
| 20 | + getStructDecoder, |
| 21 | + getStructEncoder, |
| 22 | + getU64Decoder, |
| 23 | + getU64Encoder, |
| 24 | + getU8Decoder, |
| 25 | + getU8Encoder, |
| 26 | + type Account, |
| 27 | + type Address, |
| 28 | + type Codec, |
| 29 | + type Decoder, |
| 30 | + type EncodedAccount, |
| 31 | + type Encoder, |
| 32 | + type FetchAccountConfig, |
| 33 | + type FetchAccountsConfig, |
| 34 | + type MaybeAccount, |
| 35 | + type MaybeEncodedAccount, |
| 36 | +} from '@solana/web3.js'; |
| 37 | +import { |
| 38 | + getFeesDecoder, |
| 39 | + getFeesEncoder, |
| 40 | + type Fees, |
| 41 | + type FeesArgs, |
| 42 | +} from '../types'; |
| 43 | + |
| 44 | +export type NcnConfig = { |
| 45 | + discriminator: bigint; |
| 46 | + ncn: Address; |
| 47 | + tieBreakerAdmin: Address; |
| 48 | + fees: Fees; |
| 49 | + bump: number; |
| 50 | + reserved: Array<number>; |
| 51 | +}; |
| 52 | + |
| 53 | +export type NcnConfigArgs = { |
| 54 | + discriminator: number | bigint; |
| 55 | + ncn: Address; |
| 56 | + tieBreakerAdmin: Address; |
| 57 | + fees: FeesArgs; |
| 58 | + bump: number; |
| 59 | + reserved: Array<number>; |
| 60 | +}; |
| 61 | + |
| 62 | +export function getNcnConfigEncoder(): Encoder<NcnConfigArgs> { |
| 63 | + return getStructEncoder([ |
| 64 | + ['discriminator', getU64Encoder()], |
| 65 | + ['ncn', getAddressEncoder()], |
| 66 | + ['tieBreakerAdmin', getAddressEncoder()], |
| 67 | + ['fees', getFeesEncoder()], |
| 68 | + ['bump', getU8Encoder()], |
| 69 | + ['reserved', getArrayEncoder(getU8Encoder(), { size: 127 })], |
| 70 | + ]); |
| 71 | +} |
| 72 | + |
| 73 | +export function getNcnConfigDecoder(): Decoder<NcnConfig> { |
| 74 | + return getStructDecoder([ |
| 75 | + ['discriminator', getU64Decoder()], |
| 76 | + ['ncn', getAddressDecoder()], |
| 77 | + ['tieBreakerAdmin', getAddressDecoder()], |
| 78 | + ['fees', getFeesDecoder()], |
| 79 | + ['bump', getU8Decoder()], |
| 80 | + ['reserved', getArrayDecoder(getU8Decoder(), { size: 127 })], |
| 81 | + ]); |
| 82 | +} |
| 83 | + |
| 84 | +export function getNcnConfigCodec(): Codec<NcnConfigArgs, NcnConfig> { |
| 85 | + return combineCodec(getNcnConfigEncoder(), getNcnConfigDecoder()); |
| 86 | +} |
| 87 | + |
| 88 | +export function decodeNcnConfig<TAddress extends string = string>( |
| 89 | + encodedAccount: EncodedAccount<TAddress> |
| 90 | +): Account<NcnConfig, TAddress>; |
| 91 | +export function decodeNcnConfig<TAddress extends string = string>( |
| 92 | + encodedAccount: MaybeEncodedAccount<TAddress> |
| 93 | +): MaybeAccount<NcnConfig, TAddress>; |
| 94 | +export function decodeNcnConfig<TAddress extends string = string>( |
| 95 | + encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress> |
| 96 | +): Account<NcnConfig, TAddress> | MaybeAccount<NcnConfig, TAddress> { |
| 97 | + return decodeAccount( |
| 98 | + encodedAccount as MaybeEncodedAccount<TAddress>, |
| 99 | + getNcnConfigDecoder() |
| 100 | + ); |
| 101 | +} |
| 102 | + |
| 103 | +export async function fetchNcnConfig<TAddress extends string = string>( |
| 104 | + rpc: Parameters<typeof fetchEncodedAccount>[0], |
| 105 | + address: Address<TAddress>, |
| 106 | + config?: FetchAccountConfig |
| 107 | +): Promise<Account<NcnConfig, TAddress>> { |
| 108 | + const maybeAccount = await fetchMaybeNcnConfig(rpc, address, config); |
| 109 | + assertAccountExists(maybeAccount); |
| 110 | + return maybeAccount; |
| 111 | +} |
| 112 | + |
| 113 | +export async function fetchMaybeNcnConfig<TAddress extends string = string>( |
| 114 | + rpc: Parameters<typeof fetchEncodedAccount>[0], |
| 115 | + address: Address<TAddress>, |
| 116 | + config?: FetchAccountConfig |
| 117 | +): Promise<MaybeAccount<NcnConfig, TAddress>> { |
| 118 | + const maybeAccount = await fetchEncodedAccount(rpc, address, config); |
| 119 | + return decodeNcnConfig(maybeAccount); |
| 120 | +} |
| 121 | + |
| 122 | +export async function fetchAllNcnConfig( |
| 123 | + rpc: Parameters<typeof fetchEncodedAccounts>[0], |
| 124 | + addresses: Array<Address>, |
| 125 | + config?: FetchAccountsConfig |
| 126 | +): Promise<Account<NcnConfig>[]> { |
| 127 | + const maybeAccounts = await fetchAllMaybeNcnConfig(rpc, addresses, config); |
| 128 | + assertAccountsExist(maybeAccounts); |
| 129 | + return maybeAccounts; |
| 130 | +} |
| 131 | + |
| 132 | +export async function fetchAllMaybeNcnConfig( |
| 133 | + rpc: Parameters<typeof fetchEncodedAccounts>[0], |
| 134 | + addresses: Array<Address>, |
| 135 | + config?: FetchAccountsConfig |
| 136 | +): Promise<MaybeAccount<NcnConfig>[]> { |
| 137 | + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); |
| 138 | + return maybeAccounts.map((maybeAccount) => decodeNcnConfig(maybeAccount)); |
| 139 | +} |
| 140 | + |
| 141 | +export function getNcnConfigSize(): number { |
| 142 | + return 320; |
| 143 | +} |
0 commit comments