From 887542eb0b6b2194496fb5190e23d0d088fe5aa8 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Mon, 29 Apr 2024 19:21:03 -0300 Subject: [PATCH 1/6] ON-843: update deploy script --- scripts/nft-rental-marketplace/01-deploy.ts | 23 +++ .../orium-marketplace-royalties/01-deploy.ts | 81 +------- scripts/orium-marketplace/01-deploy.ts | 91 --------- .../orium-marketplace/02-propose-upgrade.ts | 62 ------ .../03-set-default-roles-registry.ts | 28 --- scripts/orium-marketplace/04-create-offer.ts | 61 ------ scripts/orium-marketplace/05-cancel-offer.ts | 31 --- scripts/orium-marketplace/06-accept-offer.ts | 47 ----- scripts/orium-marketplace/data/metadata.ts | 123 ------------ scripts/orium-marketplace/data/offers.md | 20 -- scripts/orium-marketplace/data/roles.json | 176 ------------------ utils/deploy-upgradeable.ts | 91 +++++++++ 12 files changed, 119 insertions(+), 715 deletions(-) create mode 100644 scripts/nft-rental-marketplace/01-deploy.ts delete mode 100644 scripts/orium-marketplace/01-deploy.ts delete mode 100644 scripts/orium-marketplace/02-propose-upgrade.ts delete mode 100644 scripts/orium-marketplace/03-set-default-roles-registry.ts delete mode 100644 scripts/orium-marketplace/04-create-offer.ts delete mode 100644 scripts/orium-marketplace/05-cancel-offer.ts delete mode 100644 scripts/orium-marketplace/06-accept-offer.ts delete mode 100644 scripts/orium-marketplace/data/metadata.ts delete mode 100644 scripts/orium-marketplace/data/offers.md delete mode 100644 scripts/orium-marketplace/data/roles.json create mode 100644 utils/deploy-upgradeable.ts diff --git a/scripts/nft-rental-marketplace/01-deploy.ts b/scripts/nft-rental-marketplace/01-deploy.ts new file mode 100644 index 0000000..548248e --- /dev/null +++ b/scripts/nft-rental-marketplace/01-deploy.ts @@ -0,0 +1,23 @@ +import { network } from 'hardhat' +import { print, colors } from '../../utils/misc' +import addresses, { Network } from '../../addresses' +import { deployUpgradeableContract } from '../../utils/deploy-upgradeable' + +const NETWORK = network.name as Network +const PROXY_CONTRACT_NAME = 'NftRentalMarketplace' +const OPERATOR_ADDRESS = addresses[NETWORK].Multisig.address +const INITIALIZER_ARGUMENTS: string[] = [OPERATOR_ADDRESS, addresses[NETWORK].OriumMarketplaceRoyalties.address] +const LIBRARIES_CONTRACT_NAME = ['LibNftRentalMarketplace'] + +async function main() { + await deployUpgradeableContract(PROXY_CONTRACT_NAME, OPERATOR_ADDRESS, INITIALIZER_ARGUMENTS, LIBRARIES_CONTRACT_NAME) +} + +main() + .then(async () => { + print(colors.bigSuccess, 'All done!') + }) + .catch(error => { + console.error(error) + process.exitCode = 1 + }) diff --git a/scripts/orium-marketplace-royalties/01-deploy.ts b/scripts/orium-marketplace-royalties/01-deploy.ts index 976e991..b814398 100644 --- a/scripts/orium-marketplace-royalties/01-deploy.ts +++ b/scripts/orium-marketplace-royalties/01-deploy.ts @@ -1,89 +1,18 @@ -import hre, { ethers, network, upgrades } from 'hardhat' -import { AwsKmsSigner } from '@govtechsg/ethers-aws-kms-signer' -import { confirmOrDie, print, colors } from '../../utils/misc' -import { updateJsonFile } from '../../utils/json' +import { network } from 'hardhat' +import { print, colors } from '../../utils/misc' import addresses, { Network } from '../../addresses' import { AddressZero, THREE_MONTHS } from '../../utils/constants' - -const kmsCredentials = { - accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'AKIAxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access - secretAccessKey: process.env.AWS_ACCESS_KEY_SECRET || 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access - region: 'us-east-1', // region of your KMS key - keyId: process.env.AWS_KMS_KEY_ID || 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // KMS key id -} +import { deployUpgradeableContract } from '../../utils/deploy-upgradeable' const NETWORK = network.name as Network const { Multisig, RolesRegistry } = addresses[NETWORK] const CONTRACT_NAME = 'OriumMarketplaceRoyalties' const OPERATOR_ADDRESS = Multisig.address -const MAX_DEADLINE = THREE_MONTHS.toString() -const INITIALIZER_ARGUMENTS: string[] = [OPERATOR_ADDRESS, AddressZero, RolesRegistry.address, MAX_DEADLINE] - -const networkConfig: any = network.config -const provider = new ethers.providers.JsonRpcProvider(networkConfig.url || '') -/* const FEE_DATA: any = { - maxFeePerGas: ethers.utils.parseUnits('80', 'gwei'), - maxPriorityFeePerGas: ethers.utils.parseUnits('50', 'gwei'), -} -provider.getFeeData = async () => FEE_DATA */ -const deployer = new AwsKmsSigner(kmsCredentials).connect(provider) +const INITIALIZER_ARGUMENTS: string[] = [OPERATOR_ADDRESS, AddressZero, RolesRegistry.address, THREE_MONTHS.toString()] async function main() { - const deployerAddress = await deployer.getAddress() - confirmOrDie(`Deploying ${CONTRACT_NAME} contract on: ${NETWORK} network with ${deployerAddress}. Continue?`) - - const ContractFactory = await ethers.getContractFactory(CONTRACT_NAME, deployer) - const contract = await upgrades.deployProxy(ContractFactory, INITIALIZER_ARGUMENTS) - await contract.deployed() - print(colors.success, `${CONTRACT_NAME} deployed to: ${contract.address}`) - - print(colors.highlight, 'Updating config files...') - const deploymentInfo = { - [CONTRACT_NAME]: { - address: contract.address, - operator: OPERATOR_ADDRESS, - implementation: await upgrades.erc1967.getImplementationAddress(contract.address), - proxyAdmin: await upgrades.erc1967.getAdminAddress(contract.address), - }, - } - - console.log(deploymentInfo) - - updateJsonFile(`addresses/${NETWORK}/index.json`, deploymentInfo) - - print(colors.success, 'Config files updated!') - - try { - print(colors.highlight, 'Transferring proxy admin ownership...') - const abi = [ - { - inputs: [ - { - internalType: 'address', - name: 'newOwner', - type: 'address', - }, - ], - name: 'transferOwnership', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - ] - const proxyAdminContract = new ethers.Contract(deploymentInfo[CONTRACT_NAME].proxyAdmin, abi, deployer) - await proxyAdminContract.transferOwnership(OPERATOR_ADDRESS) - print(colors.success, `Proxy admin ownership transferred to: ${OPERATOR_ADDRESS}`) - } catch (e) { - print(colors.error, `Error transferring proxy admin ownership: ${e}`) - } - - print(colors.highlight, 'Verifying contract on Etherscan...') - await hre.run('verify:verify', { - address: contract.address, - constructorArguments: [], - }) - print(colors.success, 'Contract verified!') + await deployUpgradeableContract(CONTRACT_NAME, OPERATOR_ADDRESS, INITIALIZER_ARGUMENTS) } main() diff --git a/scripts/orium-marketplace/01-deploy.ts b/scripts/orium-marketplace/01-deploy.ts deleted file mode 100644 index ad11aac..0000000 --- a/scripts/orium-marketplace/01-deploy.ts +++ /dev/null @@ -1,91 +0,0 @@ -import hre, { ethers, network, upgrades } from 'hardhat' -import { AwsKmsSigner } from '@govtechsg/ethers-aws-kms-signer' -import { confirmOrDie, print, colors } from '../../utils/misc' -import { updateJsonFile } from '../../utils/json' -import addresses, { Network } from '../../addresses' -import { THREE_MONTHS } from '../../utils/constants' - -const kmsCredentials = { - accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'AKIAxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access - secretAccessKey: process.env.AWS_ACCESS_KEY_SECRET || 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access - region: 'us-east-1', // region of your KMS key - keyId: process.env.AWS_KMS_KEY_ID || 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // KMS key id -} - -const NETWORK = network.name as Network -const { Multisig, RolesRegistry } = addresses[NETWORK] - -const CONTRACT_NAME = 'OriumMarketplace' -const OPERATOR_ADDRESS = Multisig.address -const MAX_DEADLINE = THREE_MONTHS.toString() -const INITIALIZER_ARGUMENTS: string[] = [OPERATOR_ADDRESS, RolesRegistry.address, MAX_DEADLINE] - -const networkConfig: any = network.config -const provider = new ethers.providers.JsonRpcProvider(networkConfig.url || '') -const deployer = new AwsKmsSigner(kmsCredentials).connect(provider) - -async function main() { - const deployerAddress = await deployer.getAddress() - confirmOrDie(`Deploying ${CONTRACT_NAME} contract on: ${NETWORK} network with ${deployerAddress}. Continue?`) - - const ContractFactory = await ethers.getContractFactory(CONTRACT_NAME, deployer) - const contract = await upgrades.deployProxy(ContractFactory, INITIALIZER_ARGUMENTS) - await contract.deployed() - print(colors.success, `${CONTRACT_NAME} deployed to: ${contract.address}`) - - print(colors.highlight, 'Updating config files...') - const deploymentInfo = { - [CONTRACT_NAME]: { - address: contract.address, - operator: OPERATOR_ADDRESS, - implementation: await upgrades.erc1967.getImplementationAddress(contract.address), - proxyAdmin: await upgrades.erc1967.getAdminAddress(contract.address), - }, - } - - console.log(deploymentInfo) - - updateJsonFile(`addresses/${NETWORK}/index.json`, deploymentInfo) - - print(colors.success, 'Config files updated!') - - try { - print(colors.highlight, 'Transferring proxy admin ownership...') - const abi = [ - { - inputs: [ - { - internalType: 'address', - name: 'newOwner', - type: 'address', - }, - ], - name: 'transferOwnership', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - ] - const proxyAdminContract = new ethers.Contract(deploymentInfo[CONTRACT_NAME].proxyAdmin, abi, deployer) - await proxyAdminContract.transferOwnership(OPERATOR_ADDRESS) - print(colors.success, `Proxy admin ownership transferred to: ${OPERATOR_ADDRESS}`) - } catch (e) { - print(colors.error, `Error transferring proxy admin ownership: ${e}`) - } - - print(colors.highlight, 'Verifying contract on Etherscan...') - await hre.run('verify:verify', { - address: contract.address, - constructorArguments: [], - }) - print(colors.success, 'Contract verified!') -} - -main() - .then(async () => { - print(colors.bigSuccess, 'All done!') - }) - .catch(error => { - console.error(error) - process.exitCode = 1 - }) diff --git a/scripts/orium-marketplace/02-propose-upgrade.ts b/scripts/orium-marketplace/02-propose-upgrade.ts deleted file mode 100644 index 1447920..0000000 --- a/scripts/orium-marketplace/02-propose-upgrade.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { ethers, network as hardhatNetwork, defender, upgrades } from 'hardhat' -import hre from 'hardhat' -import config, { Network } from '../../addresses' -import { colors, print, confirmOrDie } from '../../utils/misc' -import { updateJsonFile } from '../../utils/json' - -async function main() { - const NETWORK = hardhatNetwork.name as Network - const CONTRACT_NAME = 'OriumMarketplace' - const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address - const OPERATOR_ADDRESS = config[NETWORK].Multisig.address - - await confirmOrDie(`Are you sure you want to propose an upgrade for ${CONTRACT_NAME} on ${NETWORK} network?`) - - print(colors.highlight, `Proposing upgrade for ${CONTRACT_NAME} on ${NETWORK} network...`) - - const newContract = await ethers.getContractFactory(CONTRACT_NAME) - const proposal = await defender.proposeUpgrade(CONTRACT_ADDRESS, newContract) - - print(colors.success, `Upgrade proposal created at: ${proposal.url}`) - - const tx = await proposal.txResponse?.wait() - - const implementationAddress = tx?.contractAddress - - print(colors.highlight, 'Updating config files...') - const deploymentInfo = { - [CONTRACT_NAME]: { - address: CONTRACT_ADDRESS, - operator: OPERATOR_ADDRESS, - implementation: implementationAddress, - proxyAdmin: await upgrades.erc1967.getAdminAddress(CONTRACT_ADDRESS), - }, - } - - console.log(deploymentInfo) - - updateJsonFile(`addresses/${NETWORK}/index.json`, deploymentInfo) - - print(colors.success, 'Config files updated!') - - try { - print(colors.highlight, 'Verifying implementation...') - await hre.run('verify:verify', { - address: implementationAddress, - network: NETWORK, - constructorArguments: [], - }) - print(colors.success, 'Contract verified!') - } catch (e) { - print(colors.error, `Error verifying contract: ${e}`) - } -} - -main() - .then(() => { - console.log('Done!') - }) - .catch(error => { - console.error(error) - process.exitCode = 1 - }) diff --git a/scripts/orium-marketplace/03-set-default-roles-registry.ts b/scripts/orium-marketplace/03-set-default-roles-registry.ts deleted file mode 100644 index 6efe1c5..0000000 --- a/scripts/orium-marketplace/03-set-default-roles-registry.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { ethers, network as hardhatNetwork } from 'hardhat' -import config, { Network } from '../../addresses' -import { colors, print, confirmOrDie } from '../../utils/misc' - -async function main() { - const NETWORK = hardhatNetwork.name as Network - const CONTRACT_NAME = 'OriumMarketplace' - const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address - - await confirmOrDie( - `Are you sure you want to set default roles registry ${config[NETWORK].RolesRegistry.address} for ${CONTRACT_NAME} on ${NETWORK} network?`, - ) - - const contract = await ethers.getContractAt(CONTRACT_NAME, CONTRACT_ADDRESS) - const tx = await contract.setDefaultRolesRegistry(config[NETWORK].RolesRegistry.address) - - print(colors.highlight, `Transaction hash: ${tx.hash}`) - print(colors.success, `Default roles registry set for ${CONTRACT_NAME} on ${NETWORK} network!`) -} - -main() - .then(() => { - console.log('Done!') - }) - .catch(error => { - console.error(error) - process.exitCode = 1 - }) diff --git a/scripts/orium-marketplace/04-create-offer.ts b/scripts/orium-marketplace/04-create-offer.ts deleted file mode 100644 index cfeddbd..0000000 --- a/scripts/orium-marketplace/04-create-offer.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { ethers, network as hardhatNetwork } from 'hardhat' -import config, { Network } from '../../addresses' -import { colors, print, confirmOrDie } from '../../utils/misc' -import { RentalOffer } from '../../utils/types' -import { AddressZero, ONE_DAY } from '../../utils/constants' -import { randomBytes } from 'crypto' -import { toWei } from '../../utils/bignumber' -import { BigNumber } from 'ethers' -import { data1, data2, role1, role1Data, role2, role2Data, roleMetadata1, roleMetadata2 } from './data/metadata' -import { defaultAbiCoder as abi } from 'ethers/lib/utils' -import { inputsToTypes } from '../../utils/role-metadata' - -async function main() { - const NETWORK = hardhatNetwork.name as Network - const CONTRACT_NAME = 'OriumMarketplace' - const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address - - await confirmOrDie( - `Are you sure you want to create a rental offer ${config[NETWORK].RolesRegistry.address} for ${CONTRACT_NAME} on ${NETWORK} network?`, - ) - - const contract = await ethers.getContractAt(CONTRACT_NAME, CONTRACT_ADDRESS) - - const blockTimestamp = (await ethers.provider.getBlock('latest')).timestamp - - const rentalOffer: RentalOffer = { - nonce: BigNumber.from(`0x${randomBytes(32).toString('hex')}`).toString(), - lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', - borrower: '0x596aa1f9EF171075860dFf6062Fe2009991B2323', - tokenAddress: '0x86935F11C86623deC8a25696E1C19a8659CbF95d', - tokenId: 13477, //13477,14733,16640 - feeTokenAddress: '0x385Eeac5cB85A38A9a07A70c73e0a3271CfB54A7', - feeAmountPerSecond: toWei('0'), - deadline: blockTimestamp + ONE_DAY * 60, - roles: [role2], - rolesData: [role2Data], - } - - const role1DataDecoded = abi.decode(inputsToTypes(roleMetadata1.inputs), role1Data) - const role2DataDecoded = abi.decode(inputsToTypes(roleMetadata2.inputs), role2Data) - - console.log('role1DataDecoded', role1DataDecoded) - console.log('role2DataDecoded', role2DataDecoded) - - const tx = await contract.createRentalOffer(rentalOffer) - - console.log('rentalOffer', rentalOffer) - console.log(`offerId: ${rentalOffer.lender.toLowerCase()}-${BigNumber.from(rentalOffer.nonce).toString()}`) - - print(colors.highlight, `Transaction hash: ${tx.hash}`) - print(colors.success, `Created rental offer in ${CONTRACT_NAME} on ${NETWORK} network!`) -} - -main() - .then(() => { - console.log('Done!') - }) - .catch(error => { - console.error(error) - process.exitCode = 1 - }) diff --git a/scripts/orium-marketplace/05-cancel-offer.ts b/scripts/orium-marketplace/05-cancel-offer.ts deleted file mode 100644 index 9a592ef..0000000 --- a/scripts/orium-marketplace/05-cancel-offer.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { ethers, network as hardhatNetwork } from 'hardhat' -import config, { Network } from '../../addresses' -import { colors, print, confirmOrDie } from '../../utils/misc' -import { BigNumber } from 'ethers' - -async function main() { - const NETWORK = hardhatNetwork.name as Network - const CONTRACT_NAME = 'OriumMarketplace' - const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address - - await confirmOrDie( - `Are you sure you want to cancel a rental offer ${config[NETWORK].RolesRegistry.address} for ${CONTRACT_NAME} on ${NETWORK} network?`, - ) - - const contract = await ethers.getContractAt(CONTRACT_NAME, CONTRACT_ADDRESS) - - const nonce = BigNumber.from('0x0924aa59075f0008abf36a3cd83e2f0ff5d835f6e3fa2e80efec5bf50b2ee801') - const tx = await contract.cancelRentalOffer(nonce) - - print(colors.highlight, `Transaction hash: ${tx.hash}`) - print(colors.success, `Cancelled rental offer in ${CONTRACT_NAME} on ${NETWORK} network!`) -} - -main() - .then(() => { - console.log('Done!') - }) - .catch(error => { - console.error(error) - process.exitCode = 1 - }) diff --git a/scripts/orium-marketplace/06-accept-offer.ts b/scripts/orium-marketplace/06-accept-offer.ts deleted file mode 100644 index e48a1c5..0000000 --- a/scripts/orium-marketplace/06-accept-offer.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { ethers, network as hardhatNetwork } from 'hardhat' -import config, { Network } from '../../addresses' -import { colors, print, confirmOrDie } from '../../utils/misc' -import { BigNumber } from 'ethers' -import { RentalOffer } from '../../utils/types' -import { AddressZero, ONE_DAY } from '../../utils/constants' -import { role1, role1Data, role2, role2Data } from './data/metadata' -import { toWei } from '../../utils/bignumber' - -async function main() { - const NETWORK = hardhatNetwork.name as Network - const CONTRACT_NAME = 'OriumMarketplace' - const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address - - await confirmOrDie( - `Are you sure you want to accept a rental offer ${config[NETWORK].RolesRegistry.address} for ${CONTRACT_NAME} on ${NETWORK} network?`, - ) - - const contract = await ethers.getContractAt(CONTRACT_NAME, CONTRACT_ADDRESS) - - const rentalOffer: RentalOffer = { - nonce: '83599666957982206244285234714372024507298621827571506963968085034833539793026', - lender: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', - borrower: '0x596aa1f9EF171075860dFf6062Fe2009991B2323', - tokenAddress: '0x86935F11C86623deC8a25696E1C19a8659CbF95d', - tokenId: 13477, - feeTokenAddress: '0x385Eeac5cB85A38A9a07A70c73e0a3271CfB54A7', - feeAmountPerSecond: toWei('0'), - deadline: 1709993647, - roles: [role2], - rolesData: [role2Data], - } - const duration = ONE_DAY * 59 - const tx = await contract.acceptRentalOffer(rentalOffer, duration) - - print(colors.highlight, `Transaction hash: ${tx.hash}`) - print(colors.success, `Accepted rental offer in ${CONTRACT_NAME} on ${NETWORK} network!`) -} - -main() - .then(() => { - console.log('Done!') - }) - .catch(error => { - console.error(error) - process.exitCode = 1 - }) diff --git a/scripts/orium-marketplace/data/metadata.ts b/scripts/orium-marketplace/data/metadata.ts deleted file mode 100644 index 81bf83a..0000000 --- a/scripts/orium-marketplace/data/metadata.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { toWei } from '../../../utils/bignumber' -import { USER_ROLE, abi } from '../../../utils/roles' -import { inputsToTypes } from '../../../utils/role-metadata' - -export const role1 = '0x3d926b0dd5f4880fb18c9a49c890c7d76c2a97e0d4b4c20f1bb3fe6e5f89f5f4' -export const roleMetadata1 = { - inputs: [ - { - name: 'a', - type: 'uint256', - }, - { - name: 'b', - type: 'uint256[]', - }, - { - name: 'role', - type: 'bytes32', - }, - { - name: 'customData', - type: 'bytes', - }, - { - name: 'c', - type: 'tuple', - components: [ - { - name: 'd', - type: 'uint256', - }, - { - name: 'e', - type: 'uint256[]', - }, - { - name: 'f', - type: 'tuple[]', - components: [ - { - name: 'g', - type: 'bool', - }, - { - name: 'h', - type: 'address', - }, - ], - }, - ], - }, - ], -} - -export const data1 = { - a: toWei('1').toString(), - b: [toWei('2').toString(), toWei('3').toString()], - role: USER_ROLE, - customData: abi.encode(['uint256'], [123]), - c: { - d: toWei('4').toString(), - e: [toWei('5').toString(), toWei('6').toString()], - f: [ - { - g: true, - h: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', - }, - { - g: false, - h: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', - }, - ], - }, -} - -const rolesDataTypes1 = inputsToTypes(roleMetadata1.inputs) -export const role1Data = abi.encode(rolesDataTypes1, Object.values(data1)) - -export const data2 = { - Channeling: true, - ThirdPartyAddress: '0xe3A75c99cD21674188bea652Fe378cA5cf7e7906', - ProfitShare: { - Lender: toWei('60'), - Borrower: toWei('30'), - ThirdParty: toWei('10'), - }, -} - -export const role2 = '0x3d926b0dd5f4880fb18c9a49c890c7d76c2a97e0d4b4c20f1bb3fe6e5f89f0f4' -export const roleMetadata2 = { - inputs: [ - { - name: 'Channeling', - type: 'bool', - }, - { - name: 'ThirdPartyAddress', - type: 'address', - }, - { - name: 'ProfitShare', - type: 'tuple', - validation: 'profit-share', - components: [ - { - name: 'Lender', - type: 'uint256', - }, - { - name: 'Borrower', - type: 'uint256', - }, - { - name: 'ThirdParty', - type: 'uint256', - }, - ], - }, - ], -} - -const rolesDataTypes2 = inputsToTypes(roleMetadata2.inputs) -export const role2Data = abi.encode(rolesDataTypes2, Object.values(data2)) diff --git a/scripts/orium-marketplace/data/offers.md b/scripts/orium-marketplace/data/offers.md deleted file mode 100644 index 119d6a4..0000000 --- a/scripts/orium-marketplace/data/offers.md +++ /dev/null @@ -1,20 +0,0 @@ -ENDED (nao mudou) -0xe3a75c99cd21674188bea652fe378ca5cf7e7906-92827467207011288858523338834239849691464970474542022023017144154726429167810 - -LISTED (PRIVATE OFFER) -0xe3a75c99cd21674188bea652fe378ca5cf7e7906-82886582020799629541200756965990397757300904669146022046405518330734300767324 - -LISTED (PUBLIC OFFER) AND VALID PROFIT SHARE -0xe3a75c99cd21674188bea652fe378ca5cf7e7906-76727119686150246672177417526900047429422933605649055888190087347717783751413 - -2 ROLES INCLUDED AND INVALID PROFIT SHARE -0xe3a75c99cd21674188bea652fe378ca5cf7e7906-9474262624923928255908876456205778026219503209798235532410428297833912549506 - -UNAVAILABLE -0xe3a75c99cd21674188bea652fe378ca5cf7e7906-63428932213176119977696085910213943345662706203407462357755521786574618382038 - -BORROWED (PUBLIC OFFER) -0xe3a75c99cd21674188bea652fe378ca5cf7e7906-4122942924525315035197586088002621754728657315389943190934775328105341894574 - -BORROWED (PRIVATE OFFER) -0xe3a75c99cd21674188bea652fe378ca5cf7e7906-83599666957982206244285234714372024507298621827571506963968085034833539793026 diff --git a/scripts/orium-marketplace/data/roles.json b/scripts/orium-marketplace/data/roles.json deleted file mode 100644 index 1e338c2..0000000 --- a/scripts/orium-marketplace/data/roles.json +++ /dev/null @@ -1,176 +0,0 @@ -{ - "0x14823911f2da1b49f045a0929a60b8c1f2a7fc8c06c7284ca3e8ab4e193a08c8": { - "id": "0x14823911f2da1b49f045a0929a60b8c1f2a7fc8c06c7284ca3e8ab4e193a08c8", - "name": "Gotchi Player Fully", - "inputs": [ - { - "name": "a", - "type": "uint256" - }, - { - "name": "b", - "type": "uint256[]" - }, - { - "name": "role", - "type": "bytes32" - }, - { - "name": "customData", - "type": "bytes" - }, - { - "name": "c", - "type": "tuple", - "components": [ - { - "name": "d", - "type": "uint256" - }, - { - "name": "e", - "type": "uint256[]" - }, - { - "name": "f", - "type": "tuple[]", - "components": [ - { - "name": "g", - "type": "bool" - }, - { - "name": "h", - "type": "address" - } - ] - } - ] - } - ], - "description": "Allow a user to play. Testing all input types.", - "isUniqueRole": true - }, - "0x3d926b0dd5f4880fb18c9a49c890c7d76c2a97e0d4b4c20f1bb3fe6e5f89f0f4": { - "id": "0x3d926b0dd5f4880fb18c9a49c890c7d76c2a97e0d4b4c20f1bb3fe6e5f89f0f4", - "name": "AavePlay", - "inputs": [ - { - "name": "Channeling", - "type": "bool" - }, - { - "name": "ThirdPartyAddress", - "type": "address" - }, - { - "name": "ProfitShare", - "type": "tuple", - "components": [ - { - "name": "Lender", - "type": "uint256" - }, - { - "name": "Borrower", - "type": "uint256" - }, - { - "name": "ThirdParty", - "type": "uint256" - } - ], - "validation": "profit-share" - } - ], - "description": "Allow a user to play with this Traveler.", - "isUniqueRole": true - }, - "0x3d926b0dd5f4880fb18c9a49c890c7d76c2a97e0d4b4c20f1bb3fe6e5f89f5f4": { - "id": "0x3d926b0dd5f4880fb18c9a49c890c7d76c2a97e0d4b4c20f1bb3fe6e5f89f5f4", - "name": "Gotchi Game", - "inputs": [ - { - "name": "a", - "type": "uint256" - }, - { - "name": "b", - "type": "uint256[]" - }, - { - "name": "role", - "type": "bytes32" - }, - { - "name": "customData", - "type": "bytes" - }, - { - "name": "c", - "type": "tuple", - "components": [ - { - "name": "d", - "type": "uint256" - }, - { - "name": "e", - "type": "uint256[]" - }, - { - "name": "f", - "type": "tuple[]", - "components": [ - { - "name": "g", - "type": "bool" - }, - { - "name": "h", - "type": "address" - } - ] - } - ] - } - ], - "description": "Allow a user to play with this Traveler2.", - "isUniqueRole": true - }, - "0xb449a29c4d0da88df9522903c190669913ddd75088d7afa0798a69a91699026b": { - "id": "0xb449a29c4d0da88df9522903c190669913ddd75088d7afa0798a69a91699026b", - "name": "Gotchi Game2", - "inputs": [ - { - "name": "Channeling", - "type": "bool" - }, - { - "name": "ThirdPartyAddress", - "type": "address" - }, - { - "name": "ProfitShare", - "type": "tuple", - "components": [ - { - "name": "Lender", - "type": "uint256" - }, - { - "name": "Borrower", - "type": "uint256" - }, - { - "name": "ThirdParty", - "type": "uint256" - } - ], - "validation": "profit-share" - } - ], - "description": "Allow a user to play with this Traveler3.", - "isUniqueRole": true - } -} \ No newline at end of file diff --git a/utils/deploy-upgradeable.ts b/utils/deploy-upgradeable.ts new file mode 100644 index 0000000..bca68b3 --- /dev/null +++ b/utils/deploy-upgradeable.ts @@ -0,0 +1,91 @@ +import hre, { ethers, network, upgrades } from 'hardhat' +import { print, confirmOrDie, colors } from './misc' +import { Network } from '../addresses' +import { updateJsonFile } from './json' + +const NETWORK = network.name as Network +export async function deployUpgradeableContract( + PROXY_CONTRACT_NAME: string, + OPERATOR_ADDRESS: string, + INITIALIZER_ARGUMENTS: string[], + LIBRARIES_CONTRACT_NAME?: string[], +) { + const deployerAddress = (await ethers.getSigners())[0] + const libraries: { [key: string]: string } = {} + + confirmOrDie(`Deploying ${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) + const library = await LibraryFactory.deploy() + await library.waitForDeployment() + libraries[LIBRARY_CONTRACT_NAME] = await library.getAddress() + } + + print(colors.success, 'Libraries deployed!') + } + + print(colors.highlight, 'Deploying proxy contract...') + const ContractFactory = await ethers.getContractFactory(PROXY_CONTRACT_NAME, { + libraries, + }) + const contract = await upgrades.deployProxy(ContractFactory, INITIALIZER_ARGUMENTS, { + unsafeAllowLinkedLibraries: true, + }) + await contract.waitForDeployment() + print(colors.success, `${PROXY_CONTRACT_NAME} deployed to: ${contract.address}`) + + print(colors.highlight, 'Updating config files...') + const deploymentInfo: any = { + [PROXY_CONTRACT_NAME]: { + address: await contract.getAddress(), + operator: OPERATOR_ADDRESS, + implementation: await upgrades.erc1967.getImplementationAddress(await contract.getAddress()), + proxyAdmin: await upgrades.erc1967.getAdminAddress(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!') + + try { + print(colors.highlight, 'Transferring proxy admin ownership...') + const abi = [ + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + ] + const proxyAdminContract = new ethers.Contract(deploymentInfo[PROXY_CONTRACT_NAME].proxyAdmin, abi) + await proxyAdminContract.transferOwnership(OPERATOR_ADDRESS) + print(colors.success, `Proxy admin ownership transferred to: ${OPERATOR_ADDRESS}`) + } catch (e) { + print(colors.error, `Error transferring proxy admin ownership: ${e}`) + } + + print(colors.highlight, 'Verifying contract on Etherscan...') + await hre.run('verify:verify', { + address: contract.address, + constructorArguments: [], + }) + print(colors.success, 'Contract verified!') +} From 06e19ce2e1e5bd193a541ddd618c45726d577aa6 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 30 Apr 2024 11:52:21 -0300 Subject: [PATCH 2/6] ON-843: deploy scripts --- package-lock.json | 72 +++++++ package.json | 7 +- scripts/nft-rental-marketplace/01-deploy.ts | 2 +- .../orium-marketplace-royalties/01-deploy.ts | 11 +- utils/deploy-upgradeable.ts | 27 ++- utils/ethers-aws-kms-signer.ts | 187 ++++++++++++++++++ 6 files changed, 294 insertions(+), 12 deletions(-) create mode 100644 utils/ethers-aws-kms-signer.ts diff --git a/package-lock.json b/package-lock.json index a264753..070f38e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,8 @@ "@openzeppelin/contracts": "^4.8.0-rc.1", "@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", @@ -2823,6 +2825,39 @@ "typescript": "^4.7.4" } }, + "node_modules/@peculiar/asn1-ecc": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-ecc/-/asn1-ecc-2.3.8.tgz", + "integrity": "sha512-Ah/Q15y3A/CtxbPibiLM/LKcMbnLTdUdLHUgdpB5f60sSvGkXzxJCu5ezGTFHogZXWNX3KSmYqilCrfdmBc6pQ==", + "dependencies": { + "@peculiar/asn1-schema": "^2.3.8", + "@peculiar/asn1-x509": "^2.3.8", + "asn1js": "^3.0.5", + "tslib": "^2.6.2" + } + }, + "node_modules/@peculiar/asn1-schema": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.3.8.tgz", + "integrity": "sha512-ULB1XqHKx1WBU/tTFIA+uARuRoBVZ4pNdOA878RDrRbBfBGcSzi5HBkdScC6ZbHn8z7L8gmKCgPC1LHRrP46tA==", + "dependencies": { + "asn1js": "^3.0.5", + "pvtsutils": "^1.3.5", + "tslib": "^2.6.2" + } + }, + "node_modules/@peculiar/asn1-x509": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/@peculiar/asn1-x509/-/asn1-x509-2.3.8.tgz", + "integrity": "sha512-voKxGfDU1c6r9mKiN5ZUsZWh3Dy1BABvTM3cimf0tztNwyMJPhiXY94eRTgsMQe6ViLfT6EoXxkWVzcm3mFAFw==", + "dependencies": { + "@peculiar/asn1-schema": "^2.3.8", + "asn1js": "^3.0.5", + "ipaddr.js": "^2.1.0", + "pvtsutils": "^1.3.5", + "tslib": "^2.6.2" + } + }, "node_modules/@rushstack/eslint-patch": { "version": "1.10.1", "resolved": "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.10.1.tgz", @@ -4407,6 +4442,19 @@ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" }, + "node_modules/asn1js": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.5.tgz", + "integrity": "sha512-FVnvrKJwpt9LP2lAMl8qZswRNm3T4q9CON+bxldk2iwk3FFpuwhx2FfinyitizWHsVYyaY+y5JzDR0rCMV5yTQ==", + "dependencies": { + "pvtsutils": "^1.3.2", + "pvutils": "^1.1.3", + "tslib": "^2.4.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", @@ -8263,6 +8311,14 @@ "fp-ts": "^1.0.0" } }, + "node_modules/ipaddr.js": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.2.0.tgz", + "integrity": "sha512-Ag3wB2o37wslZS19hZqorUnrnzSkpOVy+IiiDEiTqNubEYpYuHWIf6K4psgN2ZWKExS4xhVCrRVfb/wfW8fWJA==", + "engines": { + "node": ">= 10" + } + }, "node_modules/is-arguments": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", @@ -10361,6 +10417,22 @@ "node": ">=6" } }, + "node_modules/pvtsutils": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.3.5.tgz", + "integrity": "sha512-ARvb14YB9Nm2Xi6nBq1ZX6dAM0FsJnuk+31aUp4TrcZEdKUlSqOqsxJHUPJDNE3qiIp+iUPEIeR6Je/tgV7zsA==", + "dependencies": { + "tslib": "^2.6.1" + } + }, + "node_modules/pvutils": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/pvutils/-/pvutils-1.1.3.tgz", + "integrity": "sha512-pMpnA0qRdFp32b1sJl1wOJNxZLQ2cbQx+k6tjNtZ8CpvVhNqEPRgivZ2WOUev2YMajecdH7ctUPDvEe87nariQ==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/qs": { "version": "6.12.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.0.tgz", diff --git a/package.json b/package.json index ec5fef2..ebd4863 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,10 @@ "lint:staged": "npx lint-staged", "lint:fix": "npx eslint . --fix && npx prettier --write .", "contract-size": "npx hardhat size-contracts", - "deploy:mumbai": "npx hardhat run --network mumbai scripts/01-deploy.ts", - "deploy:polygon": "npx hardhat run --network polygon scripts/01-deploy.ts", + "deploy:nft-rental-marketplace:polygon": "npx hardhat run --network polygon scripts/nft-rental-marketplace/01-deploy.ts", + "deploy:nft-rental-marketplace:moonbeam": "npx hardhat run --network moonbeam scripts/nft-rental-marketplace/01-deploy.ts", + "deploy:orium-marketplace-royalties:polygon": "npx hardhat run --network polygon scripts/orium-marketplace-royalties/01-deploy.ts", + "deploy:orium-marketplace-royalties:moonbeam": "npx hardhat run --network moonbeam scripts/orium-marketplace-royalties/01-deploy.ts", "create-offer:orium-sft-marketplace:polygon": "npx hardhat run scripts/orium-sft-marketplace/02-create-offer.ts --network polygon", "cancel-offer:orium-sft-marketplace:polygon": "npx hardhat run scripts/orium-sft-marketplace/03-cancel-offer.ts --network polygon", "propose-upgrade:orium-sft-marketplace:polygon": "npx hardhat run scripts/orium-sft-marketplace/06-propose-upgrade.ts --network polygon" @@ -30,6 +32,7 @@ "@openzeppelin/contracts": "^4.8.0-rc.1", "@openzeppelin/contracts-upgradeable": "^4.8.0-rc.1", "@openzeppelin/hardhat-upgrades": "^3.0.5", + "@peculiar/asn1-ecc": "^2.3.8", "defender-admin-client": "^1.37.0", "dotenv": "^16.0.3", "hardhat": "^2.22.2", diff --git a/scripts/nft-rental-marketplace/01-deploy.ts b/scripts/nft-rental-marketplace/01-deploy.ts index 548248e..ee14f23 100644 --- a/scripts/nft-rental-marketplace/01-deploy.ts +++ b/scripts/nft-rental-marketplace/01-deploy.ts @@ -5,7 +5,7 @@ import { deployUpgradeableContract } from '../../utils/deploy-upgradeable' const NETWORK = network.name as Network const PROXY_CONTRACT_NAME = 'NftRentalMarketplace' -const OPERATOR_ADDRESS = addresses[NETWORK].Multisig.address +const OPERATOR_ADDRESS = addresses[NETWORK].KMSDeployer.address const INITIALIZER_ARGUMENTS: string[] = [OPERATOR_ADDRESS, addresses[NETWORK].OriumMarketplaceRoyalties.address] const LIBRARIES_CONTRACT_NAME = ['LibNftRentalMarketplace'] diff --git a/scripts/orium-marketplace-royalties/01-deploy.ts b/scripts/orium-marketplace-royalties/01-deploy.ts index b814398..5d7537e 100644 --- a/scripts/orium-marketplace-royalties/01-deploy.ts +++ b/scripts/orium-marketplace-royalties/01-deploy.ts @@ -5,11 +5,16 @@ import { AddressZero, THREE_MONTHS } from '../../utils/constants' import { deployUpgradeableContract } from '../../utils/deploy-upgradeable' const NETWORK = network.name as Network -const { Multisig, RolesRegistry } = addresses[NETWORK] +const { KMSDeployer, ERC7432WrapperForERC4907 } = addresses[NETWORK] const CONTRACT_NAME = 'OriumMarketplaceRoyalties' -const OPERATOR_ADDRESS = Multisig.address -const INITIALIZER_ARGUMENTS: string[] = [OPERATOR_ADDRESS, AddressZero, RolesRegistry.address, THREE_MONTHS.toString()] +const OPERATOR_ADDRESS = KMSDeployer.address +const INITIALIZER_ARGUMENTS: string[] = [ + OPERATOR_ADDRESS, + ERC7432WrapperForERC4907.address, + AddressZero, + THREE_MONTHS.toString(), +] async function main() { await deployUpgradeableContract(CONTRACT_NAME, OPERATOR_ADDRESS, INITIALIZER_ARGUMENTS) diff --git a/utils/deploy-upgradeable.ts b/utils/deploy-upgradeable.ts index bca68b3..8f4e6c5 100644 --- a/utils/deploy-upgradeable.ts +++ b/utils/deploy-upgradeable.ts @@ -2,15 +2,30 @@ import hre, { ethers, network, upgrades } from 'hardhat' import { print, confirmOrDie, colors } from './misc' import { Network } from '../addresses' import { updateJsonFile } from './json' +import { AwsKmsSigner } from './ethers-aws-kms-signer' +const kmsCredentials = { + accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'AKIAxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access + secretAccessKey: process.env.AWS_ACCESS_KEY_SECRET || 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access + region: 'us-east-1', // region of your KMS key + keyId: process.env.AWS_KMS_KEY_ID || 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // KMS key id +} const NETWORK = network.name as Network +const networkConfig: any = network.config +const provider = new ethers.JsonRpcProvider(networkConfig.url || '') +const deployer = new AwsKmsSigner(kmsCredentials).connect(provider) export async function deployUpgradeableContract( PROXY_CONTRACT_NAME: string, OPERATOR_ADDRESS: string, INITIALIZER_ARGUMENTS: string[], LIBRARIES_CONTRACT_NAME?: string[], + CUSTOM_FEE_DATA?: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }, ) { - const deployerAddress = (await ethers.getSigners())[0] + if (CUSTOM_FEE_DATA !== undefined) { + const FEE_DATA: any = CUSTOM_FEE_DATA + provider.getFeeData = async () => FEE_DATA + } + const deployerAddress = await deployer.getAddress() const libraries: { [key: string]: string } = {} confirmOrDie(`Deploying ${PROXY_CONTRACT_NAME} contract on: ${NETWORK} network with ${deployerAddress}. Continue?`) @@ -19,7 +34,7 @@ export async function deployUpgradeableContract( print(colors.highlight, 'Deploying libraries...') for (const LIBRARY_CONTRACT_NAME of LIBRARIES_CONTRACT_NAME) { - const LibraryFactory = await ethers.getContractFactory(LIBRARY_CONTRACT_NAME) + const LibraryFactory = await ethers.getContractFactory(LIBRARY_CONTRACT_NAME, deployer) const library = await LibraryFactory.deploy() await library.waitForDeployment() libraries[LIBRARY_CONTRACT_NAME] = await library.getAddress() @@ -29,8 +44,10 @@ export async function deployUpgradeableContract( } print(colors.highlight, 'Deploying proxy contract...') + console.log('INITIALIZER_ARGUMENTS', INITIALIZER_ARGUMENTS) const ContractFactory = await ethers.getContractFactory(PROXY_CONTRACT_NAME, { libraries, + signer: deployer, }) const contract = await upgrades.deployProxy(ContractFactory, INITIALIZER_ARGUMENTS, { unsafeAllowLinkedLibraries: true, @@ -53,9 +70,7 @@ export async function deployUpgradeableContract( } console.log(deploymentInfo) - updateJsonFile(`addresses/${NETWORK}/index.json`, deploymentInfo) - print(colors.success, 'Config files updated!') try { @@ -75,7 +90,7 @@ export async function deployUpgradeableContract( type: 'function', }, ] - const proxyAdminContract = new ethers.Contract(deploymentInfo[PROXY_CONTRACT_NAME].proxyAdmin, abi) + const proxyAdminContract = new ethers.Contract(deploymentInfo[PROXY_CONTRACT_NAME].proxyAdmin, abi, deployer) await proxyAdminContract.transferOwnership(OPERATOR_ADDRESS) print(colors.success, `Proxy admin ownership transferred to: ${OPERATOR_ADDRESS}`) } catch (e) { @@ -84,7 +99,7 @@ export async function deployUpgradeableContract( print(colors.highlight, 'Verifying contract on Etherscan...') await hre.run('verify:verify', { - address: contract.address, + address: await contract.getAddress(), constructorArguments: [], }) print(colors.success, 'Contract verified!') diff --git a/utils/ethers-aws-kms-signer.ts b/utils/ethers-aws-kms-signer.ts new file mode 100644 index 0000000..0ce0f13 --- /dev/null +++ b/utils/ethers-aws-kms-signer.ts @@ -0,0 +1,187 @@ +import { GetPublicKeyCommand, KMSClient, SignCommand } from '@aws-sdk/client-kms' +import { ECDSASigValue } from '@peculiar/asn1-ecc' +import { AsnConvert } from '@peculiar/asn1-schema' +import { SubjectPublicKeyInfo } from '@peculiar/asn1-x509' +import { + AbstractSigner, + assert, + assertArgument, + BytesLike, + dataLength, + getAddress, + getBytes, + hashMessage, + keccak256, + N as secp256k1N, + Provider, + recoverAddress as recoverAddressFn, + resolveAddress, + resolveProperties, + Signature, + toBeHex, + toBigInt, + Transaction, + TransactionLike, + TransactionRequest, + TypedDataDomain, + TypedDataEncoder, + TypedDataField, +} from 'ethers' + +export type EthersAwsKmsSignerConfig = { + credentials?: { + accessKeyId: string + secretAccessKey: string + } + region: string + keyId: string +} + +export class AwsKmsSigner

extends AbstractSigner { + private config: EthersAwsKmsSignerConfig + private client: KMSClient + + address!: string + + constructor(config: EthersAwsKmsSignerConfig, provider?: P) { + super(provider) + this.config = config + this.client = this._createKMSClient(config.region, config.credentials) + } + + connect(provider: Provider | null): AwsKmsSigner { + return new AwsKmsSigner(this.config, provider) + } + + async getAddress(): Promise { + if (!this.address) { + const command = new GetPublicKeyCommand({ KeyId: this.config.keyId }) + const response = await this.client.send(command) + + const publicKeyHex = response.PublicKey + if (!publicKeyHex) { + throw new Error(`Could not get Public Key from KMS.`) + } + + const ecPublicKey = AsnConvert.parse(Buffer.from(publicKeyHex), SubjectPublicKeyInfo).subjectPublicKey + + // The public key starts with a 0x04 prefix that needs to be removed + // more info: https://www.oreilly.com/library/view/mastering-ethereum/9781491971932/ch04.html + this.address = `0x${keccak256(new Uint8Array(ecPublicKey.slice(1, ecPublicKey.byteLength))).slice(-40)}` + } + + return this.address + } + + async signTransaction(tx: TransactionRequest): Promise { + // Replace any Addressable or ENS name with an address + const { to } = await resolveProperties({ + to: tx.to ? resolveAddress(tx.to, this.provider) : undefined, + from: tx.from ? resolveAddress(tx.from, this.provider) : undefined, + }) + + if (to !== null) { + tx.to = to + } + // TypeError: Cannot set property from of # which has only a getter + // if (from !== null) { + // tx.from = from; + // } + + const address = await this.getAddress() + + if (tx.from !== null) { + assertArgument(getAddress(tx.from as string) === address, 'transaction from address mismatch', 'tx.from', tx.from) + delete tx.from + } + + // Build the transaction + const btx = Transaction.from(tx as TransactionLike) + btx.signature = await this._sign(btx.unsignedHash) + + return btx.serialized + } + + async signMessage(message: string | Uint8Array): Promise { + const signature = await this._sign(hashMessage(message)) + return signature.serialized + } + + async signTypedData( + domain: TypedDataDomain, + types: Record, + value: Record, + ): Promise { + // Populate any ENS names + const populated = await TypedDataEncoder.resolveNames(domain, types, value, async (name: string) => { + // @TODO: this should use resolveName; addresses don't + // need a provider + + assert(this.provider !== null, 'cannot resolve ENS names without a provider', 'UNSUPPORTED_OPERATION', { + operation: 'resolveName', + info: { name }, + }) + + const address = await this.provider.resolveName(name) + assert(address !== null, 'unconfigured ENS name', 'UNCONFIGURED_NAME', { + value: name, + }) + + return address + }) + + const signature = await this._sign(TypedDataEncoder.hash(populated.domain, types, populated.value)) + + return signature.serialized + } + + private _createKMSClient( + region: string, + credentials?: { + accessKeyId: string + secretAccessKey: string + }, + ) { + return new KMSClient({ + credentials, + region, + }) + } + + private async _sign(digest: BytesLike): Promise { + assertArgument(dataLength(digest) === 32, 'invalid digest length', 'digest', digest) + + const command = new SignCommand({ + KeyId: this.config.keyId, + Message: getBytes(digest), + MessageType: 'DIGEST', + SigningAlgorithm: 'ECDSA_SHA_256', + }) + + const response = await this.client.send(command) + const signatureHex = response.Signature + + if (!signatureHex) { + throw new Error('Could not fetch Signature from KMS.') + } + + const signature = AsnConvert.parse(Buffer.from(signatureHex), ECDSASigValue) + + let s = toBigInt(new Uint8Array(signature.s)) + s = s > secp256k1N / BigInt(2) ? secp256k1N - s : s + + const recoverAddress = recoverAddressFn(digest, { + r: toBeHex(toBigInt(new Uint8Array(signature.r)), 32), + s: toBeHex(s, 32), + v: 0x1b, + }) + + const address = await this.getAddress() + + return Signature.from({ + r: toBeHex(toBigInt(new Uint8Array(signature.r)), 32), + s: toBeHex(s, 32), + v: recoverAddress.toLowerCase() !== address.toLowerCase() ? 0x1c : 0x1b, + }) + } +} From 33e1e951b2c32e030ad0e4d30d1431597eb6bb1b Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 30 Apr 2024 11:52:49 -0300 Subject: [PATCH 3/6] ON-843: add moonbeam --- .openzeppelin/unknown-1284.json | 211 +++++++++++++++++++++++++++++ addresses/cronos/index.json | 3 + addresses/cronosTestnet/index.json | 3 + addresses/index.ts | 4 +- addresses/moonbeam/index.json | 41 ++++++ addresses/mumbai/index.json | 35 ----- addresses/polygon/index.json | 3 + hardhat.config.ts | 15 +- 8 files changed, 271 insertions(+), 44 deletions(-) create mode 100644 .openzeppelin/unknown-1284.json create mode 100644 addresses/moonbeam/index.json delete mode 100644 addresses/mumbai/index.json diff --git a/.openzeppelin/unknown-1284.json b/.openzeppelin/unknown-1284.json new file mode 100644 index 0000000..2b24b33 --- /dev/null +++ b/.openzeppelin/unknown-1284.json @@ -0,0 +1,211 @@ +{ + "manifestVersion": "3.2", + "proxies": [ + { + "address": "0x1FdB03ee7e0A861D0495075C1459ef87bC4de54c", + "txHash": "0x0710a2ba6366380ce03c7eea8b4724cace8607e34a829eb076cbec748057e08e", + "kind": "transparent" + } + ], + "impls": { + "03dbc49f2e99c8cb01616bbbd98922ee948f4f75585d7d68dc522bfc063ef00b": { + "address": "0xeE485138ae7b0A50F2342c67675c6D0a3bd1d3ea", + "txHash": "0x8aaf710df35d3864bde19c104e99a4bfb6ab1002f03062f12b22eaa45fcbb41f", + "layout": { + "solcVersion": "0.8.9", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40" + }, + { + "label": "_owner", + "offset": 0, + "slot": "51", + "type": "t_address", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22" + }, + { + "label": "__gap", + "offset": 0, + "slot": "52", + "type": "t_array(t_uint256)49_storage", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94" + }, + { + "label": "defaultSftRolesRegistry", + "offset": 0, + "slot": "101", + "type": "t_address", + "contract": "OriumMarketplaceRoyalties", + "src": "contracts/OriumMarketplaceRoyalties.sol:26" + }, + { + "label": "defaultNftRolesRegistry", + "offset": 0, + "slot": "102", + "type": "t_address", + "contract": "OriumMarketplaceRoyalties", + "src": "contracts/OriumMarketplaceRoyalties.sol:29" + }, + { + "label": "tokenAddressToRolesRegistry", + "offset": 0, + "slot": "103", + "type": "t_mapping(t_address,t_address)", + "contract": "OriumMarketplaceRoyalties", + "src": "contracts/OriumMarketplaceRoyalties.sol:32" + }, + { + "label": "maxDuration", + "offset": 0, + "slot": "104", + "type": "t_uint64", + "contract": "OriumMarketplaceRoyalties", + "src": "contracts/OriumMarketplaceRoyalties.sol:35" + }, + { + "label": "feeInfo", + "offset": 0, + "slot": "105", + "type": "t_mapping(t_address,t_struct(FeeInfo)8707_storage)", + "contract": "OriumMarketplaceRoyalties", + "src": "contracts/OriumMarketplaceRoyalties.sol:38" + }, + { + "label": "tokenAddressToRoyaltyInfo", + "offset": 0, + "slot": "106", + "type": "t_mapping(t_address,t_struct(RoyaltyInfo)8714_storage)", + "contract": "OriumMarketplaceRoyalties", + "src": "contracts/OriumMarketplaceRoyalties.sol:41" + }, + { + "label": "isTrustedFeeTokenAddressForToken", + "offset": 0, + "slot": "107", + "type": "t_mapping(t_address,t_mapping(t_address,t_bool))", + "contract": "OriumMarketplaceRoyalties", + "src": "contracts/OriumMarketplaceRoyalties.sol:44" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_mapping(t_address,t_address)": { + "label": "mapping(address => address)", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_bool)": { + "label": "mapping(address => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_mapping(t_address,t_bool))": { + "label": "mapping(address => mapping(address => bool))", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_struct(FeeInfo)8707_storage)": { + "label": "mapping(address => struct IOriumMarketplaceRoyalties.FeeInfo)", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_struct(RoyaltyInfo)8714_storage)": { + "label": "mapping(address => struct IOriumMarketplaceRoyalties.RoyaltyInfo)", + "numberOfBytes": "32" + }, + "t_struct(FeeInfo)8707_storage": { + "label": "struct IOriumMarketplaceRoyalties.FeeInfo", + "members": [ + { + "label": "feePercentageInWei", + "type": "t_uint256", + "offset": 0, + "slot": "0" + }, + { + "label": "isCustomFee", + "type": "t_bool", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_struct(RoyaltyInfo)8714_storage": { + "label": "struct IOriumMarketplaceRoyalties.RoyaltyInfo", + "members": [ + { + "label": "creator", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "royaltyPercentageInWei", + "type": "t_uint256", + "offset": 0, + "slot": "1" + }, + { + "label": "treasury", + "type": "t_address", + "offset": 0, + "slot": "2" + } + ], + "numberOfBytes": "96" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": {} + } + } + } +} diff --git a/addresses/cronos/index.json b/addresses/cronos/index.json index 26ca0c4..d4eecb4 100644 --- a/addresses/cronos/index.json +++ b/addresses/cronos/index.json @@ -31,5 +31,8 @@ "operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806", "implementation": "0x17ecC3620cE4062fA5eC4298a6BDc6d5A25d75Fe", "proxyAdmin": "0x5E053177c73636d4378cfB4D095cFb374eBb3Da6" + }, + "ERC7432WrapperForERC4907": { + "address": "" } } \ No newline at end of file diff --git a/addresses/cronosTestnet/index.json b/addresses/cronosTestnet/index.json index 07fc602..9586010 100644 --- a/addresses/cronosTestnet/index.json +++ b/addresses/cronosTestnet/index.json @@ -31,5 +31,8 @@ "operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806", "implementation": "0xe359D2353D8f2E6Bd574E49F34c987729380EA1C", "proxyAdmin": "0xC3154ccAC181eb9d71ccd53f29F425BDdD52d983" + }, + "ERC7432WrapperForERC4907": { + "address": "" } } \ No newline at end of file diff --git a/addresses/index.ts b/addresses/index.ts index a2bca1c..09829e8 100644 --- a/addresses/index.ts +++ b/addresses/index.ts @@ -1,10 +1,10 @@ -import mumbai from './mumbai/index.json' +import moonbeam from './moonbeam/index.json' import polygon from './polygon/index.json' import cronosTestnet from './cronosTestnet/index.json' import cronos from './cronos/index.json' const config = { - mumbai, + moonbeam, polygon, cronosTestnet, cronos, diff --git a/addresses/moonbeam/index.json b/addresses/moonbeam/index.json new file mode 100644 index 0000000..f7f61a7 --- /dev/null +++ b/addresses/moonbeam/index.json @@ -0,0 +1,41 @@ +{ + "Multisig": { + "address": "" + }, + "RolesRegistry": { + "address": "" + }, + "SftRolesRegistrySingleRole": { + "address": "" + }, + "KMSDeployer": { + "address": "0x04c8c6c56dab836f8bd62cb6884371507e706806" + }, + "OriumMarketplace": { + "address": "", + "operator": "", + "implementation": "", + "proxyAdmin": "" + }, + "ImmutableOwnerCreate2Factory": { + "address": "" + }, + "OriumMarketplaceRoyalties": { + "address": "0x1FdB03ee7e0A861D0495075C1459ef87bC4de54c", + "operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806", + "implementation": "0xeE485138ae7b0A50F2342c67675c6D0a3bd1d3ea", + "proxyAdmin": "0xbee720D292d591cc94f522050cc2069070e3a15C" + }, + "OriumSftMarketplace": { + "address": "", + "operator": "", + "implementation": "", + "proxyAdmin": "", + "libraries": [ + "" + ] + }, + "ERC7432WrapperForERC4907": { + "address": "0xc3154ccac181eb9d71ccd53f29f425bddd52d983" + } +} \ No newline at end of file diff --git a/addresses/mumbai/index.json b/addresses/mumbai/index.json deleted file mode 100644 index 53aa34e..0000000 --- a/addresses/mumbai/index.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "Multisig": { - "address": "0x61c22C4e709c3027ecCCdd6ee562BB583Db9a17f" - }, - "RolesRegistry": { - "address": "0xB1b599Ec67ad23AF7FAC240191319822e674571A" - }, - "SftRolesRegistrySingleRole": { - "address": "" - }, - "KMSDeployer": { - "address": "0x04c8c6c56dab836f8bd62cb6884371507e706806" - }, - "OriumMarketplace": { - "address": "0x77766beEc578e6a6c2BF23f9f6577DC8Fa83Ef26", - "operator": "0x61c22C4e709c3027ecCCdd6ee562BB583Db9a17f", - "implementation": "0xB1E6FDAD3aB4Df7738D68c5cC4f9f419d46B6e1a", - "proxyAdmin": "0x3033689fB46FDe57789A8c84AD1C9bD3A8217985" - }, - "ImmutableOwnerCreate2Factory": { - "address": "0x066f91a9Aa4C33D4ea4c12aBee6f4cb4e919F71d" - }, - "OriumMarketplaceRoyalties": { - "address": "0x28c0DFe3e6B53ff3A25B9655A0B9D62120Ae34Fc", - "operator": "0x61c22C4e709c3027ecCCdd6ee562BB583Db9a17f", - "implementation": "0x69C4c9D8B8D815c57Cb252f228159b2794094a17", - "proxyAdmin": "0x3033689fB46FDe57789A8c84AD1C9bD3A8217985" - }, - "OriumSftMarketplace": { - "address": "0xF992Cf6815aC9c08B3631b5587e16d561ef9a969", - "operator": "0x61c22C4e709c3027ecCCdd6ee562BB583Db9a17f", - "implementation": "0x7F431494c9014d7159Ccc14c64d7Fd433354835a", - "proxyAdmin": "0x3033689fB46FDe57789A8c84AD1C9bD3A8217985" - } -} \ No newline at end of file diff --git a/addresses/polygon/index.json b/addresses/polygon/index.json index e651b64..49d4be8 100644 --- a/addresses/polygon/index.json +++ b/addresses/polygon/index.json @@ -34,5 +34,8 @@ "libraries": [ "0x39CdF22FA80A9E7B95Db29efb2936A9561c70601" ] + }, + "ERC7432WrapperForERC4907": { + "address": "" } } \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index 67e247d..2384386 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -12,13 +12,14 @@ const { ENVIRONMENT, DEFENDER_TEAM_API_KEY, DEFENDER_TEAM_API_SECRET_KEY, - MUMBAI_PROVIDER_URL, + MOONBEAM_PROVIDER_URL, POLYGON_PROVIDER_URL, DEV_PRIVATE_KEY, PROD_PRIVATE_KEY, POLYGONSCAN_API_KEY, ETHER_SCAN_API_KEY, CRONOSSCAN_API_KEY, + MOONSCAN_API_KEY, CRONOS_TESTNET_PROVIDER_URL, CRONOS_PROVIDER_URL, } = process.env @@ -34,10 +35,10 @@ const BASE_CONFIG = { etherscan: { apiKey: { polygon: POLYGONSCAN_API_KEY, - polygonMumbai: POLYGONSCAN_API_KEY, goerli: ETHER_SCAN_API_KEY, cronosTestnet: CRONOSSCAN_API_KEY, cronos: CRONOSSCAN_API_KEY, + moonbeam: MOONSCAN_API_KEY, }, customChains: [ { @@ -91,11 +92,6 @@ const PROD_CONFIG = { blockNumber: 55899875, }, }, - mumbai: { - chainId: 80001, - url: MUMBAI_PROVIDER_URL, - accounts: [DEV_PRIVATE_KEY], - }, polygon: { chainId: 137, url: POLYGON_PROVIDER_URL, @@ -112,6 +108,11 @@ const PROD_CONFIG = { url: CRONOS_PROVIDER_URL, accounts: [PROD_PRIVATE_KEY], }, + moonbeam: { + chainId: 1284, + url: MOONBEAM_PROVIDER_URL, + accounts: [DEV_PRIVATE_KEY], + }, }, defender: { apiKey: DEFENDER_TEAM_API_KEY, From d8af65d90ccc49031fd754911ec973a694ef798e Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 30 Apr 2024 12:35:42 -0300 Subject: [PATCH 4/6] ON-843: nft rental marketplace deploy moonbeam --- .openzeppelin/unknown-1284.json | 368 ++++++++++++++++++++++++++++++++ addresses/moonbeam/index.json | 9 + utils/deploy-upgradeable.ts | 22 +- 3 files changed, 397 insertions(+), 2 deletions(-) diff --git a/.openzeppelin/unknown-1284.json b/.openzeppelin/unknown-1284.json index 2b24b33..554ec15 100644 --- a/.openzeppelin/unknown-1284.json +++ b/.openzeppelin/unknown-1284.json @@ -5,6 +5,16 @@ "address": "0x1FdB03ee7e0A861D0495075C1459ef87bC4de54c", "txHash": "0x0710a2ba6366380ce03c7eea8b4724cace8607e34a829eb076cbec748057e08e", "kind": "transparent" + }, + { + "address": "0x2711383C11acA1Ab43d94D8006745331ca23b95B", + "txHash": "0x97a9f0f743ec63bb4cedb49c0b07eef9209941474c8b0d58a1301a228f1ab474", + "kind": "transparent" + }, + { + "address": "0x201E1636BB21Dfd51F93815BCD008EAe2Fa29bD9", + "txHash": "0xc65d6274d7d69f80a8acf4ddeb73132b1597f2675c2d0b7e4a9eb2a2d13eceb0", + "kind": "transparent" } ], "impls": { @@ -206,6 +216,364 @@ }, "namespaces": {} } + }, + "dcb9cdfd52e3f2d2d84e7309deb1bab1b5bdeb4c6e444ea5c27c79bd6d834e0c": { + "address": "0xbD2BaC0Ad6205c40c1CA62530d42c76eF0b2E384", + "txHash": "0xb4a59ad9b43cbd4c57667b7517cc1bb45c834d0510dae29dcf685f9002a1189f", + "layout": { + "solcVersion": "0.8.9", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40" + }, + { + "label": "_owner", + "offset": 0, + "slot": "51", + "type": "t_address", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22" + }, + { + "label": "__gap", + "offset": 0, + "slot": "52", + "type": "t_array(t_uint256)49_storage", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94" + }, + { + "label": "_paused", + "offset": 0, + "slot": "101", + "type": "t_bool", + "contract": "PausableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol:29" + }, + { + "label": "__gap", + "offset": 0, + "slot": "102", + "type": "t_array(t_uint256)49_storage", + "contract": "PausableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol:116" + }, + { + "label": "oriumMarketplaceRoyalties", + "offset": 0, + "slot": "151", + "type": "t_address", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:24" + }, + { + "label": "isCreated", + "offset": 0, + "slot": "152", + "type": "t_mapping(t_bytes32,t_bool)", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:27" + }, + { + "label": "nonceDeadline", + "offset": 0, + "slot": "153", + "type": "t_mapping(t_address,t_mapping(t_uint256,t_uint64))", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:30" + }, + { + "label": "roleDeadline", + "offset": 0, + "slot": "154", + "type": "t_mapping(t_bytes32,t_mapping(t_address,t_mapping(t_uint256,t_uint64)))", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:33" + }, + { + "label": "rentals", + "offset": 0, + "slot": "155", + "type": "t_mapping(t_bytes32,t_struct(Rental)1951_storage)", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:36" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_mapping(t_uint256,t_uint64))": { + "label": "mapping(address => mapping(uint256 => uint64))", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_bool)": { + "label": "mapping(bytes32 => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_mapping(t_address,t_mapping(t_uint256,t_uint64)))": { + "label": "mapping(bytes32 => mapping(address => mapping(uint256 => uint64)))", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_struct(Rental)1951_storage)": { + "label": "mapping(bytes32 => struct Rental)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_uint64)": { + "label": "mapping(uint256 => uint64)", + "numberOfBytes": "32" + }, + "t_struct(Rental)1951_storage": { + "label": "struct Rental", + "members": [ + { + "label": "borrower", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "expirationDate", + "type": "t_uint64", + "offset": 20, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": {} + } + }, + "a6e8547bfc157c21d02b324f241dff9c7a3f5498ad69d6286192785b96973869": { + "address": "0x1112949A242A0283c2170b9F28931ccBE8878d18", + "txHash": "0xfd86bd20c98db94842ccf2fc9cdcee0da4f650d843245db2188d16c9f8fed994", + "layout": { + "solcVersion": "0.8.9", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40" + }, + { + "label": "_owner", + "offset": 0, + "slot": "51", + "type": "t_address", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22" + }, + { + "label": "__gap", + "offset": 0, + "slot": "52", + "type": "t_array(t_uint256)49_storage", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94" + }, + { + "label": "_paused", + "offset": 0, + "slot": "101", + "type": "t_bool", + "contract": "PausableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol:29" + }, + { + "label": "__gap", + "offset": 0, + "slot": "102", + "type": "t_array(t_uint256)49_storage", + "contract": "PausableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol:116" + }, + { + "label": "oriumMarketplaceRoyalties", + "offset": 0, + "slot": "151", + "type": "t_address", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:24" + }, + { + "label": "isCreated", + "offset": 0, + "slot": "152", + "type": "t_mapping(t_bytes32,t_bool)", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:27" + }, + { + "label": "nonceDeadline", + "offset": 0, + "slot": "153", + "type": "t_mapping(t_address,t_mapping(t_uint256,t_uint64))", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:30" + }, + { + "label": "roleDeadline", + "offset": 0, + "slot": "154", + "type": "t_mapping(t_bytes32,t_mapping(t_address,t_mapping(t_uint256,t_uint64)))", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:33" + }, + { + "label": "rentals", + "offset": 0, + "slot": "155", + "type": "t_mapping(t_bytes32,t_struct(Rental)1951_storage)", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:36" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_mapping(t_uint256,t_uint64))": { + "label": "mapping(address => mapping(uint256 => uint64))", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_bool)": { + "label": "mapping(bytes32 => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_mapping(t_address,t_mapping(t_uint256,t_uint64)))": { + "label": "mapping(bytes32 => mapping(address => mapping(uint256 => uint64)))", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_struct(Rental)1951_storage)": { + "label": "mapping(bytes32 => struct Rental)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_uint64)": { + "label": "mapping(uint256 => uint64)", + "numberOfBytes": "32" + }, + "t_struct(Rental)1951_storage": { + "label": "struct Rental", + "members": [ + { + "label": "borrower", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "expirationDate", + "type": "t_uint64", + "offset": 20, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": {} + } } } } diff --git a/addresses/moonbeam/index.json b/addresses/moonbeam/index.json index f7f61a7..258417a 100644 --- a/addresses/moonbeam/index.json +++ b/addresses/moonbeam/index.json @@ -37,5 +37,14 @@ }, "ERC7432WrapperForERC4907": { "address": "0xc3154ccac181eb9d71ccd53f29f425bddd52d983" + }, + "NftRentalMarketplace": { + "address": "0x201E1636BB21Dfd51F93815BCD008EAe2Fa29bD9", + "operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806", + "implementation": "0x1112949A242A0283c2170b9F28931ccBE8878d18", + "proxyAdmin": "0x668e73cF24361cfE13801681d8885e6632A7Eaa6", + "libraries": { + "LibNftRentalMarketplace": "0x037c0ae89bAE6d86476074CE3ef4F235467B1B79" + } } } \ No newline at end of file diff --git a/utils/deploy-upgradeable.ts b/utils/deploy-upgradeable.ts index 8f4e6c5..5909485 100644 --- a/utils/deploy-upgradeable.ts +++ b/utils/deploy-upgradeable.ts @@ -28,7 +28,9 @@ export async function deployUpgradeableContract( const deployerAddress = await deployer.getAddress() const libraries: { [key: string]: string } = {} - confirmOrDie(`Deploying ${PROXY_CONTRACT_NAME} contract on: ${NETWORK} network with ${deployerAddress}. Continue?`) + await confirmOrDie( + `Deploying ${PROXY_CONTRACT_NAME} contract on: ${NETWORK} network with ${deployerAddress}. Continue?`, + ) if (LIBRARIES_CONTRACT_NAME !== undefined) { print(colors.highlight, 'Deploying libraries...') @@ -97,10 +99,26 @@ export async function deployUpgradeableContract( print(colors.error, `Error transferring proxy admin ownership: ${e}`) } + if (LIBRARIES_CONTRACT_NAME) { + print(colors.highlight, 'Verifying libraries on Etherscan...') + 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 Etherscan...') await hre.run('verify:verify', { address: await contract.getAddress(), constructorArguments: [], }) - print(colors.success, 'Contract verified!') + print(colors.success, `${PROXY_CONTRACT_NAME} verified!`) } From ad3037ef87ab26c2422b487dd4cefe3d9b9411da Mon Sep 17 00:00:00 2001 From: Daniel Lima <38267570+karacurt@users.noreply.github.com> Date: Tue, 30 Apr 2024 13:00:53 -0300 Subject: [PATCH 5/6] Update utils/deploy-upgradeable.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ernani São Thiago --- utils/deploy-upgradeable.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/deploy-upgradeable.ts b/utils/deploy-upgradeable.ts index 5909485..9210f97 100644 --- a/utils/deploy-upgradeable.ts +++ b/utils/deploy-upgradeable.ts @@ -14,6 +14,7 @@ const NETWORK = network.name as Network const networkConfig: any = network.config const provider = new ethers.JsonRpcProvider(networkConfig.url || '') const deployer = new AwsKmsSigner(kmsCredentials).connect(provider) + export async function deployUpgradeableContract( PROXY_CONTRACT_NAME: string, OPERATOR_ADDRESS: string, From 004c0799bea0999738df9f5036f059e414b170e5 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 30 Apr 2024 13:04:08 -0300 Subject: [PATCH 6/6] ON-843: PR fixes --- scripts/orium-marketplace-royalties/01-deploy.ts | 9 ++------- utils/ethers-aws-kms-signer.ts | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/scripts/orium-marketplace-royalties/01-deploy.ts b/scripts/orium-marketplace-royalties/01-deploy.ts index 5d7537e..f4f2242 100644 --- a/scripts/orium-marketplace-royalties/01-deploy.ts +++ b/scripts/orium-marketplace-royalties/01-deploy.ts @@ -5,16 +5,11 @@ import { AddressZero, THREE_MONTHS } from '../../utils/constants' import { deployUpgradeableContract } from '../../utils/deploy-upgradeable' const NETWORK = network.name as Network -const { KMSDeployer, ERC7432WrapperForERC4907 } = addresses[NETWORK] +const { KMSDeployer } = addresses[NETWORK] const CONTRACT_NAME = 'OriumMarketplaceRoyalties' const OPERATOR_ADDRESS = KMSDeployer.address -const INITIALIZER_ARGUMENTS: string[] = [ - OPERATOR_ADDRESS, - ERC7432WrapperForERC4907.address, - AddressZero, - THREE_MONTHS.toString(), -] +const INITIALIZER_ARGUMENTS: string[] = [OPERATOR_ADDRESS, AddressZero, AddressZero, THREE_MONTHS.toString()] async function main() { await deployUpgradeableContract(CONTRACT_NAME, OPERATOR_ADDRESS, INITIALIZER_ARGUMENTS) diff --git a/utils/ethers-aws-kms-signer.ts b/utils/ethers-aws-kms-signer.ts index 0ce0f13..325dab4 100644 --- a/utils/ethers-aws-kms-signer.ts +++ b/utils/ethers-aws-kms-signer.ts @@ -1,3 +1,4 @@ +// Source: https://github.com/0xcuonghx/ethers-kms-signer/blob/main/packages/ethers-aws-kms-signer/src/aws-kms-signer.ts import { GetPublicKeyCommand, KMSClient, SignCommand } from '@aws-sdk/client-kms' import { ECDSASigValue } from '@peculiar/asn1-ecc' import { AsnConvert } from '@peculiar/asn1-schema'