feat: add storage-safe bank V2
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@ contract BankV1 is Initializable, UUPSUpgradeable, OwnableUpgradeable, PausableU
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
function initialize(address asset_, address initialOwner) external initializer {
|
||||
function initialize(address asset_, address initialOwner) public initializer {
|
||||
if (asset_ == address(0)) {
|
||||
revert InvalidAsset(asset_);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.35;
|
||||
|
||||
import {BankV1} from "./BankV1.sol";
|
||||
|
||||
/// @custom:oz-upgrades-from src/BankV1.sol:BankV1
|
||||
contract BankV2 is BankV1 {
|
||||
event BalanceTransferred(address indexed from, address indexed to, uint256 amount);
|
||||
|
||||
error InvalidRecipient(address recipient);
|
||||
error SelfTransfer();
|
||||
|
||||
function transferBalance(address recipient, uint256 amount) external whenNotPaused {
|
||||
if (amount == 0) revert ZeroAmount();
|
||||
if (recipient == address(0)) revert InvalidRecipient(recipient);
|
||||
if (recipient == msg.sender) revert SelfTransfer();
|
||||
uint256 available = _balances[msg.sender];
|
||||
if (amount > available) {
|
||||
revert InsufficientBalance(msg.sender, available, amount);
|
||||
}
|
||||
_balances[msg.sender] = available - amount;
|
||||
_balances[recipient] += amount;
|
||||
emit BalanceTransferred(msg.sender, recipient, amount);
|
||||
}
|
||||
|
||||
function contractVersion() public pure override returns (uint256) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user