From 13e88bf073b61d19454e207a93a0bf275fc7efe0 Mon Sep 17 00:00:00 2001 From: Channing Date: Thu, 29 Feb 2024 23:09:28 -0800 Subject: [PATCH] Add freeze / thaw trading scripts --- hardhat.config.ts | 21 +++++++++++++++------ scripts/common/constants.ts | 6 +++++- scripts/freezeTrading.ts | 37 +++++++++++++++++++++++++++++++++++++ scripts/ownerMint.ts | 2 +- scripts/thawTrading.ts | 28 ++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 scripts/freezeTrading.ts create mode 100644 scripts/thawTrading.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index 101cd7bf..6557dc20 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -40,6 +40,8 @@ import { deployOwnedRegistrant } from './scripts/deployOwnedRegistrant'; import { getContractCodehash } from './scripts/dev/getContractCodehash'; import { deploy721BatchTransfer } from './scripts/dev/deploy721BatchTransfer'; import { send721Batch } from './scripts/send721Batch'; +import { freezeTrading } from './scripts/freezeTrading'; +import { thawTrading } from './scripts/thawTrading'; const config: HardhatUserConfig = { solidity: { @@ -77,7 +79,7 @@ const config: HardhatUserConfig = { }, sepolia: { url: - process.env.SEPOLIA_URL || 'https://ethereum-sepolia.publicnode.com', + process.env.SEPOLIA_URL || 'https://rpc.sepolia.org', accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], }, @@ -100,11 +102,6 @@ const config: HardhatUserConfig = { url: process.env.FUJI_URL || 'https://api.avax-test.network/ext/bc/C/rpc', accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], - }, - sepolia: { - url: process.env.SEPOLIA_URL || 'https://rpc.sepolia.org', - accounts: - process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], } }, gasReporter: { @@ -363,4 +360,16 @@ task('send721Batch', 'Send ERC721 tokens in batch') .addOptionalParam('tokenids', 'token ids (if not using transferFile), separate with comma') .setAction(send721Batch); +task('freezeTrading', 'Freeze trading for 721Cv2') + .addParam('contract', 'contract address') + .addOptionalParam('validator', 'security validator') + .addOptionalParam('level', 'security level') + .addOptionalParam('whitelistid', 'whitelist id') + .addOptionalParam('permittedreceiverid', 'permitted receiver list id') + .setAction(freezeTrading); + +task('thawTrading', 'Thaw trading for 721Cv2') + .addParam('contract', 'contract address') + .setAction(thawTrading); + export default config; diff --git a/scripts/common/constants.ts b/scripts/common/constants.ts index 1e5338ca..22bf500e 100644 --- a/scripts/common/constants.ts +++ b/scripts/common/constants.ts @@ -61,4 +61,8 @@ export const ChainIds: Record = { 'zksync-testnet': 10165, }; -export const ERC721BatchTransferContract = '0x38F7ba911f7efc434D29D6E39c814E9d4De3FEef'; \ No newline at end of file +export const ERC721BatchTransferContract = '0x38F7ba911f7efc434D29D6E39c814E9d4De3FEef'; + +export const ERC721CV2_VALIDATOR = '0x721C00182a990771244d7A71B9FA2ea789A3b433'; +export const ERC721CV2_FREEZE_LEVEL = 4; +export const ERC721CV2_EMPTY_LIST = 4; \ No newline at end of file diff --git a/scripts/freezeTrading.ts b/scripts/freezeTrading.ts new file mode 100644 index 00000000..86ccfb37 --- /dev/null +++ b/scripts/freezeTrading.ts @@ -0,0 +1,37 @@ +import { confirm } from '@inquirer/prompts'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { ContractDetails, ERC721CV2_EMPTY_LIST, ERC721CV2_FREEZE_LEVEL, ERC721CV2_VALIDATOR } from './common/constants'; +import { estimateGas } from './utils/helper'; + +export interface IFreezeTrading { + contract: string; + validator?: string; + level?: number; + whitelistid?: number; + permittedreceiverid?: number; +} + +export const freezeTrading = async ( + args: IFreezeTrading, + hre: HardhatRuntimeEnvironment, +) => { + const { ethers } = hre; + const factory = await ethers.getContractFactory(ContractDetails.ERC721CM.name); + const contract = factory.attach(args.contract); + + const validator = args.validator?? ERC721CV2_VALIDATOR; + const level = args.level?? ERC721CV2_FREEZE_LEVEL; + const whitelistid = args.whitelistid?? ERC721CV2_EMPTY_LIST; + const permittedreceiverid = args.permittedreceiverid?? ERC721CV2_EMPTY_LIST; + + const tx = await contract.populateTransaction.setToCustomValidatorAndSecurityPolicy(validator, level, whitelistid, permittedreceiverid); + await estimateGas(hre, tx); + console.log(`Going to freeze contract: ${args.contract}`); + if (!await confirm({ message: 'Continue?' })) return; + + const submittedTx = await contract.setToCustomValidatorAndSecurityPolicy(validator, level, whitelistid, permittedreceiverid); + + console.log(`Submitted tx ${submittedTx.hash}`); + await submittedTx.wait(); + console.log(`Contract ${args.contract} freezed`); +}; diff --git a/scripts/ownerMint.ts b/scripts/ownerMint.ts index bcdc9936..d53a1070 100644 --- a/scripts/ownerMint.ts +++ b/scripts/ownerMint.ts @@ -21,7 +21,7 @@ export const ownerMint = async ( const to = args.to ?? (await contract.signer.getAddress()); const tx = await contract.populateTransaction.ownerMint(qty, to); - estimateGas(hre, tx); + await estimateGas(hre, tx); console.log(`Going to mint ${qty.toNumber()} token(s) to ${to}`); if (!await confirm({ message: 'Continue?' })) return; diff --git a/scripts/thawTrading.ts b/scripts/thawTrading.ts new file mode 100644 index 00000000..0963249c --- /dev/null +++ b/scripts/thawTrading.ts @@ -0,0 +1,28 @@ +import { confirm } from '@inquirer/prompts'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { ContractDetails } from './common/constants'; +import { estimateGas } from './utils/helper'; + +export interface IThawTrading { + contract: string; +} + +export const thawTrading = async ( + args: IThawTrading, + hre: HardhatRuntimeEnvironment, +) => { + const { ethers } = hre; + const factory = await ethers.getContractFactory(ContractDetails.ERC721CM.name); + const contract = factory.attach(args.contract); + + const tx = await contract.populateTransaction.setToDefaultSecurityPolicy(); + await estimateGas(hre, tx); + console.log(`Going to thaw contract: ${args.contract}`); + if (!await confirm({ message: 'Continue?' })) return; + + const submittedTx = await contract.setToDefaultSecurityPolicy(); + + console.log(`Submitted tx ${submittedTx.hash}`); + await submittedTx.wait(); + console.log(`Contract ${args.contract} thawed`); +};