Skip to content

Commit

Permalink
Merge pull request #153 from VenusProtocol/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
chechu authored Dec 28, 2023
2 parents 7e07406 + d639eb5 commit 9ab976b
Show file tree
Hide file tree
Showing 112 changed files with 64,159 additions and 13,398 deletions.
21 changes: 17 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
MNEMONIC=
# true or false
FORK=false
FORKED_NETWORK=bscmainnet

DEPLOYER_PRIVATE_KEY=

## Archive nodes
ARCHIVE_NODE_bsctestnet=https://bsc-testnet.nodereal.io/v1/<YOUR_KEY_HERE>
ARCHIVE_NODE_bscmainnet=https://bsc-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_bscmainnet=http://127.0.0.1:1248
ARCHIVE_NODE_sepolia=https://ethereum-sepolia.blockpi.network/v1/rpc/public
ARCHIVE_NODE_ethereum=https://eth-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_ethereum=http://127.0.0.1:1248
#ARCHIVE_NODE_opbnbtestnet=https://opbnb-testnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_opbnbmainnet=https://opbnb-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>

ETHERSCAN_API_KEY=
REPORT_GAS=
FORK_MAINNET=
QUICK_NODE_URL=
REPORT_GAS=
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,38 @@ jobs:

- name: Verify deployments work
run: yarn hardhat deploy

export-deployments:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.VENUS_TOOLS_TOKEN }}

- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 18
cache: "yarn"

- name: Install dependencies
# Hack to get around failing "ethereumjs-abi The remote archive doesn't match the expected checksum" error
run: YARN_CHECKSUM_BEHAVIOR=update yarn

- name: Export deployments
run: |
for NETWORK in bsctestnet bscmainnet ethereum sepolia opbnbtestnet opbnbmainnet; do
EXPORT=true yarn hardhat export --network ${NETWORK} --export ./deployments/${NETWORK}.json
jq -M '{name, chainId, addresses: .contracts | map_values(.address)}' ./deployments/${NETWORK}.json > ./deployments/${NETWORK}_addresses.json
done
yarn prettier
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "feat: updating deployment files"
file_pattern: "deployments/*.json"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ deployments/localhost

# docs
docs


deployments/hardhat
124 changes: 124 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,127 @@
## [1.8.0-dev.13](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.12...v1.8.0-dev.13) (2023-12-26)


### Features

* updating deployment files ([3ee7763](https://github.com/VenusProtocol/oracle/commit/3ee776362ecf958034754df154e403a6b9a7abad))


### Bug Fixes

* wrong acm address ([7987c7b](https://github.com/VenusProtocol/oracle/commit/7987c7bb84e7183f25cf5da9138f393b9c995ff2))

## [1.8.0-dev.12](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.11...v1.8.0-dev.12) (2023-12-19)


### Features

* updating deployment files ([164ca39](https://github.com/VenusProtocol/oracle/commit/164ca3901fe136bfb8231b8f223aa1a0f54d32d3))

## [1.8.0-dev.11](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.10...v1.8.0-dev.11) (2023-12-18)


### Features

* updating deployment files ([66492ff](https://github.com/VenusProtocol/oracle/commit/66492fff92fa2bf5a3fd23fd2003b1e64771e5d0))

## [1.8.0-dev.10](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.9...v1.8.0-dev.10) (2023-12-15)


### Bug Fixes

* BOV-02 ([59c86ae](https://github.com/VenusProtocol/oracle/commit/59c86ae6a1320d7caa7e6e814fe80930ec25ea04))
* mainnet verify endpoint ([4426cd6](https://github.com/VenusProtocol/oracle/commit/4426cd69410ea19853dacc53b77c7558a5bda538))

## [1.8.0-dev.9](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.8...v1.8.0-dev.9) (2023-12-12)


### Bug Fixes

* exclude external deployments when exporting ([0286860](https://github.com/VenusProtocol/oracle/commit/02868609b31193ee9691192a0803acfaa9e0b0ad))

## [1.8.0-dev.8](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.7...v1.8.0-dev.8) (2023-12-11)

## [1.8.0-dev.7](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.6...v1.8.0-dev.7) (2023-12-08)


### Features

* add oracles deployment ([cbfc4ce](https://github.com/VenusProtocol/oracle/commit/cbfc4cee3ba7252ef41883d6703a1808576e2525))
* use address from packages ([23fe765](https://github.com/VenusProtocol/oracle/commit/23fe765e8b98e0eaa0b98a1569027e27941f0ba2))

## [1.8.0-dev.6](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.5...v1.8.0-dev.6) (2023-12-06)


### Features

* support direct feed registry in binanace oracle ([5e9d40b](https://github.com/VenusProtocol/oracle/commit/5e9d40b0ae6badc1966fc60fa31fb24da23818bc))

## [1.8.0-dev.5](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.4...v1.8.0-dev.5) (2023-12-05)

## [1.8.0-dev.4](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.3...v1.8.0-dev.4) (2023-12-01)


### Features

* generate file only with addresses of deployed contracts ([5b2b538](https://github.com/VenusProtocol/oracle/commit/5b2b538c8d06cdd085d366e4899a33fcb3fcb35c))
* updating deployment files ([5d3294b](https://github.com/VenusProtocol/oracle/commit/5d3294bc117bd74d9ebe544d0375844ad8e4c8c7))

## [1.8.0-dev.3](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.2...v1.8.0-dev.3) (2023-11-29)


### Bug Fixes

* deployment config to have optional oracle config depending on which oracle is deployed on chain ([9822ddb](https://github.com/VenusProtocol/oracle/commit/9822ddb1da8e60a610dbd1016097ef070ecb8bc1))

## [1.8.0-dev.2](https://github.com/VenusProtocol/oracle/compare/v1.8.0-dev.1...v1.8.0-dev.2) (2023-11-27)


### Features

* updating deployment files ([2e37401](https://github.com/VenusProtocol/oracle/commit/2e37401a3af966d573fc0f90c168f6714fbf7f7c))
* updating deployment files ([7ed77d1](https://github.com/VenusProtocol/oracle/commit/7ed77d1ec025815f91c2580886eac8ee41aedeae))


### Bug Fixes

* adjust PRIVATE_KEY naming ([c5dba92](https://github.com/VenusProtocol/oracle/commit/c5dba92ae2afe3aef9064ac750e5ae85d2bbd076))
* config deploy script network name fix ([e3a1a87](https://github.com/VenusProtocol/oracle/commit/e3a1a8737d5b6b03465a192992166b772e829904))
* deployment order ([dad9b1d](https://github.com/VenusProtocol/oracle/commit/dad9b1d8786f3870c055aafe802dec68dc30de02))
* lint ([e8a58dc](https://github.com/VenusProtocol/oracle/commit/e8a58dcaf1eaca2db951bc0530a99de46081ba60))
* lint error ([32c22e6](https://github.com/VenusProtocol/oracle/commit/32c22e6fa54c3858715f61c37555438c7e939482))
* linting ([8ebd43c](https://github.com/VenusProtocol/oracle/commit/8ebd43c30a61c180a9f8ecbe1003d5b493c03165))
* local deployment failure ([48b88e1](https://github.com/VenusProtocol/oracle/commit/48b88e1008849521475eff6a5d524f88538a71ac))
* minor bugs ([c7451f8](https://github.com/VenusProtocol/oracle/commit/c7451f8c505625900c072c65dae4903a848a4dc0))
* minor fix ([94d6d55](https://github.com/VenusProtocol/oracle/commit/94d6d550b5acf5161efa50de43ddb37ab05455bd))
* oracleData to handle case when not all oracles are deployed ([cd20739](https://github.com/VenusProtocol/oracle/commit/cd20739787f12c6296ffc2f4a915d93f44e0e1ce))
* redstone deployment script bug ([e71427a](https://github.com/VenusProtocol/oracle/commit/e71427aee40d7ffc0a25a7cb4b0f319bf6845da9))
* uncomment necessary lines ([7d5dde5](https://github.com/VenusProtocol/oracle/commit/7d5dde5e9075553e588aad9b20cdedfa48fe47da))
* yarn lock ([6b8b1fb](https://github.com/VenusProtocol/oracle/commit/6b8b1fbd7750c30d0e1d7cf464ea4b7566239875))
* yarn lock file ([e865777](https://github.com/VenusProtocol/oracle/commit/e865777276aea95e8882d783c894e1a52712bbcd))
* yarn.lock checksum ([82562dc](https://github.com/VenusProtocol/oracle/commit/82562dc182025189be963dad94dccb3de70e3b97))


### Reverts

* Revert "chore: update deployments" ([c2a702f](https://github.com/VenusProtocol/oracle/commit/c2a702f5770a989858e9cb46450ed58a284b88a9))

## [1.8.0-dev.1](https://github.com/VenusProtocol/oracle/compare/v1.7.4-dev.1...v1.8.0-dev.1) (2023-11-24)


### Features

* add addresses of deployed contracts in a single file ([50c0933](https://github.com/VenusProtocol/oracle/commit/50c0933cbf2576d1379d2e91fecadffd7f448a14))
* only commit deployment jsons during export ([aa24aa9](https://github.com/VenusProtocol/oracle/commit/aa24aa91e85e7d5d033c458625e311d9377ceb3a))
* updating deployment files ([d33ea60](https://github.com/VenusProtocol/oracle/commit/d33ea6003d4eb1762fbefe3d732bea5a24e09757))


### Bug Fixes

* fixed yarn lockfile ([05e031a](https://github.com/VenusProtocol/oracle/commit/05e031a80088ab6da55cc5f770df687fb12f5d8e))
* yarn lock ([c10c53b](https://github.com/VenusProtocol/oracle/commit/c10c53b63d0887be828c80b1c9512108fd2555ff))

## [1.7.4-dev.1](https://github.com/VenusProtocol/oracle/compare/v1.7.3...v1.7.4-dev.1) (2023-11-02)

## [1.7.3](https://github.com/VenusProtocol/oracle/compare/v1.7.2...v1.7.3) (2023-10-19)


Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Resilient Price Feeds is a set of smart contracts that uses multiple oracles and

DeFi protocols are vulnerable to incorrectly reported prices which can lead to lost money. A price oracle can be manipulated,fail, or suffer other attacks depending on the type of price oracle. It creates a single point of failure, opening attack vectors to the protocol if not mitigated.

The Resilient Price Feeds uses multiple oracle sources and fallback mechanisms to return accurate prices and protect from oracle failures. Currently, it includes integrations with Chainlink, Pyth, Binance Oracle and TWAP (Time-Weighted Average Price) oracles. TWAP uses PancakeSwap as the on-chain price source.
The Resilient Price Feeds uses multiple oracle sources and fallback mechanisms to return accurate prices and protect from oracle failures. Currently, it includes integrations with Chainlink, RedStone, Pyth, Binance Oracle and TWAP (Time-Weighted Average Price) oracles. TWAP uses PancakeSwap as the on-chain price source.

## Details

Expand All @@ -21,7 +21,7 @@ anchorRatio = anchorPrice/reporterPrice
isValid = anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio
```

The default configuration uses Chainlink as the main oracle, TWAP or Pyth oracle as pivot oracle depending on which supports the given market and Binance oracle as the fallback oracle. For some markets we may use Pyth as the main oracle if the token price is not supported by Chainlink or Binance oracles.
The default configuration uses Chainlink as the main oracle, TWAP, RedStone or Pyth oracle as the pivot oracle depending on which supports the given market and Binance oracle as the fallback oracle. For some markets we may use RedStone or Pyth as the main oracle if the token price is not supported by Chainlink or Binance oracles.

When fetching an oracle price, for the price to be valid it must be positive and not stagnant. If the price is invalid or stagnant it is ignored and a fallback oracle is used.

Expand Down Expand Up @@ -72,7 +72,7 @@ npx hardhat test
```

- To run fork tests add FORK_MAINNET=true PRIVATE_KEY and QUICK_NODE_KEY in the .env file.
- To run fork tests add FORK=true, FORKED_NETWORK and one ARCHIVE_NODE var in the .env file.

## Releases and Versioning

Expand All @@ -93,6 +93,14 @@ npx hardhat deploy
- In the deployment scripts you have added `tags` for example: - `func.tags = ["MockTokens"];`
- Once this is done, adding `--tags "<tag_name>,<tag_name>..."` to the deployment command will execute only the scripts containing the tags.

### Deployed Contracts

Contract addresses and abis are exported in the `deployments` directory. To create a summary export of all contracts deployed to a network run.

```
$ yarn hardhat export --network <network-name> --export ./deployments/<network-name>.json
```

## Verify Contracts

```
Expand Down
30 changes: 17 additions & 13 deletions contracts/ResilientOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr

uint256 public constant INVALID_PRICE = 0;

/// @notice vBNB address
/// @notice Native market address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable vBnb;
address public immutable nativeMarket;

/// @notice VAI address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable vai;

/// @notice Set this as asset address for BNB. This is the underlying for vBNB
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
/// @notice Set this as asset address for Native token on each chain.This is the underlying for vBNB (on bsc)
/// and can serve as any underlying asset of a market that supports native tokens
address public constant NATIVE_TOKEN_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;

/// @notice Bound validator contract address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
Expand Down Expand Up @@ -119,16 +120,19 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
}

/// @notice Constructor for the implementation contract. Sets immutable variables.
/// @param vBnbAddress The address of the vBNB
/// @param vaiAddress The address of the VAI
/// @dev nativeMarketAddress can be address(0) if on the chain we do not support native market
/// (e.g vETH on ethereum would not be supported, only vWETH)
/// @param nativeMarketAddress The address of a native market (for bsc it would be vBNB address)
/// @param vaiAddress The address of the VAI token (if there is VAI on the deployed chain).
/// Set to address(0) of VAI is not existent.
/// @param _boundValidator Address of the bound validator contract
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
address vBnbAddress,
address nativeMarketAddress,
address vaiAddress,
BoundValidatorInterface _boundValidator
) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) notNullAddress(address(_boundValidator)) {
vBnb = vBnbAddress;
) notNullAddress(address(_boundValidator)) {
nativeMarket = nativeMarketAddress;
vai = vaiAddress;
boundValidator = _boundValidator;

Expand Down Expand Up @@ -438,10 +442,10 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
* @param vToken vToken address
* @return asset underlying asset address
*/
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
if (address(vToken) == vBnb) {
asset = BNB_ADDR;
} else if (address(vToken) == vai) {
function _getUnderlyingAsset(address vToken) private view notNullAddress(vToken) returns (address asset) {
if (vToken == nativeMarket) {
asset = NATIVE_TOKEN_ADDR;
} else if (vToken == vai) {
asset = vai;
} else {
asset = VBep20Interface(vToken).underlying();
Expand Down
46 changes: 36 additions & 10 deletions contracts/oracles/BinanceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import "../interfaces/OracleInterface.sol";
* @notice This oracle fetches price of assets from Binance.
*/
contract BinanceOracle is AccessControlledV8, OracleInterface {
/// @notice Used to fetch feed registry address.
address public sidRegistryAddress;

/// @notice Set this as asset address for BNB. This is the underlying address for vBNB
Expand All @@ -27,10 +28,18 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
/// @notice Override symbols to be compatible with Binance feed registry
mapping(string => string) public symbols;

/// @notice Used to fetch price of assets used directly when space ID is not supported by current chain.
address public feedRegistryAddress;

/// @notice Emits when asset stale period is updated.
event MaxStalePeriodAdded(string indexed asset, uint256 maxStalePeriod);

/// @notice Emits when symbol of the asset is updated.
event SymbolOverridden(string indexed symbol, string overriddenSymbol);

/// @notice Emits when address of feed registry is updated.
event FeedRegistryUpdated(address indexed oldFeedRegistry, address indexed newFeedRegistry);

/**
* @notice Checks whether an address is null or not
*/
Expand All @@ -45,6 +54,16 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
_disableInitializers();
}

/**
* @notice Sets the contracts required to fetch prices
* @param _sidRegistryAddress Address of SID registry
* @param _accessControlManager Address of the access control manager contract
*/
function initialize(address _sidRegistryAddress, address _accessControlManager) external initializer {
sidRegistryAddress = _sidRegistryAddress;
__AccessControlled_init(_accessControlManager);
}

/**
* @notice Used to set the max stale period of an asset
* @param symbol The symbol of the asset
Expand Down Expand Up @@ -73,16 +92,15 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
}

/**
* @notice Sets the contracts required to fetch prices
* @param _sidRegistryAddress Address of SID registry
* @param _accessControlManager Address of the access control manager contract
* @notice Used to set feed registry address when current chain does not support space ID.
* @param newfeedRegistryAddress Address of new feed registry.
*/
function initialize(
address _sidRegistryAddress,
address _accessControlManager
) external initializer notNullAddress(_sidRegistryAddress) {
sidRegistryAddress = _sidRegistryAddress;
__AccessControlled_init(_accessControlManager);
function setFeedRegistryAddress(
address newfeedRegistryAddress
) external notNullAddress(newfeedRegistryAddress) onlyOwner {
if (sidRegistryAddress != address(0)) revert("sidRegistryAddress must be zero");
emit FeedRegistryUpdated(feedRegistryAddress, newfeedRegistryAddress);
feedRegistryAddress = newfeedRegistryAddress;
}

/**
Expand Down Expand Up @@ -127,7 +145,15 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
}

function _getPrice(string memory symbol, uint256 decimals) internal view returns (uint256) {
FeedRegistryInterface feedRegistry = FeedRegistryInterface(getFeedRegistryAddress());
FeedRegistryInterface feedRegistry;

if (sidRegistryAddress != address(0)) {
// If sidRegistryAddress is available, fetch feedRegistryAddress from sidRegistry
feedRegistry = FeedRegistryInterface(getFeedRegistryAddress());
} else {
// Use feedRegistry directly if sidRegistryAddress is not available
feedRegistry = FeedRegistryInterface(feedRegistryAddress);
}

(, int256 answer, , uint256 updatedAt, ) = feedRegistry.latestRoundDataByName(symbol, "USD");
if (answer <= 0) revert("invalid binance oracle price");
Expand Down
Loading

0 comments on commit 9ab976b

Please sign in to comment.