File size: 2,455 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;

interface ERC20 {
  function allowance(address _owner, address spender) external view returns (uint256);
  function balanceOf(address account) external view returns (uint256);
  function transfer(address recipient, uint256 amount) external returns (bool);
  function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}

contract MultiBridge {
    address public owner;
    ERC20 public immutable token;
    uint public immutable initBlock;

    event BridgeAssistUpload(address indexed sender, uint256 amount, string target);
    event Dispense(address indexed sender, uint256 amount);
    event TransferOwnership(address indexed previousOwner, address indexed newOwner);

    modifier restricted() {
        require(msg.sender == owner, "Function restricted to owner");
        _;
    }

    constructor(ERC20 _token) {
        require(address(_token) != address(0), "Invalid token address");
        token = _token;
        owner = msg.sender;
        initBlock = block.number;
    }

    function upload(uint256 amount, string memory target) external returns (bool success) {
        require(amount > 0, "Wrong amount");
        require(bytes(target).length != 0, "Incorrect target");
        require(token.transferFrom(msg.sender, address(this), amount), "Failed to transferFrom");
        emit BridgeAssistUpload(msg.sender, amount, target);
        return true;
    }

    function dispense(address recipient, uint256 _amount) external restricted returns (bool success) {
        require(_amount > 0, "Wrong amount");
        require(recipient != address(0), "Incorrect recipient");
        require(token.transfer(recipient, _amount), "Failed to transfer");
        emit Dispense(recipient, _amount);
        return true;
    }

    function transferOwnership(address _newOwner) external restricted {
        require(_newOwner != address(0), "Invalid _newOwner address");
        emit TransferOwnership(owner, _newOwner);
        owner = _newOwner;
    }

    function infoBundle(address user) external view returns (ERC20 tok, uint256 all, uint256 bal) {
        return (token, token.allowance(user, address(this)), token.balanceOf(user));
    }
}