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

Chainlink stable pricer #474

Open
wants to merge 1 commit into
base: master
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
54 changes: 54 additions & 0 deletions contracts/pricers/ChainlinkStablePricer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.10;

import {OracleInterface} from "../interfaces/OracleInterface.sol";
import {OpynPricerInterface} from "../interfaces/OpynPricerInterface.sol";

/**
* @notice A Pricer contract to push stable USDC price (1:1 to USD)
*/
contract ChainlinkStablePricer is OpynPricerInterface {
/// @notice the opyn oracle address
OracleInterface public oracle;

/// @notice asset that this pricer will a get price for
address public asset;

/**
* @param _asset asset that this pricer will get a price for
* @param _oracle Opyn Oracle address
*/
constructor(address _asset, address _oracle) public {
require(_oracle != address(0), "ChainLinkPricer: Cannot set 0 address as oracle");

oracle = OracleInterface(_oracle);
asset = _asset;
}

/**
* @notice set the expiry price in the oracle, always 1e8
* @param _expiryTimestamp expiry to set a price for
*/
function setExpiryPriceInOracle(uint256 _expiryTimestamp) external {
oracle.setExpiryPrice(asset, _expiryTimestamp, uint256(1e8));
}

/**
* @notice get the live price for the asset
* @dev overides the getPrice function in OpynPricerInterface
* @return price of the asset in USD, scaled by 1e8
*/
function getPrice() external view override returns (uint256) {
return uint256(1e8);
}

/**
* @notice get historical USDC price (always 1e8)
* @return round price and timestamp
*/
function getHistoricalPrice(
uint80 /*_roundId*/
) external view override returns (uint256, uint256) {
return ((uint256(1e8)), block.timestamp);
}
}
32 changes: 32 additions & 0 deletions scripts/deployChainlinkStablePricer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const yargs = require('yargs')

const ChainlinkStablePricer = artifacts.require('ChainlinkStablePricer.sol')

module.exports = async function(callback) {
try {
const options = yargs
.usage(
'Usage: --network <network> --asset <asset> --oracle <oracle> --gasPrice <gasPrice> --gasLimit <gasLimit>',
)
.option('network', {describe: 'Network name', type: 'string', demandOption: true})
.option('asset', {describe: 'Asset address', type: 'string', demandOption: true})
.option('oracle', {describe: 'Oracle module address', type: 'string', demandOption: true})
.option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false})
.option('gasLimit', {describe: 'Gas Limit in WEI', type: 'string', demandOption: false}).argv

console.log(`Deploying chainlink pricer contract on ${options.network} 🍕`)

const tx = await ChainlinkStablePricer.new(options.asset, options.oracle, {
gasPrice: options.gasPrice,
gas: options.gasLimit,
})

console.log('Chainlink pricer deployed! 🎉')
console.log(`Transaction hash: ${tx.transactionHash}`)
console.log(`Deployed contract address: ${tx.address}`)

callback()
} catch (err) {
callback(err)
}
}
12 changes: 10 additions & 2 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = {
gasPrice: 25000000000,
},
avax: {
provider: () => new HDWalletProvider(mnemonic, 'https://api.avax.network/ext/bc/C/rpc'),
provider: () => new HDWalletProvider(mnemonic, `https://avalanche-mainnet.infura.io/v3/${key}`),
network_id: 1,
},
fuji: {
Expand All @@ -72,7 +72,15 @@ module.exports = {
gas: 8000000,
gasPrice: 250000000000,
skipDryRun: true,
}
},
matic: {
provider: () => new HDWalletProvider(mnemonic, `https://polygon-mainnet.infura.io/v3/${key}`),
network_id: 137,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},

},

mocha: {
Expand Down