async function deployBorrowPools(deployer, network, accounts) {
    console.log(`deployBorrowPools deployering...`)
    let vaults = [BirrCastle, Sunnylands, ChateauLafitte];
    let K_CALCULATORS = [K_CALCULATOR_HUSD, K_CALCULATOR_HBTC, K_CALCULATOR_HETH];
    let itokenAddress = [itokensAddress.rUSD, itokensAddress.rBTC, itokensAddress.rETH];
    let tokenAddress = [tokensAddress.HUSD, tokensAddress.HBTC, tokensAddress.HETH];
    let ifaMasterInstance = await IFAMaster.at(publicContractAddress.IFAMaster);
    let ifaBankInstance = await IFABank.at(publicContractAddress.IFABank);
    let ifaPoolInstance = await IFAPool.at(publicContractAddress.IFAPool);
    let createIFAInstance = await CreateIFA.at(publicContractAddress.CreateIFA);
    let itokenContract = [
        new web3.eth.Contract(iTokenDelegator.abi, itokensAddress.rUSD),
        new web3.eth.Contract(iTokenDelegator.abi, itokensAddress.rBTC),
        new web3.eth.Contract(iTokenDelegator.abi, itokensAddress.rETH)
    ]

    for (let i = 0; i < vaults.length; i++) {
        // Whether to deploy the current pool , Do not deploy when POOL_ENABLE_STATUS is false
        if (!POOL_ENABLE_STATUS[i]) {
            continue;
        }
        let poolId = i;
        let K_CALCULATOR = K_CALCULATORS[i];
        let kVault = i
        let vault = vaults[kVault];
        let now = Math.floor((new Date()).getTime() / 1000 - 3600);
        let vaultInstance = await vault.new(ifaMasterInstance.address, publicContractAddress.CreateIFA)
            .then((result) => { console.log(`${poolVaultName[i]}:`, result.address); return result; });
        let name = poolVaultName[i];
        poolVaultContractAddress[poolVaultName[i]] = vaultInstance.address;
        // set rTokens
        switch (i) {
            case 0:
                await ifaMasterInstance.setiUSD(itokensAddress.rUSD);
                await ifaMasterInstance.setiToken(K_MADE_rUSD, itokensAddress.rUSD);
                break;
            case 1:
                await ifaMasterInstance.setiBTC(itokensAddress.rBTC);
                await ifaMasterInstance.setiToken(K_MADE_rBTC, itokensAddress.rBTC);
                break;
            case 2:
                await ifaMasterInstance.setiETH(itokensAddress.rETH);
                await ifaMasterInstance.setiToken(K_MADE_rETH, itokensAddress.rETH);
                break;
            default:
                console.log(`Error: set rToken fail pool_id = ${i}`)
                break;
        }
        await itokenContract[i].methods._setBanker(ifaBankInstance.address).send({ from: accounts[0] });

        let BCParams = { rate: 500, minimumLTV: 65, maxmumLTV: 90, minimumSize: web3.utils.toWei('500') };
        switch (i) {
            case 0:
                BCParams.rate = 500;
                BCParams.minimumLTV = 65;
                BCParams.maxmumLTV = 90;
                BCParams.minimumSize = web3.utils.toWei('500');
                break;
            case 1:
                BCParams.rate = 600;
                BCParams.minimumLTV = 75;
                BCParams.maxmumLTV = 90;
                BCParams.minimumSize = web3.utils.toWei('0.05');
                break;
            case 2:
                BCParams.rate = 550;
                BCParams.minimumLTV = 70;
                BCParams.maxmumLTV = 90;
                BCParams.minimumSize = web3.utils.toWei('1');
                break;
            default:
                console.log(`Error: borrow pool_id = ${i}`)
                break;
        }
        let basicCalculator = await BasicCalculator.new(ifaMasterInstance.address, BCParams.rate, BCParams.minimumLTV, BCParams.maxmumLTV, BCParams.minimumSize)
            .then((result) => { console.log(`${name}Calculators:`, result.address); return result; });
        calculatorsAddress[`${name}Calculators`] = basicCalculator.address;
        await ifaMasterInstance.addVault(kVault, vaultInstance.address);
        await ifaMasterInstance.addCalculator(K_CALCULATOR, basicCalculator.address);
        // close pool
        // await ifaBankInstance.setPoolInfo(poolId, itokenAddress[i], vaultInstance.address, basicCalculator.address);
        // await ifaPoolInstance.setPoolInfo(poolId, tokenAddress[i], vaultInstance.address, now);
        await createIFAInstance.setPoolInfo(poolId, vaultInstance.address, tokenAddress[i], allocPointBase, false);
    }
    console.log(`deployBorrowPools end\n`)
}
// depoly borrow pools total:3
depoly borrow pools total:3
depoly borrow pools total : 3
async function deployBorrowPools(deployer, network, accounts) {
    console.log(`deployBorrowPools deployering...`)
    let vaults = [BirrCastle, Sunnylands, ChateauLafitte];
    let K_CALCULATORS = [K_CALCULATOR_HUSD, K_CALCULATOR_HBTC, K_CALCULATOR_HETH];
    let itokenAddress = [itokensAddress.rUSD, itokensAddress.rBTC, itokensAddress.rETH];
    let tokenAddress = [tokensAddress.HUSD, tokensAddress.HBTC, tokensAddress.HETH];
    let ifaMasterInstance = await IFAMaster.at(publicContractAddress.IFAMaster);
    let ifaBankInstance = await IFABank.at(publicContractAddress.IFABank);
    let ifaPoolInstance = await IFAPool.at(publicContractAddress.IFAPool);
    let createIFAInstance = await CreateIFA.at(publicContractAddress.CreateIFA);
    let itokenContract = [
        new web3.eth.Contract(iTokenDelegator.abi, itokensAddress.rUSD),
        new web3.eth.Contract(iTokenDelegator.abi, itokensAddress.rBTC),
        new web3.eth.Contract(iTokenDelegator.abi, itokensAddress.rETH)
    ]
    for (let i = 0; i < vaults.length; i++) {
        if (!POOL_ENABLE_STATUS[i]) {
            continue;
        }
        let poolId = i;
        let K_CALCULATOR = K_CALCULATORS[i];
        let kVault = i
        let vault = vaults[kVault];
        let now = Math.floor((new Date()).getTime() / 1000 - 3600);
        let vaultInstance = await vault.new(ifaMasterInstance.address, publicContractAddress.CreateIFA)
            .then((result) => { console.log(`${poolVaultName[i]}:`, result.address); return result; });
        let name = poolVaultName[i];
        poolVaultContractAddress[poolVaultName[i]] = vaultInstance.address;
        switch (i) {
            case 0:
                await ifaMasterInstance.setiUSD(itokensAddress.rUSD);
                await ifaMasterInstance.setiToken(K_MADE_rUSD, itokensAddress.rUSD);
                break;
            case 1:
                await ifaMasterInstance.setiBTC(itokensAddress.rBTC);
                await ifaMasterInstance.setiToken(K_MADE_rBTC, itokensAddress.rBTC);
                break;
            case 2:
                await ifaMasterInstance.setiETH(itokensAddress.rETH);
                await ifaMasterInstance.setiToken(K_MADE_rETH, itokensAddress.rETH);
                break;
            default:
                console.log(`Error: set rToken fail pool_id = ${i}`)
                break;
        }
        await itokenContract[i].methods._setBanker(ifaBankInstance.address).send({ from: accounts[0] });
        let BCParams = { rate: 500, minimumLTV: 65, maxmumLTV: 90, minimumSize: web3.utils.toWei('500') };
        switch (i) {
            case 0:
                BCParams.rate = 500;
                BCParams.minimumLTV = 65;
                BCParams.maxmumLTV = 90;
                BCParams.minimumSize = web3.utils.toWei('500');
                break;
            case 1:
                BCParams.rate = 600;
                BCParams.minimumLTV = 75;
                BCParams.maxmumLTV = 90;
                BCParams.minimumSize = web3.utils.toWei('0.05');
                break;
            case 2:
                BCParams.rate = 550;
                BCParams.minimumLTV = 70;
                BCParams.maxmumLTV = 90;
                BCParams.minimumSize = web3.utils.toWei('1');
                break;
            default:
                console.log(`Error: borrow pool_id = ${i}`)
                break;
        }
        let basicCalculator = await BasicCalculator.new(ifaMasterInstance.address, BCParams.rate, BCParams.minimumLTV, BCParams.maxmumLTV, BCParams.minimumSize)
            .then((result) => { console.log(`${name}Calculators:`, result.address); return result; });
        calculatorsAddress[`${name}Calculators`] = basicCalculator.address;
        await ifaMasterInstance.addVault(kVault, vaultInstance.address);
        await ifaMasterInstance.addCalculator(K_CALCULATOR, basicCalculator.address);
        await createIFAInstance.setPoolInfo(poolId, vaultInstance.address, tokenAddress[i], allocPointBase, false);
    }
    console.log(`deployBorrowPools end\n`)
}
async function deployBorrowPools ( deployer , network , accounts ) { console . log ( ` ` ) let vaults = [ BirrCastle , Sunnylands , ChateauLafitte ] ; let K_CALCULATORS = [ K_CALCULATOR_HUSD , K_CALCULATOR_HBTC , K_CALCULATOR_HETH ] ; let itokenAddress = [ itokensAddress . rUSD , itokensAddress . rBTC , itokensAddress . rETH ] ; let tokenAddress = [ tokensAddress . HUSD , tokensAddress . HBTC , tokensAddress . HETH ] ; let ifaMasterInstance = await IFAMaster . at ( publicContractAddress . IFAMaster ) ; let ifaBankInstance = await IFABank . at ( publicContractAddress . IFABank ) ; let ifaPoolInstance = await IFAPool . at ( publicContractAddress . IFAPool ) ; let createIFAInstance = await CreateIFA . at ( publicContractAddress . CreateIFA ) ; let itokenContract = [ new web3 . eth . Contract ( iTokenDelegator . abi , itokensAddress . rUSD ) , new web3 . eth . Contract ( iTokenDelegator . abi , itokensAddress . rBTC ) , new web3 . eth . Contract ( iTokenDelegator . abi , itokensAddress . rETH ) ] for ( let i = 0 ; i < vaults . length ; i ++ ) { if ( ! POOL_ENABLE_STATUS [ i ] ) { continue ; } let poolId = i ; let K_CALCULATOR = K_CALCULATORS [ i ] ; let kVault = i let vault = vaults [ kVault ] ; let now = Math . floor ( ( new Date ( ) ) . getTime ( ) / 1000 - 3600 ) ; let vaultInstance = await vault . new ( ifaMasterInstance . address , publicContractAddress . CreateIFA ) . then ( ( result ) => { console . log ( ` ${ poolVaultName [ i ] } ` , result . address ) ; return result ; } ) ; let name = poolVaultName [ i ] ; poolVaultContractAddress [ poolVaultName [ i ] ] = vaultInstance . address ; switch ( i ) { case 0 : await ifaMasterInstance . setiUSD ( itokensAddress . rUSD ) ; await ifaMasterInstance . setiToken ( K_MADE_rUSD , itokensAddress . rUSD ) ; break ; case 1 : await ifaMasterInstance . setiBTC ( itokensAddress . rBTC ) ; await ifaMasterInstance . setiToken ( K_MADE_rBTC , itokensAddress . rBTC ) ; break ; case 2 : await ifaMasterInstance . setiETH ( itokensAddress . rETH ) ; await ifaMasterInstance . setiToken ( K_MADE_rETH , itokensAddress . rETH ) ; break ; default : console . log ( ` ${ i } ` ) break ; } await itokenContract [ i ] . methods . _setBanker ( ifaBankInstance . address ) . send ( { from : accounts [ 0 ] } ) ; let BCParams = { rate : 500 , minimumLTV : 65 , maxmumLTV : 90 , minimumSize : web3 . utils . toWei ( '500' ) } ; switch ( i ) { case 0 : BCParams . rate = 500 ; BCParams . minimumLTV = 65 ; BCParams . maxmumLTV = 90 ; BCParams . minimumSize = web3 . utils . toWei ( '500' ) ; break ; case 1 : BCParams . rate = 600 ; BCParams . minimumLTV = 75 ; BCParams . maxmumLTV = 90 ; BCParams . minimumSize = web3 . utils . toWei ( '0.05' ) ; break ; case 2 : BCParams . rate = 550 ; BCParams . minimumLTV = 70 ; BCParams . maxmumLTV = 90 ; BCParams . minimumSize = web3 . utils . toWei ( '1' ) ; break ; default : console . log ( ` ${ i } ` ) break ; } let basicCalculator = await BasicCalculator . new ( ifaMasterInstance . address , BCParams . rate , BCParams . minimumLTV , BCParams . maxmumLTV , BCParams . minimumSize ) . then ( ( result ) => { console . log ( ` ${ name } ` , result . address ) ; return result ; } ) ; calculatorsAddress [ ` ${ name } ` ] = basicCalculator . address ; await ifaMasterInstance . addVault ( kVault , vaultInstance . address ) ; await ifaMasterInstance . addCalculator ( K_CALCULATOR , basicCalculator . address ) ; await createIFAInstance . setPoolInfo ( poolId , vaultInstance . address , tokenAddress [ i ] , allocPointBase , false ) ; } console . log ( ` \n ` ) }
depoly borrow pools total:3
depoly borrow pools total : 3
// Whether to deploy the current pool , Do not deploy when POOL_ENABLE_STATUS is false // set rTokens // close pool // await ifaBankInstance.setPoolInfo(poolId, itokenAddress[i], vaultInstance.address, basicCalculator.address); // await ifaPoolInstance.setPoolInfo(poolId, tokenAddress[i], vaultInstance.address, now);