getAddresses.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const {getNetworksForEnv} = require("@layerzerolabs/lz-sdk");
  2. const fs = require('fs');
  3. const environmentArg = process.argv[2]
  4. const contractCsvArg = process.argv[3]
  5. async function getAddresses(environment, contractCsv) {
  6. let contracts = contractCsv.split(',')
  7. const promises = [];
  8. for (const contract of contracts) {
  9. promises.push("\n" + contract);
  10. const networks = getNetworksForEnv(environment);
  11. for (const network of networks) {
  12. promises.push(
  13. getAddressForNetwork(
  14. `../deployments/${network}/${contract[0].toUpperCase() + contract.substring(1)}.json`,
  15. network)
  16. );
  17. }
  18. }
  19. const resolvedPromises = await Promise.all(promises);
  20. resolvedPromises.forEach((networkAddressStr) => {
  21. console.log(networkAddressStr)
  22. });
  23. }
  24. function getAddressForNetwork(file, network) {
  25. return new Promise( (res) => {
  26. fs.readFile(file, (error, content) => {
  27. if (content == undefined) {
  28. console.log(`File: ${file} does not exsist`);
  29. return
  30. }
  31. res(`${network}: ${JSON.parse(content).address}`);
  32. });
  33. })
  34. }
  35. // to run: node getAddresses ${ENVIRONMENT} ${CONTRACT_CSV}
  36. // example: node getAddresses testnet Relayer,Endpoint,UltraLightNode
  37. getAddresses(environmentArg, contractCsvArg).then(res => console.log("\nComplete!"))