@hyperbridge/core 1.3.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.
@@ -37,6 +37,10 @@ struct TokenInfo {
37
37
  uint256 amount;
38
38
  }
39
39
 
40
+ /**
41
+ * @notice Information for executing calls before an order is placed on the destination chain
42
+ * @dev Used to specify pre-dispatch operations with associated assets
43
+ */
40
44
  struct DispatchInfo {
41
45
  /// @dev Assets to execute a predispatch call with
42
46
  TokenInfo[] assets;
@@ -98,6 +102,30 @@ struct Params {
98
102
  /// @dev The protocol fee in basis points charged on order inputs.
99
103
  /// 10000 = 100%, 100 = 1%, etc.
100
104
  uint256 protocolFeeBps;
105
+ /// @dev The address of the price oracle contract.
106
+ address priceOracle;
107
+ }
108
+
109
+ /**
110
+ * @dev Struct to define the destination fee parameters.
111
+ */
112
+ struct DestinationFee {
113
+ /// @dev The percentage of fee (in basis points) charged for the destination chain.
114
+ /// 10000 = 100%, 5000 = 50%, etc.
115
+ uint256 destinationFeeBps;
116
+ /// @dev The state machine ID associated with the destination fee.
117
+ bytes32 stateMachineId;
118
+ }
119
+
120
+ /**
121
+ * @dev Struct to define a parameter update request from Hyperbridge
122
+ * @notice Contains both general parameters and destination-specific fee configurations
123
+ */
124
+ struct ParamsUpdate {
125
+ /// @dev The general parameters for the IntentGateway module
126
+ Params params;
127
+ /// @dev The destination fee parameters for specific chains
128
+ DestinationFee[] destinationFees;
101
129
  }
102
130
 
103
131
  /**
@@ -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
+ }
@@ -15,33 +15,33 @@
15
15
  pragma solidity ^0.8.17;
16
16
 
17
17
  struct TeleportParams {
18
- // amount to be sent
19
- uint256 amount;
20
- // Relayer fee
21
- uint256 relayerFee;
22
- // The token identifier to send
23
- bytes32 assetId;
24
- // Redeem ERC20 on the destination?
25
- bool redeem;
26
- // recipient address
27
- bytes32 to;
28
- // recipient state machine
29
- bytes dest;
30
- // request timeout in seconds
31
- uint64 timeout;
32
- // Amount of native token to pay for dispatching the request
33
- // if 0 will use the `IIsmpHost.feeToken`
34
- uint256 nativeCost;
35
- // destination contract call data
36
- bytes data;
18
+ // amount to be sent
19
+ uint256 amount;
20
+ // Relayer fee
21
+ uint256 relayerFee;
22
+ // The token identifier to send
23
+ bytes32 assetId;
24
+ // Redeem ERC20 on the destination?
25
+ bool redeem;
26
+ // recipient address
27
+ bytes32 to;
28
+ // recipient state machine
29
+ bytes dest;
30
+ // request timeout in seconds
31
+ uint64 timeout;
32
+ // Amount of native token to pay for dispatching the request
33
+ // if 0 will use the `IIsmpHost.feeToken`
34
+ uint256 nativeCost;
35
+ // destination contract call data
36
+ bytes data;
37
37
  }
38
38
 
39
39
  // Params for the TokenGateway contract
40
40
  struct TokenGatewayParams {
41
- // address of the IsmpHost contract on this chain
42
- address host;
43
- // dispatcher for delegating external calls
44
- address dispatcher;
41
+ // address of the IsmpHost contract on this chain
42
+ address host;
43
+ // dispatcher for delegating external calls
44
+ address dispatcher;
45
45
  }
46
46
 
47
47
  /**
@@ -55,88 +55,88 @@ struct TokenGatewayParams {
55
55
  * Otherwise if hyper-fungible tokens are sent, then it simply performs a burn-and-mint.
56
56
  */
57
57
  interface ITokenGateway {
58
- // User has received some assets
59
- event AssetReceived(
60
- // The amount that was provided to the user
61
- uint256 amount,
62
- // The associated request commitment
63
- bytes32 commitment,
64
- // The source of the funds
65
- bytes32 indexed from,
66
- // The beneficiary of the funds
67
- address indexed beneficiary,
68
- // The provided assetId
69
- bytes32 indexed assetId
70
- );
58
+ // User has received some assets
59
+ event AssetReceived(
60
+ // The amount that was provided to the user
61
+ uint256 amount,
62
+ // The associated request commitment
63
+ bytes32 commitment,
64
+ // The source of the funds
65
+ bytes32 indexed from,
66
+ // The beneficiary of the funds
67
+ address indexed beneficiary,
68
+ // The provided assetId
69
+ bytes32 indexed assetId
70
+ );
71
71
 
72
- // User has sent some assets
73
- event AssetTeleported(
74
- // The beneficiary of the funds
75
- bytes32 to,
76
- // The destination chain
77
- string dest,
78
- // The amount that was requested to be sent
79
- uint256 amount,
80
- // The associated request commitment
81
- bytes32 commitment,
82
- // The source of the funds
83
- address indexed from,
84
- // The provided assetId
85
- bytes32 indexed assetId,
86
- // Flag to redeem funds from the TokenGateway
87
- bool redeem
88
- );
72
+ // User has sent some assets
73
+ event AssetTeleported(
74
+ // The beneficiary of the funds
75
+ bytes32 to,
76
+ // The destination chain
77
+ string dest,
78
+ // The amount that was requested to be sent
79
+ uint256 amount,
80
+ // The associated request commitment
81
+ bytes32 commitment,
82
+ // The source of the funds
83
+ address indexed from,
84
+ // The provided assetId
85
+ bytes32 indexed assetId,
86
+ // Flag to redeem funds from the TokenGateway
87
+ bool redeem
88
+ );
89
89
 
90
- // User assets could not be delivered and have been refunded.
91
- event AssetRefunded(
92
- // The amount that was requested to be sent
93
- uint256 amount,
94
- // The associated request commitment
95
- bytes32 commitment,
96
- // The beneficiary of the funds
97
- address indexed beneficiary,
98
- // The provided assetId
99
- bytes32 indexed assetId
100
- );
90
+ // User assets could not be delivered and have been refunded.
91
+ event AssetRefunded(
92
+ // The amount that was requested to be sent
93
+ uint256 amount,
94
+ // The associated request commitment
95
+ bytes32 commitment,
96
+ // The beneficiary of the funds
97
+ address indexed beneficiary,
98
+ // The provided assetId
99
+ bytes32 indexed assetId
100
+ );
101
101
 
102
- // @dev Unexpected zero address
103
- error ZeroAddress();
102
+ // @dev Unexpected zero address
103
+ error ZeroAddress();
104
104
 
105
- // @dev Provided amount was invalid
106
- error InvalidAmount();
105
+ // @dev Provided amount was invalid
106
+ error InvalidAmount();
107
107
 
108
- // @dev Provided token was unknown
109
- error UnknownAsset();
108
+ // @dev Provided token was unknown
109
+ error UnknownAsset();
110
110
 
111
- // @dev Protocol invariant violated
112
- error InconsistentState();
111
+ // @dev Protocol invariant violated
112
+ error InconsistentState();
113
113
 
114
- /**
115
- * @dev Read the protocol parameters
116
- */
117
- function params() external view returns (TokenGatewayParams memory);
114
+ /**
115
+ * @dev Read the protocol parameters
116
+ */
117
+ function params() external view returns (TokenGatewayParams memory);
118
118
 
119
- /**
120
- * @dev Fetch the address for an ERC20 asset
121
- */
122
- function erc20(bytes32 assetId) external view returns (address);
119
+ /**
120
+ * @dev Fetch the address for an ERC20 asset
121
+ */
122
+ function erc20(bytes32 assetId) external view returns (address);
123
123
 
124
- /**
125
- * @dev Fetch the address for a hyper-fungible asset
126
- */
127
- function erc6160(bytes32 assetId) external view returns (address);
124
+ /**
125
+ * @dev Fetch the address for a hyper-fungible asset
126
+ */
127
+ function erc6160(bytes32 assetId) external view returns (address);
128
128
 
129
- /**
130
- * @dev Fetch the TokenGateway instance for a destination.
131
- */
132
- function instance(bytes calldata destination) external view returns (address);
129
+ /**
130
+ * @dev Fetch the TokenGateway instance for a destination.
131
+ */
132
+ function instance(bytes calldata destination) external view returns (address);
133
133
 
134
- /**
135
- * @dev Teleports a local ERC20/hyper-fungible asset to the destination chain. Allows users to pay
136
- * the Hyperbridge fees in the native token or `IIsmpHost.feeToken`
137
- *
138
- * @notice If a request times out, users can request a refund permissionlessly through
139
- * `HandlerV1.handlePostRequestTimeouts`.
140
- */
141
- function teleport(TeleportParams calldata teleportParams) external payable;
134
+ /**
135
+ * @dev Teleports a local ERC20/hyper-fungible asset to the destination chain. Allows users to pay
136
+ * the Hyperbridge fees in the native token or `IIsmpHost.feeToken`
137
+ *
138
+ * @notice If a request times out, users can request a refund permissionlessly through
139
+ * `HandlerV1.handlePostRequestTimeouts`.
140
+ */
141
+ function teleport(TeleportParams calldata teleportParams) external payable;
142
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbridge/core",
3
- "version": "1.3.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",