Skip to content

Commit

Permalink
fix: add missing asset_sender to inner transactions
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Adam Chidlow <achidlow@users.noreply.github.com>
  • Loading branch information
daniel-makerx and achidlow authored Apr 22, 2024
1 parent 7ac4640 commit fd6bba3
Show file tree
Hide file tree
Showing 25 changed files with 1,524 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/sizes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
inheritance/Parent 89 89 0 89 0
inner_transactions 1264 1193 71 1193 0
inner_transactions/ArrayAccess 212 195 17 195 0
inner_transactions/CreateAndTransfer 135 123 12 123 0
inner_transactions/FieldTuple 504 462 42 462 0
inner_transactions/Greeter 321 302 19 302 0
inner_transactions/itxn_loop 191 184 7 184 0
Expand Down
10 changes: 6 additions & 4 deletions src/puya/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
from puya.teal.main import mir_to_teal
from puya.utils import determine_out_dir, make_path_relative_to_cwd

MAX_SUPPORTED_ALGOPY_VERSION = version.parse("1.0.1")
MIN_SUPPORTED_ALGOPY_VERSION = version.parse(f"{MAX_SUPPORTED_ALGOPY_VERSION.major}.0.0")
# this should contain the lowest version number that this compiler does NOT support
# i.e. the next minor version after what is defined in stubs/pyproject.toml:tool.poetry.version
MAX_SUPPORTED_ALGOPY_VERSION_EX = version.parse("1.1.0")
MIN_SUPPORTED_ALGOPY_VERSION = version.parse(f"{MAX_SUPPORTED_ALGOPY_VERSION_EX.major}.0.0")

logger = log.get_logger(__name__)

Expand Down Expand Up @@ -248,10 +250,10 @@ def _check_algopy_version(site_packages: Path) -> None:
algopy_version = version.parse(algopy.version)
logger.debug(f"Found algopy: {algopy_version}")

if not (MIN_SUPPORTED_ALGOPY_VERSION <= algopy_version <= MAX_SUPPORTED_ALGOPY_VERSION):
if not (MIN_SUPPORTED_ALGOPY_VERSION <= algopy_version < MAX_SUPPORTED_ALGOPY_VERSION_EX):
raise CodeError(
f"algopy version {algopy_version} is outside the supported range:"
f" >={MIN_SUPPORTED_ALGOPY_VERSION}, <={MAX_SUPPORTED_ALGOPY_VERSION}"
f" >={MIN_SUPPORTED_ALGOPY_VERSION}, <{MAX_SUPPORTED_ALGOPY_VERSION_EX}"
)


