-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ON-815: add set royalties function to nft rental marketplace
- Loading branch information
Daniel Lima
committed
May 9, 2024
1 parent
cbdc763
commit f7836bc
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!`) | ||
} |