Skip to content

Commit

Permalink
Add freeze / thaw trading scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
channing-magiceden committed Mar 1, 2024
1 parent 26a48f9 commit 13e88bf
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 8 deletions.
21 changes: 15 additions & 6 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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] : [],
},
Expand All @@ -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: {
Expand Down Expand Up @@ -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;
6 changes: 5 additions & 1 deletion scripts/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ export const ChainIds: Record<string, number> = {
'zksync-testnet': 10165,
};

export const ERC721BatchTransferContract = '0x38F7ba911f7efc434D29D6E39c814E9d4De3FEef';
export const ERC721BatchTransferContract = '0x38F7ba911f7efc434D29D6E39c814E9d4De3FEef';

export const ERC721CV2_VALIDATOR = '0x721C00182a990771244d7A71B9FA2ea789A3b433';
export const ERC721CV2_FREEZE_LEVEL = 4;
export const ERC721CV2_EMPTY_LIST = 4;
37 changes: 37 additions & 0 deletions scripts/freezeTrading.ts
Original file line number Diff line number Diff line change
@@ -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`);
};
2 changes: 1 addition & 1 deletion scripts/ownerMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
28 changes: 28 additions & 0 deletions scripts/thawTrading.ts
Original file line number Diff line number Diff line change
@@ -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`);
};

0 comments on commit 13e88bf

Please sign in to comment.