@ubk-labs/ubk-oracle 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/artifacts/contracts/constants/Constants.sol/Constants.dbg.json +4 -0
- package/artifacts/contracts/constants/Constants.sol/Constants.json +141 -0
- package/artifacts/contracts/core/UBKOracle.sol/UBKOracle.dbg.json +4 -0
- package/artifacts/contracts/core/UBKOracle.sol/UBKOracle.json +1028 -0
- package/artifacts/contracts/mocks/MockAggregatorV3.sol/MockAggregatorV3.dbg.json +4 -0
- package/artifacts/contracts/mocks/MockAggregatorV3.sol/MockAggregatorV3.json +177 -0
- package/artifacts/contracts/mocks/MockERC20.sol/MockERC20.dbg.json +4 -0
- package/artifacts/contracts/mocks/MockERC20.sol/MockERC20.json +381 -0
- package/artifacts/contracts/mocks/MockERC4626.sol/Mock4626.dbg.json +4 -0
- package/artifacts/contracts/mocks/MockERC4626.sol/Mock4626.json +500 -0
- package/artifacts/contracts/mocks/MockIERC4626.sol/MockIERC4626.dbg.json +4 -0
- package/artifacts/contracts/mocks/MockIERC4626.sol/MockIERC4626.json +99 -0
- package/artifacts/interfaces/IUBKOracle.sol/IUBKOracle.dbg.json +4 -0
- package/artifacts/interfaces/IUBKOracle.sol/IUBKOracle.json +264 -0
- package/contracts/constants/Constants.sol +34 -0
- package/contracts/core/UBKOracle.sol +560 -0
- package/contracts/errors/Errors.sol +17 -0
- package/contracts/mocks/MockAggregatorV3.sol +56 -0
- package/contracts/mocks/MockERC20.sol +28 -0
- package/contracts/mocks/MockERC4626.sol +74 -0
- package/contracts/mocks/MockIERC4626.sol +13 -0
- package/interfaces/IUBKOracle.sol +54 -0
- package/package.json +41 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
import "./MockERC20.sol";
|
|
5
|
+
import "./MockIERC4626.sol";
|
|
6
|
+
|
|
7
|
+
contract Mock4626 is MockERC20, MockIERC4626 {
|
|
8
|
+
uint256 public exchangeRate = 1e18; // 1:1 default
|
|
9
|
+
address private _asset; // underlying ERC20 asset
|
|
10
|
+
uint8 private immutable _assetDecimals;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
string memory name_,
|
|
14
|
+
string memory symbol_,
|
|
15
|
+
uint8 decimals_, // vault decimals (e.g. 18)
|
|
16
|
+
uint256 initialSupply,
|
|
17
|
+
address asset_
|
|
18
|
+
)
|
|
19
|
+
MockERC20(name_, symbol_, decimals_, initialSupply)
|
|
20
|
+
{
|
|
21
|
+
_asset = asset_;
|
|
22
|
+
_assetDecimals = MockERC20(asset_).decimals();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// @notice sets a mock exchange rate for testing
|
|
26
|
+
function setExchangeRate(uint256 newRate) external {
|
|
27
|
+
exchangeRate = newRate;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// @notice mock conversion (shares → assets)
|
|
31
|
+
function convertToAssets(uint256 shares) external view override returns (uint256) {
|
|
32
|
+
uint8 vaultDecimals = decimals();
|
|
33
|
+
|
|
34
|
+
// Normalize shares → assets
|
|
35
|
+
// assets = shares * 10^(assetDecimals) / 10^(vaultDecimals) * exchangeRate / 1e18
|
|
36
|
+
uint256 assets = (shares * (10 ** _assetDecimals)) / (10 ** vaultDecimals);
|
|
37
|
+
return (assets * exchangeRate) / 1e18;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// @notice ERC-4626 required function
|
|
41
|
+
function asset() external view override returns (address) {
|
|
42
|
+
return _asset;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// @notice Deposit assets and mint shares to `receiver`
|
|
46
|
+
/// @notice Deposit assets and mint shares to `receiver`
|
|
47
|
+
function deposit(uint256 assets, address receiver) external override returns (uint256 shares) {
|
|
48
|
+
require(assets > 0, "Zero deposit");
|
|
49
|
+
|
|
50
|
+
// Compute shares using convertToShares()
|
|
51
|
+
shares = this.convertToShares(assets);
|
|
52
|
+
|
|
53
|
+
// Pull underlying from sender
|
|
54
|
+
IERC20(_asset).transferFrom(msg.sender, address(this), assets);
|
|
55
|
+
|
|
56
|
+
// Mint vault shares (this ERC20) to receiver
|
|
57
|
+
_mint(receiver, shares);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// @notice mock conversion (assets → shares)
|
|
61
|
+
function convertToShares(uint256 assets) external view returns (uint256) {
|
|
62
|
+
uint8 vaultDecimals = decimals();
|
|
63
|
+
|
|
64
|
+
// Normalize: assets → shares
|
|
65
|
+
uint256 normalized = (assets * (10 ** vaultDecimals)) / (10 ** _assetDecimals);
|
|
66
|
+
|
|
67
|
+
return (normalized * 1e18) / exchangeRate;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// @notice get exchange rates
|
|
71
|
+
function getExchangeRate() external view returns (uint256) {
|
|
72
|
+
return exchangeRate;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
//Mocked interface for IERC-4626 behavior.
|
|
5
|
+
//This is far more minimal and easy to work with for testing purposes.
|
|
6
|
+
//Will be used to impart 4626 functionality to sDAI in tests.
|
|
7
|
+
interface MockIERC4626 {
|
|
8
|
+
function setExchangeRate(uint256 newRate) external;
|
|
9
|
+
function convertToAssets(uint256 shares) external view returns (uint256);
|
|
10
|
+
function convertToShares(uint256 assets) external view returns (uint256);
|
|
11
|
+
function asset() external view returns (address);
|
|
12
|
+
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
|
|
13
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
interface IUBKOracle {
|
|
5
|
+
/// @notice Operational state of the oracle.
|
|
6
|
+
enum OracleMode {
|
|
7
|
+
NORMAL,
|
|
8
|
+
PAUSED
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/// @notice Cached last valid price and timestamp.
|
|
12
|
+
struct LastValidPrice {
|
|
13
|
+
uint256 price;
|
|
14
|
+
uint256 timestamp;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/// @notice Custom vault rate bounds (min/max multiplier per vault).
|
|
18
|
+
struct VaultRateBounds {
|
|
19
|
+
uint256 minRate;
|
|
20
|
+
uint256 maxRate;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// @notice Oracle specific events for subgraph indexing.
|
|
24
|
+
event ChainlinkFeedSet(address indexed token, address indexed feed);
|
|
25
|
+
event ERC4626Registered(address indexed vault, address indexed underlying);
|
|
26
|
+
event TokenSupportAdded(address indexed token);
|
|
27
|
+
event ManualPriceSet(address indexed token, uint256 price);
|
|
28
|
+
event ManualModeEnabled(address indexed token, bool enabled);
|
|
29
|
+
event StalePeriodUpdated(uint256 newPeriod);
|
|
30
|
+
event OracleModeChanged(OracleMode oldMode, OracleMode newMode);
|
|
31
|
+
event FallbackStalePeriodUpdated(uint256 newPeriod);
|
|
32
|
+
event VaultRateBoundsSet(
|
|
33
|
+
address indexed vault,
|
|
34
|
+
uint256 minRate,
|
|
35
|
+
uint256 maxRate
|
|
36
|
+
);
|
|
37
|
+
event LastValidPriceUpdated(
|
|
38
|
+
address indexed token,
|
|
39
|
+
uint256 price,
|
|
40
|
+
uint256 timestamp
|
|
41
|
+
);
|
|
42
|
+
event OracleFallbackUsed(
|
|
43
|
+
address indexed token,
|
|
44
|
+
uint256 lastValid,
|
|
45
|
+
uint256 at,
|
|
46
|
+
string reason
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// View Functions
|
|
50
|
+
function getPrice(address token) external view returns (uint256);
|
|
51
|
+
|
|
52
|
+
// Mutators
|
|
53
|
+
function fetchAndUpdatePrice(address token) external returns (uint256);
|
|
54
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ubk-labs/ubk-oracle",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Oracle supporting ERC-20 and ERC-4626 assets for use in decentralized financial applications.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "npx hardhat compile",
|
|
7
|
+
"test": "npx hardhat test",
|
|
8
|
+
"coverage": "hardhat coverage",
|
|
9
|
+
"lint": "prettier --check .",
|
|
10
|
+
"format": "prettier --write ."
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"DeFi",
|
|
14
|
+
"Oracle",
|
|
15
|
+
"Solidity",
|
|
16
|
+
"Hardhat"
|
|
17
|
+
],
|
|
18
|
+
"author": "UBK Finance Team",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"files": [
|
|
21
|
+
"contracts",
|
|
22
|
+
"artifacts",
|
|
23
|
+
"interfaces",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@graphprotocol/hardhat-graph": "^0.1.0-alpha.2",
|
|
29
|
+
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
|
|
30
|
+
"@openzeppelin/contracts": "^5.0.1",
|
|
31
|
+
"dotenv": "^16.1.4",
|
|
32
|
+
"ethers": "^6.7.0",
|
|
33
|
+
"hardhat": "^2.26.3",
|
|
34
|
+
"hardhat-tracer": "^3.4.0",
|
|
35
|
+
"prettier": "^3.2.5",
|
|
36
|
+
"solidity-coverage": "^0.8.16"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@chainlink/contracts": "^0.6.1"
|
|
40
|
+
}
|
|
41
|
+
}
|