Skip to content

Commit

Permalink
[REG-1555] Batch Mint TLD script
Browse files Browse the repository at this point in the history
  • Loading branch information
nickshatilo committed Nov 18, 2024
1 parent ce9583e commit 575c914
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
86 changes: 86 additions & 0 deletions scripts/batchMintTlds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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 () {
const argv = yargs().env('').string('tlds').boolean('expirable').parseSync();

const tlds = argv.tlds?.split(',').map((tld) => tld.trim());
const expirable = argv.expirable ?? false;

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:', tlds.join(','));
console.log('Expirable:', expirable);

console.log('Network:', network.name);

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);
});
11 changes: 11 additions & 0 deletions src/defender.ts
Original file line number Diff line number Diff line change
@@ -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());
};
34 changes: 34 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 575c914

Please sign in to comment.