-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.sol
More file actions
59 lines (48 loc) · 2.09 KB
/
Bank.sol
File metadata and controls
59 lines (48 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.24;
import "./AccessControlled.sol";
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
function balanceOf(address who) external view returns (uint256);
}
/**
* ERC-20 vault (e.g., USDC on Base testnet). Only the ClaimEngine can instruct payments.
*/
contract Bank is AccessControlled {
IERC20 public immutable token;
address public engine;
event EngineSet(address indexed engine);
event PaymentExecuted(uint256 indexed claimId, address indexed to, uint256 amount, uint256 vaultBalanceAfter);
event Recovered(address indexed token, address indexed to, uint256 amount);
event RecoveredETH(address indexed to, uint256 amount);
constructor(IERC20 _token) { token = _token; }
function setEngine(address e) external onlyOwner {
require(e != address(0), "engine=0");
engine = e;
emit EngineSet(e);
}
function pay(address to, uint256 amount, uint256 claimId) external {
require(msg.sender == engine, "only engine");
require(token.transfer(to, amount), "transfer failed");
emit PaymentExecuted(claimId, to, amount, token.balanceOf(address(this)));
}
function vaultBalance() external view returns (uint256) {
return token.balanceOf(address(this));
}
// Ops: recover stray tokens (not the primary vault token)
function recoverToken(address other, address to, uint256 amount) external onlyOwner {
require(other != address(token), "cannot recover vault token");
require(to != address(0), "to=0");
bool ok = IERC20(other).transfer(to, amount);
require(ok, "recover transfer failed");
emit Recovered(other, to, amount);
}
// Ops: recover native ETH if accidentally sent
function recoverETH(address payable to, uint256 amount) external onlyOwner {
require(to != address(0), "to=0");
(bool s, ) = to.call{value: amount}("");
require(s, "recover eth failed");
emit RecoveredETH(to, amount);
}
receive() external payable {}
}