"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.USED_NONCE_DISCRIMINATOR = void 0;
exports.getUsedNonceDiscriminatorBytes = getUsedNonceDiscriminatorBytes;
exports.getUsedNonceEncoder = getUsedNonceEncoder;
exports.getUsedNonceDecoder = getUsedNonceDecoder;
exports.getUsedNonceCodec = getUsedNonceCodec;
exports.decodeUsedNonce = decodeUsedNonce;
exports.fetchUsedNonce = fetchUsedNonce;
exports.fetchMaybeUsedNonce = fetchMaybeUsedNonce;
exports.fetchAllUsedNonce = fetchAllUsedNonce;
exports.fetchAllMaybeUsedNonce = fetchAllMaybeUsedNonce;
exports.getUsedNonceSize = getUsedNonceSize;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
exports.USED_NONCE_DISCRIMINATOR = new Uint8Array([
    212, 222, 157, 252, 130, 71, 179, 238,
]);
function getUsedNonceDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.USED_NONCE_DISCRIMINATOR);
}
function getUsedNonceEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["quoteDeadline", (0, kit_1.getU64Encoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.USED_NONCE_DISCRIMINATOR })); });
}
function getUsedNonceDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["quoteDeadline", (0, kit_1.getU64Decoder)()],
    ]);
}
function getUsedNonceCodec() {
    return (0, kit_1.combineCodec)(getUsedNonceEncoder(), getUsedNonceDecoder());
}
function decodeUsedNonce(encodedAccount) {
    return (0, kit_1.decodeAccount)(encodedAccount, getUsedNonceDecoder());
}
function fetchUsedNonce(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, fetchMaybeUsedNonce(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    (0, kit_1.assertAccountExists)(maybeAccount);
                    return [2, maybeAccount];
            }
        });
    });
}
function fetchMaybeUsedNonce(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, decodeUsedNonce(maybeAccount)];
            }
        });
    });
}
function fetchAllUsedNonce(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, fetchAllMaybeUsedNonce(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    (0, kit_1.assertAccountsExist)(maybeAccounts);
                    return [2, maybeAccounts];
            }
        });
    });
}
function fetchAllMaybeUsedNonce(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 decodeUsedNonce(maybeAccount); })];
            }
        });
    });
}
function getUsedNonceSize() {
    return 16;
}
//# sourceMappingURL=usedNonce.js.map