From 9457b781c54ae2f5ce0033f32f25d759026449d7 Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Fri, 23 Jun 2023 09:00:51 +0700 Subject: [PATCH] stable pricer --- contracts/pricers/ChainlinkStablePricer.sol | 54 +++++++++++++++++++++ scripts/deployChainlinkStablePricer.js | 32 ++++++++++++ truffle-config.js | 12 ++++- 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 contracts/pricers/ChainlinkStablePricer.sol create mode 100644 scripts/deployChainlinkStablePricer.js diff --git a/contracts/pricers/ChainlinkStablePricer.sol b/contracts/pricers/ChainlinkStablePricer.sol new file mode 100644 index 000000000..b4de0e7a5 --- /dev/null +++ b/contracts/pricers/ChainlinkStablePricer.sol @@ -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); + } +} diff --git a/scripts/deployChainlinkStablePricer.js b/scripts/deployChainlinkStablePricer.js new file mode 100644 index 000000000..b90d37fb3 --- /dev/null +++ b/scripts/deployChainlinkStablePricer.js @@ -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 --asset --oracle --gasPrice --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) + } +} diff --git a/truffle-config.js b/truffle-config.js index eca765019..2f2ff4572 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -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: { @@ -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: {