src/DemoBTC.sol36 lines · 1447 bytes
| 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity 0.8.37; |
| 3 | |
| 4 | import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; |
| 5 | import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; |
| 6 | import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; |
| 7 | |
| 8 | /// @title DemoBTC (dBTC) v1 |
| 9 | /// @notice Demo asset behind a TransparentUpgradeableProxy. Not a real asset. |
| 10 | /// @dev ERC20 + Ownable from OZ upgradeable 5.7.0 (ERC-7201 namespaced storage). Every other demo |
| 11 | /// implementation inherits this contract, so they all share the same storage layout. |
| 12 | contract DemoBTC is Initializable, ERC20Upgradeable, OwnableUpgradeable { |
| 13 | error LengthMismatch(); |
| 14 | |
| 15 | /// @custom:oz-upgrades-unsafe-allow constructor |
| 16 | constructor() { |
| 17 | _disableInitializers(); |
| 18 | } |
| 19 | |
| 20 | function initialize(address owner_, address[] calldata holders, uint256[] calldata amounts) external initializer { |
| 21 | __ERC20_init("DemoBTC", "dBTC"); |
| 22 | __Ownable_init(owner_); |
| 23 | if (holders.length != amounts.length) revert LengthMismatch(); |
| 24 | for (uint256 i = 0; i < holders.length; i++) { |
| 25 | _mint(holders[i], amounts[i]); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | function decimals() public pure override returns (uint8) { |
| 30 | return 8; |
| 31 | } |
| 32 | |
| 33 | function mint(address to, uint256 amount) public virtual onlyOwner { |
| 34 | _mint(to, amount); |
| 35 | } |
| 36 | } |