-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetProxy.ts
677 lines (625 loc) · 28.9 KB
/
setProxy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
import { task } from 'hardhat/config'
import bs58 from 'bs58'
import { Program, workspace, BN } from '@coral-xyz/anchor'
import { types as devtoolsTypes } from '@layerzerolabs/devtools-evm-hardhat'
import {
getPeerAddress,
setupAnchor,
printProxyConfig,
getProxyProgram,
getEndpoint,
getTokenATA,
getOrderlyEid,
getSolanaChainId,
createAndSendV0Tx,
getOptions,
delay,
getUmi,
getEncodedOptions,
intoIx,
getLzConfig,
printTxLinks,
createAndSendV0TxWithTable,
getOftProgram,
checkPayloadType,
getProxyAccounts,
getUsdcMint,
getInitOAppRemainingAccounts,
quoteStakingFee,
sendStakingRequest,
quoteFee,
sendRequest,
quoteClaimFee,
sendClaimRequest,
submitProof,
checkPayload,
printEndpointConfig,
printOptions,
getBackwardFee,
getLocalLzConfig,
getSolanaNetwork,
getLedgerOAppAddress,
} from './utils'
import * as constants from './constants'
import {
getProxyConfigPda,
getLzReceiveTypesPda,
getPeerPda,
getOAppRegistryPda,
getReceiveLibConfigPda,
getDefaultReceiveLibConfigPda,
getSendLibProgramId,
getReceiveLibProgramId,
getDefaultSendLibConfigPda,
getClaimDataPda,
getBackwardFeePda,
getAccountListPda,
} from './pdaHelper'
import { PublicKey, AccountMeta, Connection, ComputeBudgetProgram, SystemProgram } from '@solana/web3.js'
import {
fromWeb3JsInstruction,
fromWeb3JsPublicKey,
toWeb3JsInstruction,
toWeb3JsPublicKey,
} from '@metaplex-foundation/umi-web3js-adapters'
import {
createNoopSigner,
createSignerFromKeypair,
signerIdentity,
transactionBuilder,
Transaction,
TransactionBuilder,
} from '@metaplex-foundation/umi'
import { addressToBytes32, bytes32ToEthAddress, Options } from '@layerzerolabs/lz-v2-utilities'
import { oft } from '@layerzerolabs/oft-v2-solana-sdk'
import { EventPDADeriver, SendHelper, EndpointProgram, EndpointPDADeriver } from '@layerzerolabs/lz-solana-sdk-v2'
import { DECIMALS_SCALE_FACTOR, ORDER_DECIMALS_ON_ETHEREUM } from './constants'
import { config } from 'process'
import { setComputeUnitLimit } from '@metaplex-foundation/mpl-toolbox'
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
import { bigint } from 'hardhat/internal/core/params/argumentTypes'
task('sol:proxy:init', 'Create and init Proxy Config PDA')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
console.log('Proxy Config PDA:', proxyConfigPda.toBase58())
const lzReceiveTypesPda = getLzReceiveTypesPda(proxyProgram.programId, proxyConfigPda)
const endpoint = getEndpoint()
const usdcMint = getUsdcMint(taskArgs.env)
const orderlyEid = getOrderlyEid(taskArgs.env)
const solChainId = getSolanaChainId(taskArgs.env)
const proxyTokenAccount = getTokenATA(usdcMint, proxyConfigPda)
const oappRegistryPda = getOAppRegistryPda(proxyConfigPda)
const accountListPda = getAccountListPda(proxyProgram.programId, proxyConfigPda)
const admin = wallet
const peerAddress = addressToBytes32(getLedgerOAppAddress(taskArgs.env))
console.log('proxy config pda', proxyConfigPda.toBase58())
console.log('OApp Registry PDA:', oappRegistryPda.toBase58())
try {
const proxyConfig = await proxyProgram.account.proxyConfig.fetch(proxyConfigPda)
printProxyConfig(proxyConfig)
} catch (e) {
console.log('Proxy Config not found, initializing...')
const initProxyParams = {
endpointProgram: endpoint.program,
usdcTokenAccount: usdcMint,
admin: admin.publicKey,
orderlyEid: orderlyEid,
solChainId: solChainId,
}
const initProxyAccounts = {
payer: wallet.publicKey,
proxyConfig: proxyConfigPda,
lzReceiveTypesAccounts: lzReceiveTypesPda,
proxyTokenAccount: proxyTokenAccount,
tokenMint: usdcMint,
}
const initRemainingAccounts = getInitOAppRemainingAccounts(wallet, proxyConfigPda)
const initProxyIx = await proxyProgram.methods
.initProxy(initProxyParams)
.accounts(initProxyAccounts)
.remainingAccounts(initRemainingAccounts)
.instruction()
const tx = await createAndSendV0Tx([initProxyIx], provider, wallet)
console.log('Tx to init Proxy as OAPP:', tx)
await delay(taskArgs.env)
}
try {
const initOAppNonceIx = endpoint.initOAppNonce(admin.publicKey, orderlyEid, proxyConfigPda, peerAddress!)
const tx = await createAndSendV0Tx([initOAppNonceIx], provider, wallet)
console.log('Tx to init OApp Nonce for Solana Proxy:', tx)
await delay(taskArgs.env)
} catch {
console.log('OApp Nonce already initialized')
}
try {
const initSendLibIx = endpoint.initSendLibrary(wallet.publicKey, proxyConfigPda, orderlyEid)
const tx = await createAndSendV0Tx([initSendLibIx], provider, wallet)
console.log('Tx to init Send Lib for Solana Proxy:', tx)
await delay(taskArgs.env)
} catch {
console.log('Send lib already initialized')
}
try {
const initReceiveLibIx = endpoint.initReceiveLibrary(wallet.publicKey, proxyConfigPda, orderlyEid)
const tx = await createAndSendV0Tx([initReceiveLibIx], provider, wallet)
console.log('Tx to init Receive Lib for Solana Proxy:', tx)
await delay(taskArgs.env)
} catch {
console.log('Receive lib already initialized')
}
try {
const sendLibProgramId = getSendLibProgramId()
const setSendLibIx = endpoint.setSendLibrary(wallet.publicKey, proxyConfigPda, sendLibProgramId, orderlyEid)
const tx = await createAndSendV0Tx([setSendLibIx], provider, wallet)
console.log('Tx to set Send Lib for Solana Proxy:', tx)
await delay(taskArgs.env)
} catch (e) {
console.log('Receive lib already set')
}
try {
const receiveLibProgramId = getReceiveLibProgramId()
const setReceiveLibIx = endpoint.setReceiveLibrary(
wallet.publicKey,
proxyConfigPda,
receiveLibProgramId,
orderlyEid,
BigInt(0)
)
const tx = await createAndSendV0Tx([setReceiveLibIx], provider, wallet)
console.log('Tx to set Receive Lib for Solana Proxy:', tx)
await delay(taskArgs.env)
} catch {
console.log('Receive lib already set')
}
})
task('sol:proxy:setpeer', 'Set Peer Config for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const orderlyEid = getOrderlyEid(taskArgs.env)
const peerAddress = addressToBytes32(getLedgerOAppAddress(taskArgs.env))
const admin = createNoopSigner(fromWeb3JsPublicKey(wallet.publicKey))
const oftStore = fromWeb3JsPublicKey(proxyConfigPda)
const solanaNetwork = getSolanaNetwork(taskArgs.env)
const options = getOptions(taskArgs.env, solanaNetwork)
const [optionSend, optionSendAndCall] = getEncodedOptions(options)
const programId = fromWeb3JsPublicKey(proxyProgram.programId)
const wrappedIx = [
oft.setPeerConfig(
{
oftStore: oftStore,
admin: admin,
},
{
__kind: 'PeerAddress',
peer: Buffer.from(peerAddress!),
remote: orderlyEid,
},
programId
),
oft.setPeerConfig(
{ oftStore: oftStore, admin: admin },
{
__kind: 'EnforcedOptions',
send: optionSend,
sendAndCall: optionSendAndCall,
remote: orderlyEid,
},
programId
),
oft.setPeerConfig(
{
oftStore: oftStore,
admin: admin,
},
{
__kind: 'FeeBps',
feeBps: 0,
remote: orderlyEid,
},
programId
),
]
const ix = intoIx(wrappedIx)
const tx = await createAndSendV0Tx(ix, provider, wallet)
console.log('Tx to set Peer for Solana Proxy:', tx)
await delay(taskArgs.env)
})
task('sol:proxy:setconfig', 'Set Config for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const oftStore = fromWeb3JsPublicKey(proxyConfigPda)
const orderlyEid = getOrderlyEid(taskArgs.env)
const rpc = getUmi(taskArgs.env).rpc
const admin = createNoopSigner(fromWeb3JsPublicKey(wallet.publicKey))
try {
const initIx = [
oft.initConfig(
{
admin: admin,
oftStore: oftStore,
payer: admin,
},
orderlyEid
),
]
const ix = intoIx(initIx)
const tx = await createAndSendV0Tx(ix, provider, wallet)
console.log('Tx to init Config for Solana Proxy:', tx)
await delay(taskArgs.env)
} catch (e) {
console.log('Config already initialized')
}
const connection = new Connection(rpc.getEndpoint(), 'confirmed')
const localNetwork = getSolanaNetwork(taskArgs.env)
const config = getLocalLzConfig(localNetwork)
const ix = [
await oft.setConfig(
connection,
{
signer: admin.publicKey,
oftStore: oftStore,
},
{
remoteEid: orderlyEid,
configType: 1, // EXECUTOR
config: {
maxMessageSize: config.sendLibConfig.executorConfig.maxMessageSize,
executor: new PublicKey(config.sendLibConfig.executorConfig.executorAddress),
},
}
),
await oft.setConfig(
connection,
{
signer: admin.publicKey,
oftStore: oftStore,
},
{
remoteEid: orderlyEid,
configType: 2, // SEND ULN
config: {
confirmations: config.sendLibConfig.ulnConfig.confirmations,
requiredDvnCount: config.sendLibConfig.ulnConfig.requiredDVNCount,
optionalDvnCount: config.sendLibConfig.ulnConfig.optionalDVNCount,
optionalDvnThreshold: config.sendLibConfig.ulnConfig.optionalDVNThreshold,
requiredDvns: config.sendLibConfig.ulnConfig.requiredDVNs.map(
(address: string) => new PublicKey(address)
), // [new Web3PublicKey(config.sendLibConfig?.ulnConfig.requiredDVNs[0]!)]
optionalDvns: [],
},
}
),
await oft.setConfig(
connection,
{
signer: admin.publicKey,
oftStore: oftStore,
},
{
remoteEid: orderlyEid,
configType: 3, // RECEIVE ULN
config: {
confirmations: config.receiveLibConfig?.ulnConfig.confirmations,
requiredDvnCount: config.receiveLibConfig?.ulnConfig.requiredDVNCount,
optionalDvnCount: config.receiveLibConfig?.ulnConfig.optionalDVNCount,
optionalDvnThreshold: config.receiveLibConfig?.ulnConfig.optionalDVNThreshold,
requiredDvns: config.receiveLibConfig?.ulnConfig.requiredDVNs.map(
(address: string) => new PublicKey(address)
), // [new Web3PublicKey(config.sendLibConfig?.ulnConfig.requiredDVNs[0]!)]
optionalDvns: [],
},
}
),
]
const web3Ix = ix.map((ix) => toWeb3JsInstruction(ix))
const tx = await createAndSendV0Tx(web3Ix, provider, wallet)
console.log('Tx to set Config for Solana Proxy:', tx)
})
task('sol:proxy:setfee', 'Set backwar fee for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const backwardFeePda = getBackwardFeePda(proxyProgram.programId)
const { orderBackwardFee, usdcBackwardFee } = getBackwardFee()
const ixSetBackwardFee = await proxyProgram.methods
.setBackwardFee({
orderBackwardFee: orderBackwardFee,
usdcBackwardFee: usdcBackwardFee,
})
.accounts({ admin: wallet.publicKey, proxyConfig: proxyConfigPda, backwardFee: backwardFeePda })
.instruction()
const tx = await createAndSendV0Tx([ixSetBackwardFee], provider, wallet)
console.log('Tx to set Backward Fee for Solana Proxy:', tx)
})
task('sol:proxy:setaccountlist', 'Set Account List for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const accountListPda = getAccountListPda(proxyProgram.programId, proxyConfigPda)
const lzReceiveTypesPda = getLzReceiveTypesPda(proxyProgram.programId, proxyConfigPda)
const usdcMint = getUsdcMint(taskArgs.env)
const ixSetAccountList = await proxyProgram.methods
.setAccountList({ usdcTokenAccount: usdcMint })
.accounts({
admin: wallet.publicKey,
proxyConfig: proxyConfigPda,
lzReceiveTypes: lzReceiveTypesPda,
accountList: accountListPda,
})
.instruction()
const tx = await createAndSendV0Tx([ixSetAccountList], provider, wallet)
console.log('Tx to set Account List for Solana Proxy:', tx)
})
task('sol:proxy:withdrawfee', 'Withdraw fee for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
// .addParam('amount', 'The amount to withdraw', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const amount = new BN(1234568)
const { orderBackwardFee, usdcBackwardFee } = getBackwardFee()
const ixWithdrawFee = await proxyProgram.methods
.withdrawFee({ amount: amount })
.accounts({ admin: wallet.publicKey, proxyConfig: proxyConfigPda, feeCollector: wallet.publicKey })
.instruction()
const tx = await createAndSendV0Tx([ixWithdrawFee], provider, wallet)
console.log('Tx to withdraw fee for Solana Proxy:', tx)
})
task('sol:proxy:pause', 'Pause Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.addParam('paused', 'The paused state', undefined, devtoolsTypes.boolean)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
console.log(taskArgs.paused)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const ixSetPause = await proxyProgram.methods
.setPause({ paused: taskArgs.paused })
.accounts({
admin: wallet.publicKey,
proxyConfig: proxyConfigPda,
})
.instruction()
const tx = await createAndSendV0Tx([ixSetPause], provider, wallet)
console.log('Tx to set Pause for Solana Proxy:', tx)
})
task('sol:proxy:admin', 'Transfer Admin for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const proxyAccounts = getProxyAccounts(taskArgs.env)
const oftStore = proxyConfigPda
const [oAppRegistry] = new EndpointPDADeriver(constants.ENDPOINT_PROGRAM_ID).oappRegistry(oftStore)
const [endpointEventAuthority] = new EventPDADeriver(constants.ENDPOINT_PROGRAM_ID).eventAuthority()
const endpointProgram = getEndpoint()
const keys = EndpointProgram.instructions.createSetDelegateInstructionAccounts(
{
oapp: oftStore,
oappRegistry: oAppRegistry,
eventAuthority: endpointEventAuthority,
program: endpointProgram.program,
},
endpointProgram.program
)
for (const acc of keys) {
acc.isSigner = false
}
let remainingAccounts = []
remainingAccounts.push(
{
pubkey: endpointProgram.program,
isSigner: false,
isWritable: false,
},
...keys
)
// console.log('remainingAccounts', remainingAccounts)
const ixSetDelegateAndAdmin = await proxyProgram.methods
.setDelegate({ delegate: proxyAccounts.multisig })
.accounts({
admin: wallet.publicKey,
proxyConfig: proxyConfigPda,
})
.remainingAccounts(remainingAccounts)
.instruction()
const ixTransferAdmin = await proxyProgram.methods
.transferAdmin({ newAdmin: proxyAccounts.multisig })
.accounts({ admin: wallet.publicKey, proxyConfig: proxyConfigPda })
.instruction()
const tx = await createAndSendV0Tx([ixSetDelegateAndAdmin, ixTransferAdmin], provider, wallet)
console.log('Tx to set Delegate and Admin for Solana Proxy:', tx)
})
task('sol:proxy:getconfig', 'Get Config for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
const oftStore = fromWeb3JsPublicKey(proxyConfigPda)
const programId = fromWeb3JsPublicKey(proxyProgram.programId)
const orderlyEid = getOrderlyEid(taskArgs.env)
const rpc = getUmi(taskArgs.env).rpc
console.log('=============== Proxy Config ===============')
const proxyConfigData = await proxyProgram.account.proxyConfig.fetch(proxyConfigPda)
printProxyConfig(proxyConfigData)
console.log('=============== OAPP Options ===============')
const peerAddress = await oft.getPeerAddress(rpc, oftStore, orderlyEid, programId)
console.log('Peer Address:', '0x' + peerAddress.slice(26).toString())
const enforcedOptions = await oft.getEnforcedOptions(rpc, oftStore, orderlyEid, programId)
const localNetwork = taskArgs.env === 'mainnet' ? 'soldev' : 'solana'
const options = getOptions(taskArgs.env, localNetwork)
printOptions(options, enforcedOptions)
try {
console.log('=============== Endpoint Config ===============')
const delegate = await oft.getDelegate(rpc, oftStore)
console.log('Delegate:', delegate.toString())
const endpointConfig = await oft.getEndpointConfig(rpc, oftStore, orderlyEid)
printEndpointConfig(endpointConfig)
} catch (e) {
console.log(`🛎️ Config for orderly network not set yet, please set it first`)
}
})
task('sol:proxy:pda', 'Get PDA for Solana Proxy and Solana OFT')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.addFlag('extendAlt', 'Extend ALT for Solana OFT')
.setAction(async (taskArgs, hre) => {
const [provider, wallet, rpc] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
console.log('Proxy program ID:', proxyProgram.programId)
const usdcMint = getUsdcMint(taskArgs.env)
const proxyConfigPda = getProxyConfigPda(proxyProgram.programId)
console.log('Proxy Config PDA:', proxyConfigPda.toBase58())
const proxyTokenAccount = getTokenATA(usdcMint, proxyConfigPda)
console.log('Proxy Token Account:', proxyTokenAccount.toBase58())
const lzReceiveTypesPda = getLzReceiveTypesPda(proxyProgram.programId, proxyConfigPda)
console.log('LZ Receive Types PDA:', lzReceiveTypesPda.toBase58())
})
task('sol:proxy:lzReceiveTypes', 'Get LZ Receive Types for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
})
// ================================ Tasks for Interactions ================================
task('sol:proxy:quote', 'Get quote for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.addParam('payloadType', 'The payload type to quote', undefined, devtoolsTypes.string)
.addParam('payload', 'The payload to quote', '0', devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const payloadType = checkPayloadType(taskArgs.payloadType)
const payload = checkPayload(payloadType, taskArgs.payload)
await quoteFee(proxyProgram, wallet.publicKey, payloadType, Buffer.from(payload), taskArgs.env)
})
task('sol:proxy:request', 'Send request for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.addParam('payloadType', 'The payload type to request', undefined, devtoolsTypes.string)
.addOptionalParam('payload', 'The payload to request', '0', devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet, rpcString] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const payloadType = checkPayloadType(taskArgs.payloadType)
const payload = checkPayload(payloadType, taskArgs.payload)
const { lzTokenFee, nativeFee } = await quoteFee(
proxyProgram,
wallet.publicKey,
payloadType,
Buffer.from(payload),
taskArgs.env
)
const tx = await sendRequest(
proxyProgram,
provider,
wallet,
payloadType,
Buffer.from(payload),
nativeFee,
lzTokenFee,
taskArgs.env
)
printTxLinks(taskArgs.env, tx)
})
task('sol:proxy:stake', 'Stake from Solana through Solana OFT')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.addParam('amount', 'The amount (WITHOUT DECIMALS) to stake', undefined, devtoolsTypes.string)
.addFlag('extendAlt', 'Extend ALT for Solana OFT')
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const { lzTokenFee, nativeFee } = await quoteStakingFee(wallet, taskArgs.amount, taskArgs.env)
console.log('lzTokenFee:', lzTokenFee.toString())
console.log('nativeFee:', nativeFee.toString())
let extendAlt = false
if (taskArgs.extendAlt) {
extendAlt = true
}
const tx = await sendStakingRequest(
provider,
wallet,
taskArgs.amount,
nativeFee.toString(),
taskArgs.env,
extendAlt
)
printTxLinks(taskArgs.env, tx)
})
task('sol:proxy:submitproof', 'Send request for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.addParam('distributionId', 'Distribution ID of the reward', 0, devtoolsTypes.int)
.addParam('cumulativeAmount', 'cumulative amount of reward from Mrekle proof', '0', devtoolsTypes.string)
.addParam('merkleProof', 'Merkle proof of the reward', '', devtoolsTypes.csv)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
// console.log('Claiming reward from the Solana network...')
// console.log('Distribution ID:', taskArgs.distributionId)
// console.log('cumulative amount:', taskArgs.cumulativeAmount)
// console.log('Merkle proof:', taskArgs.merkleProof, taskArgs.merkleProof.length)
// console.log('Proxy program ID:', proxyProgram.programId.toBase58())
const tx = await submitProof(
proxyProgram,
provider,
wallet.publicKey,
wallet,
taskArgs.distributionId,
taskArgs.cumulativeAmount,
taskArgs.merkleProof
)
printTxLinks(taskArgs.env, tx)
})
task('sol:proxy:quoteclaim', 'Quote claim for Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const claimDataPda = getClaimDataPda(proxyProgram.programId, wallet.publicKey)
let claimData
try {
claimData = await proxyProgram.account.claimData.fetch(claimDataPda)
// console.log('Distribution ID:', claimData.distributionId)
// console.log('Cumulative amount:', claimData.amount)
// console.log('Root:', claimData.root)
// console.log('User:', claimData.user.toBase58())
} catch (e) {
// console.log(e)
throw new Error('Claim data not found, please submit proof first')
}
await quoteClaimFee(proxyProgram, wallet.publicKey, taskArgs.env)
})
task('sol:proxy:claim', 'Claim reward from Solana Proxy')
.addParam('env', 'The environment to run the task', undefined, devtoolsTypes.string)
.setAction(async (taskArgs, hre) => {
const [provider, wallet] = setupAnchor(taskArgs.env)
const proxyProgram = getProxyProgram(taskArgs.env, provider)
const claimDataPda = getClaimDataPda(proxyProgram.programId, wallet.publicKey)
let claimData
try {
claimData = await proxyProgram.account.claimData.fetch(claimDataPda)
// console.log('Distribution ID:', claimData.distributionId)
// console.log('Cumulative amount:', claimData.amount)
// console.log('Root:', claimData.root)
// console.log('User:', claimData.user.toBase58())
} catch (e) {
// console.log(e)
throw new Error('Claim data not found, please submit proof first')
}
const { lzTokenFee, nativeFee } = await quoteClaimFee(proxyProgram, wallet.publicKey, taskArgs.env)
const tx = await sendClaimRequest(proxyProgram, provider, wallet, nativeFee, lzTokenFee, taskArgs.env)
printTxLinks(taskArgs.env, tx)
})