From 0296ab432a0675f7335998eb47198f13d03277da Mon Sep 17 00:00:00 2001 From: Edmund Edgar Date: Tue, 28 Nov 2023 02:59:26 +0000 Subject: [PATCH] Use the openzeppelin createCode function instead of copy-pasting stuff from the solc docs --- contracts/MoneyBoxUser.sol | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/contracts/MoneyBoxUser.sol b/contracts/MoneyBoxUser.sol index 80606b4e..bb1c194e 100644 --- a/contracts/MoneyBoxUser.sol +++ b/contracts/MoneyBoxUser.sol @@ -3,22 +3,20 @@ pragma solidity ^0.8.20; import {MoneyBox} from "./MoneyBox.sol"; +import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; abstract contract MoneyBoxUser { function _calculateMoneyBoxAddress(address _creator, bytes32 _salt, address _token) internal pure returns (address) { - // From: - // https://docs.soliditylang.org/en/latest/control-structures.html#salted-contract-creations-create2 - return address(uint160(uint(keccak256(abi.encodePacked( - bytes1(0xff), - _creator, - _salt, + return Create2.computeAddress( + _salt, keccak256(abi.encodePacked( type(MoneyBox).creationCode, - abi.encode(_token) - )) - ))))); + abi.encode(_token) + )), + _creator + ); }