@lazy-sol/access-control 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,443 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.4.11;
3
+
4
+ /**
5
+ * Tether Token (USDT)
6
+ * Source code copied from
7
+ * https://gist.githubusercontent.com/plutoegg/a8794a24dfa84d0b0104141612b52977/raw/2e3540bc52567002ee143e3ecc783dafefb3f988/TetherToken.sol
8
+ */
9
+
10
+ /**
11
+ * Math operations with safety checks
12
+ */
13
+ library SafeMath {
14
+ function mul(uint a, uint b) internal returns (uint) {
15
+ uint c = a * b;
16
+ assert(a == 0 || c / a == b);
17
+ return c;
18
+ }
19
+
20
+ function div(uint a, uint b) internal returns (uint) {
21
+ // assert(b > 0); // Solidity automatically throws when dividing by 0
22
+ uint c = a / b;
23
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
24
+ return c;
25
+ }
26
+
27
+ function sub(uint a, uint b) internal returns (uint) {
28
+ assert(b <= a);
29
+ return a - b;
30
+ }
31
+
32
+ function add(uint a, uint b) internal returns (uint) {
33
+ uint c = a + b;
34
+ assert(c >= a);
35
+ return c;
36
+ }
37
+
38
+ function max64(uint64 a, uint64 b) internal constant returns (uint64) {
39
+ return a >= b ? a : b;
40
+ }
41
+
42
+ function min64(uint64 a, uint64 b) internal constant returns (uint64) {
43
+ return a < b ? a : b;
44
+ }
45
+
46
+ function max256(uint256 a, uint256 b) internal constant returns (uint256) {
47
+ return a >= b ? a : b;
48
+ }
49
+
50
+ function min256(uint256 a, uint256 b) internal constant returns (uint256) {
51
+ return a < b ? a : b;
52
+ }
53
+
54
+ function assert(bool assertion) internal {
55
+ if (!assertion) {
56
+ throw;
57
+ }
58
+ }
59
+ }
60
+
61
+
62
+ /**
63
+ * @title Ownable
64
+ * @dev The Ownable contract has an owner address, and provides basic authorization control
65
+ * functions, this simplifies the implementation of "user permissions".
66
+ */
67
+ contract Ownable {
68
+ address public owner;
69
+
70
+
71
+ /**
72
+ * @dev The Ownable constructor sets the original `owner` of the contract to the sender
73
+ * account.
74
+ */
75
+ function Ownable() {
76
+ owner = msg.sender;
77
+ }
78
+
79
+
80
+ /**
81
+ * @dev Throws if called by any account other than the owner.
82
+ */
83
+ modifier onlyOwner() {
84
+ if (msg.sender != owner) {
85
+ throw;
86
+ }
87
+ _;
88
+ }
89
+
90
+
91
+ /**
92
+ * @dev Allows the current owner to transfer control of the contract to a newOwner.
93
+ * @param newOwner The address to transfer ownership to.
94
+ */
95
+ function transferOwnership(address newOwner) onlyOwner {
96
+ if (newOwner != address(0)) {
97
+ owner = newOwner;
98
+ }
99
+ }
100
+
101
+ }
102
+
103
+ /**
104
+ * @title Pausable
105
+ * @dev Base contract which allows children to implement an emergency stop mechanism.
106
+ */
107
+ contract Pausable is Ownable {
108
+ event Pause();
109
+ event Unpause();
110
+
111
+ bool public paused = false;
112
+
113
+
114
+ /**
115
+ * @dev modifier to allow actions only when the contract IS paused
116
+ */
117
+ modifier whenNotPaused() {
118
+ if (paused) throw;
119
+ _;
120
+ }
121
+
122
+ /**
123
+ * @dev modifier to allow actions only when the contract IS NOT paused
124
+ */
125
+ modifier whenPaused {
126
+ if (!paused) throw;
127
+ _;
128
+ }
129
+
130
+ /**
131
+ * @dev called by the owner to pause, triggers stopped state
132
+ */
133
+ function pause() onlyOwner whenNotPaused returns (bool) {
134
+ paused = true;
135
+ Pause();
136
+ return true;
137
+ }
138
+
139
+ /**
140
+ * @dev called by the owner to unpause, returns to normal state
141
+ */
142
+ function unpause() onlyOwner whenPaused returns (bool) {
143
+ paused = false;
144
+ Unpause();
145
+ return true;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @title ERC20Basic
151
+ * @dev Simpler version of ERC20 interface
152
+ * @dev see https://github.com/ethereum/EIPs/issues/20
153
+ */
154
+ contract ERC20Basic {
155
+ uint public _totalSupply;
156
+ function totalSupply() constant returns (uint);
157
+ function balanceOf(address who) constant returns (uint);
158
+ function transfer(address to, uint value);
159
+ event Transfer(address indexed from, address indexed to, uint value);
160
+ }
161
+
162
+ /**
163
+ * @title ERC20 interface
164
+ * @dev see https://github.com/ethereum/EIPs/issues/20
165
+ */
166
+ contract ERC20 is ERC20Basic {
167
+ function allowance(address owner, address spender) constant returns (uint);
168
+ function transferFrom(address from, address to, uint value);
169
+ function approve(address spender, uint value);
170
+ event Approval(address indexed owner, address indexed spender, uint value);
171
+ }
172
+
173
+ /**
174
+ * @title Basic token
175
+ * @dev Basic version of StandardToken, with no allowances.
176
+ */
177
+ contract BasicToken is Ownable, ERC20Basic {
178
+ using SafeMath for uint;
179
+
180
+ mapping(address => uint) balances;
181
+
182
+ // additional variables for use if transaction fees ever became necessary
183
+ uint public basisPointsRate = 0;
184
+ uint public maximumFee = 0;
185
+
186
+ /**
187
+ * @dev Fix for the ERC20 short address attack.
188
+ */
189
+ modifier onlyPayloadSize(uint size) {
190
+ if(msg.data.length < size + 4) {
191
+ throw;
192
+ }
193
+ _;
194
+ }
195
+
196
+ /**
197
+ * @dev transfer token for a specified address
198
+ * @param _to The address to transfer to.
199
+ * @param _value The amount to be transferred.
200
+ */
201
+ function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) {
202
+ uint fee = (_value.mul(basisPointsRate)).div(10000);
203
+ if (fee > maximumFee) {
204
+ fee = maximumFee;
205
+ }
206
+ uint sendAmount = _value.sub(fee);
207
+ balances[msg.sender] = balances[msg.sender].sub(_value);
208
+ balances[_to] = balances[_to].add(sendAmount);
209
+ balances[owner] = balances[owner].add(fee);
210
+ Transfer(msg.sender, _to, sendAmount);
211
+ Transfer(msg.sender, owner, fee);
212
+ }
213
+
214
+ /**
215
+ * @dev Gets the balance of the specified address.
216
+ * @param _owner The address to query the the balance of.
217
+ * @return An uint representing the amount owned by the passed address.
218
+ */
219
+ function balanceOf(address _owner) constant returns (uint balance) {
220
+ return balances[_owner];
221
+ }
222
+
223
+ }
224
+
225
+
226
+ /**
227
+ * @title Standard ERC20 token
228
+ *
229
+ * @dev Implementation of the basic standard token.
230
+ * @dev https://github.com/ethereum/EIPs/issues/20
231
+ * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
232
+ */
233
+ contract StandardToken is BasicToken, ERC20 {
234
+
235
+ mapping (address => mapping (address => uint)) allowed;
236
+
237
+ uint constant MAX_UINT = 2**256 - 1;
238
+
239
+ /**
240
+ * @dev Transfer tokens from one address to another
241
+ * @param _from address The address which you want to send tokens from
242
+ * @param _to address The address which you want to transfer to
243
+ * @param _value uint the amount of tokens to be transferred
244
+ */
245
+ function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) {
246
+ var _allowance = allowed[_from][msg.sender];
247
+
248
+ // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
249
+ // if (_value > _allowance) throw;
250
+
251
+ uint fee = (_value.mul(basisPointsRate)).div(10000);
252
+ if (fee > maximumFee) {
253
+ fee = maximumFee;
254
+ }
255
+ uint sendAmount = _value.sub(fee);
256
+
257
+ balances[_to] = balances[_to].add(sendAmount);
258
+ balances[owner] = balances[owner].add(fee);
259
+ balances[_from] = balances[_from].sub(_value);
260
+ if (_allowance < MAX_UINT) {
261
+ allowed[_from][msg.sender] = _allowance.sub(_value);
262
+ }
263
+ Transfer(_from, _to, sendAmount);
264
+ Transfer(_from, owner, fee);
265
+ }
266
+
267
+ /**
268
+ * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
269
+ * @param _spender The address which will spend the funds.
270
+ * @param _value The amount of tokens to be spent.
271
+ */
272
+ function approve(address _spender, uint _value) onlyPayloadSize(2 * 32) {
273
+
274
+ // To change the approve amount you first have to reduce the addresses`
275
+ // allowance to zero by calling `approve(_spender, 0)` if it is not
276
+ // already 0 to mitigate the race condition described here:
277
+ // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
278
+ if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
279
+
280
+ allowed[msg.sender][_spender] = _value;
281
+ Approval(msg.sender, _spender, _value);
282
+ }
283
+
284
+ /**
285
+ * @dev Function to check the amount of tokens than an owner allowed to a spender.
286
+ * @param _owner address The address which owns the funds.
287
+ * @param _spender address The address which will spend the funds.
288
+ * @return A uint specifying the amount of tokens still available for the spender.
289
+ */
290
+ function allowance(address _owner, address _spender) constant returns (uint remaining) {
291
+ return allowed[_owner][_spender];
292
+ }
293
+
294
+ }
295
+
296
+ contract UpgradedStandardToken is StandardToken{
297
+ // those methods are called by the legacy contract
298
+ // and they must ensure msg.sender to be the contract address
299
+ function transferByLegacy(address from, address to, uint value);
300
+ function transferFromByLegacy(address sender, address from, address spender, uint value);
301
+ function approveByLegacy(address from, address spender, uint value);
302
+ }
303
+
304
+
305
+ /// @title - Tether Token Contract - Tether.to
306
+ /// @author Enrico Rubboli - <enrico@bitfinex.com>
307
+ /// @author Will Harborne - <will@ethfinex.com>
308
+
309
+ contract TetherToken is Pausable, StandardToken {
310
+
311
+ string public name;
312
+ string public symbol;
313
+ uint public decimals;
314
+ address public upgradedAddress;
315
+ bool public deprecated;
316
+
317
+ // The contract can be initialized with a number of tokens
318
+ // All the tokens are deposited to the owner address
319
+ //
320
+ // @param _balance Initial supply of the contract
321
+ // @param _name Token Name
322
+ // @param _symbol Token symbol
323
+ // @param _decimals Token decimals
324
+ function TetherToken(uint _initialSupply, string _name, string _symbol, uint _decimals){
325
+ _totalSupply = _initialSupply;
326
+ name = _name;
327
+ symbol = _symbol;
328
+ decimals = _decimals;
329
+ balances[owner] = _initialSupply;
330
+ deprecated = false;
331
+ }
332
+
333
+ // Forward ERC20 methods to upgraded contract if this one is deprecated
334
+ function transfer(address _to, uint _value) whenNotPaused {
335
+ if (deprecated) {
336
+ return UpgradedStandardToken(upgradedAddress).transferByLegacy(msg.sender, _to, _value);
337
+ } else {
338
+ return super.transfer(_to, _value);
339
+ }
340
+ }
341
+
342
+ // Forward ERC20 methods to upgraded contract if this one is deprecated
343
+ function transferFrom(address _from, address _to, uint _value) whenNotPaused {
344
+ if (deprecated) {
345
+ return UpgradedStandardToken(upgradedAddress).transferFromByLegacy(msg.sender, _from, _to, _value);
346
+ } else {
347
+ return super.transferFrom(_from, _to, _value);
348
+ }
349
+ }
350
+
351
+ // Forward ERC20 methods to upgraded contract if this one is deprecated
352
+ function balanceOf(address who) constant returns (uint){
353
+ if (deprecated) {
354
+ return UpgradedStandardToken(upgradedAddress).balanceOf(who);
355
+ } else {
356
+ return super.balanceOf(who);
357
+ }
358
+ }
359
+
360
+ // Forward ERC20 methods to upgraded contract if this one is deprecated
361
+ function approve(address _spender, uint _value) onlyPayloadSize(2 * 32) {
362
+ if (deprecated) {
363
+ return UpgradedStandardToken(upgradedAddress).approveByLegacy(msg.sender, _spender, _value);
364
+ } else {
365
+ return super.approve(_spender, _value);
366
+ }
367
+ }
368
+
369
+ // Forward ERC20 methods to upgraded contract if this one is deprecated
370
+ function allowance(address _owner, address _spender) constant returns (uint remaining) {
371
+ if (deprecated) {
372
+ return StandardToken(upgradedAddress).allowance(_owner, _spender);
373
+ } else {
374
+ return super.allowance(_owner, _spender);
375
+ }
376
+ }
377
+
378
+ // deprecate current contract in favour of a new one
379
+ function deprecate(address _upgradedAddress) onlyOwner {
380
+ deprecated = true;
381
+ upgradedAddress = _upgradedAddress;
382
+ Deprecate(_upgradedAddress);
383
+ }
384
+
385
+ // deprecate current contract if favour of a new one
386
+ function totalSupply() constant returns (uint){
387
+ if (deprecated) {
388
+ return StandardToken(upgradedAddress).totalSupply();
389
+ } else {
390
+ return _totalSupply;
391
+ }
392
+ }
393
+
394
+ // Issue a new amount of tokens
395
+ // these tokens are deposited into the owner address
396
+ //
397
+ // @param _amount Number of tokens to be issued
398
+ function issue(uint amount) onlyOwner {
399
+ if (_totalSupply + amount < _totalSupply) throw;
400
+ if (balances[owner] + amount < balances[owner]) throw;
401
+
402
+ balances[owner] += amount;
403
+ _totalSupply += amount;
404
+ Issue(amount);
405
+ }
406
+
407
+ // Redeem tokens.
408
+ // These tokens are withdrawn from the owner address
409
+ // if the balance must be enough to cover the redeem
410
+ // or the call will fail.
411
+ // @param _amount Number of tokens to be issued
412
+ function redeem(uint amount) onlyOwner {
413
+ if (_totalSupply < amount) throw;
414
+ if (balances[owner] < amount) throw;
415
+
416
+ _totalSupply -= amount;
417
+ balances[owner] -= amount;
418
+ Redeem(amount);
419
+ }
420
+
421
+ function setParams(uint newBasisPoints, uint newMaxFee) onlyOwner {
422
+ // Ensure transparency by hardcoding limit beyond which fees can never be added
423
+ if (newBasisPoints > 20) throw;
424
+ if (newMaxFee > 50) throw;
425
+
426
+ basisPointsRate = newBasisPoints;
427
+ maximumFee = newMaxFee.mul(10**decimals);
428
+
429
+ Params(basisPointsRate, maximumFee);
430
+ }
431
+
432
+ // Called when new token are issued
433
+ event Issue(uint amount);
434
+
435
+ // Called when tokens are redeemed
436
+ event Redeem(uint amount);
437
+
438
+ // Called when contract is deprecated
439
+ event Deprecate(address newAddress);
440
+
441
+ // Called if contract ever adds fees
442
+ event Params(uint feeBasisPoints, uint maxFee);
443
+ }
@@ -0,0 +1,59 @@
1
+ // deploy: npx hardhat deploy --network goerli --tags AdapterFactory
2
+ // verify: npx hardhat etherscan-verify --network goerli --api-key $ETHERSCAN_KEY
3
+
4
+ // script is built for hardhat-deploy plugin:
5
+ // A Hardhat Plugin For Replicable Deployments And Easy Testing
6
+ // https://www.npmjs.com/package/hardhat-deploy
7
+
8
+ // deployment utils (contract state printers)
9
+ const {
10
+ print_amt,
11
+ print_contract_details,
12
+ } = require("@lazy-sol/a-missing-jem/deployment_utils");
13
+
14
+ // to be picked up and executed by hardhat-deploy plugin
15
+ module.exports = async function({deployments, getChainId, getNamedAccounts, getUnnamedAccounts}) {
16
+ // print some useful info on the account we're using for the deployment
17
+ const chainId = await getChainId();
18
+ const accounts = await web3.eth.getAccounts();
19
+ // do not use the default account for tests
20
+ const A0 = network.name === "hardhat"? accounts[1]: accounts[0];
21
+ const nonce = await web3.eth.getTransactionCount(A0);
22
+ const balance = await web3.eth.getBalance(A0);
23
+
24
+ // print initial debug information
25
+ console.log("script: %o", require("path").basename(__filename));
26
+ console.log("network %o %o", chainId, network.name);
27
+ console.log("accounts: %o, service account %o, nonce: %o, balance: %o ETH", accounts.length, A0, nonce, print_amt(balance));
28
+
29
+ // AdapterFactory
30
+ {
31
+ // deploy if required
32
+ await deployments.deploy("AdapterFactory", {
33
+ // address (or private key) that will perform the transaction.
34
+ // you can use `getNamedAccounts` to retrieve the address you want by name.
35
+ from: A0,
36
+ contract: "AdapterFactory",
37
+ // the list of argument for the constructor (or the upgrade function in case of proxy)
38
+ // args: [],
39
+ // if set it to true, will not attempt to deploy even if the contract deployed under the same name is different
40
+ skipIfAlreadyDeployed: true,
41
+ // if true, it will log the result of the deployment (tx hash, address and gas used)
42
+ log: true,
43
+ });
44
+
45
+ // get the deployment details
46
+ const deployment = await deployments.get("AdapterFactory");
47
+ const contract = new web3.eth.Contract(deployment.abi, deployment.address);
48
+
49
+ // print the deployment details
50
+ await print_contract_details(A0, deployment.abi, deployment.address);
51
+ }
52
+ };
53
+
54
+ // Tags represent what the deployment script acts on. In general, it will be a single string value,
55
+ // the name of the contract it deploys or modifies.
56
+ // Then if another deploy script has such tag as a dependency, then when the latter deploy script has a specific tag
57
+ // and that tag is requested, the dependency will be executed first.
58
+ // https://www.npmjs.com/package/hardhat-deploy#deploy-scripts-tags-and-dependencies
59
+ module.exports.tags = ["AdapterFactory", "deploy"];
@@ -0,0 +1 @@
1
+ 5