-
Notifications
You must be signed in to change notification settings - Fork 0
/
MixinFunds.sol
56 lines (50 loc) · 1.49 KB
/
MixinFunds.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol';
/**
* @title An implementation of the money related functions.
* @author HardlyDifficult (unlock-protocol.com)
*/
contract MixinFunds
{
using AddressUpgradeable for address payable;
using SafeERC20Upgradeable for IERC20Upgradeable;
/**
* The token-type that this Lock is priced in. If 0, then use ETH, else this is
* a ERC20 token address.
*/
address public tokenAddress;
function _initializeMixinFunds(
address _tokenAddress
) internal
{
tokenAddress = _tokenAddress;
require(
_tokenAddress == address(0) || IERC20Upgradeable(_tokenAddress).totalSupply() > 0,
'INVALID_TOKEN'
);
}
/**
* Transfers funds from the contract to the account provided.
*
* Security: be wary of re-entrancy when calling this function.
*/
function _transfer(
address _tokenAddress,
address payable _to,
uint _amount
) internal
{
if(_amount > 0) {
if(_tokenAddress == address(0)) {
// https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/
_to.sendValue(_amount);
} else {
IERC20Upgradeable token = IERC20Upgradeable(_tokenAddress);
token.safeTransfer(_to, _amount);
}
}
}
}