Skip to content

Commit 029627d

Browse files
committed
Task, Aggrgator added
1 parent 0440220 commit 029627d

File tree

13 files changed

+243
-93
lines changed

13 files changed

+243
-93
lines changed

Python/InitShell.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import os
3+
4+
commandFile = "Shell/Command.sh"
5+
6+
exit_code= os.system(commandFile)
7+
8+
9+
if exit_code == 0:
10+
print("Script executed successfully.")
11+
else:
12+
print("Script failed with exit code:", exit_code)

Python/SoraAI.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
from web3 import HTTPProvider, Web3, AsyncWeb3
3+
import asyncio
4+
import time
5+
6+
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))
7+
8+
if not w3.is_connected():
9+
raise Exception("Unable to connect to the blockchain")
10+
11+
def call_python_function(data):
12+
print(f"Function called from blockchain on server with data: {data}")
13+
# Your logic here
14+
15+
contract_address= "0x5FbDB2315678afecb367f032d93F642f64180aa3"
16+
contract_abi = [{"type":"constructor","inputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"registerSubNetOwner","inputs":[],"outputs":[],"stateMutability":"payable"},{"type":"function","name":"setStackingAmount","inputs":[{"name":"value","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"event","name":"subNetRegisterd","inputs":[{"name":"subnetOwner","type":"address","indexed":False,"internalType":"address"},{"name":"subnetID","type":"uint256","indexed":False,"internalType":"uint256"}],"anonymous":False}]
17+
18+
contract = w3.eth.contract(address=contract_address, abi=contract_abi)
19+
20+
def main():
21+
event_filter = contract.events.subNetRegisterd.create_filter(from_block='latest')
22+
print("registered event filter")
23+
while True:
24+
for event in event_filter.get_new_entries():
25+
print(event.args)
26+
call_python_function(event.args.subnetID)
27+
call_python_function(event.args.subnetOwner)
28+
time.sleep(10)
29+
30+
if __name__ == '__main__':
31+
main()

README.md

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
## Foundry
1+
## testnet BlockChain Layer of Sora AI
22

3-
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
4-
5-
Foundry consists of:
6-
7-
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8-
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9-
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10-
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
3+
** This layer consists of blockchain layer of Aggregrator, validator , Trainer nodes of Sora **
114

125
## Documentation
136

14-
https://book.getfoundry.sh/
7+
http://docs.thesorachain.com
158

169
## Usage
1710

@@ -21,24 +14,6 @@ https://book.getfoundry.sh/
2114
$ forge build
2215
```
2316

24-
### Test
25-
26-
```shell
27-
$ forge test
28-
```
29-
30-
### Format
31-
32-
```shell
33-
$ forge fmt
34-
```
35-
36-
### Gas Snapshots
37-
38-
```shell
39-
$ forge snapshot
40-
```
41-
4217
### Anvil
4318

4419
```shell
@@ -56,11 +31,3 @@ $ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --pri
5631
```shell
5732
$ cast <subcommand>
5833
```
59-
60-
### Help
61-
62-
```shell
63-
$ forge --help
64-
$ anvil --help
65-
$ cast --help
66-
```

Shell/Command.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "Hello from command"

foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
src = "src"
33
out = "out"
44
libs = ["lib"]
5+
remappings = ["forge-std/=lib/forge-std/src/"]
56

67
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

script/Counter.s.sol

Lines changed: 0 additions & 19 deletions
This file was deleted.

script/TheSoraChain.s.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// //// SPDX-License-Identifier: MIT
2+
3+
// pragma solidity <0.9.0;
4+
5+
// import {TheSoraChain} from "./../src/TheSoraChain.sol";
6+
// import {Script} from "forge-std/Script.sol";
7+
8+
9+
// contract DeployTheSoraChain is Script{
10+
// TheSoraChain public soraContract;
11+
12+
// function run() external returns(TheSoraChain){
13+
// vm.startBroadcast();
14+
// TheSoraChain chain = new TheSoraChain();
15+
// vm.stopBroadcast();
16+
// return chain;
17+
// }
18+
// }

src/BaseTask.sol

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
abstract contract BaseTask {
5+
struct Task {
6+
uint id;
7+
address creator;
8+
uint reward;
9+
uint totalstaked;
10+
bool isActive;
11+
address[] trainers; //we can add validators and aggregrator as well later
12+
mapping(address => uint) stakes;
13+
mapping(address => bytes) modelUpdates;
14+
}
15+
16+
uint public taskCounter;
17+
mapping(uint => Task) public tasks;
18+
19+
// Stake requirements for different roles
20+
//can be changed by the contract owner
21+
uint public CREATOR_STAKE = 5 ether;
22+
uint public AGGREGATOR_STAKE = 3 ether;
23+
uint public TRAINER_STAKE = 2 ether;
24+
25+
event TaskCreated(uint taskID, address indexed creator, uint rewards);
26+
event ModelSubmitted(
27+
uint taskID,
28+
address indexed trainer,
29+
bytes modelUpdates
30+
);
31+
event AggregrationComplete(uint taskID, bytes aggregrationModel);
32+
event RewardDistributed(uint taskID, address indexed trainer, uint reward);
33+
}

src/Counter.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Staking.sol

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "./TaskManagement.sol";
6+
/*
7+
To-Do
8+
*Trainer can unstake to asign trainer to different task
9+
*Task Creater can unstake and mark it as complete
10+
*/
11+
12+
contract Staking is TaskManagement {
13+
enum Role {
14+
TaskCreator,
15+
Aggregrator,
16+
Trainer
17+
}
18+
19+
uint public constant MINIMUM_STAKE = 1 ether;
20+
21+
function stakeTokens(
22+
uint taskID,
23+
Role role
24+
)
25+
public
26+
payable
27+
onlyActiveTask(taskID)
28+
hasToken(role)
29+
hasNotStackedEarlier(taskID)
30+
{
31+
Task storage task = tasks[taskID];
32+
task.stakes[msg.sender] = msg.value;
33+
task.totalstaked += msg.value;
34+
if (role == Role.Trainer) {
35+
task.trainers.push(msg.sender);
36+
}
37+
}
38+
39+
modifier hasToken(Role role) {
40+
require(msg.value != 0, "Stake Tokens not found");
41+
if (role == Role.TaskCreator) {
42+
require(msg.value >= CREATOR_STAKE);
43+
} else if (role == Role.Aggregrator) {
44+
require(msg.value >= AGGREGATOR_STAKE);
45+
} else if (role == Role.Trainer) {
46+
require(msg.value >= TRAINER_STAKE);
47+
} else {
48+
revert("Invalid Role");
49+
}
50+
_;
51+
}
52+
53+
modifier hasNotStackedEarlier(uint taskID) {
54+
require(
55+
tasks[taskID].stakes[msg.sender] == 0,
56+
"Already stacked for the task"
57+
);
58+
_;
59+
}
60+
}

0 commit comments

Comments
 (0)