@@ -30,23 +30,27 @@ library RouteStore {
3030 /**
3131 * @dev Network info stored in the Gateway Contract
3232 * @param gasLimit The maximum amount of gas we allow on this particular network.
33- * @param relativeGasPrice Gas price of destination chain, in terms of the source chain token.
33+ * @param relativeGasPriceNumerator Gas price of destination chain, in terms of the source chain token.
34+ * @param relativeGasPriceDenominator Gas price of destination chain, in terms of the source chain token.
3435 * @param baseFee Base fee for cross-chain message approval on destination, in terms of source native gas token.
3536 */
3637 struct NetworkInfo {
38+ bytes32 gateway;
3739 uint64 gasLimit;
38- UFloat9x56 relativeGasPrice;
3940 uint128 baseFee;
41+ uint256 relativeGasPriceNumerator;
42+ uint256 relativeGasPriceDenominator;
4043 }
4144
4245 /**
4346 * @dev Emitted when a route is updated.
4447 * @param networkId Network identifier.
45- * @param relativeGasPrice Gas price of destination chain, in terms of the source chain token.
48+ * @param relativeGasPriceNumerator Gas price of destination chain, in terms of the source chain token.
49+ * @param relativeGasPriceDenominator Gas price of destination chain, in terms of the source chain token.
4650 * @param baseFee Base fee for cross-chain message approval on destination, in terms of source native gas token.
4751 * @param gasLimit The maximum amount of gas we allow on this particular network.
4852 */
49- event RouteUpdated (uint16 indexed networkId , UFloat9x56 relativeGasPrice , uint128 baseFee , uint64 gasLimit );
53+ event RouteUpdated (uint16 indexed networkId , uint256 relativeGasPriceNumerator , uint256 relativeGasPriceDenominator , uint128 baseFee , uint64 gasLimit );
5054
5155 /**
5256 * @dev Shard info stored in the Gateway Contract
@@ -169,13 +173,12 @@ library RouteStore {
169173
170174 // Update relative gas price and base fee if any of them are greater than zero
171175 if (route.relativeGasPriceDenominator > 0 ) {
172- UFloat9x56 relativeGasPrice =
173- UFloatMath.fromRational (route.relativeGasPriceNumerator, route.relativeGasPriceDenominator);
174- stored.relativeGasPrice = relativeGasPrice;
176+ stored.relativeGasPriceNumerator = route.relativeGasPriceNumerator;
177+ stored.relativeGasPriceDenominator = route.relativeGasPriceDenominator;
175178 stored.baseFee = route.baseFee;
176179 }
177180
178- emit RouteUpdated (route.networkId.asUint (), stored.relativeGasPrice , stored.baseFee, stored.gasLimit);
181+ emit RouteUpdated (route.networkId.asUint (), stored.relativeGasPriceNumerator, stored.relativeGasPriceDenominator , stored.baseFee, stored.gasLimit);
179182 }
180183
181184 /**
@@ -191,7 +194,8 @@ library RouteStore {
191194 require (created, "network already initialized " );
192195 require (network.id != networkdID.asUint () || network.gateway == address (this ), "wrong gateway address " );
193196 info.gasLimit = 15_000_000 ; // Default to 15M gas
194- info.relativeGasPrice = UFloatMath.ONE;
197+ info.relativeGasPriceNumerator = 1 ;
198+ info.relativeGasPriceDenominator = 1 ;
195199 info.baseFee = 0 ;
196200 }
197201 }
@@ -208,16 +212,16 @@ library RouteStore {
208212 bytes32 [] memory idx = store.routes.keys;
209213 Route[] memory routes = new Route [](idx.length );
210214 for (uint256 i = 0 ; i < idx.length ; i++ ) {
211- (bool success , NetworkInfo storage route ) = tryGet (store, NetworkID.wrap (uint16 (uint256 (idx[i]))));
215+ NetworkID networkId = NetworkID.wrap (uint16 (uint256 (idx[i])));
216+ (bool success , NetworkInfo storage route ) = tryGet (store, networkId);
212217 require (success, "route not found " );
213- (uint256 numerator , uint256 denominator ) = route.relativeGasPrice.toRational ();
214218 routes[i] = Route ({
215- networkId: NetworkID. wrap ( uint16 ( uint256 (idx[i]))) ,
219+ networkId: networkId ,
216220 gasLimit: route.gasLimit,
217221 baseFee: route.baseFee,
218- gateway: bytes32 ( uint256 ( uint160 ( address ( this )))) ,
219- relativeGasPriceNumerator: numerator ,
220- relativeGasPriceDenominator: denominator
222+ gateway: route.gateway ,
223+ relativeGasPriceNumerator: route.relativeGasPriceNumerator ,
224+ relativeGasPriceDenominator: route.relativeGasPriceDenominator
221225 });
222226 }
223227 return routes;
@@ -228,7 +232,7 @@ library RouteStore {
228232 */
229233 function _checkPreconditions (NetworkInfo memory route , uint256 messageSize , uint256 gasLimit ) private pure {
230234 // Verify if the network exists
231- require (route.baseFee > 0 || UFloat9x56. unwrap ( route.relativeGasPrice) > 0 , "route is temporarily disabled " );
235+ require (route.baseFee > 0 || route.relativeGasPriceDenominator > 0 , "route is temporarily disabled " );
232236
233237 // Verify if the gas limit and message size are within the limits
234238 require (gasLimit <= route.gasLimit, "gas limit exceeded " );
@@ -254,22 +258,7 @@ library RouteStore {
254258 gasCost = GasUtils.estimateGas (uint16 (nonZeros), uint16 (zeros), gasLimit);
255259
256260 // Calculate the gas cost: gasPrice * gasCost + baseFee
257- fee = UFloatMath.saturatingMul (route.relativeGasPrice, gasCost).saturatingAdd (route.baseFee);
258- }
259-
260- /**
261- * @dev Utility function for measure the wei cost of a GMP message.
262- */
263- function estimateWeiCost (NetworkInfo memory route , bytes calldata data , uint256 gasLimit )
264- internal
265- pure
266- returns (uint256 )
267- {
268- _checkPreconditions (route, data.length , gasLimit);
269- uint256 nonZeros = GasUtils.countNonZerosCalldata (data);
270- uint256 zeros = data.length - nonZeros;
271- return
272- GasUtils.estimateWeiCost (route.relativeGasPrice, route.baseFee, uint16 (nonZeros), uint16 (zeros), gasLimit);
261+ fee = route.relativeGasPriceNumerator.saturatingMul (gasCost).saturatingDiv (route.relativeGasPriceDenominator).saturatingAdd (route.baseFee);
273262 }
274263
275264 /**
@@ -281,6 +270,9 @@ library RouteStore {
281270 returns (uint256 )
282271 {
283272 _checkPreconditions (route, messageSize, gasLimit);
284- return GasUtils.estimateWeiCost (route.relativeGasPrice, route.baseFee, uint16 (messageSize), 0 , gasLimit);
273+
274+ UFloat9x56 relativeGasPrice =
275+ UFloatMath.fromRational (route.relativeGasPriceNumerator, route.relativeGasPriceDenominator);
276+ return GasUtils.estimateWeiCost (relativeGasPrice, route.baseFee, uint16 (messageSize), 0 , gasLimit);
285277 }
286278}
0 commit comments