Contract Name:
DropsPriceOracleEthereum
Contract Source Code:
// SPDX-License-Identifier: UNLICENSED
/*
βββββββββββββ
β HOLOGRAPH β
βββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β / ^ \ β
β ~~*~~ ¸ β
β [ '<>:<>' ] ββββ β
β ββ _/"\_ ββ£ β
β βββ¬β¬ββ """ βββ¬β¬ββ β
β βββ¬β β β£ ββ¬ββ \_/ βββ¬β β β£ ββ¬ββ β
β βββ¬β β β β£ β ββ¬ββ βββ¬β β β β£ β ββ¬ββ β
β βββ¬β β β β β£ β β ββ¬ββ βββ¬β β β β β£ β β ββ¬ββ β
β βββ¬β β β β β β£ β β β ββ¬β ββ¬β β β β β β£ β β β ββ¬ββ β
β β¬β β β β β β β£ β β β ββ¤ββ β β β β β£ β β β β ββ¬β£
ββ β β β β β β£ β β β β β β β β β β£ β β β β ββ
β β©βββ©βββ©βββ©βββ©βββ¬β¬βββ©βββ©βββ©βββ©ββββ©βββ©βββ©βββ©βββ¬β¬βββ©βββ©βββ©βββ©βββ©β£
β β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β¬β¬β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β¬β¬β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β£
β β β£ β β£ β
β β β£ β β£ β
β , β β£ , ,' * β β£ β
β~~~~~^~~~~~~~~ββ¬β¬β~~~^~~~~~~~~^^~~~~~~~~^~~ββ¬β¬β~~~~~~~^~~~~~~β
ββββββββββββββββ©β©β©β©ββββββββββββββββββββββββββ©β©β©β©βββββββββββββββ
- one protocol, one bridge = infinite possibilities -
***************************************************************
DISCLAIMER: U.S Patent Pending
LICENSE: Holograph Limited Public License (H-LPL)
https://holograph.xyz/licenses/h-lpl/1.0.0
This license governs use of the accompanying software. If you
use the software, you accept this license. If you do not accept
the license, you are not permitted to use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and
"distribution" have the same meaning here as under U.S.
copyright law. A "contribution" is the original software, or
any additions or changes to the software. A "contributor" is
any person that distributes its contribution under this
license. "Licensed patents" are a contributorβs patent claims
that read directly on its contribution.
2. Grant of Rights
A) Copyright Grant- Subject to the terms of this license,
including the license conditions and limitations in sections 3
and 4, each contributor grants you a non-exclusive, worldwide,
royalty-free copyright license to reproduce its contribution,
prepare derivative works of its contribution, and distribute
its contribution or any derivative works that you create.
B) Patent Grant- Subject to the terms of this license,
including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide,
royalty-free license under its licensed patents to make, have
made, use, sell, offer for sale, import, and/or otherwise
dispose of its contribution in the software or derivative works
of the contribution in the software.
3. Conditions and Limitations
A) No Trademark License- This license does not grant you rights
to use any contributorsβ name, logo, or trademarks.
B) If you bring a patent claim against any contributor over
patents that you claim are infringed by the software, your
patent license from such contributor is terminated with
immediate effect.
C) If you distribute any portion of the software, you must
retain all copyright, patent, trademark, and attribution
notices that are present in the software.
D) If you distribute any portion of the software in source code
form, you may do so only under this license by including a
complete copy of this license with your distribution. If you
distribute any portion of the software in compiled or object
code form, you may only do so under a license that complies
with this license.
E) The software is licensed βas-is.β You bear all risks of
using it. The contributors give no express warranties,
guarantees, or conditions. You may have additional consumer
rights under your local laws which this license cannot change.
To the extent permitted under your local laws, the contributors
exclude all implied warranties, including those of
merchantability, fitness for a particular purpose and
non-infringement.
4. (F) Platform Limitation- The licenses granted in sections
2.A & 2.B extend only to the software or derivative works that
you create that run on a Holograph system product.
***************************************************************
*/
pragma solidity 0.8.13;
abstract contract Admin {
/**
* @dev bytes32(uint256(keccak256('eip1967.Holograph.admin')) - 1)
*/
bytes32 constant _adminSlot = 0x3f106594dc74eeef980dae234cde8324dc2497b13d27a0c59e55bd2ca10a07c9;
modifier onlyAdmin() {
require(msg.sender == getAdmin(), "HOLOGRAPH: admin only function");
_;
}
constructor() {}
function admin() public view returns (address) {
return getAdmin();
}
function getAdmin() public view returns (address adminAddress) {
assembly {
adminAddress := sload(_adminSlot)
}
}
function setAdmin(address adminAddress) public onlyAdmin {
assembly {
sstore(_adminSlot, adminAddress)
}
}
function adminCall(address target, bytes calldata data) external payable onlyAdmin {
assembly {
calldatacopy(0, data.offset, data.length)
let result := call(gas(), target, callvalue(), 0, data.length, 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
}
// SPDX-License-Identifier: UNLICENSED
/*
βββββββββββββ
β HOLOGRAPH β
βββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β / ^ \ β
β ~~*~~ ¸ β
β [ '<>:<>' ] ββββ β
β ββ _/"\_ ββ£ β
β βββ¬β¬ββ """ βββ¬β¬ββ β
β βββ¬β β β£ ββ¬ββ \_/ βββ¬β β β£ ββ¬ββ β
β βββ¬β β β β£ β ββ¬ββ βββ¬β β β β£ β ββ¬ββ β
β βββ¬β β β β β£ β β ββ¬ββ βββ¬β β β β β£ β β ββ¬ββ β
β βββ¬β β β β β β£ β β β ββ¬β ββ¬β β β β β β£ β β β ββ¬ββ β
β β¬β β β β β β β£ β β β ββ¤ββ β β β β β£ β β β β ββ¬β£
ββ β β β β β β£ β β β β β β β β β β£ β β β β ββ
β β©βββ©βββ©βββ©βββ©βββ¬β¬βββ©βββ©βββ©βββ©ββββ©βββ©βββ©βββ©βββ¬β¬βββ©βββ©βββ©βββ©βββ©β£
β β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β¬β¬β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β¬β¬β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β£
β β β£ β β£ β
β β β£ β β£ β
β , β β£ , ,' * β β£ β
β~~~~~^~~~~~~~~ββ¬β¬β~~~^~~~~~~~~^^~~~~~~~~^~~ββ¬β¬β~~~~~~~^~~~~~~β
ββββββββββββββββ©β©β©β©ββββββββββββββββββββββββββ©β©β©β©βββββββββββββββ
- one protocol, one bridge = infinite possibilities -
***************************************************************
DISCLAIMER: U.S Patent Pending
LICENSE: Holograph Limited Public License (H-LPL)
https://holograph.xyz/licenses/h-lpl/1.0.0
This license governs use of the accompanying software. If you
use the software, you accept this license. If you do not accept
the license, you are not permitted to use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and
"distribution" have the same meaning here as under U.S.
copyright law. A "contribution" is the original software, or
any additions or changes to the software. A "contributor" is
any person that distributes its contribution under this
license. "Licensed patents" are a contributorβs patent claims
that read directly on its contribution.
2. Grant of Rights
A) Copyright Grant- Subject to the terms of this license,
including the license conditions and limitations in sections 3
and 4, each contributor grants you a non-exclusive, worldwide,
royalty-free copyright license to reproduce its contribution,
prepare derivative works of its contribution, and distribute
its contribution or any derivative works that you create.
B) Patent Grant- Subject to the terms of this license,
including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide,
royalty-free license under its licensed patents to make, have
made, use, sell, offer for sale, import, and/or otherwise
dispose of its contribution in the software or derivative works
of the contribution in the software.
3. Conditions and Limitations
A) No Trademark License- This license does not grant you rights
to use any contributorsβ name, logo, or trademarks.
B) If you bring a patent claim against any contributor over
patents that you claim are infringed by the software, your
patent license from such contributor is terminated with
immediate effect.
C) If you distribute any portion of the software, you must
retain all copyright, patent, trademark, and attribution
notices that are present in the software.
D) If you distribute any portion of the software in source code
form, you may do so only under this license by including a
complete copy of this license with your distribution. If you
distribute any portion of the software in compiled or object
code form, you may only do so under a license that complies
with this license.
E) The software is licensed βas-is.β You bear all risks of
using it. The contributors give no express warranties,
guarantees, or conditions. You may have additional consumer
rights under your local laws which this license cannot change.
To the extent permitted under your local laws, the contributors
exclude all implied warranties, including those of
merchantability, fitness for a particular purpose and
non-infringement.
4. (F) Platform Limitation- The licenses granted in sections
2.A & 2.B extend only to the software or derivative works that
you create that run on a Holograph system product.
***************************************************************
*/
pragma solidity 0.8.13;
import "../interface/InitializableInterface.sol";
/**
* @title Initializable
* @author https://github.com/holographxyz
* @notice Use init instead of constructor
* @dev This allows for use of init function to make one time initializations without the need for a constructor
*/
abstract contract Initializable is InitializableInterface {
/**
* @dev bytes32(uint256(keccak256('eip1967.Holograph.initialized')) - 1)
*/
bytes32 constant _initializedSlot = 0x4e5f991bca30eca2d4643aaefa807e88f96a4a97398933d572a3c0d973004a01;
/**
* @dev Constructor is left empty and init is used instead
*/
constructor() {}
/**
* @notice Used internally to initialize the contract instead of through a constructor
* @dev This function is called by the deployer/factory when creating a contract
* @param initPayload abi encoded payload to use for contract initilaization
*/
function init(bytes memory initPayload) external virtual returns (bytes4);
function _isInitialized() internal view returns (bool initialized) {
assembly {
initialized := sload(_initializedSlot)
}
}
function _setInitialized() internal {
assembly {
sstore(_initializedSlot, 0x0000000000000000000000000000000000000000000000000000000000000001)
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IDropsPriceOracle {
function convertUsdToWei(uint256 usdAmount) external view returns (uint256 weiAmount);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {Admin} from "../../abstract/Admin.sol";
import {Initializable} from "../../abstract/Initializable.sol";
import {IDropsPriceOracle} from "../interface/IDropsPriceOracle.sol";
import {IUniswapV2Pair} from "./interface/IUniswapV2Pair.sol";
contract DropsPriceOracleEthereum is Admin, Initializable, IDropsPriceOracle {
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; // 18 decimals
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; // 6 decimals
address constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7; // 6 decimals
IUniswapV2Pair constant SushiV2UsdcPool = IUniswapV2Pair(0x397FF1542f962076d0BFE58eA045FfA2d347ACa0);
IUniswapV2Pair constant SushiV2UsdtPool = IUniswapV2Pair(0x06da0fd433C1A5d7a4faa01111c044910A184553);
IUniswapV2Pair constant UniV2UsdcPool = IUniswapV2Pair(0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc);
IUniswapV2Pair constant UniV2UsdtPool = IUniswapV2Pair(0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852);
/**
* @dev Constructor is left empty and init is used instead
*/
constructor() {}
/**
* @notice Used internally to initialize the contract instead of through a constructor
* @dev This function is called by the deployer/factory when creating a contract
*/
function init(bytes memory) external override returns (bytes4) {
require(!_isInitialized(), "HOLOGRAPH: already initialized");
assembly {
sstore(_adminSlot, origin())
}
_setInitialized();
return Initializable.init.selector;
}
/**
* @notice Convert USD value to native gas token value
* @dev It is important to note that different USD stablecoins use different decimal places.
* @param usdAmount a 6 decimal places USD amount
*/
function convertUsdToWei(uint256 usdAmount) external view returns (uint256 weiAmount) {
weiAmount =
(_getSushiUSDC(usdAmount) + _getSushiUSDT(usdAmount) + _getUniUSDC(usdAmount) + _getUniUSDT(usdAmount)) /
4;
}
function _getSushiUSDC(uint256 usdAmount) internal view returns (uint256 weiAmount) {
// add decimal places for amount IF decimals are above 6!
// usdAmount = usdAmount * (10**(18 - 6));
(uint112 _reserve0, uint112 _reserve1, ) = SushiV2UsdcPool.getReserves();
// x is always native token / WETH
uint256 x = _reserve1;
// y is always USD token / USDC
uint256 y = _reserve0;
uint256 numerator = (x * usdAmount) * 1000;
uint256 denominator = (y - usdAmount) * 997;
weiAmount = (numerator / denominator) + 1;
}
function _getSushiUSDT(uint256 usdAmount) internal view returns (uint256 weiAmount) {
// add decimal places for amount IF decimals are above 6!
// usdAmount = usdAmount * (10**(18 - 6));
(uint112 _reserve0, uint112 _reserve1, ) = SushiV2UsdtPool.getReserves();
// x is always native token / WETH
uint256 x = _reserve0;
// y is always USD token / USDT
uint256 y = _reserve1;
uint256 numerator = (x * usdAmount) * 1000;
uint256 denominator = (y - usdAmount) * 997;
weiAmount = (numerator / denominator) + 1;
}
function _getUniUSDC(uint256 usdAmount) internal view returns (uint256 weiAmount) {
// add decimal places for amount IF decimals are above 6!
// usdAmount = usdAmount * (10**(18 - 6));
(uint112 _reserve0, uint112 _reserve1, ) = UniV2UsdcPool.getReserves();
// x is always native token / WETH
uint256 x = _reserve1;
// y is always USD token / USDC
uint256 y = _reserve0;
uint256 numerator = (x * usdAmount) * 1000;
uint256 denominator = (y - usdAmount) * 997;
weiAmount = (numerator / denominator) + 1;
}
function _getUniUSDT(uint256 usdAmount) internal view returns (uint256 weiAmount) {
// add decimal places for amount IF decimals are above 6!
// usdAmount = usdAmount * (10**(18 - 6));
(uint112 _reserve0, uint112 _reserve1, ) = UniV2UsdtPool.getReserves();
// x is always native token / WETH
uint256 x = _reserve0;
// y is always USD token / USDT
uint256 y = _reserve1;
uint256 numerator = (x * usdAmount) * 1000;
uint256 denominator = (y - usdAmount) * 997;
weiAmount = (numerator / denominator) + 1;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint256);
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Mint(address indexed sender, uint256 amount0, uint256 amount1);
event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);
event Swap(
address indexed sender,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint256);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);
function mint(address to) external returns (uint256 liquidity);
function burn(address to) external returns (uint256 amount0, uint256 amount1);
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
// SPDX-License-Identifier: UNLICENSED
/*
βββββββββββββ
β HOLOGRAPH β
βββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β / ^ \ β
β ~~*~~ ¸ β
β [ '<>:<>' ] ββββ β
β ββ _/"\_ ββ£ β
β βββ¬β¬ββ """ βββ¬β¬ββ β
β βββ¬β β β£ ββ¬ββ \_/ βββ¬β β β£ ββ¬ββ β
β βββ¬β β β β£ β ββ¬ββ βββ¬β β β β£ β ββ¬ββ β
β βββ¬β β β β β£ β β ββ¬ββ βββ¬β β β β β£ β β ββ¬ββ β
β βββ¬β β β β β β£ β β β ββ¬β ββ¬β β β β β β£ β β β ββ¬ββ β
β β¬β β β β β β β£ β β β ββ¤ββ β β β β β£ β β β β ββ¬β£
ββ β β β β β β£ β β β β β β β β β β£ β β β β ββ
β β©βββ©βββ©βββ©βββ©βββ¬β¬βββ©βββ©βββ©βββ©ββββ©βββ©βββ©βββ©βββ¬β¬βββ©βββ©βββ©βββ©βββ©β£
β β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β¬β¬β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β¬β¬β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β΄β£
β β β£ β β£ β
β β β£ β β£ β
β , β β£ , ,' * β β£ β
β~~~~~^~~~~~~~~ββ¬β¬β~~~^~~~~~~~~^^~~~~~~~~^~~ββ¬β¬β~~~~~~~^~~~~~~β
ββββββββββββββββ©β©β©β©ββββββββββββββββββββββββββ©β©β©β©βββββββββββββββ
- one protocol, one bridge = infinite possibilities -
***************************************************************
DISCLAIMER: U.S Patent Pending
LICENSE: Holograph Limited Public License (H-LPL)
https://holograph.xyz/licenses/h-lpl/1.0.0
This license governs use of the accompanying software. If you
use the software, you accept this license. If you do not accept
the license, you are not permitted to use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and
"distribution" have the same meaning here as under U.S.
copyright law. A "contribution" is the original software, or
any additions or changes to the software. A "contributor" is
any person that distributes its contribution under this
license. "Licensed patents" are a contributorβs patent claims
that read directly on its contribution.
2. Grant of Rights
A) Copyright Grant- Subject to the terms of this license,
including the license conditions and limitations in sections 3
and 4, each contributor grants you a non-exclusive, worldwide,
royalty-free copyright license to reproduce its contribution,
prepare derivative works of its contribution, and distribute
its contribution or any derivative works that you create.
B) Patent Grant- Subject to the terms of this license,
including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide,
royalty-free license under its licensed patents to make, have
made, use, sell, offer for sale, import, and/or otherwise
dispose of its contribution in the software or derivative works
of the contribution in the software.
3. Conditions and Limitations
A) No Trademark License- This license does not grant you rights
to use any contributorsβ name, logo, or trademarks.
B) If you bring a patent claim against any contributor over
patents that you claim are infringed by the software, your
patent license from such contributor is terminated with
immediate effect.
C) If you distribute any portion of the software, you must
retain all copyright, patent, trademark, and attribution
notices that are present in the software.
D) If you distribute any portion of the software in source code
form, you may do so only under this license by including a
complete copy of this license with your distribution. If you
distribute any portion of the software in compiled or object
code form, you may only do so under a license that complies
with this license.
E) The software is licensed βas-is.β You bear all risks of
using it. The contributors give no express warranties,
guarantees, or conditions. You may have additional consumer
rights under your local laws which this license cannot change.
To the extent permitted under your local laws, the contributors
exclude all implied warranties, including those of
merchantability, fitness for a particular purpose and
non-infringement.
4. (F) Platform Limitation- The licenses granted in sections
2.A & 2.B extend only to the software or derivative works that
you create that run on a Holograph system product.
***************************************************************
*/
pragma solidity 0.8.13;
/**
* @title Initializable
* @author https://github.com/holographxyz
* @notice Use init instead of constructor
* @dev This allows for use of init function to make one time initializations without the need of a constructor
*/
interface InitializableInterface {
/**
* @notice Used internally to initialize the contract instead of through a constructor
* @dev This function is called by the deployer/factory when creating a contract
* @param initPayload abi encoded payload to use for contract initilaization
*/
function init(bytes memory initPayload) external returns (bytes4);
}