Skip to content

Commit

Permalink
upgraded libs; updated code imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Pfed-prog committed Mar 30, 2023
1 parent ac229b3 commit 19df891
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
81 changes: 41 additions & 40 deletions amm/amm_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -112,19 +113,19 @@ 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),
token.to_bytes(8, "big"),
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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand All @@ -257,32 +258,32 @@ 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,
amt=quantity,
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)
Expand All @@ -305,32 +306,32 @@ 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,
amt=quantity,
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)
Expand All @@ -350,31 +351,31 @@ 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,
amt=pool_token_amount,
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)
Expand All @@ -390,31 +391,31 @@ 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,
amt=token_amount,
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)
Expand All @@ -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)

Expand All @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions amm/utils/purestake_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""algod client"""
from algosdk.v2client import algod
from algosdk.future import transaction
from algosdk.transaction import AssetConfigTxn


class AlgoClient:
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 19df891

Please sign in to comment.