Skip to content

Commit

Permalink
build!: move lsp16 to its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
YamenMerhi committed Feb 6, 2024
1 parent c6f4f99 commit 69ec255
Show file tree
Hide file tree
Showing 22 changed files with 1,440 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dodoc/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const dodocConfig = {
'contracts/LSP9Vault/LSP9Vault.sol',
'contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol',
'lsp14/contracts/LSP14Ownable2Step.sol',
'contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol',
'lsp16/contracts/LSP16UniversalFactory.sol',
'lsp17contractextension/contracts/LSP17Extendable.sol',
'lsp17contractextension/contracts/LSP17Extension.sol',
'lsp17/Extension4337.sol',
Expand Down
5 changes: 5 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ out = 'packages/LSP2ERC725YJSONSchema/contracts/foundry_artifacts'
src = 'packages/LSP6KeyManager/contracts'
test = 'packages/LSP6KeyManager/foundry'
out = 'packages/LSP6KeyManager/contracts/foundry_artifacts'

[profile.lsp16]
src = 'packages/LSP16UniversalFactory/contracts'
test = 'packages/LSP16UniversalFactory/foundry'
out = 'packages/LSP16UniversalFactory/contracts/foundry_artifacts'
1 change: 0 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ const config: HardhatUserConfig = {
// Tools
// ------------------
'Create2Factory',
'LSP16UniversalFactory',
'LSP23LinkedContractsFactory',
],
// Whether to include the TypeChain factories or not.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"lsp7": "*",
"lsp10": "*",
"lsp14": "*",
"lsp16": "*",
"lsp17": "*",
"lsp17contractextension": "*",
"lsp20": "*",
Expand Down
4 changes: 4 additions & 0 deletions packages/LSP16UniversalFactory/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom'],
};
25 changes: 25 additions & 0 deletions packages/LSP16UniversalFactory/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "solhint:recommended",
"rules": {
"avoid-sha3": "error",
"avoid-suicide": "error",
"avoid-throw": "error",
"avoid-tx-origin": "error",
"check-send-result": "error",
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"not-rely-on-block-hash": "error",
"not-rely-on-time": "error",
"reentrancy": "error",
"constructor-syntax": "error",
"private-vars-leading-underscore": ["error", { "strict": false }],
"imports-on-top": "error",
"visibility-modifier-order": "error",
"no-unused-import": "error",
"no-global-import": "error",
"reason-string": ["warn", { "maxLength": 120 }],
"avoid-low-level-calls": "off",
"no-empty-blocks": ["error", { "ignoreConstructors": true }],
"custom-errors": "off"
}
}
3 changes: 3 additions & 0 deletions packages/LSP16UniversalFactory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LSP16 Universal Factory

Package for the [LSP16-UniversalFactory](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-16-UniversalFactory.md) standard, contains a contract that allows deploying contracts on multiple chains with the same address.
9 changes: 9 additions & 0 deletions packages/LSP16UniversalFactory/contracts/Mock/Account.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

import {ERC725} from "@erc725/smart-contracts/contracts/ERC725.sol";

contract Account is ERC725 {
// solhint-disable-next-line no-empty-blocks
constructor(address contractOwner) ERC725(contractOwner) {}
}
13 changes: 13 additions & 0 deletions packages/LSP16UniversalFactory/contracts/Mock/AccountInit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

import {
ERC725InitAbstract
} from "@erc725/smart-contracts/contracts/ERC725InitAbstract.sol";

