contract TinlakeRoot is Auth {
    BorrowerDeployerLike public borrowerDeployer;
    LenderDeployerLike public  lenderDeployer;

    bool public             deployed;
    address public          deployUsr;

    constructor (address deployUsr_) public {
        deployUsr = deployUsr_;
    }

    // --- Prepare ---
    // Sets the two deployer dependencies. This needs to be called by the deployUsr
    function prepare(address lender_, address borrower_, address ward_) public {
        require(deployUsr == msg.sender);
        borrowerDeployer = BorrowerDeployerLike(borrower_);
        lenderDeployer = LenderDeployerLike(lender_);
        wards[ward_] = 1;
        deployUsr = address(0); // disallow the deploy user to call this more than once.
    }

    // --- Deploy ---
    // After going through the deploy process on the lender and borrower method, this method is called to connect
    // lender and borrower contracts.
    function deploy() public {
        require(address(borrowerDeployer) != address(0) && address(lenderDeployer) != address(0) && deployed == false);
        deployed = true;

        address reserve_ = lenderDeployer.reserve();
        address shelf_ = borrowerDeployer.shelf();

        // Borrower depends
        DependLike_3(borrowerDeployer.collector()).depend("distributor", reserve_);
        DependLike_3(borrowerDeployer.shelf()).depend("lender", reserve_);
        DependLike_3(borrowerDeployer.shelf()).depend("distributor", reserve_);

        //AuthLike(reserve).rely(shelf_);

        //  Lender depends
        address navFeed = borrowerDeployer.feed();

        DependLike_3(reserve_).depend("shelf", shelf_);
        DependLike_3(lenderDeployer.assessor()).depend("navFeed", navFeed);

         // permissions
        address poolAdmin = 0x71d9f8CFdcCEF71B59DD81AB387e523E2834F2b8;                                             
        address oracle = 0x1c3C2E90B7D7Ac525f933597Eb228F8c74A28Cd2;

        address juniorMemberlistAdmin1 = 0x71d9f8CFdcCEF71B59DD81AB387e523E2834F2b8;
        address juniorMemberlistAdmin2 = 0x97b2d32FE673af5bb322409afb6253DFD02C0567;

        address seniorMemberlistAdmin1 = 0x71d9f8CFdcCEF71B59DD81AB387e523E2834F2b8;
        address seniorMemberlistAdmin2 = 0x97b2d32FE673af5bb322409afb6253DFD02C0567;
        address seniorMemberlistAdmin3 = 0xCE30bc6d0c9e489Ab06EC6E7F703E7DB69c5fa01;
        address seniorMemberlistAdmin4 = 0xfEADaD6b75e6C899132587b7Cb3FEd60c8554821;

        AuthLike_3(lenderDeployer.assessorAdmin()).rely(poolAdmin);
        AuthLike_3(lenderDeployer.juniorMemberlist()).rely(juniorMemberlistAdmin1);
        AuthLike_3(lenderDeployer.juniorMemberlist()).rely(juniorMemberlistAdmin2);
        AuthLike_3(lenderDeployer.seniorMemberlist()).rely(seniorMemberlistAdmin1);
        AuthLike_3(lenderDeployer.seniorMemberlist()).rely(seniorMemberlistAdmin2);
        AuthLike_3(lenderDeployer.seniorMemberlist()).rely(seniorMemberlistAdmin3);
        AuthLike_3(lenderDeployer.seniorMemberlist()).rely(seniorMemberlistAdmin4);
        AuthLike_3(navFeed).rely(oracle);
    }

    // --- Governance Functions ---
    // `relyContract` & `denyContract` can be called by any ward on the TinlakeRoot
    // contract to make an arbitrary address a ward on any contract the TinlakeRoot
    // is a ward on.
    function relyContract(address target, address usr) public auth {
        AuthLike_3(target).rely(usr);
    }

    function denyContract(address target, address usr) public auth {
        AuthLike_3(target).deny(usr);
    }

}
function relyContract(address target, address usr) public auth {
    AuthLike_3(target).rely(usr);
}

// --- Governance Functions ---
// `relyContract` & `denyContract` can be called by any ward on the TinlakeRoot
// contract to make an arbitrary address a ward on any contract the TinlakeRoot
// is a ward on.