"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.REMOTE_TOKEN_MESSENGER_DISCRIMINATOR = void 0;
exports.getRemoteTokenMessengerDiscriminatorBytes = getRemoteTokenMessengerDiscriminatorBytes;
exports.getRemoteTokenMessengerEncoder = getRemoteTokenMessengerEncoder;
exports.getRemoteTokenMessengerDecoder = getRemoteTokenMessengerDecoder;
exports.getRemoteTokenMessengerCodec = getRemoteTokenMessengerCodec;
exports.decodeRemoteTokenMessenger = decodeRemoteTokenMessenger;
exports.fetchRemoteTokenMessenger = fetchRemoteTokenMessenger;
exports.fetchMaybeRemoteTokenMessenger = fetchMaybeRemoteTokenMessenger;
exports.fetchAllRemoteTokenMessenger = fetchAllRemoteTokenMessenger;
exports.fetchAllMaybeRemoteTokenMessenger = fetchAllMaybeRemoteTokenMessenger;
exports.getRemoteTokenMessengerSize = getRemoteTokenMessengerSize;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
exports.REMOTE_TOKEN_MESSENGER_DISCRIMINATOR = new Uint8Array([
    105, 115, 174, 34, 95, 233, 138, 252,
]);
function getRemoteTokenMessengerDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.REMOTE_TOKEN_MESSENGER_DISCRIMINATOR);
}
function getRemoteTokenMessengerEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["domain", (0, kit_1.getU32Encoder)()],
        ["tokenMessenger", (0, kit_1.getAddressEncoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.REMOTE_TOKEN_MESSENGER_DISCRIMINATOR })); });
}
function getRemoteTokenMessengerDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["domain", (0, kit_1.getU32Decoder)()],
        ["tokenMessenger", (0, kit_1.getAddressDecoder)()],
    ]);
}
function getRemoteTokenMessengerCodec() {
    return (0, kit_1.combineCodec)(getRemoteTokenMessengerEncoder(), getRemoteTokenMessengerDecoder());
}
function decodeRemoteTokenMessenger(encodedAccount) {
    return (0, kit_1.decodeAccount)(encodedAccount, getRemoteTokenMessengerDecoder());
}
function fetchRemoteTokenMessenger(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, fetchMaybeRemoteTokenMessenger(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    (0, kit_1.assertAccountExists)(maybeAccount);
                    return [2, maybeAccount];
            }
        });
    });
}
function fetchMaybeRemoteTokenMessenger(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, decodeRemoteTokenMessenger(maybeAccount)];
            }
        });
    });
}
function fetchAllRemoteTokenMessenger(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, fetchAllMaybeRemoteTokenMessenger(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    (0, kit_1.assertAccountsExist)(maybeAccounts);
                    return [2, maybeAccounts];
            }
        });
    });
}
function fetchAllMaybeRemoteTokenMessenger(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 decodeRemoteTokenMessenger(maybeAccount);
                        })];
            }
        });
    });
}
function getRemoteTokenMessengerSize() {
    return 44;
}
//# sourceMappingURL=remoteTokenMessenger.js.map