@ubk-labs/ubk-oracle 0.1.4 → 0.1.6

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.
Files changed (23) hide show
  1. package/contracts/constants/{Constants.sol → UBKOracleConstants.sol} +2 -2
  2. package/contracts/core/UBKOracle.sol +36 -36
  3. package/contracts/errors/{Errors.sol → UBKOracleErrors.sol} +1 -1
  4. package/contracts/imports/UBKImports.sol +14 -0
  5. package/package.json +4 -4
  6. package/artifacts/contracts/constants/Constants.sol/Constants.dbg.json +0 -4
  7. package/artifacts/contracts/constants/Constants.sol/Constants.json +0 -141
  8. package/artifacts/contracts/core/UBKOracle.sol/UBKOracle.dbg.json +0 -4
  9. package/artifacts/contracts/core/UBKOracle.sol/UBKOracle.json +0 -1028
  10. package/artifacts/contracts/mocks/MockAggregatorV3.sol/MockAggregatorV3.dbg.json +0 -4
  11. package/artifacts/contracts/mocks/MockAggregatorV3.sol/MockAggregatorV3.json +0 -177
  12. package/artifacts/contracts/mocks/MockERC20.sol/MockERC20.dbg.json +0 -4
  13. package/artifacts/contracts/mocks/MockERC20.sol/MockERC20.json +0 -381
  14. package/artifacts/contracts/mocks/MockERC4626.sol/Mock4626.dbg.json +0 -4
  15. package/artifacts/contracts/mocks/MockERC4626.sol/Mock4626.json +0 -500
  16. package/artifacts/contracts/mocks/MockIERC4626.sol/MockIERC4626.dbg.json +0 -4
  17. package/artifacts/contracts/mocks/MockIERC4626.sol/MockIERC4626.json +0 -99
  18. package/artifacts/interfaces/IUBKOracle.sol/IUBKOracle.dbg.json +0 -4
  19. package/artifacts/interfaces/IUBKOracle.sol/IUBKOracle.json +0 -312
  20. package/contracts/mocks/MockAggregatorV3.sol +0 -56
  21. package/contracts/mocks/MockERC20.sol +0 -28
  22. package/contracts/mocks/MockERC4626.sol +0 -74
  23. package/contracts/mocks/MockIERC4626.sol +0 -13
@@ -1,10 +1,10 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.20;
3
3
 
4
- import "@ubk-labs/ubk-commons/commons/UBKConstants.sol";
4
+ import "@ubk-labs/ubk-commons/contracts/constants/UBKConstants.sol";
5
5
 
6
6
 
