forked from Synthetixio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiCollateralSynth.sol
87 lines (70 loc) · 3.21 KB
/
MultiCollateralSynth.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
pragma solidity ^0.5.16;
// Inheritance
import "./Synth.sol";
// Internal references
import "./interfaces/ICollateralManager.sol";
import "./interfaces/IEtherWrapper.sol";
import "./interfaces/IWrapperFactory.sol";
// https://docs.synthetix.io/contracts/source/contracts/multicollateralsynth
contract MultiCollateralSynth is Synth {
bytes32 public constant CONTRACT_NAME = "MultiCollateralSynth";
/* ========== ADDRESS RESOLVER CONFIGURATION ========== */
bytes32 private constant CONTRACT_COLLATERALMANAGER = "CollateralManager";
bytes32 private constant CONTRACT_ETHER_WRAPPER = "EtherWrapper";
bytes32 private constant CONTRACT_WRAPPER_FACTORY = "WrapperFactory";
/* ========== CONSTRUCTOR ========== */
constructor(
address payable _proxy,
TokenState _tokenState,
string memory _tokenName,
string memory _tokenSymbol,
address _owner,
bytes32 _currencyKey,
uint _totalSupply,
address _resolver
) public Synth(_proxy, _tokenState, _tokenName, _tokenSymbol, _owner, _currencyKey, _totalSupply, _resolver) {}
/* ========== VIEWS ======================= */
function collateralManager() internal view returns (ICollateralManager) {
return ICollateralManager(requireAndGetAddress(CONTRACT_COLLATERALMANAGER));
}
function etherWrapper() internal view returns (IEtherWrapper) {
return IEtherWrapper(requireAndGetAddress(CONTRACT_ETHER_WRAPPER));
}
function wrapperFactory() internal view returns (IWrapperFactory) {
return IWrapperFactory(requireAndGetAddress(CONTRACT_WRAPPER_FACTORY));
}
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
bytes32[] memory existingAddresses = Synth.resolverAddressesRequired();
bytes32[] memory newAddresses = new bytes32[](3);
newAddresses[0] = CONTRACT_COLLATERALMANAGER;
newAddresses[1] = CONTRACT_ETHER_WRAPPER;
newAddresses[2] = CONTRACT_WRAPPER_FACTORY;
addresses = combineArrays(existingAddresses, newAddresses);
}
/* ========== MUTATIVE FUNCTIONS ========== */
/**
* @notice Function that allows multi Collateral to issue a certain number of synths from an account.
* @param account Account to issue synths to
* @param amount Number of synths
*/
function issue(address account, uint amount) external onlyInternalContracts {
super._internalIssue(account, amount);
}
/**
* @notice Function that allows multi Collateral to burn a certain number of synths from an account.
* @param account Account to burn synths from
* @param amount Number of synths
*/
function burn(address account, uint amount) external onlyInternalContracts {
super._internalBurn(account, amount);
}
/* ========== MODIFIERS ========== */
// overriding modifier from super to add more internal contracts and checks
function _isInternalContract(address account) internal view returns (bool) {
return
super._isInternalContract(account) ||
collateralManager().hasCollateral(account) ||
wrapperFactory().isWrapper(account) ||
(account == address(etherWrapper()));
}
}