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
7 changes: 7 additions & 0 deletions .changeset/bright-cows-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@layerzerolabs/ua-devtools-solana": minor
"@layerzerolabs/devtools-solana": minor
"@layerzerolabs/io-devtools": minor
---

validate solana owner or delegate is valid before proceeding to set
5 changes: 5 additions & 0 deletions .changeset/tall-poems-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/ua-devtools": patch
---

bump target version for tsconfig
1 change: 1 addition & 0 deletions packages/devtools-solana/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@solana-developers/helpers pinned to 2.8.0 due to this issue: https://solana.stackexchange.com/questions/21945/issue-with-solana-developers-helpers-package-in-browser-environments-anchors?utm_source=chatgpt.com
2 changes: 1 addition & 1 deletion packages/devtools-solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@safe-global/api-kit": "^1.3.0",
"@safe-global/protocol-kit": "^1.3.0",
"@solana-developers/helpers": "^2.8.1",
"@solana-developers/helpers": "2.8.0",
"ethers": "^5.7.2",
"p-memoize": "~4.0.4"
},
Expand Down
55 changes: 55 additions & 0 deletions packages/devtools-solana/src/common/addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { DebugLogger, KnownErrors } from '@layerzerolabs/io-devtools'
import { Connection, PublicKey, SystemProgram } from '@solana/web3.js'
import { PROGRAM_ID as SQUADS_PROGRAM_ID } from '@sqds/multisig'

/**
* Returns true if the provided address is a valid on-curve public key. This can mean the address is either a 'regular' Solana address or a Squads Vault PDA.
*/
export function isOnCurveAddress(address: string): boolean {
try {
return PublicKey.isOnCurve(new PublicKey(address).toBytes())
} catch {
return false
}
}

/**
* Returns true if the provided address could be a Squads vault PDA.
*/
export async function isPossibleSquadsVault(connection: Connection, address: string): Promise<boolean> {
try {
const pubkey = new PublicKey(address)
const accountInfo = await connection.getAccountInfo(pubkey)

return accountInfo != null && accountInfo.owner.equals(SystemProgram.programId)
} catch (error) {
return false
}
}

export async function assertValidSolanaAdmin(connection: Connection, address: string): Promise<void> {
const pubkey = new PublicKey(address)

try {
const accountInfo = await connection.getAccountInfo(pubkey)

if (accountInfo != null && accountInfo.owner.equals(SQUADS_PROGRAM_ID)) {
DebugLogger.printErrorAndFixSuggestion(KnownErrors.SOLANA_OWNER_OR_DELEGATE_CANNOT_BE_MULTISIG_ACCOUNT)
throw new Error(
`Invalid owner/delegate address ${address}. This is a Squads multisig account. Use the vault address instead.`
)
}

if (!isOnCurveAddress(address) && !(await isPossibleSquadsVault(connection, address))) {
DebugLogger.printErrorAndFixSuggestion(KnownErrors.SOLANA_INVALID_OWNER_OR_DELEGATE)
throw new Error(
`Invalid owner/delegate address ${address}. Must be a valid on-curve address or a Squads Vault PDA.`
)
}
} catch (error) {
Comment thread
nazreen marked this conversation as resolved.
if (error instanceof Error) {
throw error
}
throw new Error(String(error))
}
}
1 change: 1 addition & 0 deletions packages/devtools-solana/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './accounts'
export * from './schema'
export * from './types'
export * from './addresses'
10 changes: 10 additions & 0 deletions packages/io-devtools/src/stdio/debugLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export enum KnownErrors {
ERROR_QUOTING_NATIVE_GAS_COST = 'ERROR_QUOTING_NATIVE_GAS_COST',
ERROR_SENDING_TRANSACTION = 'ERROR_SENDING_TRANSACTION',
ERROR_GETTING_HRE = 'ERROR_GETTING_HARDHAT_RUNTIME_ENVIRONMENT_FOR_NETWORK',
SOLANA_INVALID_OWNER_OR_DELEGATE = 'SOLANA_INVALID_OWNER_OR_DELEGATE',
SOLANA_OWNER_OR_DELEGATE_CANNOT_BE_MULTISIG_ACCOUNT = 'SOLANA_OWNER_OR_DELEGATE_MULTISIG_ACCOUNT',
}

export enum KnownWarnings {
Expand Down Expand Up @@ -92,6 +94,14 @@ export const ERRORS_FIXES_MAP: Record<KnownErrors, ErrorFixInfo> = {
tip: 'Have you added the srcEid network to your `./hardhat.config.ts` file?',
info: 'If you loaded a custom OFT deployment from an EVM network, you must add the deployment srcEid to your `./hardhat.config.ts` file for the OFT to be found.',
},
[KnownErrors.SOLANA_INVALID_OWNER_OR_DELEGATE]: {
tip: 'The owner or delegate of the Solana OApp must either be a regular on curve address or a Squads Vault Account.',
info: 'Ensure that you are using a regular on-curve Solana address or a Squads Vault PDA as the owner or delegate of the OApp.',
},
[KnownErrors.SOLANA_OWNER_OR_DELEGATE_CANNOT_BE_MULTISIG_ACCOUNT]: {
tip: 'The owner or delegate of the Solana OApp must not be the Squads multisig account address.',
info: 'If you intend to use Squads Multisig, ensure that you are providing a Squads Vault address as the owner or delegate of the OApp. The Squads Multisig account address cannot be the owner or delegate.',
},
}

export const WARNINGS_FIXES_MAP: Record<KnownWarnings, ErrorFixInfo> = {
Expand Down
4 changes: 3 additions & 1 deletion packages/ua-devtools-solana/src/oft/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { EndpointId } from '@layerzerolabs/lz-definitions'
import { EndpointV2 } from '@layerzerolabs/protocol-devtools-solana'
import { type Logger, printBoolean, printJson } from '@layerzerolabs/io-devtools'
import { mapError, AsyncRetriable } from '@layerzerolabs/devtools'
import { OmniSDK } from '@layerzerolabs/devtools-solana'
import { assertValidSolanaAdmin, OmniSDK } from '@layerzerolabs/devtools-solana'
import { Connection, PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js'
import { Options } from '@layerzerolabs/lz-v2-utilities'
import assert from 'assert'
Expand Down Expand Up @@ -121,6 +121,7 @@ export class OFT extends OmniSDK implements IOApp {
}

async setOwner(address: OmniAddress): Promise<OmniTransaction> {
await assertValidSolanaAdmin(this.connection, address)
this.logger.debug(`Setting owner to ${address}`)

return {
Expand Down Expand Up @@ -236,6 +237,7 @@ export class OFT extends OmniSDK implements IOApp {
}

async setDelegate(delegate: OmniAddress): Promise<OmniTransaction> {
await assertValidSolanaAdmin(this.connection, delegate)
this.logger.debug(`Setting delegate to ${delegate}`)
return {
...(await this.createTransaction(this._umiToWeb3Tx([await this._setOFTDelegateIx(delegate)]))),
Expand Down
1 change: 1 addition & 0 deletions packages/ua-devtools/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"exclude": ["dist", "node_modules"],
"include": ["src", "test"],
"compilerOptions": {
"target": "es2020",
"types": ["node", "jest"],
"paths": {
"@/*": ["./src/*"]
Expand Down
100 changes: 84 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.