-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from tinymanorg/v2-updates
Tinyman V2
- Loading branch information
Showing
76 changed files
with
6,259 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
ignore = E501,F403,F405,E126,E121,W503,E203 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Lint & Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.10", "3.9", "3.8"] | ||
py-algorand-sdk-version: ["1.18", "1.17", "1.16", "1.15", "1.14", "1.13"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 black py-algorand-sdk==${{ matrix.py-algorand-sdk-version }} | ||
- name: Run flake8 | ||
run: flake8 ${{ github.workspace }} --ignore=E501,F403,F405,E126,E121,W503,E203 | ||
|
||
- name: Run Black | ||
run: black ${{ github.workspace }} --check | ||
|
||
- name: Run Unit tests | ||
run: python -m unittest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
repos: | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: '3.9.2' # pick a git hash / tag to point to | ||
hooks: | ||
- id: flake8 | ||
args: ['--ignore=E501,F403,F405,E126,E121,W503,E203', '.'] | ||
exclude: ^(env|venv) | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 22.8.0 | ||
hooks: | ||
- id: black | ||
args: ['.', '--check'] | ||
exclude: ^(env|venv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Change Log | ||
|
||
## 2.0.0 | ||
|
||
### Added | ||
|
||
* Added Tinyman V2 support (`tinyman.v2`). | ||
* Added Staking support (`tinyman.staking`). | ||
- It allows creating commitment transaction by `prepare_commit_transaction` and tracking commitments by `parse_commit_transaction`. | ||
* Added `calculate_price_impact` function to `tinyman.utils`. | ||
* Improved `TransactionGroup` class. | ||
- Added `+` operator support for composability, it allows creating a new transaction group (`txn_group_1 + txn_group_2`). | ||
- Added `id` property, it returns the transactions group id. | ||
- Added `TransactionGroup.sign_with_logicsig` function and deprecated `TransactionGroup.sign_with_logicisg` because of the typo. | ||
|
||
### Changed | ||
|
||
* `get_program` (V1) is moved from `tinyman.utils` to `tinyman.v1.contracts`. | ||
* `get_state_from_account_info` (V1) is moved from `tinyman.utils` to `tinyman.v1.utils`. | ||
|
||
### Removed | ||
|
||
* Deprecated `wait_for_confirmation` function is removed. `wait_for_confirmation` is added to [Algorand SDK](https://github.com/algorand/py-algorand-sdk). | ||
* Drop Python 3.7 support. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"repo": "https://github.com/tinymanorg/tinyman-staking", | ||
"ref": "main", | ||
"contracts": { | ||
"staking_app": { | ||
"type": "app", | ||
"approval_program": { | ||
"bytecode": "BSADAAEIJgcIZW5kX3RpbWUGYXNzZXRzBG1pbnMMdmVyaWZpY2F0aW9uCGJhbGFuY2UgAmlkD3Byb2dyYW1fY291bnRlcjEZIhJAAC8xGSMSQAAZMRmBAhJAAicxGYEEEkACITEZgQUSQAIfADYaAIAFc2V0dXASQAGZADYaAIAGY3JlYXRlEkAAijYaAIAGY29tbWl0EkAAfTYaAIAFY2xhaW0SQAEDNhoAgAZ1cGRhdGUSQAE8NhoAgA51cGRhdGVfcmV3YXJkcxJAAN82GgCADXVwZGF0ZV9hc3NldHMSQAD4NhoAgAtlbmRfcHJvZ3JhbRJAAPI2GgArEkAA9TYaAIALbG9nX2JhbGFuY2USQADvACNDIyhiMgcNRCMpYiJKJAtbNjAAEkAACiMISYEODERC/+tMSDUBIypiNAEkC1s1AjYaARdBAAg2GgEXNAIPRCI2MABwAERJFicETFCwNhoBFw9EgBN0aW55bWFuU3Rha2luZy92MTpiMQVRABMSRDEFVxMANQE0ASJbIycFYhJENAEkWzYwABJENAGBEFs2GgEXEkQjQyNDIoACcjE2GgFmIoACcjI2GgJmIoACcjM2GgNmIoACcjQ2GgRmIoACcjU2GgVmI0MiKTYaAWYiKjYaAmYjQyIoNhoBF2YjQyNDMgkxABJEIis2GgFmI0MiNjAAcABESUQWJwRMULAjQycGZCMINQEnBjQBZyInBTQBZiKAA3VybDYaAWYigA9yZXdhcmRfYXNzZXRfaWQ2GgIXZiKADXJld2FyZF9wZXJpb2Q2GgMXZiKACnN0YXJ0X3RpbWU2GgQXZiIoNhoFF2YiKTYaBmYiKjYaB2YjQyNDMgkxABJDMgkxABJDAA==", | ||
"address": "KJ3W4IB66Q4ZITCNVABJXAV4I4HKWSZIJMD6BTFATQAWO5AKOV5VMZ6OFI", | ||
"size": 658, | ||
"variables": [], | ||
"source": "https://github.com/tinymanorg/tinyman-staking/tree/main/contracts/staking.teal" | ||
}, | ||
"clear_program": { | ||
"bytecode": "BIEB", | ||
"address": "P7GEWDXXW5IONRW6XRIRVPJCT2XXEQGOBGG65VJPBUOYZEJCBZWTPHS3VQ", | ||
"size": 3, | ||
"variables": [], | ||
"source": "https://github.com/tinymanorg/tinyman-staking/tree/main/contracts/clear_state.teal" | ||
}, | ||
"global_state_schema": { | ||
"num_uints": 2, | ||
"num_byte_slices": 2 | ||
}, | ||
"local_state_schema": { | ||
"num_uints": 5, | ||
"num_byte_slices": 11 | ||
}, | ||
"name": "staking_app" | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import requests | ||
from tinyman.staking import parse_commit_transaction | ||
from tinyman.staking.constants import TESTNET_STAKING_APP_ID | ||
|
||
app_id = TESTNET_STAKING_APP_ID | ||
result = requests.get( | ||
f"https://indexer.testnet.algoexplorerapi.io/v2/transactions?application-id={app_id}&latest=50" | ||
).json() | ||
for txn in result["transactions"]: | ||
commit = parse_commit_transaction(txn, app_id) | ||
if commit: | ||
print(commit) | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This sample is provided for demonstration purposes only. | ||
# It is not intended for production use. | ||
# This example does not constitute trading advice. | ||
|
||
from tinyman.v1.client import TinymanTestnetClient | ||
|
||
from tinyman.staking import prepare_commit_transaction | ||
|
||
# Hardcoding account keys is not a great practice. This is for demonstration purposes only. | ||
# See the README & Docs for alternative signing methods. | ||
account = { | ||
"address": "ALGORAND_ADDRESS_HERE", | ||
"private_key": "base64_private_key_here", # Use algosdk.mnemonic.to_private_key(mnemonic) if necessary | ||
} | ||
|
||
client = TinymanTestnetClient(user_address=account["address"]) | ||
|
||
# Fetch our two assets of interest | ||
TINYUSDC = client.fetch_asset(21582668) | ||
ALGO = client.fetch_asset(0) | ||
|
||
# Fetch the pool we will work with | ||
pool = client.fetch_pool(TINYUSDC, ALGO) | ||
|
||
|
||
sp = client.algod.suggested_params() | ||
|
||
txn_group = prepare_commit_transaction( | ||
app_id=client.staking_app_id, | ||
program_id=1, | ||
program_account="B4XVZ226UPFEIQBPIY6H454YA4B7HYXGEM7UDQR2RJP66HVLOARZTUTS6Q", | ||
pool_asset_id=pool.liquidity_asset.id, | ||
amount=600_000_000, | ||
sender=account["address"], | ||
suggested_params=sp, | ||
) | ||
|
||
txn_group.sign_with_private_key(account["address"], account["private_key"]) | ||
result = client.submit(txn_group, wait=True) | ||
print(result) |
Oops, something went wrong.