Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Myso oracle #605

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8d2b348
package-lock update
jpick713 Sep 5, 2023
2c0605a
Merge branch 'main' of github.com:mysofinance/v2 into main
jpick713 Oct 17, 2023
12d1e9f
Merge branch 'main' of github.com:mysofinance/v2 into main
jpick713 Feb 13, 2024
272a65b
added in myso oracle contracts
jpick713 Mar 18, 2024
4ab992e
added updates to myso oracle
jpick713 Mar 18, 2024
94642b5
add tests, finish contract, and update readme
jpick713 Mar 18, 2024
9f71301
added meth, rpl, and usdc plus test
jpick713 Mar 20, 2024
56e4457
added usdt and dai to test
jpick713 Mar 21, 2024
8f5e125
removed comments, shortened update time, updated tests, condensed con…
jpick713 Mar 21, 2024
e7d218f
remove unused variable commented out
jpick713 Mar 22, 2024
9e84949
added ankrEth to oracle
jpick713 Mar 27, 2024
f22af37
added start of math calculation in test token manager
jpick713 Mar 29, 2024
7ced3d9
refactored to use total loan value and have calcs in oracle
jpick713 Mar 29, 2024
6e3044d
added some constants to test token manager
jpick713 Mar 30, 2024
f0caf0c
added setter for IOO vault and included into borrow check
jpick713 Mar 31, 2024
059a41e
added a test net myso oracle in
jpick713 Apr 8, 2024
b29d0c3
fixed test for oracle with new curve
jpick713 Apr 9, 2024
d270927
myt token manager
asardon Apr 9, 2024
48a513a
added borrows and examined price along curve
jpick713 Apr 9, 2024
d109488
Merge branch 'myso-oracle' into myt-token-manager
jpick713 Apr 10, 2024
634d6b2
Merge pull request #606 from mysofinance/myt-token-manager
jpick713 Apr 10, 2024
f6e20dd
added extra note
jpick713 Apr 10, 2024
739b419
updated token manager
asardon Apr 10, 2024
9bf44a0
Merge branch 'myt-token-manager' of https://github.com/mysofinance/v2…
asardon Apr 10, 2024
1eeb59d
updated token manager
asardon Apr 10, 2024
cabcf89
updated token manager
asardon Apr 10, 2024
fac1cb4
Merge branch 'myso-oracle' into myt-token-manager
jpick713 Apr 10, 2024
2fe6a9c
Merge pull request #607 from mysofinance/myt-token-manager
jpick713 Apr 10, 2024
7481fe2
updated token manager
asardon Apr 11, 2024
251f69f
Merge branch 'myt-token-manager' of https://github.com/mysofinance/v2…
asardon Apr 11, 2024
bdaa74f
access via sig
asardon Apr 11, 2024
3ff1f21
access via sig
asardon Apr 11, 2024
75eaa96
access via sig
asardon Apr 11, 2024
22bad12
added tests
asardon Apr 11, 2024
a7e5b07
added tests
asardon Apr 11, 2024
be25020
Merge pull request #608 from mysofinance/myt-token-manager
jpick713 Apr 11, 2024
7cd513b
Merge pull request #609 from mysofinance/myso-token-manager-sig
jpick713 Apr 11, 2024
1d7bda8
added one-off signatures
asardon Apr 12, 2024
bc19f95
added public already claimed getter
asardon Apr 12, 2024
10ba136
Merge pull request #610 from mysofinance/myso-token-manager-sig
jpick713 Apr 12, 2024
79f5d11
added rsweth and fsusd to oracle
jpick713 Apr 16, 2024
8c3e15e
Merge branch 'myso-oracle' of github.com:mysofinance/v2 into myso-oracle
jpick713 Apr 16, 2024
9a32576
simplified cap handling for myso token manager and added test
theuprotocol Apr 16, 2024
5bcdc63
Merge pull request #611 from mysofinance/myso-token-manager-sig
jpick713 Apr 16, 2024
298bfa9
updated default behavior to ignore caps when set to 0
theuprotocol Apr 17, 2024
f16aa5d
updated deployment script
theuprotocol Apr 17, 2024
d2e3756
added crvusd to oracle
jpick713 Apr 22, 2024
fd1bffc
Merge branch 'myso-oracle' of github.com:mysofinance/v2 into myso-oracle
jpick713 Apr 22, 2024
3f5ad21
Merge pull request #612 from mysofinance/myso-token-manager-sig
jpick713 Apr 22, 2024
c1d245a
started adding in arbitrum oracle
jpick713 Apr 22, 2024
2561f3d
add missing interfaces
jpick713 Apr 22, 2024
817fc96
added arbitrum oracle tests
jpick713 Apr 22, 2024
4e1b146
add deployment scripts, bnb myso oracle, arb token manager with p2poo…
asardon May 2, 2024
a62d1ca
add mantle oracle
jpick713 May 3, 2024
f8dcfb2
Merge branch 'myso-oracle' of github.com:mysofinance/v2 into myso-oracle
jpick713 May 3, 2024
31eaea7
added in hardcoded IOO mantle oracle
jpick713 May 3, 2024
1ac9d9e
remove unnecessary imports
jpick713 May 3, 2024
7ffb1dd
added edits to bnb oracle
jpick713 May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IWSTETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IWSTETH {
/**
* @notice gets amount of stEth for given wstEth
* @param _wstETHAmount amount of wstEth
* @return amount of stEth
*/
function getStETHByWstETH(
uint256 _wstETHAmount
) external view returns (uint256);
}
121 changes: 121 additions & 0 deletions contracts/peer-to-peer/oracles/custom/MysoOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import {ChainlinkBase} from "../chainlink/ChainlinkBase.sol";
import {Errors} from "../../../Errors.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IWSTETH} from "../../interfaces/oracles/IWSTETH.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

