forked from Synthetixio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMintableSynthetix.sol
66 lines (53 loc) · 2.37 KB
/
MintableSynthetix.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
pragma solidity ^0.5.16;
pragma experimental ABIEncoderV2;
// Inheritance
import "./BaseSynthetix.sol";
// https://docs.synthetix.io/contracts/source/contracts/mintablesynthetix
contract MintableSynthetix is BaseSynthetix {
bytes32 private constant CONTRACT_SYNTHETIX_BRIDGE = "SynthetixBridgeToBase";
constructor(
address payable _proxy,
TokenState _tokenState,
address _owner,
uint _totalSupply,
address _resolver
) public BaseSynthetix(_proxy, _tokenState, _owner, _totalSupply, _resolver) {}
/* ========== INTERNALS =================== */
function _mintSecondary(address account, uint amount) internal {
tokenState.setBalanceOf(account, tokenState.balanceOf(account).add(amount));
emitTransfer(address(this), account, amount);
totalSupply = totalSupply.add(amount);
}
function onlyAllowFromBridge() internal view {
require(msg.sender == synthetixBridge(), "Can only be invoked by bridge");
}
/* ========== MODIFIERS =================== */
modifier onlyBridge() {
onlyAllowFromBridge();
_;
}
/* ========== VIEWS ======================= */
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
bytes32[] memory existingAddresses = BaseSynthetix.resolverAddressesRequired();
bytes32[] memory newAddresses = new bytes32[](1);
newAddresses[0] = CONTRACT_SYNTHETIX_BRIDGE;
addresses = combineArrays(existingAddresses, newAddresses);
}
function synthetixBridge() internal view returns (address) {
return requireAndGetAddress(CONTRACT_SYNTHETIX_BRIDGE);
}
/* ========== RESTRICTED FUNCTIONS ========== */
function mintSecondary(address account, uint amount) external onlyBridge {
_mintSecondary(account, amount);
}
function mintSecondaryRewards(uint amount) external onlyBridge {
IRewardsDistribution _rewardsDistribution = rewardsDistribution();
_mintSecondary(address(_rewardsDistribution), amount);
_rewardsDistribution.distributeRewards(amount);
}
function burnSecondary(address account, uint amount) external onlyBridge systemActive {
tokenState.setBalanceOf(account, tokenState.balanceOf(account).sub(amount));
emitTransfer(account, address(0), amount);
totalSupply = totalSupply.sub(amount);
}
}