forked from Synthetixio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProxyERC20.sol
115 lines (96 loc) · 4.33 KB
/
ProxyERC20.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
pragma solidity ^0.5.16;
// Inheritance
import "./Proxy.sol";
import "./interfaces/IERC20.sol";
// https://docs.synthetix.io/contracts/source/contracts/proxyerc20
contract ProxyERC20 is Proxy, IERC20 {
constructor(address _owner) public Proxy(_owner) {}
// ------------- ERC20 Details ------------- //
function name() public view returns (string memory) {
// Immutable static call from target contract
return IERC20(address(target)).name();
}
function symbol() public view returns (string memory) {
// Immutable static call from target contract
return IERC20(address(target)).symbol();
}
function decimals() public view returns (uint8) {
// Immutable static call from target contract
return IERC20(address(target)).decimals();
}
// ------------- ERC20 Interface ------------- //
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
// Immutable static call from target contract
return IERC20(address(target)).totalSupply();
}
/**
* @dev Gets the balance of the specified address.
* @param account The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address account) public view returns (uint256) {
// Immutable static call from target contract
return IERC20(address(target)).balanceOf(account);
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
// Immutable static call from target contract
return IERC20(address(target)).allowance(owner, spender);
}
/**
* @dev Transfer token for a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
// Mutable state call requires the proxy to tell the target who the msg.sender is.
target.setMessageSender(msg.sender);
// Forward the ERC20 call to the target contract
IERC20(address(target)).transfer(to, value);
// Event emitting will occur via Synthetix.Proxy._emit()
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
// Mutable state call requires the proxy to tell the target who the msg.sender is.
target.setMessageSender(msg.sender);
// Forward the ERC20 call to the target contract
IERC20(address(target)).approve(spender, value);
// Event emitting will occur via Synthetix.Proxy._emit()
return true;
}
/**
* @dev Transfer tokens from one address to another
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(
address from,
address to,
uint256 value
) public returns (bool) {
// Mutable state call requires the proxy to tell the target who the msg.sender is.
target.setMessageSender(msg.sender);
// Forward the ERC20 call to the target contract
IERC20(address(target)).transferFrom(from, to, value);
// Event emitting will occur via Synthetix.Proxy._emit()
return true;
}
}