| add love contract 9bf25a7 julienbrg 11h ago | 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity ^0.8.30; |
| 3 | |
| make love an erc20 with public mint 4c8048e julienbrg 11h ago | 4 | import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 5 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| 6 | import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; |
| add love contract 9bf25a7 julienbrg 11h ago | 7 | |
| make love an erc20 with public mint 4c8048e julienbrg 11h ago | 8 | /// @title Love |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 9 | /// @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 ago | 13 | contract Love is ERC20 { |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 14 | using SafeERC20 for IERC20; |
| add love contract 9bf25a7 julienbrg 11h ago | 15 | |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 16 | uint256 public constant RATE = 100_000; |
| 17 | |
| add weth peg tests and docs 5376202 julienbrg 9h ago | 18 | IERC20 public immutable WETH; |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 19 | |
| 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 ago | 26 | WETH = weth_; |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 27 | } |
| 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 ago | 33 | WETH.safeTransferFrom(msg.sender, address(this), wethAmount); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 34 | _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 ago | 48 | WETH.safeTransfer(msg.sender, wethAmount); |
| replace mint with weth-pegged deposit and withdraw 92dc0c7 julienbrg 9h ago | 49 | |
| 50 | emit Withdraw(msg.sender, loveAmount, wethAmount); |
| add love contract 9bf25a7 julienbrg 11h ago | 51 | } |
| 52 | } |