-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathPreviousLoanToken.sol
84 lines (71 loc) · 2.66 KB
/
PreviousLoanToken.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
/**
* Copyright 2017-2020, bZeroX, LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0.
*/
pragma solidity 0.5.17;
import "../../connectors/loantoken/AdvancedTokenStorage.sol";
//@todo can I change this proxy to EIP-1822 proxy standard, please. https://eips.ethereum.org/EIPS/eip-1822. It's really hard to work with this.
contract PreviousLoanToken is AdvancedTokenStorage {
// It is important to maintain the variables order so the delegate calls can access sovrynContractAddress and wrbtcTokenAddress
address public sovrynContractAddress;
address public wrbtcTokenAddress;
address internal target_;
constructor(
address _newOwner,
address _newTarget,
address _sovrynContractAddress,
address _wrbtcTokenAddress
) public {
transferOwnership(_newOwner);
_setTarget(_newTarget);
_setSovrynContractAddress(_sovrynContractAddress);
_setWrbtcTokenAddress(_wrbtcTokenAddress);
}
function() external payable {
if (gasleft() <= 2300) {
return;
}
address target = target_;
bytes memory data = msg.data;
assembly {
let result := delegatecall(gas, target, add(data, 0x20), mload(data), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
switch result
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
}
}
function setTarget(address _newTarget) public onlyOwner {
_setTarget(_newTarget);
}
function _setTarget(address _newTarget) internal {
require(Address.isContract(_newTarget), "target not a contract");
target_ = _newTarget;
}
function _setSovrynContractAddress(address _sovrynContractAddress) internal {
require(Address.isContract(_sovrynContractAddress), "sovryn not a contract");
sovrynContractAddress = _sovrynContractAddress;
}
function _setWrbtcTokenAddress(address _wrbtcTokenAddress) internal {
require(Address.isContract(_wrbtcTokenAddress), "wrbtc not a contract");
wrbtcTokenAddress = _wrbtcTokenAddress;
}
//@todo add check for double init, idk but init usually can be called only once.
function initialize(
address _loanTokenAddress,
string memory _name,
string memory _symbol
) public onlyOwner {
loanTokenAddress = _loanTokenAddress;
name = _name;
symbol = _symbol;
decimals = IERC20(loanTokenAddress).decimals();
initialPrice = 10 ** 18; // starting price of 1
}
}