Skip to content

Commit c1c8978

Browse files
committed
Merge branch 'development'
2 parents 1927a4d + 976f1fd commit c1c8978

File tree

101 files changed

+2302
-1422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2302
-1422
lines changed

.github/codecov.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
codecov:
22
notify:
33
after_n_builds: 4
4+
require_ci_to_pass: no
5+
6+
coverage:
7+
status: off
8+
9+
comment:
10+
layout: "diff, flags, files"
11+
behavior: default
12+
require_changes: no

.github/workflows/checks.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,14 @@ jobs:
208208
strategy:
209209
fail-fast: false
210210
env:
211-
INTEGRATION_RPC_URL: ${{ secrets.INTEGRATION_RPC_URL }}
212-
TESTNET_RPC_URL: ${{ secrets.TESTNET_RPC_URL }}
213-
INTEGRATION_ACCOUNT_PRIVATE_KEY: ${{ secrets.INTEGRATION_ACCOUNT_PRIVATE_KEY }}
214-
INTEGRATION_ACCOUNT_ADDRESS: ${{ secrets.INTEGRATION_ACCOUNT_ADDRESS }}
215-
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
216-
TESTNET_ACCOUNT_ADDRESS: ${{ secrets.TESTNET_ACCOUNT_ADDRESS }}
211+
GOERLI_INTEGRATION_RPC_URL: ${{ secrets.INTEGRATION_RPC_URL }}
212+
GOERLI_TESTNET_RPC_URL: ${{ secrets.TESTNET_RPC_URL }}
213+
SEPOLIA_INTEGRATION_RPC_URL: ${{ secrets.SEPOLIA_INTEGRATION_RPC_URL }}
214+
SEPOLIA_TESTNET_RPC_URL: ${{ secrets.SEPOLIA_TESTNET_RPC_URL }}
215+
GOERLI_INTEGRATION_ACCOUNT_PRIVATE_KEY: ${{ secrets.INTEGRATION_ACCOUNT_PRIVATE_KEY }}
216+
GOERLI_INTEGRATION_ACCOUNT_ADDRESS: ${{ secrets.INTEGRATION_ACCOUNT_ADDRESS }}
217+
GOERLI_TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
218+
GOERLI_TESTNET_ACCOUNT_ADDRESS: ${{ secrets.TESTNET_ACCOUNT_ADDRESS }}
217219
steps:
218220
- uses: actions/checkout@v3
219221

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ exclude-too-few-public-methods=
543543
ignored-parents=
544544

545545
# Maximum number of arguments for function / method.
546-
max-args=5
546+
max-args=6
547547

548548
# Maximum number of attributes for a class (see R0902).
549549
max-attributes=7

docs/account_creation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ Here is step by step example:
3232

3333
If you are experiencing transaction failures with ``FEE_TRANSFER_FAILURE``
3434
make sure that the address you are trying to deploy is prefunded with enough
35-
tokens, and verify that ``max_fee`` argument
36-
in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_transaction` is set
35+
tokens, and verify that ``max_fee`` argument in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_v1`
36+
or ``l1_resource_bounds`` argument in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_v3` is set
3737
to a high enough value.

docs/api/contract.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ PreparedFunctionCall
3434
:members:
3535
:member-order: groupwise
3636

37+
------------------------
38+
PreparedFunctionInvokeV1
39+
------------------------
40+
41+
.. autoclass-with-examples:: PreparedFunctionInvokeV1
42+
:exclude-members: __init__, __new__
43+
:members:
44+
:member-order: groupwise
45+
46+
------------------------
47+
PreparedFunctionInvokeV3
48+
------------------------
49+
50+
.. autoclass-with-examples:: PreparedFunctionInvokeV3
51+
:exclude-members: __init__, __new__
52+
:members:
53+
:member-order: groupwise
54+
3755
------------
3856
InvokeResult
3957
------------

docs/development.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,33 @@ Below is the command you can use to do this, designed for compatibility with the
2525

2626
.. code-block:: bash
2727
28-
STARKNET_VERSION="0.12.3" RPC_SPEC_VERSION="0.5.1" \
28+
STARKNET_VERSION="0.13.0" RPC_SPEC_VERSION="0.6.0" \
2929
cargo install \
3030
--locked \
3131
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
32-
--rev 78527de
32+
--rev 1bd447d
3333
3434
If you choose to install `starknet-devnet-rs <https://github.com/0xSpaceShard/starknet-devnet-rs>`_ using a different method, please make sure to add the executable ``starknet-devnet`` to your ``PATH`` environment variable.
3535

