From 7a960ce00b526ebb4918ca49dafafd2a007074a0 Mon Sep 17 00:00:00 2001 From: Nick Shatilo Date: Mon, 18 Nov 2024 16:55:33 +0000 Subject: [PATCH] [REG-1555] Batch Mint TLD script --- CHANGELOG.md | 3 ++ package.json | 1 + scripts/batchMintTlds.ts | 94 ++++++++++++++++++++++++++++++++++++++++ src/defender.ts | 11 +++++ yarn.lock | 34 +++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 scripts/batchMintTlds.ts create mode 100644 src/defender.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ce6d4fe..12474f4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v0.9.41 +- Added a script to batch mint TLDs proposal + ## v0.9.40 - Fixed `RegistrarCustody` minting permissions setup in sandbox diff --git a/package.json b/package.json index f1a631a3..9dd1f86e 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@nomiclabs/hardhat-solhint": "^3.0.1", "@opensea/seaport-js": "^4.0.0", "@openzeppelin/contracts-upgradeable": "^4.7.3", + "@openzeppelin/defender-sdk-proposal-client": "^1.15.2", "@openzeppelin/hardhat-upgrades": "^2.0.0", "@openzeppelin/upgrades-core": "^1.32.5", "@safe-global/protocol-kit": "^4.0.3", diff --git a/scripts/batchMintTlds.ts b/scripts/batchMintTlds.ts new file mode 100644 index 00000000..dc5673c8 --- /dev/null +++ b/scripts/batchMintTlds.ts @@ -0,0 +1,94 @@ +import { ethers, network, config as hardhatConfig } from 'hardhat'; +import yargs from 'yargs'; +import { getNetworkConfig } from '../src/config'; +import { getProposalClient } from '../src/defender'; +import { unwrap } from '../src/utils'; + +const DEFENDER_NETWORK_NAME_REMAPS = { + polygon: 'matic', +}; + +const MAX_BATCH_SIZE = 100; + +async function main () { + console.log('Network:', network.name); + + const argv = yargs().env('').string('tlds').boolean('expirable').parseSync(); + + const tlds = argv.tlds?.split(',').map((tld) => tld.trim()); + const expirable = argv.expirable ?? true; + + if (!tlds || !tlds.length) { + throw new Error('TLDs not provided'); + } + + if (tlds.length > MAX_BATCH_SIZE) { + throw new Error(`TLDs count exceeds ${MAX_BATCH_SIZE}`); + } + + console.log('Creating a TLD proposal for: '); + console.table( + tlds.map( + (tld) => ({ + TLD: tld, + Expirable: expirable ? 'Yes' : 'No', + }), + ['TLD', 'Expirable'], + ), + ); + + const chainId: number = unwrap(network.config, 'chainId'); + const config = getNetworkConfig(chainId); + if (!config) { + throw new Error(`Config not found for network ${chainId}`); + } + + const multisigAddr = hardhatConfig.uns.multisig[network.name]; + + if (!multisigAddr) { + throw new Error(`Multisig address is not set for network ${network.name}`); + } + + const mintingManager = await ethers.getContractAt('MintingManager', config.contracts.MintingManager.address); + const addTldFunc = mintingManager.interface.getFunction('addTld'); + + const defenderNetworkName = DEFENDER_NETWORK_NAME_REMAPS[network.name] ?? network.name; + + const response = await getProposalClient().create({ + proposal: { + contract: tlds.map(() => ({ + name: 'MintingManager', + address: config.contracts.MintingManager.address, + network: defenderNetworkName, + })), + via: multisigAddr, + viaType: 'Safe', + title: 'Add TLDs', + description: tlds.join(', '), + type: 'batch', + steps: tlds.map((tld) => ({ + contractId: [defenderNetworkName, config.contracts.MintingManager.address].join('-'), + type: 'custom', + targetFunction: { + name: addTldFunc.name, + inputs: addTldFunc.inputs.map((input) => ({ + name: input.name, + type: input.type, + baseType: input.baseType, + })), + }, + functionInputs: [tld, expirable], + })), + metadata: {}, + }, + }); + + console.log('Proposal created: ', response.url); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/src/defender.ts b/src/defender.ts new file mode 100644 index 00000000..982b46c0 --- /dev/null +++ b/src/defender.ts @@ -0,0 +1,11 @@ +import { ProposalClient } from '@openzeppelin/defender-sdk-proposal-client'; +import { unwrap } from './utils'; + +export const defenderAPICreds = () => ({ + apiKey: unwrap(process.env, 'DEFENDER_API_KEY'), + apiSecret: unwrap(process.env, 'DEFENDER_API_SECRET'), +}); + +export const getProposalClient = () => { + return new ProposalClient(defenderAPICreds()); +}; diff --git a/yarn.lock b/yarn.lock index 96db3ecb..676b9d39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1382,6 +1382,16 @@ __metadata: languageName: node linkType: hard +"@openzeppelin/defender-sdk-base-client@npm:^1.15.2": + version: 1.15.2 + resolution: "@openzeppelin/defender-sdk-base-client@npm:1.15.2" + dependencies: + amazon-cognito-identity-js: ^6.3.6 + async-retry: ^1.3.3 + checksum: 033b5558eae7098e86b34edc605cef7333fb5e840c4e3a82b7e5329ed782d442190ca21c04f814f8eab930237ee71529e336428646a3ac1fca2675e116b455db + languageName: node + linkType: hard + "@openzeppelin/defender-sdk-deploy-client@npm:^1.8.0": version: 1.12.0 resolution: "@openzeppelin/defender-sdk-deploy-client@npm:1.12.0" @@ -1393,6 +1403,18 @@ __metadata: languageName: node linkType: hard +"@openzeppelin/defender-sdk-proposal-client@npm:^1.15.2": + version: 1.15.2 + resolution: "@openzeppelin/defender-sdk-proposal-client@npm:1.15.2" + dependencies: + "@openzeppelin/defender-sdk-base-client": ^1.15.2 + axios: ^1.7.2 + ethers: ^6.9.0 + lodash: ^4.17.21 + checksum: d03e41278d70c291613d0d9d9f4fce2a2c46a4ebbffa6801bdf4c2b61afef4860182962a621f2bb39d9cd9c37f0b77443657fe5f83a3717864c750775bacfbc6 + languageName: node + linkType: hard + "@openzeppelin/hardhat-upgrades@npm:^2.0.0": version: 2.5.1 resolution: "@openzeppelin/hardhat-upgrades@npm:2.5.1" @@ -3051,6 +3073,17 @@ __metadata: languageName: node linkType: hard +"axios@npm:^1.7.2": + version: 1.7.7 + resolution: "axios@npm:1.7.7" + dependencies: + follow-redirects: ^1.15.6 + form-data: ^4.0.0 + proxy-from-env: ^1.1.0 + checksum: 882d4fe0ec694a07c7f5c1f68205eb6dc5a62aecdb632cc7a4a3d0985188ce3030e0b277e1a8260ac3f194d314ae342117660a151fabffdc5081ca0b5a8b47fe + languageName: node + linkType: hard + "balanced-match@npm:^1.0.0": version: 1.0.2 resolution: "balanced-match@npm:1.0.2" @@ -12199,6 +12232,7 @@ __metadata: "@nomiclabs/hardhat-solhint": ^3.0.1 "@opensea/seaport-js": ^4.0.0 "@openzeppelin/contracts-upgradeable": ^4.7.3 + "@openzeppelin/defender-sdk-proposal-client": ^1.15.2 "@openzeppelin/hardhat-upgrades": ^2.0.0 "@openzeppelin/upgrades-core": ^1.32.5 "@safe-global/protocol-kit": ^4.0.3