Skip to content

Commit a0ff472

Browse files
author
Mykyta Ovsiienko
committed
Revert "contract placeholders (#12)"
This reverts commit ffb8538.
1 parent 4189d41 commit a0ff472

14 files changed

Lines changed: 1170 additions & 169 deletions

.github/workflows/ci.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18-
build-and-deploy:
19-
name: Build & Deploy (deterministic)
18+
build-and-test:
19+
name: Build & Test
2020
runs-on: ubuntu-latest
2121

2222
env:
@@ -45,8 +45,23 @@ jobs:
4545
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
4646
aws-region: "us-east-1"
4747

48-
- name: Build
49-
run: just build
48+
- name: Build Reference Contracts
49+
run: just build-reference
5050

51-
- name: Deploy (deterministic, create2)
52-
run: just deploy
51+
- name: Run build and checks
52+
run: just check
53+
54+
- name: Get KMS Address
55+
run: |
56+
echo "KMS_ADDRESS=$(cast wallet address --aws)" >> $GITHUB_ENV
57+
58+
- name: Upgrade PropertyDataConsensus (Dry Run)
59+
run: just upgrade-consensus-prod polygon
60+
env:
61+
CONSENSUS_PROXY: "0x9bA70DA0Fcc5619C80b817276eBb94a4b59b2D18"
62+
63+
- name: Upgrade vMahout (Dry Run)
64+
run: just upgrade-vmahout-prod polygon
65+
env:
66+
VMAHOUT_PROXY: "0x940a9bb3ffd84EB20A69A827F91AeDB823843368"
67+
MINTER_ADDRESS: "0x9bA70DA0Fcc5619C80b817276eBb94a4b59b2D18"

.github/workflows/release.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,23 @@ jobs:
4141
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
4242
aws-region: "us-east-1"
4343

44-
- name: Build
44+
- name: Build Reference Contracts
45+
run: just build-reference
46+
47+
- name: Build Contracts
4548
run: just build
4649

47-
- name: Deploy (mainnet deterministic, create2)
48-
run: just deploy
50+
- name: Get KMS Address
51+
run: |
52+
echo "KMS_ADDRESS=$(cast wallet address --aws)" >> $GITHUB_ENV
53+
54+
- name: Upgrade PropertyDataConsensus
55+
run: just upgrade-consensus-prod polygon
56+
env:
57+
CONSENSUS_PROXY: "0x525E59e4DE2B51f52B9e30745a513E407652AB7c"
58+
59+
- name: Upgrade vMahout
60+
run: just upgrade-vmahout-prod polygon
61+
env:
62+
VMAHOUT_PROXY: "0x3b3ad74fF6840fA5Ff5E65b551fC5E8ed13c3F18"
63+
MINTER_ADDRESS: "0x525E59e4DE2B51f52B9e30745a513E407652AB7c"

contracts/ElephantDataStorage.sol

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

