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

refactor!: new flow [APE-1140] #11

Merged
merged 135 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
925f390
refactor: fix Safe API endpoints
fubuloubu Jun 28, 2023
6811528
refactor: make SafeTxID a HexBytes subclass
fubuloubu Jun 28, 2023
549dfbb
feat: add API wrapper for fetching confirmations
fubuloubu Jun 28, 2023
5fab050
feat: add method for fetching pending confirmations to SafeAccount
fubuloubu Jun 28, 2023
e359dbc
feat: add method for fetching confirmations as signature dict
fubuloubu Jun 28, 2023
8af0812
refactor: allow pending txn CLI to submit txns
fubuloubu Jun 28, 2023
9c1ad3d
refactor: add proper exceptions for Safe API client errors
fubuloubu Jun 28, 2023
0906116
refactor: Use ABC for SafeClient to support Mock
fubuloubu Jun 28, 2023
10932e5
feat: add SafeClient mock (for testing)
fubuloubu Jun 28, 2023
f707648
refactor: add client origin string to POST requests
fubuloubu Jun 28, 2023
3c6d3b8
test: use new Ape mock events comparison API
fubuloubu Jun 28, 2023
87ef9f0
fix: wrong signature encoding
fubuloubu Jun 29, 2023
20a9038
refactor: move signature ordering algorithm to utils
fubuloubu Jun 29, 2023
5457a0b
fix: load UnexecutedSafeTxData from SafeTx properly
fubuloubu Jun 29, 2023
e7fe1e8
fix: handle scenario where modules/guard is not supported by safe ver
fubuloubu Jun 29, 2023
79d6924
refactor: add api confirmations to all confs, handle client error
fubuloubu Jun 29, 2023
fe2c762
refactor: extract submitter loader into it's own method
fubuloubu Jun 29, 2023
89e7f47
feat: add utility function for submitting already conf'd SafeTx
fubuloubu Jun 29, 2023
1990cf5
feat: submit to Safe API if not submitting transaction
fubuloubu Jun 29, 2023
14b3318
test: show skipping submit can be executed from mock client
fubuloubu Jun 29, 2023
e94c2d4
Merge branch 'main' into feat/safe-api
dtdang Sep 7, 2023
3b86495
fix: change safe_tx_hash to hex value
dtdang Sep 7, 2023
f1dc4ba
docs: add more documentation
dtdang Sep 8, 2023
ef095b6
fix: empty raises
dtdang Sep 8, 2023
ba27c8e
fix: reivew comments
dtdang Sep 14, 2023
3aef2ad
fix: mock client transaction hash
dtdang Sep 15, 2023
a9316d4
fix: cli pending transactions
dtdang Sep 18, 2023
15fe09b
refactor: cli
antazoey Sep 19, 2023
8ec71d8
refactor: small fixes
antazoey Sep 19, 2023
31b86e6
fix: submit kwarg fix
antazoey Sep 19, 2023
cc416d3
feat: sign on pending
antazoey Sep 19, 2023
07d5c5b
fix: make requests work again
antazoey Sep 19, 2023
3c40b5d
chore: small fixes
antazoey Sep 19, 2023
bd361f9
fix: remove unnecessary confirmation error
dtdang Sep 20, 2023
6f79d35
docs: add service url notes
dtdang Sep 20, 2023
d2f0658
fix: exception handler response
dtdang Sep 20, 2023
1acec78
feat: add safe tx argument
dtdang Sep 20, 2023
fac48e3
fix: change default operation delegatecall
dtdang Sep 20, 2023
fe27eb7
chore: mypy
dtdang Sep 22, 2023
806d811
fix: multisend operation kwarg
dtdang Sep 26, 2023
1578a24
chore: mypy
dtdang Sep 26, 2023
880f433
fix: txn_kwargs impersonate
dtdang Sep 28, 2023
33ab14d
test: multisend operation
dtdang Oct 12, 2023
662d690
chore: mockclient mypy
dtdang Oct 12, 2023
a9f2646
chore: change to union
dtdang Oct 12, 2023
a8c3985
fix: remove extra parenthesis
dtdang Oct 12, 2023
f5b1e4d
fix: network fixture
dtdang Oct 12, 2023
cb47135
fix: foundry and alchemy
dtdang Oct 12, 2023
83f0c6e
fix: test dependencies location
dtdang Oct 25, 2023
af65c12
fix: remove get_args
dtdang Oct 25, 2023
254bfea
fix: confirmations required for signing
dtdang Oct 25, 2023
84b63d1
fix: add network warning
dtdang Oct 25, 2023
ef0bf21
fix: remove comment for url
dtdang Oct 25, 2023
43c06d8
refactor: multisend fixture
dtdang Oct 25, 2023
688d02a
fix: remove version pins
dtdang Oct 25, 2023
d5a98fa
fix: access data using .get
dtdang Oct 25, 2023
4ae4fcc
docs: fix syntax mistake
dtdang Oct 25, 2023
dd50fa0
fix: update call comment
dtdang Oct 25, 2023
d855479
fix: issues with pending
antazoey Oct 31, 2023
d4ed17a
fix: cli fixes
antazoey Oct 31, 2023
0d17dfe
feat: better forked net handling
antazoey Oct 31, 2023
b9a43b2
fix: cli parens
antazoey Oct 31, 2023
5a2197f
docs: add raises doc
antazoey Oct 31, 2023
796f917
docs: add raises doc
antazoey Oct 31, 2023
51d07b6
fix: handle when converted in addresses
antazoey Oct 31, 2023
b085060
docs: say why needed
antazoey Oct 31, 2023
ea5db70
fix: utc now
antazoey Oct 31, 2023
5b79704
feat: snake case ify
antazoey Oct 31, 2023
beb2719
feat: better vm checks
antazoey Oct 31, 2023
16bafe7
refacor: switch to assert
antazoey Oct 31, 2023
ec24330
fix: regression issues
antazoey Oct 31, 2023
940d0eb
refactor: use key
antazoey Oct 31, 2023
d289942
chore: use doc str for short help
antazoey Nov 1, 2023
7728910
chore: lint deps
antazoey Nov 1, 2023
7c7d8b9
refactor: switch to npm dep
antazoey Nov 1, 2023
5c340c7
chore: bump ape
antazoey Nov 3, 2023
dec9009
chore: delete hacks
antazoey Nov 3, 2023
3a8c806
test: call with cls
antazoey Nov 3, 2023
e7617f0
chore: del stuff
antazoey Nov 3, 2023
cd31696
test: del alchemy
antazoey Nov 3, 2023
1ffd543
refactor: more submitter callback
antazoey Nov 3, 2023
b91bac4
feat: wip
antazoey Nov 27, 2023
aded29d
refactor: and fix
antazoey Nov 28, 2023
0b2421f
docs: update docs
antazoey Nov 28, 2023
70840ba
fix: part of hash fix
antazoey Nov 29, 2023
b8d3cbb
feat: execute cli
antazoey Nov 30, 2023
31e04da
chore: print when no tx
antazoey Nov 30, 2023
a512399
refactor: allow x sigs
antazoey Dec 2, 2023
3eff332
chore: highlight problem
antazoey Dec 2, 2023
cc0aeb6
feat: sepolia support
antazoey Dec 4, 2023
7575821
fix: signature
antazoey Dec 4, 2023
10db013
fix: critical trailing slash
antazoey Dec 4, 2023
22d1fed
fix: tx getting and id issue
antazoey Dec 5, 2023
69d582b
feat: way better list cmds
antazoey Dec 5, 2023
a416b2d
fix: get_api_confs fix
antazoey Dec 5, 2023
bc41763
refactor: use eip712 hash calc
antazoey Dec 6, 2023
f7c87b1
fix: title
antazoey Dec 6, 2023
650a05f
feat: allow hashes in cli
antazoey Dec 6, 2023
a06a831
feat: allow approving x
antazoey Dec 6, 2023
ad3935b
fix: figured out how to sign
antazoey Dec 6, 2023
3886024
fix: CLI txn ids and err imprv
antazoey Dec 6, 2023
968c732
fix: issue with submit
antazoey Dec 6, 2023
6fd8a2e
fix: improve tx verbose disp
antazoey Dec 6, 2023
c06f0f2
fix: type issue
antazoey Dec 7, 2023
c6a21ea
feat: propose and reject 'fix'
antazoey Dec 7, 2023
b07d7a9
fix: issues with post_tx
antazoey Dec 7, 2023
a40b42b
fix: txns work now
antazoey Dec 7, 2023
b06b3fb
chore: bump ape
antazoey Dec 11, 2023
aa932f9
fix: metadata setup
antazoey Dec 11, 2023
0b804ba
fix: type fixes
antazoey Dec 11, 2023
d50a2fa
fix: flake8 fix
antazoey Dec 11, 2023
95749d0
fix: more type ignores
antazoey Dec 11, 2023
e7b0340
fix: pydantic 2 issue
antazoey Dec 11, 2023
7d753c2
fix: force to pin pydantic :(
antazoey Dec 11, 2023
7fbff68
chore: upgrade to 0.7
antazoey Dec 20, 2023
adf4e39
feat: complete upgrade
antazoey Dec 20, 2023
377deef
chore: bump ape
antazoey Dec 20, 2023
72b372a
refactor: sigs
antazoey Dec 20, 2023
c7ceb77
chore: more 07 upgrade
antazoey Dec 20, 2023
8f737b1
chore: spacing fix
antazoey Dec 20, 2023
ce487f3
refactor: use a lambda
antazoey Dec 20, 2023
2ac779f
test: add tests for order
antazoey Dec 20, 2023
9f5c939
fix: fixes
antazoey Dec 20, 2023
2a0a883
fix: more tx fix and refactor
antazoey Dec 20, 2023
d2ae0c6
feat: allow nonce in cli
antazoey Dec 21, 2023
d9709cc
fix: more deprecation fix
antazoey Dec 21, 2023
27aa7ef
test: init cli test
antazoey Dec 21, 2023
252208e
fix: issue with 38 39 cli annotated type
antazoey Dec 21, 2023
368a400
feat: default safe config
antazoey Dec 21, 2023
b99c065
fix: remove alias arg instead of opt
antazoey Dec 21, 2023
7a324c6
feat: use skip conf opt
antazoey Dec 21, 2023
b3c8f29
fix: issue with pending when had no safes
antazoey Dec 21, 2023
c1acab2
test: no tx test
antazoey Dec 21, 2023
f590a55
fix: issues with network in list cmd
antazoey Dec 21, 2023
178b4cb
docs: much improve guide
antazoey Dec 21, 2023
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
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