Skip to content

Instantly share code, notes, and snippets.

@bitcoinwarrior1
Created September 2, 2021 00:22
Show Gist options
  • Save bitcoinwarrior1/fba2069c4711a4680925e7b8f91d9a4f to your computer and use it in GitHub Desktop.
Save bitcoinwarrior1/fba2069c4711a4680925e7b8f91d9a4f to your computer and use it in GitHub Desktop.
Get prices from the NEST Oracle and then provide the prices for free
import 'https://raw.githubusercontent.com/NEST-Protocol/NEST-Oracle-V3.5/main/contracts/iface/INestQuery.sol';
pragma solidity ^0.6.12;
contract NESTBootleg {
struct Price {
uint ethAmount;
uint erc20Amount;
uint blockNum;
}
mapping(address => mapping(uint => Price)) prices;
INestQuery iNestQuery;
constructor(_nestQueryAddress) {
iNestQuery = INestQuery(_nestQueryAddress);
}
function updatePrice(address token) public payable {
(uint ethAmount, uint erc20Amount, uint blockNum) = iNestQuery.query(token, msg.sender);
Price newPrice = Price(ethAmount, erc20Amount, blockNum);
prices[token][blockNum] = newPrice;
}
function getPrice(address token, uint blockNum) public view returns(Price) {
return prices[token][blockNum];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment