generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from VenusProtocol/feat/derivative-prices
- Loading branch information
Showing
60 changed files
with
5,697 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface IAnkrBNB { | ||
function sharesToBonds(uint256 amount) external view returns (uint256); | ||
function decimals() external view returns (uint8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface IEtherFiLiquidityPool { | ||
function amountForShare(uint256 _share) external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface IPStakePool { | ||
struct Data { | ||
uint256 totalWei; | ||
uint256 poolTokenSupply; | ||
} | ||
|
||
/** | ||
* @dev The current exchange rate for converting stkBNB to BNB. | ||
*/ | ||
function exchangeRate() external view returns (Data memory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface IPendlePtOracle { | ||
function getPtToAssetRate(address market, uint32 duration) external view returns (uint256); | ||
function getOracleState( | ||
address market, | ||
uint32 duration | ||
) | ||
external | ||
view | ||
returns (bool increaseCardinalityRequired, uint16 cardinalityRequired, bool oldestObservationSatisfied); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface ISFrax { | ||
function convertToAssets(uint256 shares) external view returns (uint256); | ||
function decimals() external view returns (uint8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface ISfrxETH { | ||
function convertToAssets(uint256 shares) external view returns (uint256); | ||
function decimals() external view returns (uint8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface IStaderStakeManager { | ||
function convertBnbXToBnb(uint256 _amount) external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface ISynclubStakeManager { | ||
function convertSnBnbToBnb(uint256 _amount) external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
interface IWBETH { | ||
function exchangeRate() external view returns (uint256); | ||
function decimals() external view returns (uint8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
import { IAnkrBNB } from "../interfaces/IAnkrBNB.sol"; | ||
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; | ||
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol"; | ||
|
||
/** | ||
* @title AnkrBNBOracle | ||
* @author Venus | ||
* @notice This oracle fetches the price of ankrBNB asset | ||
*/ | ||
contract AnkrBNBOracle is CorrelatedTokenOracle { | ||
/// @notice This is used as token address of BNB on BSC | ||
address public constant NATIVE_TOKEN_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB; | ||
|
||
/// @notice Constructor for the implementation contract. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address ankrBNB, | ||
address resilientOracle | ||
) CorrelatedTokenOracle(ankrBNB, NATIVE_TOKEN_ADDR, resilientOracle) {} | ||
|
||
/** | ||
* @notice Fetches the amount of BNB for 1 ankrBNB | ||
* @return amount The amount of BNB for ankrBNB | ||
*/ | ||
function _getUnderlyingAmount() internal view override returns (uint256) { | ||
return IAnkrBNB(CORRELATED_TOKEN).sharesToBonds(EXP_SCALE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
import { IStaderStakeManager } from "../interfaces/IStaderStakeManager.sol"; | ||
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol"; | ||
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol"; | ||
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; | ||
|
||
/** | ||
* @title BNBxOracle | ||
* @author Venus | ||
* @notice This oracle fetches the price of BNBx asset | ||
*/ | ||
contract BNBxOracle is CorrelatedTokenOracle { | ||
/// @notice This is used as token address of BNB on BSC | ||
address public constant NATIVE_TOKEN_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB; | ||
|
||
/// @notice Address of StakeManager | ||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
IStaderStakeManager public immutable STAKE_MANAGER; | ||
|
||
/// @notice Constructor for the implementation contract. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address stakeManager, | ||
address bnbx, | ||
address resilientOracle | ||
) CorrelatedTokenOracle(bnbx, NATIVE_TOKEN_ADDR, resilientOracle) { | ||
ensureNonzeroAddress(stakeManager); | ||
STAKE_MANAGER = IStaderStakeManager(stakeManager); | ||
} | ||
|
||
/** | ||
* @notice Fetches the amount of BNB for 1 BNBx | ||
* @return price The amount of BNB for BNBx | ||
*/ | ||
function _getUnderlyingAmount() internal view override returns (uint256) { | ||
return STAKE_MANAGER.convertBnbXToBnb(EXP_SCALE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; | ||
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol"; | ||
import { OracleInterface } from "../interfaces/OracleInterface.sol"; | ||
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
|
||
/** | ||
* @title OneJumpOracle | ||
* @author Venus | ||
* @notice This oracle fetches the price of an asset in through an intermediate asset | ||
*/ | ||
contract OneJumpOracle is CorrelatedTokenOracle { | ||
/// @notice Address of the intermediate oracle | ||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
OracleInterface public immutable INTERMEDIATE_ORACLE; | ||
|
||
/// @notice Constructor for the implementation contract. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address correlatedToken, | ||
address underlyingToken, | ||
address resilientOracle, | ||
address intermediateOracle | ||
) CorrelatedTokenOracle(correlatedToken, underlyingToken, resilientOracle) { | ||
ensureNonzeroAddress(intermediateOracle); | ||
INTERMEDIATE_ORACLE = OracleInterface(intermediateOracle); | ||
} | ||
|
||
/** | ||
* @notice Fetches the amount of the underlying token for 1 correlated token, using the intermediate oracle | ||
* @return amount The amount of the underlying token for 1 correlated token scaled by the underlying token decimals | ||
*/ | ||
function _getUnderlyingAmount() internal view override returns (uint256) { | ||
uint256 underlyingDecimals = IERC20Metadata(UNDERLYING_TOKEN).decimals(); | ||
uint256 correlatedDecimals = IERC20Metadata(CORRELATED_TOKEN).decimals(); | ||
|
||
uint256 underlyingAmount = INTERMEDIATE_ORACLE.getPrice(CORRELATED_TOKEN); | ||
|
||
return (underlyingAmount * (10 ** correlatedDecimals)) / (10 ** (36 - underlyingDecimals)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
import { IPendlePtOracle } from "../interfaces/IPendlePtOracle.sol"; | ||
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; | ||
import { ensureNonzeroAddress, ensureNonzeroValue } from "@venusprotocol/solidity-utilities/contracts/validators.sol"; | ||
|
||
/** | ||
* @title PendleOracle | ||
* @author Venus | ||
* @notice This oracle fetches the price of a pendle token | ||
*/ | ||
contract PendleOracle is CorrelatedTokenOracle { | ||
/// @notice Address of the PT oracle | ||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
IPendlePtOracle public immutable PT_ORACLE; | ||
|
||
/// @notice Address of the market | ||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
address public immutable MARKET; | ||
|
||
/// @notice Twap duration for the oracle | ||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
uint32 public immutable TWAP_DURATION; | ||
|
||
/// @notice Thrown if the duration is invalid | ||
error InvalidDuration(); | ||
|
||
/// @notice Constructor for the implementation contract. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address market, | ||
address ptOracle, | ||
address ptToken, | ||
address underlyingToken, | ||
address resilientOracle, | ||
uint32 twapDuration | ||
) CorrelatedTokenOracle(ptToken, underlyingToken, resilientOracle) { | ||
ensureNonzeroAddress(market); | ||
ensureNonzeroAddress(ptOracle); | ||
ensureNonzeroValue(twapDuration); | ||
|
||
MARKET = market; | ||
PT_ORACLE = IPendlePtOracle(ptOracle); | ||
TWAP_DURATION = twapDuration; | ||
|
||
(bool increaseCardinalityRequired, , bool oldestObservationSatisfied) = PT_ORACLE.getOracleState( | ||
MARKET, | ||
TWAP_DURATION | ||
); | ||
if (increaseCardinalityRequired || !oldestObservationSatisfied) { | ||
revert InvalidDuration(); | ||
} | ||
} | ||
|
||
/** | ||
* @notice Fetches the amount of underlying token for 1 pendle token | ||
* @return amount The amount of underlying token for pendle token | ||
*/ | ||
function _getUnderlyingAmount() internal view override returns (uint256) { | ||
return PT_ORACLE.getPtToAssetRate(MARKET, TWAP_DURATION); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
import { ISFrax } from "../interfaces/ISFrax.sol"; | ||
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; | ||
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol"; | ||
|
||
/** | ||
* @title SFraxOracle | ||
* @author Venus | ||
* @notice This oracle fetches the price of sFrax | ||
*/ | ||
contract SFraxOracle is CorrelatedTokenOracle { | ||
/// @notice Constructor for the implementation contract. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address sFrax, | ||
address frax, | ||
address resilientOracle | ||
) CorrelatedTokenOracle(sFrax, frax, resilientOracle) {} | ||
|
||
/** | ||
* @notice Fetches the amount of FRAX for 1 sFrax | ||
* @return amount The amount of FRAX for sFrax | ||
*/ | ||
function _getUnderlyingAmount() internal view override returns (uint256) { | ||
return ISFrax(CORRELATED_TOKEN).convertToAssets(EXP_SCALE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
import { ISfrxETH } from "../interfaces/ISfrxETH.sol"; | ||
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; | ||
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol"; | ||
|
||
/** | ||
* @title SFrxETHOracle | ||
* @author Venus | ||
* @notice This oracle fetches the price of sfrxETH | ||
*/ | ||
contract SFrxETHOracle is CorrelatedTokenOracle { | ||
/// @notice Constructor for the implementation contract. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address sfrxETH, | ||
address frxETH, | ||
address resilientOracle | ||
) CorrelatedTokenOracle(sfrxETH, frxETH, resilientOracle) {} | ||
|
||
/** | ||
* @notice Gets the frxETH for 1 sfrxETH | ||
* @return amount Amount of frxETH | ||
*/ | ||
function _getUnderlyingAmount() internal view override returns (uint256) { | ||
return ISfrxETH(CORRELATED_TOKEN).convertToAssets(EXP_SCALE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
pragma solidity 0.8.25; | ||
|
||
import { ISynclubStakeManager } from "../interfaces/ISynclubStakeManager.sol"; | ||
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol"; | ||
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol"; | ||
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol"; | ||
|
||
/** | ||
* @title SlisBNBOracle | ||
* @author Venus | ||
* @notice This oracle fetches the price of slisBNB asset | ||
*/ | ||
contract SlisBNBOracle is CorrelatedTokenOracle { | ||
/// @notice This is used as token address of BNB on BSC | ||
address public constant NATIVE_TOKEN_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB; | ||
|
||
/// @notice Address of StakeManager | ||
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable | ||
ISynclubStakeManager public immutable STAKE_MANAGER; | ||
|
||
/// @notice Constructor for the implementation contract. | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
address stakeManager, | ||
address slisBNB, | ||
address resilientOracle | ||
) CorrelatedTokenOracle(slisBNB, NATIVE_TOKEN_ADDR, resilientOracle) { | ||
ensureNonzeroAddress(stakeManager); | ||
STAKE_MANAGER = ISynclubStakeManager(stakeManager); | ||
} | ||
|
||
/** | ||
* @notice Fetches the amount of BNB for 1 slisBNB | ||
* @return amount The amount of BNB for slisBNB | ||
*/ | ||
function _getUnderlyingAmount() internal view override returns (uint256) { | ||
return STAKE_MANAGER.convertSnBnbToBnb(EXP_SCALE); | ||
} | ||
} |
Oops, something went wrong.