This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
GelatoExecutors.sol
80 lines (68 loc) · 2.81 KB
/
GelatoExecutors.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;
import {IGelatoExecutors} from "./interfaces/IGelatoExecutors.sol";
import {GelatoProviders} from "./GelatoProviders.sol";
import {Address} from "../external/Address.sol";
import {SafeMath} from "../external/SafeMath.sol";
import {Math} from "../external/Math.sol";
/// @title GelatoExecutors
/// @author Luis Schliesske & Hilmar Orth
/// @notice Stake Management of executors & batch Unproving providers
/// @dev Find all NatSpecs inside IGelatoExecutors
abstract contract GelatoExecutors is IGelatoExecutors, GelatoProviders {
using Address for address payable; /// for sendValue method
using SafeMath for uint256;
// Executor De/Registrations and Staking
function stakeExecutor() external payable override {
uint256 currentStake = executorStake[msg.sender];
uint256 newStake = currentStake + msg.value;
require(
newStake >= minExecutorStake,
"GelatoExecutors.stakeExecutor: below minStake"
);
executorStake[msg.sender] = newStake;
emit LogExecutorStaked(msg.sender, currentStake, newStake);
}
function unstakeExecutor() external override {
require(
!isExecutorAssigned(msg.sender),
"GelatoExecutors.unstakeExecutor: msg.sender still assigned"
);
uint256 unbondedStake = executorStake[msg.sender];
require(
unbondedStake != 0,
"GelatoExecutors.unstakeExecutor: already unstaked"
);
delete executorStake[msg.sender];
msg.sender.sendValue(unbondedStake);
emit LogExecutorUnstaked(msg.sender);
}
function withdrawExcessExecutorStake(uint256 _withdrawAmount)
external
override
returns(uint256 realWithdrawAmount)
{
require(
isExecutorMinStaked(msg.sender),
"GelatoExecutors.withdrawExcessExecutorStake: not minStaked"
);
uint256 currentExecutorStake = executorStake[msg.sender];
uint256 excessExecutorStake = currentExecutorStake - minExecutorStake;
realWithdrawAmount = Math.min(_withdrawAmount, excessExecutorStake);
uint256 newExecutorStake = currentExecutorStake - realWithdrawAmount;
// Effects
executorStake[msg.sender] = newExecutorStake;
// Interaction
msg.sender.sendValue(realWithdrawAmount);
emit LogExecutorBalanceWithdrawn(msg.sender, realWithdrawAmount);
}
// To unstake, Executors must reassign ALL their Providers to another staked Executor
function multiReassignProviders(address[] calldata _providers, address _newExecutor)
external
override
{
for (uint i; i < _providers.length; i++)
executorAssignsExecutor(_providers[i], _newExecutor);
}
}