"use strict";
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;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
exports.STATE_DISCRIMINATOR = new Uint8Array([
    216, 146, 107, 94, 104, 75, 182, 177,
]);
function getStateDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.STATE_DISCRIMINATOR);
}
function getStateEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["pausedDeposits", (0, kit_1.getBooleanEncoder)()],
        ["pausedFills", (0, kit_1.getBooleanEncoder)()],
        ["owner", (0, kit_1.getAddressEncoder)()],
        ["seed", (0, kit_1.getU64Encoder)()],
        ["numberOfDeposits", (0, kit_1.getU32Encoder)()],
        ["chainId", (0, kit_1.getU64Encoder)()],
        ["currentTime", (0, kit_1.getU32Encoder)()],
        ["remoteDomain", (0, kit_1.getU32Encoder)()],
        ["crossDomainAdmin", (0, kit_1.getAddressEncoder)()],
        ["rootBundleId", (0, kit_1.getU32Encoder)()],
        ["depositQuoteTimeBuffer", (0, kit_1.getU32Encoder)()],
        ["fillDeadlineBuffer", (0, kit_1.getU32Encoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.STATE_DISCRIMINATOR })); });
}
function getStateDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["pausedDeposits", (0, kit_1.getBooleanDecoder)()],
        ["pausedFills", (0, kit_1.getBooleanDecoder)()],
        ["owner", (0, kit_1.getAddressDecoder)()],
        ["seed", (0, kit_1.getU64Decoder)()],
        ["numberOfDeposits", (0, kit_1.getU32Decoder)()],
        ["chainId", (0, kit_1.getU64Decoder)()],
        ["currentTime", (0, kit_1.getU32Decoder)()],
        ["remoteDomain", (0, kit_1.getU32Decoder)()],
        ["crossDomainAdmin", (0, kit_1.getAddressDecoder)()],
        ["rootBundleId", (0, kit_1.getU32Decoder)()],
        ["depositQuoteTimeBuffer", (0, kit_1.getU32Decoder)()],
        ["fillDeadlineBuffer", (0, kit_1.getU32Decoder)()],
    ]);
}
function getStateCodec() {
    return (0, kit_1.combineCodec)(getStateEncoder(), getStateDecoder());
}
function decodeState(encodedAccount) {
    return (0, kit_1.decodeAccount)(encodedAccount, getStateDecoder());
}
function fetchState(rpc, address, config) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var maybeAccount;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4, fetchMaybeState(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    (0, kit_1.assertAccountExists)(maybeAccount);
                    return [2, maybeAccount];
            }
        });
    });
}
function fetchMaybeState(rpc, address, config) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var maybeAccount;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4, (0, kit_1.fetchEncodedAccount)(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    return [2, decodeState(maybeAccount)];
            }
        });
    });
}
function fetchAllState(rpc, addresses, config) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var maybeAccounts;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4, fetchAllMaybeState(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    (0, kit_1.assertAccountsExist)(maybeAccounts);
                    return [2, maybeAccounts];
            }
        });
    });
}
function fetchAllMaybeState(rpc, addresses, config) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var maybeAccounts;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4, (0, kit_1.fetchEncodedAccounts)(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    return [2, maybeAccounts.map(function (maybeAccount) { return decodeState(maybeAccount); })];
            }
        });
    });
}
function getStateSize() {
    return 114;
}
//# sourceMappingURL=state.js.map