julien/lovepublic Fork 0
6b4a40d9d53d284f94b492aff5a8fc978f05781c
Commits
Clone
git clone https://git.rickub.com/julien/love.git
git clone ssh://git@rickub.com/julien/love.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Love.s.sol · 112 lines · 4.7 KBSolidity Blame HistoryRaw
add love contract 9bf25a7 julienbrg 11h ago1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.30;
3
4import {Love} from "../src/Love.sol";
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago5import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
add love contract 9bf25a7 julienbrg 11h ago6import {Script, console} from "forge-std/Script.sol";
7
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago8/// @title LoveScript
9/// @author Julien Béranger
Merge 1-add-main-logic into main dded29a rickub 10h ago10/// @notice Deploys `Love` with CREATE2 through the canonical deterministic
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago11/// deployer. The address depends on the salt and the creation code, and
12/// the creation code embeds the wETH address — so the token only gets
13/// the same address on chains where wETH sits at the same address. Keep
Merge 1-add-main-logic into main dded29a rickub 10h ago14/// `solc`, the optimizer settings and `bytecode_hash = "none"` as they
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago15/// are in `foundry.toml`, or the address changes too.
add love contract 9bf25a7 julienbrg 11h ago16contract LoveScript is Script {
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago17 /// @notice Salt used when `SALT` is not set in the environment.
Merge 1-add-main-logic into main dded29a rickub 10h ago18 bytes32 public constant DEFAULT_SALT = keccak256("LOVE");
19
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago20 /// @notice wETH address used when `WETH` is not set in the environment.
21 /// @dev wETH on Base, Optimism and every other OP-Stack chain.
22 address public constant DEFAULT_WETH = 0x4200000000000000000000000000000000000006;
23
24 /// @notice The token, once `run()` has deployed or found it.
add love contract 9bf25a7 julienbrg 11h ago25 Love public love;
26
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago27 /// @notice Deploy `Love`, or return it untouched if it is already there.
28 /// @dev Reads `SALT` and `WETH` from the environment, falling back to the
29 /// defaults, and asserts the deployed address matches the prediction.
30 /// @return The deployed token.
Merge 1-add-main-logic into main dded29a rickub 10h ago31 function run() public returns (Love) {
32 bytes32 s = salt();
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago33 address w = wethAddress();
34 address predicted = predict(s, w);
Merge 1-add-main-logic into main dded29a rickub 10h ago35
36 console.log("deployer ", CREATE2_FACTORY);
37 console.log("salt ", vm.toString(s));
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago38 console.log("weth ", w);
39 console.log("initCodeHash ", vm.toString(initCodeHash(w)));
Merge 1-add-main-logic into main dded29a rickub 10h ago40 console.log("predicted ", predicted);
41
42 if (predicted.code.length > 0) {
43 console.log("already deployed, nothing to do");
44 love = Love(predicted);
45 return love;
46 }
47
add love contract 9bf25a7 julienbrg 11h ago48 vm.startBroadcast();
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago49 love = new Love{salt: s}(IERC20(w));
Merge 1-add-main-logic into main dded29a rickub 10h ago50 vm.stopBroadcast();
51
52 require(address(love) == predicted, "LoveScript: address mismatch");
add love contract 9bf25a7 julienbrg 11h ago53
54 console.log("Love deployed at", address(love));
make love an erc20 with public mint 4c8048e julienbrg 11h ago55 console.log("name ", love.name());
56 console.log("symbol ", love.symbol());
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago57 console.log("weth ", address(love.WETH()));
58 console.log("rate ", love.RATE());
make love an erc20 with public mint 4c8048e julienbrg 11h ago59 console.log("totalSupply ", love.totalSupply());
add love contract 9bf25a7 julienbrg 11h ago60
Merge 1-add-main-logic into main dded29a rickub 10h ago61 return love;
62 }
63
64 /// @notice Print the address `run()` would deploy to, without broadcasting.
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago65 /// @return predicted The address the current salt and wETH derive to.
Merge 1-add-main-logic into main dded29a rickub 10h ago66 function predict() public view returns (address predicted) {
67 bytes32 s = salt();
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago68 address w = wethAddress();
69 predicted = predict(s, w);
Merge 1-add-main-logic into main dded29a rickub 10h ago70
71 console.log("salt ", vm.toString(s));
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago72 console.log("weth ", w);
73 console.log("initCodeHash ", vm.toString(initCodeHash(w)));
Merge 1-add-main-logic into main dded29a rickub 10h ago74 console.log("predicted ", predicted);
75 }
76
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago77 /// @notice Derive the deployment address from a salt and a wETH address.
78 /// @param s The CREATE2 salt.
79 /// @param w The wETH the token would be pegged to.
80 /// @return The address `Love` would land at.
81 function predict(bytes32 s, address w) public pure returns (address) {
82 return vm.computeCreate2Address(s, initCodeHash(w), CREATE2_FACTORY);
83 }
84
85 /// @notice The creation code CREATE2 is handed, constructor argument included.
86 /// @param w The wETH the token would be pegged to.
87 /// @return The creation code, with `w` ABI-encoded onto it.
88 function initCode(address w) public pure returns (bytes memory) {
89 return abi.encodePacked(type(Love).creationCode, abi.encode(w));
Merge 1-add-main-logic into main dded29a rickub 10h ago90 }
91
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago92 /// @notice Hash of the creation code, the second input to the address derivation.
93 /// @param w The wETH the token would be pegged to.
94 /// @return The keccak256 of `initCode(w)`.
95 function initCodeHash(address w) public pure returns (bytes32) {
96 return keccak256(initCode(w));
Merge 1-add-main-logic into main dded29a rickub 10h ago97 }
98
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago99 /// @notice The salt to deploy with.
Merge 1-add-main-logic into main dded29a rickub 10h ago100 /// @dev `SALT` overrides the default, e.g. to mine a vanity address.
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago101 /// @return The configured salt, or `DEFAULT_SALT`.
Merge 1-add-main-logic into main dded29a rickub 10h ago102 function salt() public view returns (bytes32) {
103 return vm.envOr("SALT", DEFAULT_SALT);
add love contract 9bf25a7 julienbrg 11h ago104 }
Merge 3-peg-love-to-weth into main ce13509 rickub 9h ago105
106 /// @notice The wETH address to peg the deployment to.
107 /// @dev `WETH` overrides the default, which only holds on OP-Stack chains.
108 /// @return The configured wETH address, or `DEFAULT_WETH`.
109 function wethAddress() public view returns (address) {
110 return vm.envOr("WETH", DEFAULT_WETH);
111 }
add love contract 9bf25a7 julienbrg 11h ago112}