"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.STATE_DISCRIMINATOR = void 0;
exports.getStateDiscriminatorBytes = getStateDiscriminatorBytes;
exports.getStateEncoder = getStateEncoder;
exports.getStateDecoder = getStateDecoder;
exports.getStateCodec = getStateCodec;
exports.decodeState = decodeState;
exports.fetchState = fetchState;
exports.fetchMaybeState = fetchMaybeState;
exports.fetchAllState = fetchAllState;
exports.fetchAllMaybeState = fetchAllMaybeState;
exports.getStateSize = getStateSize;
const web3_v2_js_1 = require("@solana/web3-v2.js");
exports.STATE_DISCRIMINATOR = new Uint8Array([
    216, 146, 107, 94, 104, 75, 182, 177,
]);
function getStateDiscriminatorBytes() {
    return (0, web3_v2_js_1.fixEncoderSize)((0, web3_v2_js_1.getBytesEncoder)(), 8).encode(exports.STATE_DISCRIMINATOR);
}
function getStateEncoder() {
    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)],
        ['pausedDeposits', (0, web3_v2_js_1.getBooleanEncoder)()],
        ['pausedFills', (0, web3_v2_js_1.getBooleanEncoder)()],
        ['owner', (0, web3_v2_js_1.getAddressEncoder)()],
        ['seed', (0, web3_v2_js_1.getU64Encoder)()],
        ['numberOfDeposits', (0, web3_v2_js_1.getU32Encoder)()],
        ['chainId', (0, web3_v2_js_1.getU64Encoder)()],
        ['currentTime', (0, web3_v2_js_1.getU32Encoder)()],
        ['remoteDomain', (0, web3_v2_js_1.getU32Encoder)()],
        ['crossDomainAdmin', (0, web3_v2_js_1.getAddressEncoder)()],
        ['rootBundleId', (0, web3_v2_js_1.getU32Encoder)()],
        ['depositQuoteTimeBuffer', (0, web3_v2_js_1.getU32Encoder)()],
        ['fillDeadlineBuffer', (0, web3_v2_js_1.getU32Encoder)()],
    ]), (value) => ({ ...value, discriminator: exports.STATE_DISCRIMINATOR }));
}
function getStateDecoder() {
    return (0, web3_v2_js_1.getStructDecoder)([
        ['discriminator', (0, web3_v2_js_1.fixDecoderSize)((0, web3_v2_js_1.getBytesDecoder)(), 8)],
        ['pausedDeposits', (0, web3_v2_js_1.getBooleanDecoder)()],
        ['pausedFills', (0, web3_v2_js_1.getBooleanDecoder)()],
        ['owner', (0, web3_v2_js_1.getAddressDecoder)()],
        ['seed', (0, web3_v2_js_1.getU64Decoder)()],
        ['numberOfDeposits', (0, web3_v2_js_1.getU32Decoder)()],
        ['chainId', (0, web3_v2_js_1.getU64Decoder)()],
        ['currentTime', (0, web3_v2_js_1.getU32Decoder)()],
        ['remoteDomain', (0, web3_v2_js_1.getU32Decoder)()],
        ['crossDomainAdmin', (0, web3_v2_js_1.getAddressDecoder)()],
        ['rootBundleId', (0, web3_v2_js_1.getU32Decoder)()],
        ['depositQuoteTimeBuffer', (0, web3_v2_js_1.getU32Decoder)()],
        ['fillDeadlineBuffer', (0, web3_v2_js_1.getU32Decoder)()],
    ]);
}
function getStateCodec() {
    return (0, web3_v2_js_1.combineCodec)(getStateEncoder(), getStateDecoder());
}
function decodeState(encodedAccount) {
    return (0, web3_v2_js_1.decodeAccount)(encodedAccount, getStateDecoder());
}
async function fetchState(rpc, address, config) {
    const maybeAccount = await fetchMaybeState(rpc, address, config);
    (0, web3_v2_js_1.assertAccountExists)(maybeAccount);
    return maybeAccount;
}
async function fetchMaybeState(rpc, address, config) {
    const maybeAccount = await (0, web3_v2_js_1.fetchEncodedAccount)(rpc, address, config);
    return decodeState(maybeAccount);
}
async function fetchAllState(rpc, addresses, config) {
    const maybeAccounts = await fetchAllMaybeState(rpc, addresses, config);
    (0, web3_v2_js_1.assertAccountsExist)(maybeAccounts);
    return maybeAccounts;
}
async function fetchAllMaybeState(rpc, addresses, config) {
    const maybeAccounts = await (0, web3_v2_js_1.fetchEncodedAccounts)(rpc, addresses, config);
    return maybeAccounts.map((maybeAccount) => decodeState(maybeAccount));
}
function getStateSize() {
    return 114;
}
