diff --git a/contracts/IBountyV2.sol b/contracts/IBountyV2.sol index 4205072..8770119 100644 --- a/contracts/IBountyV2.sol +++ b/contracts/IBountyV2.sol @@ -22,10 +22,6 @@ pragma solidity >=0.6.10 <0.9.0; interface IBountyV2 { - struct BountyHistory { - uint month; - uint bountyPaid; - } /** * @dev Emitted when bounty reduction is turned on or turned off. diff --git a/contracts/IKeyStorage.sol b/contracts/IKeyStorage.sol index 616b95e..8700f68 100644 --- a/contracts/IKeyStorage.sol +++ b/contracts/IKeyStorage.sol @@ -24,10 +24,6 @@ pragma solidity >=0.6.10 <0.9.0; import "./ISkaleDKG.sol"; interface IKeyStorage { - struct BroadcastedData { - KeyShare[] secretKeyContribution; - ISkaleDKG.G2Point[] verificationVector; - } struct KeyShare { bytes32[2] publicKey; diff --git a/contracts/ISchains.sol b/contracts/ISchains.sol index 4973c75..012a351 100644 --- a/contracts/ISchains.sol +++ b/contracts/ISchains.sol @@ -22,14 +22,7 @@ pragma solidity >=0.6.10 <0.9.0; interface ISchains { - struct SchainParameters { - uint lifetime; - uint8 typeOfSchain; - uint16 nonce; - string name; - address originator; - } - + /** * @dev Emitted when an schain is created. */ diff --git a/contracts/ISkaleDKG.sol b/contracts/ISkaleDKG.sol index 4c83aba..494e9f5 100644 --- a/contracts/ISkaleDKG.sol +++ b/contracts/ISkaleDKG.sol @@ -23,8 +23,6 @@ pragma solidity >=0.6.10 <0.9.0; interface ISkaleDKG { - enum DkgFunction {Broadcast, Alright, ComplaintBadData, PreResponse, Complaint, Response} - struct Fp2Point { uint a; uint b; @@ -62,12 +60,6 @@ interface ISkaleDKG { bytes32[2] publicKey; bytes32 share; } - - struct Context { - bool isDebt; - uint delta; - DkgFunction dkgFunction; - } /** * @dev Emitted when a channel is opened. diff --git a/contracts/delegation/IDelegationController.sol b/contracts/delegation/IDelegationController.sol new file mode 100644 index 0000000..0b5c5fe --- /dev/null +++ b/contracts/delegation/IDelegationController.sol @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + IDelegationController.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface IDelegationController { + enum State { + PROPOSED, + ACCEPTED, + CANCELED, + REJECTED, + DELEGATED, + UNDELEGATION_REQUESTED, + COMPLETED + } + + struct Delegation { + address holder; // address of token owner + uint validatorId; + uint amount; + uint delegationPeriod; + uint created; // time of delegation creation + uint started; // month when a delegation becomes active + uint finished; // first month after a delegation ends + string info; + } + + /** + * @dev Emitted when validator was confiscated. + */ + event Confiscated( + uint indexed validatorId, + uint amount + ); + + /** + * @dev Emitted when validator was confiscated. + */ + event SlashesProcessed( + address indexed holder, + uint limit + ); + + /** + * @dev Emitted when a delegation is proposed to a validator. + */ + event DelegationProposed( + uint delegationId + ); + + /** + * @dev Emitted when a delegation is accepted by a validator. + */ + event DelegationAccepted( + uint delegationId + ); + + /** + * @dev Emitted when a delegation is cancelled by the delegator. + */ + event DelegationRequestCanceledByUser( + uint delegationId + ); + + /** + * @dev Emitted when a delegation is requested to undelegate. + */ + event UndelegationRequested( + uint delegationId + ); + + function getAndUpdateDelegatedToValidatorNow(uint validatorId) external returns (uint); + function getAndUpdateDelegatedAmount(address holder) external returns (uint); + function getAndUpdateEffectiveDelegatedByHolderToValidator(address holder, uint validatorId, uint month) + external + returns (uint effectiveDelegated); + function delegate( + uint validatorId, + uint amount, + uint delegationPeriod, + string calldata info + ) + external; + function cancelPendingDelegation(uint delegationId) external; + function acceptPendingDelegation(uint delegationId) external; + function requestUndelegation(uint delegationId) external; + function confiscate(uint validatorId, uint amount) external; + function getAndUpdateEffectiveDelegatedToValidator(uint validatorId, uint month) external returns (uint); + function getAndUpdateDelegatedByHolderToValidatorNow(address holder, uint validatorId) external returns (uint); + function processSlashes(address holder, uint limit) external; + function processAllSlashes(address holder) external; + function getEffectiveDelegatedValuesByValidator(uint validatorId) external view returns (uint[] memory); + function getEffectiveDelegatedToValidator(uint validatorId, uint month) external view returns (uint); + function getDelegatedToValidator(uint validatorId, uint month) external view returns (uint); + function getDelegation(uint delegationId) external view returns (Delegation memory); + function getFirstDelegationMonth(address holder, uint validatorId) external view returns(uint); + function getDelegationsByValidatorLength(uint validatorId) external view returns (uint); + function getDelegationsByHolderLength(address holder) external view returns (uint); + function getState(uint delegationId) external view returns (State state); + function getLockedInPendingDelegations(address holder) external view returns (uint); + function hasUnprocessedSlashes(address holder) external view returns (bool); +} diff --git a/contracts/delegation/IDelegationPeriodManager.sol b/contracts/delegation/IDelegationPeriodManager.sol new file mode 100644 index 0000000..b20782a --- /dev/null +++ b/contracts/delegation/IDelegationPeriodManager.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + IDelegationPeriodManager.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface IDelegationPeriodManager { + /** + * @dev Emitted when a new delegation period is specified. + */ + event DelegationPeriodWasSet( + uint length, + uint stakeMultiplier + ); + + function setDelegationPeriod(uint monthsCount, uint stakeMultiplier) external; + function isDelegationPeriodAllowed(uint monthsCount) external view returns (bool); +} diff --git a/contracts/delegation/IDistributor.sol b/contracts/delegation/IDistributor.sol new file mode 100644 index 0000000..9988d11 --- /dev/null +++ b/contracts/delegation/IDistributor.sol @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + IDistributor.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface IDistributor { + /** + * @dev Emitted when bounty is withdrawn. + */ + event WithdrawBounty( + address holder, + uint validatorId, + address destination, + uint amount + ); + + /** + * @dev Emitted when a validator fee is withdrawn. + */ + event WithdrawFee( + uint validatorId, + address destination, + uint amount + ); + + /** + * @dev Emitted when bounty is distributed. + */ + event BountyWasPaid( + uint validatorId, + uint amount + ); + + function getAndUpdateEarnedBountyAmount(uint validatorId) external returns (uint earned, uint endMonth); + function withdrawBounty(uint validatorId, address to) external; + function withdrawFee(address to) external; + function getAndUpdateEarnedBountyAmountOf(address wallet, uint validatorId) + external + returns (uint earned, uint endMonth); + function getEarnedFeeAmount() external view returns (uint earned, uint endMonth); + function getEarnedFeeAmountOf(uint validatorId) external view returns (uint earned, uint endMonth); +} diff --git a/contracts/delegation/IPunisher.sol b/contracts/delegation/IPunisher.sol new file mode 100644 index 0000000..afe38c1 --- /dev/null +++ b/contracts/delegation/IPunisher.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + IPunisher.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface IPunisher { + /** + * @dev Emitted upon slashing condition. + */ + event Slash( + uint validatorId, + uint amount + ); + + /** + * @dev Emitted upon forgive condition. + */ + event Forgive( + address wallet, + uint amount + ); + + function slash(uint validatorId, uint amount) external; + function forgive(address holder, uint amount) external; + function handleSlash(address holder, uint amount) external; +} diff --git a/contracts/delegation/ITimeHelpers.sol b/contracts/delegation/ITimeHelpers.sol new file mode 100644 index 0000000..62d594b --- /dev/null +++ b/contracts/delegation/ITimeHelpers.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + ITimeHelpers.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface ITimeHelpers { + function calculateProofOfUseLockEndTime(uint month, uint lockUpPeriodDays) external view returns (uint timestamp); + function getCurrentMonth() external view returns (uint); + function timestampToYear(uint timestamp) external view returns (uint); + function timestampToMonth(uint timestamp) external view returns (uint); + function monthToTimestamp(uint month) external view returns (uint timestamp); + function addDays(uint fromTimestamp, uint n) external pure returns (uint); + function addMonths(uint fromTimestamp, uint n) external pure returns (uint); + function addYears(uint fromTimestamp, uint n) external pure returns (uint); +} diff --git a/contracts/delegation/ITokenState.sol b/contracts/delegation/ITokenState.sol new file mode 100644 index 0000000..3731ecc --- /dev/null +++ b/contracts/delegation/ITokenState.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + ITokenState.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface ITokenState { + /** + * @dev Emitted when a contract is added to the locker. + */ + event LockerWasAdded( + string locker + ); + + /** + * @dev Emitted when a contract is removed from the locker. + */ + event LockerWasRemoved( + string locker + ); + + function removeLocker(string calldata locker) external; + function addLocker(string memory locker) external; +} diff --git a/contracts/delegation/IValidatorService.sol b/contracts/delegation/IValidatorService.sol new file mode 100644 index 0000000..05697d0 --- /dev/null +++ b/contracts/delegation/IValidatorService.sol @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + IValidatorService.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface IValidatorService { + struct Validator { + string name; + address validatorAddress; + address requestedAddress; + string description; + uint feeRate; + uint registrationTime; + uint minimumDelegationAmount; + bool acceptNewRequests; + } + + /** + * @dev Emitted when a validator registers. + */ + event ValidatorRegistered( + uint validatorId + ); + + /** + * @dev Emitted when a validator address changes. + */ + event ValidatorAddressChanged( + uint validatorId, + address newAddress + ); + + /** + * @dev Emitted when a validator is enabled. + */ + event ValidatorWasEnabled( + uint validatorId + ); + + /** + * @dev Emitted when a validator is disabled. + */ + event ValidatorWasDisabled( + uint validatorId + ); + + /** + * @dev Emitted when a node address is linked to a validator. + */ + event NodeAddressWasAdded( + uint validatorId, + address nodeAddress + ); + + /** + * @dev Emitted when a node address is unlinked from a validator. + */ + event NodeAddressWasRemoved( + uint validatorId, + address nodeAddress + ); + + /** + * @dev Emitted when whitelist disabled. + */ + event WhitelistDisabled(bool status); + + /** + * @dev Emitted when validator requested new address. + */ + event RequestNewAddress(uint indexed validatorId, address previousAddress, address newAddress); + + /** + * @dev Emitted when validator set new minimum delegation amount. + */ + event SetMinimumDelegationAmount(uint indexed validatorId, uint previousMDA, uint newMDA); + + /** + * @dev Emitted when validator set new name. + */ + event SetValidatorName(uint indexed validatorId, string previousName, string newName); + + /** + * @dev Emitted when validator set new description. + */ + event SetValidatorDescription(uint indexed validatorId, string previousDescription, string newDescription); + + /** + * @dev Emitted when validator start or stop accepting new delegation requests. + */ + event AcceptingNewRequests(uint indexed validatorId, bool status); + + function registerValidator( + string calldata name, + string calldata description, + uint feeRate, + uint minimumDelegationAmount + ) + external + returns (uint validatorId); + function enableValidator(uint validatorId) external; + function disableValidator(uint validatorId) external; + function disableWhitelist() external; + function requestForNewAddress(address newValidatorAddress) external; + function confirmNewAddress(uint validatorId) external; + function linkNodeAddress(address nodeAddress, bytes calldata sig) external; + function unlinkNodeAddress(address nodeAddress) external; + function setValidatorMDA(uint minimumDelegationAmount) external; + function setValidatorName(string calldata newName) external; + function setValidatorDescription(string calldata newDescription) external; + function startAcceptingNewRequests() external; + function stopAcceptingNewRequests() external; + function removeNodeAddress(uint validatorId, address nodeAddress) external; + function getAndUpdateBondAmount(uint validatorId) external returns (uint); + function getMyNodesAddresses() external view returns (address[] memory); + function getTrustedValidators() external view returns (uint[] memory); + function checkValidatorAddressToId(address validatorAddress, uint validatorId) + external + view + returns (bool); + function getValidatorIdByNodeAddress(address nodeAddress) external view returns (uint validatorId); + function checkValidatorCanReceiveDelegation(uint validatorId, uint amount) external view; + function getNodeAddresses(uint validatorId) external view returns (address[] memory); + function validatorExists(uint validatorId) external view returns (bool); + function validatorAddressExists(address validatorAddress) external view returns (bool); + function checkIfValidatorAddressExists(address validatorAddress) external view; + function getValidator(uint validatorId) external view returns (Validator memory); + function getValidatorId(address validatorAddress) external view returns (uint); + function isAcceptingNewRequests(uint validatorId) external view returns (bool); + function isAuthorizedValidator(uint validatorId) external view returns (bool); +} diff --git a/contracts/thirdparty/IECDH.sol b/contracts/thirdparty/IECDH.sol new file mode 100644 index 0000000..6630524 --- /dev/null +++ b/contracts/thirdparty/IECDH.sol @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + IECDH.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface IECDH { + function publicKey(uint256 privKey) external pure returns (uint256 qx, uint256 qy); + function deriveKey( + uint256 privKey, + uint256 pubX, + uint256 pubY + ) + external + pure + returns (uint256 qx, uint256 qy); + function jAdd( + uint256 x1, + uint256 z1, + uint256 x2, + uint256 z2 + ) + external + pure + returns (uint256 x3, uint256 z3); + function jSub( + uint256 x1, + uint256 z1, + uint256 x2, + uint256 z2 + ) + external + pure + returns (uint256 x3, uint256 z3); + function jMul( + uint256 x1, + uint256 z1, + uint256 x2, + uint256 z2 + ) + external + pure + returns (uint256 x3, uint256 z3); + function jDiv( + uint256 x1, + uint256 z1, + uint256 x2, + uint256 z2 + ) + external + pure + returns (uint256 x3, uint256 z3); + function inverse(uint256 a) external pure returns (uint256 invA); + function ecAdd( + uint256 x1, + uint256 y1, + uint256 z1, + uint256 x2, + uint256 y2, + uint256 z2 + ) + external + pure + returns (uint256 x3, uint256 y3, uint256 z3); + function ecDouble( + uint256 x1, + uint256 y1, + uint256 z1 + ) + external + pure + returns (uint256 x3, uint256 y3, uint256 z3); + function ecMul( + uint256 d, + uint256 x1, + uint256 y1, + uint256 z1 + ) + external + pure + returns (uint256 x3, uint256 y3, uint256 z3); +} diff --git a/contracts/thirdparty/openzeppelin/IAccessControlUpgradeableLegacy.sol b/contracts/thirdparty/openzeppelin/IAccessControlUpgradeableLegacy.sol new file mode 100644 index 0000000..b4ee669 --- /dev/null +++ b/contracts/thirdparty/openzeppelin/IAccessControlUpgradeableLegacy.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +/* + IAccessControlUpgradeableLegacy.sol - SKALE Manager + Copyright (C) 2018-Present SKALE Labs + @author Artem Payvin + + SKALE Manager is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SKALE Manager is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with SKALE Manager. If not, see . +*/ + +pragma solidity >=0.6.10 <0.9.0; + +interface IAccessControlUpgradeableLegacy { + /** + * @dev Emitted when `account` is granted `role`. + * + * `sender` is the account that originated the contract call, an admin role + * bearer except when using {_setupRole}. + */ + event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); + + /** + * @dev Emitted when `account` is revoked `role`. + * + * `sender` is the account that originated the contract call: + * - if using `revokeRole`, it is the admin role bearer + * - if using `renounceRole`, it is the role bearer (i.e. `account`) + */ + event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); + + function grantRole(bytes32 role, address account) external; + function revokeRole(bytes32 role, address account) external; + function renounceRole(bytes32 role, address account) external; + function hasRole(bytes32 role, address account) external view returns (bool); + function getRoleMemberCount(bytes32 role) external view returns (uint256); + function getRoleMember(bytes32 role, uint256 index) external view returns (address); + function getRoleAdmin(bytes32 role) external view returns (bytes32); +}