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 all 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
4 changes: 2 additions & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"rules": {
"ordering": "error",
"no-global-import": "error",
"state-visibility": "error",
"state-visibility": "warn",
"imports-on-top": "error",
"no-unused-vars": "error",
"code-complexity": ["warn", 12],
"compiler-version": ["error", "^0.8.19"],
"const-name-snakecase": "error",
"const-name-snakecase": "warn",
"event-name-camelcase": "error",
"constructor-syntax": "error",
"func-name-mixedcase": "off",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The protocol supports two different models, each targeted at different use cases
## Quick Start
```
npm i
npx hardhat test
npx hardhat test --grep "IOO price correctly"
```

## Contract Files
Expand Down
11 changes: 11 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IANKRETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IANKRETH {
/**
* @notice gets amount of Eth for given ankrEth
* @param amount of ankrEth
* @return amount of eth
*/
function sharesToBonds(uint256 amount) external view returns (uint256);
}
10 changes: 10 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IFXUSD.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IFXUSD {
/**
* @notice gets USD NAV in 18 decimals
* @return NAV in USD
*/
function nav() external view returns (uint256);
}
11 changes: 11 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IGLPManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IGLPManager {
/**
* @notice gets price of GLP in USD with 30 decimals
* @param _maximize will pass true
* @return price of GLP in USD
*/
function getPrice(bool _maximize) external view returns (uint256);
}
10 changes: 10 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IGTOKEN.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IGTOKEN {
/**
* @notice gets amount of underlying token for a given amount of gToken
* @return amount of underlying token
*/
function shareToAssetsPrice() external view returns (uint256);
}
11 changes: 11 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IMETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IMETH {
/**
* @notice gets amount of Eth for given mEth
* @param mETHAmount amount of mEth
* @return amount of stEth
*/
function mETHToETH(uint256 mETHAmount) external view returns (uint256);
}
10 changes: 10 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IMysoTokenManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IMysoTokenManager {
/**
* @notice gets Myso token loan amount from MysoTokenManager
* @return total Myso loan amount up until now
*/
function totalMysoLoanAmount() external view returns (uint256);
}
10 changes: 10 additions & 0 deletions contracts/peer-to-peer/interfaces/oracles/IRSWETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IRSWETH {
/**
* @notice gets rswETH to ETH rate
* @return amount of ETH per rswETH
*/
function rswETHToETHRate() external view returns (uint256);
}
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);
}
114 changes: 114 additions & 0 deletions contracts/peer-to-peer/oracles/chainlink/ChainlinkBaseWithoutCheck.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {AggregatorV3Interface} from "../../interfaces/oracles/chainlink/AggregatorV3Interface.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Constants} from "../../../Constants.sol";
import {Errors} from "../../../Errors.sol";
import {IOracle} from "../../interfaces/IOracle.sol";

/**
* @dev supports oracles which are compatible with v2v3 or v3 interfaces
*/
abstract contract ChainlinkBaseWithoutCheck is IOracle {
// solhint-disable var-name-mixedcase
uint256 public immutable BASE_CURRENCY_UNIT;
mapping(address => address) public oracleAddrs;

constructor(
address[] memory _tokenAddrs,
address[] memory _oracleAddrs,
uint256 baseCurrencyUnit
) {
uint256 tokenAddrsLength = _tokenAddrs.length;
if (tokenAddrsLength != _oracleAddrs.length) {
revert Errors.InvalidArrayLength();
}
uint8 oracleDecimals;
uint256 version;
for (uint256 i; i < tokenAddrsLength; ) {
if (_tokenAddrs[i] == address(0) || _oracleAddrs[i] == address(0)) {
revert Errors.InvalidAddress();
}
oracleDecimals = AggregatorV3Interface(_oracleAddrs[i]).decimals();
if (10 ** oracleDecimals != baseCurrencyUnit) {
revert Errors.InvalidOracleDecimals();
}
version = AggregatorV3Interface(_oracleAddrs[i]).version();
if (version != 4) {
revert Errors.InvalidOracleVersion();
}
oracleAddrs[_tokenAddrs[i]] = _oracleAddrs[i];
unchecked {
++i;
}
}
BASE_CURRENCY_UNIT = baseCurrencyUnit;
}

function getPrice(
address collToken,
address loanToken
) external view virtual returns (uint256 collTokenPriceInLoanToken) {
(uint256 priceOfCollToken, uint256 priceOfLoanToken) = getRawPrices(
collToken,
loanToken
);
uint256 loanTokenDecimals = IERC20Metadata(loanToken).decimals();
collTokenPriceInLoanToken = Math.mulDiv(
priceOfCollToken,
10 ** loanTokenDecimals,
priceOfLoanToken
);
}

function getRawPrices(
address collToken,
address loanToken
)
public
view
virtual
returns (uint256 collTokenPriceRaw, uint256 loanTokenPriceRaw)
{
(collTokenPriceRaw, loanTokenPriceRaw) = (
_getPriceOfToken(collToken),
_getPriceOfToken(loanToken)
);
}

function _getPriceOfToken(
address token
) internal view virtual returns (uint256 tokenPriceRaw) {
address oracleAddr = oracleAddrs[token];
if (oracleAddr == address(0)) {
revert Errors.NoOracle();
}
tokenPriceRaw = _checkAndReturnLatestRoundData(oracleAddr);
}

function _checkAndReturnLatestRoundData(
address oracleAddr
) internal view virtual returns (uint256 tokenPriceRaw) {
(
uint80 roundId,
int256 answer,
,
uint256 updatedAt,
uint80 answeredInRound
) = AggregatorV3Interface(oracleAddr).latestRoundData();
if (
roundId == 0 ||
answeredInRound < roundId ||
answer < 1 ||
updatedAt > block.timestamp ||
updatedAt + Constants.MAX_PRICE_UPDATE_TIMESTAMP_DIVERGENCE <
block.timestamp
) {
revert Errors.InvalidOracleAnswer();
}
tokenPriceRaw = uint256(answer);
}
}
Loading
Loading