Skip to content

Commit

Permalink
Use the openzeppelin createCode function instead of copy-pasting stuf…
Browse files Browse the repository at this point in the history
…f from the solc docs
  • Loading branch information
edmundedgar committed Nov 28, 2023
1 parent d5aae06 commit 0296ab4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions contracts/MoneyBoxUser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

}

Expand Down

0 comments on commit 0296ab4

Please sign in to comment.