diff --git a/.openzeppelin/polygon-mumbai.json b/.openzeppelin/polygon-mumbai.json index d93d75d..16948de 100644 --- a/.openzeppelin/polygon-mumbai.json +++ b/.openzeppelin/polygon-mumbai.json @@ -1,575 +1,17 @@ { "manifestVersion": "3.2", "admin": { - "address": "0x3033689fB46FDe57789A8c84AD1C9bD3A8217985", - "txHash": "0x33553e7b45da38718017d1bd80df13bdb0a10887b96cf4cc8687b21612f5294f" + "address": "0xF081644c3745b89F8E7F47E116D2122774A0508c" }, "proxies": [ { - "address": "0x037c0ae89bAE6d86476074CE3ef4F235467B1B79", - "txHash": "0x28080596e65d9d46cb15ff4fb37769b8dba29f50066738f3cac3a778d819bb46", - "kind": "transparent" - }, - { - "address": "0x594eA0cD77fAD6e026b55B0519fD306543E29150", + "address": "0xF39048AC4677a9bEc6b6E081eB2968755BB8173e", "kind": "transparent" } ], "impls": { - "54a4d6a09a43613c32ca9e07613d8cc56e3791a26d99d9ce5db1c1f1191d6a3f": { - "address": "0x2711383C11acA1Ab43d94D8006745331ca23b95B", - "txHash": "0xb27c9567b99d8868a811a6c2411e25a437811f3914c0b6780749cb375ce41c66", - "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:62", - "retypedFrom": "bool" - }, - { - "label": "_initializing", - "offset": 1, - "slot": "0", - "type": "t_bool", - "contract": "Initializable", - "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67" - }, - { - "label": "__gap", - "offset": 0, - "slot": "1", - "type": "t_array(t_uint256)50_storage", - "contract": "ContextUpgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36" - }, - { - "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": "_HASHED_NAME", - "offset": 0, - "slot": "151", - "type": "t_bytes32", - "contract": "EIP712Upgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:32" - }, - { - "label": "_HASHED_VERSION", - "offset": 0, - "slot": "152", - "type": "t_bytes32", - "contract": "EIP712Upgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:33" - }, - { - "label": "__gap", - "offset": 0, - "slot": "153", - "type": "t_array(t_uint256)50_storage", - "contract": "EIP712Upgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:120" - }, - { - "label": "defaultRolesRegistry", - "offset": 0, - "slot": "203", - "type": "t_address", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:32" - }, - { - "label": "tokenRolesRegistry", - "offset": 0, - "slot": "204", - "type": "t_mapping(t_address,t_address)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:35" - }, - { - "label": "maxDeadline", - "offset": 0, - "slot": "205", - "type": "t_uint256", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:38" - }, - { - "label": "feeInfo", - "offset": 0, - "slot": "206", - "type": "t_mapping(t_address,t_struct(FeeInfo)2609_storage)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:41" - }, - { - "label": "royaltyInfo", - "offset": 0, - "slot": "207", - "type": "t_mapping(t_address,t_struct(RoyaltyInfo)2604_storage)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:44" - }, - { - "label": "isCreated", - "offset": 0, - "slot": "208", - "type": "t_mapping(t_bytes32,t_bool)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:47" - }, - { - "label": "nonceDeadline", - "offset": 0, - "slot": "209", - "type": "t_mapping(t_address,t_mapping(t_uint256,t_uint64))", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:50" - }, - { - "label": "rentals", - "offset": 0, - "slot": "210", - "type": "t_mapping(t_bytes32,t_struct(Rental)2597_storage)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:53" - } - ], - "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_address)": { - "label": "mapping(address => address)", - "numberOfBytes": "32" - }, - "t_mapping(t_address,t_mapping(t_uint256,t_uint64))": { - "label": "mapping(address => mapping(uint256 => uint64))", - "numberOfBytes": "32" - }, - "t_mapping(t_address,t_struct(FeeInfo)2609_storage)": { - "label": "mapping(address => struct OriumMarketplace.FeeInfo)", - "numberOfBytes": "32" - }, - "t_mapping(t_address,t_struct(RoyaltyInfo)2604_storage)": { - "label": "mapping(address => struct OriumMarketplace.RoyaltyInfo)", - "numberOfBytes": "32" - }, - "t_mapping(t_bytes32,t_bool)": { - "label": "mapping(bytes32 => bool)", - "numberOfBytes": "32" - }, - "t_mapping(t_bytes32,t_struct(Rental)2597_storage)": { - "label": "mapping(bytes32 => struct OriumMarketplace.Rental)", - "numberOfBytes": "32" - }, - "t_mapping(t_uint256,t_uint64)": { - "label": "mapping(uint256 => uint64)", - "numberOfBytes": "32" - }, - "t_struct(FeeInfo)2609_storage": { - "label": "struct OriumMarketplace.FeeInfo", - "members": [ - { - "label": "feePercentageInWei", - "type": "t_uint256", - "offset": 0, - "slot": "0" - }, - { - "label": "isCustomFee", - "type": "t_bool", - "offset": 0, - "slot": "1" - } - ], - "numberOfBytes": "64" - }, - "t_struct(Rental)2597_storage": { - "label": "struct OriumMarketplace.Rental", - "members": [ - { - "label": "borrower", - "type": "t_address", - "offset": 0, - "slot": "0" - }, - { - "label": "expirationDate", - "type": "t_uint64", - "offset": 20, - "slot": "0" - } - ], - "numberOfBytes": "32" - }, - "t_struct(RoyaltyInfo)2604_storage": { - "label": "struct OriumMarketplace.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" - } - } - } - }, - "3a2de891b9511db2351f179bd219b0c75f083aa9efa4f87953603c56ecbc6e48": { - "address": "0x92Ea5e9D5341F10eb6291BB72F3C9e617090952C", - "txHash": "0x17ce686764e07a005aa6788f8766eec07dec7d01350a081ceeec7df4f2bbba16", - "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:62", - "retypedFrom": "bool" - }, - { - "label": "_initializing", - "offset": 1, - "slot": "0", - "type": "t_bool", - "contract": "Initializable", - "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:67" - }, - { - "label": "__gap", - "offset": 0, - "slot": "1", - "type": "t_array(t_uint256)50_storage", - "contract": "ContextUpgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36" - }, - { - "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": "_HASHED_NAME", - "offset": 0, - "slot": "151", - "type": "t_bytes32", - "contract": "EIP712Upgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:32" - }, - { - "label": "_HASHED_VERSION", - "offset": 0, - "slot": "152", - "type": "t_bytes32", - "contract": "EIP712Upgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:33" - }, - { - "label": "__gap", - "offset": 0, - "slot": "153", - "type": "t_array(t_uint256)50_storage", - "contract": "EIP712Upgradeable", - "src": "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol:120" - }, - { - "label": "defaultRolesRegistry", - "offset": 0, - "slot": "203", - "type": "t_address", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:32" - }, - { - "label": "tokenRolesRegistry", - "offset": 0, - "slot": "204", - "type": "t_mapping(t_address,t_address)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:35" - }, - { - "label": "maxDeadline", - "offset": 0, - "slot": "205", - "type": "t_uint256", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:38" - }, - { - "label": "feeInfo", - "offset": 0, - "slot": "206", - "type": "t_mapping(t_address,t_struct(FeeInfo)2609_storage)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:41" - }, - { - "label": "royaltyInfo", - "offset": 0, - "slot": "207", - "type": "t_mapping(t_address,t_struct(RoyaltyInfo)2604_storage)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:44" - }, - { - "label": "isCreated", - "offset": 0, - "slot": "208", - "type": "t_mapping(t_bytes32,t_bool)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:47" - }, - { - "label": "nonceDeadline", - "offset": 0, - "slot": "209", - "type": "t_mapping(t_address,t_mapping(t_uint256,t_uint64))", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:50" - }, - { - "label": "rentals", - "offset": 0, - "slot": "210", - "type": "t_mapping(t_bytes32,t_struct(Rental)2597_storage)", - "contract": "OriumMarketplace", - "src": "contracts/OriumMarketplace.sol:53" - } - ], - "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_address)": { - "label": "mapping(address => address)", - "numberOfBytes": "32" - }, - "t_mapping(t_address,t_mapping(t_uint256,t_uint64))": { - "label": "mapping(address => mapping(uint256 => uint64))", - "numberOfBytes": "32" - }, - "t_mapping(t_address,t_struct(FeeInfo)2609_storage)": { - "label": "mapping(address => struct OriumMarketplace.FeeInfo)", - "numberOfBytes": "32" - }, - "t_mapping(t_address,t_struct(RoyaltyInfo)2604_storage)": { - "label": "mapping(address => struct OriumMarketplace.RoyaltyInfo)", - "numberOfBytes": "32" - }, - "t_mapping(t_bytes32,t_bool)": { - "label": "mapping(bytes32 => bool)", - "numberOfBytes": "32" - }, - "t_mapping(t_bytes32,t_struct(Rental)2597_storage)": { - "label": "mapping(bytes32 => struct OriumMarketplace.Rental)", - "numberOfBytes": "32" - }, - "t_mapping(t_uint256,t_uint64)": { - "label": "mapping(uint256 => uint64)", - "numberOfBytes": "32" - }, - "t_struct(FeeInfo)2609_storage": { - "label": "struct OriumMarketplace.FeeInfo", - "members": [ - { - "label": "feePercentageInWei", - "type": "t_uint256", - "offset": 0, - "slot": "0" - }, - { - "label": "isCustomFee", - "type": "t_bool", - "offset": 0, - "slot": "1" - } - ], - "numberOfBytes": "64" - }, - "t_struct(Rental)2597_storage": { - "label": "struct OriumMarketplace.Rental", - "members": [ - { - "label": "borrower", - "type": "t_address", - "offset": 0, - "slot": "0" - }, - { - "label": "expirationDate", - "type": "t_uint64", - "offset": 20, - "slot": "0" - } - ], - "numberOfBytes": "32" - }, - "t_struct(RoyaltyInfo)2604_storage": { - "label": "struct OriumMarketplace.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" - } - } - } - }, "e55e9899b6871030f89ffb91f6ad5aa4a68297a0cc552aa7dc7d801a2ae0ce17": { - "address": "0xA6F3dB9e9fd1b4e2b3215fBA3A9Ae65B1601120A", + "address": "0x9DD32aA202c58fB1cDA6b54B25D1c99CB44094F9", "layout": { "solcVersion": "0.8.9", "storage": [ @@ -658,7 +100,7 @@ "label": "feeInfo", "offset": 0, "slot": "154", - "type": "t_mapping(t_address,t_struct(FeeInfo)5448_storage)", + "type": "t_mapping(t_address,t_struct(FeeInfo)1047_storage)", "contract": "OriumMarketplace", "src": "contracts/OriumMarketplace.sol:37" }, @@ -666,7 +108,7 @@ "label": "royaltyInfo", "offset": 0, "slot": "155", - "type": "t_mapping(t_address,t_struct(RoyaltyInfo)5443_storage)", + "type": "t_mapping(t_address,t_struct(RoyaltyInfo)1042_storage)", "contract": "OriumMarketplace", "src": "contracts/OriumMarketplace.sol:40" }, @@ -690,7 +132,7 @@ "label": "rentals", "offset": 0, "slot": "158", - "type": "t_mapping(t_bytes32,t_struct(Rental)5436_storage)", + "type": "t_mapping(t_bytes32,t_struct(Rental)1035_storage)", "contract": "OriumMarketplace", "src": "contracts/OriumMarketplace.sol:49" } @@ -724,11 +166,11 @@ "label": "mapping(address => mapping(uint256 => uint64))", "numberOfBytes": "32" }, - "t_mapping(t_address,t_struct(FeeInfo)5448_storage)": { + "t_mapping(t_address,t_struct(FeeInfo)1047_storage)": { "label": "mapping(address => struct OriumMarketplace.FeeInfo)", "numberOfBytes": "32" }, - "t_mapping(t_address,t_struct(RoyaltyInfo)5443_storage)": { + "t_mapping(t_address,t_struct(RoyaltyInfo)1042_storage)": { "label": "mapping(address => struct OriumMarketplace.RoyaltyInfo)", "numberOfBytes": "32" }, @@ -736,7 +178,7 @@ "label": "mapping(bytes32 => bool)", "numberOfBytes": "32" }, - "t_mapping(t_bytes32,t_struct(Rental)5436_storage)": { + "t_mapping(t_bytes32,t_struct(Rental)1035_storage)": { "label": "mapping(bytes32 => struct OriumMarketplace.Rental)", "numberOfBytes": "32" }, @@ -744,7 +186,7 @@ "label": "mapping(uint256 => uint64)", "numberOfBytes": "32" }, - "t_struct(FeeInfo)5448_storage": { + "t_struct(FeeInfo)1047_storage": { "label": "struct OriumMarketplace.FeeInfo", "members": [ { @@ -762,7 +204,7 @@ ], "numberOfBytes": "64" }, - "t_struct(Rental)5436_storage": { + "t_struct(Rental)1035_storage": { "label": "struct OriumMarketplace.Rental", "members": [ { @@ -780,7 +222,7 @@ ], "numberOfBytes": "32" }, - "t_struct(RoyaltyInfo)5443_storage": { + "t_struct(RoyaltyInfo)1042_storage": { "label": "struct OriumMarketplace.RoyaltyInfo", "members": [ { diff --git a/addresses/mumbai/index.json b/addresses/mumbai/index.json index 257da13..e1a347f 100644 --- a/addresses/mumbai/index.json +++ b/addresses/mumbai/index.json @@ -9,10 +9,10 @@ "address": "0x04c8c6c56dab836f8bd62cb6884371507e706806" }, "OriumMarketplace": { - "address": "0x594eA0cD77fAD6e026b55B0519fD306543E29150", + "address": "0xF39048AC4677a9bEc6b6E081eB2968755BB8173e", "operator": "0x61c22C4e709c3027ecCCdd6ee562BB583Db9a17f", - "implementation": "0xA6F3dB9e9fd1b4e2b3215fBA3A9Ae65B1601120A", - "proxyAdmin": "0x3033689fB46FDe57789A8c84AD1C9bD3A8217985" + "implementation": "0x9DD32aA202c58fB1cDA6b54B25D1c99CB44094F9", + "proxyAdmin": "0xF081644c3745b89F8E7F47E116D2122774A0508c" }, "ImmutableOwnerCreate2Factory": { "address": "0x066f91a9Aa4C33D4ea4c12aBee6f4cb4e919F71d" diff --git a/contracts/proxy/CustomProxyAdmin.sol b/contracts/proxy/CustomProxyAdmin.sol new file mode 100644 index 0000000..a76e8f3 --- /dev/null +++ b/contracts/proxy/CustomProxyAdmin.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: CC0-1.0 + +pragma solidity 0.8.9; + +import { ProxyAdmin } from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; + +contract CustomProxyAdmin is ProxyAdmin { + constructor(address _owner) { + transferOwnership(_owner); + } +} diff --git a/scripts/04-create2-deploy.ts b/scripts/04-create2-deploy.ts index f24f8f2..fc983b7 100644 --- a/scripts/04-create2-deploy.ts +++ b/scripts/04-create2-deploy.ts @@ -3,10 +3,14 @@ import { AwsKmsSigner } from '@govtechsg/ethers-aws-kms-signer' import { confirmOrDie, print, colors } from '../utils/misc' import addresses, { Network } from '../addresses' import { THREE_MONTHS } from '../utils/constants' -import config from '../addresses' import { keccak256 } from 'ethers/lib/utils' -import TransparentUpgradeableProxy from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json' +import { + abi as proxyAbi, + bytecode as proxyBytecode, +} from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json' import { updateJsonFile } from '../utils/json' +import { defaultAbiCoder as abi, concat } from 'ethers/lib/utils' +import { Contract, ContractFactory } from 'ethers' const kmsCredentials = { accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'AKIAxxxxxxxxxxxxxxxx', // credentials for your IAM user with KMS access @@ -16,12 +20,13 @@ const kmsCredentials = { } const NETWORK = network.name as Network -const { Multisig, RolesRegistry } = addresses[NETWORK] +const { Multisig, RolesRegistry, ImmutableOwnerCreate2Factory } = 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 SALT = '0x00000000000000000000000000000000000000008b99e5a778edb02572010000' const networkConfig: any = network.config const provider = new ethers.providers.JsonRpcProvider(networkConfig.url || '') @@ -29,55 +34,31 @@ const deployer = new AwsKmsSigner(kmsCredentials).connect(provider) async function main() { const deployerAddress = await deployer.getAddress() + const create2Factory = await ethers.getContractAt( + 'IImmutableOwnerCreate2Factory', + ImmutableOwnerCreate2Factory.address, + deployer, + ) + await confirmOrDie( `Are you sure you want to deploy ${CONTRACT_NAME} to ${NETWORK} using ${deployerAddress} for deployer and ${OPERATOR_ADDRESS} as operator?`, ) print(colors.highlight, `Deploying ProxyAdmin to ${NETWORK}...`) - // Deploy ProxyAdmin and update network files, if there is a ProxyAdmin already deployed it will use it - const proxyAdminAddress = await upgrades.deployProxyAdmin(deployer) + const ProxyAdminFactory = await ethers.getContractFactory('CustomProxyAdmin', deployer) + const proxyAdminAddress = await create2DeployWithFactory(create2Factory, ProxyAdminFactory, [OPERATOR_ADDRESS], SALT) print(colors.success, `ProxyAdmin deployed to ${NETWORK} at ${proxyAdminAddress}`) print(colors.highlight, `Deploying implementation to ${NETWORK}...`) const ImplementationFactory = await ethers.getContractFactory(CONTRACT_NAME, deployer) - // We are not using upgrades.deployImplementation here because it will only update the storage layout of the implementation - // And it will clash when we try to forceImport the proxy network files - // This way we can have both (implementation and proxy) imported in the network files - const implementation = await ImplementationFactory.deploy() - await implementation.deployed() - print(colors.success, `Implementation deployed to ${NETWORK} at ${implementation.address}`) + const implementationAddress = await create2DeployWithFactory(create2Factory, ImplementationFactory, [], SALT) + print(colors.success, `Implementation deployed to ${NETWORK} at ${implementationAddress}`) print(colors.highlight, `Deploying proxy to ${NETWORK} with CREATE2...`) - - const create2Factory = await ethers.getContractAt( - 'IImmutableOwnerCreate2Factory', - config[NETWORK].ImmutableOwnerCreate2Factory.address, - deployer, - ) - - // encoding the implementation initialize function call with the arguments - const implementationInitData = ImplementationFactory.interface.encodeFunctionData('initialize', INITIALIZER_ARGUMENTS) - // encoding the TransparentUpgradeableProxy constructor call with the implementation address, proxy admin address and implementation initialize function call - // this is the bytecode that will be deployed with CREATE2 - const bytecode = ethers.utils.concat([ - TransparentUpgradeableProxy.bytecode, - ethers.utils.defaultAbiCoder.encode( - ['address', 'address', 'bytes'], - // Here we are passing the implementation address, proxy admin address that will be set for TransparentUpgradeableProxy - // and initialize data that will be called on implementation with delegatecall (implementationInitData) - [implementation.address, proxyAdminAddress, implementationInitData], - ), - ]) - const salt = '0x00000000000000000000000000000000000000008b99e5a778edb02572010000' - - // computing the proxy address that will be deployed with CREATE2 - const proxyContractAddress = await create2Factory.computeAddress(salt, keccak256(bytecode)) - print(colors.highlight, `Proxy will be deployed to ${proxyContractAddress}, deploying...`) - - // deploying the proxy with CREATE2, this will deploy the bytecode we computed above - const tx = await create2Factory.deploy(salt, bytecode) - print(colors.highlight, `Waiting for transaction to be mined..., tx: ${tx.hash}`) - await tx.wait() + const ProxyFactory = await ethers.getContractFactory(proxyAbi, proxyBytecode, deployer) + const initializerData = ImplementationFactory.interface.encodeFunctionData('initialize', INITIALIZER_ARGUMENTS) + const proxyConstructorArgs = [implementationAddress, proxyAdminAddress, initializerData] + const proxyContractAddress = await create2DeployWithFactory(create2Factory, ProxyFactory, proxyConstructorArgs, SALT) print(colors.success, `Proxy deployed to ${proxyContractAddress}`) // We need this to import to the network files the implementation WITH proxy address @@ -100,8 +81,7 @@ async function main() { }) print(colors.success, `Proxy verified!`) } catch (e) { - /* print(colors.error, `Proxy not verified`) - console.error(e) */ + console.error(e) } // THE FOLLOWING CODE IS THE SAME AS THE 01-deploy.ts (previous deploy script) @@ -111,7 +91,7 @@ async function main() { [CONTRACT_NAME]: { address: proxyContractAddress, operator: OPERATOR_ADDRESS, - implementation: implementation.address, + implementation: implementationAddress, proxyAdmin: proxyAdminAddress, }, } @@ -121,30 +101,32 @@ async function main() { 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}`) +async function create2DeployWithFactory(create2Factory: Contract, factory: ContractFactory, args: any[], salt: string) { + if (factory.interface.deploy.inputs.length !== args.length) { + throw new Error('Arguments length does not match factory inputs length') } + print(colors.highlight, `Deploying contract to ${NETWORK} with CREATE2...`) + + let bytecode: string | Uint8Array = factory.bytecode + console.log('factory.interface.deploy.inputs.length: ', factory.interface.deploy.inputs.length) + if (factory.interface.deploy.inputs.length > 0) { + const encodedArgs = abi.encode( + factory.interface.deploy.inputs.map(paramType => paramType.type), + args, + ) + bytecode = concat([factory.bytecode, encodedArgs]) + } + + const deploymentAddress = await create2Factory.computeAddress(salt, keccak256(bytecode)) + console.log('deploymentAddress: ', deploymentAddress) + + const tx = await create2Factory.deploy(salt, bytecode) + print(colors.highlight, `Waiting for transaction to be mined..., tx: ${tx.hash}`) + await tx.wait() + print(colors.success, `Contract deployed to ${deploymentAddress}`) + return deploymentAddress } main() diff --git a/scripts/05-verify.ts b/scripts/05-verify.ts new file mode 100644 index 0000000..8af7f90 --- /dev/null +++ b/scripts/05-verify.ts @@ -0,0 +1,32 @@ +import hre, { ethers, network, upgrades } from 'hardhat' +import { print, colors } from '../utils/misc' +import { Network } from '../addresses' +import config from '../addresses' + +const NETWORK = network.name as Network + +const CONTRACT_NAME = 'OriumMarketplace' +const CONTRACT_ADDRESS = config[NETWORK][CONTRACT_NAME].address +async function main() { + try { + await upgrades.forceImport(CONTRACT_ADDRESS, await ethers.getContractFactory(CONTRACT_NAME)) + } catch (e) { + console.error(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 + })