Skip to content

Commit

Permalink
ON-815: add set royalties function to nft rental marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed May 9, 2024
1 parent cbdc763 commit f7836bc
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contracts/NftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
22 changes: 22 additions & 0 deletions scripts/nft-rental-marketplace/05-set-royalties.ts
Original file line number Diff line number Diff line change
@@ -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
})
17 changes: 17 additions & 0 deletions scripts/nft-rental-marketplace/06-upgrade.ts
Original file line number Diff line number Diff line change
@@ -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
})
94 changes: 94 additions & 0 deletions utils/upgrade-proxy.ts
Original file line number Diff line number Diff line change
@@ -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!`)
}

0 comments on commit f7836bc

Please sign in to comment.