Skip to content

Commit 9865efa

Browse files
committed
refactor(Modules,CLI): add propose kwargs/flag for modules
1 parent c070d52 commit 9865efa

2 files changed

Lines changed: 58 additions & 19 deletions

File tree

ape_safe/_cli/modules.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,27 @@ def guard(safe: "SafeAccount"):
4444
@network_option()
4545
@account_option()
4646
@safe_argument
47+
@click.option("--propose", is_flag=True, default=False)
4748
@click.argument("module", type=AddressType)
48-
def enable(safe: "SafeAccount", account: "AccountAPI", module: AddressType):
49+
def enable(safe: "SafeAccount", account: "AccountAPI", module: AddressType, propose: bool):
4950
"""
5051
Enable MODULE for SAFE
5152
5253
**WARNING**: This is a potentially destructive action, and may make your safe vulnerable.
5354
"""
54-
safe.modules.enable(module, submitter=account)
55+
safe.modules.enable(module, submitter=account, propose=propose)
5556

5657

5758
@modules.command(cls=ConnectedProviderCommand)
5859
@network_option()
5960
@account_option()
6061
@safe_argument
62+
@click.option("--propose", is_flag=True, default=False)
6163
@click.argument("module", type=AddressType)
62-
def disable(safe: "SafeAccount", account: "AccountAPI", module: AddressType):
64+
def disable(safe: "SafeAccount", account: "AccountAPI", module: AddressType, propose: bool):
6365
"""
6466
Disable MODULE for SAFE
6567
6668
**WARNING**: This is a potentially destructive action, and may impact operations of your safe.
6769
"""
68-
safe.modules.disable(module, submitter=account)
70+
safe.modules.disable(module, submitter=account, propose=propose)

ape_safe/modules.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
if TYPE_CHECKING:
88
from collections.abc import Iterator
99

10-
from ape.api import ReceiptAPI
10+
from ape.api import AccountAPI, ReceiptAPI
1111
from ape.contracts import ContractInstance
1212

1313
from ape_safe.accounts import SafeAccount
14+
from ape_safe.client import SafeTxID
1415

1516

1617
class SafeModuleManager(ManagerAccessMixin):
@@ -27,9 +28,23 @@ def __contains__(self, module: Union[str, AddressType, "ContractInstance"]) -> b
2728
return self._safe.contract.isModuleEnabled(module)
2829

2930
def enable(
30-
self, module: Union[str, AddressType, "ContractInstance"], **txn_kwargs
31-
) -> "ReceiptAPI":
32-
return self._safe.contract.enableModule(module, sender=self._safe, **txn_kwargs)
31+
self,
32+
module: Union[str, AddressType, "ContractInstance"],
33+
submitter: Union["AccountAPI", AddressType, str, None] = None,
34+
propose: bool = False,
35+
**txn_kwargs,
36+
) -> Union["ReceiptAPI", "SafeTxID"]:
37+
if propose:
38+
txn = self._safe.contract.enableModule.as_transaction(module, **txn_kwargs)
39+
return self._safe.propose(txn=txn, submitter=submitter)
40+
41+
else:
42+
return self._safe.contract.enableModule(
43+
module,
44+
sender=self._safe,
45+
submitter=submitter,
46+
**txn_kwargs,
47+
)
3348

3449
def __iter__(self) -> "Iterator[ContractInstance]":
3550
start_module = self.SENTINEL
@@ -56,14 +71,27 @@ def _get_previous_module(
5671
raise AssertionError(f"Module {module} not in Safe modules for {self._safe}")
5772

5873
def disable(
59-
self, module: Union[str, AddressType, "ContractInstance"], **txn_kwargs
60-
) -> "ReceiptAPI":
61-
return self._safe.contract.disableModule(
62-
self._get_previous_module(module),
63-
module,
64-
sender=self._safe,
65-
**txn_kwargs,
66-
)
74+
self,
75+
module: Union[str, AddressType, "ContractInstance"],
76+
submitter: Union["AccountAPI", AddressType, str, None] = None,
77+
propose: bool = False,
78+
**txn_kwargs,
79+
) -> Union["ReceiptAPI", "SafeTxID"]:
80+
if propose:
81+
txn = self._safe.contract.disableModule.as_transaction(
82+
self._get_previous_module(module),
83+
module,
84+
**txn_kwargs,
85+
)
86+
return self._safe.propose(txn=txn, submitter=submitter)
87+
88+
else:
89+
return self._safe.contract.disableModule(
90+
self._get_previous_module(module),
91+
module,
92+
sender=self._safe,
93+
**txn_kwargs,
94+
)
6795

6896
@property
6997
def guard(self) -> Optional["ContractInstance"]:
@@ -81,6 +109,15 @@ def guard(self) -> Optional["ContractInstance"]:
81109
return self.chain_manager.contracts.instance_at(module_guard_address)
82110

83111
def set_guard(
84-
self, guard: Union[str, AddressType, "ContractInstance"], **txn_kwargs
85-
) -> "ReceiptAPI":
86-
return self._safe.contract.setModuleGuard(guard, sender=self._safe, **txn_kwargs)
112+
self,
113+
guard: Union[str, AddressType, "ContractInstance"],
114+
submitter: Union["AccountAPI", AddressType, str, None] = None,
115+
propose: bool = False,
116+
**txn_kwargs,
117+
) -> Union["ReceiptAPI", "SafeTxID"]:
118+
if propose:
119+
txn = self._safe.contract.setModuleGuard.as_transaction(guard, **txn_kwargs)
120+
return self._safe.propose(txn=txn, submitter=submitter)
121+
122+
else:
123+
return self._safe.contract.setModuleGuard(guard, sender=self._safe, **txn_kwargs)

0 commit comments

Comments
 (0)