-
Notifications
You must be signed in to change notification settings - Fork 60
/
09_fixed_input_swap.py
45 lines (33 loc) · 1.32 KB
/
09_fixed_input_swap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# This sample is provided for demonstration purposes only.
# It is not intended for production use.
# This example does not constitute trading advice.
from pprint import pprint
from urllib.parse import quote_plus
from tinyman.assets import AssetAmount
from examples.v2.tutorial.common import get_account, get_assets
from examples.v2.utils import get_algod
from tinyman.v2.client import TinymanV2TestnetClient
account = get_account()
algod = get_algod()
client = TinymanV2TestnetClient(algod_client=algod, user_address=account["address"])
ASSET_A_ID, ASSET_B_ID = get_assets()["ids"]
ASSET_A = client.fetch_asset(ASSET_A_ID)
ASSET_B = client.fetch_asset(ASSET_B_ID)
pool = client.fetch_pool(ASSET_A_ID, ASSET_B_ID)
position = pool.fetch_pool_position()
amount_in = AssetAmount(pool.asset_1, 1_000_000)
quote = pool.fetch_fixed_input_swap_quote(
amount_in=amount_in,
)
print("\nSwap Quote:")
print(quote)
txn_group = pool.prepare_swap_transactions_from_quote(quote=quote)
# Sign
txn_group.sign_with_private_key(account["address"], account["private_key"])
# Submit transactions to the network and wait for confirmation
txn_info = client.submit(txn_group, wait=True)
print("Transaction Info")
pprint(txn_info)
print(
f"Check the transaction group on Algoexplorer: https://testnet.algoexplorer.io/tx/group/{quote_plus(txn_group.id)}"
)