Skip to content

Commit

Permalink
Merge pull request #165 from VenusProtocol/feat/derivative-prices
Browse files Browse the repository at this point in the history
  • Loading branch information
web3rover authored Apr 15, 2024
2 parents 8a2d6ee + 5cd5297 commit 84750a8
Show file tree
Hide file tree
Showing 60 changed files with 5,697 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"arrowParens": avoid,
"bracketSpacing": true,
"endOfLine": "auto",
"endOfLine": "lf",
"importOrder": ["module-alias/register", "<THIRD_PARTY_MODULES>", "^[./]"],
"importOrderParserPlugins": ["typescript"],
"importOrderSeparation": true,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions contracts/interfaces/IAnkrBNB.sol
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);
}
6 changes: 6 additions & 0 deletions contracts/interfaces/IEtherFiLiquidityPool.sol
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);
}
14 changes: 14 additions & 0 deletions contracts/interfaces/IPStakePool.sol
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);
}
13 changes: 13 additions & 0 deletions contracts/interfaces/IPendlePtOracle.sol
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);
}
7 changes: 7 additions & 0 deletions contracts/interfaces/ISFrax.sol
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);
}
7 changes: 7 additions & 0 deletions contracts/interfaces/ISfrxETH.sol
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);
}
1 change: 1 addition & 0 deletions contracts/interfaces/IStETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pragma solidity ^0.8.25;

interface IStETH {
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);
function decimals() external view returns (uint8);
}
6 changes: 6 additions & 0 deletions contracts/interfaces/IStaderStakeManager.sol
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);
}
6 changes: 6 additions & 0 deletions contracts/interfaces/ISynclubStakeManager.sol
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);
}
7 changes: 7 additions & 0 deletions contracts/interfaces/IWBETH.sol
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);
}
31 changes: 31 additions & 0 deletions contracts/oracles/AnkrBNBOracle.sol
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);
}
}
40 changes: 40 additions & 0 deletions contracts/oracles/BNBxOracle.sol
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);
}
}
43 changes: 43 additions & 0 deletions contracts/oracles/OneJumpOracle.sol
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));
}
}
63 changes: 63 additions & 0 deletions contracts/oracles/PendleOracle.sol
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);
}
}
29 changes: 29 additions & 0 deletions contracts/oracles/SFraxOracle.sol
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);
}
}
29 changes: 29 additions & 0 deletions contracts/oracles/SFrxETHOracle.sol
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);
}
}
40 changes: 40 additions & 0 deletions contracts/oracles/SlisBNBOracle.sol
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);
}
}
Loading

0 comments on commit 84750a8

Please sign in to comment.