Skip to content

Commit 9c66f30

Browse files
authored
Align lzapp-migration DevEx with oft-solana (#1537)
1 parent 0cf778b commit 9c66f30

10 files changed

Lines changed: 121 additions & 209 deletions

File tree

examples/lzapp-migration/.eslintrc.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
require('@rushstack/eslint-patch/modern-module-resolution');
2+
13
module.exports = {
24
root: true,
35
extends: ['@layerzerolabs/eslint-config-next/recommended'],
4-
settings: {
5-
'import/resolver': {
6-
typescript: {
7-
project: './tsconfig.json',
8-
},
9-
},
10-
},
116
rules: {
7+
// @layerzerolabs/eslint-config-next defines rules for turborepo-based projects
8+
// that are not relevant for this particular project
129
'turbo/no-undeclared-env-vars': 'off',
1310
'import/no-unresolved': 'warn',
1411
},

examples/lzapp-migration/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,6 @@ pnpm hardhat lz:oft:solana:create --eid 40168 --program-id <PROGRAM_ID>
249249

250250
:information_source: You can also specify `--amount <AMOUNT>` to have the OFT minted to your deployer address upon token creation.
251251

252-
#### For OFTAdapter:
253-
254-
```bash
255-
pnpm hardhat lz:oft-adapter:solana:create --eid 40168 --program-id <PROGRAM_ID> --mint <TOKEN_MINT> --token-program <TOKEN_PROGRAM_ID>
256-
```
257-
258-
:information_source: You can use OFT Adapter if you want to use an existing token on Solana. For OFT Adapter, tokens will be locked when sending to other chains and unlocked when receiving from other chains.
259-
260252
#### For OFT Mint-And-Burn Adapter (MABA):
261253

262254
```bash

examples/lzapp-migration/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"lint:sol": "solhint 'contracts/**/*.sol'",
1616
"test": "$npm_execpath run test:hardhat",
1717
"test:anchor": "anchor test",
18+
"test:forge": "forge test",
1819
"test:hardhat": "hardhat test"
1920
},
2021
"resolutions": {

examples/lzapp-migration/tasks/common/wire.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ task(TASK_LZ_OAPP_WIRE)
104104
//
105105
//
106106

107-
// construct the user's keypair via the SOLANA_PRIVATE_KEY env var
108-
const keypair = useWeb3Js().web3JsKeypair
107+
// construct the user's keypair via SOLANA_PRIVATE_KEY or other supported methods
108+
const keypair = (await useWeb3Js()).web3JsKeypair
109109
const userAccount = keypair.publicKey
110110

111111
const solanaDeployment = getSolanaDeployment(args.solanaEid)

examples/lzapp-migration/tasks/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ import './evm/v1/setMinDstGas'
99
import './solana/createOFT'
1010
import './solana/sendSolana'
1111
import './solana/debug'
12+
import './solana/retryPayload'
13+
import './solana/setAuthority'
14+
import './solana/updateMetadata'
15+
import './solana/setUpdateAuthority'
16+
import './solana/getPrioFees'
17+
import './solana/base58'
1218
import './solana/initConfig'

examples/lzapp-migration/tasks/solana/index.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ import {
2424
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2525
import { createWeb3JsEddsa } from '@metaplex-foundation/umi-eddsa-web3js'
2626
import { toWeb3JsInstruction, toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'
27-
import { AddressLookupTableAccount, Connection, Keypair } from '@solana/web3.js'
27+
import { AddressLookupTableAccount, Connection } from '@solana/web3.js'
2828
import { getSimulationComputeUnits } from '@solana-developers/helpers'
29-
import bs58 from 'bs58'
3029
import { backOff } from 'exponential-backoff'
3130

3231
import { formatEid } from '@layerzerolabs/devtools'
33-
import { getPrioritizationFees } from '@layerzerolabs/devtools-solana'
32+
import { getPrioritizationFees, getSolanaKeypair } from '@layerzerolabs/devtools-solana'
3433
import { promptToContinue } from '@layerzerolabs/io-devtools'
3534
import { EndpointId, endpointIdToNetwork } from '@layerzerolabs/lz-definitions'
3635
import { OftPDA } from '@layerzerolabs/oft-v2-solana-sdk'
@@ -42,29 +41,16 @@ const LOOKUP_TABLE_ADDRESS: Partial<Record<EndpointId, PublicKey>> = {
4241
[EndpointId.SOLANA_V2_TESTNET]: publicKey('9thqPdbR27A1yLWw2spwJLySemiGMXxPnEvfmXVk4KuK'),
4342
}
4443

45-
const getFromEnv = (key: string): string => {
46-
const value = process.env[key]
47-
if (!value) {
48-
throw new Error(`${key} is not defined in the environment variables.`)
49-
}
50-
return value
51-
}
52-
53-
/**
54-
* Extracts the SOLANA_PRIVATE_KEY from the environment. This is purposely not exported for encapsulation purposes.
55-
*/
56-
const getSolanaPrivateKeyFromEnv = () => getFromEnv('SOLANA_PRIVATE_KEY')
57-
5844
/**
5945
* Derive common connection and UMI objects for a given endpoint ID.
6046
* @param eid {EndpointId}
6147
*/
6248
export const deriveConnection = async (eid: EndpointId, readOnly = false) => {
63-
const privateKey = readOnly ? bs58.encode(Keypair.generate().secretKey) : getSolanaPrivateKeyFromEnv()
49+
const keypair = await getSolanaKeypair(readOnly)
6450
const connectionFactory = createSolanaConnectionFactory()
6551
const connection = await connectionFactory(eid)
6652
const umi = createUmi(connection.rpcEndpoint).use(mplToolbox())
67-
const umiWalletKeyPair = umi.eddsa.createKeypairFromSecretKey(bs58.decode(privateKey))
53+
const umiWalletKeyPair = umi.eddsa.createKeypairFromSecretKey(keypair.secretKey)
6854
const umiWalletSigner = createSignerFromKeypair(umi, umiWalletKeyPair)
6955
umi.use(signerIdentity(umiWalletSigner))
7056
return {
@@ -75,10 +61,8 @@ export const deriveConnection = async (eid: EndpointId, readOnly = false) => {
7561
}
7662
}
7763

78-
export const useWeb3Js = () => {
79-
const privateKey = getSolanaPrivateKeyFromEnv()
80-
const secretKeyBytes = bs58.decode(privateKey)
81-
const keypair = Keypair.fromSecretKey(secretKeyBytes)
64+
export const useWeb3Js = async () => {
65+
const keypair = await getSolanaKeypair()
8266
return {
8367
web3JsKeypair: keypair,
8468
}

examples/lzapp-migration/tasks/solana/retryPayload.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { web3 } from '@coral-xyz/anchor'
22
import { toWeb3JsKeypair } from '@metaplex-foundation/umi-web3js-adapters'
3-
import { ComputeBudgetProgram, Keypair, sendAndConfirmTransaction } from '@solana/web3.js'
4-
import bs58 from 'bs58'
3+
import { ComputeBudgetProgram, sendAndConfirmTransaction } from '@solana/web3.js'
54
import { task } from 'hardhat/config'
65

76
import { makeBytes32 } from '@layerzerolabs/devtools'
@@ -48,10 +47,6 @@ task('lz:oft:solana:retry-payload', 'Retry a stored payload on Solana')
4847
lamports,
4948
withPriorityFee,
5049
}: Args) => {
51-
if (!process.env.SOLANA_PRIVATE_KEY) {
52-
throw new Error('SOLANA_PRIVATE_KEY is not defined in the environment variables.')
53-
}
54-
5550
const { connection, umiWalletKeyPair } = await deriveConnection(dstEid)
5651
const signer = toWeb3JsKeypair(umiWalletKeyPair)
5752
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash()
@@ -89,10 +84,9 @@ task('lz:oft:solana:retry-payload', 'Retry a stored payload on Solana')
8984
tx.add(instruction)
9085
tx.recentBlockhash = blockhash
9186

92-
const keypair = Keypair.fromSecretKey(bs58.decode(process.env.SOLANA_PRIVATE_KEY))
93-
tx.sign(keypair)
87+
tx.sign(signer)
9488

95-
const signature = await sendAndConfirmTransaction(connection, tx, [keypair], { skipPreflight: true })
89+
const signature = await sendAndConfirmTransaction(connection, tx, [signer], { skipPreflight: true })
9690
console.log(
9791
`View Solana transaction here: ${getExplorerTxLink(signature.toString(), dstEid == EndpointId.SOLANA_V2_TESTNET)}`
9892
)

examples/lzapp-migration/tasks/solana/setInboundRateLimit.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

examples/lzapp-migration/tasks/solana/setOutboundRateLimit.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)