"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TOKEN_PAIR_DISCRIMINATOR = void 0;
exports.getTokenPairDiscriminatorBytes = getTokenPairDiscriminatorBytes;
exports.getTokenPairEncoder = getTokenPairEncoder;
exports.getTokenPairDecoder = getTokenPairDecoder;
exports.getTokenPairCodec = getTokenPairCodec;
exports.decodeTokenPair = decodeTokenPair;
exports.fetchTokenPair = fetchTokenPair;
exports.fetchMaybeTokenPair = fetchMaybeTokenPair;
exports.fetchAllTokenPair = fetchAllTokenPair;
exports.fetchAllMaybeTokenPair = fetchAllMaybeTokenPair;
exports.getTokenPairSize = getTokenPairSize;
var tslib_1 = require("tslib");
var kit_1 = require("@solana/kit");
exports.TOKEN_PAIR_DISCRIMINATOR = new Uint8Array([
    17, 214, 45, 176, 229, 149, 197, 71,
]);
function getTokenPairDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.TOKEN_PAIR_DISCRIMINATOR);
}
function getTokenPairEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ["remoteDomain", (0, kit_1.getU32Encoder)()],
        ["remoteToken", (0, kit_1.getAddressEncoder)()],
        ["localToken", (0, kit_1.getAddressEncoder)()],
        ["bump", (0, kit_1.getU8Encoder)()],
    ]), function (value) { return (tslib_1.__assign(tslib_1.__assign({}, value), { discriminator: exports.TOKEN_PAIR_DISCRIMINATOR })); });
}
function getTokenPairDecoder() {
    return (0, kit_1.getStructDecoder)([
        ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ["remoteDomain", (0, kit_1.getU32Decoder)()],
        ["remoteToken", (0, kit_1.getAddressDecoder)()],
        ["localToken", (0, kit_1.getAddressDecoder)()],
        ["bump", (0, kit_1.getU8Decoder)()],
    ]);
}
function getTokenPairCodec() {
    return (0, kit_1.combineCodec)(getTokenPairEncoder(), getTokenPairDecoder());
}
function decodeTokenPair(encodedAccount) {
    return (0, kit_1.decodeAccount)(encodedAccount, getTokenPairDecoder());
}
function fetchTokenPair(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, fetchMaybeTokenPair(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    (0, kit_1.assertAccountExists)(maybeAccount);
                    return [2, maybeAccount];
            }
        });
    });
}
function fetchMaybeTokenPair(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, decodeTokenPair(maybeAccount)];
            }
        });
    });
}
function fetchAllTokenPair(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, fetchAllMaybeTokenPair(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    (0, kit_1.assertAccountsExist)(maybeAccounts);
                    return [2, maybeAccounts];
            }
        });
    });
}
function fetchAllMaybeTokenPair(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 decodeTokenPair(maybeAccount); })];
            }
        });
    });
}
function getTokenPairSize() {
    return 77;
}
//# sourceMappingURL=tokenPair.js.map