Skip to content

Commit

Permalink
refactor!: new flow [APE-1140] (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: Dalena <[email protected]>
Co-authored-by: Juliya Smith <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2023
1 parent 1550367 commit e3a3a0e
Show file tree
Hide file tree
Showing 35 changed files with 30,374 additions and 718 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest] # eventually add `windows-latest`
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
safe-version: ["1.3.0"]

env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -86,10 +87,13 @@ jobs:
- name: Install plugins
run: ape plugins install .

# TODO: Remove once dependency work is completed
# https://github.com/ApeWorX/ape/issues/1327
- name: Copy smart-contracts to dependencies
run: mkdir -p ~/.ape/packages/safe-contracts/v1.3.0/ && cp safe-contracts.json ~/.ape/packages/safe-contracts/v1.3.0/
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install gnosis safe
run: npm install "@gnosis.pm/safe-contracts@${{ matrix.safe-version }}"

- name: Run Tests
run: pytest -n 0 -s --cov
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml

Expand All @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.11.0
hooks:
- id: black
name: black
Expand All @@ -21,10 +21,10 @@ repos:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies: [types-setuptools, pydantic]
additional_dependencies: [types-requests, types-setuptools, pydantic]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
Expand Down
112 changes: 88 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,99 @@ $ python3 setup.py install

To use the plugin, first use the CLI extension to add a safe you created:

```bash
# Add the safe located at "my-safe.eth" ENS on the ethereum mainnet network
$ ape safe add --network ethereum:mainnet "my-safe.eth" my-safe
Safe Found
network: ethereum:mainnet
address: 0x1234....AbCd
version: 1.3.0
required_confirmations: 2
signers:
- 0x2345....BcDe
- 0x3456....CdEf
- 0x4567....DeFg

Add safe [y/N]: y
```sh
ape safe add --network ethereum:mainnet "my-safe.eth" my-safe
```

If you made a mistake or just need to remove the safe, use the `remove` command:

```sh
ape safe remove my-safe --yes
```

Once you've added the safe, you can use the multisig inside any of your ape scripts or the console:
**NOTE** `--yes` is a way to skip the prompt.

If you only add one safe, you will not have to specify which safe to use other commands.
Otherwise, for most `pending` commands, you specify the safe to use (by alias) via the `--safe` option.

Additionally, you can configure a safe to use as the default in your `ape-config.yaml` file:

```yaml
safe:
default_safe: my-safe
```
**NOTE**: Also, to avoid always needing to specify `--network`, you can set a default ecosystem, network, and provider in your config file.
The rest of the guide with not specify `--network` on each command but assume the correct one is set in the config file.
Here is an example:

```yaml
default_ecosystem: optimism
ethereum:
default_network: sepolia
sepolia:
default_provider: infura
```

Once you have a safe, you can view pending transactions:

```sh
ape safe pending list
```

It should show transactions like this:

```sh
Transaction 8 rejection (1/2) safe_tx_hash=0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7
Transaction 8 transfer (1/2) safe_tx_hash=0xed43d80255bcd5ffacb755e8f51bee825913373705d6baea006419d2a33a0a5b
```

**NOTE**: Use the `--verbose` flag to see more information about each transaction.

```sh
ape safe pending list --verbose
```

There are several operations you can do on a pending transaction.
One of them is "approve" which adds your local signers' signatures to the transaction.

```sh
ape safe pending approve 0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7
```

**NOTE**: Here we are using the transaction hash `0x09ab9a229fc60da66ec0fa8fa886ab7c95902fdf5df5a5009ba06010fbb9a9a7` to specify the transaction because there are more than one.
However, you can also use the nonce if there is only a single transaction.

If you want to both execute and approve at the same time, you can use the `--execute` option on approve and specify a sender:

```sh
ape safe pending approve 2 --execute my_account
```

Else, you can use the `execute` command directly:

```sh
ape safe pending execute 2
```

**NOTE**: `execute` requires a full signed transaction ready to be submitted on-chain.

The last main operation is `reject`.
Rejecting a transaction replaces that transaction with a zero-value transfer from the safe to itself.

```sh
ape safe pending reject 2
```

### Multisend

The following example shows how to use multisend:

```python
from ape_safe import multisend
from ape import accounts
from ape_tokens import tokens
safe = accounts.load("my-safe")
Expand All @@ -76,15 +149,6 @@ txn.add(vault.deposit, amount)
txn(sender=safe)
```

You can then use the CLI extension to view and sign for pending transactions:

```bash
$ ape safe pending --network ethereum:mainnet my-safe
Local Signer(s) detected!
Do you want to sign unconfirmed transactions [y/N]: y
... # Sign with any local signers that have not confirmed yet
```

## Development

Please see the [contributing guide](CONTRIBUTING.md) to learn more how to contribute to this project.
Expand Down
42 changes: 32 additions & 10 deletions ape-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
plugins:
- name: solidity
- name: foundry
contracts_folder: tests/contracts

ethereum:
mainnet:
default_provider: alchemy
local:
default_provider: foundry

dependencies:
- name: openzeppelin
github: OpenZeppelin/openzeppelin-contracts
version: 3.4.0
- name: safe-contracts
github: safe-global/safe-contracts
npm: "@gnosis.pm/safe-contracts"
version: 1.3.0
config_override:
solidity:
version: 0.7.6
compile:
exclude:
- "test/*"
- "interfaces/*"

ethereum:
local:
default_provider: foundry
solidity:
import_remapping:
- "@openzeppelin/contracts=openzeppelin/v3.4.0"
- "@gnosis=safe-contracts/v1.3.0"

foundry:
fork:
ethereum:
mainnet:
upstream_provider: infura
ethereum:
mainnet:
upstream_provider: alchemy
block_number: 15776634
goerli:
upstream_provider: alchemy
block_number: 7849922
sepolia:
upstream_provider: alchemy
block_number: 3091950
17 changes: 15 additions & 2 deletions ape_safe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
from typing import Optional

from ape import plugins
from ape.api import PluginConfig

from .accounts import AccountContainer, SafeAccount
from .accounts import SafeAccount, SafeContainer
from .multisend import MultiSend


class SafeConfig(PluginConfig):
default_safe: Optional[str] = None
"""Alias of the default safe."""


@plugins.register(plugins.Config)
def config_class():
return SafeConfig


@plugins.register(plugins.AccountPlugin)
def account_types():
return AccountContainer, SafeAccount
return SafeContainer, SafeAccount


__all__ = [
Expand Down
Loading

0 comments on commit e3a3a0e

Please sign in to comment.