Skip to content
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 17 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ d780294b8dccf047391a71b75dade50a6b89003b:scripts/deployment/l2/globals_gnosis_ch
7d2fbdb1556dc3ed289edf7e116b378b6f6a9d83:scripts/deployment/l2/bridges/gnosis/test_service_registry_token_utility_change_drainer.js:generic-api-key:44
7bb76e80382eff3c538af340289ed8241f4e4551:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:1
7bb76e80382eff3c538af340289ed8241f4e4551:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:2
233a57ccda8d5d84a86133422daa99807801d9fc:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:2
48 changes: 48 additions & 0 deletions contracts/interfaces/IToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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);

/// @dev Gets the number of token decimals.
/// @return Number of token decimals.
function decimals() external view returns (uint8);
}
52 changes: 52 additions & 0 deletions contracts/staking/ServiceStaking.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

import {ServiceStakingBase} from "./ServiceStakingBase.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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it ServiceStakingNativeToken?

/// @dev ServiceStaking constructor.
/// @param _maxNumServices Maximum number of staking services.
/// @param _rewardsPerSecond Staking rewards per second (in single digits).
/// @param _minStakingDeposit Minimum staking deposit for a service to be eligible to stake.
/// @param _livenessRatio Liveness ratio: number of nonces per second (in 18 digits).
/// @param _serviceRegistry ServiceRegistry contract address.
constructor(
uint256 _maxNumServices,
uint256 _rewardsPerSecond,
uint256 _minStakingDeposit,
uint256 _livenessRatio,
address _serviceRegistry
)
ServiceStakingBase(_maxNumServices, _rewardsPerSecond, _minStakingDeposit, _livenessRatio, _serviceRegistry)
{}

/// @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 {
// Add to the contract and available rewards balances
uint256 newBalance = balance + msg.value;
uint256 newAvailableRewards = availableRewards + msg.value;

// Record the new actual balance and available rewards
balance = newBalance;
availableRewards = newAvailableRewards;

emit Deposit(msg.sender, msg.value, newBalance, newAvailableRewards);
}
}
Loading