Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions examples/lzapp-migration/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
root: true,
extends: ['@layerzerolabs/eslint-config-next/recommended'],
settings: {
'import/resolver': {
typescript: {
project: './tsconfig.json',
},
},
},
rules: {
// @layerzerolabs/eslint-config-next defines rules for turborepo-based projects
// that are not relevant for this particular project
'turbo/no-undeclared-env-vars': 'off',
'import/no-unresolved': 'warn',
},
Expand Down
8 changes: 0 additions & 8 deletions examples/lzapp-migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,6 @@ pnpm hardhat lz:oft:solana:create --eid 40168 --program-id <PROGRAM_ID>

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

#### For OFTAdapter:

```bash
pnpm hardhat lz:oft-adapter:solana:create --eid 40168 --program-id <PROGRAM_ID> --mint <TOKEN_MINT> --token-program <TOKEN_PROGRAM_ID>
```

: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.

#### For OFT Mint-And-Burn Adapter (MABA):

```bash
Expand Down
1 change: 1 addition & 0 deletions examples/lzapp-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"lint:sol": "solhint 'contracts/**/*.sol'",
"test": "$npm_execpath run test:hardhat",
"test:anchor": "anchor test",
"test:forge": "forge test",
"test:hardhat": "hardhat test"
},
"resolutions": {
Expand Down
4 changes: 2 additions & 2 deletions examples/lzapp-migration/tasks/common/wire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ task(TASK_LZ_OAPP_WIRE)
//
//

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

const solanaDeployment = getSolanaDeployment(args.solanaEid)
Expand Down
6 changes: 6 additions & 0 deletions examples/lzapp-migration/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ import './evm/v1/setMinDstGas'
import './solana/createOFT'
import './solana/sendSolana'
import './solana/debug'
import './solana/retryPayload'
import './solana/setAuthority'
import './solana/updateMetadata'
import './solana/setUpdateAuthority'
import './solana/getPrioFees'
import './solana/base58'
import './solana/initConfig'
28 changes: 6 additions & 22 deletions examples/lzapp-migration/tasks/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import {
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
import { createWeb3JsEddsa } from '@metaplex-foundation/umi-eddsa-web3js'
import { toWeb3JsInstruction, toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'
import { AddressLookupTableAccount, Connection, Keypair } from '@solana/web3.js'
import { AddressLookupTableAccount, Connection } from '@solana/web3.js'
import { getSimulationComputeUnits } from '@solana-developers/helpers'
import bs58 from 'bs58'
import { backOff } from 'exponential-backoff'

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

const getFromEnv = (key: string): string => {
const value = process.env[key]
if (!value) {
throw new Error(`${key} is not defined in the environment variables.`)
}
return value
}

/**
* Extracts the SOLANA_PRIVATE_KEY from the environment. This is purposely not exported for encapsulation purposes.
*/
const getSolanaPrivateKeyFromEnv = () => getFromEnv('SOLANA_PRIVATE_KEY')

/**
* Derive common connection and UMI objects for a given endpoint ID.
* @param eid {EndpointId}
*/
export const deriveConnection = async (eid: EndpointId, readOnly = false) => {
const privateKey = readOnly ? bs58.encode(Keypair.generate().secretKey) : getSolanaPrivateKeyFromEnv()
const keypair = await getSolanaKeypair(readOnly)
const connectionFactory = createSolanaConnectionFactory()
const connection = await connectionFactory(eid)
const umi = createUmi(connection.rpcEndpoint).use(mplToolbox())
const umiWalletKeyPair = umi.eddsa.createKeypairFromSecretKey(bs58.decode(privateKey))
const umiWalletKeyPair = umi.eddsa.createKeypairFromSecretKey(keypair.secretKey)
const umiWalletSigner = createSignerFromKeypair(umi, umiWalletKeyPair)
umi.use(signerIdentity(umiWalletSigner))
return {
Expand All @@ -75,10 +61,8 @@ export const deriveConnection = async (eid: EndpointId, readOnly = false) => {
}
}

export const useWeb3Js = () => {
const privateKey = getSolanaPrivateKeyFromEnv()
const secretKeyBytes = bs58.decode(privateKey)
const keypair = Keypair.fromSecretKey(secretKeyBytes)
export const useWeb3Js = async () => {
const keypair = await getSolanaKeypair()
return {
web3JsKeypair: keypair,
}
Expand Down
12 changes: 3 additions & 9 deletions examples/lzapp-migration/tasks/solana/retryPayload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { web3 } from '@coral-xyz/anchor'
import { toWeb3JsKeypair } from '@metaplex-foundation/umi-web3js-adapters'
import { ComputeBudgetProgram, Keypair, sendAndConfirmTransaction } from '@solana/web3.js'
import bs58 from 'bs58'
import { ComputeBudgetProgram, sendAndConfirmTransaction } from '@solana/web3.js'
import { task } from 'hardhat/config'

import { makeBytes32 } from '@layerzerolabs/devtools'
Expand Down Expand Up @@ -48,10 +47,6 @@ task('lz:oft:solana:retry-payload', 'Retry a stored payload on Solana')
lamports,
withPriorityFee,
}: Args) => {
if (!process.env.SOLANA_PRIVATE_KEY) {
throw new Error('SOLANA_PRIVATE_KEY is not defined in the environment variables.')
}

const { connection, umiWalletKeyPair } = await deriveConnection(dstEid)
const signer = toWeb3JsKeypair(umiWalletKeyPair)
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash()
Expand Down Expand Up @@ -89,10 +84,9 @@ task('lz:oft:solana:retry-payload', 'Retry a stored payload on Solana')
tx.add(instruction)
tx.recentBlockhash = blockhash

const keypair = Keypair.fromSecretKey(bs58.decode(process.env.SOLANA_PRIVATE_KEY))
tx.sign(keypair)
tx.sign(signer)

const signature = await sendAndConfirmTransaction(connection, tx, [keypair], { skipPreflight: true })
const signature = await sendAndConfirmTransaction(connection, tx, [signer], { skipPreflight: true })
console.log(
`View Solana transaction here: ${getExplorerTxLink(signature.toString(), dstEid == EndpointId.SOLANA_V2_TESTNET)}`
)
Expand Down
80 changes: 0 additions & 80 deletions examples/lzapp-migration/tasks/solana/setInboundRateLimit.ts

This file was deleted.

81 changes: 0 additions & 81 deletions examples/lzapp-migration/tasks/solana/setOutboundRateLimit.ts

This file was deleted.

Loading