diff --git a/scripts/deploy-communal-api3readerproxyv1.js b/scripts/deploy-communal-api3readerproxyv1.js index c022601..28a1d46 100644 --- a/scripts/deploy-communal-api3readerproxyv1.js +++ b/scripts/deploy-communal-api3readerproxyv1.js @@ -1,11 +1,13 @@ const hre = require('hardhat'); const api3Contracts = require('@api3/contracts'); +const { validateDapiName } = require('./utils'); async function main() { const dapiName = process.env.DAPI_NAME; if (!dapiName) { throw new Error('Environment variable DAPI_NAME is not defined'); } + validateDapiName(dapiName); const chainId = hre.network.config.chainId; const api3ReaderProxyV1Address = api3Contracts.computeCommunalApi3ReaderProxyV1Address(chainId, dapiName); if ((await hre.ethers.provider.getCode(api3ReaderProxyV1Address)) === '0x') { diff --git a/scripts/deploy-dapp-specific-api3readerproxyv1-unsafe.js b/scripts/deploy-dapp-specific-api3readerproxyv1-unsafe.js index 18e4d7c..75f7504 100644 --- a/scripts/deploy-dapp-specific-api3readerproxyv1-unsafe.js +++ b/scripts/deploy-dapp-specific-api3readerproxyv1-unsafe.js @@ -3,6 +3,7 @@ // proxies with arbirary dApp aliases to be deployed. const hre = require('hardhat'); const api3Contracts = require('@api3/contracts'); +const { validateDapiName } = require('./utils'); // Unlike the `@api3/contracts` version, the below does not throw due to // `dappAlias` not being recognized @@ -20,6 +21,7 @@ async function main() { if (!dapiName) { throw new Error('Environment variable DAPI_NAME is not defined'); } + validateDapiName(dapiName); const dappAlias = process.env.DAPP_ALIAS; if (!dappAlias) { throw new Error('Environment variable DAPP_ALIAS is not defined'); diff --git a/scripts/deploy-dapp-specific-api3readerproxyv1.js b/scripts/deploy-dapp-specific-api3readerproxyv1.js index 60d7a7b..7ef5010 100644 --- a/scripts/deploy-dapp-specific-api3readerproxyv1.js +++ b/scripts/deploy-dapp-specific-api3readerproxyv1.js @@ -1,11 +1,13 @@ const hre = require('hardhat'); const api3Contracts = require('@api3/contracts'); +const { validateDapiName } = require('./utils'); async function main() { const dapiName = process.env.DAPI_NAME; if (!dapiName) { throw new Error('Environment variable DAPI_NAME is not defined'); } + validateDapiName(dapiName); const dappAlias = process.env.DAPP_ALIAS; if (!dappAlias) { throw new Error('Environment variable DAPP_ALIAS is not defined'); diff --git a/scripts/print-communal-api3readerproxyv1-address.js b/scripts/print-communal-api3readerproxyv1-address.js index 83d9752..1b59e31 100644 --- a/scripts/print-communal-api3readerproxyv1-address.js +++ b/scripts/print-communal-api3readerproxyv1-address.js @@ -1,11 +1,13 @@ const hre = require('hardhat'); const api3Contracts = require('@api3/contracts'); +const { validateDapiName } = require('./utils'); async function main() { const dapiName = process.env.DAPI_NAME; if (!dapiName) { throw new Error('Environment variable DAPI_NAME is not defined'); } + validateDapiName(dapiName); const chainId = hre.network.config.chainId; const api3ReaderProxyV1Address = api3Contracts.computeCommunalApi3ReaderProxyV1Address(chainId, dapiName); console.log(`The address of the communal Api3ReaderProxyV1 for ${dapiName} is ${api3ReaderProxyV1Address}`); diff --git a/scripts/print-dapp-specific-api3readerproxyv1-address.js b/scripts/print-dapp-specific-api3readerproxyv1-address.js index 6914d75..6b589af 100644 --- a/scripts/print-dapp-specific-api3readerproxyv1-address.js +++ b/scripts/print-dapp-specific-api3readerproxyv1-address.js @@ -1,11 +1,13 @@ const hre = require('hardhat'); const api3Contracts = require('@api3/contracts'); +const { validateDapiName } = require('./utils'); async function main() { const dapiName = process.env.DAPI_NAME; if (!dapiName) { throw new Error('Environment variable DAPI_NAME is not defined'); } + validateDapiName(dapiName); const dappAlias = process.env.DAPP_ALIAS; if (!dappAlias) { throw new Error('Environment variable DAPP_ALIAS is not defined'); diff --git a/scripts/utils.js b/scripts/utils.js new file mode 100644 index 0000000..508851b --- /dev/null +++ b/scripts/utils.js @@ -0,0 +1,15 @@ +const api3DapiManagement = require('@api3/dapi-management'); + +module.exports = { + validateDapiName: (dapiName) => { + const dapi = api3DapiManagement.dapis.find((dapi) => dapi.name === dapiName); + if (!dapi) { + throw new Error(`dAPI with name ${dapiName} does not exist`); + } + if (dapi.stage === 'deprecated') { + console.warn(`dAPI with name ${dapiName} is deprecated`); + } else if (dapi.stage !== 'active') { + throw new Error(`dAPI with name ${dapiName} is not active, its current state is ${dapi.stage}`); + } + }, +};