-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAddressFactory.sol
99 lines (78 loc) · 3.46 KB
/
AddressFactory.sol
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// The source code was taken from https://github.com/Meshugah/ERC20-CommonGasWallet
pragma solidity 0.5.13;
import "./openzeppelin-contracts/contracts/ownership/Ownable.sol";
import "./openzeppelin-contracts/contracts/lifecycle/Pausable.sol";
import "./openzeppelin-contracts/contracts/math/SafeMath.sol";
/*
ERC 20 Transfer interface
*/
contract ERC20 {
function transfer(address to, uint tokens) public returns (bool success);
}
/*
Generic Receiver Contract
*/
contract Receiver is Ownable,Pausable {
/*
@notice Send funds owned by this contract to another address
@param tracker - ERC20 token tracker ( DAI / MKR / etc. )
@param amount - Amount of tokens to send
@param receiver - Address we're sending these tokens to
@return true if transfer succeeded, false otherwise
*/
using SafeMath for uint256;
function sendFundsTo( address tracker, uint256 amount, address receiver) public onlyOwner returns ( bool ) {
// callable only by the owner, not using modifiers to improve readability
// Transfer tokens from this address to the receiver
return ERC20(tracker).transfer(receiver, amount);
}
}
/*
AddressFactory Contract
*/
contract AddressFactory is Ownable, Pausable {
using SafeMath for uint256;
using SafeMath for uint8;
mapping ( uint256 => address ) public receiversMap;
/*
@notice Create a receiver contracts
@param ID - Receiver indexed ID
*/
function createReceivers( uint256 ID ) public onlyOwner{
// Create and index our new receiver
receiversMap[ID] = address(new Receiver());
}
/*
@notice Send funds in a receiver to another address
@param ID - Receiver indexed ID
@param tracker - ERC20 token tracker ( DAI / MKR / etc. )
@param amount - Amount of tokens to send
@param receiver - Address we're sending tokens to
@return true if transfer succeeded, false otherwise
*/
function sendFundsFromReceiverTo( uint256 ID, address tracker, uint256 amount, address receiver ) public onlyOwner returns (bool) {
return Receiver( receiversMap[ID] ).sendFundsTo( tracker, amount, receiver);
}
/*
Batch Collection - Should support a few hundred transansfers
@param tracker - ERC20 token tracker ( DAI / MKR / etc. )
@param receiver - Address we're sending tokens to
@param contractAddresses - we send an array of addresses instead of ids, so we don't need to read them ( lower gas cost )
@param amounts - array of amounts
*/
function batchCollect( address tracker, address receiver, uint256[] memory amounts, address[] memory contractAddresses) public onlyOwner{
require(contractAddresses.length == amounts.length);
for(uint256 i = 0; i < contractAddresses.length; i++) {
// add exception handling
require(Receiver( contractAddresses[i] ).sendFundsTo( tracker, amounts[i], receiver), "batchCollect's call to sendFundsTo failed");
}
}
}
// tests to check:
// batchcollect check for different lengths on amounts and contractAddress, addressed with the require
// check if the batchcollect function works after the require is added
// check for floating compiler
// transfer owner with openZeppelin
// what happens when you run createReceivers(0)
// change ownership
// check for createReceivers to be less than 40