"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LOCAL_TOKEN_DISCRIMINATOR = void 0;
exports.getLocalTokenDiscriminatorBytes = getLocalTokenDiscriminatorBytes;
exports.getLocalTokenEncoder = getLocalTokenEncoder;
exports.getLocalTokenDecoder = getLocalTokenDecoder;
exports.getLocalTokenCodec = getLocalTokenCodec;
exports.decodeLocalToken = decodeLocalToken;
exports.fetchLocalToken = fetchLocalToken;
exports.fetchMaybeLocalToken = fetchMaybeLocalToken;
exports.fetchAllLocalToken = fetchAllLocalToken;
exports.fetchAllMaybeLocalToken = fetchAllMaybeLocalToken;
exports.getLocalTokenSize = getLocalTokenSize;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
exports.LOCAL_TOKEN_DISCRIMINATOR = new Uint8Array([
    159, 131, 58, 170, 193, 84, 128, 182,
]);
function getLocalTokenDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.LOCAL_TOKEN_DISCRIMINATOR);
}
function getLocalTokenEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["custody", (0, kit_1.getAddressEncoder)()],
        ["mint", (0, kit_1.getAddressEncoder)()],
        ["burnLimitPerMessage", (0, kit_1.getU64Encoder)()],
        ["messagesSent", (0, kit_1.getU64Encoder)()],
        ["messagesReceived", (0, kit_1.getU64Encoder)()],
        ["amountSent", (0, kit_1.getU128Encoder)()],
        ["amountReceived", (0, kit_1.getU128Encoder)()],
        ["bump", (0, kit_1.getU8Encoder)()],
        ["custodyBump", (0, kit_1.getU8Encoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.LOCAL_TOKEN_DISCRIMINATOR })); });
}
function getLocalTokenDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["custody", (0, kit_1.getAddressDecoder)()],
        ["mint", (0, kit_1.getAddressDecoder)()],
        ["burnLimitPerMessage", (0, kit_1.getU64Decoder)()],
        ["messagesSent", (0, kit_1.getU64Decoder)()],
        ["messagesReceived", (0, kit_1.getU64Decoder)()],
        ["amountSent", (0, kit_1.getU128Decoder)()],
        ["amountReceived", (0, kit_1.getU128Decoder)()],
        ["bump", (0, kit_1.getU8Decoder)()],
        ["custodyBump", (0, kit_1.getU8Decoder)()],
    ]);
}
function getLocalTokenCodec() {
    return (0, kit_1.combineCodec)(getLocalTokenEncoder(), getLocalTokenDecoder());
}
function decodeLocalToken(encodedAccount) {
    return (0, kit_1.decodeAccount)(encodedAccount, getLocalTokenDecoder());
}
function fetchLocalToken(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, fetchMaybeLocalToken(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    (0, kit_1.assertAccountExists)(maybeAccount);
                    return [2, maybeAccount];
            }
        });
    });
}
function fetchMaybeLocalToken(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, decodeLocalToken(maybeAccount)];
            }
        });
    });
}
function fetchAllLocalToken(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, fetchAllMaybeLocalToken(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    (0, kit_1.assertAccountsExist)(maybeAccounts);
                    return [2, maybeAccounts];
            }
        });
    });
}
function fetchAllMaybeLocalToken(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 decodeLocalToken(maybeAccount); })];
            }
        });
    });
}
function getLocalTokenSize() {
    return 130;
}
//# sourceMappingURL=localToken.js.map