3636
In order to be able to run tests on testnet and integration networks (``starknet_py/tests/e2e/tests_on_networks/``), you must set some environmental variables:
3737

38-
- ``INTEGRATION_RPC_URL``
39-
- ``TESTNET_RPC_URL``
40-
- ``INTEGRATION_ACCOUNT_PRIVATE_KEY``
41-
- ``INTEGRATION_ACCOUNT_ADDRESS``
42-
- ``TESTNET_ACCOUNT_PRIVATE_KEY``
43-
- ``TESTNET_ACCOUNT_ADDRESS``
38+
- ``GOERLI_INTEGRATION_RPC_URL``
39+
- ``GOERLI_TESTNET_RPC_URL``
40+
- ``SEPOLIA_INTEGRATION_RPC_URL``
41+
- ``SEPOLIA_TESTNET_RPC_URL``
42+
- ``GOERLI_INTEGRATION_ACCOUNT_PRIVATE_KEY``
43+
- ``GOERLI_INTEGRATION_ACCOUNT_ADDRESS``
44+
- ``GOERLI_TESTNET_ACCOUNT_PRIVATE_KEY``
45+
- ``GOERLI_TESTNET_ACCOUNT_ADDRESS``
4446

45-
The best way to do that is to create ``test-variables.env`` file in ``starknet_py/tests/e2e/`` directory, so they can be loaded by the ``python-dotenv`` library.
47+
The existing tests don't execute any invoke transactions on the Sepolia networks. If you plan to incorporate such tests, please also set the following environment variables:
48+
49+
- ``SEPOLIA_INTEGRATION_ACCOUNT_PRIVATE_KEY``
50+
- ``SEPOLIA_INTEGRATION_ACCOUNT_ADDRESS``
51+
- ``SEPOLIA_TESTNET_ACCOUNT_PRIVATE_KEY``
52+
- ``SEPOLIA_TESTNET_ACCOUNT_ADDRESS``
53+
54+
The best way to set environment variables is to create ``test-variables.env`` file in ``starknet_py/tests/e2e/`` directory, so they can be loaded by the ``python-dotenv`` library.
4655
You can find an example file ``test-variables.env.template`` in the same directory with the format of how it should look like.
4756

4857
.. code-block:: bash

docs/guide/account_and_client.rst

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,41 @@ Account and Client
44
Executing transactions
55
----------------------
66

7-
To execute transactions on Starknet, use :meth:`~starknet_py.net.account.account.Account.execute` method from :ref:`Account` interface.
7+
To execute transactions on Starknet, use :meth:`~starknet_py.net.account.account.Account.execute_v1` or :meth:`~starknet_py.net.account.account.Account.execute_v3` methods from :ref:`Account` interface.
8+
These methods will send :class:`~starknet_py.net.models.InvokeV1` and :class:`~starknet_py.net.models.InvokeV3` transactions respectively. To read about differences between transaction versions please visit `transaction types <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions>`_ from the Starknet docs.
89

910
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_executing_transactions.py
1011
:language: python
1112
:dedent: 4
1213

14+
Transaction Fee
15+
---------------
16+
17+
All methods within the :ref:`Account` that involve on-chain modifications require either specifying a maximum transaction fee or using auto estimation.
18+
In the case of V1 and V2 transactions, the transaction fee, denoted in Wei, is configured by the ``max_fee`` parameter.
19+
For V3 transactions, however, the fee is expressed in Fri and is determined by the ``l1_resource_bounds`` parameter.
20+
To enable auto estimation, set the ``auto_estimate`` parameter to ``True``.
21+
22+
.. code-block:: python
23+
24+
resp = await account.execute_v1(calls=call, auto_estimate=True)
25+
26+
.. warning::
27+
28+
It is strongly discouraged to use automatic fee estimation in production code as it may lead to an unexpectedly high fee.
29+
30+
The returned estimated fee is multiplied by ``1.5`` for V1 and V2 transactions to mitigate fluctuations in price.
31+
For V3 transactions, ``max_amount`` and ``max_price_per_unit`` are scaled by ``1.1`` and ``1.5`` respectively.
32+
33+
34+
.. note::
35+
It is possible to configure the value by which the estimated fee is multiplied,
36+
by changing ``ESTIMATED_FEE_MULTIPLIER`` for V1 and V2 transactions in :class:`~starknet_py.net.account.account.Account`.
37+
The same applies to ``ESTIMATED_AMOUNT_MULTIPLIER`` and ``ESTIMATED_UNIT_PRICE_MULTIPLIER`` for V3 transactions.
38+
1339
Creating transactions without executing them
1440
--------------------------------------------
1541

