import { __awaiter, __generator } from "tslib";
import "@nomiclabs/hardhat-ethers";
import "@openzeppelin/hardhat-upgrades";
import "hardhat-deploy";
import hre from "hardhat";
import { getContractFactory } from "../utils/getContractFactory";
import { destinationChainId, TokenRolesEnum, zeroAddress } from "../constants";
export { zeroAddress };
/**
 * Deploys a SpokePool with associated tokens for testing.
 * This is a local implementation that uses our local getContractFactory
 * instead of the one from @across-protocol/contracts.
 */
export function deploySpokePool(ethers_1) {
    return __awaiter(this, arguments, void 0, function (ethers, spokePoolName) {
        var _a, deployerWallet, crossChainAdmin, hubPool, weth, erc20, unwhitelistedErc20, destErc20, spokePool, _b, _c, erc1271;
        if (spokePoolName === void 0) { spokePoolName = "MockSpokePool"; }
        return __generator(this, function (_d) {
            switch (_d.label) {
                case 0: return [4 /*yield*/, ethers.getSigners()];
                case 1:
                    _a = _d.sent(), deployerWallet = _a[0], crossChainAdmin = _a[1], hubPool = _a[2];
                    return [4 /*yield*/, getContractFactory("WETH9", deployerWallet)];
                case 2: return [4 /*yield*/, (_d.sent()).deploy()];
                case 3:
                    weth = _d.sent();
                    return [4 /*yield*/, getContractFactory("ExpandedERC20", deployerWallet)];
                case 4: return [4 /*yield*/, (_d.sent()).deploy("USD Coin", "USDC", 18)];
                case 5:
                    erc20 = _d.sent();
                    return [4 /*yield*/, erc20.addMember(TokenRolesEnum.MINTER, deployerWallet.address)];
                case 6:
                    _d.sent();
                    return [4 /*yield*/, getContractFactory("ExpandedERC20", deployerWallet)];
                case 7: return [4 /*yield*/, (_d.sent()).deploy("Unwhitelisted", "UNWHITELISTED", 18)];
                case 8:
                    unwhitelistedErc20 = _d.sent();
                    return [4 /*yield*/, unwhitelistedErc20.addMember(TokenRolesEnum.MINTER, deployerWallet.address)];
                case 9:
                    _d.sent();
                    return [4 /*yield*/, getContractFactory("ExpandedERC20WithBlacklist", deployerWallet)];
                case 10: return [4 /*yield*/, (_d.sent()).deploy("L2 USD Coin", "L2 USDC", 18)];
                case 11:
                    destErc20 = _d.sent();
                    return [4 /*yield*/, destErc20.addMember(TokenRolesEnum.MINTER, deployerWallet.address)];
                case 12:
                    _d.sent();
                    _c = (_b = hre.upgrades).deployProxy;
                    return [4 /*yield*/, getContractFactory(spokePoolName, deployerWallet)];
                case 13: return [4 /*yield*/, _c.apply(_b, [_d.sent(), [0, crossChainAdmin.address, hubPool.address],
                        { kind: "uups", unsafeAllow: ["delegatecall"], constructorArgs: [weth.address] }])];
                case 14:
                    spokePool = _d.sent();
                    return [4 /*yield*/, spokePool.setChainId(destinationChainId)];
                case 15:
                    _d.sent();
                    return [4 /*yield*/, getContractFactory("MockERC1271", deployerWallet)];
                case 16: return [4 /*yield*/, (_d.sent()).deploy(deployerWallet.address)];
                case 17:
                    erc1271 = _d.sent();
                    return [2 /*return*/, {
                            weth: weth,
                            erc20: erc20,
                            spokePool: spokePool,
                            unwhitelistedErc20: unwhitelistedErc20,
                            destErc20: destErc20,
                            erc1271: erc1271,
                        }];
            }
        });
    });
}
/**
 * Creates a spoke pool fixture using hardhat-deploy's createFixture.
 */
export var spokePoolFixture = hre.deployments.createFixture(function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
    var ethers = _b.ethers;
    return __generator(this, function (_c) {
        switch (_c.label) {
            case 0: return [4 /*yield*/, deploySpokePool(ethers)];
            case 1: return [2 /*return*/, _c.sent()];
        }
    });
}); });
//# sourceMappingURL=SpokePool.Fixture.js.map