Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2478a6c

Browse files
Deprecate v1 and v2 transactions (software-mansion#1545)
* Remove v1 and v2 txs examples from docs * Temporarily add `verbose` flag when installing poetry * Fix command * Remove `poetry config installer.modern-installation false` * Use `poetry check --lock` instead of `poetry lock --check` * Update `pyproject.toml` to remove poetry deprecation warnings * Temporarily add `poetry --version` * Set poetry version to `1.8.5` * Temporarily bring back poetry to latest version * Revert "Temporarily bring back poetry to latest version" This reverts commit d8cab89. * Remove unnecessarily introduced CI changes * Remove changes in `pyproject.toml` * Increase resource bounds in `test_simple_declare_and_deploy` * Use latest poetry; Require python >= 3.9 * Run `poetry lock --no-update` * Remove poetry configuration of `modern-installation` * Add `poetry self add poetry-plugin-export` in docs workflow * Update migration guide * Trigger CI * Fix `test_signing_fee_estimate` * Fix `test_deploy_prefunded_account` * Update `pyproject.toml` and `poetry.lock` * Update dependencies versions * Update license to TOML format * Update `[project]` and `[tool.poetry]` * Use `[project.urls]` * Remove changes in `checks.yml` * Mark `test_account_outside_execution_any_caller` as skipped; Add todo * Fix test skipping * Fix linting * Fix linting * Fix failing `test_simple_declare_and_deploy` * Fix other failing tests * Fix formatting * Deprecate v1, v2 methods and classes * Format * Minor fixes * Fix linting * Fix formatting * Fix typechecking * Fix formatting * Fix linting * Bump artifact actions to v4 * Trigger CI * Fix docs building * Make wrapper private * Fic formatting * Use deprecation util function instead of decorator * Fix failing test * Fix linting * Fix failing tests * Change version from which v1 and v2 txs are deprecated * Set `stacklevel` to 3 * Deprecate `DeclareResult.deploy_v1` * Use v3 in `test_account_sign_without_execute` * Update development guide * Use `typing_extensions.deprecated` instead of custom function * Temporarily remove increasing account balance in `full_node_account` fixture * Fix linting * Temporarily remove increasing account balance in fixture * Use `deprecated` library * Fix linting * Bring back util function for deprecation warnings * Remove setting warnings filter * Restore increasing account balance in `full_node_account` fixture * Remove `Deprecated` package * Update `pyproject.toml` * Decrease `max_amount` in `test_simple_declare_and_deploy` * Fix failing tests * Remove unnecessary code * Remove transfer transaction; Add minor fixes * Fix linting
1 parent c878d07 commit 2478a6c

35 files changed

Lines changed: 364 additions & 162 deletions

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ It supports an account contract which proxies the calls to other contracts on St
6060

6161
Account can be created in two ways:
6262
- By constructor (It is required to provide an `address` and either `key_pair` or `signer`).
63-
- By static methods `Account.deploy_account_v1` or `Account.deploy_account_v3`
63+
- By static method `Account.deploy_account_v3`
6464

6565
Additionally, you can use the [sncast](https://foundry-rs.github.io/starknet-foundry/starknet/index.html) tool to create an account,
6666
which will automatically be saved to a file.
@@ -159,6 +159,7 @@ await account.client.wait_for_tx(transaction_response.transaction_hash)
159159
[Contract](https://starknetpy.readthedocs.io/en/latest/api/contract.html#starknet_py.contract.Contract) makes interacting with contracts deployed on Starknet much easier:
160160
```python
161161
from starknet_py.contract import Contract
162+
from starknet_py.net.client_models import ResourceBounds
162163

163164
contract_address = (
164165
"0x01336fa7c870a7403aced14dda865b75f29113230ed84e3a661f7af70fe83e7b"
@@ -178,8 +179,13 @@ contract = Contract(
178179

179180
# All exposed functions are available at contract.functions.
180181
# Here we invoke a function, creating a new transaction.
181-
invocation = await contract.functions["put"].invoke_v1(key, 7, max_fee=int(1e16))
182-
182+
invocation = await contract.functions["put"].invoke_v3(
183+
key,
184+
7,
185+
l1_resource_bounds=ResourceBounds(
186+
max_amount=int(1e5), max_price_per_unit=int(1e13)
187+
),
188+
)
183189
# Invocation returns InvokeResult object. It exposes a helper for waiting until transaction is accepted.
184190
await invocation.wait_for_acceptance()
185191

@@ -194,6 +200,7 @@ Although asynchronous API is recommended, you can also use Contract’s synchron
194200

195201
```python
196202
from starknet_py.contract import Contract
203+
from starknet_py.net.client_models import ResourceBounds
197204

198205
contract_address = (
199206
"0x01336fa7c870a7403aced14dda865b75f29113230ed84e3a661f7af70fe83e7b"
@@ -202,7 +209,11 @@ contract_address = (
202209
key = 1234
203210
contract = Contract.from_address_sync(address=contract_address, provider=account)
204211

205-
invocation = contract.functions["put"].invoke_v1_sync(key, 7, max_fee=int(1e16))
212+
l1_resource_bounds = ResourceBounds(
213+
max_amount=int(1e5), max_price_per_unit=int(1e13)
214+
),
215+
216+
invocation = contract.functions["put"].invoke_v3_sync(key, 7, l1_resource_bounds=l1_resource_bounds)
206217
invocation.wait_for_acceptance_sync()
207218

208219
(saved,) = contract.functions["get"].call_sync(key) # 7

docs/account_creation.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,5 @@ 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 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
35+
tokens, and verify that ``l1_resource_bounds`` argument in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_v3` is set
3736
to a high enough value.

docs/guide/account_and_client.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Account and Client
44
Executing transactions
55
----------------------
66

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.
7+
To execute transactions on Starknet, use :meth:`~starknet_py.net.account.account.Account.execute_v3` method from :ref:`Account` interface, which will send :class:`~starknet_py.net.models.InvokeV3` transaction.
98

109
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_executing_transactions.py
1110
:language: python
@@ -15,25 +14,22 @@ Transaction Fee
1514
---------------
1615

1716
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.
17+
For V3 transaction, the fee is expressed in Fri and is determined by the ``l1_resource_bounds`` parameter.
2018
To enable auto estimation, set the ``auto_estimate`` parameter to ``True``.
2119

2220
.. code-block:: python
2321
24-
resp = await account.execute_v1(calls=call, auto_estimate=True)
22+
resp = await account.execute_v3(calls=call, auto_estimate=True)
2523
2624
.. warning::
2725

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

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.5`` and ``1.5`` respectively.
28+
The returned estimated fee (``max_amount`` and ``max_price_per_unit``) is multiplied by ``1.5`` to mitigate fluctuations in price.
3229

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

3834
The fee for a specific transaction or list of transactions can be also estimated using the :meth:`~starknet_py.net.account.account.Account.estimate_fee` of the :ref:`Account` class.
3935

@@ -61,7 +57,7 @@ Multicall
6157
---------
6258

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

6763
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_multicall.py

docs/guide/deploying_contracts.rst

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

7-
A declare transaction can be issued in version 2 or 3. Contracts written in Cairo 0 cannot be declared 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_v2` or :meth:`~starknet_py.net.account.account.Account.sign_declare_v3` method, respectively.
7+
Contracts written in Cairo 0 cannot be declared while those written in Cairo 1 or higher should be declared with transaction version 3.
8+
To sign a declare transaction, you should utilize :meth:`~starknet_py.net.account.account.Account.sign_declare_v3` method.
99

1010
Here's an example how to use it.
1111

@@ -17,7 +17,7 @@ Here's an example how to use it.
1717
Simple deploy
1818
-------------
1919

20-
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`.
20+
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_v3`.
2121
It will deploy the contract using funds from your account. Deployment is handled by UDC.
2222

2323
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_simple_deploy.py
@@ -57,7 +57,7 @@ Cairo1 contracts
5757
Declaring Cairo1 contracts
5858
##########################
5959

60-
To declare a contract in Cairo version 1 or higher, Declare V2 or Declare V3 transaction has to be sent.
60+
To declare a contract in Cairo version 1 or higher, Declare V3 transaction has to be sent.
6161
You can see the structure of these transactions `here <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions/#declare-transaction>`_.
6262

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

docs/guide/using_existing_contracts.rst

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,34 @@ Fees
3939

4040
.. currentmodule:: starknet_py.contract
4141

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.
42+
Starknet.py requires you to specify amount of Fri that you are willing to pay when executing :meth:`~ContractFunction.invoke_v3`.
4443
Alternatively, you can estimate fee automatically, as described in the :ref:`automatic-fee-estimation` section below.
4544

4645
.. code-block:: python
4746
48-
await contract.functions["put"].invoke_v1(k, v, max_fee=5000)
47+
await contract.functions["put"].invoke_v3(k, v, l1_resource_bounds=ResourceBounds(
48+
max_amount=int(1e5), max_price_per_unit=int(1e13)
49+
))
4950
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``.
51+
The ``l1_resource_bounds`` argument can be also defined in :meth:`~ContractFunction.prepare_invoke_v3`. Subsequently, the :meth:`~PreparedFunctionInvokeV3.invoke` method on a prepared call can be used either with ``l1_resource_bounds`` omitted or with its value overridden.
5252

5353
.. code-block:: python
5454
55-
prepared_call = contract.function["put"].prepare_invoke_v1(k, v, max_fee=5000)
55+
prepared_call = contract.function["put"].prepare_invoke_v3(k, v, l1_resource_bounds=ResourceBounds(
56+
max_amount=int(1e5), max_price_per_unit=int(1e13)
57+
))
5658
await prepared_call.invoke()
57-
# or max_fee can be overridden
58-
await prepared_call.invoke(max_fee=10000)
59+
# or l1_resource_bounds can be overridden
60+
await prepared_call.invoke(l1_resource_bounds=ResourceBounds(
61+
max_amount=int(1e5), max_price_per_unit=int(1e13)
62+
))
5963
6064
.. warning::
6165

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.
66+
If ``l1_resource_bounds`` is not specified at any step it will default to ``None``,
67+
and will raise an exception when invoking a transaction, unless `auto_estimate` is specified and is set to `True`.
6468

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

6872
Fee estimation
@@ -73,29 +77,27 @@ using :meth:`PreparedFunctionInvoke.estimate_fee() <starknet_py.contract.Prepare
7377

7478
.. code-block:: python
7579
76-
await contract.functions["put"].prepare_invoke_v1(k, v).estimate_fee()
80+
await contract.functions["put"].prepare_invoke_v3(k, v).estimate_fee()
7781
7882
.. _automatic-fee-estimation:
7983

8084
Automatic fee estimation
8185
------------------------
8286

8387
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``.
88+
internally and use the returned value. ``max_amount`` and ``max_price_per_unit`` will be multiplied by ``1.5``.
8689

8790
.. code-block:: python
8891
89-
await contract.functions["put"].invoke_v1(k, v, auto_estimate=True)
92+
await contract.functions["put"].invoke_v3(k, v, auto_estimate=True)
9093
9194
.. warning::
9295

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

9598
.. note::
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.
99+
It is possible to configure the value by which the estimated fee is multiplied,
100+
by changing ``ESTIMATED_AMOUNT_MULTIPLIER`` and ``ESTIMATED_UNIT_PRICE_MULTIPLIER``.
99101

100102
Account and Client interoperability
101103
-----------------------------------
@@ -104,7 +106,7 @@ Account and Client interoperability
104106

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

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.
109+
:ref:`PreparedFunctionInvokeV3` returned by :meth:`ContractFunction.prepare_invoke_v3` can be used in Account methods to create invoke transaction.
108110

109111
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_contract_account_compatibility.py
110112
:language: python

docs/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ It supports an account contract which proxies the calls to other contracts on St
3131
Account can be created in two ways:
3232

3333
* By constructor (It is required to provide an ``address`` and either ``key_pair`` or ``signer``).
34-
* By static methods ``Account.deploy_account_v1`` or ``Account.deploy_account_v3``
34+
* By static method ``Account.deploy_account_v3``
3535

3636
There are some examples how to do it:
3737

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,3 @@ exclude = [
148148
"**/__pycache__",
149149
"starknet_py/tests/e2e/docs",
150150
]
151-

starknet_py/contract.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
FunctionSerializationAdapterV1,
4343
)
4444
from starknet_py.utils.constructor_args_translator import _is_abi_v2
45+
from starknet_py.utils.deprecation import _print_deprecation_warning
4546
from starknet_py.utils.sync import add_sync_methods
4647

4748
# pylint: disable=too-many-lines
@@ -195,6 +196,9 @@ async def deploy_v1(
195196
"""
196197
Deploys a contract.
197198
199+
.. deprecated:: 0.25.0
200+
This method is deprecated and will be removed in future versions. Use deploy_v3 instead.
201+
198202
:param deployer_address: Address of the UDC. Is set to the address of
199203
the default UDC (same address on mainnet/sepolia) by default.
200204
Must be set when using custom network other than ones listed above.
@@ -207,6 +211,10 @@ async def deploy_v1(
207211
:return: DeployResult instance.
208212
"""
209213
# pylint: disable=too-many-arguments, too-many-locals
214+
_print_deprecation_warning(
215+
"deploy_v1 is deprecated and will be removed in future versions. Use deploy_v3 instead."
216+
)
217+
210218
abi = self._get_abi()
211219

212220
return await Contract.deploy_contract_v1(
@@ -614,6 +622,9 @@ def prepare_invoke_v1(
614622
:param max_fee: Max amount of Wei to be paid when executing transaction.
615623
:return: PreparedFunctionCall.
616624
"""
625+
_print_deprecation_warning(
626+
"prepare_invoke_v1 is deprecated and will be removed in future versions. Use prepare_invoke_v3 instead."
627+
)
617628

618629
calldata = self._payload_transformer.serialize(*args, **kwargs)
619630
return PreparedFunctionInvokeV1(
@@ -644,6 +655,10 @@ async def invoke_v1(
644655
:param nonce: Nonce of the transaction.
645656
:return: InvokeResult.
646657
"""
658+
_print_deprecation_warning(
659+
"invoke_v1 is deprecated and will be removed in future versions. Use invoke_v3 instead."
660+
)
661+
647662
prepared_invoke = self.prepare_invoke_v1(*args, **kwargs)
648663
return await prepared_invoke.invoke(
649664
max_fee=max_fee, nonce=nonce, auto_estimate=auto_estimate
@@ -835,6 +850,9 @@ async def declare_v1(
835850
:return: DeclareResult instance.
836851
"""
837852

853+
_print_deprecation_warning(
854+
"declare_v1 is deprecated and will be removed in future versions. Use declare_v3 instead."
855+
)
838856
declare_tx = await account.sign_declare_v1(
839857
compiled_contract=compiled_contract,
840858
nonce=nonce,
@@ -872,6 +890,10 @@ async def declare_v2(
872890
:return: DeclareResult instance.
873891
"""
874892

893+
_print_deprecation_warning(
894+
"declare_v2 is deprecated and will be removed in future versions. Use declare_v3 instead."
895+
)
896+
875897
compiled_class_hash = _extract_compiled_class_hash(
876898
compiled_contract_casm, compiled_class_hash
877899
)
@@ -966,6 +988,10 @@ async def deploy_contract_v1(
966988
:return: DeployResult instance.
967989
"""
968990
# pylint: disable=too-many-arguments, too-many-locals
991+
_print_deprecation_warning(
992+
"deploy_contract_v1 is deprecated and will be removed in future versions. Use deploy_contract_v3 instead."
993+
)
994+
969995
deployer = Deployer(
970996
deployer_address=deployer_address,
971997
account_address=account.address if unique else None,

0 commit comments

Comments
 (0)