16-
Alongside the simpler :meth:`~starknet_py.net.account.account.Account.execute`,
1742
Account also provides a way of creating signed transaction without sending them.
1843

1944
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_account_sign_without_execute.py
@@ -24,7 +49,7 @@ Multicall
2449
---------
2550

2651
There is a possibility to execute an Invoke transaction containing multiple calls.
27-
Simply pass a list of calls to :meth:`~starknet_py.net.account.account.Account.execute` method.
52+
Simply pass a list of calls to :meth:`~starknet_py.net.account.account.Account.execute_v1` or :meth:`~starknet_py.net.account.account.Account.execute_v3` methods.
2853
Note that the nonce will be bumped only by 1.
2954

3055
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_multicall.py
@@ -38,8 +63,6 @@ Note that the nonce will be bumped only by 1.
3863

3964
Do not pass arbitrarily large number of calls in one batch. Starknet rejects the transaction when it happens.
4065

41-
42-
4366
FullNodeClient usage
4467
--------------------
4568

docs/guide/deploying_contracts.rst

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@ Deploying contracts
44
Declaring contracts
55
-------------------
66

7-
Since Cairo 0.10.0 Declare transactions can be signed and in the future, declaring without signing the transaction
8-
(and without paying the fee) will be impossible. That is why :ref:`Account` has
9-
:meth:`sign_declare_transaction()` method.
7+
A declare transaction can be issued in version 1, 2 or 3. Contracts written in Cairo 0 should be declared using version 1, while those written in Cairo 1 or higher should be declared with versions 2 or 3.
8+
To sign a declare transaction, you should utilize the :meth:`~starknet_py.net.account.account.Account.sign_declare_v1`, :meth:`~starknet_py.net.account.account.Account.sign_declare_v2` or :meth:`~starknet_py.net.account.account.Account.sign_declare_v3` method, respectively.
109

1110
Here's an example how to use it.
1211

1312
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py
1413
:language: python
1514
:dedent: 4
1615

17-
.. note::
18-
19-
Signing Declare transactions is possible only with Accounts having `__validate__` entrypoint (with `supported_tx_version = 1`).
20-
21-
2216

2317
Simple declare and deploy
2418
-------------------------
2519

2620
The simplest way of declaring and deploying contracts on the Starknet is to use the :ref:`Contract` class.
27-
Under the hood, this flow sends :meth:`Declare` transaction and then sends :meth:`InvokeFunction`
21+
Under the hood, this flow first sends ``Declare`` transaction and then sends ``Invoke``
2822
through Universal Deployment Contract (UDC) to deploy a contract.
2923

3024
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py
@@ -34,7 +28,7 @@ through Universal Deployment Contract (UDC) to deploy a contract.
3428
Simple deploy
3529
-------------
3630

37-
If you already know the class hash of an already declared contract you want to deploy just use the :meth:`Contract.deploy_contract`.
31+
If you know the class hash of an already declared contract you want to deploy just use the :meth:`~starknet_py.contract.Contract.deploy_contract_v1` or :meth:`~starknet_py.contract.Contract.deploy_contract_v3`.
3832
It will deploy the contract using funds from your account. Deployment is handled by UDC.
3933

4034
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_simple_deploy.py
@@ -62,7 +56,6 @@ Deploying and using deployed contract in the same transaction
6256

6357
:ref:`Deployer` is designed to work with multicalls too. It allows to deploy a contract
6458
and call its methods in the same multicall, ensuring atomicity of all operations combined.
65-
Isn't it brilliant? Check out the code!
6659

6760
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py
6861
:language: python
@@ -75,9 +68,7 @@ Cairo1 contracts
7568
Declaring Cairo1 contracts
7669
##########################
7770

78-
| Starknet 0.11 introduced the ability to declare contracts written in Cairo1!
79-
80-
To declare a new contract, Declare v2 or Declare v3 transaction has to be sent.
71+
To declare a contract in Cairo version 1 or higher, Declare V2 or Declare V3 transaction has to be sent.
8172
You can see the structure of these transactions `here <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions/#declare-transaction>`_.
8273

8374
The main differences in the structure of the transaction from its previous version are:

docs/guide/using_existing_contracts.rst

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,77 +37,81 @@ If you do not have ABI statically, but you know the interface of the contract on
3737
Fees
3838
----
3939

40-
starknet.py requires you to specify amount of Wei you
41-
are willing to pay either when making ``.invoke()`` transactions or when preparing
42-
function calls with ``.prepare()``.
40+
.. currentmodule:: starknet_py.contract
41+
42+
Starknet.py requires you to specify amount of Wei (for V1 transaction) or Fri (for V3 transaction) you
43+
are willing to pay when executing either :meth:`~ContractFunction.invoke_v1` or :meth:`~ContractFunction.invoke_v3` transactions.
44+
Alternatively, you can estimate fee automatically, as described in the :ref:`automatic-fee-estimation` section below.
4345

4446
.. code-block:: python
4547
46-
await contract.functions["put"].invoke(k, v, max_fee=5000)
48+
await contract.functions["put"].invoke_v1(k, v, max_fee=5000)
4749
48-
When max_fee is specified when preparing a call, you can invoke it without
49-
``max_fee``.
50+
The ``max_fee`` argument can be also defined in :meth:`~ContractFunction.prepare_invoke_v1`. Subsequently, the :meth:`~PreparedFunctionInvokeV1.invoke` method on a prepared call can be used either with ``max_fee`` omitted or with its value overridden.
51+
The same behavior applies to :meth:`~ContractFunction.prepare_invoke_v3` and ``l1_resource_bounds``.
5052

5153
.. code-block:: python
5254
53-
prepared_call = contract.function["put"].prepare(k, v, max_fee=5000)
55+
prepared_call = contract.function["put"].prepare_invoke_v1(k, v, max_fee=5000)
5456
await prepared_call.invoke()
57+
# or max_fee can be overridden
58+
await prepared_call.invoke(max_fee=10000)
5559
5660
.. warning::
5761

58-
If ``max_fee`` is not specified at any step it will default to ``None``,
59-
and will raise an exception when invoking a transaction.
62+
For V1 transactions if ``max_fee`` is not specified at any step it will default to ``None``,
63+
and will raise an exception when invoking a transaction, unless `auto_estimate` is specified and is set to `True`. The same applies to ``l1_resource_bounds`` and V3 transactions.
6064

61-
Please note you will need to have enough Wei in your Starknet account otherwise
65+
Please note you will need to have enough Wei (for V1 transaction) or Fri (for V3 transaction) in your Starknet account otherwise
6266
transaction will be rejected.
6367

6468
Fee estimation
6569
--------------
6670

6771
You can estimate required amount of fee that will need to be paid for transaction
68-
using :meth:`PreparedFunctionCall.estimate_fee() <starknet_py.contract.PreparedFunctionCall.estimate_fee>`
72+
using :meth:`PreparedFunctionInvoke.estimate_fee() <starknet_py.contract.PreparedFunctionInvoke.estimate_fee>`
6973

7074
.. code-block:: python
7175
72-
await contract.functions["put"].prepare(k, v, max_fee=5000).estimate_fee()
76+
await contract.functions["put"].prepare_invoke_v1(k, v).estimate_fee()
7377
78+
.. _automatic-fee-estimation:
7479

7580
Automatic fee estimation
7681
------------------------
7782

