|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.28; |
| 3 | + |
| 4 | +import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; |
| 5 | +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; |
| 6 | + |
| 7 | +import "./ISendToken.sol"; |
| 8 | +import "./ISendLockbox.sol"; |
| 9 | + |
| 10 | +contract SendLockbox is ISendLockbox { |
| 11 | + using SafeERC20 for IERC20; |
| 12 | + |
| 13 | + /// @notice The old ERC20 token of this contract |
| 14 | + IERC20 public immutable SEND_V0; |
| 15 | + |
| 16 | + /// @notice The new ERC20 token of this contract |
| 17 | + ISendToken public immutable SEND_V1; |
| 18 | + |
| 19 | + /// @param sendv0 The address of the old ERC20 contract |
| 20 | + /// @param sendv1 The address of the new ERC20 contract |
| 21 | + constructor(address sendv0, address sendv1) { |
| 22 | + SEND_V0 = IERC20(sendv0); |
| 23 | + SEND_V1 = ISendToken(sendv1); |
| 24 | + } |
| 25 | + |
| 26 | + /// @notice Deposit tokens into the lockbox and mints the new token to sender |
| 27 | + /// @param amount The amount of tokens to deposit |
| 28 | + function deposit(uint256 amount) external { |
| 29 | + _deposit(msg.sender, amount); |
| 30 | + } |
| 31 | + |
| 32 | + /// @notice Deposit ERC20 tokens into the lockbox |
| 33 | + /// @param to The user who should received minted tokens |
| 34 | + /// @param amount The amount of tokens to deposit |
| 35 | + function depositTo(address to, uint256 amount) external { |
| 36 | + _deposit(to, amount); |
| 37 | + } |
| 38 | + |
| 39 | + /// @notice Deposit tokens into the lockbox |
| 40 | + /// @param to The user who should received minted tokens |
| 41 | + /// @param amount The amount of tokens to deposit |
| 42 | + function _deposit(address to, uint256 amount) internal { |
| 43 | + SEND_V0.safeTransferFrom(msg.sender, address(this), amount); |
| 44 | + emit Deposit(to, amount); |
| 45 | + |
| 46 | + /// @notice v0 token has 0 decimals, v1 token has 18 decimals, therefore we multiply by 1 ether |
| 47 | + /// @notice v0 token has 100B supply, v1 token has 1B supply, therefore divided by 100 |
| 48 | + uint256 amountToMint = (amount * 1 ether) / 100; |
| 49 | + SEND_V1.mint(to, amountToMint); |
| 50 | + } |
| 51 | +} |
0 commit comments