mirror of
https://github.com/lens-protocol/core.git
synced 2026-01-10 14:48:15 -05:00
fix: Remove dependencies for address prediction
This commit is contained in:
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -1,4 +0,0 @@
|
||||
[submodule "lib/solmate"]
|
||||
path = lib/solmate
|
||||
url = https://github.com/transmissions11/solmate
|
||||
branch = v7
|
||||
|
||||
Submodule lib/solmate deleted from ed67feda67
@@ -22,6 +22,10 @@ contract EventTest is BaseTest {
|
||||
hub.whitelistFollowModule(mockFollowModule, true);
|
||||
}
|
||||
|
||||
function predictContractAddress(address user, uint256 distanceFromCurrentNonce) internal returns(address) {
|
||||
return computeCreateAddress(user, vm.getNonce(user) + distanceFromCurrentNonce);
|
||||
}
|
||||
|
||||
// MISC
|
||||
|
||||
function testProxyInitEmitsExpectedEvents() public {
|
||||
@@ -30,9 +34,9 @@ contract EventTest is BaseTest {
|
||||
|
||||
vm.startPrank(deployer);
|
||||
|
||||
address followNFTAddr = utils.predictContractAddress(deployer, 1);
|
||||
address collectNFTAddr = utils.predictContractAddress(deployer, 2);
|
||||
hubProxyAddr = utils.predictContractAddress(deployer, 3);
|
||||
address followNFTAddr = predictContractAddress(deployer, 1);
|
||||
address collectNFTAddr = predictContractAddress(deployer, 2);
|
||||
hubProxyAddr = predictContractAddress(deployer, 3);
|
||||
|
||||
// Deploy implementation contracts.
|
||||
hubImpl = new LensHub(followNFTAddr, collectNFTAddr);
|
||||
@@ -311,7 +315,7 @@ contract EventTest is BaseTest {
|
||||
followTargetIds[0] = 1;
|
||||
bytes[] memory followDatas = new bytes[](1);
|
||||
followDatas[0] = '';
|
||||
address expectedFollowNFTAddress = utils.predictContractAddress(address(hub), 0);
|
||||
address expectedFollowNFTAddress = predictContractAddress(address(hub), 0);
|
||||
|
||||
vm.prank(profileOwner);
|
||||
vm.expectEmit(true, true, false, true, address(hub));
|
||||
@@ -338,7 +342,7 @@ contract EventTest is BaseTest {
|
||||
hub.post(mockPostData);
|
||||
|
||||
uint256 expectedPubId = 1;
|
||||
address expectedCollectNFTAddress = utils.predictContractAddress(address(hub), 0);
|
||||
address expectedCollectNFTAddress = predictContractAddress(address(hub), 0);
|
||||
string memory expectedNFTName = "1-Collect-1";
|
||||
string memory expectedNFTSymbol = "1-Cl-1";
|
||||
|
||||
@@ -404,7 +408,7 @@ contract EventTest is BaseTest {
|
||||
bytes[] memory followDatas = new bytes[](1);
|
||||
followDatas[0] = '';
|
||||
uint256 expectedPubId = 1;
|
||||
address expectedCollectNFTAddress = utils.predictContractAddress(address(hub), 0);
|
||||
address expectedCollectNFTAddress = predictContractAddress(address(hub), 0);
|
||||
string memory expectedNFTName = "1-Collect-1";
|
||||
string memory expectedNFTSymbol = "1-Cl-1";
|
||||
|
||||
|
||||
@@ -17,15 +17,12 @@ import {GeneralLib} from 'contracts/libraries/GeneralLib.sol';
|
||||
import {ProfileTokenURILogic} from 'contracts/libraries/ProfileTokenURILogic.sol';
|
||||
import {MockCollectModule} from 'contracts/mocks/MockCollectModule.sol';
|
||||
import {MockReferenceModule} from 'contracts/mocks/MockReferenceModule.sol';
|
||||
import {Utils} from '../helpers/Utils.sol';
|
||||
import '../helpers/ForkManagement.sol';
|
||||
import '../Constants.sol';
|
||||
|
||||
contract TestSetup is Test, ForkManagement {
|
||||
using stdJson for string;
|
||||
|
||||
Utils internal utils;
|
||||
|
||||
string forkEnv;
|
||||
bool fork;
|
||||
string network;
|
||||
@@ -222,8 +219,6 @@ contract TestSetup is Test, ForkManagement {
|
||||
}
|
||||
|
||||
function setUp() public virtual {
|
||||
utils = new Utils();
|
||||
|
||||
// Compute the domain separator.
|
||||
domainSeparator = keccak256(
|
||||
abi.encode(
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity >=0.8.0;
|
||||
|
||||
import {Bytes32AddressLib} from "solmate/utils/Bytes32AddressLib.sol";
|
||||
|
||||
import 'forge-std/Test.sol';
|
||||
|
||||
// common utilities for forge tests
|
||||
contract Utils is Test {
|
||||
function predictContractAddress(address user, uint256 distanceFromCurrentNonce) external returns (address) {
|
||||
return LibRLP.computeAddress(user, vm.getNonce(user) + distanceFromCurrentNonce);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
library LibRLP {
|
||||
using Bytes32AddressLib for bytes32;
|
||||
|
||||
// prettier-ignore
|
||||
function computeAddress(address deployer, uint256 nonce) internal pure returns (address) {
|
||||
// The integer zero is treated as an empty byte string, and as a result it only has a length prefix, 0x80, computed via 0x80 + 0.
|
||||
// A one byte integer uses its own value as its length prefix, there is no additional "0x80 + length" prefix that comes before it.
|
||||
if (nonce == 0x00) return keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, bytes1(0x80))).fromLast20Bytes();
|
||||
if (nonce <= 0x7f) return keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, uint8(nonce))).fromLast20Bytes();
|
||||
|
||||
// Nonces greater than 1 byte all follow a consistent encoding scheme, where each value is preceded by a prefix of 0x80 + length.
|
||||
if (nonce <= type(uint8).max) return keccak256(abi.encodePacked(bytes1(0xd7), bytes1(0x94), deployer, bytes1(0x81), uint8(nonce))).fromLast20Bytes();
|
||||
if (nonce <= type(uint16).max) return keccak256(abi.encodePacked(bytes1(0xd8), bytes1(0x94), deployer, bytes1(0x82), uint16(nonce))).fromLast20Bytes();
|
||||
if (nonce <= type(uint24).max) return keccak256(abi.encodePacked(bytes1(0xd9), bytes1(0x94), deployer, bytes1(0x83), uint24(nonce))).fromLast20Bytes();
|
||||
|
||||
// More details about RLP encoding can be found here: https://eth.wiki/fundamentals/rlp
|
||||
// 0xda = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x84 ++ nonce)
|
||||
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex)
|
||||
// 0x84 = 0x80 + 0x04 (0x04 = the bytes length of the nonce, 4 bytes, in hex)
|
||||
// We assume nobody can have a nonce large enough to require more than 32 bytes.
|
||||
return keccak256(abi.encodePacked(bytes1(0xda), bytes1(0x94), deployer, bytes1(0x84), uint32(nonce))).fromLast20Bytes();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user