Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
fix: keyfile accounts signing issues and entire account flow (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jan 26, 2023
1 parent 9086bb7 commit 6c54a3d
Show file tree
Hide file tree
Showing 33 changed files with 2,203 additions and 1,009 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
File renamed without changes.
20 changes: 20 additions & 0 deletions .github/workflows/stale-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Close stale PRs"
on:
schedule:
- cron: '30 1 * * *'

jobs:
stale:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/stale@v6
with:
stale-pr-message: 'This pull request is considered stale because it has been open 30 days with no activity. Remove stale label, add a comment, or make a new commit, otherwise this PR will be closed in 5 days.'
close-pr-message: 'This PR was closed because it has been inactive for 35 days.'
stale-pr-label: "stale"
close-pr-label: "inactive"
days-before-pr-stale: 30
days-before-pr-close: 5
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
rev: v0.991
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests, types-setuptools]
additional_dependencies: [types-PyYAML, types-requests, types-setuptools, pydantic]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.14
Expand Down
84 changes: 66 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,83 @@ See the section below about [Testing](#Testing) to learn more about test account

However, when using a live network, you will have to import or create an account first.

#### Importing an Account

To import an account, use the `import` command:

```bash
ape starknet accounts import <ALIAS> --address 0x6b7111AA4111e5B2229c3332B66696888164440A773333143333B383333a183 --network starknet:testnet
ape starknet accounts import <ALIAS> \
--network testnet,testnet2 \
--address 0x6b7111AA4111e5B2229c3332B66696888164440A773333143333B383333a183 \
--class-hash "0x025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918"
--salt 123
```

To create a new account, you will use the `create` command:
The command above is using a network value of `testnet,testnet2`, meaning both Starknet's Goerli testnet and Goerli testnet2 networks.
You can run the import command more than once to add more networks at a later time.
To add all networks at once, you can also use a `--network` value of `starknet`.

If the account is already added, you can omit the `--address` flag and use the calculated one instead.
If you know the salt the account used to calculate its address, you can provide that with the `--salt` flag.
This will allow future deployments to use the same address.

Importing accounts is complex.
A common use-case is to import your Argent-X wallet.
To do this, you can use the following command:

```bash
ape starknet accounts create <NEW-ALIAS> --network starknet:testnet
ape starknet accounts import <ArgentX-Alias> \
--network starknet \
--address 0x6b7111AA4111e5B2229c3332B66696888164440A773333143333B383333a183 \
--class-hash argentx
```

The `create` command will first generate the public and private key combination and store a local keyfile for the account.
However, it does not deploy the account automatically.
The reason it does not deploy automatically is that the account needs funding to pay for its deployment and there are several ways to achieve this.
See [this section](https://starknet.io/docs/hello_starknet/account_setup.html#transferring-goerli-eth-to-the-account) of the Starknet official guides for more information.
And then export your Argent-X private key from the app and paste it in the CLI prompt.
Now, you can use your argent-x account to fund and create other accounts!

**NOTE**: You cannot use an Ethereum account to send funds to a Starknet account directly.
You must use the [StarkNet L2 bridge](https://goerli.starkgate.starknet.io/) to transfer existing Goerli L1 ETH to and from the L2 account.
#### Creating an Account

For convenience purposes, if you already have a Starknet account in Ape, you can use that account to fund the creation of new ones.
To do this, use the `--deployment-funder` flag to specify the funder alias of your other account:
To create a new account, you can use the `create` command:

```bash
ape starknet accounts create <NEW-ALIAS> --network starknet:testnet --deployment-funder <EXISTING-ALIAS>
ape starknet accounts create <NEW-ALIAS>
```

Otherwise, after you have funded your newly created account an alternative way, you can use the `deploy` command to deploy it:
By default, new accounts use the Open Zeppelin account contract implementation.
However, if you want to change the class, use the `--class-hash` option:

```bash
ape starknet accounts deploy <NEW-ALIAS>
CLASS_HASH="0x1a7820094feaf82d53f53f214b81292d717e7bb9a92bb2488092cd306f3993f"
ape starknet accounts create <NEW-ALIAS> --class-hash "${CLASS_HASH}"
```

You can create the same account in multiple networks by adjusting the `--network` flag:
**NOTE**: You may also need to change the constructor calldata using the `--constructor-calldata` flag when using a different account contract type.

The `create` command will first generate the public and private key combination and store a local keyfile for the account.
However, it does not deploy the account.
The reason it does not deploy is that the account needs funding to pay for its deployment and there are several ways to achieve this.
See [this section](https://starknet.io/docs/hello_starknet/account_setup.html#transferring-goerli-eth-to-the-account) of the Starknet official guides for more information.

#### Deploying an Account

To deploy the new account, use the `deploy` command:

```bash
ape starknet accounts create <ALIAS> --network starknet:mainnet
ape starknet accounts deploy <NEW-ALIAS> --network testnet
```

This only works if the account has been funded.
For convenience purposes, if you have another account with funds, you can use that account to fund the deployment of this one using the `--funder` option:

```bash
ape starknet account deploy <NEWLY-ALIAS> --network testnet --funder <EXISTING-FUNDED-ALIAS>
```

**NOTE**: You cannot use an Ethereum account to send funds to a Starknet account directly.
You must use the [StarkNet L2 bridge](https://goerli.starkgate.starknet.io/) to transfer existing Goerli L1 ETH to and from the L2 account.

#### Listing Accounts

See your accounts and all of their deployment addresses:

```bash
Expand All @@ -97,17 +135,27 @@ shows:
```bash
Alias - <ALIAS>
Public key - 0x123444444d716666dd88882bE2e99991555DE1c7
Class hash - 0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918
Contract address (testnet) - 0x6b7111AA4111e5B2229c3332B66696888164440A773333143333B383333a183
Contract address (mainnet) - 0x7873113A4111e5B2229c3332B66696388163440A373333143333B3833332122
```

#### Deleting an Account

You can also delete accounts:

```bash
ape starknet accounts delete <ALIAS> --network starknet:testnet
ape starknet accounts delete <ALIAS> --network testnet,testnet2
```

**NOTE**: You don't have to specify the network if your account is only deployed to a single network.
The `delete` command differs based on its values of `--network` and `--address`:

- To delete all deployments on a given network, use the `--network` option without `--address`.
- To delete all deployments matching an address (regardless of network), use the `--address` option without `--network`.
- To delete a deployment on a network with a particular address, use both `--network` and \`--address.
- Exclude both options to delete the whole account.

Note you can also specify multiple networks, the same as `import`.

#### Auto-Sign Message

Expand Down
15 changes: 10 additions & 5 deletions ape_starknet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
from ape.api.networks import LOCAL_NETWORK_NAME, NetworkAPI, create_network_type
from ape.types import AddressType

from ape_starknet.accounts import StarknetAccountContracts, StarknetKeyfileAccount
from ape_starknet.accounts import StarknetAccountContainer, StarknetKeyfileAccount
from ape_starknet.config import StarknetConfig
from ape_starknet.conversion import StarknetAddressConverter
from ape_starknet.conversion import StarknetAccountConverter, StarknetAddressConverter
from ape_starknet.ecosystems import Starknet
from ape_starknet.explorer import StarknetExplorer
from ape_starknet.provider import StarknetDevnetProvider, StarknetProvider
from ape_starknet.tokens import TokenManager
from ape_starknet.tokens import tokens
from ape_starknet.utils import NETWORKS, PLUGIN_NAME

tokens = TokenManager()
network_names = [LOCAL_NETWORK_NAME] + list(NETWORKS.keys())


@plugins.register(plugins.ConversionPlugin)
def converters():
yield AddressType, StarknetAddressConverter
yield int, StarknetAccountConverter


@plugins.register(plugins.Config)
Expand Down Expand Up @@ -49,10 +49,15 @@ def providers():

@plugins.register(plugins.AccountPlugin)
def account_types():
return StarknetAccountContracts, StarknetKeyfileAccount
return StarknetAccountContainer, StarknetKeyfileAccount


@plugins.register(plugins.ExplorerPlugin)
def explorers():
for network_name in network_names:
yield PLUGIN_NAME, network_name, StarknetExplorer


__all__ = [
"tokens",
]
Loading

0 comments on commit 6c54a3d

Please sign in to comment.