Expand Down
70 changes: 70 additions & 0 deletions stubs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,73 @@ from algopy import Contract
```

For more details on using this API and the puyapy compiler see https://algorandfoundation.github.io/puya/

## Versioning

The Algorand Python API follows [semver](https://semver.org/) principles, however since the compiler is very closely
coupled with the stubs definition, it's worth noting the interplay.

### Major
An increase in the major version should only occur if existing contracts would fail to type-check
after the update.

Some examples of situations that might cause this:
- Breaking changes to the signature of an existing function, such as a new parameter being added
to an existing
method and no default value is provided.
- Something has been renamed, or moved such that the import path has changed (excluding moving
between private modules, indicated with a leading underscore).
- Something has been removed.

The first two examples would necessitate changes in the compiler itself as well, which should
also be considered breaking changes, thus there would be a coinciding new major version of the
compiler.

The third example may not necessitate a change to the compiler, although it probably would be
likely there is one to remove the supporting code, but either way, since it will also change
the behaviour in terms of what version range of the stubs is supported, should also result in a
new major version of the compiler.

However, vice versa is not necessarily true: a new major version of the compiler may not require
a new major version of the stubs. For example:
- Any breaking change to the compiler that has no changes in the stubs.
- The default value of a parameter has changed. This changes the meaning of existing code that
does not supply a default, thus requiring a major version bump of the compiler, but no
existing contracts will fail to compile.

### Minor
When new functionality is added, the minor version should be bumped.

Example situations:
- A new high level API has been added.
- A new parameter has been added to an existing method but a default value has been provided.
- A new TEAL/AVM version has been released with new low-level op-codes that should be exposed.

In each of these cases, there should be zero impact on whether existing contracts will compile
or not. They all would also require a new compiler version to be released. Although the existing
compiler version could continue to work with new stubs version, provided none of the new
functionality is used, for simplicity the compiler should be updated to require the new stubs
version as a minimum.

### Patch
When a bug in the stubs themselves is fixed, or a non-functional change is made (such as
changes to docstrings / documentation), the patch version should be bumped.

Examples:
- Docstrings added/removed/updated.
- Type parameters that were incorrectly specified are fixed
([concrete example](https://github.com/algorandfoundation/puya/issues/191)).
- Adding something that was unintentionally omitted from the stubs, but is otherwise supported by
the current compiler.
Generally in these cases, the code would compile if a `# type: ignore[<error-code>]` was added
([concrete example](https://github.com/algorandfoundation/puya/issues/200)).

In each of these cases, the new stubs should functional correctly when paired with the current
release of the compiler.

The second example is a slight break from semver principles, since this is not backwards
compatible, as existing contracts may fail to compile. However, those contracts should not have
compiled in the first place. The minimum version of stubs supported by the compiler should be
increased to this new patch release, however this will only take effect on the next release of the
compiler itself. The current compiler release would detect the new stubs version as supported
though, and so users can update to that new version of the stubs once it is released.
4 changes: 4 additions & 0 deletions stubs/algopy-stubs/itxn.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class InnerTransaction(_InnerTransaction[InnerTransactionResult]):
## asset transfer
xfer_asset: Asset | UInt64 | int = ...,
asset_amount: UInt64 | int = ...,
asset_sender: Account | str = ...,
asset_receiver: Account | str = ...,
asset_close_to: Account | str = ...,
## asset freeze
Expand Down Expand Up @@ -172,6 +173,7 @@ class InnerTransaction(_InnerTransaction[InnerTransactionResult]):
## asset transfer
xfer_asset: Asset | UInt64 | int = ...,
asset_amount: UInt64 | int = ...,
asset_sender: Account | str = ...,
asset_receiver: Account | str = ...,
asset_close_to: Account | str = ...,
## asset freeze
Expand Down Expand Up @@ -316,6 +318,7 @@ class AssetTransfer(_InnerTransaction[AssetTransferInnerTransaction]):
xfer_asset: Asset | UInt64 | int,
asset_receiver: Account | str,
asset_amount: UInt64 | int = ...,
asset_sender: Account | str = ...,
asset_close_to: Account | str = ...,
sender: Account | str = ...,
fee: UInt64 | int = ...,
Expand All @@ -327,6 +330,7 @@ class AssetTransfer(_InnerTransaction[AssetTransferInnerTransaction]):
*,
xfer_asset: Asset | UInt64 | int = ...,
asset_amount: UInt64 | int = ...,
asset_sender: Account | str = ...,
asset_receiver: Account | str = ...,
asset_close_to: Account | str = ...,
sender: Account | str = ...,
Expand Down
5 changes: 3 additions & 2 deletions stubs/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[tool.poetry]
name = "algorand-python"
# this version represents the version of the stub API's and should follow semver semantics
# when updating this value also update src/compile.py:MAX_SUPPORTED_ALGOPY_VERSION
version = "1.0.1"
# when updating this value also update src/compile.py:MAX_SUPPORTED_ALGOPY_VERSION_EX if it is a major/minor change
# also see stubs/README.md#versioning
version = "1.0.2"
description = "API for writing Algorand Python Smart contracts"
authors = ["Algorand Foundation <contact@algorand.foundation>"]
readme = "README.md"
Expand Down
35 changes: 35 additions & 0 deletions test_cases/inner_transactions/asset_transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from algopy import (
ARC4Contract,
Global,
arc4,
itxn,
op,
)


class CreateAndTransferContract(ARC4Contract):
@arc4.abimethod()
def create_and_transfer(self) -> None:
# create
new_asset = (
itxn.AssetConfig(
total=1000,
asset_name="test",
unit_name="TST",
decimals=0,
manager=op.Global.current_application_address,
clawback=op.Global.current_application_address,
fee=0,
)
.submit()
.created_asset
)

# transfer
itxn.AssetTransfer(
asset_sender=new_asset.creator,
asset_receiver=Global.current_application_address,
asset_amount=1000,
xfer_asset=new_asset,
fee=0,
).submit()
Loading

0 comments on commit fd6bba3

Please sign in to comment.