Skip to content

Commit 3cb9d92

Browse files
authored
Merge pull request #1349 from keep-network/api
Client interfaces for random beacon and token staking
2 parents b0837d3 + 82d64c2 commit 3cb9d92

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
pragma solidity ^0.5.4;
3+
4+
/**
5+
* @title Keep Random Beacon
6+
*
7+
* @notice Keep Random Beacon generates verifiable randomness that is resistant
8+
* to bad actors both in the relay network and on the anchoring blockchain.
9+
*/
10+
interface IRandomBeacon {
11+
12+
/**
13+
* @notice Provides the customer with an estimated entry fee in wei to use
14+
* in the request. The fee estimate is only valid for the transaction it is
15+
* called in, so the customer must make the request immediately after
16+
* obtaining the estimate. Insufficient payment will lead to the request
17+
* being rejected and the transaction reverted.
18+
*
19+
* The customer may decide to provide more ether for an entry fee than
20+
* estimated by this function. This is especially heplful when callback gas
21+
* cost fluctuates. Any surplus between the passed fee and the actual cost
22+
* of producing an entry and executing a callback is returned back to the
23+
* customer.
24+
* @param callbackGas Gas required for the callback.
25+
*/
26+
function entryFeeEstimate(uint256 callbackGas) external view returns (uint256);
27+
28+
/**
29+
* @notice Submits a request to generate a new relay entry. Executes the
30+
* provided callback with the generated entry and emits
31+
* `RelayEntryGenerated(uint256 requestId, uint256 entry)` event.
32+
*
33+
* @dev Beacon does not support concurrent relay requests. No new requests
34+
* should be made while the beacon is already processing another request.
35+
* Requests made while the beacon is busy will be rejected and the
36+
* transaction reverted.
37+
38+
* @param callbackContract Callback contract address. Callback is called
39+
* once a new relay entry has been generated.
40+
* @param callbackMethod Callback contract method signature. String
41+
* representation of your method with a single
42+
* uint256 input parameter i.e. "relayEntryCallback(uint256)".
43+
* @param callbackGas Gas required for the callback.
44+
* The customer needs to ensure they provide a sufficient callback gas
45+
* to cover the gas fee of executing the callback. Any surplus is returned
46+
* to the customer. If the callback gas amount turns to be not enough to
47+
* execute the callback, callback execution is skipped.
48+
* @return An uint256 representing uniquely generated relay request ID
49+
*/
50+
function requestRelayEntry(
51+
address callbackContract,
52+
string calldata callbackMethod,
53+
uint256 callbackGas
54+
) external payable returns (uint256);
55+
56+
/**
57+
* @notice Submits a request to generate a new relay entry. Emits
58+
* `RelayEntryGenerated(uint256 requestId, uint256 entry)` event for the
59+
* generated entry.
60+
*
61+
* @dev Beacon does not support concurrent relay requests. No new requests
62+
* should be made while the beacon is already processing another request.
63+
* Requests made while the beacon is busy will be rejected and the
64+
* transaction reverted.
65+
*
66+
* @return An uint256 representing uniquely generated relay request ID
67+
*/
68+
function requestRelayEntry() external payable returns (uint256);
69+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
pragma solidity ^0.5.4;
2+
3+
/**
4+
* @title Keep Network Token Staking
5+
*
6+
* @notice Provides an information about eligible stake of network operators.
7+
* The Keep network uses staking of tokens to enforce correct behavior.
8+
* Anyone with tokens can stake them, setting them aside as collateral for
9+
* network operations. Staked tokens are delegated to an operator address who
10+
* performs work for operator contracts. Operators can earn rewards from
11+
* contributing to the network, but if they misbehave their collateral can be
12+
* taken away (stake slashing) as punishment.
13+
*/
14+
interface ITokenStaking {
15+
16+
/**
17+
* @dev Gets the eligible stake balance of the specified operator.
18+
* An eligible stake is a stake that passed the initialization period
19+
* and is not currently undelegating. Also, the operator had to approve
20+
* the specified operator contract.
21+
*
22+
* Operator with a minimum required amount of eligible stake can join the
23+
* network and participate in new work selection.
24+
*
25+
* @param _operator Address of stake operator.
26+
* @param _operatorContract Address of operator contract.
27+
* @return Eligible stake balance.
28+
*/
29+
function eligibleStake(
30+
address _operator,
31+
address _operatorContract
32+
) external view returns (uint256 balance);
33+
}

contracts/solidity/contracts/KeepRandomBeaconServiceImplV1.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "openzeppelin-solidity/contracts/utils/ReentrancyGuard.sol";
55
import "./utils/AddressArrayUtils.sol";
66
import "./DelayedWithdrawal.sol";
77
import "./Registry.sol";
8+
import "./IRandomBeacon.sol";
89

910

1011
interface OperatorContract {
@@ -29,7 +30,7 @@ interface OperatorContract {
2930
* Warning: you can't set constants directly in the contract and must use initialize()
3031
* please see openzeppelin upgradeable contracts approach for more info.
3132
*/
32-
contract KeepRandomBeaconServiceImplV1 is DelayedWithdrawal, ReentrancyGuard {
33+
contract KeepRandomBeaconServiceImplV1 is DelayedWithdrawal, ReentrancyGuard, IRandomBeacon {
3334
using SafeMath for uint256;
3435
using AddressArrayUtils for address[];
3536

contracts/solidity/contracts/TokenStaking.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity ^0.5.4;
33
import "./StakeDelegatable.sol";
44
import "./utils/UintArrayUtils.sol";
55
import "./Registry.sol";
6+
import "./ITokenStaking.sol";
67

78

89
/**
@@ -11,7 +12,7 @@ import "./Registry.sol";
1112
* A holder of the specified token can stake delegate its tokens to this contract
1213
* and recover the stake after undelegation period is over.
1314
*/
14-
contract TokenStaking is StakeDelegatable {
15+
contract TokenStaking is StakeDelegatable, ITokenStaking {
1516

1617
using UintArrayUtils for uint256[];
1718

0 commit comments

Comments
 (0)