"use strict";
/**
 * 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
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ROOT_BUNDLE_DISCRIMINATOR = void 0;
exports.getRootBundleDiscriminatorBytes = getRootBundleDiscriminatorBytes;
exports.getRootBundleEncoder = getRootBundleEncoder;
exports.getRootBundleDecoder = getRootBundleDecoder;
exports.getRootBundleCodec = getRootBundleCodec;
exports.decodeRootBundle = decodeRootBundle;
exports.fetchRootBundle = fetchRootBundle;
exports.fetchMaybeRootBundle = fetchMaybeRootBundle;
exports.fetchAllRootBundle = fetchAllRootBundle;
exports.fetchAllMaybeRootBundle = fetchAllMaybeRootBundle;
const web3_v2_js_1 = require("@solana/web3-v2.js");
exports.ROOT_BUNDLE_DISCRIMINATOR = new Uint8Array([
    66, 221, 214, 231, 25, 222, 184, 219,
]);
function getRootBundleDiscriminatorBytes() {
    return (0, web3_v2_js_1.fixEncoderSize)((0, web3_v2_js_1.getBytesEncoder)(), 8).encode(exports.ROOT_BUNDLE_DISCRIMINATOR);
}
function getRootBundleEncoder() {
    return (0, web3_v2_js_1.transformEncoder)((0, web3_v2_js_1.getStructEncoder)([
        ['discriminator', (0, web3_v2_js_1.fixEncoderSize)((0, web3_v2_js_1.getBytesEncoder)(), 8)],
        ['relayerRefundRoot', (0, web3_v2_js_1.fixEncoderSize)((0, web3_v2_js_1.getBytesEncoder)(), 32)],
        ['slowRelayRoot', (0, web3_v2_js_1.fixEncoderSize)((0, web3_v2_js_1.getBytesEncoder)(), 32)],
        [
            'claimedBitmap',
            (0, web3_v2_js_1.addEncoderSizePrefix)((0, web3_v2_js_1.getBytesEncoder)(), (0, web3_v2_js_1.getU32Encoder)()),
        ],
    ]), (value) => ({ ...value, discriminator: exports.ROOT_BUNDLE_DISCRIMINATOR }));
}
function getRootBundleDecoder() {
    return (0, web3_v2_js_1.getStructDecoder)([
        ['discriminator', (0, web3_v2_js_1.fixDecoderSize)((0, web3_v2_js_1.getBytesDecoder)(), 8)],
        ['relayerRefundRoot', (0, web3_v2_js_1.fixDecoderSize)((0, web3_v2_js_1.getBytesDecoder)(), 32)],
        ['slowRelayRoot', (0, web3_v2_js_1.fixDecoderSize)((0, web3_v2_js_1.getBytesDecoder)(), 32)],
        ['claimedBitmap', (0, web3_v2_js_1.addDecoderSizePrefix)((0, web3_v2_js_1.getBytesDecoder)(), (0, web3_v2_js_1.getU32Decoder)())],
    ]);
}
function getRootBundleCodec() {
    return (0, web3_v2_js_1.combineCodec)(getRootBundleEncoder(), getRootBundleDecoder());
}
function decodeRootBundle(encodedAccount) {
    return (0, web3_v2_js_1.decodeAccount)(encodedAccount, getRootBundleDecoder());
}
async function fetchRootBundle(rpc, address, config) {
    const maybeAccount = await fetchMaybeRootBundle(rpc, address, config);
    (0, web3_v2_js_1.assertAccountExists)(maybeAccount);
    return maybeAccount;
}
async function fetchMaybeRootBundle(rpc, address, config) {
    const maybeAccount = await (0, web3_v2_js_1.fetchEncodedAccount)(rpc, address, config);
    return decodeRootBundle(maybeAccount);
}
async function fetchAllRootBundle(rpc, addresses, config) {
    const maybeAccounts = await fetchAllMaybeRootBundle(rpc, addresses, config);
    (0, web3_v2_js_1.assertAccountsExist)(maybeAccounts);
    return maybeAccounts;
}
async function fetchAllMaybeRootBundle(rpc, addresses, config) {
    const maybeAccounts = await (0, web3_v2_js_1.fetchEncodedAccounts)(rpc, addresses, config);
    return maybeAccounts.map((maybeAccount) => decodeRootBundle(maybeAccount));
}
