-
Notifications
You must be signed in to change notification settings - Fork 2
Fix signatures and add latestTask details #30
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
base: main
Are you sure you want to change the base?
Changes from all commits
00dd89b
ebe8ed4
932a056
d8c69ea
beed897
2fe752a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,14 +25,22 @@ contract EthPriceOracle is OwnableBasedApp { | |
| event NewTaskCreated(uint32 indexed taskIndex, bytes32 taskHash); | ||
| event TaskResponded(uint32 indexed taskIndex, bytes32 taskHash, address responder, uint256 ethPrice); | ||
| event BAppOptedInByStrategy(uint32 indexed strategyId, address indexed bApp, bytes data, address[] tokens, uint32[] obligationPercentages); | ||
| event DebugOptIn(uint32 indexed strategyId, address signer, address testOneAddress, address testTwoAddress); | ||
|
|
||
| // Structs | ||
| struct Task { | ||
| uint256 price; | ||
| uint32 taskNumber; | ||
| address responder; | ||
| } | ||
|
|
||
| // Storage | ||
| mapping(uint32 => bytes32) public allTaskHashes; | ||
| mapping(address => mapping(uint32 => bytes)) public allTaskResponses; | ||
| uint32 public latestTaskNum; | ||
| uint32 public latestTaskNum; // Tracks the current task | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would consider removing comments cause they are redundant. But it's ok. |
||
| uint32 public nextTaskNumber; // Tracks the next task to be created | ||
| uint256 public mostRecentPrice; | ||
| mapping(uint32 => address) public strategySigner; | ||
| Task public latestCompleteTask; // Stores the latest completed task details | ||
| ISSVBasedApps public immutable ssvBasedApps; | ||
|
|
||
| constructor( | ||
|
|
@@ -46,9 +54,10 @@ contract EthPriceOracle is OwnableBasedApp { | |
| bytes32 taskHash = keccak256(abi.encodePacked(block.number, msg.sender)); | ||
|
|
||
| // store hash of task on-chain, emit event, and increase taskNum | ||
| allTaskHashes[latestTaskNum] = taskHash; | ||
| allTaskHashes[nextTaskNumber] = taskHash; | ||
RaekwonIII marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| latestTaskNum = nextTaskNumber; | ||
| nextTaskNumber = nextTaskNumber + 1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could probably use ++ but that's ok for the example |
||
| emit NewTaskCreated(latestTaskNum, taskHash); | ||
| latestTaskNum = latestTaskNum + 1; | ||
|
|
||
| return taskHash; | ||
| } | ||
|
|
@@ -59,26 +68,25 @@ contract EthPriceOracle is OwnableBasedApp { | |
| uint256 ethPrice, | ||
| bytes[] calldata signatures, | ||
| address[] calldata signers, | ||
| uint32 strategyId | ||
| uint32[] calldata strategyIds | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the future these 3 params could go in a struct and then you would pass an array of these structs. So you don't have to check the length. |
||
| ) external { | ||
| // check that the task is valid and hasn't been responded to yet | ||
| if (taskHash != allTaskHashes[taskNumber]) { revert TaskMismatch(); } | ||
| if (allTaskResponses[msg.sender][taskNumber].length != 0) { revert AlreadyResponded(); } | ||
| if (ethPrice <= 0) { revert InvalidPrice(); } | ||
| if (signatures.length != signers.length) { revert InvalidSignature(); } | ||
| if (signatures.length != signers.length || signatures.length != strategyIds.length) { revert InvalidSignature(); } | ||
|
|
||
| // Create the message that was signed (task num + price) | ||
| bytes32 messageHash = keccak256(abi.encodePacked(taskNumber, ethPrice)); | ||
|
|
||
| // Get the strategy signer | ||
| address strategySignerAddress = strategySigner[strategyId]; | ||
|
|
||
| // Verify each signature | ||
| for (uint i = 0; i < signatures.length; i++) { | ||
|
|
||
| for (uint256 i = 0; i < signatures.length; i++) { | ||
| // Recover the signer address from the signature | ||
| address recoveredSigner = messageHash.recover(signatures[i]); | ||
|
|
||
| // Get the strategy signer for this specific strategy | ||
| address strategySignerAddress = strategySigner[strategyIds[i]]; | ||
|
|
||
| if (strategySignerAddress != address(0)) { | ||
| // if strategy has a signer set, verify this signer is the correct one | ||
| if (strategySignerAddress != signers[i]) { | ||
|
|
@@ -87,7 +95,7 @@ contract EthPriceOracle is OwnableBasedApp { | |
| } else { | ||
| // if strategy has no signer set, check the signer is the owner of the strategy | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens here in the else if if |
||
| uint32 derivedStrategyId = IAccountBAppStrategy(address(ssvBasedApps)).accountBAppStrategy(recoveredSigner, address(this)); | ||
| if (derivedStrategyId != strategyId) { | ||
| if (derivedStrategyId != strategyIds[i]) { | ||
| revert NotOptedIn(); | ||
| } | ||
| } | ||
|
|
@@ -96,6 +104,14 @@ contract EthPriceOracle is OwnableBasedApp { | |
| // Store the response | ||
| allTaskResponses[msg.sender][taskNumber] = abi.encode(ethPrice); | ||
| mostRecentPrice = ethPrice; | ||
| latestTaskNum = taskNumber; | ||
|
|
||
| // Update the latest complete task | ||
| latestCompleteTask = Task({ | ||
| price: ethPrice, | ||
| taskNumber: taskNumber, | ||
| responder: msg.sender | ||
| }); | ||
|
|
||
| // Emit event with the ETH price | ||
| emit TaskResponded(taskNumber, taskHash, msg.sender, ethPrice); | ||
|
|
@@ -112,7 +128,6 @@ contract EthPriceOracle is OwnableBasedApp { | |
| // Store the address in the mapping | ||
| strategySigner[strategyId] = signer; | ||
|
|
||
| emit DebugOptIn(strategyId, signer, testOne[1], testTwo[2]); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.