/
ImportableRewardEscrowV2.sol
66 lines (51 loc) · 2.53 KB
/
ImportableRewardEscrowV2.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 "./BaseRewardEscrowV2.sol";
// https://docs.peri.finance/contracts/RewardEscrow
contract ImportableRewardEscrowV2 is BaseRewardEscrowV2 {
/* ========== ADDRESS RESOLVER CONFIGURATION ========== */
bytes32 private constant CONTRACT_PERIFINANCE_BRIDGE_BASE = "PeriFinanceBridgeToBase";
/* ========== CONSTRUCTOR ========== */
constructor(address _owner, address _resolver) public BaseRewardEscrowV2(_owner, _resolver) {}
/* ========== VIEWS ======================= */
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
bytes32[] memory existingAddresses = BaseRewardEscrowV2.resolverAddressesRequired();
bytes32[] memory newAddresses = new bytes32[](1);
newAddresses[0] = CONTRACT_PERIFINANCE_BRIDGE_BASE;
return combineArrays(existingAddresses, newAddresses);
}
function periFinanceBridgeToBase() internal view returns (address) {
return requireAndGetAddress(CONTRACT_PERIFINANCE_BRIDGE_BASE);
}
/* ========== MUTATIVE FUNCTIONS ========== */
function importVestingEntries(
address account,
uint256 escrowedAmount,
VestingEntries.VestingEntry[] calldata vestingEntries
) external onlyPeriFinanceBridge {
// There must be enough balance in the contract to provide for the escrowed balance.
totalEscrowedBalance = totalEscrowedBalance.add(escrowedAmount);
require(
totalEscrowedBalance <= IERC20(address(periFinance())).balanceOf(address(this)),
"Insufficient balance in the contract to provide for escrowed balance"
);
/* Add escrowedAmount to account's escrowed balance */
totalEscrowedAccountBalance[account] = totalEscrowedAccountBalance[account].add(escrowedAmount);
for (uint i = 0; i < vestingEntries.length; i++) {
_importVestingEntry(account, vestingEntries[i]);
}
}
function _importVestingEntry(address account, VestingEntries.VestingEntry memory entry) internal {
uint entryID = nextEntryId;
vestingSchedules[account][entryID] = entry;
/* append entryID to list of entries for account */
accountVestingEntryIDs[account].push(entryID);
/* Increment the next entry id. */
nextEntryId = nextEntryId.add(1);
}
modifier onlyPeriFinanceBridge() {
require(msg.sender == periFinanceBridgeToBase(), "Can only be invoked by PeriFinanceBridgeToBase contract");
_;
}
}