Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add freeze / thaw trading scripts #114

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`);
};
Loading