78-
For testing purposes it is possible to enable automatic fee estimation when making
79-
a transaction. starknet.py will then use ``estimate_fee()`` internally and use value
80-
returned by it multiplied by ``1.5`` as a ``max_fee``.
81-
82-
.. warning::
83-
84-
Do not use automatic fee estimation in production code! It may lead to
85-
very high fees paid as the amount returned by ``estimate_fee()`` may be arbitrarily large.
83+
For testing purposes it is possible to enable automatic fee estimation when making a transaction. Starknet.py will then call :meth:`~starknet_py.net.full_node_client.FullNodeClient.estimate_fee`
84+
internally and use the returned value, multiplied by ``1.5`` to mitigate fluctuations in price, as a ``max_fee`` for V1 transactions. For V3 transactions,
85+
``max_amount`` will be multiplied by ``1.1``, and ``max_price_per_unit`` by ``1.5``.
8686

8787
.. code-block:: python
8888
89-
await contract.functions["put"].invoke(k, v, auto_estimate=True)
89+
await contract.functions["put"].invoke_v1(k, v, auto_estimate=True)
90+
91+
.. warning::
9092

93+
It is strongly discouraged to use automatic fee estimation in production code as it may lead to unexpectedly high fee.
9194

9295
.. note::
93-
It is possible to configure the value by which the estimated fee is multiplied,
94-
by changing ``ESTIMATED_FEE_MULTIPLIER`` in :class:`~starknet_py.net.account.account.Account`.
96+
For V1 transactions it is possible to configure the value by which the estimated fee is multiplied,
97+
by changing ``ESTIMATED_FEE_MULTIPLIER`` in :class:`~starknet_py.net.account.account.Account`. The same applies to
98+
``ESTIMATED_AMOUNT_MULTIPLIER`` and ``ESTIMATED_UNIT_PRICE_MULTIPLIER`` for V3 transactions.
9599

96100
Account and Client interoperability
97101
-----------------------------------
98102

99103
.. currentmodule:: starknet_py.contract
100104

101-
:ref:`Contract` methods have been designed to be
102-
compatible with :ref:`Account` and :ref:`Client`.
105+
:ref:`Contract` methods have been designed to be compatible with :ref:`Account` and :ref:`Client`.
103106

104-
:ref:`PreparedFunctionCall` returned by :meth:`ContractFunction.prepare` can be used in Account methods to create Invoke transactions.
107+
:ref:`PreparedFunctionInvokeV1` and :ref:`PreparedFunctionInvokeV3` returned by :meth:`ContractFunction.prepare_invoke_v1` and :meth:`ContractFunction.prepare_invoke_v3` respectively can be used in Account methods to create Invoke transactions.
105108

106109
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_contract_account_compatibility.py
107110
:language: python
108111
:dedent: 4
109112

110-
It can also be used in :meth:`Client.call_contract() <starknet_py.net.client.Client.call_contract>`
113+
114+
Similarly, :ref:`PreparedFunctionCall` returned by :meth:`ContractFunction.prepare_call` can be used in :meth:`Client.call_contract() <starknet_py.net.client.Client.call_contract>`
111115

112116
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_contract_client_compatibility.py
113117
:language: python

docs/installation.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ You can install starknet.py on Windows in two ways:
5050

5151
1. Install it just like you would on Linux.
5252

53-
You might encounter problems related to ``libcrypto_c_exports``.
54-
5553
In such case make sure that you have `MinGW <https://www.mingw-w64.org/>`_ installed and up-to-date.
5654

5755
.. hint::
58-
An easy way to install MinGW is through `chocolatey <https://community.chocolatey.org/packages/mingw>`_.
56+
The recommended way to install is through `chocolatey <https://community.chocolatey.org/packages/mingw>`_.
5957

6058
You also should have MinGW in your PATH environment variable (e.g. ``C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin``).
6159

60+
.. warning::
61+
Please be aware that you may encounter issues related to ``libcrypto_c_exports`` (e.g LoadLibraryEx).
62+
Installing MinGW via chocolatey and correctly adding it to the PATH should solve these issues.
6263

6364
If you encounter any further problems related to installation, you can create an `issue at our GitHub <https://github.com/software-mansion/starknet.py/issues/new?assignees=&labels=bug&projects=&template=bug_report.yaml&title=%5BBUG%5D+%3Ctitle%3E>`_
6465
or ask for help in ``#🐍 | starknet-py`` channel on `Starknet Discord server <https://starknet.io/discord>`_.

0 commit comments

Comments
 (0)