contracts/Mahout.sol

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.28;
3+
4+
import { Initializable } from
5+
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
6+
import { AccessControlUpgradeable } from
7+
"@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
8+
import { UUPSUpgradeable } from
9+
"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
10+
import { EnumerableSet } from
11+
"@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
12+
import { EnumerableMap } from
13+
"@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
14+
import { VMahout } from "./VMahout.sol";
15+
16+
/**
17+
* @title PropertyDataConsensus
18+
* @notice Permissionless consensus system for property data with UUPS upgradeability
19+
*/
20+
contract PropertyDataConsensus is
21+
Initializable,
22+
AccessControlUpgradeable,
23+
UUPSUpgradeable
24+
{
25+
using EnumerableSet for EnumerableSet.AddressSet;
26+
using EnumerableMap for EnumerableMap.Bytes32ToBytes32Map;
27+
28+
event DataSubmitted(
29+
bytes32 indexed propertyHash,
30+
bytes32 indexed dataGroupHash,
31+
address indexed submitter,
32+
bytes32 dataHash
33+
);
34+
event MinimumConsensusUpdated(uint256 oldValue, uint256 newValue);
35+
event DataGroupConsensusUpdated(
36+
bytes32 indexed dataGroupHash, uint256 oldValue, uint256 newValue
37+
);
38+
event DataGroupHeartBeat(
39+
bytes32 indexed propertyHash,
40+
bytes32 indexed dataGroupHash,
41+
bytes32 indexed dataHash,
42+
address submitter
43+
);
44+
45+
// --- Structs ---
46+
struct DataVersion {
47+
bytes32 dataHash;
48+
address[] oracles;
49+
uint256 timestamp;
50+
}
51+
52+
struct DataItem {
53+
bytes32 propertyHash;
54+
bytes32 dataGroupHash;
55+
bytes32 dataHash;
56+
}
57+
58+
struct DataSubmission {
59+
address oracle;
60+
uint256 timestamp;
61+
}
62+
63+
// @deprecated there is no consensus rule for the oracle submission anymore
64+
uint256 public minimumConsensus;
65+
66+
// @deprecated we don't need to store what used to be a submission data anymore
67+
mapping(bytes32 => mapping(bytes32 => EnumerableSet.AddressSet)) private
68+
_submissionData;
69+
mapping(bytes32 => bytes32) private _currentConsensusDataHash;
70+
71+
// @deprecated we don't store consensus log anymore
72+
mapping(bytes32 => DataVersion[]) private _consensusLog;
73+
74+
VMahout public vMahout;
75+
76+
// @deprecated this is not used anymore
77+
mapping(bytes32 => uint256) public consensusRequired;
78+
79+
bytes32 public constant LEXICON_ORACLE_MANAGER_ROLE =
80+
keccak256("LEXICON_ORACLE_MANAGER_ROLE");
81+
82+
mapping(bytes32 => EnumerableMap.Bytes32ToBytes32Map) private _dataStorage;
83+
// Key is composite hash of propertyHash and dataGroupHash to ensure uniqueness
84+
mapping(bytes32 => DataSubmission) private _dataSubmissions;
85+
86+
error EmptyBatchSubmission();
87+
88+
/// @custom:oz-upgrades-unsafe-allow constructor
89+
constructor() {
90+
_disableInitializers();
91+
}
92+
93+
function _getPropertyHashFieldHash(
94+
bytes32 propertyHash,
95+
bytes32 dataGroupHash
96+
)
97+
internal
98+
pure
99+
returns (bytes32)
100+
{
101+
return keccak256(abi.encodePacked(propertyHash, dataGroupHash));
102+
}
103+
104+
/**
105+
* @notice Initialize the contract
106+
* @param initialAdmin Address that will be granted DEFAULT_ADMIN_ROLE and ORACLE_MANAGER_ROLE.
107+
*/
108+
function initialize(address initialAdmin) external initializer {
109+
__AccessControl_init();
110+
__UUPSUpgradeable_init();
111+
112+
_grantRole(DEFAULT_ADMIN_ROLE, initialAdmin);
113+
}
114+
115+
function submitData(
116+
bytes32 propertyHash,
117+
bytes32 dataGroupHash,
118+
bytes32 dataHash
119+
)
120+
public
121+
{
122+
_submitDataInternal(propertyHash, dataGroupHash, dataHash);
123+
if (address(vMahout) != address(0)) {
124+
vMahout.mint(msg.sender, 1 ether);
125+
}
126+
}
127+
128+
function submitBatchData(DataItem[] calldata items) public {
129+
uint256 length = items.length;
130+
if (length == 0) {
131+
revert EmptyBatchSubmission();
132+
}
133+
unchecked {
134+
for (uint256 i = 0; i < length; i++) {
135+
_submitDataInternal(
136+
items[i].propertyHash,
137+
items[i].dataGroupHash,
138+
items[i].dataHash
139+
);
140+
}
141+
}
142+
if (address(vMahout) != address(0)) {
143+
vMahout.mint(msg.sender, length * 1 ether);
144+
}
145+
}
146+
147+
function _submitDataInternal(
148+
bytes32 propertyHash,
149+
bytes32 dataGroupHash,
150+
bytes32 dataHash
151+
)
152+
internal
153+
{
154+
address submitter = msg.sender;
155+
bytes32 propertyDataHash =
156+
_getPropertyHashFieldHash(propertyHash, dataHash);
157+
(bool exists, bytes32 currentDataHash) =
158+
_dataStorage[propertyHash].tryGet(dataGroupHash);
159+
if (exists && currentDataHash == dataHash) {
160+
if (_dataSubmissions[propertyDataHash].oracle == submitter) {
161+
emit DataGroupHeartBeat(
162+
propertyHash, dataGroupHash, dataHash, submitter
163+
);
164+
_dataSubmissions[propertyDataHash].timestamp = block.timestamp;
165+
return;
166+
}
167+
}
168+
_dataStorage[propertyHash].set(dataGroupHash, dataHash);
169+
_dataSubmissions[propertyDataHash] =
170+
DataSubmission(submitter, block.timestamp);
171+
emit DataSubmitted(propertyHash, dataGroupHash, submitter, dataHash);
172+
}
173+
174+
function getCurrentFieldDataHash(
175+
bytes32 propertyHash,
176+
bytes32 dataGroupHash
177+
)
178+
public
179+
view
180+
returns (bytes32)
181+
{
182+
return _dataStorage[propertyHash].get(dataGroupHash);
183+
}
184+
185+
function _authorizeUpgrade(address newImplementation)
186+
internal
187+
override
188+
onlyRole(DEFAULT_ADMIN_ROLE)
189+
{ }
190+
191+
/**
192+
* @notice Sets the vMahout token address used for minting rewards to oracles.
193+
* @dev Can only be called by an account with DEFAULT_ADMIN_ROLE.
194+
* @param _vMahout The address of the vMahout token contract.
195+
*/
196+
function setVMahout(address _vMahout)
197+
external
198+
onlyRole(DEFAULT_ADMIN_ROLE)
199+
{
200+
vMahout = VMahout(_vMahout);
201+
}
202+
}

0 commit comments

Comments
 (0)