Arbitrum Stylus logo

Stylus by Example

Timelock Wallet

An Arbitrum Stylus version implementation of Solidity TimeLock.

  • TimeLock is a contract that publishes a transaction to be executed in the future. After a minimum waiting period, the transaction can be executed.
  • TimeLocks are commonly used in DAOs.

Here is the interface for TimeLock.

1interface ITimeLock {
2    function initialize() external;
3
4    function owner() external view returns (address);
5
6    function getTxId(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external view returns (bytes32);
7
8    function deposit() external payable;
9
10    function queue(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external;
11
12    function execute(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external;
13
14    function cancel(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external;
15
16    error AlreadyInitialized();
17
18    error NotOwnerError();
19
20    error AlreadyQueuedError(bytes32);
21
22    error TimestampNotInRangeError(uint256, uint256);
23
24    error NotQueuedError(bytes32);
25
26    error TimestampNotPassedError(uint256, uint256);
27
28    error TimestampExpiredError(uint256, uint256);
29
30    error TxFailedError();
31
32    event Queue(
33        bytes32 indexed txId,
34        address indexed target,
35        uint256 value,
36        string func,
37        bytes data,
38        uint256 timestamp
39    );
40
41    event Execute(
42        bytes32 indexed txId,
43        address indexed target,
44        uint256 value,
45        string func,
46        bytes data,
47        uint256 timestamp
48    );
49    
50    event Cancel(bytes32 indexed txId);
51}
1interface ITimeLock {
2    function initialize() external;
3
4    function owner() external view returns (address);
5
6    function getTxId(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external view returns (bytes32);
7
8    function deposit() external payable;
9
10    function queue(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external;
11
12    function execute(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external;
13
14    function cancel(address target, uint256 value, string calldata func, bytes calldata data, uint256 timestamp) external;
15
16    error AlreadyInitialized();
17
18    error NotOwnerError();
19
20    error AlreadyQueuedError(bytes32);
21
22    error TimestampNotInRangeError(uint256, uint256);
23
24    error NotQueuedError(bytes32);
25
26    error TimestampNotPassedError(uint256, uint256);
27
28    error TimestampExpiredError(uint256, uint256);
29
30    error TxFailedError();
31
32    event Queue(
33        bytes32 indexed txId,
34        address indexed target,
35        uint256 value,
36        string func,
37        bytes data,
38        uint256 timestamp
39    );
40
41    event Execute(
42        bytes32 indexed txId,
43        address indexed target,
44        uint256 value,
45        string func,
46        bytes data,
47        uint256 timestamp
48    );
49    
50    event Cancel(bytes32 indexed txId);
51}

Example implementation of a Timelock contract written in Rust.

src/lib.rs

1Loading...
1Loading...

Cargo.toml

1Loading...
1Loading...

src/main.rs

1Loading...
1Loading...