"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const deploySystem_1 = require("../../utils/deploy/deploySystem");
const deployThirdParty_1 = require("../../utils/deploy/deployThirdParty");
const Contracts_1 = require("../../Contracts");
const getContract_1 = require("../../utils/solidity/getContract");
exports.deployAndGetSystem = (environment) => __awaiter(this, void 0, void 0, function* () {
    const thirdParty = yield deployThirdParty_1.deployThirdParty(environment);
    const envWithDeployment = yield deploySystem_1.deploySystem(environment, thirdParty, deploySystem_1.deployAllContractsConfig);
    const addresses = envWithDeployment.deployment;
    const contracts = {
        dgx: getContract_1.getContract(environment, Contracts_1.Contracts.StandardToken, addresses.thirdPartyContracts.tokens.find(t => t.symbol === 'DGX')
            .address),
        engine: getContract_1.getContract(environment, Contracts_1.Contracts.Engine, addresses.melonContracts.engine),
        ethfinex: getContract_1.getContract(environment, Contracts_1.Contracts.ZeroExExchange, addresses.exchangeConfigs['Ethfinex'].exchange),
        ethfinexAdapter: getContract_1.getContract(environment, Contracts_1.Contracts.EthfinexAdapter, addresses.exchangeConfigs['Ethfinex'].adapter),
        eur: getContract_1.getContract(environment, Contracts_1.Contracts.StandardToken, addresses.thirdPartyContracts.tokens.find(t => t.symbol === 'EUR')
            .address),
        kyberAdapter: getContract_1.getContract(environment, Contracts_1.Contracts.KyberAdapter, addresses.exchangeConfigs['KyberNetwork'].adapter),
        kyberNetwork: getContract_1.getContract(environment, Contracts_1.Contracts.KyberNetwork, addresses.exchangeConfigs['KyberNetwork'].exchange),
        matchingMarket: getContract_1.getContract(environment, Contracts_1.Contracts.MatchingMarket, addresses.exchangeConfigs['MatchingMarket'].exchange),
        matchingMarketAdapter: getContract_1.getContract(environment, Contracts_1.Contracts.MatchingMarketAdapter, addresses.exchangeConfigs['MatchingMarket'].adapter),
        mln: getContract_1.getContract(environment, Contracts_1.Contracts.StandardToken, addresses.thirdPartyContracts.tokens.find(t => t.symbol === 'MLN')
            .address),
        priceSource: getContract_1.getContract(environment, Contracts_1.Contracts.TestingPriceFeed, addresses.melonContracts.priceSource),
        registry: getContract_1.getContract(environment, Contracts_1.Contracts.Registry, addresses.melonContracts.registry),
        version: getContract_1.getContract(environment, Contracts_1.Contracts.Version, addresses.melonContracts.version),
        weth: getContract_1.getContract(environment, Contracts_1.Contracts.StandardToken, addresses.thirdPartyContracts.tokens.find(t => t.symbol === 'WETH')
            .address),
        zeroExAdapter: getContract_1.getContract(environment, Contracts_1.Contracts.ZeroExAdapter, addresses.exchangeConfigs['ZeroEx'].adapter),
        zeroExExchange: getContract_1.getContract(environment, Contracts_1.Contracts.ZeroExExchange, addresses.exchangeConfigs['ZeroEx'].exchange),
        zrx: getContract_1.getContract(environment, Contracts_1.Contracts.StandardToken, addresses.thirdPartyContracts.tokens.find(t => t.symbol === 'ZRX')
            .address),
    };
    return { addresses, contracts };
});