/**
* @dev supports oracles which are compatible with v2v3 or v3 interfaces
*/
contract MysoOracle is ChainlinkBase, Ownable2Step {
struct MysoPrice {
jpick713 marked this conversation as resolved.
Show resolved Hide resolved
uint112 priceUntilTimestampPassed;
uint112 priceOnceTimestampPassed;
uint32 timestampLatestProposedPriceBecomesValid;
}

// solhint-disable var-name-mixedcase
address internal constant MYSO = 0x00000000000000000000000000000000DeaDBeef; // TODO: put in real myso address
address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; // weth
jpick713 marked this conversation as resolved.
Show resolved Hide resolved
address internal constant WSTETH =
0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0; //wsteth
address internal constant STETH =
0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84; //steth
uint256 internal constant MYSO_IOO_BASE_CURRENCY_UNIT = 1e18; // 18 decimals for ETH based oracles
address internal constant ETH_USD_CHAINLINK =
0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419; //eth usd chainlink

uint256 internal constant MYSO_PRICE_TIME_LOCK = 1 days;

MysoPrice public mysoPrice;

/**
* @dev constructor for MysoOracle
* @param _tokenAddrs array of token addresses
* @param _oracleAddrs array of oracle addresses
* @param _mysoUsdPrice initial price of myso in usd (use 8 decimals like chainlink) (eg. 0.50 USD = 0.5 * 1e8)
*/
constructor(
jpick713 marked this conversation as resolved.
Show resolved Hide resolved
address[] memory _tokenAddrs,
address[] memory _oracleAddrs,
uint112 _mysoUsdPrice
) ChainlinkBase(_tokenAddrs, _oracleAddrs, MYSO_IOO_BASE_CURRENCY_UNIT) {
mysoPrice = MysoPrice(
_mysoUsdPrice,
_mysoUsdPrice,
uint32(block.timestamp)
);
jpick713 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @dev updates timestampLatestProposedPriceBecomesValid and priceOnceTimestampPassed
* only updates priceUntilTimestampPassed if the prior time lock had passed
* @param _newMysoUsdPrice initial price of myso in usd (use 8 decimals like chainlink) (eg. 0.50 USD = 0.5 * 1e8)
*/

function setMysoPrice(uint112 _newMysoUsdPrice) external onlyOwner {
if (
block.timestamp < mysoPrice.timestampLatestProposedPriceBecomesValid
) {
// if the priceOnceTimestampPassed is not yet active, update that price,
// leave priceUntilTimestampPassed the same but reset the time lock
mysoPrice = MysoPrice(
mysoPrice.priceUntilTimestampPassed,
_newMysoUsdPrice,
uint32(block.timestamp + MYSO_PRICE_TIME_LOCK)
);
} else {
// if the priceOnceTimestampPassed is not yet active, update the priceUntilTimestampPassed with old priceOnceTimestampPassed,
jpick713 marked this conversation as resolved.
Show resolved Hide resolved
// update the priceOnceTimestampPassed with new price, and reset the time lock
mysoPrice = MysoPrice(
mysoPrice.priceOnceTimestampPassed,
_newMysoUsdPrice,
uint32(block.timestamp + MYSO_PRICE_TIME_LOCK)
);
}
jpick713 marked this conversation as resolved.
Show resolved Hide resolved
}

function _getPriceOfToken(
address token
) internal view virtual override returns (uint256 tokenPriceRaw) {
if (token == MYSO) {
tokenPriceRaw = _getMysoPriceInEth();
} else if (token == WETH) {
tokenPriceRaw = 1e18;
} else if (token == WSTETH) {
tokenPriceRaw = _getWstEthPrice();
} else {
tokenPriceRaw = super._getPriceOfToken(token);
}
}

function _getWstEthPrice() internal view returns (uint256 wstEthPriceRaw) {
uint256 stEthAmountPerWstEth = IWSTETH(WSTETH).getStETHByWstETH(1e18);
uint256 stEthPriceInEth = _getPriceOfToken(STETH);
wstEthPriceRaw = Math.mulDiv(
stEthPriceInEth,
stEthAmountPerWstEth,
1e18
);
}

function _getMysoPriceInEth()
internal
view
returns (uint256 mysoPriceInEth)
{
uint256 mysoPriceInUsd = block.timestamp <
mysoPrice.timestampLatestProposedPriceBecomesValid
? mysoPrice.priceUntilTimestampPassed
: mysoPrice.priceOnceTimestampPassed;
uint256 ethPriceInUsd = _checkAndReturnLatestRoundData(
ETH_USD_CHAINLINK
);
mysoPriceInEth = Math.mulDiv(mysoPriceInUsd, 1e18, ethPriceInUsd);
}
}
Loading