-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol): trigger simultaneous recurring TKO snapshots (#16715)
- Loading branch information
Showing
12 changed files
with
124 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import "./IAddressResolver.sol"; | ||
import "./LibStrings.sol"; | ||
|
||
/// @title ISnapshot | ||
/// @custom:security-contact [email protected] | ||
interface ISnapshot { | ||
function snapshot() external returns (uint256); | ||
} | ||
|
||
/// @title LibSnapshot | ||
/// @custom:security-contact [email protected] | ||
library LibSnapshot { | ||
uint256 public constant SNAPSHOT_INTERVAL = 7200; // uint = 1 L1 block | ||
|
||
/// @notice Emitted when the Taiko token snapshot is taken. | ||
/// @param tkoAddress The Taiko token address. | ||
/// @param snapshotIdx The snapshot index. | ||
/// @param snapshotId The snapshot id. | ||
event TaikoTokenSnapshot(address tkoAddress, uint256 snapshotIdx, uint256 snapshotId); | ||
|
||
/// @dev Takes a snapshot every 200,000 L1 blocks which is roughly 27 days. | ||
/// @param _taikoToken The Taiko token address. | ||
/// @param _blockId The L1's block ID. | ||
/// @param _lastSnapshotIdx The latest snapshot's index. | ||
/// @return The new snapshot's index, 0 if no new snapshot is taken. | ||
function autoSnapshot( | ||
address _taikoToken, | ||
uint256 _blockId, | ||
uint64 _lastSnapshotIdx | ||
) | ||
internal | ||
returns (uint32) | ||
{ | ||
if (_blockId % SNAPSHOT_INTERVAL != 0) return 0; | ||
|
||
// if snapshotIdx = type(uint32).max, we can handle L1 block id up to 4e14. | ||
uint32 snapshotIdx = uint32(_blockId / SNAPSHOT_INTERVAL + 1); | ||
if (snapshotIdx == _lastSnapshotIdx) return 0; | ||
|
||
uint256 snapshotId = ISnapshot(_taikoToken).snapshot(); | ||
emit TaikoTokenSnapshot(_taikoToken, snapshotIdx, snapshotId); | ||
return snapshotIdx; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.