Verified contractExactMIT
OracleCryptoSwap
Address0x4f00afa47a6487bf4540e442d6e71e0ae6f1b0f3
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.28
- Same code
Only this 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,385,730
- Creation transaction
- 0xdb8cc509f0…dbc1f5fa6a
7 files
- src/USG/Oracles/CurveLP/OracleCryptoSwap.solmain1.57 KB
- lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol216 B
- 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/Curve/ICurveTriCryptoSwap.sol6.79 KB
- src/interfaces/internals/USG/IPriceOracle.sol299 B
src/USG/Oracles/CurveLP/OracleCryptoSwap.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IPriceOracle} from "../../../interfaces/internals/USG/IPriceOracle.sol";
import {ICurveTriCryptoSwap} from "../../../interfaces/externals/Curve/ICurveTriCryptoSwap.sol";
import {OracleBase} from "../OracleBase.sol";
/// @title OracleCryptoSwap
/// @author Tangent Finance
/// @notice This contract provides price oracle functionality for a cryptoswap pool of Curve Finance.
contract OracleCryptoSwap is OracleBase {
struct OracleCryptoSwapStruct {
address lp;
IPriceOracle coin0Oracle;
uint96 coin0OracleDecimals;
}
OracleCryptoSwapStruct public params;
constructor(address _lp, IPriceOracle coin0Oracle, string memory _oracleName) OracleBase(_oracleName) {
params = OracleCryptoSwapStruct({lp: _lp, coin0Oracle: coin0Oracle, coin0OracleDecimals: uint96(coin0Oracle.decimals())});
}
function latestAnswer(bool isNoFailMode) external view override returns (uint256) {
OracleCryptoSwapStruct memory _params = params;
return _computePrice(_params.lp, _params.coin0Oracle.latestAnswer(isNoFailMode));
}
function latestAnswerUpdate(bool isNoFailMode) external override returns (uint256) {
OracleCryptoSwapStruct memory _params = params;
return _computePrice(_params.lp, _params.coin0Oracle.latestAnswerUpdate(isNoFailMode));
}
function _computePrice(address lp, uint256 coin0Price) internal view returns (uint256) {
return (ICurveTriCryptoSwap(lp).lp_price() * coin0Price) / 1e18;
}
}
lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
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/Curve/ICurveTriCryptoSwap.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
interface ICurveTriCryptoSwap is IERC20Metadata {
function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external returns (uint256);
function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy, bool use_eth) external returns (uint256);
function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy, bool use_eth, address receiver) external returns (uint256);
function exchange_underlying(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external returns (uint256);
function exchange_underlying(uint256 i, uint256 j, uint256 dx, uint256 min_dy, address receiver) external returns (uint256);
function exchange_extended(uint256 i, uint256 j, uint256 dx, uint256 min_dy, bool use_eth, address sender, address receiver, bytes32 cb) external returns (uint256);
function add_liquidity(uint256[3] calldata amounts, uint256 min_mint_amount) external returns (uint256);
function add_liquidity(uint256[3] calldata amounts, uint256 min_mint_amount, bool use_eth) external returns (uint256);
function add_liquidity(uint256[3] calldata amounts, uint256 min_mint_amount, bool use_eth, address receiver) external returns (uint256);
function remove_liquidity(uint256 _amount, uint256[3] calldata min_amounts) external returns (uint256[3] calldata);
function remove_liquidity(uint256 _amount, uint256[3] calldata min_amounts, bool use_eth) external returns (uint256[3] calldata);
function remove_liquidity(uint256 _amount, uint256[3] calldata min_amounts, bool use_eth, address receiver) external returns (uint256[3] calldata);
function remove_liquidity(uint256 _amount, uint256[3] calldata min_amounts, bool use_eth, address receiver, bool claim_admin_fees) external returns (uint256[3] calldata);
function remove_liquidity_one_coin(uint256 token_amount, uint256 i, uint256 min_amount) external returns (uint256);
function remove_liquidity_one_coin(uint256 token_amount, uint256 i, uint256 min_amount, bool use_eth) external returns (uint256);
function remove_liquidity_one_coin(uint256 token_amount, uint256 i, uint256 min_amount, bool use_eth, address receiver) external returns (uint256);
function claim_admin_fees() external;
function transferFrom(address _from, address _to, uint256 _value) external returns (bool);
function transfer(address _to, uint256 _value) external returns (bool);
function approve(address _spender, uint256 _value) external returns (bool);
function increaseAllowance(address _spender, uint256 _add_value) external returns (bool);
function decreaseAllowance(address _spender, uint256 _sub_value) external returns (bool);
function permit(address _owner, address _spender, uint256 _value, uint256 _deadline, uint8 _v, bytes32 _r, bytes32 _s) external returns (bool);
function fee_receiver() external view returns (address);
function calc_token_amount(uint256[3] calldata amounts, bool deposit) external view returns (uint256);
function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256);
function get_dx(uint256 i, uint256 j, uint256 dy) external view returns (uint256);
function lp_price() external view returns (uint256);
function get_virtual_price() external view returns (uint256);
function price_oracle() external view returns (uint256);
function price_oracle(uint256 k) external view returns (uint256);
function last_prices(uint256 k) external view returns (uint256);
function price_scale(uint256 k) external view returns (uint256);
function fee() external view returns (uint256);
function calc_withdraw_one_coin(uint256 token_amount, uint256 i) external view returns (uint256);
function calc_token_fee(uint256[3] calldata amounts, uint256[3] calldata xp) external view returns (uint256);
function A() external view returns (uint256);
function gamma() external view returns (uint256);
function mid_fee() external view returns (uint256);
function out_fee() external view returns (uint256);
function fee_gamma() external view returns (uint256);
function allowed_extra_profit() external view returns (uint256);
function adjustment_step() external view returns (uint256);
function ma_time() external view returns (uint256);
function precisions() external view returns (uint256[3] calldata);
function fee_calc(uint256[3] calldata xp) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function ramp_A_gamma(uint256 future_A, uint256 future_gamma, uint256 future_time) external;
function stop_ramp_A_gamma() external;
function commit_new_parameters(
uint256 _new_mid_fee,
uint256 _new_out_fee,
uint256 _new_fee_gamma,
uint256 _new_allowed_extra_profit,
uint256 _new_adjustment_step,
uint256 _new_ma_time
) external;
function apply_new_parameters() external;
function revert_new_parameters() external;
function WETH20() external view returns (address);
function MATH() external view returns (address);
function coins(uint256 arg0) external view returns (address);
function factory() external view returns (address);
function last_prices_timestamp() external view returns (uint256);
function initial_A_gamma() external view returns (uint256);
function initial_A_gamma_time() external view returns (uint256);
function future_A_gamma() external view returns (uint256);
function future_A_gamma_time() external view returns (uint256);
function balances(uint256 arg0) external view returns (uint256);
function D() external view returns (uint256);
function xcp_profit() external view returns (uint256);
function xcp_profit_a() external view returns (uint256);
function virtual_price() external view returns (uint256);
function packed_rebalancing_params() external view returns (uint256);
function packed_fee_params() external view returns (uint256);
function ADMIN_FEE() external view returns (uint256);
function admin_actions_deadline() 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 totalSupply() 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.