julien/lovepublic Fork 0
5376202c13fb4103a21f603fecc7fd40680b607b
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.sol · 52 lines · 1.9 KBSolidity Blame HistoryRaw
add love contract 9bf25a7 julienbrg 11h ago1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.30;
3
make love an erc20 with public mint 4c8048e julienbrg 11h ago4import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago5import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
add love contract 9bf25a7 julienbrg 11h ago7
make love an erc20 with public mint 4c8048e julienbrg 11h ago8/// @title Love
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago9/// @notice An ERC-20 pegged to wETH at a fixed rate of 100000 LOVE per wETH.
10/// Every LOVE in circulation is backed by wETH held by this contract:
11/// supply only moves through `deposit` and `withdraw`, and both are
12/// permissionless.
make love an erc20 with public mint 4c8048e julienbrg 11h ago13contract Love is ERC20 {
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago14 using SafeERC20 for IERC20;
add love contract 9bf25a7 julienbrg 11h ago15
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago16 uint256 public constant RATE = 100_000;
17
add weth peg tests and docs 5376202 julienbrg 9h ago18 IERC20 public immutable WETH;
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago19
20 error AmountNotDivisibleByRate(uint256 loveAmount, uint256 rate);
21
22 event Deposit(address indexed account, uint256 wethAmount, uint256 loveAmount);
23 event Withdraw(address indexed account, uint256 loveAmount, uint256 wethAmount);
24
25 constructor(IERC20 weth_) ERC20("Love", "LOVE") {
add weth peg tests and docs 5376202 julienbrg 9h ago26 WETH = weth_;
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago27 }
28
29 /// @notice Lock `wethAmount` wETH and mint `wethAmount * RATE` LOVE to the caller.
30 function deposit(uint256 wethAmount) external {
31 uint256 loveAmount = wethAmount * RATE;
32
add weth peg tests and docs 5376202 julienbrg 9h ago33 WETH.safeTransferFrom(msg.sender, address(this), wethAmount);
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago34 _mint(msg.sender, loveAmount);
35
36 emit Deposit(msg.sender, wethAmount, loveAmount);
37 }
38
39 /// @notice Burn `loveAmount` LOVE and release `loveAmount / RATE` wETH to the caller.
40 /// @dev Reverts unless `loveAmount` is a multiple of `RATE`, so the peg never
41 /// rounds against the caller or the remaining holders.
42 function withdraw(uint256 loveAmount) external {
43 if (loveAmount % RATE != 0) revert AmountNotDivisibleByRate(loveAmount, RATE);
44
45 uint256 wethAmount = loveAmount / RATE;
46
47 _burn(msg.sender, loveAmount);
add weth peg tests and docs 5376202 julienbrg 9h ago48 WETH.safeTransfer(msg.sender, wethAmount);
replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago49
50 emit Withdraw(msg.sender, loveAmount, wethAmount);
add love contract 9bf25a7 julienbrg 11h ago51 }
52}