@@ -4,12 +4,9 @@ pragma solidity ^0.8.0;
4
4
5
5
import "../../interfaces/relayer/IWormholeReceiver.sol " ;
6
6
import "../../interfaces/IWormhole.sol " ;
7
- import "../../interfaces/relayer/IRelayProvider.sol " ;
8
7
import "../../interfaces/relayer/IForwardInstructionViewer.sol " ;
9
8
import "../../interfaces/relayer/IWormholeRelayerInternalStructs.sol " ;
10
9
import "../../interfaces/relayer/IForwardWrapper.sol " ;
11
- import "../../interfaces/relayer/IWormholeReceiver.sol " ;
12
- import "../../interfaces/relayer/IRelayProvider.sol " ;
13
10
import {CoreRelayerLibrary} from "../coreRelayer/CoreRelayerLibrary.sol " ;
14
11
15
12
contract ForwardWrapper is CoreRelayerLibrary {
@@ -31,18 +28,21 @@ contract ForwardWrapper is CoreRelayerLibrary {
31
28
// Calls the 'receiveWormholeMessages' endpoint on the contract 'instruction.targetAddress'
32
29
// (with the gas limit and value specified in instruction, and 'encodedVMs' as the input)
33
30
bytes memory returnData;
34
- (callToTargetContractSucceeded, returnData) = forwardInstructionViewer.fromWormholeFormat (instruction.targetAddress).call {
35
- gas: instruction.executionParameters.gasLimit,
36
- value: instruction.receiverValueTarget
37
- }(abi.encodeWithSelector (IWormholeReceiver.receiveWormholeMessages.selector , data, signedVaas));
31
+ (callToTargetContractSucceeded, returnData) = forwardInstructionViewer.fromWormholeFormat (
32
+ instruction.targetAddress
33
+ ).call {gas: instruction.executionParameters.gasLimit, value: instruction.receiverValueTarget}(
34
+ abi.encodeWithSelector (IWormholeReceiver.receiveWormholeMessages.selector , data, signedVaas)
35
+ );
38
36
39
37
uint256 postGas = gasleft ();
40
38
41
39
returnDataTruncated = callToTargetContractSucceeded ? bytes ("" ) : truncateReturnData (returnData);
42
40
// Calculate the amount of gas used in the call (upperbounding at the gas limit, which shouldn't have been exceeded)
43
- gasUsed = uint32 ((preGas - postGas) > instruction.executionParameters.gasLimit
44
- ? instruction.executionParameters.gasLimit
45
- : (preGas - postGas));
41
+ gasUsed = uint32 (
42
+ (preGas - postGas) > instruction.executionParameters.gasLimit
43
+ ? instruction.executionParameters.gasLimit
44
+ : (preGas - postGas)
45
+ );
46
46
47
47
// Calculate the amount of maxTransactionFee to refund (multiply the maximum refund by the fraction of gas unused)
48
48
uint256 transactionFeeRefundAmount = (instruction.executionParameters.gasLimit - gasUsed)
@@ -68,11 +68,25 @@ contract ForwardWrapper is CoreRelayerLibrary {
68
68
}
69
69
}
70
70
71
- function safeRelayProviderSupportsChain (IRelayProvider relayProvider , uint16 chainId )
72
- external
73
- view
74
- returns (bool isSupported )
75
- {
76
- return relayProvider.isChainSupported (chainId);
71
+ function getValuesFromRelayProvider (
72
+ address providerAddress ,
73
+ uint16 sourceChain ,
74
+ uint16 targetChain ,
75
+ uint256 receiverValuePlusOverhead
76
+ ) public view returns (address rewardAddress , uint256 maximumBudget , uint256 receiverValueTarget ) {
77
+ IRelayProvider relayProvider = IRelayProvider (providerAddress);
78
+ require (relayProvider.isChainSupported (targetChain));
79
+ uint256 deliveryOverhead = relayProvider.quoteDeliveryOverhead (targetChain);
80
+ rewardAddress = relayProvider.getRewardAddress ();
81
+ maximumBudget = relayProvider.quoteMaximumBudget (targetChain);
82
+ uint256 srcNativeCurrencyPrice = relayProvider.quoteAssetPrice (sourceChain);
83
+ uint256 dstNativeCurrencyPrice = relayProvider.quoteAssetPrice (targetChain);
84
+ (uint16 buffer , uint16 denominator ) = relayProvider.getAssetConversionBuffer (targetChain);
85
+ receiverValueTarget = receiverValuePlusOverhead > deliveryOverhead
86
+ ? (
87
+ (receiverValuePlusOverhead - deliveryOverhead) * srcNativeCurrencyPrice * denominator
88
+ / (dstNativeCurrencyPrice * (uint256 (0 ) + denominator + buffer))
89
+ )
90
+ : 0 ;
77
91
}
78
92
}
0 commit comments