Skip to content

Commit

Permalink
Merge pull request #30 from platypus-finance/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MrBeaverTail authored Nov 24, 2022
2 parents 4ab5062 + eb56c80 commit ce7a98d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
55 changes: 55 additions & 0 deletions contracts/oracle/ConstantChainlinkAggregator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: GPL-3.0
import '@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol';

pragma solidity 0.8.9;

// Always returns 1 in 8 d.p as price
contract ConstantChainlinkAggregator is AggregatorV3Interface {
int256 public latestAnswer = 1e8;

function latestTimestamp() external view returns (uint256) {
return block.timestamp;
}

function latestRoundData()
external
view
override
returns (
uint80,
int256,
uint256,
uint256,
uint80
)
{
return (0, latestAnswer, 0, block.timestamp, 0);
}

function version() external pure override returns (uint256) {
return 0;
}

function decimals() external pure override returns (uint8) {
return 8;
}

function description() external pure override returns (string memory) {
return 'Constant chainlink feed';
}

function getRoundData(uint80)
external
pure
override
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
return (0, 0, 0, 0, 0);
}
}
2 changes: 1 addition & 1 deletion slither.db.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions test/ChainlinkProxyPriceProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ethers } from 'hardhat'
import chai from 'chai'
import { ContractFactory } from 'ethers'
import { solidity } from 'ethereum-waffle'
import { parseEther } from '@ethersproject/units'
import { parseEther, parseUnits } from '@ethersproject/units'

chai.use(solidity)
const { expect } = chai
Expand All @@ -11,6 +11,7 @@ describe('ChainlinkProxyPriceProvider', function () {
let owner, users
let ChainlinkProxyPriceProvider: ContractFactory
let TestChainlinkAggregator: ContractFactory
let ConstantChainlinkAggregator: ContractFactory

beforeEach(async function () {
const [first, ...rest] = await ethers.getSigners()
Expand All @@ -19,6 +20,7 @@ describe('ChainlinkProxyPriceProvider', function () {

ChainlinkProxyPriceProvider = await ethers.getContractFactory('ChainlinkProxyPriceProvider')
TestChainlinkAggregator = await ethers.getContractFactory('TestChainlinkAggregator')
ConstantChainlinkAggregator = await ethers.getContractFactory('ConstantChainlinkAggregator')
})

beforeEach(async function () {
Expand All @@ -35,17 +37,22 @@ describe('ChainlinkProxyPriceProvider', function () {
this.DAIAddress = '0xbA7dEebBFC5fA1100Fb055a87773e1E99Cd3507a'
this.WAVAXAddress = '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7'

this.USPAddress = '0x2E12576A13d610508A320aeCe98c7fC9eeF17A67'
this.USPUSD = await ConstantChainlinkAggregator.deploy()

this.provider = await ChainlinkProxyPriceProvider.connect(owner).deploy(
[this.USDTAddress, this.LINKAddress],
[this.USDTAVAX.address, this.LINKAVAX.address]
[this.USDTAddress, this.LINKAddress, this.USPAddress],
[this.USDTAVAX.address, this.LINKAVAX.address, this.USPUSD.address]
)
// await this.provider.connect(owner).setETHAddress(this.WAVAXAddress)
})

describe('getAssetPrice', function () {
it('gets an asset price by address', async function () {
expect(await this.provider.getAssetPrice(this.USDTAddress)).to.be.equal(parseEther('0.001677'))
expect(await this.provider.getAssetPrice(this.LINKAddress)).to.be.equal(parseEther('0.02496761'))
expect(await this.provider.getAssetPrice(this.USPAddress)).to.be.equal(parseUnits('1', 8))

expect(await this.USPUSD.latestAnswer()).to.be.equal(parseUnits('1', 8))
})

it('reverts if asset has no source', async function () {
Expand Down

0 comments on commit ce7a98d

Please sign in to comment.