tristero 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ Metadata-Version: 2.3
2
+ Name: tristero
3
+ Version: 0.1.3
4
+ Summary: Library for trading on Tristero
5
+ Author: pty1
6
+ Author-email: pty1 <pty11@proton.me>
7
+ Requires-Dist: eth-account>=0.13.7
8
+ Requires-Dist: httpx>=0.28.1
9
+ Requires-Dist: pydantic>=2.12.4
10
+ Requires-Dist: tenacity>=9.1.2
11
+ Requires-Dist: web3>=7.14.0
12
+ Requires-Dist: websockets>=15.0.1
13
+ Requires-Python: >=3.13
14
+ Description-Content-Type: text/markdown
15
+
16
+ # Tristero
17
+ [![PyPI version](https://badge.fury.io/py/tristero.svg)](https://badge.fury.io/py/tristero)
18
+ [![Python Support](https://img.shields.io/pypi/pyversions/tristero.svg)](https://pypi.org/project/tristero/)
19
+
20
+ This repository is home to Tristero's trading library.
21
+
22
+ ### Installation
23
+ ```
24
+ pip install tristero
25
+ ```
26
+
27
+ ### Quick Start
28
+
29
+ Execute a cross-chain swap in just a few lines:
30
+
31
+ ```py
32
+ import os
33
+ from tristero.client import TokenSpec, execute_swap
34
+ from eth_account import Account
35
+ from web3 import AsyncWeb3
36
+ from tristero.api import ChainID
37
+
38
+ private_key = os.getenv("EVM_PRIVATE_KEY")
39
+ account = Account.from_key(private_key)
40
+ w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider("https://arbitrum-one-rpc.publicnode.com"))
41
+
42
+ result = await execute_swap(
43
+ w3=w3,
44
+ account=account,
45
+ src_t=TokenSpec(chain_id=ChainID.arbitrum, token_address="0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"), # USDT
46
+ dst_t=TokenSpec(chain_id=ChainID.base, token_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"), # USDC
47
+ raw_amount=10000000 # Raw token amount (multiply by 10^decimals)
48
+ )
49
+ ```
50
+
51
+ ### How it works
52
+
53
+ Tristero swaps happen in two steps:
54
+
55
+ 1. Quote & Sign - Request a quote from the server and sign it with your private key
56
+ 2. Submit & Fill - Submit the signed order to be filled at a later date
57
+
58
+ This library provides both high-level convenience functions and lower-level components for precise control.
59
+
60
+ ### API Reference
61
+
62
+ #### Execute Full Swap
63
+ `execute_swap` handles the entire workflow automatically: quoting, signing, submitting, and monitoring.
64
+ ```py
65
+ from tristero.swap import execute_swap, TokenSpec
66
+ from web3 import AsyncWeb3
67
+ from eth_account.signers.local import LocalAccount
68
+
69
+ w3 = AsyncWeb3(...) # Your Web3 provider
70
+ account: LocalAccount = ... # Your account
71
+
72
+ result = await execute_swap(
73
+ w3=w3,
74
+ account=account,
75
+ src_t=TokenSpec(chain_id=ChainID.ethereum, token_address="0xA0b8..."),
76
+ dst_t=TokenSpec(chain_id=ChainID.arbitrum, token_address="0xaf88..."),
77
+ raw_amount=10*(10**18),
78
+ retry=True,
79
+ timeout=300.0 # 5 minutes
80
+ )
81
+ ```
82
+
83
+ #### Requesting a quote
84
+
85
+ `get_quote` requests a quote for a particular swap, letting you see output amounts and gas fees.
86
+
87
+ ```py
88
+ from tristero.api import get_quote, ChainID
89
+
90
+ quote = await get_quote(
91
+ from_wallet="0x1234...", # Source wallet address
92
+ to_wallet="0x5678...", # Destination wallet address
93
+ from_chain_id=ChainID.ethereum, # Source chain
94
+ from_address="0xA0b8...", # Source token address (or "native")
95
+ to_chain_id=ChainID.arbitrum, # Destination chain
96
+ to_address="0xaf88...", # Destination token address (or "native")
97
+ amount=10*(10**18), # Amount in smallest unit (wei)
98
+ )
99
+ ```
100
+
101
+ #### Creating a signed order
102
+ `create_order` creates and signs an order without submitting to be filled.
103
+
104
+ ```py
105
+ from tristero.api import get_quote, ChainID
106
+
107
+ w3 = AsyncWeb3(...) # Your Web3 provider
108
+ account: LocalAccount = ... # Your account
109
+
110
+ data, sig = await create_order(
111
+ w3,
112
+ account,
113
+ from_chain_id=ChainID.ethereum,
114
+ from_address="0xA0b8...",
115
+ to_chain_id=ChainID.arbitrum,
116
+ to_address="0xaf88...",
117
+ raw_amount=10*(10**18),
118
+ )
119
+
120
+ ```
121
+
122
+ #### Submit order
123
+
124
+ `fill_order` submits a signed order for execution.
125
+
126
+ ```py
127
+ from tristero.api import fill_order
128
+
129
+ data, sig = ... # from earlier
130
+
131
+ response = await fill_order(
132
+ signature=str(sig.signature.to_0x_hex()),
133
+ domain=data.domain.model_dump(by_alias=True, mode="json"),
134
+ message=data.message.model_dump(by_alias=True, mode="json"),
135
+ )
136
+
137
+ order_id = response['id']
138
+ ```
139
+
140
+ #### Subscribing for updates
141
+
142
+ Orders can be monitored for changes and status live
143
+
144
+ ```py
145
+ from tristero.api import poll_updates
146
+ import json
147
+
148
+ ws = await poll_updates(order_id)
149
+
150
+ async for msg in ws:
151
+ update = json.loads(msg)
152
+ print(f"Completed: {update['completed']}")
153
+ print(f"Failed: {update['failed']}")
154
+
155
+ if update["completed"] or update["failed"]:
156
+ await ws.close()
157
+ break
158
+ ```
@@ -0,0 +1,143 @@
1
+ # Tristero
2
+ [![PyPI version](https://badge.fury.io/py/tristero.svg)](https://badge.fury.io/py/tristero)
3
+ [![Python Support](https://img.shields.io/pypi/pyversions/tristero.svg)](https://pypi.org/project/tristero/)
4
+
5
+ This repository is home to Tristero's trading library.
6
+
7
+ ### Installation
8
+ ```
9
+ pip install tristero
10
+ ```
11
+
12
+ ### Quick Start
13
+
14
+ Execute a cross-chain swap in just a few lines:
15
+
16
+ ```py
17
+ import os
18
+ from tristero.client import TokenSpec, execute_swap
19
+ from eth_account import Account
20
+ from web3 import AsyncWeb3
21
+ from tristero.api import ChainID
22
+
23
+ private_key = os.getenv("EVM_PRIVATE_KEY")
24
+ account = Account.from_key(private_key)
25
+ w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider("https://arbitrum-one-rpc.publicnode.com"))
26
+
27
+ result = await execute_swap(
28
+ w3=w3,
29
+ account=account,
30
+ src_t=TokenSpec(chain_id=ChainID.arbitrum, token_address="0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"), # USDT
31
+ dst_t=TokenSpec(chain_id=ChainID.base, token_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"), # USDC
32
+ raw_amount=10000000 # Raw token amount (multiply by 10^decimals)
33
+ )
34
+ ```
35
+
36
+ ### How it works
37
+
38
+ Tristero swaps happen in two steps:
39
+
40
+ 1. Quote & Sign - Request a quote from the server and sign it with your private key
41
+ 2. Submit & Fill - Submit the signed order to be filled at a later date
42
+
43
+ This library provides both high-level convenience functions and lower-level components for precise control.
44
+
45
+ ### API Reference
46
+
47
+ #### Execute Full Swap
48
+ `execute_swap` handles the entire workflow automatically: quoting, signing, submitting, and monitoring.
49
+ ```py
50
+ from tristero.swap import execute_swap, TokenSpec
51
+ from web3 import AsyncWeb3
52
+ from eth_account.signers.local import LocalAccount
53
+
54
+ w3 = AsyncWeb3(...) # Your Web3 provider
55
+ account: LocalAccount = ... # Your account
56
+
57
+ result = await execute_swap(
58
+ w3=w3,
59
+ account=account,
60
+ src_t=TokenSpec(chain_id=ChainID.ethereum, token_address="0xA0b8..."),
61
+ dst_t=TokenSpec(chain_id=ChainID.arbitrum, token_address="0xaf88..."),
62
+ raw_amount=10*(10**18),
63
+ retry=True,
64
+ timeout=300.0 # 5 minutes
65
+ )
66
+ ```
67
+
68
+ #### Requesting a quote
69
+
70
+ `get_quote` requests a quote for a particular swap, letting you see output amounts and gas fees.
71
+
72
+ ```py
73
+ from tristero.api import get_quote, ChainID
74
+
75
+ quote = await get_quote(
76
+ from_wallet="0x1234...", # Source wallet address
77
+ to_wallet="0x5678...", # Destination wallet address
78
+ from_chain_id=ChainID.ethereum, # Source chain
79
+ from_address="0xA0b8...", # Source token address (or "native")
80
+ to_chain_id=ChainID.arbitrum, # Destination chain
81
+ to_address="0xaf88...", # Destination token address (or "native")
82
+ amount=10*(10**18), # Amount in smallest unit (wei)
83
+ )
84
+ ```
85
+
86
+ #### Creating a signed order
87
+ `create_order` creates and signs an order without submitting to be filled.
88
+
89
+ ```py
90
+ from tristero.api import get_quote, ChainID
91
+
92
+ w3 = AsyncWeb3(...) # Your Web3 provider
93
+ account: LocalAccount = ... # Your account
94
+
95
+ data, sig = await create_order(
96
+ w3,
97
+ account,
98
+ from_chain_id=ChainID.ethereum,
99
+ from_address="0xA0b8...",
100
+ to_chain_id=ChainID.arbitrum,
101
+ to_address="0xaf88...",
102
+ raw_amount=10*(10**18),
103
+ )
104
+
105
+ ```
106
+
107
+ #### Submit order
108
+
109
+ `fill_order` submits a signed order for execution.
110
+
111
+ ```py
112
+ from tristero.api import fill_order
113
+
114
+ data, sig = ... # from earlier
115
+
116
+ response = await fill_order(
117
+ signature=str(sig.signature.to_0x_hex()),
118
+ domain=data.domain.model_dump(by_alias=True, mode="json"),
119
+ message=data.message.model_dump(by_alias=True, mode="json"),
120
+ )
121
+
122
+ order_id = response['id']
123
+ ```
124
+
125
+ #### Subscribing for updates
126
+
127
+ Orders can be monitored for changes and status live
128
+
129
+ ```py
130
+ from tristero.api import poll_updates
131
+ import json
132
+
133
+ ws = await poll_updates(order_id)
134
+
135
+ async for msg in ws:
136
+ update = json.loads(msg)
137
+ print(f"Completed: {update['completed']}")
138
+ print(f"Failed: {update['failed']}")
139
+
140
+ if update["completed"] or update["failed"]:
141
+ await ws.close()
142
+ break
143
+ ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tristero"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "Library for trading on Tristero"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -108,7 +108,7 @@ def or_native(chain_id: ChainID, address: str):
108
108
  return native_address(chain_id) if address == "native" else address
109
109
 
110
110
 
111
- async def get_quote_tristero(
111
+ async def get_quote(
112
112
  from_wallet: str,
113
113
  to_wallet: str,
114
114
  from_chain_id: ChainID,
@@ -144,7 +144,7 @@ async def get_quote_tristero(
144
144
  raise QuoteException(e, data) from e
145
145
 
146
146
 
147
- async def fill_tristero(signature: str, domain: dict[str, Any], message: dict[str, Any]):
147
+ async def fill_order(signature: str, domain: dict[str, Any], message: dict[str, Any]):
148
148
  async with httpx.AsyncClient() as c:
149
149
  data = {"signature": signature, "domain": domain, "message": message}
150
150
  resp = await c.post(
@@ -155,4 +155,4 @@ async def fill_tristero(signature: str, domain: dict[str, Any], message: dict[st
155
155
 
156
156
  async def poll_updates(order_id: str):
157
157
  ws = await connect(f"{get_config().ws_url}/{order_id}")
158
- return ws
158
+ return ws
@@ -6,7 +6,7 @@ from typing import Any, TypeVar
6
6
  from eth_account.signers.local import LocalAccount
7
7
  from pydantic import BaseModel
8
8
 
9
- from tristero.api import ChainID, fill_tristero, poll_updates
9
+ from tristero.api import ChainID, fill_order, poll_updates
10
10
  from .permit2 import create_order
11
11
  from web3 import AsyncBaseProvider, AsyncWeb3
12
12
  import logging
@@ -106,7 +106,7 @@ async def start_swap(w3: AsyncWeb3[P], account: LocalAccount, from_t: TokenSpec,
106
106
  to_t.token_address,
107
107
  raw_amount,
108
108
  )
109
- response = await fill_tristero(
109
+ response = await fill_order(
110
110
  str(sig.signature.to_0x_hex()),
111
111
  data.domain.model_dump(by_alias=True, mode="json"),
112
112
  data.message.model_dump(by_alias=True, mode="json"),
@@ -24,7 +24,7 @@ from web3.eth import AsyncEth
24
24
 
25
25
  from .api import (
26
26
  _WRAPPED_GAS_ADDRESSES,
27
- get_quote_tristero,
27
+ get_quote,
28
28
  _PERMIT2_CONTRACT_ADDRESSES,
29
29
  ChainID,
30
30
  )
@@ -370,7 +370,7 @@ async def create_order(
370
370
  ):
371
371
  if not to_address:
372
372
  to_address = account.address
373
- q = await get_quote_tristero(
373
+ q = await get_quote(
374
374
  account.address,
375
375
  to_address,
376
376
  src_chain,
tristero-0.1.2/PKG-INFO DELETED
@@ -1,49 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: tristero
3
- Version: 0.1.2
4
- Summary: Library for trading on Tristero
5
- Author: pty1
6
- Author-email: pty1 <pty11@proton.me>
7
- Requires-Dist: eth-account>=0.13.7
8
- Requires-Dist: httpx>=0.28.1
9
- Requires-Dist: pydantic>=2.12.4
10
- Requires-Dist: tenacity>=9.1.2
11
- Requires-Dist: web3>=7.14.0
12
- Requires-Dist: websockets>=15.0.1
13
- Requires-Python: >=3.13
14
- Description-Content-Type: text/markdown
15
-
16
- # Tristero
17
- [![PyPI version](https://badge.fury.io/py/tristero.svg)](https://badge.fury.io/py/tristero)
18
- [![Python Support](https://img.shields.io/pypi/pyversions/tristero.svg)](https://pypi.org/project/tristero/)
19
-
20
- This repository is home to Tristero's trading library.
21
-
22
- ### Installation
23
- ```
24
- pip install tristero
25
- ```
26
-
27
- ### Usage
28
-
29
- You can get started making swaps on Tristero as easily as:
30
-
31
- ```py
32
- import os
33
- from tristero.client import TokenSpec, execute_swap, wait_for_completion
34
- from eth_account import Account
35
- from web3 import AsyncWeb3
36
- from tristero.api import ChainID
37
-
38
- private_key = os.getenv("EVM_PRIVATE_KEY")
39
- account = Account.from_key(private_key)
40
- w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider("https://arbitrum-one-rpc.publicnode.com")) # adjust RPC endpoint as needed
41
-
42
- res = await execute_swap(
43
- w3,
44
- account,
45
- TokenSpec(chain_id=ChainID.arbitrum, token_address="0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"), # USDT0(arbitrum)
46
- TokenSpec(chain_id=ChainID.base, token_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"), # USDC(base)
47
- 10000000 # Raw token amount (no decimals). You can calculate this with amount * (10 ** decimals)
48
- )
49
- ```
tristero-0.1.2/README.md DELETED
@@ -1,34 +0,0 @@
1
- # Tristero
2
- [![PyPI version](https://badge.fury.io/py/tristero.svg)](https://badge.fury.io/py/tristero)
3
- [![Python Support](https://img.shields.io/pypi/pyversions/tristero.svg)](https://pypi.org/project/tristero/)
4
-
5
- This repository is home to Tristero's trading library.
6
-
7
- ### Installation
8
- ```
9
- pip install tristero
10
- ```
11
-
12
- ### Usage
13
-
14
- You can get started making swaps on Tristero as easily as:
15
-
16
- ```py
17
- import os
18
- from tristero.client import TokenSpec, execute_swap, wait_for_completion
19
- from eth_account import Account
20
- from web3 import AsyncWeb3
21
- from tristero.api import ChainID
22
-
23
- private_key = os.getenv("EVM_PRIVATE_KEY")
24
- account = Account.from_key(private_key)
25
- w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider("https://arbitrum-one-rpc.publicnode.com")) # adjust RPC endpoint as needed
26
-
27
- res = await execute_swap(
28
- w3,
29
- account,
30
- TokenSpec(chain_id=ChainID.arbitrum, token_address="0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"), # USDT0(arbitrum)
31
- TokenSpec(chain_id=ChainID.base, token_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"), # USDC(base)
32
- 10000000 # Raw token amount (no decimals). You can calculate this with amount * (10 ** decimals)
33
- )
34
- ```
File without changes