From f02631371b4d8976e4a86d7f817f62d345659229 Mon Sep 17 00:00:00 2001 From: nick Date: Fri, 8 Nov 2024 21:42:01 +0900 Subject: [PATCH] feat: update contract --- contracts/v0.2/src/SubmissionProxy.sol | 57 +++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/contracts/v0.2/src/SubmissionProxy.sol b/contracts/v0.2/src/SubmissionProxy.sol index e140153a1..1bca03b42 100644 --- a/contracts/v0.2/src/SubmissionProxy.sol +++ b/contracts/v0.2/src/SubmissionProxy.sol @@ -37,8 +37,8 @@ contract SubmissionProxy is Ownable { mapping(address => OracleInfo) public whitelist; mapping(bytes32 feedHash => IFeed feed) public feeds; - mapping(bytes32 feedHash => uint8 threshold) thresholds; - mapping(bytes32 feedHash => uint256 lastSubmissionTime) lastSubmissionTimes; + mapping(bytes32 feedHash => uint8 threshold) public thresholds; + mapping(bytes32 feedHash => uint256 lastSubmissionTime) public lastSubmissionTimes; event OracleAdded(address oracle, uint256 expirationTime); event OracleRemoved(address oracle); @@ -445,6 +445,59 @@ contract SubmissionProxy is Ownable { } } + function submitOnlyNew( + bytes32[] calldata _feedHashes, + int256[] calldata _answers, + uint256[] calldata _timestamps, + bytes[] calldata _proofs + ) external { + 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++) { + submitSingleIfNew(_feedHashes[i], _answers[i], _timestamps[i], _proofs[i]); + } + } + + function submitSingleIfNew(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public { + if (lastSubmissionTimes[_feedHash] >= _timestamp) { + return; + } + + if (_timestamp <= (block.timestamp - dataFreshness) * 1000 ) { + revert AnswerTooOld(); + } + + (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.