// solhint-disable-next-line no-empty-blocks
contract AccountInit is ERC725InitAbstract {
function initialize(address newOwner) public virtual initializer {
ERC725InitAbstract._initialize(newOwner);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

contract ContractNoConstructor {
uint256 private _number = 5;

function getNumber() public view returns (uint256) {
return _number;
}

function setNumber(uint256 newNumber) public {
_number = newNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

/**
* @dev sample contract used for testing
*/
contract FallbackInitializer {
address public caller;

receive() external payable {
_initialize();
}

fallback() external payable {
_initialize();
}

function _initialize() internal {
caller = msg.sender;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

import {
Initializable
} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract ImplementationTester is Initializable {
address private _owner;

function initialize(address newOwner) public virtual initializer {
_owner = newOwner;
}

function owner() public view virtual returns (address) {
return _owner;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

contract NonPayableContract {
address private _owner;

constructor(address newOwner) {
_owner = newOwner;
}

function getOwner() public view returns (address) {
return _owner;
}
}
16 changes: 16 additions & 0 deletions packages/LSP16UniversalFactory/contracts/Mock/PayableContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

/**
* @dev sample contract used for testing
*/
contract PayableContract {
// solhint-disable no-empty-blocks
constructor() payable {}

// solhint-disable no-empty-blocks
function payableTrue() public payable {}

// solhint-disable no-empty-blocks
function payableFalse() public {}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import "forge-std/console.sol";

import {Address} from "@openzeppelin/contracts/utils/Address.sol";

import "../../../contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol";
import "../../../contracts/Mocks/NonPayableFallback.sol";
import "../../../contracts/Mocks/FallbackInitializer.sol";
import "lsp0/contracts/LSP0ERC725Account.sol";
import "lsp0/contracts/LSP0ERC725AccountInit.sol";
import {LSP16UniversalFactory} from "../contracts/LSP16UniversalFactory.sol";
import {
NonPayableFallback
} from "../../../contracts/Mocks/NonPayableFallback.sol";
import {
FallbackInitializer
} from "../../../contracts/Mocks/FallbackInitializer.sol";
import {Account} from "../contracts/Mocks/Account.sol";
import {AccountInit} from "../contracts/Mocks/AccountInit.sol";

contract LSP16UniversalProfileTest is Test {
LSP16UniversalFactory public lsp16;
NonPayableFallback public nonPayableFallbackContract;
FallbackInitializer public fallbackInitializer;
LSP0ERC725Account public lsp0;
LSP0ERC725AccountInit public lsp0Init;

Account public account;
AccountInit public accountInit;

bytes public nonPayableFallbackBytecode =
type(NonPayableFallback).creationCode;
Expand All @@ -35,8 +40,9 @@ contract LSP16UniversalProfileTest is Test {

nonPayableFallbackContract = new NonPayableFallback();
fallbackInitializer = new FallbackInitializer();
lsp0Init = new LSP0ERC725AccountInit();
lsp0 = new LSP0ERC725Account(address(20));

account = new Account(address(20));
accountInit = new AccountInit();

uniqueInitializableSalt = lsp16.generateSalt(
randomBytes32ForSalt,
Expand Down Expand Up @@ -103,13 +109,13 @@ contract LSP16UniversalProfileTest is Test {
assert(salt != uniqueInitializableSalt);
}

function testdeployERC1167ProxyWithUPInit() public {
function testdeployERC1167ProxyWithAccountInit() public {
bytes32 salt = lsp16.generateSalt(bytes32(++testCounter), false, "");

(bool success, bytes memory returnData) = address(lsp16).call(
abi.encodeWithSignature(
"deployERC1167Proxy(address,bytes32)",
address(lsp0Init),
address(accountInit),
salt
)
);
Expand All @@ -120,7 +126,7 @@ contract LSP16UniversalProfileTest is Test {
);
}

function testdeployERC1167ProxyAndInitializeShouldNotKeepValueWithUPInit(
function testdeployERC1167ProxyAndInitializeShouldNotKeepValueWithAccountInit(
uint256 valueToTransfer,
bytes memory initializeCalldata
) public {
Expand All @@ -143,7 +149,7 @@ contract LSP16UniversalProfileTest is Test {
}(
abi.encodeWithSignature(
"deployERC1167ProxyAndInitialize(address,bytes32,bytes)",
address(lsp0Init),
address(accountInit),
salt,
lsp0Initbytes
)
Expand All @@ -156,7 +162,7 @@ contract LSP16UniversalProfileTest is Test {
assert(address(lsp16).balance == 0);
}

function testDeployCreate2ShouldNotKeepValueWithUP(
function testDeployCreate2ShouldNotKeepValueWithAccount(
uint256 valueToTransfer
) public {
vm.deal(address(this), valueToTransfer);
Expand All @@ -170,7 +176,7 @@ contract LSP16UniversalProfileTest is Test {
abi.encodeWithSignature(
"deployCreate2(bytes,bytes32)",
abi.encodePacked(
type(LSP0ERC725Account).creationCode,
type(Account).creationCode,
abi.encode(address(this))
),
salt
Expand All @@ -187,7 +193,7 @@ contract LSP16UniversalProfileTest is Test {
);
}

function testdeployCreate2AndInitializeShouldNotKeepValueWithUPInit(
function testdeployCreate2AndInitializeShouldNotKeepValueWithAccountInit(
uint128 valueForInitializer,
bytes4 initilializerBytes
) public {
Expand All @@ -205,7 +211,7 @@ contract LSP16UniversalProfileTest is Test {
}(
abi.encodeWithSignature(
"deployCreate2AndInitialize(bytes,bytes32,bytes,uint256,uint256)",
type(LSP0ERC725AccountInit).creationCode,
type(AccountInit).creationCode,
salt,
_removeRandomByteFromBytes4(initilializerBytes),
0, // constructor is not payable
Expand Down Expand Up @@ -267,7 +273,7 @@ contract LSP16UniversalProfileTest is Test {
(bool success, ) = address(lsp16).call{value: valueToTransfer}(
abi.encodeWithSignature(
"deployERC1167ProxyAndInitialize(address,bytes32,bytes)",
address(lsp0Init),
address(accountInit),
salt,
initializeCalldata
)
Expand Down Expand Up @@ -342,7 +348,7 @@ contract LSP16UniversalProfileTest is Test {
);
}

function testcomputeAddressShouldReturnCorrectUPAddressWithdeployCreate2AndInitialize(
function testcomputeAddressShouldReturnCorrectAccountAddressWithdeployCreate2AndInitialize(
bytes32 providedSalt,
uint256 valueForInitializer,
bytes4 initilializerBytes
Expand All @@ -355,7 +361,7 @@ contract LSP16UniversalProfileTest is Test {
);

address expectedAddress = lsp16.computeAddress(
keccak256(type(LSP0ERC725AccountInit).creationCode),
keccak256(type(AccountInit).creationCode),
providedSalt,
true,
initializeCallData
Expand All @@ -365,7 +371,7 @@ contract LSP16UniversalProfileTest is Test {
}(
abi.encodeWithSignature(
"deployCreate2AndInitialize(bytes,bytes32,bytes,uint256,uint256)",
type(LSP0ERC725AccountInit).creationCode,
type(AccountInit).creationCode,
providedSalt,
initializeCallData,
0,
Expand All @@ -383,7 +389,7 @@ contract LSP16UniversalProfileTest is Test {
assert(expectedAddress == returnedAddress);
}

function testcomputeAddressShouldReturnCorrectUPAddressWithDeployCreate2(
function testcomputeAddressShouldReturnCorrectAccountAddressWithDeployCreate2(
bytes32 providedSalt,
uint256 valueForConstructor
) public {
Expand All @@ -393,7 +399,7 @@ contract LSP16UniversalProfileTest is Test {
address expectedAddress = lsp16.computeAddress(
keccak256(
abi.encodePacked(
type(LSP0ERC725Account).creationCode,
type(Account).creationCode,
abi.encode(address(this))
)
),
Expand All @@ -407,7 +413,7 @@ contract LSP16UniversalProfileTest is Test {
abi.encodeWithSignature(
"deployCreate2(bytes,bytes32)",
abi.encodePacked(
type(LSP0ERC725Account).creationCode,
type(Account).creationCode,
abi.encode(address(this))
),
providedSalt
Expand Down Expand Up @@ -436,7 +442,7 @@ contract LSP16UniversalProfileTest is Test {
);

address expectedAddress = lsp16.computeERC1167Address(
address(lsp0Init),
address(accountInit),
providedSalt,
true,
initializeCallData
Expand All @@ -446,7 +452,7 @@ contract LSP16UniversalProfileTest is Test {
}(
abi.encodeWithSignature(
"deployERC1167ProxyAndInitialize(address,bytes32,bytes)",
address(lsp0Init),
address(accountInit),
providedSalt,
initializeCallData
)
Expand All @@ -465,15 +471,15 @@ contract LSP16UniversalProfileTest is Test {
bytes32 providedSalt
) public {
address expectedAddress = lsp16.computeERC1167Address(
address(lsp0),
address(account),
providedSalt,
false,
""
);
(bool success, bytes memory returnedData) = address(lsp16).call(
abi.encodeWithSignature(
"deployERC1167Proxy(address,bytes32)",
address(lsp0),
address(account),
providedSalt
)
);
Expand Down
Loading

0 comments on commit 69ec255

Please sign in to comment.