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

fixes #154

Open
wants to merge 4 commits into
base: hayesgm/open-oracle-v1
Choose a base branch
from
Open

fixes #154

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
yarn-error.log
junit.xml
coverage/*
.saddle_history
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "compound-config"]
path = compound-config
url = https://github.com/compound-finance/compound-config.git
1 change: 1 addition & 0 deletions compound-config
Submodule compound-config added at 66c405
16 changes: 10 additions & 6 deletions contracts/Uniswap/UniswapAnchoredView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,16 @@ contract UniswapAnchoredView is UniswapConfig {

// Adjust rawUniswapPrice according to the units of the non-ETH asset
// In the case of ETH, we would have to scale by 1e6 / USDC_UNITS, but since baseUnit2 is 1e6 (USDC), it cancels
if (config.isUniswapReversed) {
// unscaledPriceMantissa * ethBaseUnit / config.baseUnit / expScale, but we simplify bc ethBaseUnit == expScale
anchorPrice = unscaledPriceMantissa / config.baseUnit;
} else {
anchorPrice = mul(unscaledPriceMantissa, config.baseUnit) / ethBaseUnit / expScale;
}

// In the case of non-ETH tokens
// a. pokeWindowValues already handled uniswap reversed cases, so priceAverage will always be Token/ETH TWAP price.
// b. conversionFactor = ETH price * 1e6
// unscaledPriceMantissa = priceAverage(token/ETH TWAP price) * expScale * conversionFactor
// so ->
// anchorPrice = priceAverage * tokenBaseUnit / ethBaseUnit * ETH_price * 1e6
// = priceAverage * conversionFactor * tokenBaseUnit / ethBaseUnit
// = unscaledPriceMantissa / expScale * tokenBaseUnit / ethBaseUnit
anchorPrice = mul(unscaledPriceMantissa, config.baseUnit) / ethBaseUnit / expScale;

emit AnchorPriceUpdated(symbol, anchorPrice, oldTimestamp, block.timestamp);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"dependencies": {
"bignumber.js": "^9.0.0",
"eth-saddle": "0.1.20",
"eth-saddle": "0.1.21",
"web3": "^1.2.4",
"yargs": "^15.0.2"
},
Expand Down
22 changes: 22 additions & 0 deletions saddle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,27 @@ module.exports = {
{ file: "~/.ethereum/mainnet" } // Load from given file with contents as the private key (e.g. 0x...)
]
}
},
get_network_file: (network) => {
return null;
},
read_network_file: (network) => {
const fs = require('fs');
const path = require('path');
const util = require('util');

const networkFile = path.join(process.cwd(), 'compound-config', 'networks', `${network}.json`);
return util.promisify(fs.readFile)(networkFile).then((json) => {
const contracts = JSON.parse(json)['Contracts'] || {};

return Object.fromEntries(Object.entries(contracts).map(([contract, address]) => {
const mapper = {
PriceFeed: 'UniswapAnchoredView',
PriceData: 'OpenOraclePriceData'
};

return [mapper[contract] || contract, address];
}));
});
}
};
3 changes: 1 addition & 2 deletions tests/UniswapAnchoredViewTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ async function setup({isMockedView, freeze}) {
const anchorMantissa = numToHex(1e17);
const priceData = await deploy('OpenOraclePriceData', []);
const anchorPeriod = 60;
const timestamp = 1600000000;

const timestamp = Math.floor(Date.now() / 1000);

if (freeze) {
await sendRPC(web3, 'evm_freezeTime', [timestamp]);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3673,10 +3673,10 @@ eth-query@^2.0.2, eth-query@^2.1.0, eth-query@^2.1.2:
json-rpc-random-id "^1.0.0"
xtend "^4.0.1"

eth-saddle@0.1.20:
version "0.1.20"
resolved "https://registry.yarnpkg.com/eth-saddle/-/eth-saddle-0.1.20.tgz#1ce8217e36735c23667a003beaeaa65e0f07e150"
integrity sha512-LiOfheTXtyUd2ZZYORfKL4Lx42yach8SabbtyyGM5MwH6Th7GFk+TGDDerIJ9lvmCxeZBqxG0jVmKXfFez/0Dg==
eth-saddle@0.1.21:
version "0.1.21"
resolved "https://registry.yarnpkg.com/eth-saddle/-/eth-saddle-0.1.21.tgz#692ac403f6f68c71f3e81336869e2259ab77d97e"
integrity sha512-XsswjrWJaQnixrQk7ycL8fOUoqqyRbkSo9TkGJrgxNNcYjtF6/wFOjxgfwxxd3FIQWLCuAF4jcO6RpFRiEAh4Q==
dependencies:
"@0x/subproviders" "^6.0.0"
"@compound-finance/sol-coverage" "^4.0.10-alpha.7"
Expand Down