@layerzerolabs/lz-solana-sdk-v2 2.3.11 → 2.3.12

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/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as web370 from '@solana/web3.js';
2
2
  import web370__default, { PublicKey, Keypair, AddressLookupTableProgram, VersionedTransaction, TransactionMessage, NONCE_ACCOUNT_LENGTH, Transaction, SystemProgram, NonceAccount, TransactionInstruction } from '@solana/web3.js';
3
- import { BN as BN$1 } from 'bn.js';
3
+ import BN3, { BN as BN$1 } from 'bn.js';
4
4
  import { BN } from '@coral-xyz/anchor';
5
5
  import * as beet158 from '@metaplex-foundation/beet';
6
6
  import { uniformFixedSizeArray, u8, FixableBeetArgsStruct, u32, u64, bytes, u16, BeetArgsStruct, bool, array } from '@metaplex-foundation/beet';
@@ -6061,7 +6061,7 @@ var Endpoint = class {
6061
6061
  const [sendLibraryConfig] = this.endpointDeriver.sendLibraryConfig(oappIDPDA2, dstEid);
6062
6062
  const [sendLibraryInfo] = this.endpointDeriver.messageLibraryInfo(newSendLib);
6063
6063
  const [oappRegistry] = this.endpointDeriver.oappRegistry(oappIDPDA2);
6064
- return createSetSendLibraryInstruction(
6064
+ const ix = createSetSendLibraryInstruction(
6065
6065
  {
6066
6066
  signer: oappAdmin,
6067
6067
  sendLibraryConfig,
@@ -6079,6 +6079,7 @@ var Endpoint = class {
6079
6079
  },
6080
6080
  this.program
6081
6081
  );
6082
+ return Promise.resolve(ix);
6082
6083
  }
6083
6084
  async initReceiveLibrary(connection, delegate, receiver, srcEid, commitmentOrConfig) {
6084
6085
  const [oappRegistry] = this.endpointDeriver.oappRegistry(receiver);
@@ -6107,7 +6108,7 @@ var Endpoint = class {
6107
6108
  const [receiveLibraryConfig] = this.endpointDeriver.receiveLibraryConfig(oappIDPDA2, srcEid);
6108
6109
  const [receiveLibraryInfo] = this.endpointDeriver.messageLibraryInfo(newReceiveLib);
6109
6110
  const [oappRegistry] = this.endpointDeriver.oappRegistry(oappIDPDA2);
6110
- return createSetReceiveLibraryInstruction(
6111
+ const ix = createSetReceiveLibraryInstruction(
6111
6112
  {
6112
6113
  signer: oappAdmin,
6113
6114
  receiveLibraryConfig,
@@ -6126,18 +6127,21 @@ var Endpoint = class {
6126
6127
  },
6127
6128
  this.program
6128
6129
  );
6130
+ return Promise.resolve(ix);
6129
6131
  }
6130
6132
  async setOappConfig(connection, oappDelegate, oappID, msgLibProgram, eid, config, commitment = "confirmed") {
6131
6133
  const [msgLib] = new MessageLibPDADeriver(msgLibProgram).messageLib();
6132
6134
  const [msgLibInfo] = this.endpointDeriver.messageLibraryInfo(msgLib);
6133
6135
  const msgLibVersion = await this.getMessageLibVersion(connection, oappDelegate, msgLibProgram, commitment);
6134
6136
  let msgLibClient;
6135
- if (msgLibVersion?.major.toString() === "0" && msgLibVersion?.minor == 0 && msgLibVersion?.endpointVersion == 2) {
6137
+ if (msgLibVersion?.major.toString() === "0" && msgLibVersion.minor == 0 && msgLibVersion.endpointVersion == 2) {
6136
6138
  msgLibClient = new simple_message_lib_exports.SimpleMessageLib(msgLibProgram);
6137
- } else if (msgLibVersion?.major.toString() === "3" && msgLibVersion?.minor == 0 && msgLibVersion?.endpointVersion == 2) {
6139
+ } else if (msgLibVersion?.major.toString() === "3" && msgLibVersion.minor == 0 && msgLibVersion.endpointVersion == 2) {
6138
6140
  msgLibClient = new uln_exports.Uln(msgLibProgram);
6139
6141
  } else {
6140
- throw new Error(`unsupported message lib version ${msgLibVersion?.major}.${msgLibVersion?.minor}`);
6142
+ throw new Error(
6143
+ `unsupported message lib version ${msgLibVersion?.major.toString()}.${msgLibVersion?.minor.toString()}`
6144
+ );
6141
6145
  }
6142
6146
  const [oappRegistry] = this.endpointDeriver.oappRegistry(oappID);
6143
6147
  const ix = createSetConfigInstruction(
@@ -6201,17 +6205,15 @@ var Endpoint = class {
6201
6205
  },
6202
6206
  this.program
6203
6207
  );
6204
- return new Promise((resolve) => {
6205
- resolve(
6206
- [
6207
- {
6208
- pubkey: this.program,
6209
- isSigner: false,
6210
- isWritable: false
6211
- }
6212
- ].concat(accounts)
6213
- );
6214
- });
6208
+ return Promise.resolve(
6209
+ [
6210
+ {
6211
+ pubkey: this.program,
6212
+ isSigner: false,
6213
+ isWritable: false
6214
+ }
6215
+ ].concat(accounts)
6216
+ );
6215
6217
  }
6216
6218
  /***
6217
6219
  * Get the account meta of the send instruction for CPI(Cross-Program Invocation )
@@ -6266,7 +6268,7 @@ var Endpoint = class {
6266
6268
  [Buffer.from(OAPP_SEED, "utf-8"), receiver.toBuffer()],
6267
6269
  this.program
6268
6270
  );
6269
- return createSkipInstruction(
6271
+ const ix = createSkipInstruction(
6270
6272
  {
6271
6273
  signer: payer,
6272
6274
  oappRegistry: oAppRegistry,
@@ -6282,11 +6284,12 @@ var Endpoint = class {
6282
6284
  receiver,
6283
6285
  srcEid,
6284
6286
  sender: Array.from(sender.toBytes()),
6285
- nonce
6287
+ nonce: new BN3(nonce)
6286
6288
  }
6287
6289
  },
6288
6290
  this.program
6289
6291
  );
6292
+ return Promise.resolve(ix);
6290
6293
  }
6291
6294
  async initVerify(connection, payer, sender, receiver, srcEid, nonce, commitmentOrConfig) {
6292
6295
  const [nonceAccount] = this.endpointDeriver.nonce(receiver, srcEid, addressToBytes32(sender.toBase58()));
@@ -6306,7 +6309,7 @@ var Endpoint = class {
6306
6309
  srcEid,
6307
6310
  sender: Array.from(sender.toBytes()),
6308
6311
  receiver,
6309
- nonce
6312
+ nonce: new BN3(nonce)
6310
6313
  }
6311
6314
  },
6312
6315
  this.program
@@ -6321,7 +6324,7 @@ var Endpoint = class {
6321
6324
  const [receiveLibraryConfig] = this.endpointDeriver.receiveLibraryConfig(receiver, srcEid);
6322
6325
  const [nonce] = this.endpointDeriver.nonce(receiver, srcEid, sender);
6323
6326
  const [pendingNonce] = this.endpointDeriver.pendingNonce(receiver, srcEid, sender);
6324
- const ix = createVerifyInstruction(
6327
+ const accounts = createVerifyInstructionAccounts(
6325
6328
  {
6326
6329
  receiveLibrary,
6327
6330
  receiveLibraryConfig,
@@ -6332,14 +6335,47 @@ var Endpoint = class {
6332
6335
  program: this.program,
6333
6336
  eventAuthority: this.eventAuthorityPDA
6334
6337
  },
6335
- // Fake params
6338
+ this.program
6339
+ );
6340
+ accounts.forEach((key) => {
6341
+ key.isSigner = false;
6342
+ });
6343
+ const program = {
6344
+ pubkey: this.program,
6345
+ isSigner: false,
6346
+ isWritable: false
6347
+ };
6348
+ return [program, ...accounts];
6349
+ }
6350
+ /***
6351
+ * setConfig is only supported by ULN
6352
+ */
6353
+ getSetConfigIXAccountMetaForCPI(connection, msgLibProgram, oappID, eid, commitmentOrConfig = "confirmed") {
6354
+ const msgLib = msgLibProgram;
6355
+ const [msgLibInfo] = this.endpointDeriver.messageLibraryInfo(msgLib);
6356
+ const ix = createSetConfigInstruction(
6357
+ {
6358
+ signer: oappID,
6359
+ messageLibInfo: msgLibInfo,
6360
+ messageLib: msgLib,
6361
+ messageLibProgram: msgLibProgram,
6362
+ // anchorRemainingAccounts: await uln.getSetConfigIXAccountMetaForCPI( // FIXME: FIXME: uncomment this line later
6363
+ // connection,
6364
+ // this.program,
6365
+ // oappID,
6366
+ // eid,
6367
+ // commitmentOrConfig
6368
+ // ),
6369
+ oappRegistry: msgLib
6370
+ // FIXME: oappRegistry is wrong
6371
+ },
6372
+ // Fake params. Just to get the ix.keys
6336
6373
  {
6337
6374
  params: {
6338
- srcEid,
6339
- sender: Array.from(addressToBytes32(packet.sender())),
6340
- receiver,
6341
- nonce: 1,
6342
- payloadHash: Array.from(addressToBytes32(packet.sender()))
6375
+ eid,
6376
+ configType: 1,
6377
+ config: Uint8Array.from([]),
6378
+ oapp: oappID
6343
6379
  }
6344
6380
  }
6345
6381
  );
@@ -6349,8 +6385,8 @@ var Endpoint = class {
6349
6385
  return [
6350
6386
  {
6351
6387
  pubkey: this.program,
6352
- isSigner: false,
6353
- isWritable: false
6388
+ isWritable: false,
6389
+ isSigner: false
6354
6390
  }
6355
6391
  ].concat(ix.keys);
6356
6392
  }
@@ -6693,7 +6729,7 @@ var Endpoint = class {
6693
6729
  const slot = await connection.getSlot();
6694
6730
  const timestamp = await connection.getBlockTime(slot);
6695
6731
  invariant(timestamp, "timestamp should not be null");
6696
- const isValid = timeout2.expiry > timestamp;
6732
+ const isValid = parseInt(timeout2.expiry.toString()) > timestamp;
6697
6733
  return {
6698
6734
  programId: defaultInfo.messageLib,
6699
6735
  msgLib: defaultInfo.messageLib,
@@ -6716,7 +6752,7 @@ var Endpoint = class {
6716
6752
  const slot = await connection.getSlot();
6717
6753
  const timestamp = await connection.getBlockTime(slot);
6718
6754
  invariant(timestamp, "timestamp should not be null");
6719
- const isValid = timeout.expiry > timestamp;
6755
+ const isValid = parseInt(timeout.expiry.toString()) > timestamp;
6720
6756
  return {
6721
6757
  programId: messageLibInfo.owner,
6722
6758
  msgLib: info.messageLib,
@@ -6758,6 +6794,14 @@ var Endpoint = class {
6758
6794
  return null;
6759
6795
  }
6760
6796
  }
6797
+ async getPendingInboundNonce(connection, oappIDPDA2, remoteEid, remoteOappAddr, commitmentOrConfig) {
6798
+ const [nonce] = this.endpointDeriver.pendingNonce(oappIDPDA2, remoteEid, remoteOappAddr);
6799
+ try {
6800
+ return await PendingInboundNonce.fromAccountAddress(connection, nonce, commitmentOrConfig);
6801
+ } catch (e) {
6802
+ return null;
6803
+ }
6804
+ }
6761
6805
  async getMessageLibVersion(connection, payer, messageLibProgram, commitment = "confirmed") {
6762
6806
  const ix = simple_message_lib_exports.instructions.createVersionInstruction(messageLibProgram);
6763
6807
  const simulateResp = await simulateTransaction(connection, [ix], messageLibProgram, payer, commitment);
@@ -10854,7 +10898,7 @@ var DVN = class {
10854
10898
  _getExpiration() {
10855
10899
  return (/* @__PURE__ */ new Date()).getTime() / 1e3 + 120;
10856
10900
  }
10857
- async setMsgLibs(connection, payer, msgLibs, sign) {
10901
+ setMsgLibs(connection, payer, msgLibs, sign) {
10858
10902
  const expiration = this._getExpiration();
10859
10903
  return this.invoke(connection, this.vid, payer, this.createSetMsgLibsInstruction(msgLibs), expiration, sign);
10860
10904
  }
@@ -15772,7 +15816,7 @@ var Uln = class {
15772
15816
  /**
15773
15817
  * before calling this function, you should call initUln to initialize the uln
15774
15818
  */
15775
- async setTreasury(admin, treasury, treasuryFeeCap) {
15819
+ async setTreasury(admin, treasury) {
15776
15820
  const [setting] = this.deriver.setting();
15777
15821
  const ix = createSetTreasuryInstruction(
15778
15822
  {
@@ -15990,14 +16034,47 @@ var Uln = class {
15990
16034
  this.program
15991
16035
  );
15992
16036
  }
15993
- async isVerified(connection, dvn, packetBytes) {
16037
+ async isDvnVerified(connection, endpointProgram, dvn, packetBytes, commitmentOrConfig = "confirmed") {
15994
16038
  const packet = PacketV1Codec.fromBytes(packetBytes);
15995
16039
  const headerHash = packet.headerHash();
15996
16040
  const headerHashBytes = Uint8Array.from(Buffer.from(headerHash.slice(2), "hex"));
15997
16041
  const payloadHash = packet.payloadHash();
15998
16042
  const payloadHashBytes = Uint8Array.from(Buffer.from(payloadHash.slice(2), "hex"));
15999
16043
  const [confirmationsPDA] = this.deriver.confirmations(headerHashBytes, payloadHashBytes, dvn);
16000
- return await connection.getAccountInfo(confirmationsPDA) !== null;
16044
+ const endpoint = new endpoint_exports.Endpoint(endpointProgram);
16045
+ const receiver = new PublicKey(arrayify(packet.receiver()));
16046
+ const sender = arrayify(packet.sender());
16047
+ const nonce = await endpoint.getNonce(connection, receiver, packet.srcEid(), sender, commitmentOrConfig);
16048
+ const pendingNonce = await endpoint.getPendingInboundNonce(
16049
+ connection,
16050
+ receiver,
16051
+ packet.srcEid(),
16052
+ sender,
16053
+ commitmentOrConfig
16054
+ );
16055
+ if (!nonce || !pendingNonce) {
16056
+ return false;
16057
+ }
16058
+ if (parseInt(nonce.inboundNonce.toString()) >= parseInt(packet.nonce())) {
16059
+ return true;
16060
+ }
16061
+ if (pendingNonce.nonces.find((n) => n.toString() === packet.nonce()) !== void 0) {
16062
+ return true;
16063
+ }
16064
+ try {
16065
+ const confirmation = await Confirmations.fromAccountAddress(
16066
+ connection,
16067
+ confirmationsPDA,
16068
+ commitmentOrConfig
16069
+ );
16070
+ if (confirmation.value === null) {
16071
+ return false;
16072
+ } else {
16073
+ return true;
16074
+ }
16075
+ } catch (e) {
16076
+ return false;
16077
+ }
16001
16078
  }
16002
16079
  async commitVerification(connection, endpointProgram, packetBytes) {
16003
16080
  const packet = PacketV1Codec.fromBytes(packetBytes);