Skip to content

Commit

Permalink
ON-815
Browse files Browse the repository at this point in the history
: update scripts
  • Loading branch information
Daniel Lima committed May 10, 2024
1 parent f7836bc commit 4827b2a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions scripts/nft-rental-marketplace/07-approve-nft.ts
Original file line number Diff line number Diff line change
@@ -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
})
18 changes: 13 additions & 5 deletions utils/write-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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...`)
Expand Down

0 comments on commit 4827b2a

Please sign in to comment.