@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/oft-v2-solana-sdk",
3
- "version": "3.0.53",
3
+ "version": "3.0.56",
4
4
  "license": "BUSL-1.1",
5
5
  "exports": {
6
6
  ".": {
@@ -20,23 +20,19 @@
20
20
  "src/**/*"
21
21
  ],
22
22
  "scripts": {
23
- "_test": "anchor test --skip-build",
24
- "api-gen": "$npm_execpath gen-idl && $npm_execpath ts-node scripts/generate.ts",
25
- "build": "$npm_execpath clean-prebuild && $npm_execpath sync-target && $npm_execpath api-gen && $npm_execpath build-ts",
23
+ "api-gen": "$npm_execpath ts-node scripts/generate.ts",
24
+ "build": "$npm_execpath clean-prebuild && $npm_execpath sync && $npm_execpath api-gen && $npm_execpath build-ts",
26
25
  "build-ts": "$npm_execpath tsc --noEmit && $npm_execpath tsup",
27
26
  "clean": "$npm_execpath clean-prebuild",
28
27
  "clean-prebuild": "rimraf .turbo target dist",
29
- "gen-idl": "$npm_execpath sync-target-idl && rsync -avc --delete target/idl/ ./idl/",
30
- "sync-oft202": "cp ../contracts/target/idl/oft.json target/idl/oft202.json && cp ../contracts/target/deploy/oft.so target/deploy/oft202.so",
31
- "sync-target": "$npm_execpath sync-target-deploy && $npm_execpath sync-target-idl && $npm_execpath sync-oft202",
32
- "sync-target-deploy": "mkdir -p target/deploy && rsync -avc --delete ../../../../../packages/layerzero-v2/solana/target/deploy/ target/deploy/",
33
- "sync-target-idl": "mkdir -p target/idl && rsync -avc --delete ../../../../../packages/layerzero-v2/solana/target/idl/oft.json target/idl/"
28
+ "sync": "./sync.mjs",
29
+ "test": "yarn run ts-mocha -b -p ./tsconfig.json -t 10000000 tests/**/*.test.ts"
34
30
  },
35
31
  "dependencies": {
36
32
  "@ethersproject/bytes": "^5.7.0",
37
- "@layerzerolabs/lz-foundation": "^3.0.53",
38
- "@layerzerolabs/lz-solana-sdk-v2": "^3.0.53",
39
- "@layerzerolabs/lz-v2-utilities": "^3.0.53",
33
+ "@layerzerolabs/lz-foundation": "^3.0.56",
34
+ "@layerzerolabs/lz-solana-sdk-v2": "^3.0.56",
35
+ "@layerzerolabs/lz-v2-utilities": "^3.0.56",
40
36
  "@metaplex-foundation/beet": "^0.7.1",
41
37
  "@metaplex-foundation/beet-solana": "^0.4.0",
42
38
  "@metaplex-foundation/umi": "^0.9.2",
@@ -53,9 +49,10 @@
53
49
  "@kinobi-so/nodes-from-anchor": "^0.21.2",
54
50
  "@kinobi-so/renderers": "^0.21.3",
55
51
  "@kinobi-so/renderers-js-umi": "^0.21.6",
52
+ "@layerzerolabs/lz-definitions": "^3.0.56",
56
53
  "@layerzerolabs/oft-v2-solana": "^0.0.0",
57
- "@layerzerolabs/tsup-config-next": "^3.0.53",
58
- "@layerzerolabs/typescript-config-next": "^3.0.53",
54
+ "@layerzerolabs/tsup-config-next": "^3.0.56",
55
+ "@layerzerolabs/typescript-config-next": "^3.0.56",
59
56
  "@metaplex-foundation/mpl-toolbox": "^0.9.2",
60
57
  "@metaplex-foundation/solita": "^0.20.1",
61
58
  "@metaplex-foundation/umi": "^0.9.2",
@@ -68,6 +65,7 @@
68
65
  "@types/glob": "^8.1.0",
69
66
  "@types/mocha": "^10.0.6",
70
67
  "@types/node": "^20.10.5",
68
+ "axios": "^1.6.2",
71
69
  "chai": "^4.3.10",
72
70
  "chai-as-promised": "^7.1.1",
73
71
  "kinobi": "^0.21.4",
@@ -76,7 +74,8 @@
76
74
  "ts-mocha": "^10.0.0",
77
75
  "ts-node": "^10.9.1",
78
76
  "tsup": "^8.3.5",
79
- "typescript": "~5.2.2"
77
+ "typescript": "~5.2.2",
78
+ "zx": "^8.1.3"
80
79
  },
81
80
  "publishConfig": {
82
81
  "access": "public"
package/src/oft202.ts CHANGED
@@ -4,8 +4,8 @@
4
4
  // 2. init adapter OFT from existing mint, optionally an existing escrow
5
5
  // 3. Wire a peer
6
6
  // 4. Set the DVN etc. options
7
- import { hexlify } from '@ethersproject/bytes'
8
7
  import {
8
+ AccountMeta,
9
9
  Cluster,
10
10
  Program,
11
11
  ProgramError,
@@ -16,23 +16,21 @@ import {
16
16
  WrappedInstruction,
17
17
  createNullRpc,
18
18
  none,
19
- publicKeyBytes,
20
19
  some,
21
20
  } from '@metaplex-foundation/umi'
22
21
  import { createDefaultProgramRepository } from '@metaplex-foundation/umi-program-repository'
23
22
  import { fromWeb3JsPublicKey, toWeb3JsInstruction, toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'
24
23
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
25
- import { AccountMeta, ComputeBudgetProgram, Connection } from '@solana/web3.js'
24
+ import { ComputeBudgetProgram } from '@solana/web3.js'
26
25
 
27
26
  import {
28
- EndpointPDADeriver,
29
27
  EndpointProgram,
30
- EventPDADeriver,
28
+ EventPDA,
31
29
  SimpleMessageLibProgram,
30
+ SolanaPacketPath,
32
31
  UlnProgram,
33
- simulateTransaction,
34
- } from '@layerzerolabs/lz-solana-sdk-v2'
35
- import { PacketPath } from '@layerzerolabs/lz-v2-utilities'
32
+ simulateWeb3JsTransaction,
33
+ } from '@layerzerolabs/lz-solana-sdk-v2/umi'
36
34
 
37
35
  import { OFT_DECIMALS } from './consts'
38
36
  import * as OFTAccounts from './generated/oft202/accounts'
@@ -70,7 +68,7 @@ export * as shared from './generated/oft202/shared'
70
68
  export * as types from './generated/oft202/types/index'
71
69
  export * as errors from './generated/oft202/errors'
72
70
 
73
- const ENDPOINT_PROGRAM_ID = fromWeb3JsPublicKey(EndpointProgram.PROGRAM_ID)
71
+ const { ENDPOINT_PROGRAM_ID } = EndpointProgram
74
72
  const PROGRAM_NAME = 'oft'
75
73
 
76
74
  export function createOFTProgramRepo(oftProgram: PublicKey, rpc?: RpcInterface): ProgramRepositoryInterface {
@@ -103,7 +101,7 @@ export function initOft(
103
101
  ): WrappedInstruction {
104
102
  const programsRepo = createOFTProgramRepo(programs.oft)
105
103
  const deriver = new OftPDA(programsRepo.getPublicKey(PROGRAM_NAME))
106
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID))
104
+ const endpoint = new EndpointProgram.Endpoint(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
107
105
  const { payer, admin, mint, escrow } = accounts
108
106
  const [oftStore] = deriver.oftStore(escrow.publicKey)
109
107
  const [lzReceiveTypes] = deriver.lzReceiveTypesAccounts(oftStore)
@@ -124,19 +122,17 @@ export function initOft(
124
122
  oftType: oftType,
125
123
  admin: admin,
126
124
  sharedDecimals: sharedDecimals,
127
- endpointProgram: fromWeb3JsPublicKey(endpoint.program),
125
+ endpointProgram: endpoint.programId,
128
126
  }
129
127
  )
130
128
  const retval = txBuilder.addRemainingAccounts(
131
- endpoint
132
- .getRegisterOappIxAccountMetaForCPI(toWeb3JsPublicKey(payer.publicKey), toWeb3JsPublicKey(oftStore))
133
- .map((acc) => {
134
- return {
135
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
136
- isSigner: acc.isSigner,
137
- isWritable: acc.isWritable,
138
- }
139
- })
129
+ endpoint.getRegisterOappIxAccountMetaForCPI(payer.publicKey, oftStore).map((acc) => {
130
+ return {
131
+ pubkey: acc.pubkey,
132
+ isSigner: acc.isSigner,
133
+ isWritable: acc.isWritable,
134
+ }
135
+ })
140
136
  ).items[0]
141
137
  retval.signers = [payer, escrow]
142
138
  return retval
@@ -155,7 +151,6 @@ export function setOFTConfig(
155
151
  ): WrappedInstruction {
156
152
  let actualParams: types.SetOFTConfigParamsArgs
157
153
  const { oftStore, admin } = accounts
158
- const oftStoreWeb3Js = toWeb3JsPublicKey(oftStore)
159
154
  const remainingAccounts: AccountMeta[] = []
160
155
  if (params.__kind === 'Admin') {
161
156
  if (params.admin === undefined) {
@@ -173,18 +168,9 @@ export function setOFTConfig(
173
168
  __kind: 'Delegate',
174
169
  fields: [params.delegate],
175
170
  }
176
- const endpointProgram = toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
177
- const [oAppRegistry] = new EndpointPDADeriver(endpointProgram).oappRegistry(oftStoreWeb3Js)
178
- const [endpointEventAuthority] = new EventPDADeriver(endpointProgram).eventAuthority()
179
- const keys = EndpointProgram.instructions.createSetDelegateInstructionAccounts(
180
- {
181
- oapp: oftStoreWeb3Js,
182
- oappRegistry: oAppRegistry,
183
- eventAuthority: endpointEventAuthority,
184
- program: endpointProgram,
185
- },
186
- endpointProgram
187
- )
171
+ const endpointProgram = programs.endpoint ?? ENDPOINT_PROGRAM_ID
172
+ const endpointSDK = new EndpointProgram.Endpoint(endpointProgram)
173
+ const keys = endpointSDK.getSetDelegateIxAccountMetaForCPI(oftStore)
188
174
  for (const acc of keys) {
189
175
  acc.isSigner = false
190
176
  }
@@ -235,7 +221,7 @@ export function setOFTConfig(
235
221
  return txBuilder.addRemainingAccounts(
236
222
  remainingAccounts.map((acc) => {
237
223
  return {
238
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
224
+ pubkey: acc.pubkey,
239
225
  isSigner: acc.isSigner,
240
226
  isWritable: acc.isWritable,
241
227
  }
@@ -381,29 +367,25 @@ export async function send(
381
367
  const [oftStore] = deriver.oftStore(tokenEscrow)
382
368
  const [peer] = deriver.peer(oftStore, dstEid)
383
369
 
384
- const connection = new Connection(rpc.getEndpoint())
385
370
  if (remainingAccounts === undefined || remainingAccounts.length === 0) {
386
371
  const peerAddr: Uint8Array =
387
372
  accounts.peerAddr ??
388
373
  (await OFTAccounts.fetchPeerConfig({ rpc }, peer).then((peerInfo) => peerInfo.peerAddress))
389
374
 
390
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID))
391
- const msgLibProgram = await getSendLibraryProgram(connection, endpoint, payer.publicKey, oftStore, dstEid)
392
- const packetPath: PacketPath = {
393
- srcEid: 0,
375
+ const endpoint = new EndpointProgram.Endpoint(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
376
+ const msgLibProgram = await getSendLibraryProgram(rpc, endpoint, payer.publicKey, oftStore, dstEid)
377
+ const packetPath: SolanaPacketPath = {
394
378
  dstEid,
395
- sender: hexlify(publicKeyBytes(oftStore)),
396
- receiver: hexlify(peerAddr),
379
+ sender: oftStore,
380
+ receiver: peerAddr,
397
381
  }
398
- remainingAccounts = await endpoint.getSendIXAccountMetaForCPI(
399
- connection,
400
- toWeb3JsPublicKey(payer.publicKey),
401
- packetPath,
402
- msgLibProgram
403
- )
382
+ remainingAccounts = await endpoint.getSendIXAccountMetaForCPI(rpc, payer.publicKey, {
383
+ path: packetPath,
384
+ msgLibProgram: msgLibProgram,
385
+ })
404
386
  }
405
387
 
406
- const [eventAuthorityPDA] = new EventPDADeriver(toWeb3JsPublicKey(oftProgramId)).eventAuthority()
388
+ const [eventAuthorityPDA] = new EventPDA(oftProgramId).eventAuthority()
407
389
  const tokenProgram: PublicKey = programs.token ?? fromWeb3JsPublicKey(TOKEN_PROGRAM_ID)
408
390
  const txBuilder = instructions.send(
409
391
  { programs: programsRepo },
@@ -415,7 +397,7 @@ export async function send(
415
397
  tokenEscrow: tokenEscrow,
416
398
  tokenMint: tokenMint,
417
399
  tokenProgram: tokenProgram,
418
- eventAuthority: fromWeb3JsPublicKey(eventAuthorityPDA),
400
+ eventAuthority: eventAuthorityPDA,
419
401
  program: oftProgramId,
420
402
  // params
421
403
  dstEid: dstEid,
@@ -433,7 +415,7 @@ export async function send(
433
415
  return txBuilder.addRemainingAccounts(
434
416
  remainingAccounts.map((acc) => {
435
417
  return {
436
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
418
+ pubkey: acc.pubkey,
437
419
  isSigner: acc.isSigner,
438
420
  isWritable: acc.isWritable,
439
421
  }
@@ -465,7 +447,8 @@ export async function quote(
465
447
  oft: PublicKey | ProgramRepositoryInterface
466
448
  endpoint?: PublicKey
467
449
  },
468
- remainingAccounts?: AccountMeta[]
450
+ remainingAccounts?: AccountMeta[],
451
+ addressLookupTable?: PublicKey
469
452
  ): Promise<{ nativeFee: bigint; lzTokenFee: bigint }> {
470
453
  const { dstEid, to, amountLd, minAmountLd, options, payInLzToken, composeParams } = quoteParams
471
454
  const { payer, tokenMint, tokenEscrow } = accounts
@@ -474,25 +457,17 @@ export async function quote(
474
457
  const [oftStore] = deriver.oftStore(tokenEscrow)
475
458
  const [peer] = deriver.peer(oftStore, dstEid)
476
459
 
477
- const connection = new Connection(rpc.getEndpoint(), 'confirmed')
478
460
  if (remainingAccounts === undefined || remainingAccounts.length === 0) {
479
461
  const peerAddr: Uint8Array =
480
462
  accounts.peerAddr ??
481
463
  (await OFTAccounts.fetchPeerConfig({ rpc }, peer).then((peerInfo) => peerInfo.peerAddress))
482
464
 
483
- const endpoint = new EndpointProgram.Endpoint(toWeb3JsPublicKey(programs.endpoint ?? ENDPOINT_PROGRAM_ID))
484
- const messageLib = await getSendLibraryProgram(connection, endpoint, payer, oftStore, dstEid)
485
-
486
- remainingAccounts = await endpoint.getQuoteIXAccountMetaForCPI(
487
- connection,
488
- toWeb3JsPublicKey(payer),
489
- {
490
- sender: hexlify(publicKeyBytes(oftStore)),
491
- dstEid: dstEid,
492
- receiver: hexlify(peerAddr),
493
- },
494
- messageLib
495
- )
465
+ const endpoint = new EndpointProgram.Endpoint(programs.endpoint ?? ENDPOINT_PROGRAM_ID)
466
+ const messageLib = await getSendLibraryProgram(rpc, endpoint, payer, oftStore, dstEid)
467
+ remainingAccounts = await endpoint.getQuoteIXAccountMetaForCPI(rpc, payer, {
468
+ path: { sender: oftStore, dstEid: dstEid, receiver: peerAddr },
469
+ msgLibProgram: messageLib,
470
+ })
496
471
  }
497
472
 
498
473
  let txBuilder = instructions.quoteSend(
@@ -516,7 +491,7 @@ export async function quote(
516
491
  // Get remaining accounts from msgLib(simple_msgLib or uln)
517
492
  remainingAccounts.map((acc) => {
518
493
  return {
519
- pubkey: fromWeb3JsPublicKey(acc.pubkey),
494
+ pubkey: acc.pubkey,
520
495
  isSigner: acc.isSigner,
521
496
  isWritable: acc.isWritable,
522
497
  }
@@ -526,15 +501,16 @@ export async function quote(
526
501
  const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
527
502
  units: 1000000,
528
503
  })
529
- const buffer = await simulateTransaction(
530
- connection,
504
+ return simulateWeb3JsTransaction(
505
+ rpc,
531
506
  [modifyComputeUnits, web3Ix],
532
507
  web3Ix.programId,
533
508
  toWeb3JsPublicKey(payer),
534
- 'confirmed'
509
+ EndpointProgram.types.getMessagingFeeSerializer(),
510
+ 'confirmed',
511
+ undefined,
512
+ addressLookupTable === undefined ? undefined : toWeb3JsPublicKey(addressLookupTable)
535
513
  )
536
- const fee = EndpointProgram.types.messagingFeeBeet.read(buffer, 0)
537
- return { nativeFee: BigInt(fee.nativeFee.toString()), lzTokenFee: BigInt(fee.lzTokenFee.toString()) }
538
514
  }
539
515
 
540
516
  export async function quoteOft(
@@ -580,35 +556,34 @@ export async function quoteOft(
580
556
  )
581
557
  .getInstructions()[0]
582
558
  const web3Ix = toWeb3JsInstruction(ix)
583
- const connection = new Connection(rpc.getEndpoint())
584
- const returnedValues = await simulateTransaction(
585
- connection,
559
+
560
+ return simulateWeb3JsTransaction(
561
+ rpc.getEndpoint(),
586
562
  [web3Ix],
587
563
  web3Ix.programId,
588
564
  toWeb3JsPublicKey(payer),
565
+ types.getQuoteOFTResultSerializer(),
589
566
  'confirmed'
590
567
  )
591
- const [result] = types.getQuoteOFTResultSerializer().deserialize(returnedValues, 0)
592
- return result
593
568
  }
594
569
 
595
570
  async function getSendLibraryProgram(
596
- connection: Connection,
571
+ rpc: RpcInterface,
597
572
  endpoint: EndpointProgram.Endpoint,
598
573
  payer: PublicKey,
599
574
  oftStore: PublicKey,
600
575
  remoteEid: number
601
576
  ): Promise<SimpleMessageLibProgram.SimpleMessageLib | UlnProgram.Uln> {
602
- const sendLibInfo = await endpoint.getSendLibrary(connection, toWeb3JsPublicKey(oftStore), remoteEid)
603
- if (!sendLibInfo?.programId) {
577
+ const sendLibInfo = await endpoint.getSendLibrary(rpc, oftStore, remoteEid)
578
+ if (!sendLibInfo.programId) {
604
579
  throw new Error('Send library not initialized or blocked message library')
605
580
  }
606
581
  const { programId: msgLibProgram } = sendLibInfo
607
- const msgLibVersion = await endpoint.getMessageLibVersion(connection, toWeb3JsPublicKey(payer), msgLibProgram)
608
- if (msgLibVersion?.major.toString() === '0' && msgLibVersion.minor == 0 && msgLibVersion.endpointVersion == 2) {
582
+ const msgLibVersion = await endpoint.getMessageLibVersion(rpc, payer, msgLibProgram)
583
+ if (msgLibVersion.major.toString() === '0' && msgLibVersion.minor == 0 && msgLibVersion.endpointVersion == 2) {
609
584
  return new SimpleMessageLibProgram.SimpleMessageLib(msgLibProgram)
610
585
  } else if (
611
- msgLibVersion?.major.toString() === '3' &&
586
+ msgLibVersion.major.toString() === '3' &&
612
587
  msgLibVersion.minor == 0 &&
613
588
  msgLibVersion.endpointVersion == 2
614
589
  ) {