From 4827b2a44b6a616055607360a2ee10d469600a55 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Fri, 10 May 2024 10:44:10 -0300 Subject: [PATCH] ON-815 : update scripts --- package-lock.json | 1 - .../nft-rental-marketplace/07-approve-nft.ts | 23 +++++++++++++++++++ utils/write-contract.ts | 18 +++++++++++---- 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 scripts/nft-rental-marketplace/07-approve-nft.ts diff --git a/package-lock.json b/package-lock.json index 070f38e..f56782d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "@openzeppelin/contracts-upgradeable": "^4.8.0-rc.1", "@openzeppelin/hardhat-upgrades": "^3.0.5", "@peculiar/asn1-ecc": "^2.3.8", - "@peculiar/asn1-schema": "^2.3.8", "defender-admin-client": "^1.37.0", "dotenv": "^16.0.3", "hardhat": "^2.22.2", diff --git a/scripts/nft-rental-marketplace/07-approve-nft.ts b/scripts/nft-rental-marketplace/07-approve-nft.ts new file mode 100644 index 0000000..70e9b0d --- /dev/null +++ b/scripts/nft-rental-marketplace/07-approve-nft.ts @@ -0,0 +1,23 @@ +import { print, colors } from '../../utils/misc' +import { callContractFunction } from '../../utils/write-contract' +import addresses, { Network } from '../../addresses' +import { network } from 'hardhat' + +const NETWORK = network.name as Network +const CONTRACT_NAME = 'MockERC721' +const CONTRACT_FUNCTION = 'setApprovalForAll' +const FUNCTION_PARAMS = [addresses[NETWORK].NftRentalMarketplace.address, true] +const CUSTOM_CONTRACT_ADDRESS = '0xcB13945Ca8104f813992e4315F8fFeFE64ac49cA' + +async function main() { + await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, FUNCTION_PARAMS, { CUSTOM_CONTRACT_ADDRESS }) +} + +main() + .then(() => { + print(colors.bigSuccess, 'All done!') + }) + .catch(error => { + console.error(error) + process.exitCode = 1 + }) diff --git a/utils/write-contract.ts b/utils/write-contract.ts index e449208..66c3e43 100644 --- a/utils/write-contract.ts +++ b/utils/write-contract.ts @@ -12,15 +12,19 @@ const NETWORK = network.name as Network * @param CONTRACT_NAME The name of the contract * @param FUNCTION_NAME The function to call * @param FUNCTION_ARGUMENTS The arguments to pass to the function - * @param CUSTOM_FEE_DATA The custom fee data (optional) + * @param OPTIONS The custom fee data, signer or contract file name */ export async function callContractFunction( - CONTRACT_NAME: keyof (typeof config)[Network], + CONTRACT_NAME: keyof (typeof config)[Network] | string, FUNCTION_NAME: string, FUNCTION_ARGUMENTS: any, - CUSTOM_FEE_DATA?: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }, - CUSTOM_SIGNER?: Signer, + OPTIONS: { + CUSTOM_FEE_DATA?: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint } + CUSTOM_SIGNER?: Signer + CUSTOM_CONTRACT_ADDRESS?: string + }, ) { + const { CUSTOM_FEE_DATA, CUSTOM_SIGNER, CUSTOM_CONTRACT_ADDRESS } = OPTIONS const signer = CUSTOM_SIGNER || (await ethers.getSigners())[0] console.log('CONTRACT_NAME', CONTRACT_NAME) await confirmOrDie( @@ -32,7 +36,11 @@ export async function callContractFunction( } print(colors.warn, `Arguments:`) console.log(FUNCTION_ARGUMENTS) - const contract = await ethers.getContractAt(CONTRACT_NAME, config[NETWORK][CONTRACT_NAME].address, signer) + const contract = await ethers.getContractAt( + CONTRACT_NAME, + CUSTOM_CONTRACT_ADDRESS ?? config[NETWORK][CONTRACT_NAME as keyof (typeof config)[Network]].address, + signer, + ) print(colors.highlight, `Sending Transaction...`) const response = await contract[FUNCTION_NAME](...FUNCTION_ARGUMENTS) print(colors.highlight, `Waiting for transaction to be mined...`)