Verified contractExactMIT
OracleDuoPoolStable
Address0xc0bf3bae48f9258bbf4a32d3c60b0de345a45595
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.28
- Same code
1 more contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- No
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,283,935
- Creation transaction
- 0x556fb68839…ffca1f2343
7 files
- src/USG/Oracles/CurveLP/OracleDuoPoolStable.solmain3.09 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- src/USG/Oracles/OracleBase.sol469 B
- src/interfaces/externals/Chainlink/IAggregatorV3.sol697 B
- src/interfaces/externals/Curve/ICurveStableSwapNG.sol5.57 KB
- src/interfaces/internals/USG/IPriceOracle.sol299 B
src/USG/Oracles/CurveLP/OracleDuoPoolStable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../../../interfaces/internals/USG/IPriceOracle.sol";
import "../../../interfaces/externals/Curve/ICurveStableSwapNG.sol";
import "../../../interfaces/externals/Chainlink/IAggregatorV3.sol";
import {OracleBase} from "../OracleBase.sol";
/// @title OracleDuoPoolStable
/// @author Tangent Finance
/// @notice This contract provides price oracle functionality for a dual pool stablePool of Curve Finance.
contract OracleDuoPoolStable is OracleBase {
/// @notice Struct to store oracle parameters
struct OracleDuoPoolStruct {
/// @dev Oracle for the first coin
IPriceOracle coin0Oracle;
/// @dev Decimals for the first coin's oracle
uint96 coin0OracleDecimals;
/// @dev Oracle for the second coin
IPriceOracle coin1Oracle;
/// @dev Decimals for the second coin's oracle
uint96 coin1OracleDecimals;
/// @dev Curve stable swap pool
ICurveStableSwapNG lp;
}
/// @notice Public variable to store oracle parameters
OracleDuoPoolStruct public params;
/**
* @notice Constructor to initialize the OracleDuoPoolStable contract
* @param _lp Address of the Curve stable swap pool
* @param _coin0Oracle Address of the oracle for the first coin
* @param _coin1Oracle Address of the oracle for the second coin
*/
constructor(address _lp, IPriceOracle _coin0Oracle, IPriceOracle _coin1Oracle, string memory _oracleName) OracleBase(_oracleName) {
params = OracleDuoPoolStruct({
coin0Oracle: _coin0Oracle,
coin1Oracle: _coin1Oracle,
lp: ICurveStableSwapNG(_lp),
coin0OracleDecimals: uint96(_coin0Oracle.decimals()),
coin1OracleDecimals: uint96(_coin1Oracle.decimals())
});
}
/**
* @notice Returns the latest price from the oracle
* @return The price of the stable pool, adjusted to 18 decimals
*/
function latestAnswer(bool isNoFailMode) external view override returns (uint256) {
OracleDuoPoolStruct memory _params = params;
return _computePrice(_params.lp, _params.coin0Oracle.latestAnswer(isNoFailMode), _params.coin1Oracle.latestAnswer(isNoFailMode));
}
function latestAnswerUpdate(bool isNoFailMode) external override returns (uint256) {
OracleDuoPoolStruct memory _params = params;
return _computePrice(_params.lp, _params.coin0Oracle.latestAnswerUpdate(isNoFailMode), _params.coin1Oracle.latestAnswerUpdate(isNoFailMode));
}
function _computePrice(ICurveStableSwapNG lp, uint256 coin0Price, uint256 coin1Price) internal view returns (uint256) {
return (lp.get_virtual_price() * min(coin0Price, coin1Price)) / 10 ** 18;
}
/// @dev Internal function to get the minimum of two numbers
function min(uint256 a, uint256 b) internal pure returns (uint256) {
if (a > b) {
return b;
}
return a;
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
src/USG/Oracles/OracleBase.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IPriceOracle} from "../../interfaces/internals/USG/IPriceOracle.sol";
abstract contract OracleBase is IPriceOracle {
string public oracleName;
constructor(string memory _oracleName) {
oracleName = _oracleName;
}
function decimals() external pure returns (uint8) {
return 18;
}
function latestAnswer(bool isNoFailMode) external view virtual returns (uint256);
}
src/interfaces/externals/Chainlink/IAggregatorV3.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IAggregatorV3 {
function latestAnswer() external view returns (uint256);
function latestRound() external view returns (uint80);
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
src/interfaces/externals/Curve/ICurveStableSwapNG.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface ICurveStableSwapNG is IERC20Metadata {
function exchange(int128 i, int128 j, uint256 _dx, uint256 _min_dy) external returns (uint256);
function exchange(int128 i, int128 j, uint256 _dx, uint256 _min_dy, address _receiver) external returns (uint256);
function exchange_received(int128 i, int128 j, uint256 _dx, uint256 _min_dy) external returns (uint256);
function exchange_received(int128 i, int128 j, uint256 _dx, uint256 _min_dy, address _receiver) external returns (uint256);
function add_liquidity(uint256[] memory _amounts, uint256 _min_mint_amount) external returns (uint256);
function add_liquidity(uint256[2] memory _amounts, uint256 _min_mint_amount) external returns (uint256);
function add_liquidity(uint256[] memory _amounts, uint256 _min_mint_amount, address _receiver) external returns (uint256);
function remove_liquidity_one_coin(uint256 _burn_amount, int128 i, uint256 _min_received) external returns (uint256);
function remove_liquidity_one_coin(uint256 _burn_amount, int128 i, uint256 _min_received, address _receiver) external returns (uint256);
function remove_liquidity_imbalance(uint256[] memory _amounts, uint256 _max_burn_amount) external returns (uint256);
function remove_liquidity_imbalance(uint256[] memory _amounts, uint256 _max_burn_amount, address _receiver) external returns (uint256);
function remove_liquidity(uint256 _burn_amount, uint256[] memory _min_amounts) external returns (uint256[] memory);
function remove_liquidity(uint256 _burn_amount, uint256[2] memory _min_amounts) external returns (uint256[2] memory);
function remove_liquidity(uint256 _burn_amount, uint256[2] memory _min_amounts, address _receiver) external returns (uint256[2] memory);
function remove_liquidity(uint256 _burn_amount, uint256[2] memory _min_amounts, address _receiver, bool _claim_admin_fees) external returns (uint256[2] memory);
function withdraw_admin_fees() external;
function last_price() external view returns (uint256);
function last_price(uint256 i) external view returns (uint256);
function ema_price(uint256 i) external view returns (uint256);
function get_p(uint256 i) external view returns (uint256);
function get_p() external view returns (uint256);
function price_oracle() external view returns (uint256);
function price_oracle(uint256 i) external view returns (uint256);
function D_oracle() external view returns (uint256);
function transfer(address _to, uint256 _value) external returns (bool);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool);
function approve(address _spender, uint256 _value) external returns (bool);
function permit(address _owner, address _spender, uint256 _value, uint256 _deadline, uint8 _v, bytes32 _r, bytes32 _s) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function get_dx(int128 i, int128 j, uint256 dy) external view returns (uint256);
function get_dy(int128 i, int128 j, uint256 dx) external view returns (uint256);
function calc_withdraw_one_coin(uint256 _burn_amount, int128 i) external view returns (uint256);
function totalSupply() external view returns (uint256);
function get_virtual_price() external view returns (uint256);
function calc_token_amount(uint256[] memory _amounts, bool _is_deposit) external view returns (uint256);
function A() external view returns (uint256);
function A_precise() external view returns (uint256);
function balances(uint256 i) external view returns (uint256);
function get_balances() external view returns (uint256[] memory);
function stored_rates() external view returns (uint256[] memory);
function dynamic_fee(int128 i, int128 j) external view returns (uint256);
function ramp_A(uint256 _future_A, uint256 _future_time) external;
function stop_ramp_A() external;
function set_new_fee(uint256 _new_fee, uint256 _new_offpeg_fee_multiplier) external;
function set_ma_exp_time(uint256 _ma_exp_time, uint256 _D_ma_time) external;
function N_COINS() external view returns (uint256);
function coins(uint256 arg0) external view returns (address);
function fee() external view returns (uint256);
function offpeg_fee_multiplier() external view returns (uint256);
function admin_fee() external view returns (uint256);
function initial_A() external view returns (uint256);
function future_A() external view returns (uint256);
function initial_A_time() external view returns (uint256);
function future_A_time() external view returns (uint256);
function admin_balances(uint256 arg0) external view returns (uint256);
function ma_exp_time() external view returns (uint256);
function D_ma_time() external view returns (uint256);
function ma_last_time() external view returns (uint256);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function version() external view returns (string memory);
function balanceOf(address arg0) external view returns (uint256);
function allowance(address arg0, address arg1) external view returns (uint256);
function nonces(address arg0) external view returns (uint256);
function salt() external view returns (bytes32);
}
src/interfaces/internals/USG/IPriceOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IPriceOracle {
function latestAnswer(bool isNoFailMode) external view returns (uint256);
function latestAnswerUpdate(bool isNoFailMode) external returns (uint256);
function decimals() external view returns (uint8);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@contracts/=contracts/",
"@tests/=tests/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"@openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"@safe/=lib/safe-smart-account/contracts/",
"forge-std/=lib/forge-std/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
"openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"safe-smart-account/=lib/safe-smart-account/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.