// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract BankAccounts {
mapping(bytes32 => address) public whitelistedTokens;
mapping(address => mapping(bytes32 => uint256)) public bankAccountBalances;
address public owner;
event Deposit(uint256 amount, bytes32 symbol, address bankAccount);
event Withdrawal(uint256 amount, bytes32 symbol, address bankAccount);
event TransferToOwner(uint256 amount, bytes32 symbol, address bankAccount);
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner, "Only owner may call this function");
_;
}
function whitelistToken(bytes32 symbol, address tokenAddress) external onlyOwner {
whitelistedTokens[symbol] = tokenAddress;
}
function transferToOwner(uint256 amount, bytes32 symbol, address bankAccount) external onlyOwner {
require(bankAccountBalances[bankAccount][symbol] >= amount, "Insufficient balance");
IERC20 token = IERC20(whitelistedTokens[symbol]);
bankAccountBalances[bankAccount][symbol] -= amount;
token.transfer(owner, amount);
emit TransferToOwner(amount, symbol, bankAccount);
}
function deposit(uint256 amount, bytes32 symbol, address senderWallet, address bankAccount) external onlyOwner {
require(whitelistedTokens[symbol] != address(0), "Token not whitelisted");
IERC20 token = IERC20(whitelistedTokens[symbol]);
token.transferFrom(senderWallet, address(this), amount);
bankAccountBalances[bankAccount][symbol] += amount;
emit Deposit(amount, symbol, bankAccount);
}
function withdraw(uint256 amount, bytes32 symbol, address senderWallet, address bankAccount) external onlyOwner {
require(whitelistedTokens[symbol] != address(0), "Token not whitelisted");
require(bankAccount != address(0), "Invalid bank account");
require(bankAccountBalances[bankAccount][symbol] >= amount, "Insufficient balance on bank account");
IERC20 token = IERC20(whitelistedTokens[symbol]);
bankAccountBalances[bankAccount][symbol] -= amount;
token.transfer(senderWallet, amount);
emit Withdrawal(amount, symbol, bankAccount);
}
function balance(bytes32 symbol, address bankAccount) public view returns (uint256) {
require(whitelistedTokens[symbol] != address(0), "Token not whitelisted");
return bankAccountBalances[bankAccount][symbol];
}
}