diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 769ee5d..6e2f1eb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: matrix: python-version: ["3.11", "3.10", "3.9", "3.8"] py-algorand-sdk-version: ["1.10.0", "1.11.0", "1.12.0", "1.13.0", "1.13.1", "1.14.0", "1.15.0", "1.16.0", "1.16.1", - "1.17.0", "1.18.0", "1.19.0", "1.20.0", "1.20.1", "1.20.2"] + "1.17.0", "1.18.0", "1.19.0", "1.20.0", "1.20.1", "1.20.2", "2.0.0"] steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index 1ddea3d..b7125fa 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The SDK supports Tinyman V2 and V1.1. ## Requirements - Python 3.8+ -- py-algorand-sdk 1.10.0+, <2.0.0 +- py-algorand-sdk 1.10.0+ ## Installation tinyman-py-sdk is not released on PYPI. It can be installed directly from this repository with pip: diff --git a/examples/v1/swapping1_less_convenience.py b/examples/v1/swapping1_less_convenience.py index 6345c4e..7d762d8 100644 --- a/examples/v1/swapping1_less_convenience.py +++ b/examples/v1/swapping1_less_convenience.py @@ -8,7 +8,7 @@ from tinyman.v1.pools import Pool from tinyman.assets import Asset -from algosdk.future.transaction import wait_for_confirmation +from tinyman.compat import wait_for_confirmation from algosdk.v2client.algod import AlgodClient from tinyman.v1.client import TinymanClient diff --git a/examples/v2/tutorial/11_flash_loan_1_single_asset.py b/examples/v2/tutorial/11_flash_loan_1_single_asset.py index 87b556f..9a88b30 100644 --- a/examples/v2/tutorial/11_flash_loan_1_single_asset.py +++ b/examples/v2/tutorial/11_flash_loan_1_single_asset.py @@ -9,7 +9,7 @@ from examples.v2.tutorial.common import get_account, get_assets from examples.v2.utils import get_algod from tinyman.v2.client import TinymanV2TestnetClient -from algosdk.future.transaction import AssetTransferTxn +from tinyman.compat import AssetTransferTxn account = get_account() algod = get_algod() diff --git a/examples/v2/tutorial/12_flash_loan_2_multiple_assets.py b/examples/v2/tutorial/12_flash_loan_2_multiple_assets.py index abc991f..7fb7e94 100644 --- a/examples/v2/tutorial/12_flash_loan_2_multiple_assets.py +++ b/examples/v2/tutorial/12_flash_loan_2_multiple_assets.py @@ -9,7 +9,7 @@ from examples.v2.tutorial.common import get_account, get_assets from examples.v2.utils import get_algod from tinyman.v2.client import TinymanV2TestnetClient -from algosdk.future.transaction import AssetTransferTxn, PaymentTxn +from tinyman.compat import AssetTransferTxn, PaymentTxn account = get_account() algod = get_algod() diff --git a/examples/v2/tutorial/13_flash_swap_1_pay_in_other_currency.py b/examples/v2/tutorial/13_flash_swap_1_pay_in_other_currency.py index dcc551a..e6b7702 100644 --- a/examples/v2/tutorial/13_flash_swap_1_pay_in_other_currency.py +++ b/examples/v2/tutorial/13_flash_swap_1_pay_in_other_currency.py @@ -4,7 +4,7 @@ from pprint import pprint from urllib.parse import quote_plus -from algosdk.future.transaction import AssetTransferTxn, PaymentTxn +from tinyman.compat import AssetTransferTxn, PaymentTxn from examples.v2.tutorial.common import get_account, get_assets from examples.v2.utils import get_algod diff --git a/examples/v2/tutorial/14_flash_swap_2_pay_in_same_currency.py b/examples/v2/tutorial/14_flash_swap_2_pay_in_same_currency.py index f7e3809..4c1e8e8 100644 --- a/examples/v2/tutorial/14_flash_swap_2_pay_in_same_currency.py +++ b/examples/v2/tutorial/14_flash_swap_2_pay_in_same_currency.py @@ -4,7 +4,7 @@ from pprint import pprint from urllib.parse import quote_plus -from algosdk.future.transaction import AssetTransferTxn, PaymentTxn +from tinyman.compat import AssetTransferTxn, PaymentTxn from examples.v2.tutorial.common import get_account, get_assets from examples.v2.utils import get_algod diff --git a/examples/v2/tutorial/15_flash_swap_3_pay_in_multiple_currencies.py b/examples/v2/tutorial/15_flash_swap_3_pay_in_multiple_currencies.py index 0c01311..43f02be 100644 --- a/examples/v2/tutorial/15_flash_swap_3_pay_in_multiple_currencies.py +++ b/examples/v2/tutorial/15_flash_swap_3_pay_in_multiple_currencies.py @@ -4,7 +4,7 @@ from pprint import pprint from urllib.parse import quote_plus -from algosdk.future.transaction import AssetTransferTxn, PaymentTxn +from tinyman.compat import AssetTransferTxn, PaymentTxn from examples.v2.tutorial.common import get_account, get_assets from examples.v2.utils import get_algod diff --git a/examples/v2/tutorial/common.py b/examples/v2/tutorial/common.py index 6ff0912..48cec8d 100644 --- a/examples/v2/tutorial/common.py +++ b/examples/v2/tutorial/common.py @@ -4,7 +4,7 @@ import random from pprint import pprint -from algosdk.future.transaction import AssetCreateTxn, wait_for_confirmation +from tinyman.compat import AssetCreateTxn, wait_for_confirmation def get_account_file_path(filename="account.json"): diff --git a/setup.py b/setup.py index f063b5a..bece06d 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ project_urls={ "Source": "https://github.com/tinyman/tinyman-py-sdk", }, - install_requires=["py-algorand-sdk >= 1.10.0, <2.0.0"], + install_requires=["py-algorand-sdk >= 1.10.0"], packages=setuptools.find_packages(), python_requires=">=3.8", package_data={"tinyman.v1": ["asc.json"], "tinyman.v2": ["amm_approval.map.json"]}, diff --git a/tests/__init__.py b/tests/__init__.py index f58854a..181d6bd 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,4 @@ -from algosdk.future.transaction import SuggestedParams +from tinyman.compat import SuggestedParams def get_suggested_params(): diff --git a/tests/v2/test_add_liquidity.py b/tests/v2/test_add_liquidity.py index 2c40204..7ab1e64 100644 --- a/tests/v2/test_add_liquidity.py +++ b/tests/v2/test_add_liquidity.py @@ -3,7 +3,7 @@ from algosdk.account import generate_account from algosdk.constants import ASSETTRANSFER_TXN, APPCALL_TXN from algosdk.encoding import decode_address -from algosdk.future.transaction import OnComplete +from tinyman.compat import OnComplete from algosdk.logic import get_application_address from tests.v2 import BaseTestCase diff --git a/tests/v2/test_bootstrap.py b/tests/v2/test_bootstrap.py index 89a60fb..96527b9 100644 --- a/tests/v2/test_bootstrap.py +++ b/tests/v2/test_bootstrap.py @@ -3,7 +3,7 @@ from algosdk.account import generate_account from algosdk.constants import APPCALL_TXN, PAYMENT_TXN from algosdk.encoding import decode_address -from algosdk.future.transaction import OnComplete +from tinyman.compat import OnComplete from algosdk.logic import get_application_address from tests.v2 import BaseTestCase diff --git a/tests/v2/test_flash_loan.py b/tests/v2/test_flash_loan.py index 70ed099..4937991 100644 --- a/tests/v2/test_flash_loan.py +++ b/tests/v2/test_flash_loan.py @@ -3,7 +3,7 @@ from algosdk.account import generate_account from algosdk.constants import APPCALL_TXN from algosdk.encoding import decode_address -from algosdk.future.transaction import AssetTransferTxn, OnComplete +from tinyman.compat import AssetTransferTxn, OnComplete from algosdk.logic import get_application_address from tests.v2 import BaseTestCase diff --git a/tests/v2/test_flash_swap.py b/tests/v2/test_flash_swap.py index 3c0c0fa..a2cbbe3 100644 --- a/tests/v2/test_flash_swap.py +++ b/tests/v2/test_flash_swap.py @@ -3,7 +3,7 @@ from algosdk.account import generate_account from algosdk.constants import APPCALL_TXN from algosdk.encoding import decode_address -from algosdk.future.transaction import OnComplete +from tinyman.compat import OnComplete from algosdk.logic import get_application_address from tests.v2 import BaseTestCase diff --git a/tests/v2/test_remove_liquidity.py b/tests/v2/test_remove_liquidity.py index 8d81f4e..d94e93b 100644 --- a/tests/v2/test_remove_liquidity.py +++ b/tests/v2/test_remove_liquidity.py @@ -3,7 +3,7 @@ from algosdk.account import generate_account from algosdk.constants import ASSETTRANSFER_TXN, APPCALL_TXN from algosdk.encoding import decode_address -from algosdk.future.transaction import OnComplete +from tinyman.compat import OnComplete from algosdk.logic import get_application_address from tests.v2 import BaseTestCase diff --git a/tests/v2/test_swap.py b/tests/v2/test_swap.py index 7570d77..efbde9c 100644 --- a/tests/v2/test_swap.py +++ b/tests/v2/test_swap.py @@ -3,7 +3,7 @@ from algosdk.account import generate_account from algosdk.constants import ASSETTRANSFER_TXN, APPCALL_TXN from algosdk.encoding import decode_address -from algosdk.future.transaction import OnComplete +from tinyman.compat import OnComplete from algosdk.logic import get_application_address from tests.v2 import BaseTestCase diff --git a/tinyman/client.py b/tinyman/client.py index 6c285b1..40ca95a 100644 --- a/tinyman/client.py +++ b/tinyman/client.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import wait_for_confirmation +from tinyman.compat import wait_for_confirmation from algosdk.v2client.algod import AlgodClient from tinyman.assets import Asset diff --git a/tinyman/compat.py b/tinyman/compat.py new file mode 100644 index 0000000..cab4e23 --- /dev/null +++ b/tinyman/compat.py @@ -0,0 +1,36 @@ +# flake8: noqa + +try: + from algosdk.transaction import ( + ApplicationClearStateTxn, + ApplicationOptInTxn, + ApplicationNoOpTxn, + AssetTransferTxn, + AssetCreateTxn, + AssetOptInTxn, + assign_group_id, + LogicSigAccount, + LogicSigTransaction, + PaymentTxn, + SuggestedParams, + Transaction, + OnComplete, + wait_for_confirmation, + ) +except ImportError: + from algosdk.future.transaction import ( + ApplicationClearStateTxn, + ApplicationOptInTxn, + ApplicationNoOpTxn, + AssetTransferTxn, + AssetCreateTxn, + AssetOptInTxn, + assign_group_id, + LogicSigAccount, + LogicSigTransaction, + PaymentTxn, + SuggestedParams, + Transaction, + OnComplete, + wait_for_confirmation, + ) diff --git a/tinyman/optin.py b/tinyman/optin.py index 8c41bcd..772f9ad 100644 --- a/tinyman/optin.py +++ b/tinyman/optin.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ApplicationOptInTxn, AssetOptInTxn +from tinyman.compat import ApplicationOptInTxn, AssetOptInTxn from tinyman.utils import TransactionGroup diff --git a/tinyman/staking/__init__.py b/tinyman/staking/__init__.py index 11191c3..c1ca99d 100644 --- a/tinyman/staking/__init__.py +++ b/tinyman/staking/__init__.py @@ -7,7 +7,7 @@ from algosdk.constants import PAYMENT_TXN, ASSETTRANSFER_TXN from algosdk.encoding import is_valid_address -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationClearStateTxn, ApplicationOptInTxn, PaymentTxn, diff --git a/tinyman/utils.py b/tinyman/utils.py index 2f00c94..5e43659 100644 --- a/tinyman/utils.py +++ b/tinyman/utils.py @@ -7,7 +7,7 @@ from typing import Optional from algosdk.error import AlgodHTTPError -from algosdk.future.transaction import ( +from tinyman.compat import ( LogicSigTransaction, assign_group_id, wait_for_confirmation, diff --git a/tinyman/v1/bootstrap.py b/tinyman/v1/bootstrap.py index 4358ed2..5918099 100644 --- a/tinyman/v1/bootstrap.py +++ b/tinyman/v1/bootstrap.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationOptInTxn, PaymentTxn, AssetCreateTxn, diff --git a/tinyman/v1/burn.py b/tinyman/v1/burn.py index 28e623b..dc69927 100644 --- a/tinyman/v1/burn.py +++ b/tinyman/v1/burn.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn +from tinyman.compat import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn from tinyman.utils import TransactionGroup from .contracts import get_pool_logicsig diff --git a/tinyman/v1/contracts.py b/tinyman/v1/contracts.py index 53e8a26..f6b3829 100644 --- a/tinyman/v1/contracts.py +++ b/tinyman/v1/contracts.py @@ -1,11 +1,17 @@ +import sys import json import importlib.resources -from algosdk.future.transaction import LogicSigAccount +from tinyman.compat import LogicSigAccount import tinyman.v1 from base64 import b64decode from tinyman.utils import encode_value -_contracts = json.loads(importlib.resources.read_text(tinyman.v1, "asc.json")) +if sys.version_info >= (3, 9): + _contracts = json.loads( + importlib.resources.files(tinyman.v1).joinpath("asc.json").read_text() + ) +else: + _contracts = json.loads(importlib.resources.read_text(tinyman.v1, "asc.json")) pool_logicsig_def = _contracts["contracts"]["pool_logicsig"]["logic"] diff --git a/tinyman/v1/fees.py b/tinyman/v1/fees.py index 36b6964..630509c 100644 --- a/tinyman/v1/fees.py +++ b/tinyman/v1/fees.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn +from tinyman.compat import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn from tinyman.utils import TransactionGroup from .contracts import get_pool_logicsig diff --git a/tinyman/v1/mint.py b/tinyman/v1/mint.py index cd6f751..15327f7 100644 --- a/tinyman/v1/mint.py +++ b/tinyman/v1/mint.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn +from tinyman.compat import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn from tinyman.utils import TransactionGroup from .contracts import get_pool_logicsig diff --git a/tinyman/v1/optout.py b/tinyman/v1/optout.py index ff2b4fc..89e7418 100644 --- a/tinyman/v1/optout.py +++ b/tinyman/v1/optout.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ApplicationClearStateTxn +from tinyman.compat import ApplicationClearStateTxn from algosdk.v2client.algod import AlgodClient diff --git a/tinyman/v1/redeem.py b/tinyman/v1/redeem.py index 7dad3b5..c9be038 100644 --- a/tinyman/v1/redeem.py +++ b/tinyman/v1/redeem.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn +from tinyman.compat import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn from tinyman.utils import TransactionGroup from .contracts import get_pool_logicsig diff --git a/tinyman/v1/swap.py b/tinyman/v1/swap.py index 219a04d..fcdcfef 100644 --- a/tinyman/v1/swap.py +++ b/tinyman/v1/swap.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn +from tinyman.compat import ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn from tinyman.utils import TransactionGroup from .contracts import get_pool_logicsig diff --git a/tinyman/v2/add_liquidity.py b/tinyman/v2/add_liquidity.py index 631717f..45ba993 100644 --- a/tinyman/v2/add_liquidity.py +++ b/tinyman/v2/add_liquidity.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn, diff --git a/tinyman/v2/bootstrap.py b/tinyman/v2/bootstrap.py index c83ef89..4e02e99 100644 --- a/tinyman/v2/bootstrap.py +++ b/tinyman/v2/bootstrap.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationOptInTxn, PaymentTxn, SuggestedParams, diff --git a/tinyman/v2/contracts.py b/tinyman/v2/contracts.py index 7a2d433..06996b0 100644 --- a/tinyman/v2/contracts.py +++ b/tinyman/v2/contracts.py @@ -1,6 +1,6 @@ from base64 import b64decode -from algosdk.future.transaction import LogicSigAccount +from tinyman.compat import LogicSigAccount from tinyman.v2.constants import POOL_LOGICSIG_TEMPLATE diff --git a/tinyman/v2/fees.py b/tinyman/v2/fees.py index 03af641..5b18c29 100644 --- a/tinyman/v2/fees.py +++ b/tinyman/v2/fees.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationNoOpTxn, SuggestedParams, ) diff --git a/tinyman/v2/flash_loan.py b/tinyman/v2/flash_loan.py index f887fd4..5ff31e1 100644 --- a/tinyman/v2/flash_loan.py +++ b/tinyman/v2/flash_loan.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( Transaction, ApplicationNoOpTxn, PaymentTxn, diff --git a/tinyman/v2/flash_swap.py b/tinyman/v2/flash_swap.py index d87d283..7aa332c 100644 --- a/tinyman/v2/flash_swap.py +++ b/tinyman/v2/flash_swap.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( Transaction, ApplicationNoOpTxn, SuggestedParams, diff --git a/tinyman/v2/management.py b/tinyman/v2/management.py index a96f3c1..f8b93f2 100644 --- a/tinyman/v2/management.py +++ b/tinyman/v2/management.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationNoOpTxn, SuggestedParams, ) diff --git a/tinyman/v2/pools.py b/tinyman/v2/pools.py index ac5d646..607d8ec 100644 --- a/tinyman/v2/pools.py +++ b/tinyman/v2/pools.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import LogicSigAccount, Transaction, SuggestedParams +from tinyman.compat import LogicSigAccount, Transaction, SuggestedParams from algosdk.v2client.algod import AlgodClient from tinyman.assets import Asset, AssetAmount diff --git a/tinyman/v2/remove_liquidity.py b/tinyman/v2/remove_liquidity.py index b6488f9..843cdc5 100644 --- a/tinyman/v2/remove_liquidity.py +++ b/tinyman/v2/remove_liquidity.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationNoOpTxn, AssetTransferTxn, SuggestedParams, diff --git a/tinyman/v2/swap.py b/tinyman/v2/swap.py index c8b2c7b..00b47d0 100644 --- a/tinyman/v2/swap.py +++ b/tinyman/v2/swap.py @@ -1,6 +1,6 @@ from typing import Optional -from algosdk.future.transaction import ( +from tinyman.compat import ( ApplicationNoOpTxn, PaymentTxn, AssetTransferTxn, diff --git a/tinyman/v2/utils.py b/tinyman/v2/utils.py index 6c39953..fc3404a 100644 --- a/tinyman/v2/utils.py +++ b/tinyman/v2/utils.py @@ -1,3 +1,4 @@ +import sys import importlib.resources import json from base64 import b64decode @@ -6,9 +7,18 @@ from tinyman.tealishmap import TealishMap from tinyman.utils import bytes_to_int -tealishmap = TealishMap( - json.loads(importlib.resources.read_text(tinyman.v2, "amm_approval.map.json")) -) +if sys.version_info >= (3, 9): + tealishmap = TealishMap( + json.loads( + importlib.resources.files(tinyman.v2) + .joinpath("amm_approval.map.json") + .read_text() + ) + ) +else: + tealishmap = TealishMap( + json.loads(importlib.resources.read_text(tinyman.v2, "amm_approval.map.json")) + ) def decode_logs(logs: "list") -> dict: