@bananapus/core-v6 0.0.76 → 0.0.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/core-v6",
3
- "version": "0.0.76",
3
+ "version": "0.0.77",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,58 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.28;
3
+
4
+ import {mulDiv} from "@prb/math/src/Common.sol";
5
+
6
+ import {IJBPriceFeed} from "../interfaces/IJBPriceFeed.sol";
7
+
8
+ /// @notice A composite price feed that triangulates two existing feeds sharing a common quote ("pivot") currency to
9
+ /// price a pair that has no direct feed.
10
+ /// @dev Composes `NUMERATOR` (the pivot priced per unit of the target pair's *unit* currency) and `DENOMINATOR` (the
11
+ /// pivot priced per unit of the target pair's *pricing* currency) into "pricing currency per unit currency". The
12
+ /// pivot is implicit in the two legs supplied at construction — it is never hardcoded — so different instances can
13
+ /// triangulate through different pivots, and `JBPrices` stays a plain registry with no triangulation logic.
14
+ ///
15
+ /// Worked example (ETH<->USDC has no direct feed, triangulate through USD): supply
16
+ /// `NUMERATOR` = the USD-per-USDC feed and `DENOMINATOR` = the USD-per-ETH feed. `currentUnitPrice` then returns
17
+ /// "ETH per 1 USDC", and registering this feed for the `(pricingCurrency = ETH, unitCurrency = USDC)` pair lets
18
+ /// `JBPrices` auto-invert it to "USDC per 1 ETH" for the opposite direction.
19
+ ///
20
+ /// Safety: this feed inherits each leg's staleness/validity reverts. If either leg reverts (stale, negative, or
21
+ /// incomplete round) the composite reverts, so a stale or invalid leg can never yield a usable composite price.
22
+ contract JBTriangularPriceFeed is IJBPriceFeed {
23
+ //*********************************************************************//
24
+ // --------------- public immutable stored properties ---------------- //
25
+ //*********************************************************************//
26
+
27
+ /// @notice The feed pricing one unit of the target pair's *unit* currency in the shared pivot currency.
28
+ IJBPriceFeed public immutable NUMERATOR;
29
+
30
+ /// @notice The feed pricing one unit of the target pair's *pricing* currency in the shared pivot currency.
31
+ IJBPriceFeed public immutable DENOMINATOR;
32
+
33
+ //*********************************************************************//
34
+ // -------------------------- constructor ---------------------------- //
35
+ //*********************************************************************//
36
+
37
+ /// @param numerator The feed pricing the unit currency in the pivot currency (e.g. a USD-per-USDC feed).
38
+ /// @param denominator The feed pricing the pricing currency in the pivot currency (e.g. a USD-per-ETH feed).
39
+ constructor(IJBPriceFeed numerator, IJBPriceFeed denominator) {
40
+ NUMERATOR = numerator;
41
+ DENOMINATOR = denominator;
42
+ }
43
+
44
+ //*********************************************************************//
45
+ // ------------------------- external views -------------------------- //
46
+ //*********************************************************************//
47
+
48
+ /// @inheritdoc IJBPriceFeed
49
+ /// @dev Returns `numerator / denominator` at the requested precision, which cancels the shared pivot unit and
50
+ /// yields "pricing currency per 1 unit currency".
51
+ function currentUnitPrice(uint256 decimals) external view override returns (uint256) {
52
+ return mulDiv({
53
+ x: NUMERATOR.currentUnitPrice(decimals),
54
+ y: 10 ** decimals,
55
+ denominator: DENOMINATOR.currentUnitPrice(decimals)
56
+ });
57
+ }
58
+ }