@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/CHANGELOG.md +32 -0
- package/dist/index.cjs +281 -385
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/index.mjs +164 -268
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -15
- package/src/oft202.ts +57 -82
- package/src/oft302.ts +145 -245
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 {
|
|
26
|
+
import { ComputeBudgetProgram } from '@solana/web3.js'
|
|
33
27
|
|
|
34
28
|
import {
|
|
35
|
-
|
|
29
|
+
EndpointPDA,
|
|
36
30
|
EndpointProgram,
|
|
37
|
-
|
|
31
|
+
EventPDA,
|
|
38
32
|
MessageLibInterface,
|
|
39
33
|
SetConfigType,
|
|
40
34
|
SimpleMessageLibProgram,
|
|
41
|
-
|
|
35
|
+
SolanaPacketPath,
|
|
36
|
+
UlnPDA,
|
|
42
37
|
UlnProgram,
|
|
43
|
-
|
|
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 =
|
|
69
|
-
const ULN_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(
|
|
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:
|
|
116
|
+
endpointProgram: endpoint.programId,
|
|
123
117
|
}
|
|
124
118
|
)
|
|
125
119
|
const retval = txBuilder.addRemainingAccounts(
|
|
126
|
-
endpoint
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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 =
|
|
172
|
-
const
|
|
173
|
-
const
|
|
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:
|
|
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(
|
|
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(
|
|
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(
|
|
374
|
-
return {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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(
|
|
403
|
-
return {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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(
|
|
390
|
+
const endpoint = new EndpointProgram.Endpoint(endpointProgram)
|
|
442
391
|
let msgLib: MessageLibInterface
|
|
443
|
-
if (msgLibProgram
|
|
444
|
-
msgLib = new SimpleMessageLibProgram.SimpleMessageLib(SimpleMessageLibProgram.
|
|
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(
|
|
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
|
-
|
|
411
|
+
rpc: RpcInterface,
|
|
465
412
|
accounts: {
|
|
466
|
-
signer:
|
|
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<
|
|
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(
|
|
490
|
-
return
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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(
|
|
575
|
-
const msgLibProgram = await getSendLibraryProgram(
|
|
576
|
-
const 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:
|
|
580
|
-
receiver:
|
|
520
|
+
sender: oftStore,
|
|
521
|
+
receiver: peerAddr,
|
|
581
522
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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
|
|
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:
|
|
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:
|
|
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(
|
|
677
|
-
const messageLib = await getSendLibraryProgram(
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
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:
|
|
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
|
-
|
|
723
|
-
|
|
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
|
-
|
|
778
|
-
|
|
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(
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
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
|
|
837
|
-
const ulnDeriver = new
|
|
838
|
-
const web3OftStore = toWeb3JsPublicKey(oftStore)
|
|
748
|
+
const endpointDeriver = new EndpointPDA(endpointProgram)
|
|
749
|
+
const ulnDeriver = new UlnPDA(msgLibProgram)
|
|
839
750
|
|
|
840
|
-
const [sendLib] = endpointDeriver.sendLibraryConfig(
|
|
751
|
+
const [sendLib] = endpointDeriver.sendLibraryConfig(oftStore, endpointId)
|
|
841
752
|
const [defaultSendLib] = endpointDeriver.defaultSendLibraryConfig(endpointId)
|
|
842
|
-
const [receiveLib] = endpointDeriver.receiveLibraryConfig(
|
|
753
|
+
const [receiveLib] = endpointDeriver.receiveLibraryConfig(oftStore, endpointId)
|
|
843
754
|
const [defaultReceiveLib] = endpointDeriver.defaultReceiveLibraryConfig(endpointId)
|
|
844
755
|
|
|
845
756
|
const [msgLib] = ulnDeriver.messageLib()
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
770
|
+
ulnReceiveConfig?: UlnProgram.accounts.ReceiveConfig
|
|
771
|
+
} = await EndpointProgram.accounts.fetchReceiveLibraryConfig({ rpc }, defaultReceiveLib)
|
|
861
772
|
|
|
862
|
-
const nil64 =
|
|
773
|
+
const nil64 = 18446744073709551615n // max u64
|
|
863
774
|
const nil8 = 255
|
|
864
775
|
|
|
865
|
-
if (sendLibraryConfig.messageLib
|
|
776
|
+
if (sendLibraryConfig.messageLib === defaultPublicKey()) {
|
|
866
777
|
sendLibraryConfig = defaultSendLibraryConfig
|
|
867
778
|
}
|
|
868
|
-
if (receiveLibraryConfig.messageLib
|
|
779
|
+
if (receiveLibraryConfig.messageLib === defaultPublicKey()) {
|
|
869
780
|
receiveLibraryConfig = defaultReceiveLibraryConfig
|
|
870
781
|
}
|
|
871
782
|
// get the uln config if necessary
|
|
872
|
-
if (sendLibraryConfig.messageLib
|
|
783
|
+
if (sendLibraryConfig.messageLib === msgLib) {
|
|
873
784
|
const [ulnDefaultSendConfigPDA] = ulnDeriver.defaultSendConfig(endpointId)
|
|
874
|
-
const [ulnSendConfigPDA] = ulnDeriver.sendConfig(endpointId,
|
|
875
|
-
const ulnSendConfig = await UlnProgram.accounts.
|
|
876
|
-
const ulnDefaultSendConfig = await UlnProgram.accounts.
|
|
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
|
|
882
|
-
ulnSendConfig.uln.confirmations =
|
|
883
|
-
} else if (ulnSendConfig.uln.confirmations ==
|
|
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
|
|
810
|
+
if (receiveLibraryConfig.messageLib === msgLib) {
|
|
903
811
|
const [ulnDefaultReceiveConfigPDA] = ulnDeriver.defaultReceiveConfig(endpointId)
|
|
904
|
-
const [ulnReceiveConfigPDA] = ulnDeriver.receiveConfig(endpointId,
|
|
905
|
-
const ulnReceiveConfig = await UlnProgram.accounts.
|
|
906
|
-
|
|
907
|
-
|
|
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
|
|
914
|
-
ulnReceiveConfig.uln.confirmations =
|
|
915
|
-
} else if (ulnReceiveConfig.uln.confirmations ==
|
|
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
|
|
961
|
-
|
|
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
|
-
|
|
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(
|
|
989
|
-
if (!sendLibInfo
|
|
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(
|
|
994
|
-
if (msgLibVersion
|
|
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
|
|
897
|
+
msgLibVersion.major.toString() === '3' &&
|
|
998
898
|
msgLibVersion.minor == 0 &&
|
|
999
899
|
msgLibVersion.endpointVersion == 2
|
|
1000
900
|
) {
|