Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoktorski committed Feb 6, 2024
2 parents 1927a4d + 976f1fd commit c1c8978
Show file tree
Hide file tree
Showing 101 changed files with 2,302 additions and 1,422 deletions.
9 changes: 9 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
codecov:
notify:
after_n_builds: 4
require_ci_to_pass: no

coverage:
status: off

comment:
layout: "diff, flags, files"
behavior: default
require_changes: no
14 changes: 8 additions & 6 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@ jobs:
strategy:
fail-fast: false
env:
INTEGRATION_RPC_URL: ${{ secrets.INTEGRATION_RPC_URL }}
TESTNET_RPC_URL: ${{ secrets.TESTNET_RPC_URL }}
INTEGRATION_ACCOUNT_PRIVATE_KEY: ${{ secrets.INTEGRATION_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_ACCOUNT_ADDRESS: ${{ secrets.INTEGRATION_ACCOUNT_ADDRESS }}
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
TESTNET_ACCOUNT_ADDRESS: ${{ secrets.TESTNET_ACCOUNT_ADDRESS }}
GOERLI_INTEGRATION_RPC_URL: ${{ secrets.INTEGRATION_RPC_URL }}
GOERLI_TESTNET_RPC_URL: ${{ secrets.TESTNET_RPC_URL }}
SEPOLIA_INTEGRATION_RPC_URL: ${{ secrets.SEPOLIA_INTEGRATION_RPC_URL }}
SEPOLIA_TESTNET_RPC_URL: ${{ secrets.SEPOLIA_TESTNET_RPC_URL }}
GOERLI_INTEGRATION_ACCOUNT_PRIVATE_KEY: ${{ secrets.INTEGRATION_ACCOUNT_PRIVATE_KEY }}
GOERLI_INTEGRATION_ACCOUNT_ADDRESS: ${{ secrets.INTEGRATION_ACCOUNT_ADDRESS }}
GOERLI_TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
GOERLI_TESTNET_ACCOUNT_ADDRESS: ${{ secrets.TESTNET_ACCOUNT_ADDRESS }}
steps:
- uses: actions/checkout@v3

Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ exclude-too-few-public-methods=
ignored-parents=

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

# Maximum number of attributes for a class (see R0902).
max-attributes=7
Expand Down
4 changes: 2 additions & 2 deletions docs/account_creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ Here is step by step example:

If you are experiencing transaction failures with ``FEE_TRANSFER_FAILURE``
make sure that the address you are trying to deploy is prefunded with enough
tokens, and verify that ``max_fee`` argument
in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_transaction` is set
tokens, and verify that ``max_fee`` argument in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_v1`
or ``l1_resource_bounds`` argument in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_v3` is set
to a high enough value.
18 changes: 18 additions & 0 deletions docs/api/contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ PreparedFunctionCall
:members:
:member-order: groupwise

------------------------
PreparedFunctionInvokeV1
------------------------

.. autoclass-with-examples:: PreparedFunctionInvokeV1
:exclude-members: __init__, __new__
:members:
:member-order: groupwise

------------------------
PreparedFunctionInvokeV3
------------------------

.. autoclass-with-examples:: PreparedFunctionInvokeV3
:exclude-members: __init__, __new__
:members:
:member-order: groupwise

------------
InvokeResult
------------
Expand Down
27 changes: 18 additions & 9 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,33 @@ Below is the command you can use to do this, designed for compatibility with the

.. code-block:: bash
STARKNET_VERSION="0.12.3" RPC_SPEC_VERSION="0.5.1" \
STARKNET_VERSION="0.13.0" RPC_SPEC_VERSION="0.6.0" \
cargo install \
--locked \
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
--rev 78527de
--rev 1bd447d
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.

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:

- ``INTEGRATION_RPC_URL``
- ``TESTNET_RPC_URL``
- ``INTEGRATION_ACCOUNT_PRIVATE_KEY``
- ``INTEGRATION_ACCOUNT_ADDRESS``
- ``TESTNET_ACCOUNT_PRIVATE_KEY``
- ``TESTNET_ACCOUNT_ADDRESS``
- ``GOERLI_INTEGRATION_RPC_URL``
- ``GOERLI_TESTNET_RPC_URL``
- ``SEPOLIA_INTEGRATION_RPC_URL``
- ``SEPOLIA_TESTNET_RPC_URL``
- ``GOERLI_INTEGRATION_ACCOUNT_PRIVATE_KEY``
- ``GOERLI_INTEGRATION_ACCOUNT_ADDRESS``
- ``GOERLI_TESTNET_ACCOUNT_PRIVATE_KEY``
- ``GOERLI_TESTNET_ACCOUNT_ADDRESS``

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.
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:

- ``SEPOLIA_INTEGRATION_ACCOUNT_PRIVATE_KEY``
- ``SEPOLIA_INTEGRATION_ACCOUNT_ADDRESS``
- ``SEPOLIA_TESTNET_ACCOUNT_PRIVATE_KEY``
- ``SEPOLIA_TESTNET_ACCOUNT_ADDRESS``

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.
You can find an example file ``test-variables.env.template`` in the same directory with the format of how it should look like.

.. code-block:: bash
Expand Down
33 changes: 28 additions & 5 deletions docs/guide/account_and_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,41 @@ Account and Client
Executing transactions
----------------------

To execute transactions on Starknet, use :meth:`~starknet_py.net.account.account.Account.execute` method from :ref:`Account` interface.
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.
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.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_executing_transactions.py
:language: python
:dedent: 4

Transaction Fee
---------------

All methods within the :ref:`Account` that involve on-chain modifications require either specifying a maximum transaction fee or using auto estimation.
In the case of V1 and V2 transactions, the transaction fee, denoted in Wei, is configured by the ``max_fee`` parameter.
For V3 transactions, however, the fee is expressed in Fri and is determined by the ``l1_resource_bounds`` parameter.
To enable auto estimation, set the ``auto_estimate`` parameter to ``True``.

.. code-block:: python
resp = await account.execute_v1(calls=call, auto_estimate=True)
.. warning::

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

The returned estimated fee is multiplied by ``1.5`` for V1 and V2 transactions to mitigate fluctuations in price.
For V3 transactions, ``max_amount`` and ``max_price_per_unit`` are scaled by ``1.1`` and ``1.5`` respectively.


.. note::
It is possible to configure the value by which the estimated fee is multiplied,
by changing ``ESTIMATED_FEE_MULTIPLIER`` for V1 and V2 transactions in :class:`~starknet_py.net.account.account.Account`.
The same applies to ``ESTIMATED_AMOUNT_MULTIPLIER`` and ``ESTIMATED_UNIT_PRICE_MULTIPLIER`` for V3 transactions.

Creating transactions without executing them
--------------------------------------------

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

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_account_sign_without_execute.py
Expand All @@ -24,7 +49,7 @@ Multicall
---------

There is a possibility to execute an Invoke transaction containing multiple calls.
Simply pass a list of calls to :meth:`~starknet_py.net.account.account.Account.execute` method.
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.
Note that the nonce will be bumped only by 1.

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

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



FullNodeClient usage
--------------------

Expand Down
19 changes: 5 additions & 14 deletions docs/guide/deploying_contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ Deploying contracts
Declaring contracts
-------------------

Since Cairo 0.10.0 Declare transactions can be signed and in the future, declaring without signing the transaction
(and without paying the fee) will be impossible. That is why :ref:`Account` has
:meth:`sign_declare_transaction()` method.
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.
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.

Here's an example how to use it.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py
:language: python
:dedent: 4

.. note::

Signing Declare transactions is possible only with Accounts having `__validate__` entrypoint (with `supported_tx_version = 1`).



Simple declare and deploy
-------------------------

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

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

If you already know the class hash of an already declared contract you want to deploy just use the :meth:`Contract.deploy_contract`.
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`.
It will deploy the contract using funds from your account. Deployment is handled by UDC.

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

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

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py
:language: python
Expand All @@ -75,9 +68,7 @@ Cairo1 contracts
Declaring Cairo1 contracts
##########################

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

The main differences in the structure of the transaction from its previous version are:
Expand Down
58 changes: 31 additions & 27 deletions docs/guide/using_existing_contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,77 +37,81 @@ If you do not have ABI statically, but you know the interface of the contract on
Fees
----

starknet.py requires you to specify amount of Wei you
are willing to pay either when making ``.invoke()`` transactions or when preparing
function calls with ``.prepare()``.
.. currentmodule:: starknet_py.contract

Starknet.py requires you to specify amount of Wei (for V1 transaction) or Fri (for V3 transaction) you
are willing to pay when executing either :meth:`~ContractFunction.invoke_v1` or :meth:`~ContractFunction.invoke_v3` transactions.
Alternatively, you can estimate fee automatically, as described in the :ref:`automatic-fee-estimation` section below.

.. code-block:: python
await contract.functions["put"].invoke(k, v, max_fee=5000)
await contract.functions["put"].invoke_v1(k, v, max_fee=5000)
When max_fee is specified when preparing a call, you can invoke it without
``max_fee``.
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.
The same behavior applies to :meth:`~ContractFunction.prepare_invoke_v3` and ``l1_resource_bounds``.

.. code-block:: python
prepared_call = contract.function["put"].prepare(k, v, max_fee=5000)
prepared_call = contract.function["put"].prepare_invoke_v1(k, v, max_fee=5000)
await prepared_call.invoke()
# or max_fee can be overridden
await prepared_call.invoke(max_fee=10000)
.. warning::

If ``max_fee`` is not specified at any step it will default to ``None``,
and will raise an exception when invoking a transaction.
For V1 transactions if ``max_fee`` is not specified at any step it will default to ``None``,
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.

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

Fee estimation
--------------

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

.. code-block:: python
await contract.functions["put"].prepare(k, v, max_fee=5000).estimate_fee()
await contract.functions["put"].prepare_invoke_v1(k, v).estimate_fee()
.. _automatic-fee-estimation:

Automatic fee estimation
------------------------

For testing purposes it is possible to enable automatic fee estimation when making
a transaction. starknet.py will then use ``estimate_fee()`` internally and use value
returned by it multiplied by ``1.5`` as a ``max_fee``.

.. warning::

Do not use automatic fee estimation in production code! It may lead to
very high fees paid as the amount returned by ``estimate_fee()`` may be arbitrarily large.
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`
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,
``max_amount`` will be multiplied by ``1.1``, and ``max_price_per_unit`` by ``1.5``.

.. code-block:: python
await contract.functions["put"].invoke(k, v, auto_estimate=True)
await contract.functions["put"].invoke_v1(k, v, auto_estimate=True)
.. warning::

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

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

Account and Client interoperability
-----------------------------------

.. currentmodule:: starknet_py.contract

:ref:`Contract` methods have been designed to be
compatible with :ref:`Account` and :ref:`Client`.
:ref:`Contract` methods have been designed to be compatible with :ref:`Account` and :ref:`Client`.

:ref:`PreparedFunctionCall` returned by :meth:`ContractFunction.prepare` can be used in Account methods to create Invoke transactions.
: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.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_contract_account_compatibility.py
:language: python
:dedent: 4

It can also be used in :meth:`Client.call_contract() <starknet_py.net.client.Client.call_contract>`

Similarly, :ref:`PreparedFunctionCall` returned by :meth:`ContractFunction.prepare_call` can be used in :meth:`Client.call_contract() <starknet_py.net.client.Client.call_contract>`

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_contract_client_compatibility.py
:language: python
Expand Down
7 changes: 4 additions & 3 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ You can install starknet.py on Windows in two ways:

1. Install it just like you would on Linux.

You might encounter problems related to ``libcrypto_c_exports``.

In such case make sure that you have `MinGW <https://www.mingw-w64.org/>`_ installed and up-to-date.

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

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

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

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>`_
or ask for help in ``#🐍 | starknet-py`` channel on `Starknet Discord server <https://starknet.io/discord>`_.
Expand Down
Loading

0 comments on commit c1c8978

Please sign in to comment.