"use strict";
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadDeployments = void 0;
const _1 = require(".");
const _deployments_devnet_json_1 = __importDefault(require("../.deployments.devnet.json"));
function toDeployments(json) {
    const contracts = {
        Governance: Object.assign(Object.assign({}, json.contracts.Governance), { contractInstance: _1.Governance.at(json.contracts.Governance.contractInstance.address) }),
        LocalTokenPool: Object.assign(Object.assign({}, json.contracts.LocalTokenPool), { contractInstance: _1.LocalTokenPool.at(json.contracts.LocalTokenPool.contractInstance.address) }),
        RemoteTokenPool: Object.assign(Object.assign({}, json.contracts.RemoteTokenPool), { contractInstance: _1.RemoteTokenPool.at(json.contracts.RemoteTokenPool.contractInstance.address) }),
        TokenBridgeForChain: Object.assign(Object.assign({}, json.contracts.TokenBridgeForChain), { contractInstance: _1.TokenBridgeForChain.at(json.contracts.TokenBridgeForChain.contractInstance.address) }),
        AttestTokenHandler: Object.assign(Object.assign({}, json.contracts.AttestTokenHandler), { contractInstance: _1.AttestTokenHandler.at(json.contracts.AttestTokenHandler.contractInstance.address) }),
        UnexecutedSequence: Object.assign(Object.assign({}, json.contracts.UnexecutedSequence), { contractInstance: _1.UnexecutedSequence.at(json.contracts.UnexecutedSequence.contractInstance.address) }),
        TokenBridgeFactory: Object.assign(Object.assign({}, json.contracts.TokenBridgeFactory), { contractInstance: _1.TokenBridgeFactory.at(json.contracts.TokenBridgeFactory.contractInstance.address) }),
        TokenBridge: Object.assign(Object.assign({}, json.contracts.TokenBridge), { contractInstance: _1.TokenBridge.at(json.contracts.TokenBridge.contractInstance.address) }),
        TestToken: Object.assign(Object.assign({}, json.contracts.TestToken), { contractInstance: _1.TestToken.at(json.contracts.TestToken.contractInstance.address) }),
    };
    return Object.assign(Object.assign({}, json), { contracts: contracts });
}
function loadDeployments(networkId, deployerAddress) {
    const deployments = networkId === "devnet" ? _deployments_devnet_json_1.default : undefined;
    if (deployments === undefined) {
        throw Error("The contract has not been deployed to the " + networkId);
    }
    const allDeployments = Array.isArray(deployments)
        ? deployments
        : [deployments];
    if (deployerAddress === undefined) {
        if (allDeployments.length > 1) {
            throw Error("The contract has been deployed multiple times on " +
                networkId +
                ", please specify the deployer address");
        }
        else {
            return toDeployments(allDeployments[0]);
        }
    }
    const result = allDeployments.find((d) => d.deployerAddress === deployerAddress);
    if (result === undefined) {
        throw Error("The contract deployment result does not exist");
    }
    return toDeployments(result);
}
exports.loadDeployments = loadDeployments;
