Skip to content

Commit e9ad978

Browse files
DEVREL-1009 fix: solana enforced options setter logic (#1867)
Co-authored-by: Shankar Subramanian <shankar@layerzerolabs.org>
1 parent 1136e94 commit e9ad978

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

.changeset/olive-eggs-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@layerzerolabs/ua-devtools-solana": patch
3+
---
4+
5+
Refactor enforced option setter on Solana to keep existing value rather than reset to null

packages/ua-devtools-solana/src/oft/sdk.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,24 @@ export class OFT extends OmniSDK implements IOApp {
294294
this.logger.verbose(`Setting enforced options to ${printJson(enforcedOptions)}`)
295295

296296
const optionsByEidAndMsgType = this.reduceEnforcedOptions(enforcedOptions)
297-
const emptyOptions = Options.newOptions().toBytes()
298297
const ixs: WrappedInstruction[] = []
298+
299299
for (const [eid, optionsByMsgType] of optionsByEidAndMsgType) {
300-
const sendOption = optionsByMsgType.get(MSG_TYPE_SEND) ?? emptyOptions
301-
const sendAndCallOption = optionsByMsgType.get(MSG_TYPE_SEND_AND_CALL) ?? emptyOptions
300+
// Helper to get option: from update map OR fetch from chain (safely)
301+
const getOption = async (msgType: MsgType) => {
302+
if (optionsByMsgType.has(msgType)) {
303+
return optionsByMsgType.get(msgType)!
304+
}
305+
const hex = await this.getEnforcedOptions(eid, msgType)
306+
return hex && hex !== '0x' ? Options.fromOptions(hex).toBytes() : Options.newOptions().toBytes()
307+
}
308+
309+
// Fetch both in parallel
310+
const [sendOption, sendAndCallOption] = await Promise.all([
311+
getOption(MSG_TYPE_SEND),
312+
getOption(MSG_TYPE_SEND_AND_CALL),
313+
])
314+
302315
ixs.push(await this._setPeerEnforcedOptionsIx(sendOption, sendAndCallOption, eid))
303316
}
304317

0 commit comments

Comments
 (0)