Borrowing and Repaying
import "./IVaultFactory.sol";
import "./IVault.sol";
import "./ERC20.sol";
// --- core contract logic ---
IVaultFactory vaultFactory = IVaultFactory(0x.....0);
address vaultAddress = 0x...0;
address destinationAddress = msg.sender;
IVault myVault = IVault(vaultAddress);
// get the maximum amount you can borrow
(uint256 maxBorrowable, ) = myVault.borrowable();
// borrowing can only be done from the VaultFactory
vaultFactory.borrow(vaultAddress, maxBorrowable, destinationAddress);
// healthFactor is 18 decimals,
// meaning 1e18 = 1.0 HF
uint256 healthFactor = myVault.healthFactor(false);
require(healthFactor > 2 ** 1e18, "borrowed too much!");Repaying your loan
Last updated