forked from Synthetixio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRewardEscrowV2.sol
82 lines (60 loc) · 3.02 KB
/
RewardEscrowV2.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
pragma solidity ^0.5.16;
pragma experimental ABIEncoderV2;
// Inheritance
import "./BaseRewardEscrowV2.sol";
// Internal references
import "./interfaces/IRewardEscrow.sol";
// https://docs.synthetix.io/contracts/RewardEscrow
contract RewardEscrowV2 is BaseRewardEscrowV2 {
/* ========== ADDRESS RESOLVER CONFIGURATION ========== */
bytes32 private constant CONTRACT_SYNTHETIX_BRIDGE_OPTIMISM = "SynthetixBridgeToOptimism";
/* ========== 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_SYNTHETIX_BRIDGE_OPTIMISM;
return combineArrays(existingAddresses, newAddresses);
}
function synthetixBridgeToOptimism() internal view returns (address) {
return requireAndGetAddress(CONTRACT_SYNTHETIX_BRIDGE_OPTIMISM);
}
/* ========== L2 MIGRATION ========== */
function burnForMigration(address account, uint[] calldata entryIDs)
external
onlySynthetixBridge
returns (uint256 escrowedAccountBalance, VestingEntries.VestingEntry[] memory vestingEntries)
{
require(entryIDs.length > 0, "Entry IDs required");
vestingEntries = new VestingEntries.VestingEntry[](entryIDs.length);
for (uint i = 0; i < entryIDs.length; i++) {
VestingEntries.VestingEntry memory entry = vestingSchedules(account, entryIDs[i]);
// only unvested
if (entry.escrowAmount > 0) {
vestingEntries[i] = entry;
/* add the escrow amount to escrowedAccountBalance */
escrowedAccountBalance = escrowedAccountBalance.add(entry.escrowAmount);
/* Delete the vesting entry being migrated */
state().setZeroAmount(account, entryIDs[i]);
}
}
/**
* update account total escrow balances for migration
* transfer the escrowed SNX being migrated to the L2 deposit contract
*/
if (escrowedAccountBalance > 0) {
state().updateEscrowAccountBalance(account, -SafeCast.toInt256(escrowedAccountBalance));
synthetixERC20().transfer(synthetixBridgeToOptimism(), escrowedAccountBalance);
}
emit BurnedForMigrationToL2(account, entryIDs, escrowedAccountBalance, block.timestamp);
return (escrowedAccountBalance, vestingEntries);
}
/* ========== MODIFIERS ========== */
modifier onlySynthetixBridge() {
require(msg.sender == synthetixBridgeToOptimism(), "Can only be invoked by SynthetixBridgeToOptimism contract");
_;
}
/* ========== EVENTS ========== */
event BurnedForMigrationToL2(address indexed account, uint[] entryIDs, uint escrowedAmountMigrated, uint time);
}