Skip to content

Commit

Permalink
Merge pull request #7 from Onyx-Protocol/feat/nft-price-adapter
Browse files Browse the repository at this point in the history
Nft price adapter
  • Loading branch information
ozdav97 authored Jul 10, 2024
2 parents d7952c3 + e422118 commit 871c89a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions contracts/ChainlinkOracle/INFTOracle.sol
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);
}
42 changes: 42 additions & 0 deletions contracts/ChainlinkOracle/NFTPriceAdapter.sol
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
);
}
}

0 comments on commit 871c89a

Please sign in to comment.