Skip to content

Commit

Permalink
add solana support to metadata-tools (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanL0 authored Jan 9, 2025
1 parent 0995096 commit e455d72
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-horses-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/metadata-tools": minor
---

add solana support to metadata-tools
24 changes: 22 additions & 2 deletions packages/metadata-tools/src/config-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function DVNsToAddresses(dvns: string[], chainKey: string, metadata: IMet
return dvnAddresses.sort()
}

function isSolanaDeployment(deployment: { chainKey: string; executor?: { pda?: string; address?: string } }) {
return deployment.chainKey.startsWith('solana')
}

export async function translatePathwayToConfig(
pathway: TwoWayConfig,
metadata: IMetadata
Expand All @@ -92,6 +96,14 @@ export async function translatePathwayToConfig(
const sourceLZDeployment = getEndpointIdDeployment(sourceContract.eid, metadata)
const destinationLZDeployment = getEndpointIdDeployment(destinationContract.eid, metadata)

const sourceExecutor = isSolanaDeployment(sourceLZDeployment)
? sourceLZDeployment.executor?.pda
: sourceLZDeployment.executor?.address

if (!sourceExecutor) {
throw new Error(`Can't find executor for source endpoint with eid: "${sourceContract.eid}".`)
}

const sourceRequiredDVNs = DVNsToAddresses(requiredDVNs, sourceLZDeployment.chainKey, metadata)
const destinationRequiredDVNs = DVNsToAddresses(requiredDVNs, destinationLZDeployment.chainKey, metadata)

Expand Down Expand Up @@ -131,7 +143,7 @@ export async function translatePathwayToConfig(
sendConfig: {
executorConfig: {
maxMessageSize: 10000,
executor: sourceLZDeployment.executor.address,
executor: sourceExecutor,
},
ulnConfig: {
confirmations: BigInt(sourceToDestinationConfirmations),
Expand Down Expand Up @@ -165,6 +177,14 @@ export async function translatePathwayToConfig(
}

if (destinationToSourceConfirmations) {
const destinationExecutor = isSolanaDeployment(destinationLZDeployment)
? destinationLZDeployment.executor?.pda
: destinationLZDeployment.executor?.address

if (!destinationExecutor) {
throw new Error(`Can't find executor for destination endpoint with eid: "${destinationContract.eid}".`)
}

sourceToDestinationConfig.config.receiveConfig = {
ulnConfig: {
confirmations: BigInt(destinationToSourceConfirmations),
Expand All @@ -179,7 +199,7 @@ export async function translatePathwayToConfig(
destinationToSourceConfig.config.sendConfig = {
executorConfig: {
maxMessageSize: 10000,
executor: destinationLZDeployment.executor.address,
executor: destinationExecutor,
},
ulnConfig: {
confirmations: BigInt(destinationToSourceConfirmations),
Expand Down
2 changes: 1 addition & 1 deletion packages/metadata-tools/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface IMetadata {
relayerV2?: { address: string }
ultraLightNodeV2?: { address: string }
nonceContract?: { address: string }
executor?: { address: string }
executor?: { address: string; pda?: string }
deadDVN?: { address: string }
endpointV2?: { address: string }
sendUln302?: { address: string }
Expand Down
7 changes: 4 additions & 3 deletions packages/metadata-tools/test/data/solana-mainnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"created": "2024-12-12T03:31:22.000Z",
"updated": "2024-12-12T03:31:22.000Z",
"created": "2025-01-07T18:33:21.000Z",
"updated": "2025-01-07T18:33:21.000Z",
"tableName": "layerzero-chain_metadata",
"environment": "mainnet",
"blockExplorers": [
Expand All @@ -17,7 +17,8 @@
"address": "8ahPGPjEbpgGaZx2NV1iG5Shj7TDwvsjkEDcGWjt94TP"
},
"executor": {
"address": "AwrbHeCyniXaQhiJZkLhgWdUCteeWSGaSN1sTfLiY7xK"
"pda": "AwrbHeCyniXaQhiJZkLhgWdUCteeWSGaSN1sTfLiY7xK",
"address": "6doghB248px58JSSwG4qejQ46kFMW4AMj7vzJnWZHNZn"
},
"endpointV2": {
"address": "76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6"
Expand Down
3 changes: 2 additions & 1 deletion packages/metadata-tools/test/data/solana-testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"address": "8ahPGPjEbpgGaZx2NV1iG5Shj7TDwvsjkEDcGWjt94TP"
},
"executor": {
"address": "AwrbHeCyniXaQhiJZkLhgWdUCteeWSGaSN1sTfLiY7xK"
"pda": "AwrbHeCyniXaQhiJZkLhgWdUCteeWSGaSN1sTfLiY7xK",
"address": "6doghB248px58JSSwG4qejQ46kFMW4AMj7vzJnWZHNZn"
},
"endpointV2": {
"address": "76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6"
Expand Down

0 comments on commit e455d72

Please sign in to comment.