Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timelock component #996

Merged
merged 107 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
c39a881
start timelock comp draft
andrew-fleming May 22, 2024
2caf277
move timelock to own dir, finish drafting component
andrew-fleming May 25, 2024
54db1f7
tmp: add utility impls
andrew-fleming May 25, 2024
c48521c
add timelock mock
andrew-fleming May 25, 2024
61a9258
add test mod for timelock
andrew-fleming May 25, 2024
df1d886
fix commnet
andrew-fleming May 25, 2024
40ad554
add constructor to timelock mock
andrew-fleming May 26, 2024
f009bd9
set min_delay in initializer
andrew-fleming May 26, 2024
43bf794
start tests
andrew-fleming May 26, 2024
83525ba
fix fmt
andrew-fleming May 26, 2024
587a29f
fix schedule assertion
andrew-fleming May 27, 2024
e50b1db
add schedule tests
andrew-fleming May 27, 2024
4b3a44c
fix fmt
andrew-fleming May 27, 2024
169397c
remove unused import
andrew-fleming May 27, 2024
07bb530
fix errs, _before_call
andrew-fleming May 28, 2024
65d2be6
start execute tests
andrew-fleming May 28, 2024
6f3a47f
fix fmt
andrew-fleming May 28, 2024
0e3b35b
fix after_call
andrew-fleming May 28, 2024
2c1186e
add execute tests
andrew-fleming May 30, 2024
fcd0331
add abi interface
andrew-fleming May 30, 2024
9450530
add reentrancy mock for timelock
andrew-fleming May 30, 2024
290ecbc
add tests for cancel and update_delay
andrew-fleming May 30, 2024
c5d4102
fix hash_op test
andrew-fleming May 30, 2024
ba28288
add execute with predecessor test
andrew-fleming May 30, 2024
4540db2
add timelock utils, add operation_state debug impl
andrew-fleming May 30, 2024
cc70677
fix fmt
andrew-fleming May 30, 2024
aab9245
improve imports
andrew-fleming May 30, 2024
b19c193
improve _execute
andrew-fleming May 30, 2024
b470278
add basic mock for tests
andrew-fleming May 31, 2024
269ea6e
add tmp call struct
andrew-fleming May 31, 2024
08908b5
add batch fns to interface
andrew-fleming May 31, 2024
090d1a3
add batch fns
andrew-fleming May 31, 2024
2b11d3e
refactor tests to use dedicated mock, add batch tests
andrew-fleming May 31, 2024
7f5a848
fix fmt
andrew-fleming May 31, 2024
2b42f6d
remove use clause
andrew-fleming May 31, 2024
ae31e78
add timelock mixin
andrew-fleming May 31, 2024
ae1b474
fix interface name
andrew-fleming May 31, 2024
d12be8e
improve event assertions
andrew-fleming May 31, 2024
98fb423
fix execute and schedule events
andrew-fleming May 31, 2024
c8efa81
fix fmt
andrew-fleming May 31, 2024
7054fcd
add safe token transfer tests
andrew-fleming May 31, 2024
41681d9
fix fmt
andrew-fleming May 31, 2024
7144eec
tidy up code
andrew-fleming May 31, 2024
0070607
add descriptions to events
andrew-fleming May 31, 2024
4a4d495
clean up code
andrew-fleming May 31, 2024
9ce8d02
inline CallPartialEq fns
andrew-fleming May 31, 2024
6c67531
start fn descriptions
andrew-fleming Jun 2, 2024
f5b484a
remove comments
andrew-fleming Jun 2, 2024
7527d0d
remove comment
andrew-fleming Jun 2, 2024
cd0352c
fix fmt
andrew-fleming Jun 2, 2024
f638c82
add changelog entries
andrew-fleming Jun 3, 2024
a51aae3
improve spacing
andrew-fleming Jun 3, 2024
a3c03d8
add line break to hash test
andrew-fleming Jun 3, 2024
39561ee
clean up tests
andrew-fleming Jun 3, 2024
8764889
clean up tests
andrew-fleming Jun 3, 2024
6cacdc7
fix constants in attacker impl
andrew-fleming Jun 3, 2024
e4fd560
add initializer helper, register access control support
andrew-fleming Jun 13, 2024
3583d38
add _before_call and _after_call tests
andrew-fleming Jun 13, 2024
e878cae
fix reentrant batch mock call
andrew-fleming Jun 13, 2024
70f44f4
add _schedule and _execute tests
andrew-fleming Jun 13, 2024
4018bbe
add timelock description
andrew-fleming Jun 13, 2024
29e0865
fix formatting
andrew-fleming Jun 13, 2024
ca5b0dd
fix comments
andrew-fleming Jun 13, 2024
0909f9f
fix comment
andrew-fleming Jun 13, 2024
3edf90f
fix conflicts, migrate timelock to 2023_11 edition
andrew-fleming Jun 14, 2024
ae45e5b
fmt
andrew-fleming Jun 14, 2024
3e533e1
tidy up tests
andrew-fleming Jun 14, 2024
e6dc707
remove batch helper fn
andrew-fleming Jun 14, 2024
b92165a
remove event from mocks
andrew-fleming Jun 14, 2024
3bc0a6b
fix conflicts
andrew-fleming Jun 17, 2024
8b29788
Apply suggestions from code review
andrew-fleming Jun 20, 2024
7dddac9
update spdx
andrew-fleming Jun 20, 2024
996123b
remove token receiver support
andrew-fleming Jun 21, 2024
a48b2a3
add additional cancel tests
andrew-fleming Jun 21, 2024
309b4d0
Apply suggestions from code review
andrew-fleming Jun 28, 2024
0f89aa0
initializer: remove mut, use while loop
andrew-fleming Jun 28, 2024
2278f4f
fix fmt
andrew-fleming Jun 28, 2024
d366e81
add assert_only_self fn
andrew-fleming Jun 28, 2024
9900a8c
fix getter comments re: pending/waiting
andrew-fleming Jun 28, 2024
9686d22
add assert_only_role
andrew-fleming Jun 28, 2024
e3e62ea
add specific op errors
andrew-fleming Jun 28, 2024
ac9c4b8
make event names consistent
andrew-fleming Jun 28, 2024
9350e50
fix test
andrew-fleming Jun 28, 2024
9a7f3bf
remove serialization from HashCallImpl
andrew-fleming Jul 6, 2024
a11a6e7
remove unused components from mock
andrew-fleming Jul 6, 2024
1487b9f
clean up code
andrew-fleming Jul 6, 2024
025bc6d
fix conflicts
andrew-fleming Jul 11, 2024
7f09ecc
update to 2.7.0-rc.1
andrew-fleming Jul 11, 2024
ab0025a
fix fmt
andrew-fleming Jul 11, 2024
de47270
import Call from corelib
andrew-fleming Jul 11, 2024
e97407e
update spdx
andrew-fleming Jul 11, 2024
f5c1e63
fix fmt
andrew-fleming Jul 11, 2024
3d96bf2
move OperationState, derive debug
andrew-fleming Jul 16, 2024
6352975
fix fmt
andrew-fleming Jul 16, 2024
ad47074
Merge branch 'main' into timelock
andrew-fleming Jul 16, 2024
858bb94
fix hash impls
andrew-fleming Jul 16, 2024
6c37eb8
add for loops
andrew-fleming Jul 16, 2024
a4c1f29
fix PartialEq, add tests
andrew-fleming Jul 17, 2024
09a11b0
fix fmt
andrew-fleming Jul 17, 2024
986e888
simplify mixin fns
andrew-fleming Jul 17, 2024
03f0a22
switch Poseidon to Pedersen
andrew-fleming Jul 17, 2024
d4d10df
make admin a req in initializer
andrew-fleming Jul 17, 2024
862a5c4
update tests with admin
andrew-fleming Jul 17, 2024
2de0eee
fix fmt
andrew-fleming Jul 17, 2024
edfe5fb
fix comment
andrew-fleming Jul 17, 2024
0f24416
undo changes
andrew-fleming Jul 18, 2024
c485f78
add no admin initializer test
andrew-fleming Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- TimelockController component (#996)
- HashCall implementation (#996)
- CallPartialEq (#996)

## 0.14.0 (2024-06-14)

### Changed (Breaking)
Expand Down
1 change: 1 addition & 0 deletions src/governance.cairo
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod timelock;
pub mod utils;
8 changes: 8 additions & 0 deletions src/governance/timelock.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod interface;
pub mod timelock_controller;
pub mod utils;

pub use timelock_controller::TimelockControllerComponent::{
PROPOSER_ROLE, CANCELLER_ROLE, EXECUTOR_ROLE
};
pub use timelock_controller::TimelockControllerComponent;
123 changes: 123 additions & 0 deletions src/governance/timelock/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.13.0 (governance/timelock/interface.cairo)
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved

use openzeppelin::governance::timelock::utils::OperationState;
use openzeppelin::governance::timelock::utils::call_impls::Call;
use starknet::ContractAddress;

#[starknet::interface]
pub trait ITimelock<TState> {
fn is_operation(self: @TState, id: felt252) -> bool;
fn is_operation_pending(self: @TState, id: felt252) -> bool;
fn is_operation_ready(self: @TState, id: felt252) -> bool;
fn is_operation_done(self: @TState, id: felt252) -> bool;
fn get_timestamp(self: @TState, id: felt252) -> u64;
fn get_operation_state(self: @TState, id: felt252) -> OperationState;
fn get_min_delay(self: @TState) -> u64;
fn hash_operation(self: @TState, call: Call, predecessor: felt252, salt: felt252) -> felt252;
fn hash_operation_batch(
self: @TState, calls: Span<Call>, predecessor: felt252, salt: felt252
) -> felt252;
fn schedule(ref self: TState, call: Call, predecessor: felt252, salt: felt252, delay: u64);
fn schedule_batch(
ref self: TState, calls: Span<Call>, predecessor: felt252, salt: felt252, delay: u64
);
fn cancel(ref self: TState, id: felt252);
fn execute(ref self: TState, call: Call, predecessor: felt252, salt: felt252);
fn execute_batch(ref self: TState, calls: Span<Call>, predecessor: felt252, salt: felt252);
fn update_delay(ref self: TState, new_delay: u64);
}

#[starknet::interface]
pub trait TimelockABI<TState> {
fn is_operation(self: @TState, id: felt252) -> bool;
fn is_operation_pending(self: @TState, id: felt252) -> bool;
fn is_operation_ready(self: @TState, id: felt252) -> bool;
fn is_operation_done(self: @TState, id: felt252) -> bool;
fn get_timestamp(self: @TState, id: felt252) -> u64;
fn get_operation_state(self: @TState, id: felt252) -> OperationState;
fn get_min_delay(self: @TState) -> u64;
fn hash_operation(self: @TState, call: Call, predecessor: felt252, salt: felt252) -> felt252;
fn hash_operation_batch(
self: @TState, calls: Span<Call>, predecessor: felt252, salt: felt252
) -> felt252;
fn schedule(ref self: TState, call: Call, predecessor: felt252, salt: felt252, delay: u64);
fn schedule_batch(
ref self: TState, calls: Span<Call>, predecessor: felt252, salt: felt252, delay: u64
);
fn cancel(ref self: TState, id: felt252);
fn execute(ref self: TState, call: Call, predecessor: felt252, salt: felt252);
fn execute_batch(ref self: TState, calls: Span<Call>, predecessor: felt252, salt: felt252);
fn update_delay(ref self: TState, new_delay: u64);

// ISRC5
fn supports_interface(self: @TState, interface_id: felt252) -> bool;

// IAccessControl
fn has_role(self: @TState, role: felt252, account: ContractAddress) -> bool;
fn get_role_admin(self: @TState, role: felt252) -> felt252;
fn grant_role(ref self: TState, role: felt252, account: ContractAddress);
fn revoke_role(ref self: TState, role: felt252, account: ContractAddress);
fn renounce_role(ref self: TState, role: felt252, account: ContractAddress);

// IAccessControlCamel
fn hasRole(self: @TState, role: felt252, account: ContractAddress) -> bool;
fn getRoleAdmin(self: @TState, role: felt252) -> felt252;
fn grantRole(ref self: TState, role: felt252, account: ContractAddress);
fn revokeRole(ref self: TState, role: felt252, account: ContractAddress);
fn renounceRole(ref self: TState, role: felt252, account: ContractAddress);

// IERC721Receiver
fn on_erc721_received(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove these from the timelock component, since they are separated components, and can be optionally added in the preset if required. Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will definitely reduce some of the dependency noise in the implementation if we remove them. My concern, though, is that I'm not sure it's best to make this opt in as I'd expect token receiver support out of the box (especially with erc1155 transfers). Do you disagree and think opt in is better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, opt-in is better. I don't see why every Timelock should be a valid token receiver, since usually Timelocks own contracts for delayed execution of admin actions, and this use case doesn't require being able to receive tokens. It is true that a Timelock could be helpful to "scrow" tokens, but that's why opt-in makes sense IMO. Curious about @Amxx thoughts on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would tend toward not including it by default but not because I don't think its usefull. In fact I think most (if not all) timelock should have it.

But the thing is, if you put the 721 hook, then you also need to put the 1155 hook (because why not?) ... but then are there any other hooks you should have ? Possibly ...

If you put them, you are removing that responsability from the user, and when something ends up missing that is on you. If you don't put any, and give that responsability to the user (or to the preset), then you separate the concerns better. On one hand you have the timelock logic that should probably not change a lot, on the other you have the hooks, were new stuff might be included more often.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points, I'm convinced. Thanks for the feedback! Will update accordingly

self: @TState,
operator: ContractAddress,
from: ContractAddress,
token_id: u256,
data: Span<felt252>
) -> felt252;

// IERC721ReceiverCamel
fn onERC721Received(
self: @TState,
operator: ContractAddress,
from: ContractAddress,
tokenId: u256,
data: Span<felt252>
) -> felt252;

// IERC1155Receiver
fn on_erc1155_received(
self: @TState,
operator: ContractAddress,
from: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>
) -> felt252;
fn on_erc1155_batch_received(
self: @TState,
operator: ContractAddress,
from: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) -> felt252;

// IERC1155ReceiverCamel
fn onERC1155Received(
self: @TState,
operator: ContractAddress,
from: ContractAddress,
tokenId: u256,
value: u256,
data: Span<felt252>
) -> felt252;
fn onERC1155BatchReceived(
self: @TState,
operator: ContractAddress,
from: ContractAddress,
tokenIds: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) -> felt252;
}
Loading
Loading