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

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @layerzerolabs/lz-solana-sdk-v2
2
2
 
3
+ ## 3.0.117
4
+
5
+ ### Patch Changes
6
+
7
+ - fd54ee9: fix bugs that caused TypeScript SDK to behave differently from Rust contracts.
8
+ - Updated dependencies [fd54ee9]
9
+ - @layerzerolabs/lz-corekit-solana@3.0.117
10
+ - @layerzerolabs/lz-definitions@3.0.117
11
+ - @layerzerolabs/lz-foundation@3.0.117
12
+ - @layerzerolabs/lz-serdes@3.0.117
13
+ - @layerzerolabs/lz-utilities@3.0.117
14
+ - @layerzerolabs/lz-v2-utilities@3.0.117
15
+
3
16
  ## 3.0.116
4
17
 
5
18
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -5918,7 +5918,7 @@ var sendLibrarySetEventBeet = new beet159__namespace.BeetArgsStruct(
5918
5918
  // src/solita/endpoint.ts
5919
5919
  var EventEmitDiscriminator = "e445a52e51cb9a1d";
5920
5920
  var DefaultMessageLib = web314.PublicKey.default;
5921
- var Endpoint = class {
5921
+ var Endpoint = class _Endpoint {
5922
5922
  /**
5923
5923
  * Creates an instance of the Endpoint class.
5924
5924
  *
@@ -6373,9 +6373,6 @@ var Endpoint = class {
6373
6373
  const sender = new web314.PublicKey(lzUtilities.arrayify(sender_));
6374
6374
  const receiver = lzV2Utilities.addressToBytes32(receiver_);
6375
6375
  const sendLibInfo = await this.getSendLibrary(connection, sender, dstEid);
6376
- if (!sendLibInfo?.programId) {
6377
- throw new Error("default send library not initialized or blocked message lib");
6378
- }
6379
6376
  const { msgLib, programId: owner } = sendLibInfo;
6380
6377
  const [sendLibraryInfo] = this.deriver.messageLibraryInfo(msgLib);
6381
6378
  const remainingAccounts = await msgLibProgram.getQuoteIXAccountMetaForCPI(connection, payer, path);
@@ -6421,9 +6418,6 @@ var Endpoint = class {
6421
6418
  const sender = new web314.PublicKey(lzUtilities.arrayify(sender_));
6422
6419
  const receiver = lzV2Utilities.addressToBytes32(receiver_);
6423
6420
  const info = await this.getSendLibrary(connection, sender, dstEid, commitmentOrConfig);
6424
- if (!info?.programId) {
6425
- throw new Error("default send library not initialized or blocked message lib");
6426
- }
6427
6421
  const sendLibrary = info.msgLib;
6428
6422
  const [sendLibraryInfo] = this.deriver.messageLibraryInfo(sendLibrary);
6429
6423
  const remainingAccounts = await msgLibProgram.getSendIXAccountMetaForCPI(connection, payer, path);
@@ -6879,7 +6873,7 @@ var Endpoint = class {
6879
6873
  * @param {Connection} connection - The connection to the Solana cluster.
6880
6874
  * @param {number} srcEid - The source endpoint ID.
6881
6875
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
6882
- * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default receive library or null if not found.
6876
+ * @returns {Promise<{ msgLib: PublicKey; owner: PublicKey } | null>} A promise that resolves to the default receive library or null if not found.
6883
6877
  */
6884
6878
  async getDefaultReceiveLibrary(connection, srcEid, commitmentOrConfig) {
6885
6879
  const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid);
@@ -6889,14 +6883,16 @@ var Endpoint = class {
6889
6883
  defaultReceiveLibConfig,
6890
6884
  commitmentOrConfig
6891
6885
  );
6892
- const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig);
6893
- if (!messageLibInfo) {
6894
- return {
6895
- msgLib: defaultInfo.messageLib
6896
- };
6886
+ let msgLibProgram;
6887
+ if (_Endpoint.checkIfBlockedMessageLib(defaultInfo.messageLib)) {
6888
+ msgLibProgram = blocked_messagelib_exports.PROGRAM_ID;
6889
+ } else {
6890
+ const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig);
6891
+ invariant3__default.default(messageLibInfo, "messageLibInfo should not be null");
6892
+ msgLibProgram = messageLibInfo.owner;
6897
6893
  }
6898
6894
  return {
6899
- owner: messageLibInfo.owner,
6895
+ owner: msgLibProgram,
6900
6896
  msgLib: defaultInfo.messageLib
6901
6897
  };
6902
6898
  } catch (e) {
@@ -6909,7 +6905,7 @@ var Endpoint = class {
6909
6905
  * @param {Connection} connection - The connection to the Solana cluster.
6910
6906
  * @param {number} dstEid - The destination endpoint ID.
6911
6907
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
6912
- * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default send library or null if not found.
6908
+ * @returns {Promise<{ msgLib: PublicKey; owner: PublicKey } | null>} A promise that resolves to the default send library or null if not found.
6913
6909
  */
6914
6910
  async getDefaultSendLibrary(connection, dstEid, commitmentOrConfig) {
6915
6911
  const [defaultSendLibConfig] = this.deriver.defaultSendLibraryConfig(dstEid);
@@ -6919,14 +6915,16 @@ var Endpoint = class {
6919
6915
  defaultSendLibConfig,
6920
6916
  commitmentOrConfig
6921
6917
  );
6922
- const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig);
6923
- if (!messageLibInfo) {
6924
- return {
6925
- msgLib: defaultInfo.messageLib
6926
- };
6918
+ let msgLibProgram;
6919
+ if (_Endpoint.checkIfBlockedMessageLib(defaultInfo.messageLib)) {
6920
+ msgLibProgram = blocked_messagelib_exports.PROGRAM_ID;
6921
+ } else {
6922
+ const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig);
6923
+ invariant3__default.default(messageLibInfo, "messageLibInfo should not be null");
6924
+ msgLibProgram = messageLibInfo.owner;
6927
6925
  }
6928
6926
  return {
6929
- owner: messageLibInfo.owner,
6927
+ owner: msgLibProgram,
6930
6928
  msgLib: defaultInfo.messageLib
6931
6929
  };
6932
6930
  } catch (e) {
@@ -6940,7 +6938,7 @@ var Endpoint = class {
6940
6938
  * @param {PublicKey} oappPda - The OApp PDA.
6941
6939
  * @param {number} dstEid - The destination endpoint ID.
6942
6940
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig='confirmed'] - The commitment level or account info configuration.
6943
- * @returns {Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean } | null>} A promise that resolves to the configured send library or null if not found.
6941
+ * @returns {Promise<{ msgLib: PublicKey; programId: PublicKey; isDefault: boolean } | null>} A promise that resolves to the configured send library or null if not found.
6944
6942
  */
6945
6943
  async getSendLibrary(connection, oappPda, dstEid, commitmentOrConfig = "confirmed") {
6946
6944
  const [sendLibConfig] = this.deriver.sendLibraryConfig(oappPda, dstEid);
@@ -6950,27 +6948,27 @@ var Endpoint = class {
6950
6948
  commitmentOrConfig
6951
6949
  );
6952
6950
  if (!defaultSendLibConfigBuf || !sendLibConfigBuf) {
6953
- console.warn("send library not initialized, return empty array");
6954
- return null;
6951
+ throw new Error(
6952
+ `Unable to find defaultSendLibraryConfig/sendLibraryConfig account at ${defaultSendLibConfig.toString()}/${sendLibConfig.toString()}`
6953
+ );
6955
6954
  }
6956
6955
  const [sendLibConfigInfo] = SendLibraryConfig.fromAccountInfo(sendLibConfigBuf, 0);
6957
6956
  const [defaultSendLibConfigInfo] = SendLibraryConfig.fromAccountInfo(defaultSendLibConfigBuf, 0);
6958
6957
  const msgLib = sendLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString() ? defaultSendLibConfigInfo.messageLib : sendLibConfigInfo.messageLib;
6959
6958
  const isDefault = sendLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString();
6960
- const msgLibInfo = await connection.getAccountInfo(msgLib, commitmentOrConfig);
6961
- if (!msgLibInfo) {
6962
- return {
6963
- programId: void 0,
6964
- msgLib,
6965
- isDefault
6966
- };
6959
+ let msgLibProgram;
6960
+ if (_Endpoint.checkIfBlockedMessageLib(msgLib)) {
6961
+ msgLibProgram = blocked_messagelib_exports.PROGRAM_ID;
6967
6962
  } else {
6968
- return {
6969
- programId: msgLibInfo.owner,
6970
- msgLib,
6971
- isDefault
6972
- };
6963
+ const msgLibAccountInfo = await connection.getAccountInfo(msgLib, commitmentOrConfig);
6964
+ invariant3__default.default(msgLibAccountInfo, "msgLibAccountInfo should not be null");
6965
+ msgLibProgram = msgLibAccountInfo.owner;
6973
6966
  }
6967
+ return {
6968
+ programId: msgLibProgram,
6969
+ msgLib,
6970
+ isDefault
6971
+ };
6974
6972
  }
6975
6973
  /**
6976
6974
  * Gets the configured receive library for the app.
@@ -6983,49 +6981,37 @@ var Endpoint = class {
6983
6981
  */
6984
6982
  async getReceiveLibrary(connection, oappPda, srcEid, commitmentOrConfig) {
6985
6983
  const [receiveLibConfig] = this.deriver.receiveLibraryConfig(oappPda, srcEid);
6986
- const accountInfo = await connection.getAccountInfo(receiveLibConfig, commitmentOrConfig);
6987
- if (accountInfo == null) {
6988
- return null;
6989
- }
6990
- const [info] = ReceiveLibraryConfig.fromAccountInfo(accountInfo, 0);
6991
- if (info.messageLib.toString() == DefaultMessageLib.toString()) {
6992
- const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid);
6993
- const defaultInfo = await ReceiveLibraryConfig.fromAccountAddress(
6994
- connection,
6995
- defaultReceiveLibConfig,
6996
- commitmentOrConfig
6984
+ const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid);
6985
+ const [defaultReceiveLibConfigBuf, receiveLibConfigBuf] = await connection.getMultipleAccountsInfo(
6986
+ [defaultReceiveLibConfig, receiveLibConfig],
6987
+ commitmentOrConfig
6988
+ );
6989
+ if (!defaultReceiveLibConfigBuf || !receiveLibConfigBuf) {
6990
+ throw new Error(
6991
+ `Unable to find defaultReceiveLibraryConfig/receiveLibraryConfig account at ${defaultReceiveLibConfig.toString()}/${receiveLibConfig.toString()}`
6997
6992
  );
6998
- const messageLibInfo2 = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig);
6999
- if (messageLibInfo2) {
7000
- const { timeout: timeout2 } = defaultInfo;
7001
- if (timeout2) {
7002
- return {
7003
- programId: defaultInfo.messageLib,
7004
- msgLib: defaultInfo.messageLib,
7005
- isDefault: true,
7006
- timeout: { msgLib: timeout2.messageLib, expiry: BigInt(timeout2.expiry.toString()) }
7007
- };
7008
- }
7009
- }
7010
- return {
7011
- programId: messageLibInfo2?.owner,
7012
- msgLib: defaultInfo.messageLib,
7013
- isDefault: true,
7014
- timeout: null
7015
- };
7016
6993
  }
7017
- const messageLibInfo = await connection.getAccountInfo(info.messageLib, commitmentOrConfig);
7018
- invariant3__default.default(messageLibInfo, "messageLibInfo should not be null");
7019
- const { timeout } = info;
7020
- if (timeout) {
7021
- return {
7022
- programId: messageLibInfo.owner,
7023
- msgLib: info.messageLib,
7024
- isDefault: false,
7025
- timeout: { msgLib: timeout.messageLib, expiry: BigInt(timeout.expiry.toString()) }
7026
- };
6994
+ const [receiveLibConfigInfo] = ReceiveLibraryConfig.fromAccountInfo(receiveLibConfigBuf, 0);
6995
+ const [defaultReceiveLibConfigInfo] = ReceiveLibraryConfig.fromAccountInfo(
6996
+ defaultReceiveLibConfigBuf,
6997
+ 0
6998
+ );
6999
+ const finalReceiveLibConfigInfo = receiveLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString() ? defaultReceiveLibConfigInfo : receiveLibConfigInfo;
7000
+ const { messageLib, timeout } = finalReceiveLibConfigInfo;
7001
+ let msgLibProgram;
7002
+ if (_Endpoint.checkIfBlockedMessageLib(messageLib)) {
7003
+ msgLibProgram = blocked_messagelib_exports.PROGRAM_ID;
7004
+ } else {
7005
+ const msgLibAccountInfo = await connection.getAccountInfo(messageLib, commitmentOrConfig);
7006
+ invariant3__default.default(msgLibAccountInfo, "msgLibAccountInfo should not be null");
7007
+ msgLibProgram = msgLibAccountInfo.owner;
7027
7008
  }
7028
- return { programId: messageLibInfo.owner, msgLib: info.messageLib, isDefault: false, timeout: null };
7009
+ return {
7010
+ programId: msgLibProgram,
7011
+ msgLib: messageLib,
7012
+ isDefault: receiveLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString(),
7013
+ timeout: timeout === null ? void 0 : { msgLib: timeout.messageLib, expiry: BigInt(timeout.expiry.toString()) }
7014
+ };
7029
7015
  }
7030
7016
  // rename to a more generic name
7031
7017
  /**
@@ -7154,6 +7140,10 @@ var Endpoint = class {
7154
7140
  this.program
7155
7141
  );
7156
7142
  }
7143
+ static checkIfBlockedMessageLib(msgLib) {
7144
+ const [blockedMessageLib] = new MessageLibPDADeriver(blocked_messagelib_exports.PROGRAM_ID).messageLib();
7145
+ return msgLib.toString() === blockedMessageLib.toString();
7146
+ }
7157
7147
  };
7158
7148
 
7159
7149
  // src/solita/simple-message-lib.ts
@@ -17416,30 +17406,14 @@ var Uln = class {
17416
17406
  );
17417
17407
  invariant3__default.default(defaultSendConfigBuf, "defaultSendConfig not initialized");
17418
17408
  const [defaultSendConfigState] = SendConfig.fromAccountInfo(defaultSendConfigBuf);
17419
- let {
17420
- executor,
17421
- uln: { requiredDvns, optionalDvns }
17422
- } = defaultSendConfigState;
17423
17409
  const sendConfigState = sendConfigBuf ? SendConfig.fromAccountInfo(sendConfigBuf)[0] : null;
17424
- if (sendConfigState?.executor && !sendConfigState.executor.executor.equals(web314.PublicKey.default)) {
17425
- ({ executor } = sendConfigState);
17426
- }
17427
- if (sendConfigState && sendConfigState.uln.requiredDvns.length > 0) {
17428
- requiredDvns = sendConfigState.uln.requiredDvns.filter((p) => {
17429
- return !p.equals(web314.PublicKey.default);
17430
- });
17431
- }
17432
- if (sendConfigState && sendConfigState.uln.optionalDvns.length > 0) {
17433
- optionalDvns = sendConfigState.uln.optionalDvns.filter((p) => {
17434
- return !p.equals(web314.PublicKey.default);
17435
- });
17436
- }
17410
+ const finalConfigState = this.getUlnConfigState(defaultSendConfigState, sendConfigState);
17411
+ const finalExecutorConfigState = this.getExecutorConfigState(defaultSendConfigState, sendConfigState);
17412
+ const { executor } = finalExecutorConfigState;
17413
+ const { requiredDvns, optionalDvns } = finalConfigState;
17437
17414
  const dvns = requiredDvns.concat(optionalDvns);
17438
- const [executorBuf, ...dvnBuf] = await connection.getMultipleAccountsInfo(
17439
- [executor.executor, ...dvns],
17440
- commitment
17441
- );
17442
- invariant3__default.default(executorBuf, `executor:${executor.executor.toBase58()} not initialized`);
17415
+ const [executorBuf, ...dvnBuf] = await connection.getMultipleAccountsInfo([executor, ...dvns], commitment);
17416
+ invariant3__default.default(executorBuf, `executor:${executor.toBase58()} not initialized`);
17443
17417
  return {
17444
17418
  executor: {
17445
17419
  config: accounts_exports4.ExecutorConfig.fromAccountInfo(executorBuf)[0],
@@ -17829,16 +17803,6 @@ var Uln = class {
17829
17803
  * @throws {Error} If no DVN is found.
17830
17804
  */
17831
17805
  async getFinalReceiveConfigState(connection, receiver, eid, commitmentOrConfig = "confirmed") {
17832
- const NIL_CONFIRMATIONS = "18446744073709551615";
17833
- const NIL_DVN_COUNT = "255";
17834
- const rtn_config = {
17835
- confirmations: 0,
17836
- requiredDvnCount: 0,
17837
- optionalDvnCount: 0,
17838
- optionalDvnThreshold: 0,
17839
- requiredDvns: [],
17840
- optionalDvns: []
17841
- };
17842
17806
  const [defaultConfig] = this.deriver.defaultReceiveConfig(eid);
17843
17807
  const [customConfig] = this.deriver.receiveConfig(eid, receiver);
17844
17808
  const [defaultConfigInfo, customConfigInfo] = await connection.getMultipleAccountsInfo(
@@ -17850,7 +17814,24 @@ var Uln = class {
17850
17814
  }
17851
17815
  const defaultConfigState = ReceiveConfig2.fromAccountInfo(defaultConfigInfo)[0];
17852
17816
  const customConfigState = customConfigInfo ? ReceiveConfig2.fromAccountInfo(customConfigInfo)[0] : null;
17853
- if (customConfigState == null || customConfigState.uln.confirmations == 0) {
17817
+ const ulnConfigState = this.getUlnConfigState(defaultConfigState, customConfigState);
17818
+ return ReceiveConfig2.fromArgs({
17819
+ bump: defaultConfigState.bump,
17820
+ uln: ulnConfigState
17821
+ });
17822
+ }
17823
+ getUlnConfigState(defaultConfigState, customConfigState) {
17824
+ const NIL_CONFIRMATIONS = "18446744073709551615";
17825
+ const NIL_DVN_COUNT = "255";
17826
+ const rtn_config = {
17827
+ confirmations: 0,
17828
+ requiredDvnCount: 0,
17829
+ optionalDvnCount: 0,
17830
+ optionalDvnThreshold: 0,
17831
+ requiredDvns: [],
17832
+ optionalDvns: []
17833
+ };
17834
+ if (customConfigState == null || customConfigState.uln.confirmations.toString() === "0") {
17854
17835
  rtn_config.confirmations = defaultConfigState.uln.confirmations;
17855
17836
  } else if (customConfigState.uln.confirmations.toString() !== NIL_CONFIRMATIONS) {
17856
17837
  rtn_config.confirmations = customConfigState.uln.confirmations;
@@ -17878,10 +17859,24 @@ var Uln = class {
17878
17859
  if (rtn_config.requiredDvnCount === 0 && rtn_config.optionalDvnCount === 0) {
17879
17860
  throw new Error("no dvn");
17880
17861
  }
17881
- return ReceiveConfig2.fromArgs({
17882
- bump: defaultConfigState.bump,
17883
- uln: rtn_config
17884
- });
17862
+ return rtn_config;
17863
+ }
17864
+ getExecutorConfigState(defaultConfigState, customConfigState) {
17865
+ const rtn_config = {
17866
+ maxMessageSize: 0,
17867
+ executor: web314.PublicKey.default
17868
+ };
17869
+ if (customConfigState == null || customConfigState.executor.executor.equals(web314.PublicKey.default)) {
17870
+ rtn_config.executor = defaultConfigState.executor.executor;
17871
+ } else {
17872
+ rtn_config.executor = customConfigState.executor.executor;
17873
+ }
17874
+ if (customConfigState == null || customConfigState.executor.maxMessageSize === 0) {
17875
+ rtn_config.maxMessageSize = defaultConfigState.executor.maxMessageSize;
17876
+ } else {
17877
+ rtn_config.maxMessageSize = customConfigState.executor.maxMessageSize;
17878
+ }
17879
+ return rtn_config;
17885
17880
  }
17886
17881
  };
17887
17882