Skip to content

Commit

Permalink
fix: add function based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Nov 12, 2024
1 parent 17d5b19 commit d68433e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions contracts/v0.2/src/SubmissionProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,56 @@ contract SubmissionProxy is Ownable {
}
}

// works same as submit, but will only return error if the proof is invalid, ignore if answer is superseded
function updatePrices(bytes32[] calldata _feedHashes, int256[] calldata _answers, uint256[] calldata _timestamps, bytes[] calldata _proofs) public {
if (
_feedHashes.length != _answers.length || _answers.length != _proofs.length
|| _proofs.length != _timestamps.length || _feedHashes.length > maxSubmission
) {
revert InvalidSubmissionLength();
}

uint256 feedsLength_ = _feedHashes.length;
for (uint256 i = 0; i < feedsLength_; i++) {
updatePrice(_feedHashes[i], _answers[i], _timestamps[i], _proofs[i]);
}
}


function updatePrice(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public {
if (_timestamp <= (block.timestamp - dataFreshness) * 1000 ) {
revert AnswerOutdated();
}

if (lastSubmissionTimes[_feedHash] >= _timestamp) {
return;
}

(bytes[] memory proofs_, bool success_) = splitProofs(_proof);
if (!success_) {
// splitting proofs failed -> do not submit!
revert InvalidProofFormat();
}

if (address(feeds[_feedHash]) == address(0)) {
// feedHash not registered -> do not submit!
revert FeedHashNotFound();
}

if (keccak256(abi.encodePacked(feeds[_feedHash].name())) != _feedHash) {
// feedHash not matching with registered feed -> do not submit!
revert InvalidFeedHash();
}

bytes32 message_ = keccak256(abi.encodePacked(_answer, _timestamp, _feedHash));
if (validateProof(_feedHash, message_, proofs_)) {
feeds[_feedHash].submit(_answer);
lastSubmissionTimes[_feedHash] = _timestamp;
} else {
revert InvalidProof();
}
}

/**
* @notice Return the version and type of the feed.
* @return typeAndVersion The type and version of the feed.
Expand Down

0 comments on commit d68433e

Please sign in to comment.