contract GoaldIndirectDeployer {
    address constant PROXY_ADDRESS = 0x1c7e0b9a33b83c7bBCF068958887bE4292637F3c;

    address[] deployedGoalds;

    event GoaldDeployed(address goaldAddress);

    /**
     * See the constructor of the Goald contract for details on the parameters. There is no concern for reentrancy since this is the
     * only function, and multiple calls will probably hit the block gas limit very quickly.
     */
    function deploy(
        address collateralToken,
        address paymentToken,
        uint96  fee,
        uint8   feeIntervalDays,
        uint16  finalizationIntervals
    ) external returns (address) {
        // Make sure that we are allowed to create new Goald.
        IGoaldProxy latestProxy = IGoaldProxy(IGoaldProxy(PROXY_ADDRESS).getProxyAddress());
        require(latestProxy.getProxyAddress() == address(latestProxy), "Proxy address mismatch");
        require(latestProxy.getLatestDeployerAddress() == address(this), "Not latest deployer");

        // Create the goald.
        GoaldIndirect goald = new GoaldIndirect(address(latestProxy), msg.sender, collateralToken, paymentToken, fee, feeIntervalDays, finalizationIntervals);
        address goaldAddress = address(goald);
        deployedGoalds.push(goaldAddress);

        // Tell the proxy we created a goald.
        latestProxy.notifyGoaldCreated(msg.sender);

        // Hello world!
        emit GoaldDeployed(goaldAddress);

        return goaldAddress;
    }
}
function deploy(
    address collateralToken,
    address paymentToken,
    uint96  fee,
    uint8   feeIntervalDays,
    uint16  finalizationIntervals
) external returns (address) {
    // Make sure that we are allowed to create new Goald.
    IGoaldProxy latestProxy = IGoaldProxy(IGoaldProxy(PROXY_ADDRESS).getProxyAddress());
    require(latestProxy.getProxyAddress() == address(latestProxy), "Proxy address mismatch");
    require(latestProxy.getLatestDeployerAddress() == address(this), "Not latest deployer");

    // Create the goald.
    GoaldIndirect goald = new GoaldIndirect(address(latestProxy), msg.sender, collateralToken, paymentToken, fee, feeIntervalDays, finalizationIntervals);
    address goaldAddress = address(goald);
    deployedGoalds.push(goaldAddress);

    // Tell the proxy we created a goald.
    latestProxy.notifyGoaldCreated(msg.sender);

    // Hello world!
    emit GoaldDeployed(goaldAddress);

    return goaldAddress;
}

/**
 * See the constructor of the Goald contract for details on the parameters. There is no concern for reentrancy since this is the
 * only function, and multiple calls will probably hit the block gas limit very quickly.
 */