Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaveracll committed Aug 29, 2024
1 parent 5354c29 commit 201c30b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-balloons-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#added Add ZKSync L2EP SequencerUptimeFeed contract
18 changes: 10 additions & 8 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ let config = {
version: '0.8.19',
settings: COMPILER_SETTINGS,
},
'contracts/node_modules/@zksync/contracts/l2-contracts/contracts/bridge/interfaces/IL2SharedBridge.sol': {
version: '0.8.20',
settings: COMPILER_SETTINGS,
},
'node_modules/@zksync/contracts/l1-contracts/contracts/vendor/AddressAliasHelper.sol': {
version: '0.8.24',
settings: COMPILER_SETTINGS,
},
'contracts/node_modules/@zksync/contracts/l2-contracts/contracts/bridge/interfaces/IL2SharedBridge.sol':
{
version: '0.8.20',
settings: COMPILER_SETTINGS,
},
'node_modules/@zksync/contracts/l1-contracts/contracts/vendor/AddressAliasHelper.sol':
{
version: '0.8.24',
settings: COMPILER_SETTINGS,
},
},
},
mocha: {
Expand Down
24 changes: 0 additions & 24 deletions contracts/src/v0.8/l2ep/dev/zksync/ZKSyncSequencerUptimeFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import {SimpleReadAccessController} from "../../../shared/access/SimpleReadAcces
import {IL2SharedBridge} from "@zksync/contracts/l2-contracts/contracts/bridge/interfaces/IL2SharedBridge.sol";
import {AddressHelper} from "@zksync/contracts/l1-contracts/contracts/vendor/AddressAliasHelper.sol";

///
/// @title ZKSyncSequencerUptimeFeed - L2 sequencer uptime status aggregator
/// @notice L2 contract that receives status updates from a specific L1 address,
/// records a new answer if the status changed
///
contract ZKSyncSequencerUptimeFeed is
AggregatorV2V3Interface,
ZKSyncSequencerUptimeFeedInterface,
Expand Down Expand Up @@ -63,11 +61,9 @@ contract ZKSyncSequencerUptimeFeed is
// solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i
IL2SharedBridge private immutable s_l2SharedBridge;

///
/// @param l1SenderAddress Address of the L1 contract that is permissioned to call this contract
/// @param l2CrossDomainMessengerAddr Address of the L2CrossDomainMessenger contract
/// @param initialStatus The initial status of the feed
///
constructor(address l1SenderAddress, address l2CrossDomainMessengerAddr, bool initialStatus) {
_setL1Sender(l1SenderAddress);
s_l2SharedBridge = IL2SharedBridge(l2CrossDomainMessengerAddr);
Expand All @@ -77,22 +73,16 @@ contract ZKSyncSequencerUptimeFeed is
_recordRound(1, initialStatus, timestamp);
}

///
/// @notice Check if a roundId is valid in this current contract state
/// @dev Mainly used for AggregatorV2V3Interface functions
/// @param roundId Round ID to check
///
function _isValidRound(uint256 roundId) private view returns (bool) {
return roundId > 0 && roundId <= type(uint80).max && s_feedState.latestRoundId >= roundId;
}

///
/// @notice versions:
///
/// - ZKSyncSequencerUptimeFeed 1.0.0: initial release
///
/// @inheritdoc TypeAndVersionInterface
///
function typeAndVersion() external pure virtual override returns (string memory) {
return "ZKSyncSequencerUptimeFeed 1.0.0";
}
Expand All @@ -102,11 +92,9 @@ contract ZKSyncSequencerUptimeFeed is
return s_l1Sender;
}

///
/// @notice Set the allowed L1 sender for this contract to a new L1 sender
/// @dev Can be disabled by setting the L1 sender as `address(0)`. Accessible only by owner.
/// @param to new L1 sender that will be allowed to call `updateStatus` on this contract
///
function transferL1Sender(address to) external virtual onlyOwner {
_setL1Sender(to);
}
Expand All @@ -120,22 +108,16 @@ contract ZKSyncSequencerUptimeFeed is
}
}

///
/// @dev Returns an AggregatorV2V3Interface compatible answer from status flag
///
/// @param status The status flag to convert to an aggregator-compatible answer
///
function _getStatusAnswer(bool status) private pure returns (int256) {
return status ? int256(1) : int256(0);
}

///
/// @notice Helper function to record a round and set the latest feed state.
///
/// @param roundId The round ID to record
/// @param status Sequencer status
/// @param timestamp The L1 block timestamp of status update
///
function _recordRound(uint80 roundId, bool status, uint64 timestamp) private {
uint64 updatedAt = uint64(block.timestamp);

Expand All @@ -146,26 +128,20 @@ contract ZKSyncSequencerUptimeFeed is
emit AnswerUpdated(_getStatusAnswer(status), roundId, timestamp);
}

///
/// @notice Helper function to update when a round was last updated
///
/// @param roundId The round ID to update
/// @param status Sequencer status
///
function _updateRound(uint80 roundId, bool status) private {
uint64 updatedAt = uint64(block.timestamp);
s_rounds[roundId].updatedAt = updatedAt;
s_feedState.updatedAt = updatedAt;
emit RoundUpdated(_getStatusAnswer(status), updatedAt);
}

///
/// @notice Record a new status and timestamp if it has changed since the last round.
/// @dev This function will revert if not called from `l1Sender` via the L1->L2 messenger.
///
/// @param status Sequencer status
/// @param timestamp Block timestamp of status update
///
function updateStatus(bool status, uint64 timestamp) external override {
// TODO: Address aliasing will be necessary to check on the L2 the L1 caller.
// The aliasing can be applied using AddressAliasHelper.applyL1ToL2Alias(msg.sender).
Expand Down

0 comments on commit 201c30b

Please sign in to comment.