@layerzerolabs/lz-solana-sdk-v2 3.0.116 → 3.0.118

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.
package/src/solita/uln.ts CHANGED
@@ -482,36 +482,16 @@ export class Uln implements MessageLibInterface {
482
482
  invariant(defaultSendConfigBuf, 'defaultSendConfig not initialized')
483
483
 
484
484
  const [defaultSendConfigState] = accounts.SendConfig.fromAccountInfo(defaultSendConfigBuf)
485
- let {
486
- executor,
487
- uln: { requiredDvns, optionalDvns },
488
- } = defaultSendConfigState
489
485
  const sendConfigState = sendConfigBuf ? accounts.SendConfig.fromAccountInfo(sendConfigBuf)[0] : null
486
+ const finalConfigState = this.getUlnConfigState(defaultSendConfigState, sendConfigState)
487
+ const finalExecutorConfigState = this.getExecutorConfigState(defaultSendConfigState, sendConfigState)
490
488
 
491
- // if the executor is set in the send config, use it
492
- if (sendConfigState?.executor && !sendConfigState.executor.executor.equals(PublicKey.default)) {
493
- ;({ executor } = sendConfigState)
494
- }
495
-
496
- // if the requiredDvns is set in the send config, use it
497
- if (sendConfigState && sendConfigState.uln.requiredDvns.length > 0) {
498
- requiredDvns = sendConfigState.uln.requiredDvns.filter((p) => {
499
- return !p.equals(PublicKey.default)
500
- })
501
- }
489
+ const { executor } = finalExecutorConfigState
490
+ const { requiredDvns, optionalDvns } = finalConfigState
502
491
 
503
- // if the optionalDvns is set in the send config, use it
504
- if (sendConfigState && sendConfigState.uln.optionalDvns.length > 0) {
505
- optionalDvns = sendConfigState.uln.optionalDvns.filter((p) => {
506
- return !p.equals(PublicKey.default)
507
- })
508
- }
509
492
  const dvns = requiredDvns.concat(optionalDvns)
510
- const [executorBuf, ...dvnBuf] = await connection.getMultipleAccountsInfo(
511
- [executor.executor, ...dvns],
512
- commitment
513
- )
514
- invariant(executorBuf, `executor:${executor.executor.toBase58()} not initialized`)
493
+ const [executorBuf, ...dvnBuf] = await connection.getMultipleAccountsInfo([executor, ...dvns], commitment)
494
+ invariant(executorBuf, `executor:${executor.toBase58()} not initialized`)
515
495
 
516
496
  return {
517
497
  executor: {
@@ -980,18 +960,6 @@ export class Uln implements MessageLibInterface {
980
960
  eid: number,
981
961
  commitmentOrConfig: Commitment | GetAccountInfoConfig = 'confirmed'
982
962
  ): Promise<accounts.ReceiveConfig> {
983
- const NIL_CONFIRMATIONS = '18446744073709551615' // max u64
984
- const NIL_DVN_COUNT = '255'
985
-
986
- const rtn_config: types.UlnConfig = {
987
- confirmations: 0,
988
- requiredDvnCount: 0,
989
- optionalDvnCount: 0,
990
- optionalDvnThreshold: 0,
991
- requiredDvns: [],
992
- optionalDvns: [],
993
- }
994
-
995
963
  const [defaultConfig] = this.deriver.defaultReceiveConfig(eid)
996
964
  const [customConfig] = this.deriver.receiveConfig(eid, receiver)
997
965
 
@@ -1005,7 +973,30 @@ export class Uln implements MessageLibInterface {
1005
973
  const defaultConfigState = accounts.ReceiveConfig.fromAccountInfo(defaultConfigInfo)[0]
1006
974
  const customConfigState = customConfigInfo ? accounts.ReceiveConfig.fromAccountInfo(customConfigInfo)[0] : null
1007
975
 
1008
- if (customConfigState == null || customConfigState.uln.confirmations == 0) {
976
+ const ulnConfigState = this.getUlnConfigState(defaultConfigState, customConfigState)
977
+ return accounts.ReceiveConfig.fromArgs({
978
+ bump: defaultConfigState.bump,
979
+ uln: ulnConfigState,
980
+ })
981
+ }
982
+
983
+ private getUlnConfigState(
984
+ defaultConfigState: accounts.ReceiveConfig | accounts.SendConfig,
985
+ customConfigState: accounts.ReceiveConfig | accounts.SendConfig | null
986
+ ): types.UlnConfig {
987
+ const NIL_CONFIRMATIONS = '18446744073709551615' // max uint64
988
+ const NIL_DVN_COUNT = '255'
989
+
990
+ const rtn_config: types.UlnConfig = {
991
+ confirmations: 0,
992
+ requiredDvnCount: 0,
993
+ optionalDvnCount: 0,
994
+ optionalDvnThreshold: 0,
995
+ requiredDvns: [],
996
+ optionalDvns: [],
997
+ }
998
+
999
+ if (customConfigState == null || customConfigState.uln.confirmations.toString() === '0') {
1009
1000
  rtn_config.confirmations = defaultConfigState.uln.confirmations
1010
1001
  } else if (customConfigState.uln.confirmations.toString() !== NIL_CONFIRMATIONS) {
1011
1002
  rtn_config.confirmations = customConfigState.uln.confirmations
@@ -1036,10 +1027,30 @@ export class Uln implements MessageLibInterface {
1036
1027
  if (rtn_config.requiredDvnCount === 0 && rtn_config.optionalDvnCount === 0) {
1037
1028
  throw new Error('no dvn')
1038
1029
  }
1030
+ return rtn_config
1031
+ }
1039
1032
 
1040
- return accounts.ReceiveConfig.fromArgs({
1041
- bump: defaultConfigState.bump,
1042
- uln: rtn_config,
1043
- })
1033
+ private getExecutorConfigState(
1034
+ defaultConfigState: accounts.SendConfig,
1035
+ customConfigState: accounts.SendConfig | null
1036
+ ): types.ExecutorConfig {
1037
+ const rtn_config: types.ExecutorConfig = {
1038
+ maxMessageSize: 0,
1039
+ executor: PublicKey.default,
1040
+ }
1041
+
1042
+ if (customConfigState == null || customConfigState.executor.executor.equals(PublicKey.default)) {
1043
+ rtn_config.executor = defaultConfigState.executor.executor
1044
+ } else {
1045
+ rtn_config.executor = customConfigState.executor.executor
1046
+ }
1047
+
1048
+ if (customConfigState == null || customConfigState.executor.maxMessageSize === 0) {
1049
+ rtn_config.maxMessageSize = defaultConfigState.executor.maxMessageSize
1050
+ } else {
1051
+ rtn_config.maxMessageSize = customConfigState.executor.maxMessageSize
1052
+ }
1053
+
1054
+ return rtn_config
1044
1055
  }
1045
1056
  }
package/src/uln.ts CHANGED
@@ -571,35 +571,18 @@ export class Uln implements MessageLibInterface {
571
571
  invariant(defaultSendConfigBuf.exists, 'defaultSendConfig not initialized')
572
572
 
573
573
  const defaultSendConfigState = accounts.deserializeSendConfig(defaultSendConfigBuf)
574
- let {
575
- executor,
576
- uln: { requiredDvns, optionalDvns },
577
- } = defaultSendConfigState
578
574
  const sendConfigState = sendConfigBuf.exists ? accounts.deserializeSendConfig(sendConfigBuf) : null
579
575
 
580
- // if the executor is set in the send config, use it
581
- if (sendConfigState?.executor && sendConfigState.executor.executor !== defaultPublicKey()) {
582
- ;({ executor } = sendConfigState)
583
- }
576
+ const finalConfigState = this.getUlnConfigState(defaultSendConfigState, sendConfigState)
577
+ const finalExecutorConfigState = this.getExecutorConfigState(defaultSendConfigState, sendConfigState)
584
578
 
585
- // if the requiredDvns is set in the send config, use it
586
- if (sendConfigState && sendConfigState.uln.requiredDvns.length > 0) {
587
- requiredDvns = sendConfigState.uln.requiredDvns.filter((p) => {
588
- return p !== defaultPublicKey()
589
- })
590
- }
591
-
592
- // if the optionalDvns is set in the send config, use it
593
- if (sendConfigState && sendConfigState.uln.optionalDvns.length > 0) {
594
- optionalDvns = sendConfigState.uln.optionalDvns.filter((p) => {
595
- return p !== defaultPublicKey()
596
- })
597
- }
579
+ const { requiredDvns, optionalDvns } = finalConfigState
580
+ const { executor } = finalExecutorConfigState
598
581
  const dvns = requiredDvns.concat(optionalDvns)
599
- const [executorBuf, ...dvnBuf] = await rpc.getAccounts([executor.executor, ...dvns], {
582
+ const [executorBuf, ...dvnBuf] = await rpc.getAccounts([executor, ...dvns], {
600
583
  commitment,
601
584
  })
602
- invariant(executorBuf.exists, `executor:${executor.executor} not initialized`)
585
+ invariant(executorBuf.exists, `executor:${executor} not initialized`)
603
586
 
604
587
  return {
605
588
  executor: {
@@ -999,7 +982,7 @@ export class Uln implements MessageLibInterface {
999
982
  }
1000
983
  const defaultConfigState = accounts.deserializeReceiveConfig(defaultConfigInfo)
1001
984
  const customConfigState = customConfigInfo.exists ? accounts.deserializeReceiveConfig(customConfigInfo) : null
1002
- return this.getConfigState(defaultConfigState, customConfigState)
985
+ return this.getUlnConfigState(defaultConfigState, customConfigState)
1003
986
  }
1004
987
 
1005
988
  async getFinalSendConfigState(
@@ -1019,10 +1002,10 @@ export class Uln implements MessageLibInterface {
1019
1002
  }
1020
1003
  const defaultConfigState = accounts.deserializeSendConfig(defaultConfigInfo)
1021
1004
  const customConfigState = customConfigInfo.exists ? accounts.deserializeSendConfig(customConfigInfo) : null
1022
- return this.getConfigState(defaultConfigState, customConfigState)
1005
+ return this.getUlnConfigState(defaultConfigState, customConfigState)
1023
1006
  }
1024
1007
 
1025
- private getConfigState(
1008
+ private getUlnConfigState(
1026
1009
  defaultConfigState: accounts.ReceiveConfig | accounts.SendConfig,
1027
1010
  customConfigState: accounts.ReceiveConfig | accounts.SendConfig | null
1028
1011
  ): types.UlnConfig {
@@ -1071,4 +1054,28 @@ export class Uln implements MessageLibInterface {
1071
1054
  }
1072
1055
  return rtn_config
1073
1056
  }
1057
+
1058
+ private getExecutorConfigState(
1059
+ defaultConfigState: accounts.SendConfig,
1060
+ customConfigState: accounts.SendConfig | null
1061
+ ): types.ExecutorConfig {
1062
+ const rtn_config: types.ExecutorConfig = {
1063
+ maxMessageSize: 0,
1064
+ executor: defaultPublicKey(),
1065
+ }
1066
+
1067
+ if (customConfigState == null || customConfigState.executor.executor === defaultPublicKey()) {
1068
+ rtn_config.executor = defaultConfigState.executor.executor
1069
+ } else {
1070
+ rtn_config.executor = customConfigState.executor.executor
1071
+ }
1072
+
1073
+ if (customConfigState == null || customConfigState.executor.maxMessageSize === 0) {
1074
+ rtn_config.maxMessageSize = defaultConfigState.executor.maxMessageSize
1075
+ } else {
1076
+ rtn_config.maxMessageSize = customConfigState.executor.maxMessageSize
1077
+ }
1078
+
1079
+ return rtn_config
1080
+ }
1074
1081
  }