| add love contract 9bf25a7 julienbrg 11h ago | 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity ^0.8.30; |
| 3 | |
| 4 | import {Love} from "../src/Love.sol"; |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 5 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| add love contract 9bf25a7 julienbrg 11h ago | 6 | import {Script, console} from "forge-std/Script.sol"; |
| 7 | |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 8 | /// @notice Deploys `Love` with CREATE2 through the canonical deterministic |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 9 | /// deployer. The address depends on the salt and the creation code, and |
| 10 | /// the creation code embeds the wETH address — so the token only gets |
| 11 | /// the same address on chains where wETH sits at the same address. Keep |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 12 | /// `solc`, the optimizer settings and `bytecode_hash = "none"` as they |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 13 | /// are in `foundry.toml`, or the address changes too. |
| add love contract 9bf25a7 julienbrg 11h ago | 14 | contract LoveScript is Script { |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 15 | bytes32 public constant DEFAULT_SALT = keccak256("LOVE"); |
| 16 | |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 17 | /// @dev wETH on Base, Optimism and every other OP-Stack chain. |
| 18 | address public constant DEFAULT_WETH = 0x4200000000000000000000000000000000000006; |
| 19 | |
| add love contract 9bf25a7 julienbrg 11h ago | 20 | Love public love; |
| 21 | |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 22 | function run() public returns (Love) { |
| 23 | bytes32 s = salt(); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 24 | address w = wethAddress(); |
| 25 | address predicted = predict(s, w); |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 26 | |
| 27 | console.log("deployer ", CREATE2_FACTORY); |
| 28 | console.log("salt ", vm.toString(s)); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 29 | console.log("weth ", w); |
| 30 | console.log("initCodeHash ", vm.toString(initCodeHash(w))); |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 31 | console.log("predicted ", predicted); |
| 32 | |
| 33 | if (predicted.code.length > 0) { |
| 34 | console.log("already deployed, nothing to do"); |
| 35 | love = Love(predicted); |
| 36 | return love; |
| 37 | } |
| 38 | |
| add love contract 9bf25a7 julienbrg 11h ago | 39 | vm.startBroadcast(); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 40 | love = new Love{salt: s}(IERC20(w)); |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 41 | vm.stopBroadcast(); |
| 42 | |
| 43 | require(address(love) == predicted, "LoveScript: address mismatch"); |
| add love contract 9bf25a7 julienbrg 11h ago | 44 | |
| 45 | console.log("Love deployed at", address(love)); |
| make love an erc20 with public mint 4c8048e julienbrg 11h ago | 46 | console.log("name ", love.name()); |
| 47 | console.log("symbol ", love.symbol()); |
| add weth peg tests and docs 5376202 julienbrg 9h ago | 48 | console.log("weth ", address(love.WETH())); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 49 | console.log("rate ", love.RATE()); |
| make love an erc20 with public mint 4c8048e julienbrg 11h ago | 50 | console.log("totalSupply ", love.totalSupply()); |
| add love contract 9bf25a7 julienbrg 11h ago | 51 | |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 52 | return love; |
| 53 | } |
| 54 | |
| 55 | /// @notice Print the address `run()` would deploy to, without broadcasting. |
| 56 | function predict() public view returns (address predicted) { |
| 57 | bytes32 s = salt(); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 58 | address w = wethAddress(); |
| 59 | predicted = predict(s, w); |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 60 | |
| 61 | console.log("salt ", vm.toString(s)); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 62 | console.log("weth ", w); |
| 63 | console.log("initCodeHash ", vm.toString(initCodeHash(w))); |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 64 | console.log("predicted ", predicted); |
| 65 | } |
| 66 | |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 67 | function predict(bytes32 s, address w) public pure returns (address) { |
| 68 | return vm.computeCreate2Address(s, initCodeHash(w), CREATE2_FACTORY); |
| 69 | } |
| 70 | |
| 71 | function initCode(address w) public pure returns (bytes memory) { |
| 72 | return abi.encodePacked(type(Love).creationCode, abi.encode(w)); |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 73 | } |
| 74 | |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 75 | function initCodeHash(address w) public pure returns (bytes32) { |
| 76 | return keccak256(initCode(w)); |
| Merge 1-add-main-logic into main dded29a rickub 10h ago | 77 | } |
| 78 | |
| 79 | /// @dev `SALT` overrides the default, e.g. to mine a vanity address. |
| 80 | function salt() public view returns (bytes32) { |
| 81 | return vm.envOr("SALT", DEFAULT_SALT); |
| add love contract 9bf25a7 julienbrg 11h ago | 82 | } |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 83 | |
| 84 | /// @dev `WETH` overrides the default, which only holds on OP-Stack chains. |
| 85 | function wethAddress() public view returns (address) { |
| 86 | return vm.envOr("WETH", DEFAULT_WETH); |
| 87 | } |
| add love contract 9bf25a7 julienbrg 11h ago | 88 | } |