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

Add endpoint addresses generator script #2

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -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",
Copy link
Contributor

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, while ua-utils is public.

"@nomiclabs/hardhat-ethers": "npm:[email protected]",
"dotenv": "^16.0.3",
"ethers": "^5.5.2",
Expand All @@ -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"
},
Expand Down
71 changes: 71 additions & 0 deletions scripts/prepare-endpoints.cts
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);
}
4 changes: 2 additions & 2 deletions src/utils/crossChainHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Safe from "@gnosis.pm/safe-core-sdk";
import { LZ_APP_ABI } from "../constants/abi";
import { MainnetEndpointId, TestnetEndpointId, SandboxEndpointId } from "@layerzerolabs/lz-definitions";
import { promptToProceed, arrayToCsv, getConfig } from "./helpers";
const path = require("path");
const fs = require("fs");
import path from "path";
import fs from "fs";
import { writeFile } from "fs/promises";


Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export default defineConfig({
splitting: false,
treeshake: true,
format: ["esm", "cjs"],
});
});
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,17 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@layerzerolabs/lz-definitions@latest":
version "1.5.50"
resolved "https://registry.npmjs.org/@layerzerolabs/lz-definitions/-/lz-definitions-1.5.50.tgz#73bc7ce2f3417be83d83ef5861e8b4647b5ac458"
integrity sha512-lFV2Kdge1Q2RXmkXFs09q7sdL39CJ3UF0m0vFqaGmBHOqeSrIpDeoZBd/kcwTQkdmE2j5Gii8mBaD9b/sv9Nuw==
"@layerzerolabs/lz-definitions@1.5.52":
version "1.5.52"
resolved "https://registry.yarnpkg.com/@layerzerolabs/lz-definitions/-/lz-definitions-1.5.52.tgz#ebe74ee149b840fca8d8539a61de62068dc32349"
integrity sha512-ZPvJjxE7P+0GjWYOcGZqGACQJhy6TmX3cnk3MLk7ZMhxrh0GaCbDrv0glX8yc1GkzXIPviELbGWEwWaFZxIfqQ==
dependencies:
tiny-invariant "^1.3.1"

"@layerzerolabs/lz-evm-sdk-v1@latest":
version "1.5.50"
resolved "https://registry.npmjs.org/@layerzerolabs/lz-evm-sdk-v1/-/lz-evm-sdk-v1-1.5.50.tgz#37bb5571bd517259d7384f696080e6c57f55d417"
integrity sha512-8YGQPBTQGVjtwDeABhkbzHKQ5Lyv9UhmSd6+xBZiZ369qTNNgJco9qJ9LdT9WGEprzf+/38uO+MSJffTy5scmw==
"@layerzerolabs/lz-evm-sdk-v1@1.5.52":
version "1.5.52"
resolved "https://registry.yarnpkg.com/@layerzerolabs/lz-evm-sdk-v1/-/lz-evm-sdk-v1-1.5.52.tgz#9e0f1013275f726d677d4775a1d27a81eb0798be"
integrity sha512-XjmrjmthZXvRYf2dXIZ75qBhrAs3ZwDFbgtyPsph5+3kYtFB7FIGc2OUhe2YuVryhQTL33C42eRjDLHPWLbO5A==
dependencies:
"@ethersproject/abi" "^5.7.0"
"@ethersproject/providers" "^5.7.2"
Expand Down