From efad2c01736f98ef94db6b931a4f08668d7b5861 Mon Sep 17 00:00:00 2001 From: echo Date: Tue, 10 Dec 2024 10:02:02 +0800 Subject: [PATCH] predict --- src/XAccountFactory.sol | 8 ++++++-- src/XAccountUIFactory.sol | 5 +++++ src/interfaces/IXAccountFactory.sol | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/XAccountFactory.sol b/src/XAccountFactory.sol index 3778bdb..74f0dda 100644 --- a/src/XAccountFactory.sol +++ b/src/XAccountFactory.sol @@ -10,7 +10,7 @@ import "./utils/CREATE3.sol"; /// @dev XAccountFactory is a factory contract for create xAccount. /// - 1 account can deploy multi xAccount on target chain for each factory. contract XAccountFactory { - address public constant safeMsgportModule = 0x1899e901F53534489CEA580b6Ec688DddCcd0b91; + address public immutable SAFE_MSGPORT_MODULE; /// Safe Deployment: https://github.com/safe-global/safe-deployments/tree/main/src/assets/v1.3.0 address public constant safeFallbackHandler = 0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4; address public constant safeSingletonL2 = 0x3E5c63644E683549055b9Be8653de26E0B4CD36E; @@ -29,6 +29,10 @@ contract XAccountFactory { address recovery ); + constructor(address safeMsgportModule) { + SAFE_MSGPORT_MODULE = safeMsgportModule; + } + /// @dev Create xAccount on target chain. /// @notice Only could be called by source chain. /// @param salt Pseudo random number. @@ -89,7 +93,7 @@ contract XAccountFactory { bytes memory creationCode1 = safeFactory.proxyCreationCode(); bytes memory deploymentCode1 = abi.encodePacked(creationCode1, uint256(uint160(safeSingletonL2))); - (proxy, module) = CREATE3.deploy(salt, deploymentCode1, safeMsgportModule); + (proxy, module) = CREATE3.deploy(salt, deploymentCode1, SAFE_MSGPORT_MODULE); } /// @dev Calculate xAccount address. diff --git a/src/XAccountUIFactory.sol b/src/XAccountUIFactory.sol index 2369853..8b4b0c9 100644 --- a/src/XAccountUIFactory.sol +++ b/src/XAccountUIFactory.sol @@ -32,4 +32,9 @@ contract XAccountUIFactory { function getDeployed(uint256 fromChainId, address owner) public view returns (address[] memory) { return _xAccounts[fromChainId][owner].values(); } + + function xAccountOf(address deployer, uint256 fromChainId, address owner) public view returns (address, address) { + bytes32 salt = keccak256(abi.encodePacked(deployer)); + return FACTORY.xAccountOf(address(this), salt, fromChainId, owner); + } } diff --git a/src/interfaces/IXAccountFactory.sol b/src/interfaces/IXAccountFactory.sol index 18cfc11..a14a84d 100644 --- a/src/interfaces/IXAccountFactory.sol +++ b/src/interfaces/IXAccountFactory.sol @@ -5,4 +5,9 @@ interface IXAccountFactory { function create(bytes32 salt, uint256 fromChainId, address owner, address port, address recovery) external returns (address, address); + + function xAccountOf(address deployer, bytes32 salt, uint256 fromChainId, address owner) + public + view + returns (address, address); }