@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/lz-solana-sdk-v2",
3
- "version": "3.0.116",
3
+ "version": "3.0.117",
4
4
  "license": "BUSL-1.1",
5
5
  "exports": {
6
6
  ".": {
@@ -39,12 +39,12 @@
39
39
  "test-uln": "TEST_SCOPES=uln anchor test --skip-build"
40
40
  },
41
41
  "dependencies": {
42
- "@layerzerolabs/lz-corekit-solana": "^3.0.116",
43
- "@layerzerolabs/lz-definitions": "^3.0.116",
44
- "@layerzerolabs/lz-foundation": "^3.0.116",
45
- "@layerzerolabs/lz-serdes": "^3.0.116",
46
- "@layerzerolabs/lz-utilities": "^3.0.116",
47
- "@layerzerolabs/lz-v2-utilities": "^3.0.116",
42
+ "@layerzerolabs/lz-corekit-solana": "^3.0.117",
43
+ "@layerzerolabs/lz-definitions": "^3.0.117",
44
+ "@layerzerolabs/lz-foundation": "^3.0.117",
45
+ "@layerzerolabs/lz-serdes": "^3.0.117",
46
+ "@layerzerolabs/lz-utilities": "^3.0.117",
47
+ "@layerzerolabs/lz-v2-utilities": "^3.0.117",
48
48
  "@metaplex-foundation/beet": "^0.7.1",
49
49
  "@metaplex-foundation/beet-solana": "^0.4.0",
50
50
  "@metaplex-foundation/mpl-toolbox": "^0.9.2",
@@ -67,8 +67,8 @@
67
67
  "@kinobi-so/renderers": "^0.21.3",
68
68
  "@kinobi-so/renderers-js-umi": "^0.21.6",
69
69
  "@layerzerolabs/layerzero-v2-solana": "^0.0.0",
70
- "@layerzerolabs/tsup-config-next": "^3.0.116",
71
- "@layerzerolabs/typescript-config-next": "^3.0.116",
70
+ "@layerzerolabs/tsup-config-next": "^3.0.117",
71
+ "@layerzerolabs/typescript-config-next": "^3.0.117",
72
72
  "@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
73
73
  "@types/bn.js": "^5.1.5",
74
74
  "@types/chai": "^4.3.11",
package/src/endpoint.ts CHANGED
@@ -21,12 +21,14 @@ import {
21
21
  import { createDefaultProgramRepository } from '@metaplex-foundation/umi-program-repository'
22
22
  import { toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'
23
23
  import { TransactionInstruction } from '@solana/web3.js'
24
+ import invariant from 'tiny-invariant'
24
25
 
25
26
  import { keccak_256 } from '@layerzerolabs/lz-foundation'
26
27
  import { arrayify } from '@layerzerolabs/lz-utilities'
27
28
  import { PacketV1Codec, addressToBytes32 } from '@layerzerolabs/lz-v2-utilities'
28
29
 
29
30
  import {
31
+ BlockedMessageLibProgram,
30
32
  MessageLibInterface,
31
33
  SetConfigType,
32
34
  SimpleMessageLibProgram,
@@ -635,9 +637,6 @@ export class Endpoint {
635
637
  const { path, msgLibProgram } = params
636
638
  const { sender, dstEid, receiver } = path
637
639
  const sendLibInfo = await this.getSendLibrary(rpc, sender, dstEid, commitment)
638
- if (!sendLibInfo.programId) {
639
- throw new Error('default send library not initialized or blocked message lib')
640
- }
641
640
  const { msgLib, programId: owner } = sendLibInfo
642
641
  const txBuilder = instructions.quote(
643
642
  { programs: this.programRepo },
@@ -690,9 +689,6 @@ export class Endpoint {
690
689
  const { path, msgLibProgram } = params
691
690
  const { sender, dstEid, receiver } = path
692
691
  const info = await this.getSendLibrary(rpc, sender, dstEid, commitment)
693
- if (!info.programId) {
694
- throw new Error('default send library not initialized or blocked message lib')
695
- }
696
692
  const sendLibrary = info.msgLib
697
693
  const txBuilder = instructions.send(
698
694
  { programs: this.programRepo },
@@ -1022,13 +1018,13 @@ export class Endpoint {
1022
1018
  * @param {Connection} connection - The connection to the Solana cluster.
1023
1019
  * @param {number} srcEid - The source endpoint ID.
1024
1020
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1025
- * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default receive library or null if not found.
1021
+ * @returns {Promise<{ msgLib: PublicKey; owner: PublicKey } | null>} A promise that resolves to the default receive library or null if not found.
1026
1022
  */
1027
1023
  async getDefaultReceiveLibrary(
1028
1024
  rpc: RpcInterface,
1029
1025
  srcEid: number,
1030
1026
  commitment: Commitment = 'confirmed'
1031
- ): Promise<{ msgLib: PublicKey; owner?: PublicKey } | null> {
1027
+ ): Promise<{ msgLib: PublicKey; owner: PublicKey } | null> {
1032
1028
  const [defaultReceiveLibConfig] = this.pda.defaultReceiveLibraryConfig(srcEid)
1033
1029
 
1034
1030
  const defaultInfo = await accounts.safeFetchReceiveLibraryConfig({ rpc }, defaultReceiveLibConfig, {
@@ -1037,15 +1033,18 @@ export class Endpoint {
1037
1033
  if (defaultInfo == null) {
1038
1034
  return null
1039
1035
  }
1040
- const messageLibInfo = await rpc.getAccount(defaultInfo.messageLib, { commitment })
1041
- // notice: BlockedMessageLib is not initialized its PDA, so it will be null if defaultInfo.messageLib is BlockedMessageLib
1042
- if (!messageLibInfo.exists) {
1043
- return {
1044
- msgLib: defaultInfo.messageLib,
1045
- }
1036
+
1037
+ let msgLibProgram: PublicKey | undefined
1038
+
1039
+ if (Endpoint.checkIfBlockedMessageLib(defaultInfo.messageLib)) {
1040
+ msgLibProgram = BlockedMessageLibProgram.BLOCKED_MESSAGELIB_PROGRAM_ID
1041
+ } else {
1042
+ const messageLibInfo = await rpc.getAccount(defaultInfo.messageLib, { commitment })
1043
+ invariant(messageLibInfo.exists, 'messageLibInfo should not be null')
1044
+ msgLibProgram = messageLibInfo.owner
1046
1045
  }
1047
1046
  return {
1048
- owner: messageLibInfo.owner,
1047
+ owner: msgLibProgram,
1049
1048
  msgLib: defaultInfo.messageLib,
1050
1049
  }
1051
1050
  }
@@ -1056,28 +1055,29 @@ export class Endpoint {
1056
1055
  * @param {Connection} connection - The connection to the Solana cluster.
1057
1056
  * @param {number} dstEid - The destination endpoint ID.
1058
1057
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1059
- * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default send library or null if not found.
1058
+ * @returns {Promise<{ msgLib: PublicKey; owner: PublicKey } | null>} A promise that resolves to the default send library or null if not found.
1060
1059
  */
1061
1060
  async getDefaultSendLibrary(
1062
1061
  rpc: RpcInterface,
1063
1062
  dstEid: number,
1064
1063
  commitment: Commitment = 'confirmed'
1065
- ): Promise<{ msgLib: PublicKey; owner?: PublicKey } | null> {
1064
+ ): Promise<{ msgLib: PublicKey; owner: PublicKey } | null> {
1066
1065
  const [defaultSendLibConfig] = this.pda.defaultSendLibraryConfig(dstEid)
1067
1066
 
1068
1067
  const defaultInfo = await accounts.safeFetchSendLibraryConfig({ rpc }, defaultSendLibConfig, { commitment })
1069
1068
  if (defaultInfo == null) {
1070
1069
  return null
1071
1070
  }
1072
- const messageLibInfo = await rpc.getAccount(defaultInfo.messageLib, { commitment })
1073
- // notice: BlockedMessageLib is not initialized its PDA, so it will be null if defaultInfo.messageLib is BlockedMessageLib
1074
- if (!messageLibInfo.exists) {
1075
- return {
1076
- msgLib: defaultInfo.messageLib,
1077
- }
1071
+ let msgLibProgram: PublicKey | undefined
1072
+ if (Endpoint.checkIfBlockedMessageLib(defaultInfo.messageLib)) {
1073
+ msgLibProgram = BlockedMessageLibProgram.BLOCKED_MESSAGELIB_PROGRAM_ID
1074
+ } else {
1075
+ const messageLibInfo = await rpc.getAccount(defaultInfo.messageLib, { commitment })
1076
+ invariant(messageLibInfo.exists, 'messageLibInfo should not be null')
1077
+ msgLibProgram = messageLibInfo.owner
1078
1078
  }
1079
1079
  return {
1080
- owner: messageLibInfo.owner,
1080
+ owner: msgLibProgram,
1081
1081
  msgLib: defaultInfo.messageLib,
1082
1082
  }
1083
1083
  }
@@ -1089,14 +1089,14 @@ export class Endpoint {
1089
1089
  * @param {PublicKey} oappPda - The OApp PDA.
1090
1090
  * @param {number} dstEid - The destination endpoint ID.
1091
1091
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig='confirmed'] - The commitment level or account info configuration.
1092
- * @returns {Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean } | null>} A promise that resolves to the configured send library or null if not found.
1092
+ * @returns {Promise<{ msgLib: PublicKey; programId: PublicKey; isDefault: boolean } | null>} A promise that resolves to the configured send library or null if not found.
1093
1093
  */
1094
1094
  async getSendLibrary(
1095
1095
  rpc: RpcInterface,
1096
1096
  oappPda: PublicKey,
1097
1097
  dstEid: number,
1098
1098
  commitment: Commitment = 'confirmed'
1099
- ): Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean }> {
1099
+ ): Promise<{ msgLib: PublicKey; programId: PublicKey; isDefault: boolean }> {
1100
1100
  const [sendLibConfig] = this.pda.sendLibraryConfig(oappPda, dstEid)
1101
1101
  const [defaultSendLibConfig] = this.pda.defaultSendLibraryConfig(dstEid)
1102
1102
  const [defaultSendLibConfigBuf, sendLibConfigBuf] = await rpc.getAccounts(
@@ -1115,21 +1115,18 @@ export class Endpoint {
1115
1115
  ? defaultSendLibConfigInfo.messageLib
1116
1116
  : sendLibConfigInfo.messageLib
1117
1117
  const isDefault = sendLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString()
1118
- const msgLibInfo = await rpc.getAccount(msgLib, { commitment })
1119
-
1120
- // notice: BlockedMessageLib is not initialized its PDA, so programId will be null if msgLib is BlockedMessageLib
1121
- if (!msgLibInfo.exists) {
1122
- return {
1123
- programId: undefined,
1124
- msgLib,
1125
- isDefault,
1126
- }
1118
+ let msgLibProgram: PublicKey | undefined
1119
+ if (Endpoint.checkIfBlockedMessageLib(msgLib)) {
1120
+ msgLibProgram = BlockedMessageLibProgram.BLOCKED_MESSAGELIB_PROGRAM_ID
1127
1121
  } else {
1128
- return {
1129
- programId: msgLibInfo.owner,
1130
- msgLib,
1131
- isDefault,
1132
- }
1122
+ const msgLibInfo = await rpc.getAccount(msgLib, { commitment })
1123
+ invariant(msgLibInfo.exists, 'msgLibInfo should not be null')
1124
+ msgLibProgram = msgLibInfo.owner
1125
+ }
1126
+ return {
1127
+ programId: msgLibProgram,
1128
+ msgLib,
1129
+ isDefault,
1133
1130
  }
1134
1131
  }
1135
1132
 
@@ -1140,7 +1137,7 @@ export class Endpoint {
1140
1137
  * @param {PublicKey} oappPda - The OApp PDA.
1141
1138
  * @param {number} srcEid - The source endpoint ID.
1142
1139
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1143
- * @returns {Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean; timeout: { msgLib: PublicKey; expiry: bigint } | null } | null>} A promise that resolves to the configured receive library or null if not found.
1140
+ * @returns {Promise<{ msgLib: PublicKey; programId: PublicKey; isDefault: boolean; timeout: { msgLib: PublicKey; expiry: bigint } | null } | null>} A promise that resolves to the configured receive library or null if not found.
1144
1141
  */
1145
1142
  async getReceiveLibrary(
1146
1143
  rpc: RpcInterface,
@@ -1148,8 +1145,8 @@ export class Endpoint {
1148
1145
  srcEid: number,
1149
1146
  commitment: Commitment = 'confirmed'
1150
1147
  ): Promise<{
1151
- msgLib: PublicKey // message library pda, it might be null if the message lib is blocked
1152
- programId?: PublicKey
1148
+ msgLib: PublicKey
1149
+ programId: PublicKey
1153
1150
  isDefault: boolean
1154
1151
  timeout?: { msgLib: PublicKey; expiry: bigint }
1155
1152
  }> {
@@ -1172,26 +1169,23 @@ export class Endpoint {
1172
1169
  : receiveLibConfigInfo
1173
1170
  const msgLib = finalReceiveLibConfigInfo.messageLib
1174
1171
  const isDefault = receiveLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString()
1175
- const msgLibInfo = await rpc.getAccount(msgLib, { commitment })
1176
-
1172
+ let msgLibProgram: PublicKey | undefined
1173
+ if (Endpoint.checkIfBlockedMessageLib(msgLib)) {
1174
+ msgLibProgram = BlockedMessageLibProgram.BLOCKED_MESSAGELIB_PROGRAM_ID
1175
+ } else {
1176
+ const msgLibInfo = await rpc.getAccount(msgLib, { commitment })
1177
+ invariant(msgLibInfo.exists, 'msgLibInfo should not be null')
1178
+ msgLibProgram = msgLibInfo.owner
1179
+ }
1177
1180
  const receiveTimeout = isSome(finalReceiveLibConfigInfo.timeout)
1178
1181
  ? {
1179
1182
  msgLib: finalReceiveLibConfigInfo.timeout.value.messageLib,
1180
1183
  expiry: finalReceiveLibConfigInfo.timeout.value.expiry,
1181
1184
  }
1182
1185
  : undefined
1183
- // notice: BlockedMessageLib is not initialized its PDA, so programId will be undefined if msgLib is BlockedMessageLib
1184
- if (!msgLibInfo.exists) {
1185
- return {
1186
- programId: undefined,
1187
- msgLib,
1188
- isDefault,
1189
- timeout: receiveTimeout,
1190
- }
1191
- }
1192
1186
 
1193
1187
  return {
1194
- programId: msgLibInfo.owner,
1188
+ programId: msgLibProgram,
1195
1189
  msgLib,
1196
1190
  isDefault,
1197
1191
  timeout: receiveTimeout,
@@ -1344,4 +1338,11 @@ export class Endpoint {
1344
1338
  }
1345
1339
  ).items[0]
1346
1340
  }
1341
+
1342
+ static checkIfBlockedMessageLib(msgLib: PublicKey): boolean {
1343
+ const [blockedMessageLib] = new MessageLibPDA(
1344
+ BlockedMessageLibProgram.BLOCKED_MESSAGELIB_PROGRAM_ID
1345
+ ).messageLib()
1346
+ return msgLib.toString() === blockedMessageLib.toString()
1347
+ }
1347
1348
  }
@@ -14,6 +14,7 @@ import { arrayify } from '@layerzerolabs/lz-utilities'
14
14
  import { PacketV1Codec, addressToBytes32 } from '@layerzerolabs/lz-v2-utilities'
15
15
 
16
16
  import {
17
+ BlockedMessageLibProgram,
17
18
  MessageLibInterface,
18
19
  SetConfigType,
19
20
  SimpleMessageLibProgram,
@@ -587,9 +588,6 @@ export class Endpoint {
587
588
  const sender = new PublicKey(arrayify(sender_))
588
589
  const receiver = addressToBytes32(receiver_)
589
590
  const sendLibInfo = await this.getSendLibrary(connection, sender, dstEid)
590
- if (!sendLibInfo?.programId) {
591
- throw new Error('default send library not initialized or blocked message lib')
592
- }
593
591
  const { msgLib, programId: owner } = sendLibInfo
594
592
  const [sendLibraryInfo] = this.deriver.messageLibraryInfo(msgLib)
595
593
  const remainingAccounts = await msgLibProgram.getQuoteIXAccountMetaForCPI(connection, payer, path)
@@ -644,9 +642,6 @@ export class Endpoint {
644
642
  const sender = new PublicKey(arrayify(sender_))
645
643
  const receiver = addressToBytes32(receiver_)
646
644
  const info = await this.getSendLibrary(connection, sender, dstEid, commitmentOrConfig)
647
- if (!info?.programId) {
648
- throw new Error('default send library not initialized or blocked message lib')
649
- }
650
645
  const sendLibrary = info.msgLib
651
646
 
652
647
  const [sendLibraryInfo] = this.deriver.messageLibraryInfo(sendLibrary)
@@ -1158,13 +1153,13 @@ export class Endpoint {
1158
1153
  * @param {Connection} connection - The connection to the Solana cluster.
1159
1154
  * @param {number} srcEid - The source endpoint ID.
1160
1155
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1161
- * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default receive library or null if not found.
1156
+ * @returns {Promise<{ msgLib: PublicKey; owner: PublicKey } | null>} A promise that resolves to the default receive library or null if not found.
1162
1157
  */
1163
1158
  async getDefaultReceiveLibrary(
1164
1159
  connection: Connection,
1165
1160
  srcEid: number,
1166
1161
  commitmentOrConfig?: Commitment | GetAccountInfoConfig
1167
- ): Promise<{ msgLib: PublicKey; owner?: PublicKey } | null> {
1162
+ ): Promise<{ msgLib: PublicKey; owner: PublicKey } | null> {
1168
1163
  const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid)
1169
1164
  try {
1170
1165
  const defaultInfo = await accounts.ReceiveLibraryConfig.fromAccountAddress(
@@ -1172,15 +1167,17 @@ export class Endpoint {
1172
1167
  defaultReceiveLibConfig,
1173
1168
  commitmentOrConfig
1174
1169
  )
1175
- const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1176
- // notice: BlockedMessageLib is not initialized its PDA, so it will be null if defaultInfo.messageLib is BlockedMessageLib
1177
- if (!messageLibInfo) {
1178
- return {
1179
- msgLib: defaultInfo.messageLib,
1180
- }
1170
+ let msgLibProgram: PublicKey | undefined
1171
+
1172
+ if (Endpoint.checkIfBlockedMessageLib(defaultInfo.messageLib)) {
1173
+ msgLibProgram = BlockedMessageLibProgram.PROGRAM_ID
1174
+ } else {
1175
+ const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1176
+ invariant(messageLibInfo, 'messageLibInfo should not be null')
1177
+ msgLibProgram = messageLibInfo.owner
1181
1178
  }
1182
1179
  return {
1183
- owner: messageLibInfo.owner,
1180
+ owner: msgLibProgram,
1184
1181
  msgLib: defaultInfo.messageLib,
1185
1182
  }
1186
1183
  } catch (e) {
@@ -1194,13 +1191,13 @@ export class Endpoint {
1194
1191
  * @param {Connection} connection - The connection to the Solana cluster.
1195
1192
  * @param {number} dstEid - The destination endpoint ID.
1196
1193
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1197
- * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default send library or null if not found.
1194
+ * @returns {Promise<{ msgLib: PublicKey; owner: PublicKey } | null>} A promise that resolves to the default send library or null if not found.
1198
1195
  */
1199
1196
  async getDefaultSendLibrary(
1200
1197
  connection: Connection,
1201
1198
  dstEid: number,
1202
1199
  commitmentOrConfig?: Commitment | GetAccountInfoConfig
1203
- ): Promise<{ msgLib: PublicKey; owner?: PublicKey } | null> {
1200
+ ): Promise<{ msgLib: PublicKey; owner: PublicKey } | null> {
1204
1201
  const [defaultSendLibConfig] = this.deriver.defaultSendLibraryConfig(dstEid)
1205
1202
  try {
1206
1203
  const defaultInfo = await accounts.SendLibraryConfig.fromAccountAddress(
@@ -1208,15 +1205,16 @@ export class Endpoint {
1208
1205
  defaultSendLibConfig,
1209
1206
  commitmentOrConfig
1210
1207
  )
1211
- const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1212
- // notice: BlockedMessageLib is not initialized its PDA, so it will be null if defaultInfo.messageLib is BlockedMessageLib
1213
- if (!messageLibInfo) {
1214
- return {
1215
- msgLib: defaultInfo.messageLib,
1216
- }
1208
+ let msgLibProgram: PublicKey | undefined
1209
+ if (Endpoint.checkIfBlockedMessageLib(defaultInfo.messageLib)) {
1210
+ msgLibProgram = BlockedMessageLibProgram.PROGRAM_ID
1211
+ } else {
1212
+ const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1213
+ invariant(messageLibInfo, 'messageLibInfo should not be null')
1214
+ msgLibProgram = messageLibInfo.owner
1217
1215
  }
1218
1216
  return {
1219
- owner: messageLibInfo.owner,
1217
+ owner: msgLibProgram,
1220
1218
  msgLib: defaultInfo.messageLib,
1221
1219
  }
1222
1220
  } catch (e) {
@@ -1231,14 +1229,14 @@ export class Endpoint {
1231
1229
  * @param {PublicKey} oappPda - The OApp PDA.
1232
1230
  * @param {number} dstEid - The destination endpoint ID.
1233
1231
  * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig='confirmed'] - The commitment level or account info configuration.
1234
- * @returns {Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean } | null>} A promise that resolves to the configured send library or null if not found.
1232
+ * @returns {Promise<{ msgLib: PublicKey; programId: PublicKey; isDefault: boolean } | null>} A promise that resolves to the configured send library or null if not found.
1235
1233
  */
1236
1234
  async getSendLibrary(
1237
1235
  connection: Connection,
1238
1236
  oappPda: PublicKey,
1239
1237
  dstEid: number,
1240
1238
  commitmentOrConfig: Commitment | GetAccountInfoConfig = 'confirmed'
1241
- ): Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean } | null> {
1239
+ ): Promise<{ msgLib: PublicKey; programId: PublicKey; isDefault: boolean }> {
1242
1240
  const [sendLibConfig] = this.deriver.sendLibraryConfig(oappPda, dstEid)
1243
1241
  const [defaultSendLibConfig] = this.deriver.defaultSendLibraryConfig(dstEid)
1244
1242
  const [defaultSendLibConfigBuf, sendLibConfigBuf] = await connection.getMultipleAccountsInfo(
@@ -1246,8 +1244,9 @@ export class Endpoint {
1246
1244
  commitmentOrConfig
1247
1245
  )
1248
1246
  if (!defaultSendLibConfigBuf || !sendLibConfigBuf) {
1249
- console.warn('send library not initialized, return empty array')
1250
- return null
1247
+ throw new Error(
1248
+ `Unable to find defaultSendLibraryConfig/sendLibraryConfig account at ${defaultSendLibConfig.toString()}/${sendLibConfig.toString()}`
1249
+ )
1251
1250
  }
1252
1251
  const [sendLibConfigInfo] = accounts.SendLibraryConfig.fromAccountInfo(sendLibConfigBuf, 0)
1253
1252
  const [defaultSendLibConfigInfo] = accounts.SendLibraryConfig.fromAccountInfo(defaultSendLibConfigBuf, 0)
@@ -1256,21 +1255,18 @@ export class Endpoint {
1256
1255
  ? defaultSendLibConfigInfo.messageLib
1257
1256
  : sendLibConfigInfo.messageLib
1258
1257
  const isDefault = sendLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString()
1259
- const msgLibInfo = await connection.getAccountInfo(msgLib, commitmentOrConfig)
1260
-
1261
- // notice: BlockedMessageLib is not initialized its PDA, so it will be null if msgLib is BlockedMessageLib
1262
- if (!msgLibInfo) {
1263
- return {
1264
- programId: undefined,
1265
- msgLib,
1266
- isDefault,
1267
- }
1258
+ let msgLibProgram: PublicKey | undefined
1259
+ if (Endpoint.checkIfBlockedMessageLib(msgLib)) {
1260
+ msgLibProgram = BlockedMessageLibProgram.PROGRAM_ID
1268
1261
  } else {
1269
- return {
1270
- programId: msgLibInfo.owner,
1271
- msgLib,
1272
- isDefault,
1273
- }
1262
+ const msgLibAccountInfo = await connection.getAccountInfo(msgLib, commitmentOrConfig)
1263
+ invariant(msgLibAccountInfo, 'msgLibAccountInfo should not be null')
1264
+ msgLibProgram = msgLibAccountInfo.owner
1265
+ }
1266
+ return {
1267
+ programId: msgLibProgram,
1268
+ msgLib,
1269
+ isDefault,
1274
1270
  }
1275
1271
  }
1276
1272
 
@@ -1290,60 +1286,52 @@ export class Endpoint {
1290
1286
  commitmentOrConfig?: Commitment | GetAccountInfoConfig
1291
1287
  ): Promise<{
1292
1288
  msgLib: PublicKey // message library pda, it might be null if the message lib is blocked
1293
- programId?: PublicKey
1289
+ programId: PublicKey
1294
1290
  isDefault: boolean
1295
- timeout: { msgLib: PublicKey; expiry: bigint } | null
1296
- } | null> {
1291
+ timeout?: { msgLib: PublicKey; expiry: bigint }
1292
+ }> {
1297
1293
  const [receiveLibConfig] = this.deriver.receiveLibraryConfig(oappPda, srcEid)
1298
- const accountInfo = await connection.getAccountInfo(receiveLibConfig, commitmentOrConfig)
1299
- if (accountInfo == null) {
1300
- // throw new Error(`Unable to find MessageLibConfig account at ${sendLibPda}`)
1301
- return null
1302
- }
1303
- const [info] = accounts.ReceiveLibraryConfig.fromAccountInfo(accountInfo, 0)
1304
- if (info.messageLib.toString() == DefaultMessageLib.toString()) {
1305
- // use default message lib
1306
- const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid)
1307
- const defaultInfo = await accounts.ReceiveLibraryConfig.fromAccountAddress(
1308
- connection,
1309
- defaultReceiveLibConfig,
1310
- commitmentOrConfig
1294
+ const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid)
1295
+ // const accountInfo = await connection.getAccountInfo(receiveLibConfig, commitmentOrConfig)
1296
+ const [defaultReceiveLibConfigBuf, receiveLibConfigBuf] = await connection.getMultipleAccountsInfo(
1297
+ [defaultReceiveLibConfig, receiveLibConfig],
1298
+ commitmentOrConfig
1299
+ )
1300
+ if (!defaultReceiveLibConfigBuf || !receiveLibConfigBuf) {
1301
+ throw new Error(
1302
+ `Unable to find defaultReceiveLibraryConfig/receiveLibraryConfig account at ${defaultReceiveLibConfig.toString()}/${receiveLibConfig.toString()}`
1311
1303
  )
1312
- const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1313
- if (messageLibInfo) {
1314
- const { timeout } = defaultInfo
1315
- if (timeout) {
1316
- return {
1317
- programId: defaultInfo.messageLib,
1318
- msgLib: defaultInfo.messageLib,
1319
- isDefault: true,
1320
- timeout: { msgLib: timeout.messageLib, expiry: BigInt(timeout.expiry.toString()) },
1321
- }
1322
- }
1323
- }
1324
- return {
1325
- programId: messageLibInfo?.owner,
1326
- msgLib: defaultInfo.messageLib,
1327
- isDefault: true,
1328
- timeout: null,
1329
- }
1330
1304
  }
1331
- const messageLibInfo = await connection.getAccountInfo(info.messageLib, commitmentOrConfig)
1332
- invariant(messageLibInfo, 'messageLibInfo should not be null')
1333
- const { timeout } = info
1334
- if (timeout) {
1335
- // const slot = await connection.getSlot()
1336
- // const timestamp = await connection.getBlockTime(slot)
1337
- // invariant(timestamp, 'timestamp should not be null')
1338
- // const isValid = parseInt(timeout.expiry.toString()) > timestamp
1339
- return {
1340
- programId: messageLibInfo.owner,
1341
- msgLib: info.messageLib,
1342
- isDefault: false,
1343
- timeout: { msgLib: timeout.messageLib, expiry: BigInt(timeout.expiry.toString()) },
1344
- }
1305
+
1306
+ const [receiveLibConfigInfo] = accounts.ReceiveLibraryConfig.fromAccountInfo(receiveLibConfigBuf, 0)
1307
+ const [defaultReceiveLibConfigInfo] = accounts.ReceiveLibraryConfig.fromAccountInfo(
1308
+ defaultReceiveLibConfigBuf,
1309
+ 0
1310
+ )
1311
+ const finalReceiveLibConfigInfo =
1312
+ receiveLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString()
1313
+ ? defaultReceiveLibConfigInfo
1314
+ : receiveLibConfigInfo
1315
+
1316
+ const { messageLib, timeout } = finalReceiveLibConfigInfo
1317
+
1318
+ let msgLibProgram: PublicKey | undefined
1319
+ if (Endpoint.checkIfBlockedMessageLib(messageLib)) {
1320
+ msgLibProgram = BlockedMessageLibProgram.PROGRAM_ID
1321
+ } else {
1322
+ const msgLibAccountInfo = await connection.getAccountInfo(messageLib, commitmentOrConfig)
1323
+ invariant(msgLibAccountInfo, 'msgLibAccountInfo should not be null')
1324
+ msgLibProgram = msgLibAccountInfo.owner
1325
+ }
1326
+ return {
1327
+ programId: msgLibProgram,
1328
+ msgLib: messageLib,
1329
+ isDefault: receiveLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString(),
1330
+ timeout:
1331
+ timeout === null
1332
+ ? undefined
1333
+ : { msgLib: timeout.messageLib, expiry: BigInt(timeout.expiry.toString()) },
1345
1334
  }
1346
- return { programId: messageLibInfo.owner, msgLib: info.messageLib, isDefault: false, timeout: null }
1347
1335
  }
1348
1336
 
1349
1337
  // rename to a more generic name
@@ -1514,4 +1502,9 @@ export class Endpoint {
1514
1502
  this.program
1515
1503
  )
1516
1504
  }
1505
+
1506
+ static checkIfBlockedMessageLib(msgLib: PublicKey): boolean {
1507
+ const [blockedMessageLib] = new MessageLibPDADeriver(BlockedMessageLibProgram.PROGRAM_ID).messageLib()
1508
+ return msgLib.toString() === blockedMessageLib.toString()
1509
+ }
1517
1510
  }