@layerzerolabs/oft-v2-solana-sdk 3.0.53 → 3.0.56

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/oft302.ts CHANGED
@@ -6,8 +6,8 @@
6
6
  // 4. Set the DVN etc. options
7
7
  import { hexlify } from '@ethersproject/bytes'
8
8
  import {
9
+ AccountMeta,
9
10
  Cluster,
10
- Instruction,
11
11
  Program,
12
12
  ProgramError,
13
13
  ProgramRepositoryInterface,
@@ -18,31 +18,25 @@ import {
18
18
  createNullRpc,
19
19
  defaultPublicKey,
20
20
  none,
21
- publicKeyBytes,
22
21
  some,
23
22
  } from '@metaplex-foundation/umi'
24
23
  import { createDefaultProgramRepository } from '@metaplex-foundation/umi-program-repository'
25
- import {
26
- fromWeb3JsInstruction,
27
- fromWeb3JsPublicKey,
28
- toWeb3JsInstruction,
29
- toWeb3JsPublicKey,
30
- } from '@metaplex-foundation/umi-web3js-adapters'
24
+ import { fromWeb3JsPublicKey, toWeb3JsInstruction, toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'
31
25
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
32
- import { AccountMeta, ComputeBudgetProgram, Connection } from '@solana/web3.js'
26
+ import { ComputeBudgetProgram } from '@solana/web3.js'
33
27
 
34
28
  import {
35
- EndpointPDADeriver,
29
+ EndpointPDA,
36
30
  EndpointProgram,
37
- EventPDADeriver,
31
+ EventPDA,
38
32
  MessageLibInterface,
39
33
  SetConfigType,
40
34
  SimpleMessageLibProgram,
41
- UlnPDADeriver,
35
+ SolanaPacketPath,
36
+ UlnPDA,
42
37
  UlnProgram,
43
- simulateTransaction,
44
- } from '@layerzerolabs/lz-solana-sdk-v2'
45
- import { PacketPath } from '@layerzerolabs/lz-v2-utilities'
38
+ simulateWeb3JsTransaction,
39
+ } from '@layerzerolabs/lz-solana-sdk-v2/umi'
46
40
 
47
41
  import { OFT_DECIMALS } from './consts'
48
42
  import * as OFTAccounts from './generated/oft302/accounts'
@@ -65,8 +59,8 @@ export * as shared from './generated/oft302/shared'
65
59
  export * as types from './generated/oft302/types'
66
60
  export * as errors from './generated/oft302/errors'
67
61
 
68
- const ENDPOINT_PROGRAM_ID = fromWeb3JsPublicKey(EndpointProgram.PROGRAM_ID)
69
- const ULN_PROGRAM_ID = fromWeb3JsPublicKey(UlnProgram.PROGRAM_ID)
62
+ const ENDPOINT_PROGRAM_ID: PublicKey = EndpointProgram.ENDPOINT_PROGRAM_ID
63
+ const ULN_PROGRAM_ID: PublicKey = UlnProgram.ULN_PROGRAM_ID
70
64
 
71
65
  export function createOFTProgramRepo(oftProgram: PublicKey, rpc?: RpcInterface): ProgramRepositoryInterface {
72
66
  if (rpc === undefined) {
@@ -98,7 +92,7 @@ export function initOft(
98
92
  ): WrappedInstruction {
99
93
  const programsRepo = typeof programs.oft === 'string' ? createOFTProgramRepo(programs.oft) : programs.oft
100
94
  const deriver = new OftPDA(programsRepo.getPublicKey('oft'))
101
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID))
95
+ const endpoint = new EndpointProgram.Endpoint(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
102
96
  const { payer, admin, mint, escrow } = accounts
103
97
  const [oftStore] = deriver.oftStore(escrow.publicKey)
104
98
  const [lzReceiveTypes] = deriver.lzReceiveTypesAccounts(oftStore)
@@ -119,19 +113,17 @@ export function initOft(
119
113
  oftType: oftType,
120
114
  admin: admin,
121
115
  sharedDecimals: sharedDecimals,
122
- endpointProgram: fromWeb3JsPublicKey(endpoint.program),
116
+ endpointProgram: endpoint.programId,
123
117
  }
124
118
  )
125
119
  const retval = txBuilder.addRemainingAccounts(
126
- endpoint
127
- .getRegisterOappIxAccountMetaForCPI(toWeb3JsPublicKey(payer.publicKey), toWeb3JsPublicKey(oftStore))
128
- .map((acc) => {
129
- return {
130
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
131
- isSigner: acc.isSigner,
132
- isWritable: acc.isWritable,
133
- }
134
- })
120
+ endpoint.getRegisterOappIxAccountMetaForCPI(payer.publicKey, oftStore).map((acc) => {
121
+ return {
122
+ pubkey: acc.pubkey,
123
+ isSigner: acc.isSigner,
124
+ isWritable: acc.isWritable,
125
+ }
126
+ })
135
127
  ).items[0]
136
128
  retval.signers = [payer, escrow]
137
129
  return retval
@@ -150,7 +142,6 @@ export function setOFTConfig(
150
142
  ): WrappedInstruction {
151
143
  let actualParams: types.SetOFTConfigParamsArgs
152
144
  const { oftStore, admin } = accounts
153
- const oftStoreWeb3Js = toWeb3JsPublicKey(oftStore)
154
145
  const remainingAccounts: AccountMeta[] = []
155
146
  if (params.__kind === 'Admin') {
156
147
  if (params.admin === undefined) {
@@ -168,29 +159,13 @@ export function setOFTConfig(
168
159
  __kind: 'Delegate',
169
160
  fields: [params.delegate],
170
161
  }
171
- const endpointProgram = toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
172
- const [oAppRegistry] = new EndpointPDADeriver(endpointProgram).oappRegistry(oftStoreWeb3Js)
173
- const [endpointEventAuthority] = new EventPDADeriver(endpointProgram).eventAuthority()
174
- const keys = EndpointProgram.instructions.createSetDelegateInstructionAccounts(
175
- {
176
- oapp: oftStoreWeb3Js,
177
- oappRegistry: oAppRegistry,
178
- eventAuthority: endpointEventAuthority,
179
- program: endpointProgram,
180
- },
181
- endpointProgram
182
- )
162
+ const endpointProgram = programs.endpoint ?? ENDPOINT_PROGRAM_ID
163
+ const endpointSDK = new EndpointProgram.Endpoint(endpointProgram)
164
+ const keys = endpointSDK.getSetDelegateIxAccountMetaForCPI(oftStore)
183
165
  for (const acc of keys) {
184
166
  acc.isSigner = false
185
167
  }
186
- remainingAccounts.push(
187
- {
188
- pubkey: endpointProgram,
189
- isSigner: false,
190
- isWritable: false,
191
- },
192
- ...keys
193
- )
168
+ remainingAccounts.push(...keys)
194
169
  } else if (params.__kind === 'DefaultFee') {
195
170
  if (params.defaultFee === undefined) {
196
171
  throw new Error('DefaultFee is required')
@@ -230,7 +205,7 @@ export function setOFTConfig(
230
205
  return txBuilder.addRemainingAccounts(
231
206
  remainingAccounts.map((acc) => {
232
207
  return {
233
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
208
+ pubkey: acc.pubkey,
234
209
  isSigner: acc.isSigner,
235
210
  isWritable: acc.isWritable,
236
211
  }
@@ -328,14 +303,8 @@ export function initSendLibrary(
328
303
  endpointProgram: PublicKey = ENDPOINT_PROGRAM_ID
329
304
  ): WrappedInstruction {
330
305
  const { admin, oftStore } = accounts
331
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(endpointProgram))
332
- return {
333
- instruction: fromWeb3JsInstruction(
334
- endpoint.initSendLibrary(toWeb3JsPublicKey(admin.publicKey), toWeb3JsPublicKey(oftStore), remoteEid)
335
- ),
336
- signers: [admin],
337
- bytesCreatedOnChain: 0,
338
- }
306
+ const endpoint = new EndpointProgram.Endpoint(endpointProgram)
307
+ return endpoint.initOAppSendLibrary(admin, { sender: oftStore, remote: remoteEid })
339
308
  }
340
309
 
341
310
  export function initReceiveLibrary(
@@ -347,14 +316,8 @@ export function initReceiveLibrary(
347
316
  endpointProgram: PublicKey = ENDPOINT_PROGRAM_ID
348
317
  ): WrappedInstruction {
349
318
  const { admin, oftStore } = accounts
350
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(endpointProgram))
351
- return {
352
- instruction: fromWeb3JsInstruction(
353
- endpoint.initReceiveLibrary(toWeb3JsPublicKey(admin.publicKey), toWeb3JsPublicKey(oftStore), remoteEid)
354
- ),
355
- signers: [admin],
356
- bytesCreatedOnChain: 0,
357
- }
319
+ const endpoint = new EndpointProgram.Endpoint(endpointProgram)
320
+ return endpoint.initOAppReceiveLibrary(admin, { receiver: oftStore, remote: remoteEid })
358
321
  }
359
322
 
360
323
  export function setSendLibrary(
@@ -370,19 +333,12 @@ export function setSendLibrary(
370
333
  ): WrappedInstruction {
371
334
  const { sendLibraryProgram, remoteEid } = params
372
335
  const { admin, oftStore } = accounts
373
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(endpointProgram))
374
- return {
375
- instruction: fromWeb3JsInstruction(
376
- endpoint.setSendLibrary(
377
- toWeb3JsPublicKey(admin.publicKey),
378
- toWeb3JsPublicKey(oftStore),
379
- toWeb3JsPublicKey(sendLibraryProgram),
380
- remoteEid
381
- )
382
- ),
383
- signers: [admin],
384
- bytesCreatedOnChain: 0,
385
- }
336
+ const endpoint = new EndpointProgram.Endpoint(endpointProgram)
337
+ return endpoint.setOAppSendLibrary(admin, {
338
+ sender: oftStore,
339
+ remote: remoteEid,
340
+ msgLibProgram: sendLibraryProgram,
341
+ })
386
342
  }
387
343
 
388
344
  export function setReceiveLibrary(
@@ -399,20 +355,13 @@ export function setReceiveLibrary(
399
355
  ): WrappedInstruction {
400
356
  const { receiveLibraryProgram, remoteEid, gracePeriod } = params
401
357
  const { admin, oftStore } = accounts
402
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(endpointProgram))
403
- return {
404
- instruction: fromWeb3JsInstruction(
405
- endpoint.setReceiveLibrary(
406
- toWeb3JsPublicKey(admin.publicKey),
407
- toWeb3JsPublicKey(oftStore),
408
- toWeb3JsPublicKey(receiveLibraryProgram),
409
- remoteEid,
410
- gracePeriod
411
- )
412
- ),
413
- signers: [admin],
414
- bytesCreatedOnChain: 0,
415
- }
358
+ const endpoint = new EndpointProgram.Endpoint(endpointProgram)
359
+ return endpoint.setOAppReceiveLibrary(admin, {
360
+ receiver: oftStore,
361
+ remote: remoteEid,
362
+ msgLibProgram: receiveLibraryProgram,
363
+ gracePeriod: gracePeriod,
364
+ })
416
365
  }
417
366
 
418
367
  export function initConfig(
@@ -438,32 +387,30 @@ export function initConfig(
438
387
  endpointProgram = programs.endpoint ?? ENDPOINT_PROGRAM_ID
439
388
  }
440
389
 
441
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(endpointProgram))
390
+ const endpoint = new EndpointProgram.Endpoint(endpointProgram)
442
391
  let msgLib: MessageLibInterface
443
- if (msgLibProgram.toString() === SimpleMessageLibProgram.PROGRAM_ID.toBase58()) {
444
- msgLib = new SimpleMessageLibProgram.SimpleMessageLib(SimpleMessageLibProgram.PROGRAM_ID)
392
+ if (msgLibProgram === SimpleMessageLibProgram.SIMPLE_MESSAGELIB_PROGRAM_ID) {
393
+ msgLib = new SimpleMessageLibProgram.SimpleMessageLib(SimpleMessageLibProgram.SIMPLE_MESSAGELIB_PROGRAM_ID)
445
394
  } else {
446
- msgLib = new UlnProgram.Uln(toWeb3JsPublicKey(msgLibProgram))
447
- }
448
- return {
449
- instruction: fromWeb3JsInstruction(
450
- endpoint.initOAppConfig(
451
- toWeb3JsPublicKey(admin.publicKey),
452
- msgLib,
453
- toWeb3JsPublicKey(payer.publicKey),
454
- toWeb3JsPublicKey(oftStore),
455
- remoteEid
456
- )
457
- ),
458
- signers: [admin, payer],
459
- bytesCreatedOnChain: 0,
395
+ msgLib = new UlnProgram.Uln(msgLibProgram)
460
396
  }
397
+ return endpoint.initOAppConfig(
398
+ {
399
+ delegate: admin,
400
+ payer: payer.publicKey,
401
+ },
402
+ {
403
+ msgLibSDK: msgLib,
404
+ oapp: oftStore,
405
+ remote: remoteEid,
406
+ }
407
+ )
461
408
  }
462
409
 
463
410
  export async function setConfig(
464
- connection: Connection,
411
+ rpc: RpcInterface,
465
412
  accounts: {
466
- signer: PublicKey
413
+ signer: Signer
467
414
  oftStore: PublicKey
468
415
  },
469
416
  params: {
@@ -475,7 +422,7 @@ export async function setConfig(
475
422
  msgLib?: PublicKey
476
423
  endpoint?: PublicKey
477
424
  }
478
- ): Promise<Instruction> {
425
+ ): Promise<WrappedInstruction> {
479
426
  const { signer, oftStore } = accounts
480
427
  const { remoteEid, configType, config } = params
481
428
  let msgLibProgram: PublicKey, endpointProgram: PublicKey
@@ -486,20 +433,16 @@ export async function setConfig(
486
433
  msgLibProgram = programs.msgLib ?? ULN_PROGRAM_ID
487
434
  endpointProgram = programs.endpoint ?? ENDPOINT_PROGRAM_ID
488
435
  }
489
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(endpointProgram))
490
- return fromWeb3JsInstruction(
491
- await endpoint.setOappConfig(
492
- connection,
493
- toWeb3JsPublicKey(signer),
494
- toWeb3JsPublicKey(oftStore),
495
- toWeb3JsPublicKey(msgLibProgram),
496
- remoteEid,
497
- {
498
- configType,
499
- value: config,
500
- }
501
- )
502
- )
436
+ const endpoint = new EndpointProgram.Endpoint(endpointProgram)
437
+ return endpoint.setOAppConfig(rpc, signer, {
438
+ oapp: oftStore,
439
+ eid: remoteEid,
440
+ config: {
441
+ configType,
442
+ value: config,
443
+ },
444
+ msgLibProgram: msgLibProgram,
445
+ })
503
446
  }
504
447
 
505
448
  export function withdrawFee(
@@ -565,40 +508,25 @@ export async function send(
565
508
  const [oftStore] = deriver.oftStore(tokenEscrow)
566
509
  const [peer] = deriver.peer(oftStore, dstEid)
567
510
 
568
- const connection = new Connection(rpc.getEndpoint())
569
511
  if (remainingAccounts === undefined || remainingAccounts.length === 0) {
570
512
  const peerAddr: Uint8Array =
571
513
  accounts.peerAddr ??
572
514
  (await OFTAccounts.fetchPeerConfig({ rpc }, peer).then((peerInfo) => peerInfo.peerAddress))
573
515
 
574
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID))
575
- const msgLibProgram = await getSendLibraryProgram(connection, endpoint, payer.publicKey, oftStore, dstEid)
576
- const packetPath: PacketPath = {
577
- srcEid: 0,
516
+ const endpoint = new EndpointProgram.Endpoint(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
517
+ const msgLibProgram = await getSendLibraryProgram(rpc, endpoint, payer.publicKey, oftStore, dstEid)
518
+ const packetPath: SolanaPacketPath = {
578
519
  dstEid,
579
- sender: hexlify(publicKeyBytes(oftStore)),
580
- receiver: hexlify(peerAddr),
520
+ sender: oftStore,
521
+ receiver: peerAddr,
581
522
  }
582
- // const [endpointSettings] = endpoint.deriver.setting()
583
- // invariant(await isAccountInitialized(connection, endpointSettings), 'endpointSettings account not initialized')
584
- // invariant(await isAccountInitialized(connection, peer), 'peer account not initialized')
585
- // invariant(await isAccountInitialized(connection, payer), 'payer account not initialized')
586
- // invariant(
587
- // await isAccountInitialized(
588
- // connection,
589
- // endpoint.deriver.nonce(oftStore, dstEid, Uint8Array.from(peerAddr))[0]
590
- // ),
591
- // 'nonce account not initialized'
592
- // )
593
- remainingAccounts = await endpoint.getSendIXAccountMetaForCPI(
594
- connection,
595
- toWeb3JsPublicKey(payer.publicKey),
596
- packetPath,
597
- msgLibProgram
598
- )
523
+ remainingAccounts = await endpoint.getSendIXAccountMetaForCPI(rpc, payer.publicKey, {
524
+ path: packetPath,
525
+ msgLibProgram: msgLibProgram,
526
+ })
599
527
  }
600
528
 
601
- const [eventAuthorityPDA] = new EventPDADeriver(toWeb3JsPublicKey(programs.oft)).eventAuthority()
529
+ const [eventAuthorityPDA] = new EventPDA(programs.oft).eventAuthority()
602
530
  const tokenProgram: PublicKey = programs.token ?? fromWeb3JsPublicKey(TOKEN_PROGRAM_ID)
603
531
  const txBuilder = instructions.send(
604
532
  { programs: createOFTProgramRepo(programs.oft) },
@@ -610,7 +538,7 @@ export async function send(
610
538
  tokenEscrow: tokenEscrow,
611
539
  tokenMint: tokenMint,
612
540
  tokenProgram: tokenProgram,
613
- eventAuthority: fromWeb3JsPublicKey(eventAuthorityPDA),
541
+ eventAuthority: eventAuthorityPDA,
614
542
  program: programs.oft,
615
543
  // params
616
544
  dstEid: dstEid,
@@ -628,7 +556,7 @@ export async function send(
628
556
  return txBuilder.addRemainingAccounts(
629
557
  remainingAccounts.map((acc) => {
630
558
  return {
631
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
559
+ pubkey: acc.pubkey,
632
560
  isSigner: acc.isSigner,
633
561
  isWritable: acc.isWritable,
634
562
  }
@@ -667,25 +595,17 @@ export async function quote(
667
595
  const [oftStore] = deriver.oftStore(tokenEscrow)
668
596
  const [peer] = deriver.peer(oftStore, dstEid)
669
597
 
670
- const connection = new Connection(rpc.getEndpoint(), 'confirmed')
671
598
  if (remainingAccounts === undefined || remainingAccounts.length === 0) {
672
599
  const peerAddr: Uint8Array =
673
600
  accounts.peerAddr ??
674
601
  (await OFTAccounts.fetchPeerConfig({ rpc }, peer).then((peerInfo) => peerInfo.peerAddress))
675
602
 
676
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID))
677
- const messageLib = await getSendLibraryProgram(connection, endpoint, payer, oftStore, dstEid)
678
-
679
- remainingAccounts = await endpoint.getQuoteIXAccountMetaForCPI(
680
- connection,
681
- toWeb3JsPublicKey(payer),
682
- {
683
- sender: hexlify(publicKeyBytes(oftStore)),
684
- dstEid: dstEid,
685
- receiver: hexlify(peerAddr),
686
- },
687
- messageLib
688
- )
603
+ const endpoint = new EndpointProgram.Endpoint(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
604
+ const messageLib = await getSendLibraryProgram(rpc, endpoint, payer, oftStore, dstEid)
605
+ remainingAccounts = await endpoint.getQuoteIXAccountMetaForCPI(rpc, payer, {
606
+ path: { sender: oftStore, dstEid: dstEid, receiver: peerAddr },
607
+ msgLibProgram: messageLib,
608
+ })
689
609
  }
690
610
 
691
611
  let txBuilder = instructions.quoteSend(
@@ -709,7 +629,7 @@ export async function quote(
709
629
  // Get remaining accounts from msgLib(simple_msgLib or uln)
710
630
  remainingAccounts.map((acc) => {
711
631
  return {
712
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
632
+ pubkey: acc.pubkey,
713
633
  isSigner: acc.isSigner,
714
634
  isWritable: acc.isWritable,
715
635
  }
@@ -719,17 +639,16 @@ export async function quote(
719
639
  const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
720
640
  units: 1000000,
721
641
  })
722
- const buffer = await simulateTransaction(
723
- connection,
642
+ return simulateWeb3JsTransaction(
643
+ rpc,
724
644
  [modifyComputeUnits, web3Ix],
725
645
  web3Ix.programId,
726
646
  toWeb3JsPublicKey(payer),
647
+ EndpointProgram.types.getMessagingFeeSerializer(),
727
648
  'confirmed',
728
649
  undefined,
729
650
  addressLookupTable === undefined ? undefined : toWeb3JsPublicKey(addressLookupTable)
730
651
  )
731
- const fee = EndpointProgram.types.messagingFeeBeet.read(buffer, 0)
732
- return { nativeFee: BigInt(fee.nativeFee.toString()), lzTokenFee: BigInt(fee.lzTokenFee.toString()) }
733
652
  }
734
653
 
735
654
  export async function quoteOft(
@@ -773,17 +692,16 @@ export async function quoteOft(
773
692
  }
774
693
  )
775
694
  .getInstructions()[0]
695
+
776
696
  const web3Ix = toWeb3JsInstruction(ix)
777
- const connection = new Connection(rpc.getEndpoint())
778
- const returnedValues = await simulateTransaction(
779
- connection,
697
+ return simulateWeb3JsTransaction(
698
+ rpc.getEndpoint(),
780
699
  [web3Ix],
781
700
  web3Ix.programId,
782
701
  toWeb3JsPublicKey(payer),
702
+ types.getQuoteOFTResultSerializer(),
783
703
  'confirmed'
784
704
  )
785
- const [result] = types.getQuoteOFTResultSerializer().deserialize(returnedValues, 0)
786
- return result
787
705
  }
788
706
 
789
707
  export function initOAppNonce(
@@ -796,19 +714,13 @@ export function initOAppNonce(
796
714
  endpointProgram: PublicKey = ENDPOINT_PROGRAM_ID
797
715
  ): WrappedInstruction {
798
716
  const { admin, oftStore } = accounts
799
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(endpointProgram))
800
- return {
801
- instruction: fromWeb3JsInstruction(
802
- endpoint.initOAppNonce(
803
- toWeb3JsPublicKey(admin.publicKey),
804
- remoteEid,
805
- toWeb3JsPublicKey(oftStore),
806
- remoteOappAddr
807
- )
808
- ),
809
- signers: [admin],
810
- bytesCreatedOnChain: 0,
811
- }
717
+ const endpoint = new EndpointProgram.Endpoint(endpointProgram)
718
+
719
+ return endpoint.initOAppNonce(admin, {
720
+ localOApp: oftStore,
721
+ remote: remoteEid,
722
+ remoteOApp: remoteOappAddr,
723
+ })
812
724
  }
813
725
 
814
726
  export async function getEndpointConfig(
@@ -820,9 +732,9 @@ export async function getEndpointConfig(
820
732
  endpoint?: PublicKey
821
733
  }
822
734
  ): Promise<{
823
- sendLibraryConfig: EndpointProgram.accounts.SendLibraryConfig & { ulnSendConfig?: UlnProgram.SendConfig }
735
+ sendLibraryConfig: EndpointProgram.accounts.SendLibraryConfig & { ulnSendConfig?: UlnProgram.accounts.SendConfig }
824
736
  receiveLibraryConfig: EndpointProgram.accounts.ReceiveLibraryConfig & {
825
- ulnReceiveConfig?: UlnProgram.ReceiveConfig
737
+ ulnReceiveConfig?: UlnProgram.accounts.ReceiveConfig
826
738
  }
827
739
  }> {
828
740
  let msgLibProgram: PublicKey, endpointProgram: PublicKey
@@ -833,54 +745,50 @@ export async function getEndpointConfig(
833
745
  msgLibProgram = programs.msgLib ?? ULN_PROGRAM_ID
834
746
  endpointProgram = programs.endpoint ?? ENDPOINT_PROGRAM_ID
835
747
  }
836
- const endpointDeriver = new EndpointPDADeriver(toWeb3JsPublicKey(endpointProgram))
837
- const ulnDeriver = new UlnPDADeriver(toWeb3JsPublicKey(msgLibProgram))
838
- const web3OftStore = toWeb3JsPublicKey(oftStore)
748
+ const endpointDeriver = new EndpointPDA(endpointProgram)
749
+ const ulnDeriver = new UlnPDA(msgLibProgram)
839
750
 
840
- const [sendLib] = endpointDeriver.sendLibraryConfig(web3OftStore, endpointId)
751
+ const [sendLib] = endpointDeriver.sendLibraryConfig(oftStore, endpointId)
841
752
  const [defaultSendLib] = endpointDeriver.defaultSendLibraryConfig(endpointId)
842
- const [receiveLib] = endpointDeriver.receiveLibraryConfig(web3OftStore, endpointId)
753
+ const [receiveLib] = endpointDeriver.receiveLibraryConfig(oftStore, endpointId)
843
754
  const [defaultReceiveLib] = endpointDeriver.defaultReceiveLibraryConfig(endpointId)
844
755
 
845
756
  const [msgLib] = ulnDeriver.messageLib()
846
- const connection = new Connection(rpc.getEndpoint())
847
- let sendLibraryConfig: EndpointProgram.accounts.SendLibraryConfig & { ulnSendConfig?: UlnProgram.SendConfig } =
848
- await EndpointProgram.accounts.SendLibraryConfig.fromAccountAddress(connection, sendLib)
757
+ let sendLibraryConfig: EndpointProgram.accounts.SendLibraryConfig & {
758
+ ulnSendConfig?: UlnProgram.accounts.SendConfig
759
+ } = await EndpointProgram.accounts.fetchSendLibraryConfig({ rpc }, sendLib)
849
760
 
850
761
  let receiveLibraryConfig: EndpointProgram.accounts.ReceiveLibraryConfig & {
851
- ulnReceiveConfig?: UlnProgram.ReceiveConfig
852
- } = await EndpointProgram.accounts.ReceiveLibraryConfig.fromAccountAddress(connection, receiveLib)
762
+ ulnReceiveConfig?: UlnProgram.accounts.ReceiveConfig
763
+ } = await EndpointProgram.accounts.fetchReceiveLibraryConfig({ rpc }, receiveLib)
853
764
 
854
765
  const defaultSendLibraryConfig: EndpointProgram.accounts.SendLibraryConfig & {
855
- ulnSendConfig?: UlnProgram.SendConfig
856
- } = await EndpointProgram.accounts.SendLibraryConfig.fromAccountAddress(connection, defaultSendLib)
766
+ ulnSendConfig?: UlnProgram.accounts.SendConfig
767
+ } = await EndpointProgram.accounts.fetchSendLibraryConfig({ rpc }, defaultSendLib)
857
768
 
858
769
  const defaultReceiveLibraryConfig: EndpointProgram.accounts.ReceiveLibraryConfig & {
859
- ulnReceiveConfig?: UlnProgram.ReceiveConfig
860
- } = await EndpointProgram.accounts.ReceiveLibraryConfig.fromAccountAddress(connection, defaultReceiveLib)
770
+ ulnReceiveConfig?: UlnProgram.accounts.ReceiveConfig
771
+ } = await EndpointProgram.accounts.fetchReceiveLibraryConfig({ rpc }, defaultReceiveLib)
861
772
 
862
- const nil64 = '18446744073709551615' // max u64
773
+ const nil64 = 18446744073709551615n // max u64
863
774
  const nil8 = 255
864
775
 
865
- if (sendLibraryConfig.messageLib.toBase58() === defaultPublicKey().toString()) {
776
+ if (sendLibraryConfig.messageLib === defaultPublicKey()) {
866
777
  sendLibraryConfig = defaultSendLibraryConfig
867
778
  }
868
- if (receiveLibraryConfig.messageLib.toBase58() === defaultPublicKey().toString()) {
779
+ if (receiveLibraryConfig.messageLib === defaultPublicKey()) {
869
780
  receiveLibraryConfig = defaultReceiveLibraryConfig
870
781
  }
871
782
  // get the uln config if necessary
872
- if (sendLibraryConfig.messageLib.equals(msgLib)) {
783
+ if (sendLibraryConfig.messageLib === msgLib) {
873
784
  const [ulnDefaultSendConfigPDA] = ulnDeriver.defaultSendConfig(endpointId)
874
- const [ulnSendConfigPDA] = ulnDeriver.sendConfig(endpointId, web3OftStore)
875
- const ulnSendConfig = await UlnProgram.accounts.SendConfig.fromAccountAddress(connection, ulnSendConfigPDA)
876
- const ulnDefaultSendConfig = await UlnProgram.accounts.SendConfig.fromAccountAddress(
877
- connection,
878
- ulnDefaultSendConfigPDA
879
- )
785
+ const [ulnSendConfigPDA] = ulnDeriver.sendConfig(endpointId, oftStore)
786
+ const ulnSendConfig = await UlnProgram.accounts.fetchSendConfig({ rpc }, ulnSendConfigPDA)
787
+ const ulnDefaultSendConfig = await UlnProgram.accounts.fetchSendConfig({ rpc }, ulnDefaultSendConfigPDA)
880
788
  // get the uln config for the send library
881
- if (nil64 === ulnSendConfig.uln.confirmations.toString()) {
882
- ulnSendConfig.uln.confirmations = 0
883
- } else if (ulnSendConfig.uln.confirmations == 0) {
789
+ if (nil64 === ulnSendConfig.uln.confirmations) {
790
+ ulnSendConfig.uln.confirmations = 0n
791
+ } else if (ulnSendConfig.uln.confirmations == 0n) {
884
792
  ulnSendConfig.uln.confirmations = ulnDefaultSendConfig.uln.confirmations
885
793
  }
886
794
  if (ulnSendConfig.uln.requiredDvnCount == nil8) {
@@ -899,20 +807,17 @@ export async function getEndpointConfig(
899
807
  }
900
808
  sendLibraryConfig.ulnSendConfig = ulnSendConfig
901
809
  }
902
- if (receiveLibraryConfig.messageLib.equals(msgLib)) {
810
+ if (receiveLibraryConfig.messageLib === msgLib) {
903
811
  const [ulnDefaultReceiveConfigPDA] = ulnDeriver.defaultReceiveConfig(endpointId)
904
- const [ulnReceiveConfigPDA] = ulnDeriver.receiveConfig(endpointId, web3OftStore)
905
- const ulnReceiveConfig = await UlnProgram.accounts.ReceiveConfig.fromAccountAddress(
906
- connection,
907
- ulnReceiveConfigPDA
908
- )
909
- const ulnDefaultReceiveConfig = await UlnProgram.accounts.ReceiveConfig.fromAccountAddress(
910
- connection,
812
+ const [ulnReceiveConfigPDA] = ulnDeriver.receiveConfig(endpointId, oftStore)
813
+ const ulnReceiveConfig = await UlnProgram.accounts.fetchReceiveConfig({ rpc }, ulnReceiveConfigPDA)
814
+ const ulnDefaultReceiveConfig = await UlnProgram.accounts.fetchReceiveConfig(
815
+ { rpc },
911
816
  ulnDefaultReceiveConfigPDA
912
817
  )
913
- if (nil64 === ulnReceiveConfig.uln.confirmations.toString()) {
914
- ulnReceiveConfig.uln.confirmations = 0
915
- } else if (ulnReceiveConfig.uln.confirmations == 0) {
818
+ if (nil64 === ulnReceiveConfig.uln.confirmations) {
819
+ ulnReceiveConfig.uln.confirmations = 0n
820
+ } else if (ulnReceiveConfig.uln.confirmations == 0n) {
916
821
  ulnReceiveConfig.uln.confirmations = ulnDefaultReceiveConfig.uln.confirmations
917
822
  }
918
823
  if (ulnReceiveConfig.uln.requiredDvnCount == nil8) {
@@ -957,14 +862,9 @@ export async function getDelegate(
957
862
  oftInstance: PublicKey,
958
863
  endpointProgram: PublicKey = ENDPOINT_PROGRAM_ID
959
864
  ): Promise<PublicKey> {
960
- const [oAppRegistry] = new EndpointPDADeriver(toWeb3JsPublicKey(endpointProgram)).oappRegistry(
961
- toWeb3JsPublicKey(oftInstance)
962
- )
963
- const oAppRegistryInfo = await EndpointProgram.accounts.OAppRegistry.fromAccountAddress(
964
- new Connection(rpc.getEndpoint()),
965
- oAppRegistry
966
- )
967
- return fromWeb3JsPublicKey(oAppRegistryInfo.delegate)
865
+ const [oAppRegistry] = new EndpointPDA(endpointProgram).oappRegistry(oftInstance)
866
+ const oAppRegistryInfo = await EndpointProgram.accounts.fetchOAppRegistry({ rpc }, oAppRegistry)
867
+ return oAppRegistryInfo.delegate
968
868
  }
969
869
 
970
870
  export async function getEnforcedOptions(
@@ -979,22 +879,22 @@ export async function getEnforcedOptions(
979
879
  }
980
880
 
981
881
  async function getSendLibraryProgram(
982
- connection: Connection,
882
+ rpc: RpcInterface,
983
883
  endpoint: EndpointProgram.Endpoint,
984
884
  payer: PublicKey,
985
885
  oftStore: PublicKey,
986
886
  remoteEid: number
987
887
  ): Promise<SimpleMessageLibProgram.SimpleMessageLib | UlnProgram.Uln> {
988
- const sendLibInfo = await endpoint.getSendLibrary(connection, toWeb3JsPublicKey(oftStore), remoteEid)
989
- if (!sendLibInfo?.programId) {
888
+ const sendLibInfo = await endpoint.getSendLibrary(rpc, oftStore, remoteEid)
889
+ if (!sendLibInfo.programId) {
990
890
  throw new Error('Send library not initialized or blocked message library')
991
891
  }
992
892
  const { programId: msgLibProgram } = sendLibInfo
993
- const msgLibVersion = await endpoint.getMessageLibVersion(connection, toWeb3JsPublicKey(payer), msgLibProgram)
994
- if (msgLibVersion?.major.toString() === '0' && msgLibVersion.minor == 0 && msgLibVersion.endpointVersion == 2) {
893
+ const msgLibVersion = await endpoint.getMessageLibVersion(rpc, payer, msgLibProgram)
894
+ if (msgLibVersion.major.toString() === '0' && msgLibVersion.minor == 0 && msgLibVersion.endpointVersion == 2) {
995
895
  return new SimpleMessageLibProgram.SimpleMessageLib(msgLibProgram)
996
896
  } else if (
997
- msgLibVersion?.major.toString() === '3' &&
897
+ msgLibVersion.major.toString() === '3' &&
998
898
  msgLibVersion.minor == 0 &&
999
899
  msgLibVersion.endpointVersion == 2
1000
900
  ) {