@@ -34,10 +34,7 @@ import Assertions from '../assertions';
34
34
export default class ERC20API {
35
35
private assert : Assertions ;
36
36
private erc20Wrapper : ERC20Wrapper ;
37
- public constructor (
38
- provider : Provider ,
39
- assertions ?: Assertions
40
- ) {
37
+ public constructor ( provider : Provider , assertions ?: Assertions ) {
41
38
this . erc20Wrapper = new ERC20Wrapper ( provider ) ;
42
39
this . assert = assertions || new Assertions ( ) ;
43
40
}
@@ -47,61 +44,86 @@ export default class ERC20API {
47
44
*
48
45
* @param tokenAddress Address of the ERC20 token
49
46
* @param userAddress Address of the user
47
+ * @param callerAddress Optional. The address of user transferring from.
50
48
* @return The balance of the ERC20 token in BigNumber format
51
49
*/
52
- public async getBalanceAsync ( tokenAddress : Address , userAddress : Address ) : Promise < BigNumber > {
50
+ public async getBalanceAsync (
51
+ tokenAddress : Address ,
52
+ userAddress : Address ,
53
+ callerAddress : Address = undefined
54
+ ) : Promise < BigNumber > {
53
55
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
54
56
this . assert . schema . isValidAddress ( 'userAddress' , userAddress ) ;
55
57
56
- return this . erc20Wrapper . balanceOf ( tokenAddress , userAddress ) ;
58
+ return this . erc20Wrapper . balanceOf (
59
+ tokenAddress ,
60
+ userAddress ,
61
+ callerAddress
62
+ ) ;
57
63
}
58
64
59
65
/**
60
66
* Gets name of the ERC20 token
61
67
*
62
68
* @param tokenAddress Address of the ERC20 token
69
+ * @param callerAddress Optional. The address of user transferring from.
63
70
* @return The name of the ERC20 token
64
71
*/
65
- public async getTokenNameAsync ( tokenAddress : Address ) : Promise < string > {
72
+ public async getTokenNameAsync (
73
+ tokenAddress : Address ,
74
+ callerAddress : Address = undefined
75
+ ) : Promise < string > {
66
76
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
67
77
68
- return this . erc20Wrapper . name ( tokenAddress ) ;
78
+ return this . erc20Wrapper . name ( tokenAddress , callerAddress ) ;
69
79
}
70
80
71
81
/**
72
82
* Gets symbol of the ERC20 token
73
83
*
74
84
* @param tokenAddress Address of the ERC20 token
85
+ * @param callerAddress Optional. The address of user transferring from.
75
86
* @return The symbol of the ERC20 token
76
87
*/
77
- public async getTokenSymbolAsync ( tokenAddress : Address ) : Promise < string > {
88
+ public async getTokenSymbolAsync (
89
+ tokenAddress : Address ,
90
+ callerAddress : Address = undefined
91
+ ) : Promise < string > {
78
92
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
79
93
80
- return this . erc20Wrapper . symbol ( tokenAddress ) ;
94
+ return this . erc20Wrapper . symbol ( tokenAddress , callerAddress ) ;
81
95
}
82
96
83
97
/**
84
98
* Gets the total supply of the ERC20 token
85
99
*
86
100
* @param tokenAddress Address of the ERC20 token
101
+ * @param callerAddress Optional. The address of user transferring from.
87
102
* @return The total supply of ERC-20 in BigNumber format
88
103
*/
89
- public async getTotalSupplyAsync ( tokenAddress : Address ) : Promise < BigNumber > {
104
+ public async getTotalSupplyAsync (
105
+ tokenAddress : Address ,
106
+ callerAddress : Address = undefined
107
+ ) : Promise < BigNumber > {
90
108
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
91
109
92
- return this . erc20Wrapper . totalSupply ( tokenAddress ) ;
110
+ return this . erc20Wrapper . totalSupply ( tokenAddress , callerAddress ) ;
93
111
}
94
112
95
113
/**
96
114
* Gets decimals of the ERC20 token
97
115
*
98
116
* @param tokenAddress Address of the ERC20 token
117
+ * @param callerAddress Optional. The address of user transferring from.
99
118
* @return The decimals of the ERC20 token
100
119
*/
101
- public async getDecimalsAsync ( tokenAddress : Address ) : Promise < BigNumber > {
120
+ public async getDecimalsAsync (
121
+ tokenAddress : Address ,
122
+ callerAddress : Address = undefined
123
+ ) : Promise < BigNumber > {
102
124
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
103
125
104
- return this . erc20Wrapper . decimals ( tokenAddress ) ;
126
+ return this . erc20Wrapper . decimals ( tokenAddress , callerAddress ) ;
105
127
}
106
128
107
129
/**
@@ -110,18 +132,25 @@ export default class ERC20API {
110
132
* @param tokenAddress Address of the token
111
133
* @param ownerAddress Address of the owner
112
134
* @param spenderAddress Address of the spender
135
+ * @param callerAddress Optional. The address of user transferring from.
113
136
* @return The allowance of the spender in BigNumber format
114
137
*/
115
138
public async getAllowanceAsync (
116
139
tokenAddress : Address ,
117
140
ownerAddress : Address ,
118
141
spenderAddress : Address ,
142
+ callerAddress : Address = undefined
119
143
) : Promise < BigNumber > {
120
144
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
121
145
this . assert . schema . isValidAddress ( 'ownerAddress' , ownerAddress ) ;
122
146
this . assert . schema . isValidAddress ( 'spenderAddress' , spenderAddress ) ;
123
147
124
- return this . erc20Wrapper . allowance ( tokenAddress , ownerAddress , spenderAddress ) ;
148
+ return this . erc20Wrapper . allowance (
149
+ tokenAddress ,
150
+ ownerAddress ,
151
+ spenderAddress ,
152
+ callerAddress
153
+ ) ;
125
154
}
126
155
127
156
/**
@@ -140,13 +169,19 @@ export default class ERC20API {
140
169
to : Address ,
141
170
value : BigNumber ,
142
171
callerAddress : Address = undefined ,
143
- txOpts : TransactionOverrides = { } ,
172
+ txOpts : TransactionOverrides = { }
144
173
) : Promise < ContractTransaction > {
145
174
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
146
175
this . assert . schema . isValidAddress ( 'toAddress' , to ) ;
147
176
this . assert . schema . isValidNumber ( 'value' , value ) ;
148
177
149
- return await this . erc20Wrapper . transfer ( tokenAddress , to , value , callerAddress , txOpts ) ;
178
+ return await this . erc20Wrapper . transfer (
179
+ tokenAddress ,
180
+ to ,
181
+ value ,
182
+ callerAddress ,
183
+ txOpts
184
+ ) ;
150
185
}
151
186
152
187
/**
@@ -170,7 +205,13 @@ export default class ERC20API {
170
205
this . assert . schema . isValidAddress ( 'spenderAddress' , spenderAddress ) ;
171
206
this . assert . schema . isValidNumber ( 'value' , value ) ;
172
207
173
- return this . erc20Wrapper . approve ( tokenAddress , spenderAddress , value , callerAddress , txOpts ) ;
208
+ return this . erc20Wrapper . approve (
209
+ tokenAddress ,
210
+ spenderAddress ,
211
+ value ,
212
+ callerAddress ,
213
+ txOpts
214
+ ) ;
174
215
}
175
216
176
217
/**
@@ -190,13 +231,20 @@ export default class ERC20API {
190
231
to : Address ,
191
232
value : BigNumber ,
192
233
callerAddress : Address = undefined ,
193
- txOpts : TransactionOverrides = { } ,
234
+ txOpts : TransactionOverrides = { }
194
235
) : Promise < ContractTransaction > {
195
236
this . assert . schema . isValidAddress ( 'tokenAddress' , tokenAddress ) ;
196
237
this . assert . schema . isValidAddress ( 'toAddress' , to ) ;
197
238
this . assert . schema . isValidAddress ( 'fromAddress' , from ) ;
198
239
this . assert . schema . isValidNumber ( 'value' , value ) ;
199
240
200
- return this . erc20Wrapper . transferFrom ( tokenAddress , from , to , value , callerAddress , txOpts ) ;
241
+ return this . erc20Wrapper . transferFrom (
242
+ tokenAddress ,
243
+ from ,
244
+ to ,
245
+ value ,
246
+ callerAddress ,
247
+ txOpts
248
+ ) ;
201
249
}
202
250
}
0 commit comments