diff --git a/contracts/NftRentalMarketplace.sol b/contracts/NftRentalMarketplace.sol index 64d3d23..39b379a 100644 --- a/contracts/NftRentalMarketplace.sol +++ b/contracts/NftRentalMarketplace.sol @@ -310,4 +310,13 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr function unpause() external onlyOwner { _unpause(); } + + /** + * @notice Sets the address of the OriumMarketplaceRoyalties contract. + * @dev Only owner can call this function. + * @param _oriumMarketplaceRoyalties The address of the OriumMarketplaceRoyalties contract. + */ + function setOriumMarketplaceRoyalties(address _oriumMarketplaceRoyalties) external onlyOwner { + oriumMarketplaceRoyalties = _oriumMarketplaceRoyalties; + } } diff --git a/scripts/nft-rental-marketplace/05-set-royalties.ts b/scripts/nft-rental-marketplace/05-set-royalties.ts new file mode 100644 index 0000000..7035024 --- /dev/null +++ b/scripts/nft-rental-marketplace/05-set-royalties.ts @@ -0,0 +1,22 @@ +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 = 'NftRentalMarketplace' +const CONTRACT_FUNCTION = 'setOriumMarketplaceRoyalties' +const FUNCTION_PARAMS = [addresses[NETWORK].OriumMarketplaceRoyalties.address] + +async function main() { + await callContractFunction(CONTRACT_NAME, CONTRACT_FUNCTION, FUNCTION_PARAMS) +} + +main() + .then(() => { + print(colors.bigSuccess, 'All done!') + }) + .catch(error => { + console.error(error) + process.exitCode = 1 + }) diff --git a/scripts/nft-rental-marketplace/06-upgrade.ts b/scripts/nft-rental-marketplace/06-upgrade.ts new file mode 100644 index 0000000..1ef8255 --- /dev/null +++ b/scripts/nft-rental-marketplace/06-upgrade.ts @@ -0,0 +1,17 @@ +import { print, colors } from '../../utils/misc' +import { upgradeProxy } from '../../utils/upgrade-proxy' + +const CONTRACT_NAME = 'NftRentalMarketplace' + +async function main() { + await upgradeProxy(CONTRACT_NAME) +} + +main() + .then(() => { + print(colors.bigSuccess, 'All done!') + }) + .catch(error => { + console.error(error) + process.exitCode = 1 + }) diff --git a/utils/upgrade-proxy.ts b/utils/upgrade-proxy.ts new file mode 100644 index 0000000..e43bde8 --- /dev/null +++ b/utils/upgrade-proxy.ts @@ -0,0 +1,94 @@ +import hre, { ethers, network, upgrades } from 'hardhat' +import { print, confirmOrDie, colors } from './misc' +import addresses, { Network } from '../addresses' +import { updateJsonFile } from './json' +import { kmsDeployer, kmsProvider } from './deployer' + +const NETWORK = network.name as Network + +/** + * @notice Upgrade an proxy contract + * @dev The contract must existis in a solidity file in the contracts folder with the same name + * @param PROXY_CONTRACT_NAME The name of the contract + * @param LIBRARIES_CONTRACT_NAME The name of the libraries + * @param CUSTOM_FEE_DATA The custom fee data + */ +export async function upgradeProxy( + PROXY_CONTRACT_NAME: keyof (typeof addresses)[Network], + LIBRARIES_CONTRACT_NAME?: string[], + CUSTOM_FEE_DATA?: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }, +) { + if (CUSTOM_FEE_DATA !== undefined) { + const FEE_DATA: any = CUSTOM_FEE_DATA + kmsProvider.getFeeData = async () => FEE_DATA + } + const deployerAddress = await kmsDeployer.getAddress() + const libraries: { [key: string]: string } = {} + + await confirmOrDie( + `Upgrading ${PROXY_CONTRACT_NAME} contract on: ${NETWORK} network with ${deployerAddress}. Continue?`, + ) + + if (LIBRARIES_CONTRACT_NAME !== undefined) { + print(colors.highlight, 'Deploying libraries...') + + for (const LIBRARY_CONTRACT_NAME of LIBRARIES_CONTRACT_NAME) { + const LibraryFactory = await ethers.getContractFactory(LIBRARY_CONTRACT_NAME, kmsDeployer) + const library = await LibraryFactory.deploy() + await library.waitForDeployment() + libraries[LIBRARY_CONTRACT_NAME] = await library.getAddress() + } + + print(colors.success, 'Libraries deployed!') + } + + print(colors.highlight, 'Upgrading proxy contract...') + const ContractFactory = await ethers.getContractFactory(PROXY_CONTRACT_NAME, { + libraries, + signer: kmsDeployer, + }) + const contract = await upgrades.upgradeProxy(addresses[NETWORK][PROXY_CONTRACT_NAME].address, ContractFactory, { + unsafeAllowLinkedLibraries: true, + }) + await contract.waitForDeployment() + print(colors.success, `${PROXY_CONTRACT_NAME} upgraded to: ${contract.address}`) + + print(colors.highlight, 'Updating config files...') + const deploymentInfo: any = { + [PROXY_CONTRACT_NAME]: { + ...addresses[NETWORK][PROXY_CONTRACT_NAME], + implementation: await upgrades.erc1967.getImplementationAddress(await contract.getAddress()), + }, + } + + if (LIBRARIES_CONTRACT_NAME) { + deploymentInfo[PROXY_CONTRACT_NAME].libraries = libraries + } + + console.log(deploymentInfo) + updateJsonFile(`addresses/${NETWORK}/index.json`, deploymentInfo) + print(colors.success, 'Config files updated!') + + if (LIBRARIES_CONTRACT_NAME) { + print(colors.highlight, 'Verifying libraries on block explorer...') + for (const LIBRARY_CONTRACT_NAME of LIBRARIES_CONTRACT_NAME) { + try { + print(colors.highlight, `Verifying library ${LIBRARY_CONTRACT_NAME}...`) + await hre.run('verify:verify', { + address: libraries[LIBRARY_CONTRACT_NAME], + constructorArguments: [], + }) + print(colors.success, `${LIBRARY_CONTRACT_NAME} verified!`) + } catch (e) { + print(colors.error, `Error verifying library ${LIBRARY_CONTRACT_NAME}: ${e}`) + } + } + } + + print(colors.highlight, 'Verifying contract on block explorer...') + await hre.run('verify:verify', { + address: await contract.getAddress(), + constructorArguments: [], + }) + print(colors.success, `${PROXY_CONTRACT_NAME} verified!`) +}