-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: first implementation of the service staking #116
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2487fb6
feat: first implementation of the service staking
kupermind 54abdab
refactor: continue working on the service staking implementation
kupermind 5dd6c20
Merge branch 'main' into service_staking
kupermind d863092
refactor: advancing service staking contracts
kupermind 8cc3855
refactor: advancing service staking contracts
kupermind 4d2112c
refactor: separate interfaces, separate balance accounting and record…
kupermind 5f44079
chore: change variable names
kupermind d7801c9
refactor: more service stakng optimizations
kupermind 9154cb9
refactor: more code optimization for service staking
kupermind a013cc5
refactor: more code optimization for service staking
kupermind c61db33
refactor: more code optimization for service staking
kupermind 1d13365
refactor: more code optimization for service staking
kupermind e409d0c
refactor: more code optimization for service staking
kupermind 1ca785c
refactor: more code optimization for service staking
kupermind 9d6e990
refactor: more code optimization for service staking
kupermind 78da510
refactor: more code optimization for service staking
kupermind 68af804
refactor: adding max number of staking services
kupermind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.21; | ||
|
||
/// @dev Generic token interface for IERC20 and IERC721 tokens. | ||
interface IToken { | ||
/// @dev Gets the amount of tokens owned by a specified account. | ||
/// @param account Account address. | ||
/// @return Amount of tokens owned. | ||
function balanceOf(address account) external view returns (uint256); | ||
|
||
/// @dev Gets the owner of the token Id. | ||
/// @param tokenId Token Id. | ||
/// @return Token Id owner address. | ||
function ownerOf(uint256 tokenId) external view returns (address); | ||
|
||
/// @dev Gets the total amount of tokens stored by the contract. | ||
/// @return Amount of tokens. | ||
function totalSupply() external view returns (uint256); | ||
|
||
/// @dev Transfers the token amount. | ||
/// @param to Address to transfer to. | ||
/// @param amount The amount to transfer. | ||
/// @return True if the function execution is successful. | ||
function transfer(address to, uint256 amount) external returns (bool); | ||
|
||
/// @dev Gets remaining number of tokens that the `spender` can transfer on behalf of `owner`. | ||
/// @param owner Token owner. | ||
/// @param spender Account address that is able to transfer tokens on behalf of the owner. | ||
/// @return Token amount allowed to be transferred. | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
|
||
/// @dev Sets `amount` as the allowance of `spender` over the caller's tokens. | ||
/// @param spender Account address that will be able to transfer tokens on behalf of the caller. | ||
/// @param amount Token amount. | ||
/// @return True if the function execution is successful. | ||
function approve(address spender, uint256 amount) external returns (bool); | ||
|
||
/// @dev Transfers the token amount that was previously approved up until the maximum allowance. | ||
/// @param from Account address to transfer from. | ||
/// @param to Account address to transfer to. | ||
/// @param amount Amount to transfer to. | ||
/// @return True if the function execution is successful. | ||
function transferFrom(address from, address to, uint256 amount) external returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.21; | ||
|
||
import {ServiceStakingBase} from "./ServiceStakingBase.sol"; | ||
import "../interfaces/IService.sol"; | ||
|
||
/// @title ServiceStakingToken - Smart contract for staking a service by its owner when the service has an ETH as the deposit | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
/// @author Andrey Lebedev - <[email protected]> | ||
/// @author Mariapia Moscatiello - <[email protected]> | ||
contract ServiceStaking is ServiceStakingBase { | ||
/// @dev ServiceStaking constructor. | ||
/// @param _apy Staking APY (in single digits). | ||
/// @param _minStakingDeposit Minimum security deposit for a service to be eligible to stake. | ||
/// @param _stakingRatio Staking ratio: number of seconds per nonce (in 18 digits). | ||
DavidMinarsch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// @param _serviceRegistry ServiceRegistry contract address. | ||
constructor(uint256 _apy, uint256 _minStakingDeposit, uint256 _stakingRatio, address _serviceRegistry) | ||
ServiceStakingBase(_apy, _minStakingDeposit, _stakingRatio, _serviceRegistry) | ||
{ | ||
// TODO: calculate minBalance | ||
} | ||
|
||
/// @dev Checks token security deposit. | ||
/// @param serviceId Service Id. | ||
function _checkTokenSecurityDeposit(uint256 serviceId) internal view override { | ||
// Get the service security token and deposit | ||
(uint96 stakingDeposit, , , , , , ) = IService(serviceRegistry).mapServices(serviceId); | ||
|
||
// The security deposit must be greater or equal to the minimum defined one | ||
if (stakingDeposit < minStakingDeposit) { | ||
revert(); | ||
} | ||
} | ||
|
||
/// @dev Withdraws the reward amount to a service owner. | ||
/// @param to Address to. | ||
/// @param amount Amount to withdraw. | ||
function _withdraw(address to, uint256 amount) internal override { | ||
// Update the contract balance | ||
balance -= amount; | ||
|
||
// Transfer the amount | ||
(bool result, ) = to.call{value: amount}(""); | ||
if (!result) { | ||
revert TransferFailed(address(0), address(this), to, amount); | ||
} | ||
} | ||
|
||
receive() external payable { | ||
// Distribute current staking rewards | ||
_checkpoint(0); | ||
|
||
// Add to the contract and available rewards balances | ||
uint256 newBalance = balance + msg.value; | ||
uint256 newAvailableRewards = availableRewards + msg.value; | ||
|
||
// Update rewards per second | ||
uint256 newRewardsPerSecond = (newAvailableRewards * apy) / (100 * 365 days); | ||
rewardsPerSecond = newRewardsPerSecond; | ||
|
||
// Record the new actual balance and available rewards | ||
balance = newBalance; | ||
availableRewards = newAvailableRewards; | ||
|
||
emit Deposit(msg.sender, msg.value, newBalance, newAvailableRewards, newRewardsPerSecond); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call it ServiceStakingNativeToken?