-
Notifications
You must be signed in to change notification settings - Fork 594
/
SynthetixStateWithLimitedSetup.sol
99 lines (78 loc) · 3.67 KB
/
SynthetixStateWithLimitedSetup.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
88
89
90
91
92
93
94
95
96
97
98
99
pragma solidity ^0.5.16;
// Inheritance
import "./LimitedSetup.sol";
import "./SynthetixState.sol";
// Internal References
import "./interfaces/IFeePool.sol";
// https://docs.synthetix.io/contracts/source/contracts/synthetixstate
contract SynthetixStateWithLimitedSetup is SynthetixState, LimitedSetup {
IFeePool public feePool;
// Import state
uint public importedDebtAmount;
constructor(address _owner, address _associatedContract)
public
SynthetixState(_owner, _associatedContract)
LimitedSetup(1 weeks)
{}
/* ========== SETTERS ========== */
/**
* @notice set the FeePool contract as it is the only authority to be able to call
* appendVestingEntry with the onlyFeePool modifer
*/
function setFeePool(IFeePool _feePool) external onlyOwner {
feePool = _feePool;
emit FeePoolUpdated(address(_feePool));
}
// /**
// * @notice Import issuer data
// * @dev Only callable by the contract owner, and only for 1 week after deployment.
// */
function importIssuerData(address[] calldata accounts, uint[] calldata sUSDAmounts) external onlyOwner onlyDuringSetup {
require(accounts.length == sUSDAmounts.length, "Length mismatch");
for (uint8 i = 0; i < accounts.length; i++) {
_addToDebtRegister(accounts[i], sUSDAmounts[i]);
}
}
// /**
// * @notice Import issuer debt data
// * @dev Only used from importIssuerData above, meant to be disposable
// */
function _addToDebtRegister(address account, uint amount) internal {
// What is the value that we've previously imported?
uint totalDebtIssued = importedDebtAmount;
// What will the new total be including the new value?
uint newTotalDebtIssued = amount.add(totalDebtIssued);
// Save that for the next import.
importedDebtAmount = newTotalDebtIssued;
// What is their percentage (as a high precision int) of the total debt?
uint debtPercentage = amount.divideDecimalRoundPrecise(newTotalDebtIssued);
// And what effect does this percentage change have on the global debt holding of other issuers?
// The delta specifically needs to not take into account any existing debt as it's already
// accounted for in the delta from when they issued previously.
// The delta is a high precision integer.
uint delta = SafeDecimalMath.preciseUnit().sub(debtPercentage);
// We ignore any existingDebt as this is being imported in as amount
// Are they a new issuer? If so, record them. (same as incrementTotalIssuerCount)
if (issuanceData[account].initialDebtOwnership == 0) {
totalIssuerCount = totalIssuerCount.add(1);
}
// Save the debt entry parameters (same as setCurrentIssuanceData)
issuanceData[account].initialDebtOwnership = debtPercentage;
issuanceData[account].debtEntryIndex = debtLedger.length;
// And if we're the first, push 1 as there was no effect to any other holders, otherwise push
// the change for the rest of the debt holders. The debt ledger holds high precision integers.
if (debtLedger.length > 0) {
debtLedger.push(debtLedger[debtLedger.length - 1].multiplyDecimalRoundPrecise(delta));
} else {
debtLedger.push(SafeDecimalMath.preciseUnit());
}
// append issuanceData to FeePoolState
feePool.appendAccountIssuanceRecord(
account,
issuanceData[account].initialDebtOwnership,
issuanceData[account].debtEntryIndex
);
}
/* ========== EVENTS ========== */
event FeePoolUpdated(address newFeePool);
}