Skip to content

Commit

Permalink
Replace addressFrom with Foundry utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
solimander committed Oct 16, 2023
1 parent 440bf0c commit 4744284
Showing 1 changed file with 1 addition and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract UpgradeDescriptorV2PopulateArtFromExisting is Script {
INounsArt.Trait memory heads = EXISTING_ART.getHeadsTrait();
INounsArt.Trait memory glasses = EXISTING_ART.getGlassesTrait();

INounsArt predictedArt = INounsArt(addressFrom(upgrader, vm.getNonce(upgrader) + 1));
INounsArt predictedArt = INounsArt(computeCreateAddress(upgrader, vm.getNonce(upgrader) + 1));

vm.startBroadcast(upgraderKey);

Expand Down Expand Up @@ -73,26 +73,4 @@ contract UpgradeDescriptorV2PopulateArtFromExisting is Script {
}
vm.stopBroadcast();
}

function addressFrom(address _origin, uint256 _nonce) internal pure returns (address _address) {
bytes memory data;
if (_nonce == 0x00) {
data = abi.encodePacked(bytes1(0xd6), bytes1(0x94), _origin, bytes1(0x80));
} else if (_nonce <= 0x7f) {
data = abi.encodePacked(bytes1(0xd6), bytes1(0x94), _origin, uint8(_nonce));
} else if (_nonce <= 0xff) {
data = abi.encodePacked(bytes1(0xd7), bytes1(0x94), _origin, bytes1(0x81), uint8(_nonce));
} else if (_nonce <= 0xffff) {
data = abi.encodePacked(bytes1(0xd8), bytes1(0x94), _origin, bytes1(0x82), uint16(_nonce));
} else if (_nonce <= 0xffffff) {
data = abi.encodePacked(bytes1(0xd9), bytes1(0x94), _origin, bytes1(0x83), uint24(_nonce));
} else {
data = abi.encodePacked(bytes1(0xda), bytes1(0x94), _origin, bytes1(0x84), uint32(_nonce));
}
bytes32 hash = keccak256(data);
assembly {
mstore(0, hash)
_address := mload(0)
}
}
}

0 comments on commit 4744284

Please sign in to comment.