"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConnectedProgram = getConnectedProgram;
exports.getSpokePoolProgram = getSpokePoolProgram;
exports.getMessageTransmitterProgram = getMessageTransmitterProgram;
exports.getTokenMessengerMinterProgram = getTokenMessengerMinterProgram;
exports.getMulticallHandlerProgram = getMulticallHandlerProgram;
exports.getMessageTransmitterV2Program = getMessageTransmitterV2Program;
exports.getTokenMessengerMinterV2Program = getTokenMessengerMinterV2Program;
exports.getSponsoredCctpSrcPeripheryProgram = getSponsoredCctpSrcPeripheryProgram;
var anchor_1 = require("@coral-xyz/anchor");
var contracts_1 = require("@across-protocol/contracts");
var assets_1 = require("../assets");
var helpers_1 = require("./helpers");
function getConnectedProgram(idl, provider, programId) {
    idl.address = programId;
    return new anchor_1.Program(idl, provider);
}
function resolveProgramId(programName, provider, options) {
    var _a = options !== null && options !== void 0 ? options : {}, network = _a.network, programId = _a.programId;
    if (programId) {
        return programId;
    }
    var resolvedNetwork = network !== null && network !== void 0 ? network : ((0, helpers_1.isSolanaDevnet)(provider) ? "devnet" : "mainnet");
    var deployedAddress = (0, contracts_1.getDeployedAddress)(programName, (0, helpers_1.getSolanaChainId)(resolvedNetwork).toString());
    if (!deployedAddress) {
        throw new Error("".concat(programName, " Program ID not found for ").concat(resolvedNetwork));
    }
    return deployedAddress;
}
function getSpokePoolProgram(provider, options) {
    var id = resolveProgramId("SvmSpoke", provider, options);
    return getConnectedProgram(assets_1.SvmSpokeIdl, provider, id);
}
function getMessageTransmitterProgram(provider, options) {
    var id = resolveProgramId("MessageTransmitter", provider, options);
    return getConnectedProgram(assets_1.MessageTransmitterIdl, provider, id);
}
function getTokenMessengerMinterProgram(provider, options) {
    var id = resolveProgramId("TokenMessengerMinter", provider, options);
    return getConnectedProgram(assets_1.TokenMessengerMinterIdl, provider, id);
}
function getMulticallHandlerProgram(provider, options) {
    var id = resolveProgramId("MulticallHandler", provider, options);
    return getConnectedProgram(assets_1.MulticallHandlerIdl, provider, id);
}
function getMessageTransmitterV2Program(provider, options) {
    var id = resolveProgramId("MessageTransmitterV2", provider, options);
    return getConnectedProgram(assets_1.MessageTransmitterV2Idl, provider, id);
}
function getTokenMessengerMinterV2Program(provider, options) {
    var id = resolveProgramId("TokenMessengerMinterV2", provider, options);
    return getConnectedProgram(assets_1.TokenMessengerMinterV2Idl, provider, id);
}
function getSponsoredCctpSrcPeripheryProgram(provider, options) {
    var id = resolveProgramId("SponsoredCctpSrcPeriphery", provider, options);
    return getConnectedProgram(assets_1.SponsoredCctpSrcPeripheryIdl, provider, id);
}
//# sourceMappingURL=programConnectors.js.map