Skip to content

Commit 5dade82

Browse files
committed
Aggregration and Validation staking added
1 parent 029627d commit 5dade82

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/AggregationAndValidation.sol

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
//implements aggregrator staking for future node
5+
//if aggregrator and validator are seperate entities
6+
//we use this contract else for testnet
7+
//Single entity acts as task creator,aggregrator and validator
8+
9+
import "./BaseTask.sol";
10+
11+
contract AggrgrationAndValidation is BaseTask {
12+
address aggregratorAddress;
13+
14+
function stakeAsAggregrator(uint taskID) public payable {
15+
require(tasks[taskID].isActive, "Task is not active");
16+
require(
17+
aggregratorAddress == address(0),
18+
"Aggregator already assigned"
19+
);
20+
require(
21+
msg.value >= AGGREGATOR_STAKE,
22+
"Insufficient stake for aggregator"
23+
);
24+
Task storage task = tasks[taskID];
25+
26+
task.stakes[msg.sender] = msg.value;
27+
task.totalstaked += msg.value;
28+
aggregratorAddress = msg.sender;
29+
30+
31+
}
32+
33+
//add aggregration logic for blockchain layer
34+
}

src/BaseTask.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.0;
33

4+
//defines constants and base task struct
5+
46
abstract contract BaseTask {
57
struct Task {
68
uint id;

src/Staking.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
pragma solidity ^0.8.0;
44

55
import "./TaskManagement.sol";
6+
7+
//implements a role based stacking mechanism
8+
/*Task Creator stakes at least CREATOR_STAKE while creating the task.
9+
Trainer Nodes stake TRAINER_STAKE when joining as trainers.
10+
Aggregator stakes AGGREGATOR_STAKE during the aggregation phase.
11+
*/
12+
613
/*
714
To-Do
815
*Trainer can unstake to asign trainer to different task

src/TaskManagement.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.0;
33

4+
//ensure the task creater stakes the required amount
5+
6+
47
import "./BaseTask.sol";
58

69
contract TaskManagement is BaseTask {
7-
function createTask(uint reward) public payable {
10+
function createTask(uint reward) public payable isCreatorRole(reward) {
811
require(msg.value == reward, "reward must be deposited");
912

1013
Task storage newTask = tasks[taskCounter];
1114
newTask.id = taskCounter;
1215
newTask.creator = msg.sender;
1316
newTask.reward = reward;
17+
newTask.totalstaked += CREATOR_STAKE; //can be more than required
1418
newTask.isActive = true; //should be set for specific time eventually
1519

1620
emit TaskCreated((taskCounter), msg.sender, reward);
@@ -31,6 +35,7 @@ contract TaskManagement is BaseTask {
3135
msg.value == reward + CREATOR_STAKE,
3236
"Reward and stake must be deposited"
3337
);
38+
_;
3439
}
3540

3641
modifier onlyActiveTask(uint taskId) {

0 commit comments

Comments
 (0)