Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]feat: add nft level asset #87

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions abis/NFTOracle.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,44 @@
"name": "FeedAdminUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "nftContract",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "levelAsset",
"type": "address"
}
],
"name": "LevelAssetAdded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "nftContract",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "levelAsset",
"type": "address"
}
],
"name": "LevelAssetRemoved",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -126,6 +164,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "levelAsset",
"type": "address"
}
],
"name": "addLevelAsset",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -164,6 +215,30 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_nftContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "getAssetPriceByTokenId",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -202,6 +277,30 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_nftContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "getLevelAssetByTokenId",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -442,6 +541,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "levelAsset",
"type": "address"
}
],
"name": "removeLevelAsset",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/INFTLevelAsset.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.4;

interface INFTLevelAsset {
function nftContract() external view returns (address);

function nftLevelKey() external view returns (bytes32);

function nftLevelName() external view returns (string memory);

function isValid(uint256 tokenId) external view returns (bool);
}
2 changes: 2 additions & 0 deletions contracts/interfaces/INFTOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface INFTOracle {
// get asset price
function getAssetPrice(address _nftContract) external view returns (uint256);

function getAssetPriceByTokenId(address _nftContract, uint256 tokenId) external view returns (uint256);

// get latest timestamp
function getLatestTimestamp(address _nftContract) external view returns (uint256);

Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/INFTOracleGetter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface INFTOracleGetter {
@dev returns the asset price in ETH
*/
function getAssetPrice(address asset) external view returns (uint256);

function getAssetPriceByTokenId(address _nftContract, uint256 tokenId) external view returns (uint256);
}
3 changes: 2 additions & 1 deletion contracts/libraries/logic/BorrowLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ library BorrowLogic {
vars.loanAddress,
vars.loanId,
vars.reserveOracle,
vars.nftOracle
vars.nftOracle,
params.nftTokenId
);

if (vars.loanId == 0) {
Expand Down
22 changes: 16 additions & 6 deletions contracts/libraries/logic/GenericLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ library GenericLogic {
address loanAddress,
uint256 loanId,
address reserveOracle,
address nftOracle
address nftOracle,
uint256 nftTokenId
)
internal
view
Expand Down Expand Up @@ -92,7 +93,9 @@ library GenericLogic {
nftAddress,
nftData,
reserveOracle,
nftOracle
nftOracle,
nftTokenId,
true
);

// calculate health by borrow and collateral
Expand Down Expand Up @@ -133,7 +136,9 @@ library GenericLogic {
address nftAddress,
DataTypes.NftData storage nftData,
address reserveOracle,
address nftOracle
address nftOracle,
uint256 nftTokenId,
bool useNftTokenId
) internal view returns (uint256, uint256) {
reserveData;
nftData;
Expand All @@ -143,7 +148,11 @@ library GenericLogic {
// calculate total collateral balance for the nft
// all asset price has converted to ETH based, unit is in WEI (18 decimals)

vars.nftUnitPrice = INFTOracleGetter(nftOracle).getAssetPrice(nftAddress);
if (useNftTokenId) {
vars.nftUnitPrice = INFTOracleGetter(nftOracle).getAssetPriceByTokenId(nftAddress, nftTokenId);
} else {
vars.nftUnitPrice = INFTOracleGetter(nftOracle).getAssetPrice(nftAddress);
}
vars.totalCollateralInETH = vars.nftUnitPrice;

if (reserveAddress != address(0)) {
Expand Down Expand Up @@ -220,7 +229,8 @@ library GenericLogic {
DataTypes.NftData storage nftData,
address poolLoan,
address reserveOracle,
address nftOracle
address nftOracle,
uint256 nftTokenId
)
internal
view
Expand Down Expand Up @@ -248,7 +258,7 @@ library GenericLogic {

(vars.ltv, vars.liquidationThreshold, vars.liquidationBonus) = nftData.configuration.getCollateralParams();

vars.nftPriceInETH = INFTOracleGetter(nftOracle).getAssetPrice(nftAsset);
vars.nftPriceInETH = INFTOracleGetter(nftOracle).getAssetPriceByTokenId(nftAsset, nftTokenId);
vars.reservePriceInETH = IReserveOracleGetter(reserveOracle).getAssetPrice(reserveAsset);

vars.nftPriceInReserve = ((10**vars.reserveDecimals) * vars.nftPriceInETH) / vars.reservePriceInETH;
Expand Down
9 changes: 6 additions & 3 deletions contracts/libraries/logic/LiquidateLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ library LiquidateLogic {
nftData,
vars.loanAddress,
vars.reserveOracle,
vars.nftOracle
vars.nftOracle,
loanData.nftTokenId
);

// first time bid need to burn debt tokens and transfer reserve to bTokens
Expand Down Expand Up @@ -289,7 +290,8 @@ library LiquidateLogic {
nftData,
vars.poolLoan,
vars.reserveOracle,
vars.nftOracle
vars.nftOracle,
loanData.nftTokenId
);

// check bid fine in min & max range
Expand Down Expand Up @@ -425,7 +427,8 @@ library LiquidateLogic {
nftData,
vars.poolLoan,
vars.reserveOracle,
vars.nftOracle
vars.nftOracle,
loanData.nftTokenId
);

// Last bid price can not cover borrow amount
Expand Down
6 changes: 4 additions & 2 deletions contracts/libraries/logic/ValidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ library ValidationLogic {
address loanAddress,
uint256 loanId,
address reserveOracle,
address nftOracle
address nftOracle,
uint256 nftTokenId
) external view {
ValidateBorrowLocalVars memory vars;

Expand Down Expand Up @@ -131,7 +132,8 @@ library ValidationLogic {
loanAddress,
loanId,
reserveOracle,
nftOracle
nftOracle,
nftTokenId
);

require(vars.userCollateralBalance > 0, Errors.VL_COLLATERAL_BALANCE_IS_0);
Expand Down
Loading