-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add endpoint addresses generator script #2
Draft
janjakubnanista
wants to merge
3
commits into
main
Choose a base branch
from
endpoints
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ | |
"types": "dist/index.d.ts", | ||
"module": "dist/index.mjs", | ||
"scripts": { | ||
"prepare": "ts-node scripts/prepare-endpoints.cts", | ||
"build": "npx tsup", | ||
"prebuild": "tsc -noEmit" | ||
"prebuild": "npx tsc -noEmit" | ||
}, | ||
"files": [ | ||
"dist/", | ||
|
@@ -19,6 +20,7 @@ | |
"@gnosis.pm/safe-core-sdk-types": "^1.0.0", | ||
"@gnosis.pm/safe-ethers-lib": "^1.0.0", | ||
"@gnosis.pm/safe-service-client": "1.1.1", | ||
"@layerzerolabs/lz-evm-sdk-v1": "1.5.52", | ||
"@nomiclabs/hardhat-ethers": "npm:[email protected]", | ||
"dotenv": "^16.0.3", | ||
"ethers": "^5.5.2", | ||
|
@@ -29,9 +31,8 @@ | |
"typescript": "^4.9.4" | ||
}, | ||
"dependencies": { | ||
"@layerzerolabs/lz-definitions": "latest", | ||
"@layerzerolabs/lz-definitions": "1.5.52", | ||
"@layerzerolabs/lz-sdk": "0.0.12", | ||
"@layerzerolabs/lz-evm-sdk-v1": "latest", | ||
"chalk": "4.1.2", | ||
"cli-ux": "^6.0.9" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { mkdirSync, opendirSync, writeFileSync } from "fs"; | ||
import { dirname, join, resolve } from "path"; | ||
import assert from "assert"; | ||
|
||
main(); | ||
|
||
/** | ||
* Pulls the endpoint addresses from the upstream package | ||
* without pulling the whole package into the bundled code | ||
*/ | ||
async function main() { | ||
// First we'll resolve the path to the @layerzerolabs/lz-evm-sdk-v1 package | ||
// | ||
// Instead of resolving the path to the module name itself, i.e. | ||
// `require.resolve("@layerzerolabs/lz-evm-sdk-v1")` we need to pinpoint | ||
// a specific file in the root of the package. | ||
// | ||
// This is because resolving the module name would result in a path to the main entrypoint | ||
// which could be nested in arbitrary directory under the package. We though want the package | ||
// root since we know the deployments folder is in the package root. | ||
const endpointDeploymentsPackagePath = require.resolve( | ||
"@layerzerolabs/lz-evm-sdk-v1/package.json" | ||
); | ||
|
||
// Now that we have the path to package.json, we can easily construct the path | ||
// to the deployments folder | ||
const deploymentsFolderPath = resolve( | ||
dirname(endpointDeploymentsPackagePath), | ||
"deployments" | ||
); | ||
|
||
// We'll accumulate the endpoint addresses in this object | ||
const endpointAddresses: Record<string, string> = {}; | ||
|
||
// Now we'll iterate over the contents of the deployments folder | ||
for await (const deploymentFolderName of opendirSync(deploymentsFolderPath)) { | ||
const networkName = deploymentFolderName.name; | ||
const endpointDeploymentFilePath = join( | ||
deploymentsFolderPath, | ||
networkName, | ||
"Endpoint.json" | ||
); | ||
|
||
try { | ||
// We'll load up the Endpoint deployment file and get the address from it | ||
const deployment = require(endpointDeploymentFilePath); | ||
const address = deployment.address; | ||
|
||
assert(!!address, `Missing endpoint address`); | ||
|
||
endpointAddresses[networkName] = address; | ||
} catch (error) { | ||
console.warn( | ||
`Problem getting endpoint address for ${networkName}: ${error}` | ||
); | ||
} | ||
} | ||
|
||
// The final step is to serialize the findings | ||
// and store them in the generated folder | ||
const outputFilePath = resolve( | ||
__dirname, | ||
"..", | ||
"generated", | ||
"endpoints.json" | ||
); | ||
const output = JSON.stringify(endpointAddresses, null, "\t"); | ||
|
||
mkdirSync(dirname(outputFilePath), { recursive: true }); | ||
writeFileSync(outputFilePath, output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ export default defineConfig({ | |
splitting: false, | ||
treeshake: true, | ||
format: ["esm", "cjs"], | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@layerzerolabs/lz-evm-sdk-v1
is a private package, whileua-utils
is public.