Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transaction note for integrations #51

Merged
merged 6 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change Log

## Unreleased

### Added

* Added `client_name` attribute to `TinymanClient` classes. [#51](https://github.com/tinymanorg/tinyman-py-sdk/pull/51)
* Added note to application call transactions. The note (`tinyman/<v1|v2>:j{"origin":"<client-name>"}`) follows [Algorand Transaction Note Field Conventions ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md). [#51](https://github.com/tinymanorg/tinyman-py-sdk/pull/51)
* Added `version` property and `generate_app_call_note` method to `TinymanClient` classes. [#51](https://github.com/tinymanorg/tinyman-py-sdk/pull/51)
* Added `get_version` and `generate_app_call_note` to `tinyman.utils`. [#51](https://github.com/tinymanorg/tinyman-py-sdk/pull/51)

### Changed

* ...

### Removed
* ...


## 2.0.0

### Added
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ tinyman-py-sdk is not released on PYPI. It can be installed directly from this r

`pip install git+https://github.com/tinymanorg/tinyman-py-sdk.git`


## Integration

If you are integrating your project into Tinyman, you can provide `client_name` while setting up Tinyman Client classes.
The client name will be added to the application call transaction's note field. It is recommended and completely optional.

```python
client = TinymanV2MainnetClient(..., client_name="project name", ...)
```

## V2

## Sneak Preview
Expand Down
53 changes: 53 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from base64 import b64encode
from unittest import TestCase

from tinyman.utils import generate_app_call_note, parse_app_call_note


class BaseTestCase(TestCase):
maxDiff = None

def test_app_call_note(self):
note = generate_app_call_note(
version="v2", client_name="unit-test", extra_data={"extra": "some text"}
)
expected_result = {
"version": "v2",
"data": {"extra": "some text", "origin": "unit-test"},
}

# test possible versions
string_note = note
bytes_note = string_note.encode()
base64_note = b64encode(bytes_note).decode()

result = parse_app_call_note(string_note)
self.assertDictEqual(
result,
expected_result,
)

result = parse_app_call_note(base64_note)
self.assertDictEqual(
result,
expected_result,
)

result = parse_app_call_note(base64_note)
self.assertDictEqual(
result,
expected_result,
)

result = parse_app_call_note("invalid format")
self.assertEqual(result, None)
result = parse_app_call_note(
"INVALID+dGlueW1hbi92MjpqeyJvcmlnaW4iOiJ0aW55bWFuLXB5dGhvbi1zZGsifQ=="
)
self.assertEqual(result, None)
result = parse_app_call_note(b"invalid format")
self.assertEqual(result, None)
result = parse_app_call_note(
b'INVALID+tinyman/v2:j{"origin":"tinyman-python-sdk"}'
)
self.assertEqual(result, None)
4 changes: 4 additions & 0 deletions tests/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def get_pool_state(
}
state.update(**kwargs)
return state

@classmethod
def app_call_note(cls):
return b'tinyman/v2:j{"origin":"tinyman-py-sdk"}'
8 changes: 6 additions & 2 deletions tests/v2/test_add_liquidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ADD_LIQUIDITY_APP_ARGUMENT,
ADD_LIQUIDITY_FLEXIBLE_MODE_APP_ARGUMENT,
ADD_LIQUIDITY_SINGLE_MODE_APP_ARGUMENT,
TESTNET_VALIDATOR_APP_ID_V2,
)
from tinyman.v2.contracts import get_pool_logicsig
from tinyman.v2.pools import Pool
Expand All @@ -28,7 +29,7 @@
class InitialAddLiquidityTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.sender_private_key, cls.user_address = generate_account()
cls.asset_1_id = 10
cls.asset_2_id = 8
Expand Down Expand Up @@ -121,14 +122,15 @@ def test_add_liquidity(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)


class AddLiquidityTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.sender_private_key, cls.user_address = generate_account()
cls.asset_1_id = 10
cls.asset_2_id = 8
Expand Down Expand Up @@ -240,6 +242,7 @@ def test_flexible_add_liquidity(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)

Expand Down Expand Up @@ -311,5 +314,6 @@ def test_single_asset_add_liquidity(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)
10 changes: 7 additions & 3 deletions tests/v2/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
from algosdk.logic import get_application_address

from tests.v2 import BaseTestCase
from tinyman.v2.constants import BOOTSTRAP_APP_ARGUMENT
from tinyman.v2.constants import BOOTSTRAP_APP_ARGUMENT, TESTNET_VALIDATOR_APP_ID_V2
from tinyman.v2.contracts import get_pool_logicsig
from tinyman.v2.pools import Pool


class BootstrapTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.application_address = get_application_address(cls.VALIDATOR_APP_ID)

cls.sender_private_key, cls.user_address = generate_account()
Expand Down Expand Up @@ -74,6 +74,7 @@ def test_bootstrap(self):
"rekey": decode_address(self.application_address),
"snd": decode_address(self.pool_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)

Expand Down Expand Up @@ -101,14 +102,15 @@ def test_pool_is_already_funded(self):
"rekey": decode_address(self.application_address),
"snd": decode_address(self.pool_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)


class BootstrapAlgoPoolTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.application_address = get_application_address(cls.VALIDATOR_APP_ID)

cls.sender_private_key, cls.user_address = generate_account()
Expand Down Expand Up @@ -167,6 +169,7 @@ def test_bootstrap(self):
"rekey": decode_address(self.application_address),
"snd": decode_address(self.pool_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)

Expand Down Expand Up @@ -194,5 +197,6 @@ def test_pool_is_already_funded(self):
"rekey": decode_address(self.application_address),
"snd": decode_address(self.pool_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)
10 changes: 8 additions & 2 deletions tests/v2/test_flash_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from tests.v2 import BaseTestCase
from tinyman.assets import AssetAmount
from tinyman.utils import int_to_bytes
from tinyman.v2.constants import FLASH_LOAN_APP_ARGUMENT, VERIFY_FLASH_LOAN_APP_ARGUMENT
from tinyman.v2.constants import (
FLASH_LOAN_APP_ARGUMENT,
VERIFY_FLASH_LOAN_APP_ARGUMENT,
TESTNET_VALIDATOR_APP_ID_V2,
)
from tinyman.v2.contracts import get_pool_logicsig
from tinyman.v2.pools import Pool
from tinyman.v2.quotes import FlashLoanQuote
Expand All @@ -18,7 +22,7 @@
class FlashLoanTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.sender_private_key, cls.user_address = generate_account()
cls.asset_1_id = 10
cls.asset_2_id = 8
Expand Down Expand Up @@ -98,6 +102,7 @@ def test_flash_loan(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)

Expand Down Expand Up @@ -134,5 +139,6 @@ def test_flash_loan(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)
11 changes: 9 additions & 2 deletions tests/v2/test_flash_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from tests.v2 import BaseTestCase
from tinyman.utils import int_to_bytes
from tinyman.v2.constants import FLASH_SWAP_APP_ARGUMENT, VERIFY_FLASH_SWAP_APP_ARGUMENT
from tinyman.v2.constants import (
FLASH_SWAP_APP_ARGUMENT,
VERIFY_FLASH_SWAP_APP_ARGUMENT,
TESTNET_VALIDATOR_APP_ID_V2,
)
from tinyman.v2.contracts import get_pool_logicsig
from tinyman.v2.flash_swap import prepare_flash_swap_transactions
from tinyman.v2.pools import Pool
Expand All @@ -17,7 +21,7 @@
class FlashSwapTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.sender_private_key, cls.user_address = generate_account()
cls.asset_1_id = 10
cls.asset_2_id = 8
Expand Down Expand Up @@ -49,6 +53,7 @@ def test_flash_swap(self):
transactions=[],
sender=self.user_address,
suggested_params=self.get_suggested_params(),
app_call_note=self.app_call_note().decode(),
)

transactions = txn_group.transactions
Expand All @@ -73,6 +78,7 @@ def test_flash_swap(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)

Expand All @@ -95,5 +101,6 @@ def test_flash_swap(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)
9 changes: 7 additions & 2 deletions tests/v2/test_remove_liquidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from tests.v2 import BaseTestCase
from tinyman.assets import AssetAmount
from tinyman.utils import int_to_bytes
from tinyman.v2.constants import REMOVE_LIQUIDITY_APP_ARGUMENT
from tinyman.v2.constants import (
REMOVE_LIQUIDITY_APP_ARGUMENT,
TESTNET_VALIDATOR_APP_ID_V2,
)
from tinyman.v2.contracts import get_pool_logicsig
from tinyman.v2.pools import Pool
from tinyman.v2.quotes import RemoveLiquidityQuote, SingleAssetRemoveLiquidityQuote
Expand All @@ -18,7 +21,7 @@
class RemoveLiquidityTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.sender_private_key, cls.user_address = generate_account()
cls.asset_1_id = 10
cls.asset_2_id = 8
Expand Down Expand Up @@ -112,6 +115,7 @@ def test_remove_liquidity(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)

Expand Down Expand Up @@ -184,5 +188,6 @@ def test_single_asset_remove_liquidity(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)
5 changes: 4 additions & 1 deletion tests/v2/test_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
SWAP_APP_ARGUMENT,
FIXED_INPUT_APP_ARGUMENT,
FIXED_OUTPUT_APP_ARGUMENT,
TESTNET_VALIDATOR_APP_ID_V2,
)
from tinyman.v2.contracts import get_pool_logicsig
from tinyman.v2.pools import Pool
Expand All @@ -22,7 +23,7 @@
class SwapTestCase(BaseTestCase):
@classmethod
def setUpClass(cls):
cls.VALIDATOR_APP_ID = 12345
cls.VALIDATOR_APP_ID = TESTNET_VALIDATOR_APP_ID_V2
cls.sender_private_key, cls.user_address = generate_account()
cls.asset_1_id = 10
cls.asset_2_id = 8
Expand Down Expand Up @@ -103,6 +104,7 @@ def test_fixed_input_swap(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)

Expand Down Expand Up @@ -166,5 +168,6 @@ def test_fixed_output_swap(self):
"lv": ANY,
"snd": decode_address(self.user_address),
"type": APPCALL_TXN,
"note": self.app_call_note(),
},
)
Loading