-
Notifications
You must be signed in to change notification settings - Fork 595
/
ExchangerWithVirtualSynth.sol
55 lines (43 loc) · 2 KB
/
ExchangerWithVirtualSynth.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
pragma solidity ^0.5.16;
// Inheritance
import "./Exchanger.sol";
// Internal references
import "./interfaces/IVirtualSynth.sol";
import "./MinimalProxyFactory.sol";
import "./VirtualSynth.sol";
// https://docs.synthetix.io/contracts/source/contracts/exchangerwithvirtualsynth
contract ExchangerWithVirtualSynth is MinimalProxyFactory, Exchanger {
constructor(address _owner, address _resolver) public MinimalProxyFactory() Exchanger(_owner, _resolver) {}
/* ========== ADDRESS RESOLVER CONFIGURATION ========== */
bytes32 private constant CONTRACT_VIRTUALSYNTH_MASTERCOPY = "VirtualSynthMastercopy";
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
bytes32[] memory existingAddresses = Exchanger.resolverAddressesRequired();
bytes32[] memory newAddresses = new bytes32[](1);
newAddresses[0] = CONTRACT_VIRTUALSYNTH_MASTERCOPY;
addresses = combineArrays(existingAddresses, newAddresses);
}
/* ========== INTERNAL FUNCTIONS ========== */
function _virtualSynthMastercopy() internal view returns (address) {
return requireAndGetAddress(CONTRACT_VIRTUALSYNTH_MASTERCOPY);
}
function _createVirtualSynth(
IERC20 synth,
address recipient,
uint amount,
bytes32 currencyKey
) internal returns (IVirtualSynth) {
// prevent inverse synths from being allowed due to purgeability
require(currencyKey[0] != 0x69, "Cannot virtualize this synth");
VirtualSynth vSynth = VirtualSynth(_cloneAsMinimalProxy(_virtualSynthMastercopy(), "Could not create new vSynth"));
vSynth.initialize(synth, resolver, recipient, amount, currencyKey);
emit VirtualSynthCreated(address(synth), recipient, address(vSynth), currencyKey, amount);
return IVirtualSynth(address(vSynth));
}
event VirtualSynthCreated(
address indexed synth,
address indexed recipient,
address vSynth,
bytes32 currencyKey,
uint amount
);
}