From 94e1c32253dc805771c71dff6e90456133fb5b26 Mon Sep 17 00:00:00 2001 From: maxvia87 Date: Sat, 12 Aug 2023 09:03:17 +0200 Subject: [PATCH 1/4] refactor: rename to LSP23LinkedContractsFactory --- ...y.sol => ILSP23LinkedContractsFactory.sol} | 2 +- ...ry.sol => LSP23LinkedContractsFactory.sol} | 12 +- .../LSP23LinkedContractsDeployment.test.ts | 119 +++++++++--------- .../LSP23LinkedContractsDeployment/helpers.ts | 8 +- 4 files changed, 73 insertions(+), 68 deletions(-) rename contracts/LSP23LinkedContractsDeployment/{ILinkedContractsFactory.sol => ILSP23LinkedContractsFactory.sol} (99%) rename contracts/LSP23LinkedContractsDeployment/{LinkedContractsFactory.sol => LSP23LinkedContractsFactory.sol} (97%) diff --git a/contracts/LSP23LinkedContractsDeployment/ILinkedContractsFactory.sol b/contracts/LSP23LinkedContractsDeployment/ILSP23LinkedContractsFactory.sol similarity index 99% rename from contracts/LSP23LinkedContractsDeployment/ILinkedContractsFactory.sol rename to contracts/LSP23LinkedContractsDeployment/ILSP23LinkedContractsFactory.sol index 3245fbd95..b81ee6561 100644 --- a/contracts/LSP23LinkedContractsDeployment/ILinkedContractsFactory.sol +++ b/contracts/LSP23LinkedContractsDeployment/ILSP23LinkedContractsFactory.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -interface ILinkedContractsFactory { +interface ILSP23LinkedContractsFactory { event DeployedContracts( address indexed primaryContract, address indexed secondaryContract, diff --git a/contracts/LSP23LinkedContractsDeployment/LinkedContractsFactory.sol b/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol similarity index 97% rename from contracts/LSP23LinkedContractsDeployment/LinkedContractsFactory.sol rename to contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol index 77be6b0b3..95544cb81 100644 --- a/contracts/LSP23LinkedContractsDeployment/LinkedContractsFactory.sol +++ b/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol @@ -4,16 +4,16 @@ pragma solidity ^0.8.4; import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; import {IPostDeploymentModule} from "./IPostDeploymentModule.sol"; -import {ILinkedContractsFactory} from "./ILinkedContractsFactory.sol"; +import {ILSP23LinkedContractsFactory} from "./ILSP23LinkedContractsFactory.sol"; import { InvalidValueSum, PrimaryContractProxyInitFailureError, SecondaryContractProxyInitFailureError } from "./LSP23Errors.sol"; -contract LinkedContractsFactory is ILinkedContractsFactory { +contract LSP23LinkedContractsFactory is ILSP23LinkedContractsFactory { /** - * @inheritdoc ILinkedContractsFactory + * @inheritdoc ILSP23LinkedContractsFactory */ function deployContracts( PrimaryContractDeployment calldata primaryContractDeployment, @@ -69,7 +69,7 @@ contract LinkedContractsFactory is ILinkedContractsFactory { } /** - * @inheritdoc ILinkedContractsFactory + * @inheritdoc ILSP23LinkedContractsFactory */ function deployERC1167Proxies( PrimaryContractDeploymentInit calldata primaryContractDeploymentInit, @@ -128,7 +128,7 @@ contract LinkedContractsFactory is ILinkedContractsFactory { } /** - * @inheritdoc ILinkedContractsFactory + * @inheritdoc ILSP23LinkedContractsFactory */ function computeAddresses( PrimaryContractDeployment calldata primaryContractDeployment, @@ -174,7 +174,7 @@ contract LinkedContractsFactory is ILinkedContractsFactory { } /** - * @inheritdoc ILinkedContractsFactory + * @inheritdoc ILSP23LinkedContractsFactory */ function computeERC1167Addresses( PrimaryContractDeploymentInit calldata primaryContractDeploymentInit, diff --git a/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts b/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts index af8e14da9..0276e8018 100644 --- a/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts +++ b/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts @@ -1,7 +1,7 @@ import { ethers } from 'hardhat'; import { expect } from 'chai'; -import { LinkedContractsFactory } from '../../typechain-types'; +import { LSP23LinkedContractsFactory } from '../../typechain-types'; import { ERC725YDataKeys } from '../../constants'; import { calculateProxiesAddresses, @@ -19,7 +19,7 @@ describe('UniversalProfileDeployer', function () { const universalProfileBytecode = (await ethers.getContractFactory('UniversalProfile')) .bytecode; - const { upPostDeploymentModule, LinkedContractsFactory } = + const { upPostDeploymentModule, LSP23LinkedContractsFactory } = await deployImplementationContracts(); // universalProfileCreationCode = universalProfileBytecode + abi encoded address of upInitPostDeploymentModule @@ -29,13 +29,14 @@ describe('UniversalProfileDeployer', function () { const salt = ethers.utils.randomBytes(32); - const primaryContractDeployment: LinkedContractsFactory.PrimaryContractDeploymentStruct = { - salt, - fundingAmount: 0, - creationBytecode: universalProfileCreationCode, - }; + const primaryContractDeployment: LSP23LinkedContractsFactory.PrimaryContractDeploymentStruct = + { + salt, + fundingAmount: 0, + creationBytecode: universalProfileCreationCode, + }; - const secondaryContractDeployment: LinkedContractsFactory.SecondaryContractDeploymentInitStruct = + const secondaryContractDeployment: LSP23LinkedContractsFactory.SecondaryContractDeploymentInitStruct = { fundingAmount: 0, creationBytecode: keyManagerBytecode, @@ -88,7 +89,7 @@ describe('UniversalProfileDeployer', function () { // get the address of the UP and the KeyManager contracts const [upContract, keyManagerContract] = - await LinkedContractsFactory.callStatic.deployContracts( + await LSP23LinkedContractsFactory.callStatic.deployContracts( primaryContractDeployment, secondaryContractDeployment, upPostDeploymentModule.address, @@ -96,7 +97,7 @@ describe('UniversalProfileDeployer', function () { ); /* deploying gives a gas error while static calls work fine */ - // await LinkedContractsFactory.deployContracts( + // await LSP23LinkedContractsFactory.deployContracts( // primaryContractDeployment, // secondaryContractDeployment, // ethers.constants.AddressZero, @@ -104,7 +105,7 @@ describe('UniversalProfileDeployer', function () { // ); const [expectedUpAddress, expectedKeyManagerAddress] = - await LinkedContractsFactory.computeAddresses( + await LSP23LinkedContractsFactory.computeAddresses( primaryContractDeployment, secondaryContractDeployment, upPostDeploymentModule.address, @@ -124,7 +125,7 @@ describe('UniversalProfileDeployer', function () { const universalProfileBytecode = (await ethers.getContractFactory('UniversalProfile')) .bytecode; - const { upPostDeploymentModule, LinkedContractsFactory } = + const { upPostDeploymentModule, LSP23LinkedContractsFactory } = await deployImplementationContracts(); // universalProfileCreationCode = universalProfileBytecode + abi encoded address of upInitPostDeploymentModule @@ -134,13 +135,14 @@ describe('UniversalProfileDeployer', function () { const salt = ethers.utils.randomBytes(32); - const primaryContractDeployment: LinkedContractsFactory.PrimaryContractDeploymentStruct = { - salt, - fundingAmount: universalProfileFundAmount, - creationBytecode: universalProfileCreationCode, - }; + const primaryContractDeployment: LSP23LinkedContractsFactory.PrimaryContractDeploymentStruct = + { + salt, + fundingAmount: universalProfileFundAmount, + creationBytecode: universalProfileCreationCode, + }; - const secondaryContractDeployment: LinkedContractsFactory.SecondaryContractDeploymentInitStruct = + const secondaryContractDeployment: LSP23LinkedContractsFactory.SecondaryContractDeploymentInitStruct = { fundingAmount: 0, creationBytecode: keyManagerBytecode, @@ -193,7 +195,7 @@ describe('UniversalProfileDeployer', function () { // get the address of the UP and the KeyManager contracts const [upContract, keyManagerContract] = - await LinkedContractsFactory.callStatic.deployContracts( + await LSP23LinkedContractsFactory.callStatic.deployContracts( primaryContractDeployment, secondaryContractDeployment, upPostDeploymentModule.address, @@ -202,7 +204,7 @@ describe('UniversalProfileDeployer', function () { ); /* deploying gives a gas error while static calls work fine */ - // await LinkedContractsFactory.deployContracts( + // await LSP23LinkedContractsFactory.deployContracts( // primaryContractDeployment, // secondaryContractDeployment, // ethers.constants.AddressZero, @@ -210,7 +212,7 @@ describe('UniversalProfileDeployer', function () { // ); const [expectedUpAddress, expectedKeyManagerAddress] = - await LinkedContractsFactory.computeAddresses( + await LSP23LinkedContractsFactory.computeAddresses( primaryContractDeployment, secondaryContractDeployment, upPostDeploymentModule.address, @@ -230,7 +232,7 @@ describe('UniversalProfileDeployer', function () { const universalProfileBytecode = (await ethers.getContractFactory('UniversalProfile')) .bytecode; - const { upPostDeploymentModule, LinkedContractsFactory } = + const { upPostDeploymentModule, LSP23LinkedContractsFactory } = await deployImplementationContracts(); // universalProfileCreationCode = universalProfileBytecode + abi encoded address of upInitPostDeploymentModule @@ -240,13 +242,14 @@ describe('UniversalProfileDeployer', function () { const salt = ethers.utils.randomBytes(32); - const primaryContractDeployment: LinkedContractsFactory.PrimaryContractDeploymentStruct = { - salt, - fundingAmount: universalProfileFundAmount, - creationBytecode: universalProfileCreationCode, - }; + const primaryContractDeployment: LSP23LinkedContractsFactory.PrimaryContractDeploymentStruct = + { + salt, + fundingAmount: universalProfileFundAmount, + creationBytecode: universalProfileCreationCode, + }; - const secondaryContractDeployment: LinkedContractsFactory.SecondaryContractDeploymentInitStruct = + const secondaryContractDeployment: LSP23LinkedContractsFactory.SecondaryContractDeploymentInitStruct = { fundingAmount: 0, creationBytecode: keyManagerBytecode, @@ -299,14 +302,14 @@ describe('UniversalProfileDeployer', function () { // get the address of the UP and the KeyManager contracts await expect( - LinkedContractsFactory.callStatic.deployContracts( + LSP23LinkedContractsFactory.callStatic.deployContracts( primaryContractDeployment, secondaryContractDeployment, upPostDeploymentModule.address, encodedBytes, { value: universalProfileFundAmount.add(ethers.utils.parseEther('0.1')) }, ), - ).to.be.revertedWithCustomError(LinkedContractsFactory, 'InvalidValueSum'); + ).to.be.revertedWithCustomError(LSP23LinkedContractsFactory, 'InvalidValueSum'); }); }); describe('for proxies deployment', function () { @@ -316,7 +319,7 @@ describe('UniversalProfileDeployer', function () { const { keyManagerInit, universalProfileInit, - LinkedContractsFactory, + LSP23LinkedContractsFactory, upInitPostDeploymentModule, UniversalProfileInitFactory, KeyManagerInitFactory, @@ -324,7 +327,7 @@ describe('UniversalProfileDeployer', function () { const salt = ethers.utils.randomBytes(32); - const primaryContractDeploymentInit: LinkedContractsFactory.PrimaryContractDeploymentInitStruct = + const primaryContractDeploymentInit: LSP23LinkedContractsFactory.PrimaryContractDeploymentInitStruct = { salt, fundingAmount: 0, @@ -334,7 +337,7 @@ describe('UniversalProfileDeployer', function () { ]), }; - const secondaryContractDeploymentInit: LinkedContractsFactory.SecondaryContractDeploymentInitStruct = + const secondaryContractDeploymentInit: LSP23LinkedContractsFactory.SecondaryContractDeploymentInitStruct = { fundingAmount: 0, implementationContract: keyManagerInit.address, @@ -388,14 +391,14 @@ describe('UniversalProfileDeployer', function () { // get the address of the UP and the KeyManager contracts const [upAddress, keyManagerAddress] = - await LinkedContractsFactory.callStatic.deployERC1167Proxies( + await LSP23LinkedContractsFactory.callStatic.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, encodedBytes, ); - await LinkedContractsFactory.deployERC1167Proxies( + await LSP23LinkedContractsFactory.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -409,7 +412,7 @@ describe('UniversalProfileDeployer', function () { const keyManagerProxyOwner = await keyManagerProxy.target(); const [expectedUpProxyAddress, expectedKeyManagerProxyAddress] = - await LinkedContractsFactory.computeERC1167Addresses( + await LSP23LinkedContractsFactory.computeERC1167Addresses( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -425,7 +428,7 @@ describe('UniversalProfileDeployer', function () { secondaryContractDeploymentInit.extraInitializationParams, upInitPostDeploymentModule.address, encodedBytes, - LinkedContractsFactory.address, + LSP23LinkedContractsFactory.address, ); expect(upAddress).to.equal(expectedUpProxyAddress); @@ -446,7 +449,7 @@ describe('UniversalProfileDeployer', function () { const secondaryFundingAmount = ethers.utils.parseEther('1'); const { - LinkedContractsFactory, + LSP23LinkedContractsFactory, upInitPostDeploymentModule, universalProfileInit, keyManagerInit, @@ -454,7 +457,7 @@ describe('UniversalProfileDeployer', function () { const salt = ethers.utils.randomBytes(32); - const primaryContractDeploymentInit: LinkedContractsFactory.PrimaryContractDeploymentInitStruct = + const primaryContractDeploymentInit: LSP23LinkedContractsFactory.PrimaryContractDeploymentInitStruct = { salt, fundingAmount: primaryFundingAmount, @@ -464,7 +467,7 @@ describe('UniversalProfileDeployer', function () { ]), }; - const secondaryContractDeploymentInit: LinkedContractsFactory.SecondaryContractDeploymentInitStruct = + const secondaryContractDeploymentInit: LSP23LinkedContractsFactory.SecondaryContractDeploymentInitStruct = { fundingAmount: secondaryFundingAmount, implementationContract: keyManagerInit.address, @@ -485,18 +488,18 @@ describe('UniversalProfileDeployer', function () { ]); await expect( - LinkedContractsFactory.deployERC1167Proxies( + LSP23LinkedContractsFactory.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, encodedBytes, { value: primaryFundingAmount }, // Only sending primary funding amount ), - ).to.be.revertedWithCustomError(LinkedContractsFactory, 'InvalidValueSum'); + ).to.be.revertedWithCustomError(LSP23LinkedContractsFactory, 'InvalidValueSum'); // Sending more than required await expect( - LinkedContractsFactory.deployERC1167Proxies( + LSP23LinkedContractsFactory.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -507,11 +510,11 @@ describe('UniversalProfileDeployer', function () { .add(ethers.utils.parseEther('0.1')), }, // Sending extra 0.1 ETH ), - ).to.be.revertedWithCustomError(LinkedContractsFactory, 'InvalidValueSum'); + ).to.be.revertedWithCustomError(LSP23LinkedContractsFactory, 'InvalidValueSum'); }); it('should successfully deploy primary and secondary proxies with the correct values', async function () { const { - LinkedContractsFactory, + LSP23LinkedContractsFactory, upInitPostDeploymentModule, universalProfileInit, keyManagerInit, @@ -521,7 +524,7 @@ describe('UniversalProfileDeployer', function () { const primaryFundingAmount = ethers.utils.parseEther('1'); const secondaryFundingAmount = ethers.utils.parseEther('0'); // key manager does not accept funds - const primaryContractDeploymentInit: LinkedContractsFactory.PrimaryContractDeploymentInitStruct = + const primaryContractDeploymentInit: LSP23LinkedContractsFactory.PrimaryContractDeploymentInitStruct = { salt, fundingAmount: primaryFundingAmount, @@ -531,7 +534,7 @@ describe('UniversalProfileDeployer', function () { ]), }; - const secondaryContractDeploymentInit: LinkedContractsFactory.SecondaryContractDeploymentInitStruct = + const secondaryContractDeploymentInit: LSP23LinkedContractsFactory.SecondaryContractDeploymentInitStruct = { fundingAmount: secondaryFundingAmount, implementationContract: keyManagerInit.address, @@ -547,7 +550,7 @@ describe('UniversalProfileDeployer', function () { ]); const [primaryAddress, secondaryAddress] = - await LinkedContractsFactory.callStatic.deployERC1167Proxies( + await LSP23LinkedContractsFactory.callStatic.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -555,7 +558,7 @@ describe('UniversalProfileDeployer', function () { { value: primaryFundingAmount.add(secondaryFundingAmount) }, ); - await LinkedContractsFactory.deployERC1167Proxies( + await LSP23LinkedContractsFactory.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -574,7 +577,7 @@ describe('UniversalProfileDeployer', function () { }); it('should successfully deploy primary and secondary proxies', async function () { const { - LinkedContractsFactory, + LSP23LinkedContractsFactory, upInitPostDeploymentModule, universalProfileInit, keyManagerInit, @@ -608,7 +611,7 @@ describe('UniversalProfileDeployer', function () { ]); const [primaryAddress, secondaryAddress] = - await LinkedContractsFactory.callStatic.deployERC1167Proxies( + await LSP23LinkedContractsFactory.callStatic.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -616,7 +619,7 @@ describe('UniversalProfileDeployer', function () { { value: primaryFundingAmount.add(secondaryFundingAmount) }, ); - await LinkedContractsFactory.callStatic.deployERC1167Proxies( + await LSP23LinkedContractsFactory.callStatic.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -629,7 +632,7 @@ describe('UniversalProfileDeployer', function () { }); it('should emit DeployedERC1167Proxies event with correct parameters', async function () { const { - LinkedContractsFactory, + LSP23LinkedContractsFactory, upInitPostDeploymentModule, universalProfileInit, keyManagerInit, @@ -663,7 +666,7 @@ describe('UniversalProfileDeployer', function () { ]); const [primaryAddress, secondaryAddress] = - await LinkedContractsFactory.callStatic.deployERC1167Proxies( + await LSP23LinkedContractsFactory.callStatic.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -671,7 +674,7 @@ describe('UniversalProfileDeployer', function () { { value: primaryFundingAmount.add(secondaryFundingAmount) }, ); - const tx = await LinkedContractsFactory.deployERC1167Proxies( + const tx = await LSP23LinkedContractsFactory.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -700,7 +703,7 @@ describe('UniversalProfileDeployer', function () { }); it('should revert if trying to deploy twice with the same deployment info', async function () { const { - LinkedContractsFactory, + LSP23LinkedContractsFactory, upInitPostDeploymentModule, universalProfileInit, keyManagerInit, @@ -733,7 +736,7 @@ describe('UniversalProfileDeployer', function () { [ethers.utils.randomBytes(32)], ]); - await LinkedContractsFactory.deployERC1167Proxies( + await LSP23LinkedContractsFactory.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, @@ -742,7 +745,7 @@ describe('UniversalProfileDeployer', function () { ); await expect( - LinkedContractsFactory.deployERC1167Proxies( + LSP23LinkedContractsFactory.deployERC1167Proxies( primaryContractDeploymentInit, secondaryContractDeploymentInit, upInitPostDeploymentModule.address, diff --git a/tests/LSP23LinkedContractsDeployment/helpers.ts b/tests/LSP23LinkedContractsDeployment/helpers.ts index e2b47af56..1c48b9e09 100644 --- a/tests/LSP23LinkedContractsDeployment/helpers.ts +++ b/tests/LSP23LinkedContractsDeployment/helpers.ts @@ -65,8 +65,10 @@ export async function deployImplementationContracts() { const UniversalProfileInitFactory = await ethers.getContractFactory('UniversalProfileInit'); const universalProfileInit = await UniversalProfileInitFactory.deploy(); - const LinkedContractsFactoryFactory = await ethers.getContractFactory('LinkedContractsFactory'); - const LinkedContractsFactory = await LinkedContractsFactoryFactory.deploy(); + const LinkedContractsFactoryFactory = await ethers.getContractFactory( + 'LSP23LinkedContractsFactory', + ); + const LSP23LinkedContractsFactory = await LinkedContractsFactoryFactory.deploy(); const UPPostDeploymentManagerFactory = await ethers.getContractFactory( 'UniversalProfilePostDeploymentModule', @@ -83,7 +85,7 @@ export async function deployImplementationContracts() { KeyManagerInitFactory, universalProfileInit, UniversalProfileInitFactory, - LinkedContractsFactory, + LSP23LinkedContractsFactory, upPostDeploymentModule, upInitPostDeploymentModule, }; From 4bec28576e27d42bdcbedc0dd88abd073568a087 Mon Sep 17 00:00:00 2001 From: maxvia87 Date: Mon, 14 Aug 2023 11:24:09 +0200 Subject: [PATCH 2/4] chore: add lsp23 to hardhat.config --- hardhat.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 9d69635e0..671f999c5 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -150,7 +150,7 @@ const config: HardhatUserConfig = { // ------------------ 'Create2Factory', 'LSP16UniversalFactory', - 'LinkedContractsFactory', + 'LSP23LinkedContractsFactory', ], // Whether to include the TypeChain factories or not. // If this is enabled, you need to run the TypeChain files through the TypeScript compiler before shipping to the registry. From 66655acb7001e05984557f4a02fc986bf30df0ea Mon Sep 17 00:00:00 2001 From: CJ42 Date: Mon, 14 Aug 2023 11:01:43 +0100 Subject: [PATCH 3/4] test: resolve LSP23 gas issue on test deployment --- ...iversalProfileInitPostDeploymentModule.sol | 6 ++- .../UniversalProfilePostDeploymentModule.sol | 6 ++- .../LSP23LinkedContractsDeployment.test.ts | 43 +++++++++++++------ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfileInitPostDeploymentModule.sol b/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfileInitPostDeploymentModule.sol index bb6d4408c..90a905181 100644 --- a/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfileInitPostDeploymentModule.sol +++ b/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfileInitPostDeploymentModule.sol @@ -1,6 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; +import { + OPERATION_4_DELEGATECALL +} from "@erc725/smart-contracts/contracts/constants.sol"; + import {UniversalProfileInit} from "../../UniversalProfileInit.sol"; contract UniversalProfileInitPostDeploymentModule is UniversalProfileInit { @@ -45,7 +49,7 @@ contract UniversalProfileInitPostDeploymentModule is UniversalProfileInit { // call the execute function with delegate_call on the universalProfile contract to setData and transferOwnership UniversalProfileInit(payable(universalProfile)).execute( - 4, + OPERATION_4_DELEGATECALL, address(this), 0, abi.encodeWithSignature( diff --git a/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfilePostDeploymentModule.sol b/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfilePostDeploymentModule.sol index 2f4a7633a..5baf9566d 100644 --- a/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfilePostDeploymentModule.sol +++ b/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfilePostDeploymentModule.sol @@ -1,6 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; +import { + OPERATION_4_DELEGATECALL +} from "@erc725/smart-contracts/contracts/constants.sol"; + import {UniversalProfile} from "../../UniversalProfile.sol"; contract UniversalProfilePostDeploymentModule is UniversalProfile { @@ -43,7 +47,7 @@ contract UniversalProfilePostDeploymentModule is UniversalProfile { // call the execute function with delegate_call on the universalProfile contract to setData and transferOwnership UniversalProfile(payable(universalProfile)).execute( - 4, + OPERATION_4_DELEGATECALL, address(this), 0, abi.encodeWithSignature( diff --git a/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts b/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts index 0276e8018..4ec0e454b 100644 --- a/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts +++ b/tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts @@ -1,7 +1,11 @@ import { ethers } from 'hardhat'; import { expect } from 'chai'; -import { LSP23LinkedContractsFactory } from '../../typechain-types'; +import { + LSP23LinkedContractsFactory, + LSP6KeyManager, + UniversalProfile, +} from '../../typechain-types'; import { ERC725YDataKeys } from '../../constants'; import { calculateProxiesAddresses, @@ -15,9 +19,11 @@ describe('UniversalProfileDeployer', function () { it('should deploy both contract (with no value)', async function () { const [allPermissionsSigner, universalReceiver, recoverySigner] = await ethers.getSigners(); - const keyManagerBytecode = (await ethers.getContractFactory('LSP6KeyManager')).bytecode; - const universalProfileBytecode = (await ethers.getContractFactory('UniversalProfile')) - .bytecode; + const KeyManagerFactory = await ethers.getContractFactory('LSP6KeyManager'); + const UniversalProfileFactory = await ethers.getContractFactory('UniversalProfile'); + + const keyManagerBytecode = KeyManagerFactory.bytecode; + const universalProfileBytecode = UniversalProfileFactory.bytecode; const { upPostDeploymentModule, LSP23LinkedContractsFactory } = await deployImplementationContracts(); @@ -96,13 +102,17 @@ describe('UniversalProfileDeployer', function () { encodedBytes, ); - /* deploying gives a gas error while static calls work fine */ - // await LSP23LinkedContractsFactory.deployContracts( - // primaryContractDeployment, - // secondaryContractDeployment, - // ethers.constants.AddressZero, - // '0x', - // ); + await LSP23LinkedContractsFactory.deployContracts( + primaryContractDeployment, + secondaryContractDeployment, + upPostDeploymentModule.address, + encodedBytes, + { + // Need to specify gasLimit, otherwise Hardhat reverts strangely with the following error: + // InvalidInputError: Transaction gas limit is 30915224 and exceeds block gas limit of 30000000 + gasLimit: 30_000_000, + }, + ); const [expectedUpAddress, expectedKeyManagerAddress] = await LSP23LinkedContractsFactory.computeAddresses( @@ -113,9 +123,18 @@ describe('UniversalProfileDeployer', function () { ); expect(upContract).to.equal(expectedUpAddress); - expect(keyManagerContract).to.equal(expectedKeyManagerAddress); + + const keyManagerInstance: LSP6KeyManager = KeyManagerFactory.attach(keyManagerContract); + const universalProfileInstance: UniversalProfile = UniversalProfileFactory.attach(upContract); + + // CHECK that the UP is owned by the KeyManager contract + expect(await universalProfileInstance.owner()).to.equal(keyManagerContract); + + // CHECK that the `target()` of the KeyManager contract is the UP contract + expect(await keyManagerInstance.target()).to.equal(upContract); }); + it('should deploy both contract (with value)', async function () { const [allPermissionsSigner, universalReceiver, recoverySigner] = await ethers.getSigners(); From cfac2b620f837fc5a5ffded5db2b6df1c10e28ca Mon Sep 17 00:00:00 2001 From: maxvia87 Date: Tue, 15 Aug 2023 10:53:32 +0200 Subject: [PATCH 4/4] docs: generate docs for lsp23 --- .../LSP23LinkedContractsFactory.md | 373 ++++++++++++++++++ dodoc/config.ts | 1 + 2 files changed, 374 insertions(+) create mode 100644 docs/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.md diff --git a/docs/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.md b/docs/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.md new file mode 100644 index 000000000..a40a8e15a --- /dev/null +++ b/docs/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.md @@ -0,0 +1,373 @@ + + + +# LSP23LinkedContractsFactory + +:::info Standard Specifications + +[`LSP-23-LinkedContractsDeployment`](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md) + +::: +:::info Solidity implementation + +[`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) + +::: + +## Public Methods + +Public methods are accessible externally from users, allowing interaction with this function from dApps or other smart contracts. +When marked as 'public', a method can be called both externally and internally, on the other hand, when marked as 'external', a method can only be called externally. + +### computeAddresses + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#computeaddresses) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Function signature: `computeAddresses(ILSP23LinkedContractsFactory.PrimaryContractDeployment,ILSP23LinkedContractsFactory.SecondaryContractDeployment,address,bytes)` +- Function selector: `0xdecfb0b9` + +::: + +```solidity +function computeAddresses( + ILSP23LinkedContractsFactory.PrimaryContractDeployment primaryContractDeployment, + ILSP23LinkedContractsFactory.SecondaryContractDeployment secondaryContractDeployment, + address postDeploymentModule, + bytes postDeploymentModuleCalldata +) + external + view + returns (address primaryContractAddress, address secondaryContractAddress); +``` + +#### Parameters + +| Name | Type | Description | +| ------------------------------ | :--------------------------------------------------------: | ----------- | +| `primaryContractDeployment` | `ILSP23LinkedContractsFactory.PrimaryContractDeployment` | - | +| `secondaryContractDeployment` | `ILSP23LinkedContractsFactory.SecondaryContractDeployment` | - | +| `postDeploymentModule` | `address` | - | +| `postDeploymentModuleCalldata` | `bytes` | - | + +#### Returns + +| Name | Type | Description | +| -------------------------- | :-------: | ----------- | +| `primaryContractAddress` | `address` | - | +| `secondaryContractAddress` | `address` | - | + +
+ +### computeERC1167Addresses + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#computeerc1167addresses) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Function signature: `computeERC1167Addresses(ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit,ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit,address,bytes)` +- Function selector: `0x8da85898` + +::: + +```solidity +function computeERC1167Addresses( + ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit primaryContractDeploymentInit, + ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit secondaryContractDeploymentInit, + address postDeploymentModule, + bytes postDeploymentModuleCalldata +) + external + view + returns (address primaryContractAddress, address secondaryContractAddress); +``` + +#### Parameters + +| Name | Type | Description | +| --------------------------------- | :------------------------------------------------------------: | ----------- | +| `primaryContractDeploymentInit` | `ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit` | - | +| `secondaryContractDeploymentInit` | `ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit` | - | +| `postDeploymentModule` | `address` | - | +| `postDeploymentModuleCalldata` | `bytes` | - | + +#### Returns + +| Name | Type | Description | +| -------------------------- | :-------: | ----------- | +| `primaryContractAddress` | `address` | - | +| `secondaryContractAddress` | `address` | - | + +
+ +### deployContracts + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#deploycontracts) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Function signature: `deployContracts(ILSP23LinkedContractsFactory.PrimaryContractDeployment,ILSP23LinkedContractsFactory.SecondaryContractDeployment,address,bytes)` +- Function selector: `0xf830c0ab` + +::: + +```solidity +function deployContracts( + ILSP23LinkedContractsFactory.PrimaryContractDeployment primaryContractDeployment, + ILSP23LinkedContractsFactory.SecondaryContractDeployment secondaryContractDeployment, + address postDeploymentModule, + bytes postDeploymentModuleCalldata +) + external + payable + returns (address primaryContractAddress, address secondaryContractAddress); +``` + +#### Parameters + +| Name | Type | Description | +| ------------------------------ | :--------------------------------------------------------: | ----------- | +| `primaryContractDeployment` | `ILSP23LinkedContractsFactory.PrimaryContractDeployment` | - | +| `secondaryContractDeployment` | `ILSP23LinkedContractsFactory.SecondaryContractDeployment` | - | +| `postDeploymentModule` | `address` | - | +| `postDeploymentModuleCalldata` | `bytes` | - | + +#### Returns + +| Name | Type | Description | +| -------------------------- | :-------: | ----------- | +| `primaryContractAddress` | `address` | - | +| `secondaryContractAddress` | `address` | - | + +
+ +### deployERC1167Proxies + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#deployerc1167proxies) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Function signature: `deployERC1167Proxies(ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit,ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit,address,bytes)` +- Function selector: `0x17c042c4` + +::: + +```solidity +function deployERC1167Proxies( + ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit primaryContractDeploymentInit, + ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit secondaryContractDeploymentInit, + address postDeploymentModule, + bytes postDeploymentModuleCalldata +) + external + payable + returns (address primaryContractAddress, address secondaryContractAddress); +``` + +#### Parameters + +| Name | Type | Description | +| --------------------------------- | :------------------------------------------------------------: | ----------- | +| `primaryContractDeploymentInit` | `ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit` | - | +| `secondaryContractDeploymentInit` | `ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit` | - | +| `postDeploymentModule` | `address` | - | +| `postDeploymentModuleCalldata` | `bytes` | - | + +#### Returns + +| Name | Type | Description | +| -------------------------- | :-------: | ----------- | +| `primaryContractAddress` | `address` | - | +| `secondaryContractAddress` | `address` | - | + +
+ +## Internal Methods + +Any method labeled as `internal` serves as utility function within the contract. They can be used when writing solidity contracts that inherit from this contract. These methods can be extended or modified by overriding their internal behavior to suit specific needs. + +Internal functions cannot be called externally, whether from other smart contracts, dApp interfaces, or backend services. Their restricted accessibility ensures that they remain exclusively available within the context of the current contract, promoting controlled and encapsulated usage of these internal utilities. + +### \_deployPrimaryContract + +```solidity +function _deployPrimaryContract(struct ILSP23LinkedContractsFactory.PrimaryContractDeployment primaryContractDeployment, struct ILSP23LinkedContractsFactory.SecondaryContractDeployment secondaryContractDeployment, address postDeploymentModule, bytes postDeploymentModuleCalldata) internal nonpayable returns (address primaryContractAddress); +``` + +
+ +### \_deploySecondaryContract + +```solidity +function _deploySecondaryContract(struct ILSP23LinkedContractsFactory.SecondaryContractDeployment secondaryContractDeployment, address primaryContractAddress) internal nonpayable returns (address secondaryContractAddress); +``` + +
+ +### \_deployAndInitializePrimaryContractProxy + +```solidity +function _deployAndInitializePrimaryContractProxy(struct ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit primaryContractDeploymentInit, struct ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit secondaryContractDeploymentInit, address postDeploymentModule, bytes postDeploymentModuleCalldata) internal nonpayable returns (address primaryContractAddress); +``` + +
+ +### \_deployAndInitializeSecondaryContractProxy + +```solidity +function _deployAndInitializeSecondaryContractProxy(struct ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit secondaryContractDeploymentInit, address primaryContractAddress) internal nonpayable returns (address secondaryContractAddress); +``` + +
+ +### \_generatePrimaryContractSalt + +```solidity +function _generatePrimaryContractSalt(struct ILSP23LinkedContractsFactory.PrimaryContractDeployment primaryContractDeployment, struct ILSP23LinkedContractsFactory.SecondaryContractDeployment secondaryContractDeployment, address postDeploymentModule, bytes postDeploymentModuleCalldata) internal pure returns (bytes32 primaryContractGeneratedSalt); +``` + +
+ +### \_generatePrimaryContractProxySalt + +```solidity +function _generatePrimaryContractProxySalt(struct ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit primaryContractDeploymentInit, struct ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit secondaryContractDeploymentInit, address postDeploymentModule, bytes postDeploymentModuleCalldata) internal pure returns (bytes32 primaryContractProxyGeneratedSalt); +``` + +
+ +## Events + +### DeployedContracts + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#deployedcontracts) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Event signature: `DeployedContracts(address,address,ILSP23LinkedContractsFactory.PrimaryContractDeployment,ILSP23LinkedContractsFactory.SecondaryContractDeployment,address,bytes)` +- Event topic hash: `0x1ea27dabd8fd1508e844ab51c2fd3d9081f2684346857f9187da6d4a1aa7d3e6` + +::: + +```solidity +event DeployedContracts(address indexed primaryContract, address indexed secondaryContract, ILSP23LinkedContractsFactory.PrimaryContractDeployment primaryContractDeployment, ILSP23LinkedContractsFactory.SecondaryContractDeployment secondaryContractDeployment, address postDeploymentModule, bytes postDeploymentModuleCalldata); +``` + +#### Parameters + +| Name | Type | Description | +| --------------------------------- | :--------------------------------------------------------: | ----------- | +| `primaryContract` **`indexed`** | `address` | - | +| `secondaryContract` **`indexed`** | `address` | - | +| `primaryContractDeployment` | `ILSP23LinkedContractsFactory.PrimaryContractDeployment` | - | +| `secondaryContractDeployment` | `ILSP23LinkedContractsFactory.SecondaryContractDeployment` | - | +| `postDeploymentModule` | `address` | - | +| `postDeploymentModuleCalldata` | `bytes` | - | + +
+ +### DeployedERC1167Proxies + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#deployederc1167proxies) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Event signature: `DeployedERC1167Proxies(address,address,ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit,ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit,address,bytes)` +- Event topic hash: `0xb03dbe7a02c063899f863d542410b5b038c8f537045be3a26e7144e0074e1c7b` + +::: + +```solidity +event DeployedERC1167Proxies(address indexed primaryContract, address indexed secondaryContract, ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit primaryContractDeploymentInit, ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit secondaryContractDeploymentInit, address postDeploymentModule, bytes postDeploymentModuleCalldata); +``` + +#### Parameters + +| Name | Type | Description | +| --------------------------------- | :------------------------------------------------------------: | ----------- | +| `primaryContract` **`indexed`** | `address` | - | +| `secondaryContract` **`indexed`** | `address` | - | +| `primaryContractDeploymentInit` | `ILSP23LinkedContractsFactory.PrimaryContractDeploymentInit` | - | +| `secondaryContractDeploymentInit` | `ILSP23LinkedContractsFactory.SecondaryContractDeploymentInit` | - | +| `postDeploymentModule` | `address` | - | +| `postDeploymentModuleCalldata` | `bytes` | - | + +
+ +## Errors + +### InvalidValueSum + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#invalidvaluesum) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Error signature: `InvalidValueSum()` +- Error hash: `0x2fd9ca91` + +::: + +```solidity +error InvalidValueSum(); +``` + +_Invalid value sent._ + +Reverts when the `msg.value` sent is not equal to the sum of value used for the deployment of the contract & its owner contract. + +
+ +### PrimaryContractProxyInitFailureError + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#primarycontractproxyinitfailureerror) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Error signature: `PrimaryContractProxyInitFailureError(bytes)` +- Error hash: `0x4364b6ee` + +::: + +```solidity +error PrimaryContractProxyInitFailureError(bytes errorData); +``` + +_Failed to deploy & initialise the Primary Contract Proxy. Error: `errorData`._ + +Reverts when the deployment & intialisation of the contract has failed. + +#### Parameters + +| Name | Type | Description | +| ----------- | :-----: | ----------------------------------------------------------------------------- | +| `errorData` | `bytes` | Potentially information about why the deployment & intialisation have failed. | + +
+ +### SecondaryContractProxyInitFailureError + +:::note References + +- Specification details: [**LSP-23-LinkedContractsDeployment**](https://github.com/lukso-network/lips/tree/main/LSPs/LSP-23-LinkedContractsDeployment.md#secondarycontractproxyinitfailureerror) +- Solidity implementation: [`LSP23LinkedContractsFactory.sol`](https://github.com/lukso-network/lsp-smart-contracts/blob/develop/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol) +- Error signature: `SecondaryContractProxyInitFailureError(bytes)` +- Error hash: `0x9654a854` + +::: + +```solidity +error SecondaryContractProxyInitFailureError(bytes errorData); +``` + +_Failed to deploy & initialise the Secondary Contract Proxy. Error: `errorData`._ + +Reverts when the deployment & intialisation of the secondary contract has failed. + +#### Parameters + +| Name | Type | Description | +| ----------- | :-----: | ----------------------------------------------------------------------------- | +| `errorData` | `bytes` | Potentially information about why the deployment & intialisation have failed. | + +
diff --git a/dodoc/config.ts b/dodoc/config.ts index 6630bdeda..254dc7214 100644 --- a/dodoc/config.ts +++ b/dodoc/config.ts @@ -16,6 +16,7 @@ export const dodocConfig = { 'contracts/LSP17ContractExtension/LSP17Extendable.sol', 'contracts/LSP17ContractExtension/LSP17Extension.sol', 'contracts/LSP20CallVerification/LSP20CallVerification.sol', + 'contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol', // tokens 'contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol',