Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗞️ solana cli debugging tasks #1327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/silly-chairs-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/oft-solana-example": patch
---

Debugging Hardhat tasks
1 change: 1 addition & 0 deletions examples/oft-solana/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './solana/initConfig'
import './solana/clearPayload'
import './solana/createOFT'
import './solana/createOFTAdapter'
import './solana/debug'
import './solana/getRateLimits'
import './solana/sendOFT'
import './solana/setAuthority'
Expand Down
85 changes: 85 additions & 0 deletions examples/oft-solana/tasks/solana/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { publicKey } from '@metaplex-foundation/umi'
import { toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'
import { PublicKey } from '@solana/web3.js'
import { task } from 'hardhat/config'

import { types } from '@layerzerolabs/devtools-evm-hardhat'
import { EndpointId } from '@layerzerolabs/lz-definitions'
import { EndpointPDADeriver, EndpointProgram } from '@layerzerolabs/lz-solana-sdk-v2'
import { oft } from '@layerzerolabs/oft-v2-solana-sdk'

import { deriveConnection, getSolanaDeployment } from './index'

/**
* Get the OFTStore account from the task arguments, the deployment file, or throw an error.
* @param {EndpointId} eid
* @param {string} oftStore
*/
const getOftStore = (eid: EndpointId, oftStore?: string) => publicKey(oftStore ?? getSolanaDeployment(eid).oftStore)

task('lz:oft:solana:dump-oft-store', 'Gets the OFTStore information')
.addParam(
'eid',
'Solana mainnet (30168) or testnet (40168). Defaults to mainnet.',
EndpointId.SOLANA_V2_MAINNET,
types.eid
)
.addParam(
'oftStore',
'The OFTStore public key. Derived from deployments if not provided.',
undefined,
types.string,
true
)
.setAction(async (taskArgs, _) => {
const { umi } = await deriveConnection(taskArgs.eid)
const oftStore = getOftStore(taskArgs.eid, taskArgs.oftStore)
console.dir(await oft.accounts.fetchOFTStore(umi, oftStore), { depth: null })
})

task('lz:oft:solana:get-admin', 'Gets the OFTStore information')
.addParam(
'eid',
'Solana mainnet (30168) or testnet (40168). Defaults to mainnet.',
EndpointId.SOLANA_V2_MAINNET,
types.eid
)
.addParam(
'oftStore',
'The OFTStore public key. Derived from deployments if not provided.',
undefined,
types.string,
true
)
.setAction(async (taskArgs, _) => {
const { umi } = await deriveConnection(taskArgs.eid)
const oftStore = getOftStore(taskArgs.eid, taskArgs.oftStore)
console.log(`admin: ${(await oft.accounts.fetchOFTStore(umi, oftStore)).admin}`)
})

task('lz:oft:solana:get-delegate', 'Gets the OAppRegistry information')
.addParam(
'eid',
'Solana mainnet (30168) or testnet (40168). Defaults to mainnet.',
EndpointId.SOLANA_V2_MAINNET,
types.eid
)
.addParam(
'oftStore',
'The OFTStore public key. Derived from deployments if not provided.',
undefined,
types.string,
true
)
.addParam('endpoint', 'The Endpoint public key', EndpointProgram.PROGRAM_ID.toBase58(), types.string)
.setAction(async (taskArgs, _) => {
const { connection } = await deriveConnection(taskArgs.eid)
const deriver = new EndpointPDADeriver(new PublicKey(taskArgs.endpoint))
const oftStore = getOftStore(taskArgs.eid, taskArgs.oftStore)
const [oAppRegistry] = deriver.oappRegistry(toWeb3JsPublicKey(oftStore))
const oAppRegistryInfo = await EndpointProgram.accounts.OAppRegistry.fromAccountAddress(
connection,
oAppRegistry
)
console.log(`delegate: ${oAppRegistryInfo?.delegate?.toBase58()}`)
})