From 19df89130e08d3c4c515e04155809a5316362388 Mon Sep 17 00:00:00 2001 From: pfed-prog Date: Thu, 30 Mar 2023 10:14:23 +0200 Subject: [PATCH] upgraded libs; updated code imports --- README.md | 2 +- amm/amm_app.py | 81 ++++++++++++++++++----------------- amm/utils/purestake_client.py | 6 +-- requirements.txt | 12 +++++- 4 files changed, 54 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index e2f2467..7fc4b9d 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,6 @@ In `amm.py` we keep the high-level logic of the contract, `helpers.py` contains [How to publish PIP package](https://shobhitgupta.medium.com/how-to-publish-your-own-pip-package-560bde836b17) -[Algorand Ecosystem Algo Amm page](https://ecosystem.algorand.com/project/algo-amm) +[Algorand Ecosystem Algo AMM page](https://ecosystem.algorand.com/project/algo-amm) [How To Use unittest to Write a Test Case for a Function in Python](https://www.digitalocean.com/community/tutorials/how-to-use-unittest-to-write-a-test-case-for-a-function-in-python) diff --git a/amm/amm_app.py b/amm/amm_app.py index 143c81b..f162862 100644 --- a/amm/amm_app.py +++ b/amm/amm_app.py @@ -4,14 +4,15 @@ from base64 import b64decode from pyteal import compileTeal, Mode, Expr - -from algosdk.v2client.algod import AlgodClient from algosdk import encoding -from algosdk.future import transaction +from algosdk.transaction import (StateSchema, ApplicationCreateTxn, + OnComplete, PaymentTxn, ApplicationCallTxn, assign_group_id, + AssetOptInTxn, AssetTransferTxn, ApplicationDeleteTxn) +from algosdk.v2client.algod import AlgodClient from algosdk.logic import get_application_address -from amm.contracts.amm import approval_program, clear_program from amm.utils.account import Account +from amm.contracts.amm import approval_program, clear_program MIN_BALANCE_REQUIREMENT = ( # min account balance @@ -112,9 +113,9 @@ def create_amm_app( self.stable_token = token approval, clear = get_contracts(self.client) - global_schema = transaction.StateSchema( + global_schema = StateSchema( num_uints=13, num_byte_slices=1) - local_schema = transaction.StateSchema(num_uints=0, num_byte_slices=0) + local_schema = StateSchema(num_uints=0, num_byte_slices=0) app_args = [ encoding.decode_address(deployer.public_key), @@ -122,9 +123,9 @@ def create_amm_app( min_increment.to_bytes(8, "big"), ] - txn = transaction.ApplicationCreateTxn( + txn = ApplicationCreateTxn( sender=deployer.public_key, - on_complete=transaction.OnComplete.NoOpOC, + on_complete=OnComplete.NoOpOC, approval_program=approval, clear_program=clear, global_schema=global_schema, @@ -155,23 +156,23 @@ def setup_amm_app( Return: app asset ids """ - fund_app_tx = transaction.PaymentTxn( + fund_app_tx = PaymentTxn( sender=funder.public_key, receiver=self.app_addr, amt=MIN_BALANCE_REQUIREMENT, sp=self.suggested_params, ) - setup_tx = transaction.ApplicationCallTxn( + setup_tx = ApplicationCallTxn( sender=funder.public_key, index=self.app_id, - on_complete=transaction.OnComplete.NoOpOC, + on_complete=OnComplete.NoOpOC, app_args=[b"setup"], foreign_assets=[self.stable_token], sp=self.suggested_params, ) - transaction.assign_group_id([fund_app_tx, setup_tx]) + assign_group_id([fund_app_tx, setup_tx]) signed_fund_spp_txn = fund_app_tx.sign(funder.private_key) signed_setup_tx = setup_tx.sign(funder.private_key) @@ -206,7 +207,7 @@ def opt_in_to_pool_token( account: The account opting into the token. """ - opt_in_tx = transaction.AssetOptInTxn( + opt_in_tx = AssetOptInTxn( sender=account.public_key, index=self.pool_token, sp=self.suggested_params ) @@ -224,7 +225,7 @@ def opt_in_to_no_token( account: The account opting into the token. """ - opt_in_tx = transaction.AssetOptInTxn( + opt_in_tx = AssetOptInTxn( sender=account.public_key, index=self.no_token, sp=self.suggested_params ) @@ -242,7 +243,7 @@ def opt_in_to_yes_token( account: The account opting into the token. """ - opt_in_tx = transaction.AssetOptInTxn( + opt_in_tx = AssetOptInTxn( sender=account.public_key, index=self.yes_token, sp=self.suggested_params ) @@ -257,14 +258,14 @@ def supply( """Supply liquidity to the pool""" # pay for the fee incurred by AMM for sending back the pool token - fee_tx = transaction.PaymentTxn( + fee_tx = PaymentTxn( sender=supplier.public_key, receiver=self.app_addr, amt=MIN_BALANCE_REQUIREMENT, sp=self.suggested_params, ) - token_tx = transaction.AssetTransferTxn( + token_tx = AssetTransferTxn( sender=supplier.public_key, receiver=self.app_addr, index=self.stable_token, @@ -272,17 +273,17 @@ def supply( sp=self.suggested_params, ) - app_call_tx = transaction.ApplicationCallTxn( + app_call_tx = ApplicationCallTxn( sender=supplier.public_key, index=self.app_id, - on_complete=transaction.OnComplete.NoOpOC, + on_complete=OnComplete.NoOpOC, app_args=[b"supply"], foreign_assets=[self.stable_token, self.pool_token, self.yes_token, self.no_token], sp=self.suggested_params, ) - transaction.assign_group_id([fee_tx, token_tx, app_call_tx]) + assign_group_id([fee_tx, token_tx, app_call_tx]) signed_fee_tx = fee_tx.sign(supplier.private_key) signed_token_tx = token_tx.sign(supplier.private_key) signed_app_call_tx = app_call_tx.sign(supplier.private_key) @@ -305,14 +306,14 @@ def swap( else: return - fee_tx = transaction.PaymentTxn( + fee_tx = PaymentTxn( sender=supplier.public_key, receiver=self.app_addr, amt=2_000, sp=self.suggested_params, ) - token_tx = transaction.AssetTransferTxn( + token_tx = AssetTransferTxn( sender=supplier.public_key, receiver=self.app_addr, index=self.stable_token, @@ -320,17 +321,17 @@ def swap( sp=self.suggested_params, ) - app_call_tx = transaction.ApplicationCallTxn( + app_call_tx = ApplicationCallTxn( sender=supplier.public_key, index=self.app_id, - on_complete=transaction.OnComplete.NoOpOC, + on_complete=OnComplete.NoOpOC, app_args=[b"swap", second_argument], foreign_assets=[self.stable_token, self.pool_token, self.yes_token, self.no_token], sp=self.suggested_params, ) - transaction.assign_group_id([fee_tx, token_tx, app_call_tx]) + assign_group_id([fee_tx, token_tx, app_call_tx]) signed_fee_tx = fee_tx.sign(supplier.private_key) signed_token_tx = token_tx.sign(supplier.private_key) signed_app_call_tx = app_call_tx.sign(supplier.private_key) @@ -350,14 +351,14 @@ def withdraw( """ # pay for the fee incurred by AMM for sending back tokens A and B - fee_tx = transaction.PaymentTxn( + fee_tx = PaymentTxn( sender=withdrawal_account.public_key, receiver=self.app_addr, amt=2_000, sp=self.suggested_params, ) - pool_token_tx = transaction.AssetTransferTxn( + pool_token_tx = AssetTransferTxn( sender=withdrawal_account.public_key, receiver=self.app_addr, index=self.pool_token, @@ -365,16 +366,16 @@ def withdraw( sp=self.suggested_params, ) - app_call_tx = transaction.ApplicationCallTxn( + app_call_tx = ApplicationCallTxn( sender=withdrawal_account.public_key, index=self.app_id, - on_complete=transaction.OnComplete.NoOpOC, + on_complete=OnComplete.NoOpOC, app_args=[b"withdraw"], foreign_assets=[self.stable_token, self.pool_token], sp=self.suggested_params, ) - transaction.assign_group_id([fee_tx, pool_token_tx, app_call_tx]) + assign_group_id([fee_tx, pool_token_tx, app_call_tx]) signed_fee_tx = fee_tx.sign(withdrawal_account.private_key) signed_token_tx = pool_token_tx.sign(withdrawal_account.private_key) signed_app_call_tx = app_call_tx.sign(withdrawal_account.private_key) @@ -390,14 +391,14 @@ def redeem( """redeems """ # pay for the fee incurred by AMM for sending back tokens A and B - fee_tx = transaction.PaymentTxn( + fee_tx = PaymentTxn( sender=withdrawal_account.public_key, receiver=self.app_addr, amt=2_000, sp=self.suggested_params, ) - token_tx = transaction.AssetTransferTxn( + token_tx = AssetTransferTxn( sender=withdrawal_account.public_key, receiver=self.app_addr, index=token_in, @@ -405,16 +406,16 @@ def redeem( sp=self.suggested_params, ) - app_call_tx = transaction.ApplicationCallTxn( + app_call_tx = ApplicationCallTxn( sender=withdrawal_account.public_key, index=self.app_id, - on_complete=transaction.OnComplete.NoOpOC, + on_complete=OnComplete.NoOpOC, app_args=[b"redeem"], foreign_assets=[token_out, token_in], sp=self.suggested_params, ) - transaction.assign_group_id([fee_tx, token_tx, app_call_tx]) + assign_group_id([fee_tx, token_tx, app_call_tx]) signed_fee_tx = fee_tx.sign(withdrawal_account.private_key) signed_token_tx = token_tx.sign(withdrawal_account.private_key) signed_app_call_tx = app_call_tx.sign(withdrawal_account.private_key) @@ -431,22 +432,22 @@ def set_result( """ sets result of the event """ - fee_tx = transaction.PaymentTxn( + fee_tx = PaymentTxn( sender=funder.public_key, receiver=self.app_addr, amt=2_000, sp=self.suggested_params, ) - call_tx = transaction.ApplicationCallTxn( + call_tx = ApplicationCallTxn( sender=funder.public_key, index=self.app_id, - on_complete=transaction.OnComplete.NoOpOC, + on_complete=OnComplete.NoOpOC, app_args=[b"result", second_argument], sp=self.suggested_params, ) - transaction.assign_group_id([fee_tx, call_tx]) + assign_group_id([fee_tx, call_tx]) signed_fee_tx = fee_tx.sign(funder.private_key) signed_app_call_tx = call_tx.sign(funder.private_key) @@ -465,7 +466,7 @@ def close_amm( private_key: closer account private key to sign the transactions. """ - delete_tx = transaction.ApplicationDeleteTxn( + delete_tx = ApplicationDeleteTxn( sender=closing_account.public_key, index=self.app_id, sp=self.client.suggested_params(), diff --git a/amm/utils/purestake_client.py b/amm/utils/purestake_client.py index 17a7703..6f57b65 100644 --- a/amm/utils/purestake_client.py +++ b/amm/utils/purestake_client.py @@ -1,6 +1,6 @@ """algod client""" from algosdk.v2client import algod -from algosdk.future import transaction +from algosdk.transaction import AssetConfigTxn class AlgoClient: @@ -33,9 +33,7 @@ def create_asset(self, account): """create asset""" sender = account.public_key - -#### - txn = transaction.AssetConfigTxn( + txn = AssetConfigTxn( sender=sender, sp=self.params, total=1_000_000_000, diff --git a/requirements.txt b/requirements.txt index 72fe617..ec57c7d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,9 @@ +autopep8==2.0.2 bleach==6.0.0 certifi==2022.12.7 cffi==1.15.1 charset-normalizer==3.1.0 +click==8.1.3 commonmark==0.9.1 cryptography==39.0.1 docstring-parser==0.14.1 @@ -16,14 +18,19 @@ markdown-it-py==2.1.0 mdurl==0.1.2 more-itertools==9.0.0 msgpack==1.0.4 +mypy-extensions==1.0.0 nose2==0.12.0 +packaging==23.0 +pathspec==0.11.1 pkginfo==1.9.6 -py-algorand-sdk==1.20.2 +platformdirs==3.2.0 +py-algorand-sdk==2.1.2 +pycodestyle==2.10.0 pycparser==2.21 pycryptodomex==3.17 Pygments==2.14.0 PyNaCl==1.5.0 -pyteal==0.20.1 +pyteal==0.24.0 python-dotenv==1.0.0 readme-renderer==37.3 requests==2.28.2 @@ -34,6 +41,7 @@ SecretStorage==3.3.3 semantic-version==2.10.0 six==1.16.0 tabulate==0.9.0 +tomli==2.0.1 twine==4.0.2 urllib3==1.26.14 webencodings==0.5.1