/**
 * 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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array } from '@solana/kit';

export const PROTOCOL_POSITION_STATE_DISCRIMINATOR = new Uint8Array([100, 226, 145, 99, 146, 218, 160, 106]);

export function getProtocolPositionStateDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PROTOCOL_POSITION_STATE_DISCRIMINATOR); }

export type ProtocolPositionState = { discriminator: ReadonlyUint8Array; bump: number; poolId: Address; tickLowerIndex: number; tickUpperIndex: number; liquidity: bigint; feeGrowthInside0LastX64: bigint; feeGrowthInside1LastX64: bigint; tokenFeesOwed0: bigint; tokenFeesOwed1: bigint; rewardGrowthInside: Array<bigint>; padding: Array<bigint>;  };

export type ProtocolPositionStateArgs = { bump: number; poolId: Address; tickLowerIndex: number; tickUpperIndex: number; liquidity: number | bigint; feeGrowthInside0LastX64: number | bigint; feeGrowthInside1LastX64: number | bigint; tokenFeesOwed0: number | bigint; tokenFeesOwed1: number | bigint; rewardGrowthInside: Array<number | bigint>; padding: Array<number | bigint>;  };

/** Gets the encoder for {@link ProtocolPositionStateArgs} account data. */
export function getProtocolPositionStateEncoder(): FixedSizeEncoder<ProtocolPositionStateArgs> {
    return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['bump', getU8Encoder()], ['poolId', getAddressEncoder()], ['tickLowerIndex', getI32Encoder()], ['tickUpperIndex', getI32Encoder()], ['liquidity', getU128Encoder()], ['feeGrowthInside0LastX64', getU128Encoder()], ['feeGrowthInside1LastX64', getU128Encoder()], ['tokenFeesOwed0', getU64Encoder()], ['tokenFeesOwed1', getU64Encoder()], ['rewardGrowthInside', getArrayEncoder(getU128Encoder(), { size: 3 })], ['padding', getArrayEncoder(getU64Encoder(), { size: 8 })]]), (value) => ({ ...value, discriminator: PROTOCOL_POSITION_STATE_DISCRIMINATOR }));
}

/** Gets the decoder for {@link ProtocolPositionState} account data. */
export function getProtocolPositionStateDecoder(): FixedSizeDecoder<ProtocolPositionState> {
    return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['bump', getU8Decoder()], ['poolId', getAddressDecoder()], ['tickLowerIndex', getI32Decoder()], ['tickUpperIndex', getI32Decoder()], ['liquidity', getU128Decoder()], ['feeGrowthInside0LastX64', getU128Decoder()], ['feeGrowthInside1LastX64', getU128Decoder()], ['tokenFeesOwed0', getU64Decoder()], ['tokenFeesOwed1', getU64Decoder()], ['rewardGrowthInside', getArrayDecoder(getU128Decoder(), { size: 3 })], ['padding', getArrayDecoder(getU64Decoder(), { size: 8 })]]);
}

/** Gets the codec for {@link ProtocolPositionState} account data. */
export function getProtocolPositionStateCodec(): FixedSizeCodec<ProtocolPositionStateArgs, ProtocolPositionState> {
    return combineCodec(getProtocolPositionStateEncoder(), getProtocolPositionStateDecoder());
}

export function decodeProtocolPositionState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<ProtocolPositionState, TAddress>;
export function decodeProtocolPositionState<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<ProtocolPositionState, TAddress>;
export function decodeProtocolPositionState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<ProtocolPositionState, TAddress> | MaybeAccount<ProtocolPositionState, TAddress> {
  return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getProtocolPositionStateDecoder());
}

export async function fetchProtocolPositionState<TAddress extends string = string>(
  rpc: Parameters<typeof fetchEncodedAccount>[0],
  address: Address<TAddress>,
  config?: FetchAccountConfig,
): Promise<Account<ProtocolPositionState, TAddress>> {
  const maybeAccount = await fetchMaybeProtocolPositionState(rpc, address, config);
  assertAccountExists(maybeAccount);
  return maybeAccount;
}

export async function fetchMaybeProtocolPositionState<TAddress extends string = string>(
  rpc: Parameters<typeof fetchEncodedAccount>[0],
  address: Address<TAddress>,
  config?: FetchAccountConfig,
): Promise<MaybeAccount<ProtocolPositionState, TAddress>> {
  const maybeAccount = await fetchEncodedAccount(rpc, address, config);
  return decodeProtocolPositionState(maybeAccount);
}

export async function fetchAllProtocolPositionState(
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
  addresses: Array<Address>,
  config?: FetchAccountsConfig,
): Promise<Account<ProtocolPositionState>[]> {
  const maybeAccounts = await fetchAllMaybeProtocolPositionState(rpc, addresses, config);
  assertAccountsExist(maybeAccounts);
  return maybeAccounts;
}

export async function fetchAllMaybeProtocolPositionState(
  rpc: Parameters<typeof fetchEncodedAccounts>[0],
  addresses: Array<Address>,
  config?: FetchAccountsConfig,
): Promise<MaybeAccount<ProtocolPositionState>[]> {
  const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
  return maybeAccounts.map((maybeAccount) => decodeProtocolPositionState(maybeAccount));
}

export function getProtocolPositionStateSize(): number {
  return 225;
}