-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Onyx-Protocol/feat/nft-price-adapter
Nft price adapter
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.5.16; | ||
|
||
// Interface for BendDAO NFT Oracle | ||
// https://etherscan.io/address/0x7c2a19e54e48718f6c60908a9cff3396e4ea1eba | ||
|
||
interface INFTOracle { | ||
|
||
// get asset price | ||
function getAssetPrice(address _nftContract) external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.5.16; | ||
|
||
import "../SafeMath.sol"; | ||
import "./AggregatorV2V3Interface.sol"; | ||
import "./INFTOracle.sol"; | ||
|
||
contract NFTPriceAdapter { | ||
using SafeMath for uint256; | ||
|
||
AggregatorV2V3Interface public ETH_PRICE_FEED; | ||
INFTOracle public NFT_PRICE_ORACLE; | ||
address public NFT_CONTRACT; | ||
|
||
uint8 public constant DECIMALS = 18; | ||
|
||
constructor(address _ethPriceFeed, address _nftOracle, address _nftContract) public { | ||
ETH_PRICE_FEED = AggregatorV2V3Interface(_ethPriceFeed); | ||
NFT_PRICE_ORACLE = INFTOracle(_nftOracle); | ||
NFT_CONTRACT = _nftContract; | ||
} | ||
|
||
function decimals() external view returns (uint8) { | ||
return DECIMALS; | ||
} | ||
|
||
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) { | ||
(, int256 ethPrice, , , ) = ETH_PRICE_FEED.latestRoundData(); | ||
uint8 ethDecimals = ETH_PRICE_FEED.decimals(); | ||
uint256 assetPrice = NFT_PRICE_ORACLE.getAssetPrice(NFT_CONTRACT); | ||
int256 price = int256(assetPrice.mul(uint256(ethPrice)).div(10 ** ethDecimals)); | ||
|
||
return ( | ||
1, | ||
price, | ||
block.timestamp, | ||
block.timestamp, | ||
1 | ||
); | ||
} | ||
} |