Skip to content

Instantly share code, notes, and snippets.

View alexroan's full-sized avatar

Alex Roan alexroan

View GitHub Profile
@alexroan
alexroan / KrakenConsumer.sol
Last active March 25, 2021 12:22
KrakenConsumer.sol
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/ChainlinkClient.sol";
/**
* DO NOT USE IN PRODUCTION!!
* THIS IS EXAMPLE CONTRACT FOR THE KOVAN TESTNET
*/
contract KrakenConsumer is ChainlinkClient {
pragma solidity ^0.5.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
pragma solidity ^0.5.0;
interface Oracle {
function getUnderlyingPrice(address cToken) external view returns (uint);
}
contract Comptroller {
Oracle public oracle;
}
@alexroan
alexroan / VRFD20.sol
Last active July 12, 2021 01:57
Game of Thrones 20 Sided Dice
// SPDX-License-Identifier: MIT
pragma solidity 0.6.6;
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/Owned.sol";
/**
* @notice A Chainlink VRF consumer which uses randomness to mimic the rolling
* of a 20 sided die
* @dev This is only an example implementation and not necessarily suitable for mainnet.
@alexroan
alexroan / bytesSwap.sol
Created October 23, 2020 15:23
bytesSwap.sol
pragma solidity ^0.7.0;
library bytesSwap {
function bytes32ToString(bytes32 _bytes32) public pure returns (string memory) {
uint8 i = 0;
while(i < 32 && _bytes32[i] != 0) {
i++;
}
bytes memory bytesArray = new bytes(i);
@alexroan
alexroan / Client.sol
Last active March 25, 2021 12:23
ChainlinkHackathon/OpenLibrary/Client.sol
pragma solidity ^0.6.0;
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract Client is ChainlinkClient {
// where to store the last id scanned
bytes32 public last_uid;
// chainlink vars for communicating with the RFID external adapter
address private oracle;
bytes32 private jobId;
@alexroan
alexroan / HistoricalPriceConsumerV3.sol
Last active March 16, 2021 13:22
New Historical Price Consumer
// This example code is designed to quickly deploy an example contract using Remix.
pragma solidity ^0.6.7;
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract HistoricalPriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
@alexroan
alexroan / getLatestPrice_web3.py
Created August 4, 2020 13:20
getLatestPrice_web3.py
from web3 import Web3
web3 = Web3(Web3.HTTPProvider('https://ropsten.infura.io/v3/<infura_project_id>'))
abi = '[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"int256","name":"current","type":"int256"},{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"AnswerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":true,"internalType":"address","name":"startedBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"}],"name":"NewRound","type":"event"},{"inputs":[{"internalType":"uint256","name":"roundId","type":"uint256"}],"name":"getAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"roundId","type":"uint256"}],"name":"getTimestamp","outputs":[{"internal
@alexroan
alexroan / getLatestPrice_web3.js
Created August 4, 2020 12:18
getLatestPrice_web3.js
// Require web3js
const Web3 = require("web3");
// Setup web3
const provider = new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/<infura_project_id>");
const web3 = new Web3(provider);
// Load ABI and Address
const aggregatorInterfaceABI = [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"int256","name":"current","type":"int256"},{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"AnswerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":true,"internalType":"address","name":"startedBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"}],"name":"NewRound","type":"event"},{"inputs":[{"internalType":"uint256","name":"roundId","type":"uint256"}],"name":"getAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"
@alexroan
alexroan / HistoricalPriceConsumerV3.sol
Last active March 16, 2021 13:23
HistoricalPriceConsumerV3
// This example code is designed to quickly deploy an example contract using Remix.
pragma solidity ^0.6.7;
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract HistoricalPriceConsumerV3 {
AggregatorV3Interface internal priceFeed;