7
- library Constants {
7
+ library UBKOracleConstants {
8
8
  // -----------------------------------------------------------------------
9
9
  // UBK System Constants
10
10
  // -----------------------------------------------------------------------
@@ -9,8 +9,8 @@ import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
9
9
  import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
10
10
 
11
11
  import "../../interfaces/IUBKOracle.sol";
12
- import "../errors/Errors.sol";
13
- import "../constants/Constants.sol";
12
+ import "../errors/UBKOracleErrors.sol";
13
+ import "../constants/UBKOracleConstants.sol";
14
14
 
15
15
  /**
16
16
  * @title Oracle
@@ -63,11 +63,11 @@ contract UBKOracle is IUBKOracle, Ownable {
63
63
  mapping(address => VaultRateBounds) public vaultRateBounds;
64
64
 
65
65
  /// @notice Maximum staleness period for Chainlink feeds (seconds).
66
- uint256 public stalePeriod = Constants.ORACLE_DEFAULT_STALE_PERIOD;
66
+ uint256 public stalePeriod = UBKOracleConstants.ORACLE_DEFAULT_STALE_PERIOD;
67
67
 
68
68
  /// @notice Staleness tolerance for fallback prices (seconds).
69
69
  uint256 public fallbackStalePeriod =
70
- Constants.ORACLE_DEFAULT_STALE_PERIOD * 2;
70
+ UBKOracleConstants.ORACLE_DEFAULT_STALE_PERIOD * 2;
71
71
 
72
72
  OracleMode public mode = OracleMode.NORMAL;
73
73
 
@@ -90,7 +90,7 @@ contract UBKOracle is IUBKOracle, Ownable {
90
90
  */
91
91
  constructor(address _owner) Ownable(_owner) {
92
92
  if (_owner == address(0))
93
- revert ZeroAddress("Oracle:constructor", "owner");
93
+ revert ZeroAddress("UBKOracle::constructor", "owner");
94
94
  }
95
95
 
96
96
  /// @notice Ensures oracle is not paused.
@@ -102,7 +102,7 @@ contract UBKOracle is IUBKOracle, Ownable {
102
102
 
103
103
  /// @notice Prevents infinite recursion when resolving nested ERC4626 vaults.
104
104
  modifier checkRecursion() {
105
- if (_recursionDepth >= Constants.MAX_RECURSION_DEPTH)
105
+ if (_recursionDepth >= UBKOracleConstants.MAX_RECURSION_DEPTH)
106
106
  revert RecursiveResolution(address(0));
107
107
  _recursionDepth++;
108
108
  _;
@@ -126,12 +126,12 @@ contract UBKOracle is IUBKOracle, Ownable {
126
126
  /**
127
127
  * @notice Sets the maximum time (in seconds) a Chainlink feed value is valid.
128
128
  * @param period The new staleness threshold.
129
- * @dev Must lie within [Constants.ORACLE_MIN_STALE_PERIOD, Constants.ORACLE_MAX_STALE_PERIOD].
129
+ * @dev Must lie within [UBKOracleConstants.ORACLE_MIN_STALE_PERIOD, UBKOracleConstants.ORACLE_MAX_STALE_PERIOD].
130
130
  */
131
131
  function setStalePeriod(uint256 period) external onlyOwner {
132
132
  if (
133
- period < Constants.ORACLE_MIN_STALE_PERIOD ||
134
- period > Constants.ORACLE_MAX_STALE_PERIOD
133
+ period < UBKOracleConstants.ORACLE_MIN_STALE_PERIOD ||
134
+ period > UBKOracleConstants.ORACLE_MAX_STALE_PERIOD
135
135
  ) revert InvalidStalePeriod(period);
136
136
  stalePeriod = period;
137
137
  emit StalePeriodUpdated(period);
@@ -161,7 +161,7 @@ contract UBKOracle is IUBKOracle, Ownable {
161
161
  uint256 maxRate
162
162
  ) external onlyOwner {
163
163
  if (vault == address(0))
164
- revert ZeroAddress("Oracle:setVaultRateBounds", "vault");
164
+ revert ZeroAddress("UBKOracle::setVaultRateBounds", "vault");
165
165
  if (minRate == 0 || maxRate <= minRate || maxRate > 100e18)
166
166
  revert InvalidVaultBounds(vault, minRate, maxRate);
167
167
 
@@ -181,20 +181,20 @@ contract UBKOracle is IUBKOracle, Ownable {
181
181
  uint256 price
182
182
  ) external onlyOwner whenNotPaused {
183
183
  if (token == address(0))
184
- revert ZeroAddress("Oracle:setManualPrice", "token");
184
+ revert ZeroAddress("UBKOracle::setManualPrice", "token");
185
185
  if (
186
- price < Constants.ORACLE_MIN_ABSOLUTE_PRICE_WAD ||
187
- price > Constants.ORACLE_MAX_ABSOLUTE_PRICE_WAD
186
+ price < UBKOracleConstants.ORACLE_MIN_ABSOLUTE_PRICE_WAD ||
187
+ price > UBKOracleConstants.ORACLE_MAX_ABSOLUTE_PRICE_WAD
188
188
  ) revert InvalidManualPrice(token, price);
189
189
 
190
190
  LastValidPrice memory lv = lastValidPrice[token];
191
191
  if (lv.price > 0 && block.timestamp - lv.timestamp <= stalePeriod) {
192
192
  uint256 lowerBound = (lv.price *
193
- (Constants.WAD - Constants.ORACLE_MANUAL_PRICE_MAX_DELTA_WAD)) /
194
- Constants.WAD;
193
+ (UBKOracleConstants.WAD - UBKOracleConstants.ORACLE_MANUAL_PRICE_MAX_DELTA_WAD)) /
194
+ UBKOracleConstants.WAD;
195
195
  uint256 upperBound = (lv.price *
196
- (Constants.WAD + Constants.ORACLE_MANUAL_PRICE_MAX_DELTA_WAD)) /
197
- Constants.WAD;
196
+ (UBKOracleConstants.WAD + UBKOracleConstants.ORACLE_MANUAL_PRICE_MAX_DELTA_WAD)) /
197
+ UBKOracleConstants.WAD;
198
198
  if (price < lowerBound || price > upperBound)
199
199
  revert InvalidManualPrice(token, price);
200
200
  }
@@ -214,7 +214,7 @@ contract UBKOracle is IUBKOracle, Ownable {
214
214
  */
215
215
  function disableManualPrice(address token) external onlyOwner {
216
216
  if (token == address(0))
217
- revert ZeroAddress("Oracle:disableManualPrice", "token");
217
+ revert ZeroAddress("UBKOracle::disableManualPrice", "token");
218
218
  isManual[token] = false;
219
219
  emit ManualModeEnabled(token, false);
220
220
  }
@@ -227,7 +227,7 @@ contract UBKOracle is IUBKOracle, Ownable {
227
227
  */
228
228
  function setChainlinkFeed(address token, address feed) external onlyOwner {
229
229
  if (token == address(0) || feed == address(0))
230
- revert ZeroAddress("Oracle:setChainlinkFeed", "input");
230
+ revert ZeroAddress("UBKOracle::setChainlinkFeed", "input");
231
231
  if (feed.code.length == 0) revert InvalidFeedContract(feed);
232
232
 
233
233
  AggregatorV3Interface agg = AggregatorV3Interface(feed);
@@ -264,7 +264,7 @@ contract UBKOracle is IUBKOracle, Ownable {
264
264
  address underlying
265
265
  ) external onlyOwner {
266
266
  if (vault == address(0) || underlying == address(0))
267
- revert ZeroAddress("Oracle:setERC4626Vault", "input");
267
+ revert ZeroAddress("UBKOracle::setERC4626Vault", "input");
268
268
  try IERC4626(vault).asset() returns (address) {} catch {
269
269
  revert InvalidERC4626Vault(vault);
270
270
  }
@@ -295,7 +295,7 @@ contract UBKOracle is IUBKOracle, Ownable {
295
295
  address token
296
296
  ) external whenNotPaused returns (uint256) {
297
297
  if (token == address(0))
298
- revert ZeroAddress("Oracle:fetchAndUpdatePrice", "token");
298
+ revert ZeroAddress("UBKOracle::fetchAndUpdatePrice", "token");
299
299
  return _fetchAndUpdatePrice(token);
300
300
  }
301
301
 
@@ -352,9 +352,9 @@ contract UBKOracle is IUBKOracle, Ownable {
352
352
  ) external view returns (uint256 usdValue) {
353
353
  if (amount == 0) return 0;
354
354
  uint8 decimals = IERC20Metadata(token).decimals();
355
- uint256 normalized = (amount * Constants.WAD) / (10 ** decimals);
355
+ uint256 normalized = (amount * UBKOracleConstants.WAD) / (10 ** decimals);
356
356
  uint256 price = _getPrice(token); // 18 decimals
357
- usdValue = (normalized * price) / Constants.WAD;
357
+ usdValue = (normalized * price) / UBKOracleConstants.WAD;
358
358
  }
359
359
 
360
360
  /**
@@ -370,8 +370,8 @@ contract UBKOracle is IUBKOracle, Ownable {
370
370
  if (usdAmount == 0) return 0;
371
371
  uint8 decimals = IERC20Metadata(token).decimals();
372
372
  uint256 price = _getPrice(token); // 18 decimals
373
- uint256 normalized = (usdAmount * Constants.WAD) / price;
374
- tokenAmount = (normalized * (10 ** decimals)) / Constants.WAD;
373
+ uint256 normalized = (usdAmount * UBKOracleConstants.WAD) / price;
374
+ tokenAmount = (normalized * (10 ** decimals)) / UBKOracleConstants.WAD;
375
375
  }
376
376
 
377
377
  // -----------------------------------------------------------------------
@@ -385,7 +385,7 @@ contract UBKOracle is IUBKOracle, Ownable {
385
385
  * @return price Cached price in 1e18 precision.
386
386
  */
387
387
  function _getPrice(address token) internal view returns (uint256) {
388
- if (token == address(0)) revert ZeroAddress("Oracle:getPrice", "token");
388
+ if (token == address(0)) revert ZeroAddress("UBKOracle::getPrice", "token");
389
389
  LastValidPrice memory lv = lastValidPrice[token];
390
390
  if (lv.price == 0) revert NoFallbackPrice(token);
391
391
  if (!this.isPriceFresh(token))
@@ -412,24 +412,24 @@ contract UBKOracle is IUBKOracle, Ownable {
412
412
  if (assetsPerShare == 0 || assetsPerShare > 1e36)
413
413
  revert InvalidVaultExchangeRate(vault, assetsPerShare);
414
414
 
415
- uint256 scaledAssets = (assetsPerShare * Constants.WAD) /
415
+ uint256 scaledAssets = (assetsPerShare * UBKOracleConstants.WAD) /
416
416
  (10 ** underlyingDecimals);
417
- uint256 scaledShare = (oneShare * Constants.WAD) /
417
+ uint256 scaledShare = (oneShare * UBKOracleConstants.WAD) /
418
418
  (10 ** shareDecimals);
419
- uint256 rate = (scaledAssets * Constants.WAD) / scaledShare;
419
+ uint256 rate = (scaledAssets * UBKOracleConstants.WAD) / scaledShare;
420
420
 
421
421
  VaultRateBounds memory bounds = vaultRateBounds[vault];
422
422
  uint256 minRate = bounds.minRate == 0
423
- ? Constants.ORACLE_MIN_VAULT_RATE_WAD
423
+ ? UBKOracleConstants.ORACLE_MIN_VAULT_RATE_WAD
424
424
  : bounds.minRate;
425
425
  uint256 maxRate = bounds.maxRate == 0
426
- ? Constants.ORACLE_MAX_VAULT_RATE_WAD
426
+ ? UBKOracleConstants.ORACLE_MAX_VAULT_RATE_WAD
427
427
  : bounds.maxRate;
428
428
  if (rate > maxRate || rate < minRate)
429
429
  revert SuspiciousVaultRate(vault, rate);
430
430
 
431
431
  uint256 underlyingPrice = resolvePrice(underlying);
432
- return (underlyingPrice * rate) / Constants.WAD;
432
+ return (underlyingPrice * rate) / UBKOracleConstants.WAD;
433
433
  }
434
434
 
435
435
  /**
@@ -478,8 +478,8 @@ contract UBKOracle is IUBKOracle, Ownable {
478
478
  }
479
479
 
480
480
  if (
481
- clPrice < Constants.ORACLE_MIN_ABSOLUTE_PRICE_WAD ||
482
- clPrice > Constants.ORACLE_MAX_ABSOLUTE_PRICE_WAD
481
+ clPrice < UBKOracleConstants.ORACLE_MIN_ABSOLUTE_PRICE_WAD ||
482
+ clPrice > UBKOracleConstants.ORACLE_MAX_ABSOLUTE_PRICE_WAD
483
483
  ) return (0, false);
484
484
 
485
485
  return (clPrice, true);
@@ -531,8 +531,8 @@ contract UBKOracle is IUBKOracle, Ownable {
531
531
  ) internal returns (uint256 price) {
532
532
  price = resolvePrice(token);
533
533
  if (
534
- price < Constants.ORACLE_MIN_ABSOLUTE_PRICE_WAD ||
535
- price > Constants.ORACLE_MAX_ABSOLUTE_PRICE_WAD
534
+ price < UBKOracleConstants.ORACLE_MIN_ABSOLUTE_PRICE_WAD ||
535
+ price > UBKOracleConstants.ORACLE_MAX_ABSOLUTE_PRICE_WAD
536
536
  ) revert InvalidOraclePrice(token, address(0));
537
537
 
538
538
  lastValidPrice[token] = LastValidPrice(price, block.timestamp);
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.20;
3
3
 
4
- import "@ubk-labs/ubk-commons/commons/UBKErrors.sol";
4
+ import "@ubk-labs/ubk-commons/contracts/errors/UBKErrors.sol";
5
5
 
6
6
  // ───────────── Errors ─────────────
7
7
  error InvalidManualPrice(address token, uint256 price);
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ // Importing these ensures Hardhat generates artifacts for them.
5
+ import "@ubk-labs/ubk-commons/contracts/mocks/MockERC20.sol";
6
+ import "@ubk-labs/ubk-commons/contracts/mocks/MockERC4626.sol";
7
+ import "@ubk-labs/ubk-commons/contracts/mocks/MockAggregatorV3.sol";
8
+
9
+ abstract contract UBKImports {
10
+ /**
11
+ This shim file will import all external contracts to enable
12
+ automatic artifact generation by HardHat.
13
+ */
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubk-labs/ubk-oracle",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Oracle supporting ERC-20 and ERC-4626 assets for use in decentralized financial applications.",
5
5
  "scripts": {
6
6
  "build": "npx hardhat compile",
@@ -19,10 +19,10 @@
19
19
  "license": "MIT",
20
20
  "files": [
21
21
  "contracts",
22
- "artifacts",
23
22
  "interfaces",
24
23
  "README.md",
25
- "LICENSE"
24
+ "LICENSE",
25
+ "package.json"
26
26
  ],
27
27
  "devDependencies": {
28
28
  "@graphprotocol/hardhat-graph": "^0.1.0-alpha.2",
@@ -37,6 +37,6 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@chainlink/contracts": "^0.6.1",
40
- "@ubk-labs/ubk-commons": "^0.1.1"
40
+ "@ubk-labs/ubk-commons": "^0.1.5"
41
41
  }
42
42
  }
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/a0477a94e5e107b46c8b3b0821913376.json"
4
- }
@@ -1,141 +0,0 @@
1
- {
2
- "_format": "hh-sol-artifact-1",
3
- "contractName": "Constants",
4
- "sourceName": "contracts/constants/Constants.sol",
5
- "abi": [
6
- {
7
- "inputs": [],
8
- "name": "MAX_RECURSION_DEPTH",
9
- "outputs": [
10
- {
11
- "internalType": "uint256",
12
- "name": "",
13
- "type": "uint256"
14
- }
15
- ],
16
- "stateMutability": "view",
17
- "type": "function"
18
- },
19
- {
20
- "inputs": [],
21
- "name": "ORACLE_DEFAULT_STALE_PERIOD",
22
- "outputs": [
23
- {
24
- "internalType": "uint256",
25
- "name": "",
26
- "type": "uint256"
27
- }
28
- ],
29
- "stateMutability": "view",
30
- "type": "function"
31
- },
32
- {
33
- "inputs": [],
34
- "name": "ORACLE_MANUAL_PRICE_MAX_DELTA_WAD",
35
- "outputs": [
36
- {
37
- "internalType": "uint256",
38
- "name": "",
39
- "type": "uint256"
40
- }
41
- ],
42
- "stateMutability": "view",
43
- "type": "function"
44
- },
45
- {
46
- "inputs": [],
47
- "name": "ORACLE_MAX_ABSOLUTE_PRICE_WAD",
48
- "outputs": [
49
- {
50
- "internalType": "uint256",
51
- "name": "",
52
- "type": "uint256"
53
- }
54
- ],
55
- "stateMutability": "view",
56
- "type": "function"
57
- },
58
- {
59
- "inputs": [],
60
- "name": "ORACLE_MAX_STALE_PERIOD",
61
- "outputs": [
62
- {
63
- "internalType": "uint256",
64
- "name": "",
65
- "type": "uint256"
66
- }
67
- ],
68
- "stateMutability": "view",
69
- "type": "function"
70
- },
71
- {
72
- "inputs": [],
73
- "name": "ORACLE_MAX_VAULT_RATE_WAD",
74
- "outputs": [
75
- {
76
- "internalType": "uint256",
77
- "name": "",
78
- "type": "uint256"
79
- }
80
- ],
81
- "stateMutability": "view",
82
- "type": "function"
83
- },
84
- {
85
- "inputs": [],
86
- "name": "ORACLE_MIN_ABSOLUTE_PRICE_WAD",
87
- "outputs": [
88
- {
89
- "internalType": "uint256",
90
- "name": "",
91
- "type": "uint256"
92
- }
93
- ],
94
- "stateMutability": "view",
95
- "type": "function"
96
- },
97
- {
98
- "inputs": [],
99
- "name": "ORACLE_MIN_STALE_PERIOD",
100
- "outputs": [
101
- {
102
- "internalType": "uint256",
103
- "name": "",
104
- "type": "uint256"
105
- }
106
- ],
107
- "stateMutability": "view",
108
- "type": "function"
109
- },
110
- {
111
- "inputs": [],
112
- "name": "ORACLE_MIN_VAULT_RATE_WAD",
113
- "outputs": [
114
- {
115
- "internalType": "uint256",
116
- "name": "",
117
- "type": "uint256"
118
- }
119
- ],
120
- "stateMutability": "view",
121
- "type": "function"
122
- },
123
- {
124
- "inputs": [],
125
- "name": "WAD",
126
- "outputs": [
127
- {
128
- "internalType": "uint256",
129
- "name": "",
130
- "type": "uint256"
131
- }
132
- ],
133
- "stateMutability": "view",
134
- "type": "function"
135
- }
136
- ],
137
- "bytecode": "0x61016861003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100a85760003560e01c8063730513511161007057806373051351146101015780639a1b2c43146100ad578063afb9888514610112578063d160ed4d14610121578063f3f7de781461012957600080fd5b80634e9331ef146100ad5780635c94d0f9146100c85780636a146024146100d75780636bae86bb146100e65780636c0d5b36146100f2575b600080fd5b6100b6610e1081565b60405190815260200160405180910390f35b6100b667016345785d8a000081565b6100b6670de0b6b3a764000081565b6100b66402540be40081565b6100b66729a2241af62c000081565b6100b669d3c21bcecceda100000081565b6100b66702c68af0bb14000081565b6100b6600581565b6100b6612a308156fea2646970667358221220fc119d5143d6a571f8dab8bde95a47efdbad04c9eee68a7292ade134cd2ce55364736f6c63430008150033",
138
- "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600436106100a85760003560e01c8063730513511161007057806373051351146101015780639a1b2c43146100ad578063afb9888514610112578063d160ed4d14610121578063f3f7de781461012957600080fd5b80634e9331ef146100ad5780635c94d0f9146100c85780636a146024146100d75780636bae86bb146100e65780636c0d5b36146100f2575b600080fd5b6100b6610e1081565b60405190815260200160405180910390f35b6100b667016345785d8a000081565b6100b6670de0b6b3a764000081565b6100b66402540be40081565b6100b66729a2241af62c000081565b6100b669d3c21bcecceda100000081565b6100b66702c68af0bb14000081565b6100b6600581565b6100b6612a308156fea2646970667358221220fc119d5143d6a571f8dab8bde95a47efdbad04c9eee68a7292ade134cd2ce55364736f6c63430008150033",
139
- "linkReferences": {},
140
- "deployedLinkReferences": {}
141
- }
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/a0477a94e5e107b46c8b3b0821913376.json"
4
- }