@hifi/protocol
v1.12.0
Published
The core Hifi fixed-rate, fixed-term lending protocol
Downloads
240
Readme
Hifi Protocol
The core Hifi fixed-rate, fixed-term lending protocol. Hifi is a decentralized finance protocol that brings fixed-rate, fixed-term lending to Ethereum-based blockchains.
The build artifacts can be browsed via unpkg.com.
Installation
With yarn:
$ yarn add @hifi/protocol
Or npm:
$ npm install @hifi/protocol
Usage
The node package that you just installed contains both Solidity and JavaScript code. The former is the smart contracts themselves; the latter, the smart contract ABIs and the TypeChain bindings.
Solidity
The core Hifi protocol can only be compiled with Solidity v0.8.4 and above, because we are reverting with custom errors instead of reason strings.
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;
import "@hifi/protocol/contracts/core/balance-sheet/IBalanceSheetV2.sol";
contract YourContract {
// Find the address on https://docs.hifi.finance
IBalanceSheetV2 balanceSheet = IBalanceSheetV2(0x...);
function queryAccountLiquidity(address user) external view returns (uint256 excessLiquidity, uint256 shortfallLiquidity) {
(excessLiquidity, shortfallLiquidity) = balanceSheet.getCurrentAccountLiquidity(user);
}
function queryCollateralAmount(address user, IErc20 collateral) external view returns (uint256 collateralAmount) {
collateralAmount = balanceSheet.getCollateralAmount(user, collateral);
}
function queryDebtAmount(address user, IHToken hToken) external view returns (uint256 debtAmount) {
debtAmount = balanceSheet.getDebtAmount(user, hToken);
}
}
JavaScript
import type { BalanceSheetV2__factory } from "@hifi/protocol/dist/types/factories/contracts/core/balance-sheet/BalanceSheetV2__factory";
async function queryAccountLiquidity() {
const signer = "..."; // Get hold of an ethers.js Signer
const balanceSheetFactory = new BalanceSheetV2__factory(signer); // Find the address on https://docs.hifi.finance
const balanceSheet = balanceSheetFactory.attach("0x...");
const user = "0x...";
const accountLiquidity = await balanceSheet.getCurrentAccountLiquidity(user);
}
Deployment
Fintroller
$ yarn hardhat deploy:contract:fintroller \
--new-owner ${NEW_OWNER} \
--confirmations 5 \
--network ${NETWORK} \
--print true \
--verify true
Chainlink Operator
$ yarn hardhat deploy:contract:chainlink-operator \
--new-owner ${NEW_OWNER} \
--confirmations 5 \
--network ${NETWORK} \
--print true \
--verify true
Balance Sheet
$ yarn hardhat deploy:contract:balance-sheet \
--fintroller ${FINTROLLER} \
--oracle ${ORACLE} \
--new-owner ${NEW_OWNER} \
--confirmations 5 \
--network ${NETWORK} \
--print true \
--verify true
HToken
$ yarn hardhat deploy:contract:h-token \
--name ${NAME} \
--symbol ${SYMBOL} \
--maturity ${MATURITY} \
--balance-sheet ${BALANCE_SHEET} \
--fintroller ${FINTROLLER} \
--underlying ${UNDERLYING} \
--confirmations 5 \
--network ${NETWORK} \
--print true \
--verify true
Simple Price Feed
$ yarn hardhat deploy:contract:simple-price-feed \
--description ${DESCRIPTION} \
--confirmations 5 \
--network ${NETWORK} \
--print true \
--verify true
Stablecoin Price Feed
$ yarn hardhat deploy:contract:stablecoin-price-feed \
--price ${PRICE} \
--description ${DESCRIPTION} \
--confirmations 5 \
--network ${NETWORK} \
--print true \
--verify true
Uniswap V3 Price Feed
$ yarn hardhat deploy:contract:uniswap-v3-price-feed \
--pool ${POOL} \
--quoteAsset ${QUOTE_ASSET} \
--twapInterval ${TWAP_INTERVAL} \
--maxPrice ${MAX_PRICE} \
--confirmations 5 \
--network ${NETWORK} \
--print true \
--verify true
License
BUSL 1.1 © Mainframe Group Inc.