@@ -21,8 +21,8 @@ import {toUniversalAddress} from "wormhole-solidity-sdk/Utils.sol";
2121 * - Provides `quoteGreeting()` for on-chain cost estimation
2222 *
2323 * Supports both EVM and Solana destinations:
24- * - EVM: use `sendGreeting` / `quoteGreeting` (msgValue = 0 )
25- * - Solana: use `sendGreetingWithMsgValue ` / `quoteGreetingWithMsgValue`
24+ * - EVM: use `sendGreeting` / `quoteGreeting` (no msgValue )
25+ * - Solana: use overloaded `sendGreeting ` / `quoteGreeting` with msgValue param
2626 * (msgValue in lamports for rent/fees)
2727 */
2828contract HelloWormholeOnChainQuote is ExecutorSendReceiveQuoteOnChain , AccessControl {
@@ -122,11 +122,12 @@ contract HelloWormholeOnChainQuote is ExecutorSendReceiveQuoteOnChain, AccessCon
122122 greeting = string (payload);
123123 }
124124
125+ // Emit an event with the greeting message and sender details
125126 emit GreetingReceived (greeting, peerChain, peerAddress);
126127 }
127128
128129 /**
129- * @notice Get a quote for sending a greeting using on-chain quoter
130+ * @notice Get a quote for sending a greeting using on-chain quoter (EVM destinations)
130131 * @param targetChain The Wormhole chain ID of the destination
131132 * @param gasLimit Gas limit for execution on target chain
132133 * @param quoterAddress The on-chain quoter contract address
@@ -137,47 +138,51 @@ contract HelloWormholeOnChainQuote is ExecutorSendReceiveQuoteOnChain, AccessCon
137138 view
138139 returns (uint256 totalCost )
139140 {
140- require (targetChain != CHAIN_ID_SOLANA, "Use quoteGreetingWithMsgValue for Solana " );
141- return _quoteGreeting (targetChain, gasLimit, 0 , quoterAddress);
141+ return quoteGreeting (targetChain, gasLimit, 0 , quoterAddress);
142142 }
143143
144144 /**
145145 * @notice Get a quote for sending a greeting with msgValue (needed for Solana destinations)
146+ * @param targetChain The Wormhole chain ID of the destination
147+ * @param gasLimit Gas limit for execution on target chain
146148 * @param msgValue For Solana: lamports for rent/priority fees. For EVM: 0.
149+ * @param quoterAddress The on-chain quoter contract address
150+ * @return totalCost The total cost including Wormhole message fee and executor fee
147151 */
148- function quoteGreetingWithMsgValue (uint16 targetChain , uint128 gasLimit , uint128 msgValue , address quoterAddress )
149- external
150- view
151- returns (uint256 totalCost )
152- {
153- return _quoteGreeting (targetChain, gasLimit, msgValue, quoterAddress);
154- }
155-
156- function _quoteGreeting (uint16 targetChain , uint128 gasLimit , uint128 msgValue , address quoterAddress )
157- internal
152+ function quoteGreeting (uint16 targetChain , uint128 gasLimit , uint128 msgValue , address quoterAddress )
153+ public
158154 view
159155 returns (uint256 totalCost )
160156 {
161157 bytes32 peerAddress = peers[targetChain];
162158 require (peerAddress != bytes32 (0 ), "No peer set for target chain " );
163159
160+ // Build relay instructions
164161 bytes memory relayInstructions = RelayInstructionLib.encodeGas (gasLimit, msgValue);
165162
163+ // Build request bytes (same format as _publishAndCompose uses)
166164 bytes memory requestBytes = RequestLib.encodeVaaMultiSigRequest (
167165 _chainId,
168166 toUniversalAddress (address (this )),
169167 0 // sequence placeholder - not needed for quote
170168 );
171169
170+ // Get executor quote from on-chain quoter
172171 uint256 executorFee = _executorQuoterRouter.quoteExecution (
173- targetChain, peerAddress, address (0 ), quoterAddress, requestBytes, relayInstructions
172+ targetChain,
173+ peerAddress,
174+ address (0 ), // refund address not needed for quote
175+ quoterAddress,
176+ requestBytes,
177+ relayInstructions
174178 );
175179
180+ // Total = executor fee + Wormhole message fee
176181 totalCost = executorFee + _coreBridge.messageFee ();
177182 }
178183
179184 /**
180- * @notice Send a cross-chain greeting using on-chain quote
185+ * @notice Send a cross-chain greeting using on-chain quote (EVM destinations)
181186 * @param greeting The message to send
182187 * @param targetChain The Wormhole chain ID of the destination
183188 * @param gasLimit Gas limit for execution on target chain
@@ -192,49 +197,47 @@ contract HelloWormholeOnChainQuote is ExecutorSendReceiveQuoteOnChain, AccessCon
192197 uint256 totalCost ,
193198 address quoterAddress
194199 ) external payable returns (uint64 sequence ) {
195- require (targetChain != CHAIN_ID_SOLANA, "Use sendGreetingWithMsgValue for Solana " );
196- sequence = _sendGreeting (greeting, targetChain, gasLimit, 0 , totalCost, quoterAddress);
200+ sequence = sendGreeting (greeting, targetChain, gasLimit, 0 , totalCost, quoterAddress);
197201 }
198202
199203 /**
200204 * @notice Send a cross-chain greeting with msgValue (needed for Solana destinations)
205+ * @param greeting The message to send
206+ * @param targetChain The Wormhole chain ID of the destination
207+ * @param gasLimit Gas limit for execution on target chain
201208 * @param msgValue For Solana: lamports for rent/priority fees. For EVM: 0.
209+ * @param totalCost Total cost (Wormhole fee + executor fee from quoteGreeting)
210+ * @param quoterAddress The on-chain quoter contract address
211+ * @return sequence The Wormhole sequence number
202212 */
203- function sendGreetingWithMsgValue (
204- string calldata greeting ,
205- uint16 targetChain ,
206- uint128 gasLimit ,
207- uint128 msgValue ,
208- uint256 totalCost ,
209- address quoterAddress
210- ) external payable returns (uint64 sequence ) {
211- sequence = _sendGreeting (greeting, targetChain, gasLimit, msgValue, totalCost, quoterAddress);
212- }
213-
214- function _sendGreeting (
213+ function sendGreeting (
215214 string calldata greeting ,
216215 uint16 targetChain ,
217216 uint128 gasLimit ,
218217 uint128 msgValue ,
219218 uint256 totalCost ,
220219 address quoterAddress
221- ) internal returns (uint64 sequence ) {
220+ ) public payable returns (uint64 sequence ) {
221+ // Encode the greeting as bytes
222222 bytes memory payload = bytes (greeting);
223223
224+ // Solana enforces a 512-byte cap on incoming messages; fail early so the
225+ // relay fee is not spent on a delivery that will be rejected on Solana.
224226 if (targetChain == CHAIN_ID_SOLANA && payload.length > SOLANA_MAX_PAYLOAD_BYTES) {
225227 revert PayloadTooLargeForSolana (payload.length , SOLANA_MAX_PAYLOAD_BYTES);
226228 }
227229
230+ // Publish and relay the message to the target chain using on-chain quote
228231 sequence = _publishAndRelay (
229232 payload,
230233 CONSISTENCY_LEVEL_INSTANT,
231234 totalCost,
232235 targetChain,
233- msg .sender ,
234- quoterAddress,
236+ msg .sender , // refund address
237+ quoterAddress, // on-chain quoter instead of signedQuote
235238 gasLimit,
236239 msgValue,
237- ""
240+ "" // no extra relay instructions
238241 );
239242 emit GreetingSent (greeting, targetChain, sequence);
240243 }
0 commit comments