Skip to content

Commit

Permalink
feat: silo oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec committed Jan 24, 2024
1 parent 0a857de commit b21aaca
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.12;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

import "../../../BaseOracleChainlinkMultiTwoFeeds.sol";
import "../../../../interfaces/external/IERC4626.sol";

/// @title OracleSTEURETHChainlinkArbitrum
/// @author Angle Labs, Inc.
/// @notice Gives the price of stEUR in ETH in base 18
contract OracleSTEURETHChainlinkArbitrum is BaseOracleChainlinkMultiTwoFeeds {
string public constant DESCRIPTION = "stEUR/ETH Oracle";
IERC4626 public constant STEUR = IERC4626(0x004626A008B1aCdC4c74ab51644093b155e59A23);

constructor(uint32 _stalePeriod, address _treasury) BaseOracleChainlinkMultiTwoFeeds(_stalePeriod, _treasury) {}

/// @inheritdoc IOracle
function circuitChainlink() public pure override returns (AggregatorV3Interface[] memory) {
AggregatorV3Interface[] memory _circuitChainlink = new AggregatorV3Interface[](2);
// Oracle agEUR/USD
_circuitChainlink[0] = AggregatorV3Interface(0x37963F10245e7c3a10c0E9d43a6E617B4Bc8440A);
// Oracle ETH/USD
_circuitChainlink[1] = AggregatorV3Interface(0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612);
return _circuitChainlink;
}

/// @inheritdoc BaseOracleChainlinkMultiTwoFeeds
function _getQuoteAmount() internal view override returns (uint256) {
return STEUR.convertToAssets(1 ether);
}

// TODO: latestAnswer
}
37 changes: 37 additions & 0 deletions deploy/newOracle/newOracle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { DeployFunction } from 'hardhat-deploy/types';
import yargs from 'yargs';

import { OracleSTEURETHChainlinkArbitrum, OracleSTEURETHChainlinkArbitrum__factory } from '../../typechain';

const argv = yargs.env('').boolean('ci').parseSync();

const func: DeployFunction = async ({ deployments, ethers, network }) => {
const { deploy } = deployments;
const { deployer } = await ethers.getNamedSigners();

// const treasury = (await deployments.get(`Treasury`)).address;
const treasury = '0x37963F10245e7c3a10c0E9d43a6E617B4Bc8440A';
console.log('Now deploying the Oracle wstETH/USD');
console.log(`Treasury: ${treasury}`);
await deploy('Oracle_STEUR_ETH', {
contract: `OracleSTEURETHChainlinkArbitrum`,
from: deployer.address,
args: [3600 * 36, treasury],
log: !argv.ci,
});
const oracle = (await deployments.get('Oracle_STEUR_ETH')).address;
console.log(`Successfully deployed Oracle stEUR/ETH at the address ${oracle}`);

const oracleContract = new ethers.Contract(
oracle,
OracleSTEURETHChainlinkArbitrum__factory.createInterface(),
deployer,
) as OracleSTEURETHChainlinkArbitrum;

const oracleValue = await oracleContract.read();
console.log('Oracle value', oracleValue.toString());
console.log('');
};

func.tags = ['newOracle'];
export default func;
16 changes: 16 additions & 0 deletions e2e/arbitrum/oraclesChainlink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
MockTreasury__factory,
OracleBTCEURChainlinkArbitrum,
OracleBTCEURChainlinkArbitrum__factory,
OracleSTEURETHChainlinkArbitrum,
OracleSTEURETHChainlinkArbitrum__factory,
} from '../../typechain';

contract('Oracles Chainlink', () => {
Expand All @@ -18,6 +20,7 @@ contract('Oracles Chainlink', () => {
let bob: SignerWithAddress;

let oracleBTC: OracleBTCEURChainlinkArbitrum;
let oracleSTEUR: OracleSTEURETHChainlinkArbitrum;
let stalePeriod: BigNumber;
let treasury: MockTreasury;

Expand All @@ -33,6 +36,7 @@ contract('Oracles Chainlink', () => {
ZERO_ADDRESS,
)) as MockTreasury;
oracleBTC = await new OracleBTCEURChainlinkArbitrum__factory(deployer).deploy(stalePeriod, treasury.address);
oracleSTEUR = await new OracleSTEURETHChainlinkArbitrum__factory(deployer).deploy(stalePeriod, treasury.address);
});

describe('Oracle BTC', () => {
Expand All @@ -47,4 +51,16 @@ contract('Oracles Chainlink', () => {
expect(await oracleBTC.treasury()).to.be.equal(treasury.address);
});
});
describe('Oracle stEUR', () => {
it('read', async () => {
const receipt = await oracleSTEUR.read();
const gas = await oracleSTEUR.estimateGas.read();
console.log(gas.toString());
console.log(receipt.toString());
});
it('initialization', async () => {
expect(await oracleSTEUR.stalePeriod()).to.be.equal(stalePeriod);
expect(await oracleSTEUR.treasury()).to.be.equal(treasury.address);
});
});
});
8 changes: 3 additions & 5 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ const config: HardhatUserConfig = {
forking: {
enabled: argv.fork || false,
// Mainnet

/*
url: nodeUrl('mainnet'),
blockNumber: 18976806,

*/
// Polygon
/*
url: nodeUrl('forkpolygon'),
Expand All @@ -162,10 +162,8 @@ const config: HardhatUserConfig = {
blockNumber: 114397708,
*/
// Arbitrum
/*
url: nodeUrl('arbitrum'),
blockNumber: 19356874,
*/
blockNumber: 173676662,
// Avalanche
/*
url: nodeUrl('avalanche'),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"size": "yarn hardhat:compile && hardhat size-contracts",
"hardhat:test": "hardhat test",
"test:e2e:mainnet": "FORK=true hardhat test e2e/mainnet/oraclesChainlink.test.ts",
"test:e2e:arbitrum": "FORK=true hardhat test e2e/arbitrum/oraclesChainlink.test.ts",
"test:e2e:balance": "FORK=true hardhat test e2e/mainnet/balanceOf.test.ts",
"test:e2e": "FORK=true hardhat test",
"test:all": "yarn test && yarn test:e2e:mainnet",
Expand Down

0 comments on commit b21aaca

Please sign in to comment.