TODO: fix this
The activities and relations DCR model of this pattern is reflecting the following Solidity contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TimeBasedDeprecation {
uint256 public deprecationTime;
address public owner;
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call this.");
_;
}
modifier notDeprecated() {
require(block.timestamp < deprecationTime, "This function is deprecated.");
_;
}
constructor(uint256 _secondsTillDeprecation) {
deprecationTime = block.timestamp + _secondsTillDeprecation;
owner = msg.sender;
}
function setDeprecationTime(uint256 _newDeprecationTime) external onlyOwner {
deprecationTime = _newDeprecationTime;
}
function perform() external notDeprecated {
// Some logic here
}
}
Description:
deprecationTime
: This variable holds the timestamp after which the function will be deprecated.notDeprecated
modifier: This modifier checks if the current timestamp is less than the deprecationTime. If it's not, the function will revert with a message indicating that the function is deprecated.setDeprecationTime
: This function allows the owner to set a new deprecation timestamp.performAction
: This is a sample function that will be deprecated after the deprecationTime is reached.
As DCR semantics does not support checking a condition when the activity is called, we use an auxiliary activity auxiliary_deprecate to exclude the perform
function/activity exactly at the time set by setDeprecationTime
. Furthermore, to enforce execution of this axiliary activity at that exact time we use pre-condition and response relations from setDeprecationTime
(that has the id deprecationTime
and integer type) to the axiliary activity with the same duration of deprecationTime
for delay (on yellow arrow) and deadline (on blue arrow).