@hyperbridge/core 1.4.0 → 1.5.0

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.
@@ -102,6 +102,8 @@ struct Params {
102
102
  /// @dev The protocol fee in basis points charged on order inputs.
103
103
  /// 10000 = 100%, 100 = 1%, etc.
104
104
  uint256 protocolFeeBps;
105
+ /// @dev The address of the price oracle contract.
106
+ address priceOracle;
105
107
  }
106
108
 
107
109
  /**
@@ -0,0 +1,85 @@
1
+ // Copyright (C) Polytope Labs Ltd.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ pragma solidity ^0.8.24;
16
+
17
+ import {TokenInfo} from "./IntentGatewayV2.sol";
18
+
19
+ /**
20
+ * @title IIntentPriceOracle
21
+ * @author Polytope Labs (hello@polytope.technology)
22
+ * @notice Interface for tracking cumulative weighted average spreads for same-token swaps
23
+ * @dev Only supports same-token swaps across chains
24
+ */
25
+ interface IIntentPriceOracle {
26
+ /**
27
+ * @notice Struct to track cumulative spread data for weighted average calculation
28
+ */
29
+ struct CumulativeSpreadData {
30
+ /// @dev Sum of (spread * volume) for all fills
31
+ int256 weightedSpreadSum;
32
+ /// @dev Total volume in normalized token units (18 decimals)
33
+ uint256 totalVolume;
34
+ /// @dev Number of fills
35
+ uint256 fillCount;
36
+ /// @dev Last update timestamp
37
+ uint256 lastUpdate;
38
+ }
39
+
40
+ /**
41
+ * @notice Event emitted when spread is recorded for a filled order
42
+ * @param commitment The order commitment hash
43
+ * @param destinationToken The destination token address
44
+ * @param spreadBps The spread in basis points
45
+ */
46
+ event SpreadRecorded(bytes32 indexed commitment, address indexed destinationToken, int256 spreadBps);
47
+
48
+ /**
49
+ * @notice Event emitted when token decimals are updated
50
+ * @param sourceChain The source chain state machine ID
51
+ * @param token The token address
52
+ * @param decimals The number of decimals
53
+ */
54
+ event TokenDecimalsUpdated(bytes sourceChain, address indexed token, uint8 decimals);
55
+
56
+ /**
57
+ * @notice Records the spread for a filled order and computes weighted average
58
+ * @param commitment The order commitment hash
59
+ * @param sourceChain The source chain identifier (bytes format)
60
+ * @param inputs The input tokens that were escrowed
61
+ * @param outputs The output tokens provided by the filler (actual amounts)
62
+ */
63
+ function recordSpread(
64
+ bytes32 commitment,
65
+ bytes memory sourceChain,
66
+ TokenInfo[] calldata inputs,
67
+ TokenInfo[] calldata outputs
68
+ ) external;
69
+
70
+ /**
71
+ * @notice Gets the decimals for a token on a specific source chain
72
+ * @param sourceChain The source chain identifier
73
+ * @param token The token address
74
+ * @return decimals The number of decimals (defaults to 18 if not set)
75
+ */
76
+ function decimals(bytes memory sourceChain, address token) external view returns (uint8 decimals);
77
+
78
+ /**
79
+ * @notice Gets the cumulative weighted average spread data for a token on a source chain
80
+ * @param sourceChain The source chain identifier
81
+ * @param token The token address
82
+ * @return data The cumulative spread data
83
+ */
84
+ function spread(bytes memory sourceChain, address token) external view returns (CumulativeSpreadData memory data);
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbridge/core",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Hyperbridge Solidity SDK for dispatching & receiving cross-chain messages",
5
5
  "author": "Polytope Labs <hello@polytope.technology>",
6
6
  "license": "Apache-2.0",