aquarius-sdk 0.0.1__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.
- aquarius_sdk-0.0.1/LICENSE +202 -0
- aquarius_sdk-0.0.1/PKG-INFO +44 -0
- aquarius_sdk-0.0.1/README.md +28 -0
- aquarius_sdk-0.0.1/aquarius/__init__.py +22 -0
- aquarius_sdk-0.0.1/aquarius/assets.py +43 -0
- aquarius_sdk-0.0.1/aquarius/client.py +154 -0
- aquarius_sdk-0.0.1/aquarius/errors.py +10 -0
- aquarius_sdk-0.0.1/aquarius_sdk.egg-info/PKG-INFO +44 -0
- aquarius_sdk-0.0.1/aquarius_sdk.egg-info/SOURCES.txt +13 -0
- aquarius_sdk-0.0.1/aquarius_sdk.egg-info/dependency_links.txt +1 -0
- aquarius_sdk-0.0.1/aquarius_sdk.egg-info/requires.txt +5 -0
- aquarius_sdk-0.0.1/aquarius_sdk.egg-info/top_level.txt +1 -0
- aquarius_sdk-0.0.1/pyproject.toml +26 -0
- aquarius_sdk-0.0.1/setup.cfg +4 -0
- aquarius_sdk-0.0.1/tests/test_interface.py +50 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aquarius-sdk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python SDK for the Aquarius protocol on Stellar
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://aqua.network
|
|
7
|
+
Project-URL: Documentation, https://docs.aqua.network/developers/quickstart
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: stellar-sdk>=13
|
|
12
|
+
Requires-Dist: requests>=2.28
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# aquarius-sdk
|
|
18
|
+
|
|
19
|
+
The Python SDK for [Aquarius](https://aqua.network) — swaps, liquidity, and rewards on Stellar.
|
|
20
|
+
|
|
21
|
+
**Status: interface preview (0.0.x).** The swap surface works end-to-end — quote → execute, exact-input and exact-output, on mainnet and testnet. Pools, liquidity, and rewards are under development, and the API may change before 0.1. Follow the [developer documentation](https://docs.aqua.network/developers/quickstart) for the stable integration path in the meantime.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from stellar_sdk import Keypair
|
|
25
|
+
from aquarius import AquariusClient, Asset, XLM
|
|
26
|
+
|
|
27
|
+
AQUA = Asset.classic("AQUA", "GAHPYWLK6YRN7CVYZOO4H3VDRZ7PVF5UJGLZCSPAEIKJE2XSWF5LAGER")
|
|
28
|
+
|
|
29
|
+
aqua = AquariusClient(network="testnet", signer=Keypair.random())
|
|
30
|
+
aqua.fund_with_friendbot() # testnet only: 10,000 test XLM
|
|
31
|
+
aqua.ensure_trustline(AQUA)
|
|
32
|
+
|
|
33
|
+
quote = aqua.quote(XLM, AQUA, amount_in=10_0000000) # amount_out= for exact output
|
|
34
|
+
print(f"10 XLM -> {quote.amount_out / 1e7:,.2f} AQUA via {len(quote.route)} pool(s)")
|
|
35
|
+
|
|
36
|
+
receipt = quote.execute()
|
|
37
|
+
print(f"received {receipt.amount_out / 1e7:,.2f} AQUA in tx {receipt.tx_hash}")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- Reads need no signer; writes take a `Keypair`. Raw secrets are never stored.
|
|
41
|
+
- Slippage guards raise a typed `SlippageError` ("re-quote and retry"); missing routes raise `NoRouteError`.
|
|
42
|
+
- Amounts are integer stroops (1 token = 10^7 stroops).
|
|
43
|
+
|
|
44
|
+
Questions and integration help: [Discord](https://discord.gg/sgzFscHp4C).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# aquarius-sdk
|
|
2
|
+
|
|
3
|
+
The Python SDK for [Aquarius](https://aqua.network) — swaps, liquidity, and rewards on Stellar.
|
|
4
|
+
|
|
5
|
+
**Status: interface preview (0.0.x).** The swap surface works end-to-end — quote → execute, exact-input and exact-output, on mainnet and testnet. Pools, liquidity, and rewards are under development, and the API may change before 0.1. Follow the [developer documentation](https://docs.aqua.network/developers/quickstart) for the stable integration path in the meantime.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from stellar_sdk import Keypair
|
|
9
|
+
from aquarius import AquariusClient, Asset, XLM
|
|
10
|
+
|
|
11
|
+
AQUA = Asset.classic("AQUA", "GAHPYWLK6YRN7CVYZOO4H3VDRZ7PVF5UJGLZCSPAEIKJE2XSWF5LAGER")
|
|
12
|
+
|
|
13
|
+
aqua = AquariusClient(network="testnet", signer=Keypair.random())
|
|
14
|
+
aqua.fund_with_friendbot() # testnet only: 10,000 test XLM
|
|
15
|
+
aqua.ensure_trustline(AQUA)
|
|
16
|
+
|
|
17
|
+
quote = aqua.quote(XLM, AQUA, amount_in=10_0000000) # amount_out= for exact output
|
|
18
|
+
print(f"10 XLM -> {quote.amount_out / 1e7:,.2f} AQUA via {len(quote.route)} pool(s)")
|
|
19
|
+
|
|
20
|
+
receipt = quote.execute()
|
|
21
|
+
print(f"received {receipt.amount_out / 1e7:,.2f} AQUA in tx {receipt.tx_hash}")
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- Reads need no signer; writes take a `Keypair`. Raw secrets are never stored.
|
|
25
|
+
- Slippage guards raise a typed `SlippageError` ("re-quote and retry"); missing routes raise `NoRouteError`.
|
|
26
|
+
- Amounts are integer stroops (1 token = 10^7 stroops).
|
|
27
|
+
|
|
28
|
+
Questions and integration help: [Discord](https://discord.gg/sgzFscHp4C).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""aquarius-sdk — the Python SDK for the Aquarius protocol on Stellar.
|
|
2
|
+
|
|
3
|
+
Interface preview. The swap surface works end-to-end on testnet and mainnet;
|
|
4
|
+
pools, liquidity, and rewards are not implemented yet.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .assets import XLM, Asset
|
|
8
|
+
from .client import AquariusClient, Quote, Receipt
|
|
9
|
+
from .errors import AquariusError, NoRouteError, SlippageError
|
|
10
|
+
|
|
11
|
+
__version__ = "0.0.1"
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"AquariusClient",
|
|
15
|
+
"Asset",
|
|
16
|
+
"XLM",
|
|
17
|
+
"Quote",
|
|
18
|
+
"Receipt",
|
|
19
|
+
"AquariusError",
|
|
20
|
+
"NoRouteError",
|
|
21
|
+
"SlippageError",
|
|
22
|
+
]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from stellar_sdk import Asset as _StellarAsset
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class Asset:
|
|
10
|
+
"""A token, however you happen to know it: native, code+issuer, or contract ID."""
|
|
11
|
+
|
|
12
|
+
code: str | None = None
|
|
13
|
+
issuer: str | None = None
|
|
14
|
+
_contract: str | None = None
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def native(cls) -> "Asset":
|
|
18
|
+
return cls(code="XLM")
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def classic(cls, code: str, issuer: str) -> "Asset":
|
|
22
|
+
return cls(code=code, issuer=issuer)
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def contract(cls, contract_id: str) -> "Asset":
|
|
26
|
+
return cls(_contract=contract_id)
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def is_native(self) -> bool:
|
|
30
|
+
return self._contract is None and self.issuer is None
|
|
31
|
+
|
|
32
|
+
def contract_id(self, passphrase: str) -> str:
|
|
33
|
+
if self._contract:
|
|
34
|
+
return self._contract
|
|
35
|
+
if self.is_native:
|
|
36
|
+
return _StellarAsset.native().contract_id(passphrase)
|
|
37
|
+
return _StellarAsset(self.code, self.issuer).contract_id(passphrase)
|
|
38
|
+
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
return self.code or self._contract
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
XLM = Asset.native()
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from stellar_sdk import Asset as _StellarAsset, Keypair, Network, Server, SorobanServer, TransactionBuilder, scval
|
|
7
|
+
from stellar_sdk.xdr import SCVal, TransactionMeta
|
|
8
|
+
|
|
9
|
+
from .assets import Asset
|
|
10
|
+
from .errors import NoRouteError, SlippageError
|
|
11
|
+
|
|
12
|
+
_NETWORKS = {
|
|
13
|
+
"mainnet": dict(
|
|
14
|
+
router="CBQDHNBFBZYE4MKPWBSJOPIYLW4SFSXAXUTSXJN76GNKYVYPCKWC6QUK",
|
|
15
|
+
api="https://amm-api.aqua.network/api/external/v2",
|
|
16
|
+
rpc="https://mainnet.sorobanrpc.com",
|
|
17
|
+
horizon="https://horizon.stellar.org",
|
|
18
|
+
passphrase=Network.PUBLIC_NETWORK_PASSPHRASE,
|
|
19
|
+
),
|
|
20
|
+
"testnet": dict(
|
|
21
|
+
router="CBCFTQSPDBAIZ6R6PJQKSQWKNKWH2QIV3I4J72SHWBIK3ADRRAM5A6GD",
|
|
22
|
+
api="https://amm-api-testnet.aqua.network/api/external/v2",
|
|
23
|
+
rpc="https://soroban-testnet.stellar.org:443",
|
|
24
|
+
horizon="https://horizon-testnet.stellar.org",
|
|
25
|
+
passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
|
|
26
|
+
),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class Receipt:
|
|
32
|
+
tx_hash: str
|
|
33
|
+
amount_in: int # stroops actually spent
|
|
34
|
+
amount_out: int # stroops actually received
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class Quote:
|
|
39
|
+
amount_in: int
|
|
40
|
+
amount_out: int
|
|
41
|
+
guard: int # min_out (exact-input) or max_in (exact-output)
|
|
42
|
+
route: list[str] # pool addresses along the path
|
|
43
|
+
is_exact_input: bool
|
|
44
|
+
_xdr: str = field(repr=False)
|
|
45
|
+
_token_in: str = field(repr=False)
|
|
46
|
+
_client: "AquariusClient" = field(repr=False)
|
|
47
|
+
|
|
48
|
+
def execute(self) -> Receipt:
|
|
49
|
+
"""Build, sign, submit, confirm, and parse the swap this quote describes."""
|
|
50
|
+
return self._client._execute(self)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AquariusClient:
|
|
54
|
+
def __init__(self, network: str = "mainnet", signer: Keypair | None = None):
|
|
55
|
+
cfg = _NETWORKS[network]
|
|
56
|
+
self.network = network
|
|
57
|
+
self.router = cfg["router"]
|
|
58
|
+
self.api = cfg["api"]
|
|
59
|
+
self.passphrase = cfg["passphrase"]
|
|
60
|
+
self.horizon = Server(cfg["horizon"])
|
|
61
|
+
self.rpc = SorobanServer(cfg["rpc"])
|
|
62
|
+
self.signer = signer
|
|
63
|
+
|
|
64
|
+
# -- reads (no signer required) -------------------------------------------
|
|
65
|
+
|
|
66
|
+
def quote(self, from_: Asset, to: Asset, *, amount_in: int | None = None,
|
|
67
|
+
amount_out: int | None = None, slippage: float = 0.01) -> Quote:
|
|
68
|
+
"""Best route for a swap. Pass amount_in (exact input) or amount_out (exact output)."""
|
|
69
|
+
if (amount_in is None) == (amount_out is None):
|
|
70
|
+
raise ValueError("pass exactly one of amount_in / amount_out")
|
|
71
|
+
is_exact_input = amount_in is not None
|
|
72
|
+
endpoint = "/find-path/" if is_exact_input else "/find-path-strict-receive/"
|
|
73
|
+
response = requests.post(f"{self.api}{endpoint}", json={
|
|
74
|
+
"token_in_address": from_.contract_id(self.passphrase),
|
|
75
|
+
"token_out_address": to.contract_id(self.passphrase),
|
|
76
|
+
"amount": str(amount_in if is_exact_input else amount_out),
|
|
77
|
+
}).json()
|
|
78
|
+
return self._parse_find_path(response, from_, to,
|
|
79
|
+
amount_in=amount_in, amount_out=amount_out,
|
|
80
|
+
slippage=slippage)
|
|
81
|
+
|
|
82
|
+
# -- writes ----------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
def swap(self, from_: Asset, to: Asset, **kwargs) -> Receipt:
|
|
85
|
+
"""quote() + execute() in one call, for bots."""
|
|
86
|
+
return self.quote(from_, to, **kwargs).execute()
|
|
87
|
+
|
|
88
|
+
# -- Stellar quirks, absorbed ----------------------------------------------
|
|
89
|
+
|
|
90
|
+
def ensure_trustline(self, asset: Asset) -> None:
|
|
91
|
+
"""Create the trustline if the signer's account doesn't hold one. No-op for native."""
|
|
92
|
+
if asset.is_native:
|
|
93
|
+
return
|
|
94
|
+
account = self.horizon.accounts().account_id(self.signer.public_key).call()
|
|
95
|
+
for b in account["balances"]:
|
|
96
|
+
if b.get("asset_code") == asset.code and b.get("asset_issuer") == asset.issuer:
|
|
97
|
+
return
|
|
98
|
+
tx = (TransactionBuilder(self.horizon.load_account(self.signer.public_key),
|
|
99
|
+
network_passphrase=self.passphrase, base_fee=100)
|
|
100
|
+
.append_change_trust_op(asset=_StellarAsset(asset.code, asset.issuer))
|
|
101
|
+
.set_timeout(60).build())
|
|
102
|
+
tx.sign(self.signer)
|
|
103
|
+
self.horizon.submit_transaction(tx)
|
|
104
|
+
|
|
105
|
+
def fund_with_friendbot(self) -> None:
|
|
106
|
+
"""Testnet only: fund the signer's account with 10,000 test XLM."""
|
|
107
|
+
requests.get("https://friendbot.stellar.org",
|
|
108
|
+
params={"addr": self.signer.public_key}).raise_for_status()
|
|
109
|
+
|
|
110
|
+
# -- internals ---------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
def _parse_find_path(self, response: dict, from_: Asset, to: Asset, *,
|
|
113
|
+
amount_in: int | None, amount_out: int | None,
|
|
114
|
+
slippage: float) -> Quote:
|
|
115
|
+
if not response.get("success"):
|
|
116
|
+
raise NoRouteError(f"no route {from_} -> {to}")
|
|
117
|
+
token_in = from_.contract_id(self.passphrase)
|
|
118
|
+
if amount_in is not None:
|
|
119
|
+
out = int(response["amount"])
|
|
120
|
+
return Quote(amount_in, out, int(out * (1 - slippage)), response["pools"],
|
|
121
|
+
True, response["swap_chain_xdr"], token_in, self)
|
|
122
|
+
required_in = int(response["amount"])
|
|
123
|
+
return Quote(required_in, amount_out, int(required_in * (1 + slippage)), response["pools"],
|
|
124
|
+
False, response["swap_chain_xdr"], token_in, self)
|
|
125
|
+
|
|
126
|
+
def _execute(self, q: Quote) -> Receipt:
|
|
127
|
+
fn = "swap_chained" if q.is_exact_input else "swap_chained_strict_receive"
|
|
128
|
+
amount = q.amount_in if q.is_exact_input else q.amount_out
|
|
129
|
+
try:
|
|
130
|
+
tx = self.rpc.prepare_transaction(
|
|
131
|
+
TransactionBuilder(self.horizon.load_account(self.signer.public_key),
|
|
132
|
+
network_passphrase=self.passphrase, base_fee=10000)
|
|
133
|
+
.append_invoke_contract_function_op(
|
|
134
|
+
contract_id=self.router, function_name=fn,
|
|
135
|
+
parameters=[
|
|
136
|
+
scval.to_address(self.signer.public_key),
|
|
137
|
+
SCVal.from_xdr(q._xdr),
|
|
138
|
+
scval.to_address(q._token_in),
|
|
139
|
+
scval.to_uint128(amount),
|
|
140
|
+
scval.to_uint128(q.guard),
|
|
141
|
+
])
|
|
142
|
+
.set_timeout(300).build())
|
|
143
|
+
except Exception as e: # surface the two guard errors as a typed, retryable error
|
|
144
|
+
if "#2006" in str(e) or "#2020" in str(e):
|
|
145
|
+
raise SlippageError("price moved past your guard — re-quote and retry") from e
|
|
146
|
+
raise
|
|
147
|
+
tx.sign(self.signer)
|
|
148
|
+
resp = self.horizon.submit_transaction(tx)
|
|
149
|
+
meta = TransactionMeta.from_xdr(self.rpc.get_transaction(resp["id"]).result_meta_xdr)
|
|
150
|
+
soroban_meta = meta.v4.soroban_meta if meta.v == 4 else meta.v3.soroban_meta
|
|
151
|
+
result = scval.from_uint128(soroban_meta.return_value)
|
|
152
|
+
if q.is_exact_input:
|
|
153
|
+
return Receipt(resp["id"], q.amount_in, result)
|
|
154
|
+
return Receipt(resp["id"], result, q.amount_out)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class AquariusError(Exception):
|
|
2
|
+
"""Base class for every error this SDK raises."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class NoRouteError(AquariusError):
|
|
6
|
+
"""The find-path API found no route for the requested pair and amount."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SlippageError(AquariusError):
|
|
10
|
+
"""The pool moved past your guard (contract errors 2006 / 2020). Re-quote and retry."""
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aquarius-sdk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python SDK for the Aquarius protocol on Stellar
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://aqua.network
|
|
7
|
+
Project-URL: Documentation, https://docs.aqua.network/developers/quickstart
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: stellar-sdk>=13
|
|
12
|
+
Requires-Dist: requests>=2.28
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# aquarius-sdk
|
|
18
|
+
|
|
19
|
+
The Python SDK for [Aquarius](https://aqua.network) — swaps, liquidity, and rewards on Stellar.
|
|
20
|
+
|
|
21
|
+
**Status: interface preview (0.0.x).** The swap surface works end-to-end — quote → execute, exact-input and exact-output, on mainnet and testnet. Pools, liquidity, and rewards are under development, and the API may change before 0.1. Follow the [developer documentation](https://docs.aqua.network/developers/quickstart) for the stable integration path in the meantime.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from stellar_sdk import Keypair
|
|
25
|
+
from aquarius import AquariusClient, Asset, XLM
|
|
26
|
+
|
|
27
|
+
AQUA = Asset.classic("AQUA", "GAHPYWLK6YRN7CVYZOO4H3VDRZ7PVF5UJGLZCSPAEIKJE2XSWF5LAGER")
|
|
28
|
+
|
|
29
|
+
aqua = AquariusClient(network="testnet", signer=Keypair.random())
|
|
30
|
+
aqua.fund_with_friendbot() # testnet only: 10,000 test XLM
|
|
31
|
+
aqua.ensure_trustline(AQUA)
|
|
32
|
+
|
|
33
|
+
quote = aqua.quote(XLM, AQUA, amount_in=10_0000000) # amount_out= for exact output
|
|
34
|
+
print(f"10 XLM -> {quote.amount_out / 1e7:,.2f} AQUA via {len(quote.route)} pool(s)")
|
|
35
|
+
|
|
36
|
+
receipt = quote.execute()
|
|
37
|
+
print(f"received {receipt.amount_out / 1e7:,.2f} AQUA in tx {receipt.tx_hash}")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- Reads need no signer; writes take a `Keypair`. Raw secrets are never stored.
|
|
41
|
+
- Slippage guards raise a typed `SlippageError` ("re-quote and retry"); missing routes raise `NoRouteError`.
|
|
42
|
+
- Amounts are integer stroops (1 token = 10^7 stroops).
|
|
43
|
+
|
|
44
|
+
Questions and integration help: [Discord](https://discord.gg/sgzFscHp4C).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
aquarius/__init__.py
|
|
5
|
+
aquarius/assets.py
|
|
6
|
+
aquarius/client.py
|
|
7
|
+
aquarius/errors.py
|
|
8
|
+
aquarius_sdk.egg-info/PKG-INFO
|
|
9
|
+
aquarius_sdk.egg-info/SOURCES.txt
|
|
10
|
+
aquarius_sdk.egg-info/dependency_links.txt
|
|
11
|
+
aquarius_sdk.egg-info/requires.txt
|
|
12
|
+
aquarius_sdk.egg-info/top_level.txt
|
|
13
|
+
tests/test_interface.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aquarius
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "aquarius-sdk"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Python SDK for the Aquarius protocol on Stellar"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
dependencies = [
|
|
10
|
+
"stellar-sdk>=13",
|
|
11
|
+
"requests>=2.28",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Homepage = "https://aqua.network"
|
|
16
|
+
Documentation = "https://docs.aqua.network/developers/quickstart"
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
dev = ["pytest>=8"]
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["setuptools>=68"]
|
|
23
|
+
build-backend = "setuptools.build_meta"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
include = ["aquarius*"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""No-network tests: public surface, argument validation, golden-fixture parsing."""
|
|
2
|
+
import json
|
|
3
|
+
import pathlib
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
import aquarius
|
|
8
|
+
from aquarius import XLM, AquariusClient, Asset, NoRouteError
|
|
9
|
+
|
|
10
|
+
TESTDATA = pathlib.Path(__file__).resolve().parents[2] / "testdata"
|
|
11
|
+
|
|
12
|
+
TESTNET_AQUA = Asset.classic("AQUA", "GAHPYWLK6YRN7CVYZOO4H3VDRZ7PVF5UJGLZCSPAEIKJE2XSWF5LAGER")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_public_surface():
|
|
16
|
+
for name in aquarius.__all__:
|
|
17
|
+
assert getattr(aquarius, name)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_asset_forms_resolve_to_contract_ids():
|
|
21
|
+
passphrase = "Test SDF Network ; September 2015"
|
|
22
|
+
assert XLM.contract_id(passphrase) == "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC"
|
|
23
|
+
assert TESTNET_AQUA.contract_id(passphrase) == "CDNVQW44C3HALYNVQ4SOBXY5EWYTGVYXX6JPESOLQDABJI5FC5LTRRUE"
|
|
24
|
+
assert Asset.contract("CABC").contract_id(passphrase) == "CABC"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_quote_requires_exactly_one_amount():
|
|
28
|
+
aqua = AquariusClient(network="testnet")
|
|
29
|
+
with pytest.raises(ValueError):
|
|
30
|
+
aqua.quote(XLM, TESTNET_AQUA)
|
|
31
|
+
with pytest.raises(ValueError):
|
|
32
|
+
aqua.quote(XLM, TESTNET_AQUA, amount_in=1, amount_out=1)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_parse_find_path_golden_fixture():
|
|
36
|
+
aqua = AquariusClient(network="testnet")
|
|
37
|
+
response = json.loads((TESTDATA / "find_path_testnet_xlm_aqua.json").read_text())
|
|
38
|
+
quote = aqua._parse_find_path(response, XLM, TESTNET_AQUA,
|
|
39
|
+
amount_in=100_000_000, amount_out=None, slippage=0.01)
|
|
40
|
+
assert quote.is_exact_input
|
|
41
|
+
assert quote.amount_out == int(response["amount"])
|
|
42
|
+
assert quote.guard == int(quote.amount_out * 0.99)
|
|
43
|
+
assert quote.route == response["pools"]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_no_route_raises_typed_error():
|
|
47
|
+
aqua = AquariusClient(network="testnet")
|
|
48
|
+
with pytest.raises(NoRouteError):
|
|
49
|
+
aqua._parse_find_path({"success": False}, XLM, TESTNET_AQUA,
|
|
50
|
+
amount_in=1, amount_out=None, slippage=0.01)
|