// Load the ethers librariy
// Load the ABI. The flashloan Provider interface can be found on
// https://github.com/Equalizer-Finance/equalizer-smart-contracts-v1/blob/master/contracts/interfaces/IERC3156FlashLender.sol
const providerAbi = require("./abi.json");
const jsonRpcURL = 'https://rinkeby.infura.io/v3/<API-KEY>';
// Private key of the account that will borrow a flash loan
// Important! Never share your private key with anyone!
const privateKey = '<YOUR-PRIVATE-KEY-GOES-HERE>';
// the address of the FlashLoan Receiver that implements the interface
// https://github.com/Equalizer-Finance/equalizer-smart-contracts-v1/blob/master/contracts/interfaces/IERC3156FlashBorrower.sol
// example receiver here: https://rinkeby.etherscan.io/address/0x9B38b85e22C94F4a57b4507216B7E444b667B872#code
const flashLoanReceiverAddress = '0x41EC9B0C0f0a354e3d7d9f1982643eEd0a8C2EB1';
// the address of the flashloan provider - rinkeby example
const flashLoanProviderAddress = '0x3649380F6ce217Ae1d76FCc4092d3c84EB45f7d1';
// the address of the borrowed token - rinkeby USDT example below
const tokenAddress = '0xbE6C02195A28d163A1DF2e05B0596416d326b190';
// can be extracted from vaultFactory with tokenAddress
const vaultOfToken = '0xCfB9243003EAB8676634e891162a6f7c74855E8f';
const provider = new ethers.providers.JsonRpcProvider(jsonRpcURL);
const wallet = new ethers.Wallet(privateKey, provider);
// init the contract of flashloan provider with wallet connected to it
const flashLoanProviderContract = new ethers.Contract(flashLoanProviderAddress, providerAbi, wallet);
// const receiverContract = new ethers.Contract (flashLoanReceiverAddress, )
// check max loan amount for the token
const maxAmount = await flashLoanProviderContract.maxFlashLoan(tokenAddress);
// make sure u set allowance for the provider for the vault
console.log(await (await flashLoanProviderContract.flashLoan(flashLoanReceiverAddress, tokenAddress, 100, "0x", {