armachain 0.3.0__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.
- armachain-0.3.0/LICENSE +21 -0
- armachain-0.3.0/MANIFEST.in +5 -0
- armachain-0.3.0/PKG-INFO +340 -0
- armachain-0.3.0/README.md +306 -0
- armachain-0.3.0/armachain/__init__.py +173 -0
- armachain-0.3.0/armachain/account.py +40 -0
- armachain-0.3.0/armachain/account_actions.py +186 -0
- armachain-0.3.0/armachain/bridge.py +36 -0
- armachain-0.3.0/armachain/client.py +96 -0
- armachain-0.3.0/armachain/dex.py +966 -0
- armachain-0.3.0/armachain/explorer.py +143 -0
- armachain-0.3.0/armachain/hedge.py +172 -0
- armachain-0.3.0/armachain/http.py +166 -0
- armachain-0.3.0/armachain/leverage_bound_signing.py +116 -0
- armachain-0.3.0/armachain/master_trade.py +199 -0
- armachain-0.3.0/armachain/money.py +135 -0
- armachain-0.3.0/armachain/network_binding.py +155 -0
- armachain-0.3.0/armachain/nonce_guard.py +242 -0
- armachain-0.3.0/armachain/oracle.py +39 -0
- armachain-0.3.0/armachain/order_outcome.py +173 -0
- armachain-0.3.0/armachain/purchase34.py +94 -0
- armachain-0.3.0/armachain/py.typed +0 -0
- armachain-0.3.0/armachain/rpc.py +216 -0
- armachain-0.3.0/armachain/signed_read.py +80 -0
- armachain-0.3.0/armachain/signing.py +1819 -0
- armachain-0.3.0/armachain/spot.py +100 -0
- armachain-0.3.0/armachain/spot_typed.py +204 -0
- armachain-0.3.0/armachain/staking.py +138 -0
- armachain-0.3.0/armachain/staking_signing.py +506 -0
- armachain-0.3.0/armachain/timestamped_signing.py +344 -0
- armachain-0.3.0/armachain/tokenomics.py +42 -0
- armachain-0.3.0/armachain/transfer_receipts.py +185 -0
- armachain-0.3.0/armachain/types.py +401 -0
- armachain-0.3.0/armachain/unit_bound_signing.py +198 -0
- armachain-0.3.0/armachain/withdrawal_signing.py +66 -0
- armachain-0.3.0/armachain.egg-info/PKG-INFO +340 -0
- armachain-0.3.0/armachain.egg-info/SOURCES.txt +41 -0
- armachain-0.3.0/armachain.egg-info/dependency_links.txt +1 -0
- armachain-0.3.0/armachain.egg-info/requires.txt +13 -0
- armachain-0.3.0/armachain.egg-info/top_level.txt +1 -0
- armachain-0.3.0/pyproject.toml +62 -0
- armachain-0.3.0/setup.cfg +4 -0
- armachain-0.3.0/setup.py +5 -0
armachain-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ArmaChain Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
armachain-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: armachain
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Official Python SDK for ArmaChain -- independent L1 blockchain with integrated CEX-grade DEX
|
|
5
|
+
Author: ArmaChain Team
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Documentation, https://docs.armascan.io
|
|
8
|
+
Keywords: armachain,blockchain,dex,sdk,web3
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: httpx>=0.25
|
|
23
|
+
Provides-Extra: signing
|
|
24
|
+
Requires-Dist: pyblake3>=0.3; extra == "signing"
|
|
25
|
+
Requires-Dist: pycryptodome>=3.19; extra == "signing"
|
|
26
|
+
Requires-Dist: eth_keys>=0.4; extra == "signing"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
30
|
+
Requires-Dist: pyblake3>=0.3; extra == "dev"
|
|
31
|
+
Requires-Dist: pycryptodome>=3.19; extra == "dev"
|
|
32
|
+
Requires-Dist: eth_keys>=0.4; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# armachain
|
|
36
|
+
|
|
37
|
+
Official Python SDK for ArmaChain -- independent L1 blockchain with integrated CEX-grade DEX.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install armachain
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For development:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install -e ".[dev]"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import asyncio
|
|
55
|
+
from armachain import ArmaChainClient
|
|
56
|
+
|
|
57
|
+
async def main():
|
|
58
|
+
client = ArmaChainClient(
|
|
59
|
+
api_url="https://api.armascan.io", # REST API
|
|
60
|
+
rpc_url="https://rpc.armascan.io", # JSON-RPC
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# Check block height
|
|
64
|
+
height = await client.rpc.get_block_number()
|
|
65
|
+
print(f"Block height: {height}")
|
|
66
|
+
|
|
67
|
+
# Get DEX orderbook
|
|
68
|
+
book = await client.dex.get_orderbook(0)
|
|
69
|
+
print(f"Bids: {len(book['bids'])}, Asks: {len(book['asks'])}")
|
|
70
|
+
|
|
71
|
+
# Get oracle prices
|
|
72
|
+
prices = await client.oracle.get_prices()
|
|
73
|
+
for p in prices:
|
|
74
|
+
print(f"{p['symbol']}: {p['mark_price']}")
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Modules
|
|
80
|
+
|
|
81
|
+
| Module | Methods | Description |
|
|
82
|
+
|--------|---------|-------------|
|
|
83
|
+
| `client.rpc` | 22 | JSON-RPC, health, network, balances, transactions |
|
|
84
|
+
| `client.dex` | 30 | Perpetual futures, orders, positions, funding, analytics |
|
|
85
|
+
| `client.spot` | 6 | Spot trading, immediate-delivery markets |
|
|
86
|
+
| `client.oracle` | 4 | Mark prices, oracle health, quorum |
|
|
87
|
+
| `client.bridge` | 2 | Cross-chain transfer status, bridge status |
|
|
88
|
+
| `client.tokenomics` | 4 | Fees, burns, revenue share, vesting |
|
|
89
|
+
| `client.staking` | 10 | Validators, delegation, governance, proposals |
|
|
90
|
+
| `client.explorer` | 12 | Batches, transactions, addresses, contracts |
|
|
91
|
+
|
|
92
|
+
**Total: ~104 methods** across 9 modules.
|
|
93
|
+
|
|
94
|
+
## Breaking changes in 0.3.0
|
|
95
|
+
|
|
96
|
+
Removed: the methods the public API does not serve. A call to any of them could only be refused, so they no longer exist
|
|
97
|
+
(an `AttributeError` instead of a runtime refusal): `initiate_transfer`, `get_internal_transactions`, `submit_price`,
|
|
98
|
+
`get_peers`, `get_trader_fees`, `get_loyalty_tier`, `claim_revenue_share`, `set_auto_compound`.
|
|
99
|
+
|
|
100
|
+
Changed, same meaning on a public route: `is_ready` and `is_alive` read `/health/ready` and `/health/live` and return
|
|
101
|
+
true only for status `ready` / `alive`; `get_transaction_count` uses JSON-RPC `eth_getTransactionCount`.
|
|
102
|
+
|
|
103
|
+
## Examples
|
|
104
|
+
|
|
105
|
+
### DEX Trading
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
# Get all DEX markets
|
|
109
|
+
markets = await client.dex.get_markets()
|
|
110
|
+
|
|
111
|
+
# Get BTC/USDC orderbook (market_id=0)
|
|
112
|
+
book = await client.dex.get_orderbook(0)
|
|
113
|
+
|
|
114
|
+
# List open positions
|
|
115
|
+
positions = await client.dex.get_positions("0x...")
|
|
116
|
+
|
|
117
|
+
# Get OHLCV candles
|
|
118
|
+
candles = await client.dex.get_candles(market_id=0, interval="1h", limit=50)
|
|
119
|
+
|
|
120
|
+
# Submit an order
|
|
121
|
+
result = await client.dex.submit_order(
|
|
122
|
+
payload={"market_id": 0, "side": "buy", "price": 65000, "size": 1.0, "order_type": "Limit"},
|
|
123
|
+
signature="0x...",
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Spot Trading
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# List spot markets
|
|
131
|
+
markets = await client.spot.get_markets()
|
|
132
|
+
|
|
133
|
+
# Get spot orderbook
|
|
134
|
+
book = await client.spot.get_orderbook(5)
|
|
135
|
+
|
|
136
|
+
# Submit a limit buy
|
|
137
|
+
result = await client.spot.submit_order(
|
|
138
|
+
address="0x...",
|
|
139
|
+
market_id=5,
|
|
140
|
+
side="Buy",
|
|
141
|
+
price=65000,
|
|
142
|
+
size=100,
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### RPC & Network
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
# Chain state
|
|
150
|
+
height = await client.rpc.get_block_number()
|
|
151
|
+
chain_id = await client.rpc.get_chain_id()
|
|
152
|
+
balance = await client.rpc.get_balance("0x...")
|
|
153
|
+
|
|
154
|
+
# JSON-RPC calls
|
|
155
|
+
gas = await client.rpc.gas_price()
|
|
156
|
+
receipt = await client.rpc.get_transaction_receipt("0x...")
|
|
157
|
+
|
|
158
|
+
# Broadcast signed tx
|
|
159
|
+
tx_hash = await client.rpc.send_raw_transaction("0xsigned...")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Tokenomics
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# Fee schedule (9 tiers: Base to VIP3)
|
|
166
|
+
tiers = await client.tokenomics.get_fee_schedule()
|
|
167
|
+
|
|
168
|
+
# Burn statistics
|
|
169
|
+
burns = await client.tokenomics.get_burn_stats()
|
|
170
|
+
|
|
171
|
+
# Revenue share (Validators 35% | Stakers 30% | Burn 25% | Treasury 10%)
|
|
172
|
+
revenue = await client.tokenomics.get_revenue_share()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Staking & Governance
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
# List validators
|
|
179
|
+
validators = await client.staking.get_validators()
|
|
180
|
+
|
|
181
|
+
# Governance proposals
|
|
182
|
+
proposals = await client.staking.get_proposals()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Explorer
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# Get batch by height
|
|
189
|
+
batch = await client.explorer.get_batch(12345)
|
|
190
|
+
|
|
191
|
+
# Get transaction
|
|
192
|
+
tx = await client.explorer.get_transaction("0x...")
|
|
193
|
+
|
|
194
|
+
# Address info
|
|
195
|
+
balance = await client.explorer.get_address_balance("0x...")
|
|
196
|
+
txs = await client.explorer.get_address_transactions("0x...")
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Configuration
|
|
200
|
+
|
|
201
|
+
| Parameter | Default | Description |
|
|
202
|
+
|-----------|---------|-------------|
|
|
203
|
+
| `api_url` | `https://api.armascan.io` | REST API base URL |
|
|
204
|
+
| `rpc_url` | `https://rpc.armascan.io` | JSON-RPC endpoint URL |
|
|
205
|
+
| `timeout` | `10.0` | Request timeout in seconds |
|
|
206
|
+
|
|
207
|
+
## Error Handling
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from armachain import ArmaChainError
|
|
211
|
+
|
|
212
|
+
try:
|
|
213
|
+
balance = await client.rpc.get_balance("0xinvalid")
|
|
214
|
+
except ArmaChainError as e:
|
|
215
|
+
print(f"Error [{e.code}]: {e.message}")
|
|
216
|
+
if e.status_code:
|
|
217
|
+
print(f"HTTP status: {e.status_code}")
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Testing
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pip install -e ".[dev]"
|
|
224
|
+
pytest
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Chain Info
|
|
228
|
+
|
|
229
|
+
- **Chain ID**: 2028
|
|
230
|
+
- **Total Supply**: 1,000,000,000 ARMA
|
|
231
|
+
- **Order Types**: Market, Limit, ReduceOnly, PostOnly, plus the advanced orders TWAP, Iceberg, OCO and the Mark-triggered conditional order (`POST /api/dex/advanced-orders/v2/conditional`). StopLimit, StopMarket, TrailingStop, TakeLimit and TakeMarket trigger on the last trade price and cannot be placed on any market: they are retired on perpetual markets (the node refuses them with 400), and spot markets take resting GTC limit orders only. For a stop-loss or take-profit on a perpetual market, use the Mark-triggered conditional order.
|
|
232
|
+
- **Fee Tiers**: 9 (Base 8/4 bps to VIP3 2/-3 bps)
|
|
233
|
+
|
|
234
|
+
### Native ML-DSA library
|
|
235
|
+
|
|
236
|
+
Offline ML-DSA-65 signing loads `libarmadilithium3.dylib` / `.so` from the package directory, or from the path in
|
|
237
|
+
`ARMA_DILITHIUM3_LIB`. Without it, key generation and signing raise `ImportError` and nothing is signed.
|
|
238
|
+
|
|
239
|
+
CI and release gates must set `ARMA_DILITHIUM3_REQUIRED=1` and `ARMA_DILITHIUM3_LIB`: then a missing library fails the
|
|
240
|
+
signature tests. Unset (or `0`), they skip and the session ends with a `native-skipped` count.
|
|
241
|
+
|
|
242
|
+
### Signed atomic ARMA money bodies (version 3)
|
|
243
|
+
|
|
244
|
+
`dex.withdraw` requires explicit keyword arguments `chain_id`, `nonce`,
|
|
245
|
+
`pq_signature` and `pq_pubkey`. Old unsigned calls fail locally before HTTP.
|
|
246
|
+
The amount is **atomic ARMA units**, supplied as a positive Python integer or
|
|
247
|
+
ASCII decimal string (up to u128); floats and booleans are rejected. Only ARMA
|
|
248
|
+
is supported. There is no automatic nonce allocation, signing, key acquisition,
|
|
249
|
+
key storage or retry in `DexModule`.
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from armachain import build_signed_money
|
|
253
|
+
|
|
254
|
+
# Read accepted time with await client.dex.get_committed_clock().
|
|
255
|
+
# Get an advisory quote with client.dex.get_opening_quote(submitter, gross).
|
|
256
|
+
# Choose max_open_fee/expires_at_ms explicitly from the quote and your policy.
|
|
257
|
+
# Every signature binds the 32-byte network id N (GET /health dex_bridge_network_id).
|
|
258
|
+
# Missing, malformed or all-zero raises NetworkBindingError; there is no default and no v1 form.
|
|
259
|
+
network_id = await client.bridge.network_id() # or pin: network_id(pin="0x...")
|
|
260
|
+
body = build_signed_money(
|
|
261
|
+
"deposit", submitter=submitter, chain_id=2028, nonce=nonce, asset=0,
|
|
262
|
+
amount=gross_atomic, source_ref=source_ref, timestamp_ms=chain_time_ms,
|
|
263
|
+
max_open_fee=max_open_fee, expires_at_ms=expires_at_ms,
|
|
264
|
+
public_key=public_key, signer=offline_signer, network_id=network_id,
|
|
265
|
+
)
|
|
266
|
+
await client.dex.deposit(network_id=network_id, **body)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Fresh money requests contain `submitter` and no claimed `trader_id` or `address`.
|
|
270
|
+
WithdrawV3 additionally signs `vault_address=None` for self or the owned Sub address.
|
|
271
|
+
Legacy Fund/Deposit/Withdraw-v2 forms are retired and refused locally.
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
Use `secret_key=caller_owned_bytes` instead of `signer` only when the native
|
|
275
|
+
Dilithium library is available. Keys are neither acquired nor stored by the SDK.
|
|
276
|
+
The signing key must derive `submitter`; chain ID remains explicitly 2028.
|
|
277
|
+
`source_ref` is an explicit 32-byte caller reference, never a registry identity.
|
|
278
|
+
|
|
279
|
+
Responses describe admission, not committed balance movement. A transport failure
|
|
280
|
+
has an unknown outcome; reconcile the exact attempt before allocating another
|
|
281
|
+
nonce. The existing lost-transaction nonce guard remains active for final bodies.
|
|
282
|
+
|
|
283
|
+
Faucet requests are address requests that the server signs; send no amount. One claim gives 100 ARMA on L1 and 1,000 mock USDC on the exchange.
|
|
284
|
+
|
|
285
|
+
### Keyless Sub creation and DEX transfers
|
|
286
|
+
|
|
287
|
+
`build_signed_action("create_sub_account", ...)` encodes tag35 and
|
|
288
|
+
`build_signed_action("dex_transfer", ...)` encodes tag36. Both require all final
|
|
289
|
+
fields explicitly, use `signature_scheme=0` for ML-DSA-65 or `2` for EIP712,
|
|
290
|
+
and support caller-owned ephemeral key bytes or an offline digest signer.
|
|
291
|
+
For EIP712 supply the independently trusted consensus domain salt; use
|
|
292
|
+
`account_action_typed_data` to present the exact typed fields in a wallet.
|
|
293
|
+
|
|
294
|
+
`derive_sub_address(trusted_network, master, index)` hashes the approved domain,
|
|
295
|
+
N, full master address, and BE32 index. Its Borsh index remains LE32. Read N only
|
|
296
|
+
from a caller-trusted configured node's `get_subaccount_network_id()` result
|
|
297
|
+
(`/health/ready.dex_bridge_network_id`), or independently trusted local identity.
|
|
298
|
+
Do not substitute a genesis hash, anchor, chain ID or signing-session salt.
|
|
299
|
+
|
|
300
|
+
Submit the built bodies with `dex.create_sub_account(**body)` and
|
|
301
|
+
`dex.transfer(**body)`. `get_sub_accounts`, `get_sub_account` and
|
|
302
|
+
`get_account_action_quote` require an `authorize` callback producing ArmaSignedRead
|
|
303
|
+
for the exact target. No master override is sent. Quotes remain advisory;
|
|
304
|
+
the SDK validates the node's eligible/blocked capacity and reason without choosing a quota
|
|
305
|
+
equation. A transfer's signed source vault is distinct from its signer/nonce owner.
|
|
306
|
+
|
|
307
|
+
### Durable receipt reconciliation
|
|
308
|
+
|
|
309
|
+
Freeze a `TransferExpectation` with the original transaction/signing hashes,
|
|
310
|
+
master nonce, kind and expected monetary source/destination. Use
|
|
311
|
+
`dex.get_transfer_status(expected)` for the original ID, or
|
|
312
|
+
`dex.get_transfer_attempts(expected)` for the master's nonce slot. These perform
|
|
313
|
+
GET requests only. Repeating the read never signs or automatically posts anything.
|
|
314
|
+
|
|
315
|
+
A returned per-attempt `outcome.final` releases the corresponding lost nonce.
|
|
316
|
+
Refusal names alone do not determine this: consumed Insufficient/NotYetValid can
|
|
317
|
+
be final, an unused opening refusal can remain nonfinal, and historical v2 nonce
|
|
318
|
+
facts remain `None`. Every inclusion retains its own `trader_id`; an applied vault
|
|
319
|
+
withdrawal and a later duplicate rendered against master can coexist for one ID.
|
|
320
|
+
The final monetary `source_account` and `beneficiary` are distinct from signer.
|
|
321
|
+
|
|
322
|
+
`dex.get_transfer_history(authorize=...)` reads the existing private history
|
|
323
|
+
endpoint with an exact ArmaSignedRead target. New create/transfer kinds and nullable
|
|
324
|
+
legacy effects are preserved. Every signature (ML-DSA and EIP-712) binds the network id N:
|
|
325
|
+
the EIP-712 domain salt IS N, and `create_sub_account` / `transfer` take `network_id=N`.
|
|
326
|
+
Sub details support explicit `positions_cursor`/`positions_limit` and retain the
|
|
327
|
+
returned `positions_next_cursor` instead of silently dropping a later page.
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
### Master trading on a keyless Sub
|
|
331
|
+
|
|
332
|
+
Use the master trading envelope for an existing own Sub. The actual master signs and allocates its own nonce; `vaultAddress` / `vault_address` selects the economic account and is signed together with the complete original action bytes. The server independently checks current ownership, nonce and expiry. A trading agent has no authority through this API.
|
|
333
|
+
|
|
334
|
+
The codec supports place4, cancel5, amend6, advanced create7/cancel8/amend9, cancel-action18, TP/SL19, leverage20 and amend-v2 22. Use the existing canonical signable body with `unsignedMasterTradeAction` / `unsigned_master_trade_action`, or an existing full tagged body with the master builder: only the decoded signature/key containers are cleared. All semantic fields and the original inner scheme stay unchanged. Cancel-action18 uses its existing EIP712 scheme1; leverage20/amend22 use2. Place version2 is invalid. Current cancel-action/leverage bodies are version3 signed timestamps; old height/deadline encodings must not be relabeled.
|
|
335
|
+
|
|
336
|
+
TypeScript exports `buildMasterTrade`, `buildUnsignedMasterPlaceOrder`, `signMasterTrade`, `encodeMasterTrade`, `decodeMasterTrade` and `DexModule.submitMasterTrade`. Large values are bigint or canonical decimal strings. Python exports `MasterTrade`, `build_master_trade`, `sign_master_trade`, `encode_master_trade`, `decode_master_trade` and `DexModule.submit_master_trade`. Both Rust SDKs export `MasterTradeTx` and `submit_master_trade`; the maintained Rust SDK also provides existing local-key MLDSA/ECDSA signing adapters. Pure encoders never invent an account key, nonce, timestamp, source reference or leverage value.
|
|
337
|
+
|
|
338
|
+
Submit the full original tagged bytes to `POST /api/dex/master-trade` as the sole JSON field `tx`. A response with `accepted:true,pending:true` confirms the action was received, not that it was applied. Retry the same signed bytes while following the original outer transaction hash. EIP712 uses the network id N (GET /health `dex_bridge_network_id`) as its domain salt; the ML-DSA scheme signs the domain hash with the same N (`sign_master_trade(..., network_id=N)`).
|
|
339
|
+
|
|
340
|
+
Private reads append canonical lowercase `vault_address=0x<40 hex digits>` before authorizing the exact target. The signer/session remains the master; the server checks current own-Sub read authority. TypeScript `selectedAccountReadQuery`, Python `selected_account_read_query`, and Rust selected-target/query helpers preserve this boundary. Outcome `economic_account` and `wire` may be null for legacy Unknown records; never infer a selected Sub from `address`. `signing_nonce` is a lossless decimal string. `master_verified_refusal` and `master_consumed_refusal` remain distinct; terminal state follows the response's explicit finality and nonce-consumption fields.
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# armachain
|
|
2
|
+
|
|
3
|
+
Official Python SDK for ArmaChain -- independent L1 blockchain with integrated CEX-grade DEX.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install armachain
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For development:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -e ".[dev]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import asyncio
|
|
21
|
+
from armachain import ArmaChainClient
|
|
22
|
+
|
|
23
|
+
async def main():
|
|
24
|
+
client = ArmaChainClient(
|
|
25
|
+
api_url="https://api.armascan.io", # REST API
|
|
26
|
+
rpc_url="https://rpc.armascan.io", # JSON-RPC
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Check block height
|
|
30
|
+
height = await client.rpc.get_block_number()
|
|
31
|
+
print(f"Block height: {height}")
|
|
32
|
+
|
|
33
|
+
# Get DEX orderbook
|
|
34
|
+
book = await client.dex.get_orderbook(0)
|
|
35
|
+
print(f"Bids: {len(book['bids'])}, Asks: {len(book['asks'])}")
|
|
36
|
+
|
|
37
|
+
# Get oracle prices
|
|
38
|
+
prices = await client.oracle.get_prices()
|
|
39
|
+
for p in prices:
|
|
40
|
+
print(f"{p['symbol']}: {p['mark_price']}")
|
|
41
|
+
|
|
42
|
+
asyncio.run(main())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Modules
|
|
46
|
+
|
|
47
|
+
| Module | Methods | Description |
|
|
48
|
+
|--------|---------|-------------|
|
|
49
|
+
| `client.rpc` | 22 | JSON-RPC, health, network, balances, transactions |
|
|
50
|
+
| `client.dex` | 30 | Perpetual futures, orders, positions, funding, analytics |
|
|
51
|
+
| `client.spot` | 6 | Spot trading, immediate-delivery markets |
|
|
52
|
+
| `client.oracle` | 4 | Mark prices, oracle health, quorum |
|
|
53
|
+
| `client.bridge` | 2 | Cross-chain transfer status, bridge status |
|
|
54
|
+
| `client.tokenomics` | 4 | Fees, burns, revenue share, vesting |
|
|
55
|
+
| `client.staking` | 10 | Validators, delegation, governance, proposals |
|
|
56
|
+
| `client.explorer` | 12 | Batches, transactions, addresses, contracts |
|
|
57
|
+
|
|
58
|
+
**Total: ~104 methods** across 9 modules.
|
|
59
|
+
|
|
60
|
+
## Breaking changes in 0.3.0
|
|
61
|
+
|
|
62
|
+
Removed: the methods the public API does not serve. A call to any of them could only be refused, so they no longer exist
|
|
63
|
+
(an `AttributeError` instead of a runtime refusal): `initiate_transfer`, `get_internal_transactions`, `submit_price`,
|
|
64
|
+
`get_peers`, `get_trader_fees`, `get_loyalty_tier`, `claim_revenue_share`, `set_auto_compound`.
|
|
65
|
+
|
|
66
|
+
Changed, same meaning on a public route: `is_ready` and `is_alive` read `/health/ready` and `/health/live` and return
|
|
67
|
+
true only for status `ready` / `alive`; `get_transaction_count` uses JSON-RPC `eth_getTransactionCount`.
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
### DEX Trading
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
# Get all DEX markets
|
|
75
|
+
markets = await client.dex.get_markets()
|
|
76
|
+
|
|
77
|
+
# Get BTC/USDC orderbook (market_id=0)
|
|
78
|
+
book = await client.dex.get_orderbook(0)
|
|
79
|
+
|
|
80
|
+
# List open positions
|
|
81
|
+
positions = await client.dex.get_positions("0x...")
|
|
82
|
+
|
|
83
|
+
# Get OHLCV candles
|
|
84
|
+
candles = await client.dex.get_candles(market_id=0, interval="1h", limit=50)
|
|
85
|
+
|
|
86
|
+
# Submit an order
|
|
87
|
+
result = await client.dex.submit_order(
|
|
88
|
+
payload={"market_id": 0, "side": "buy", "price": 65000, "size": 1.0, "order_type": "Limit"},
|
|
89
|
+
signature="0x...",
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Spot Trading
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
# List spot markets
|
|
97
|
+
markets = await client.spot.get_markets()
|
|
98
|
+
|
|
99
|
+
# Get spot orderbook
|
|
100
|
+
book = await client.spot.get_orderbook(5)
|
|
101
|
+
|
|
102
|
+
# Submit a limit buy
|
|
103
|
+
result = await client.spot.submit_order(
|
|
104
|
+
address="0x...",
|
|
105
|
+
market_id=5,
|
|
106
|
+
side="Buy",
|
|
107
|
+
price=65000,
|
|
108
|
+
size=100,
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### RPC & Network
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
# Chain state
|
|
116
|
+
height = await client.rpc.get_block_number()
|
|
117
|
+
chain_id = await client.rpc.get_chain_id()
|
|
118
|
+
balance = await client.rpc.get_balance("0x...")
|
|
119
|
+
|
|
120
|
+
# JSON-RPC calls
|
|
121
|
+
gas = await client.rpc.gas_price()
|
|
122
|
+
receipt = await client.rpc.get_transaction_receipt("0x...")
|
|
123
|
+
|
|
124
|
+
# Broadcast signed tx
|
|
125
|
+
tx_hash = await client.rpc.send_raw_transaction("0xsigned...")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Tokenomics
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
# Fee schedule (9 tiers: Base to VIP3)
|
|
132
|
+
tiers = await client.tokenomics.get_fee_schedule()
|
|
133
|
+
|
|
134
|
+
# Burn statistics
|
|
135
|
+
burns = await client.tokenomics.get_burn_stats()
|
|
136
|
+
|
|
137
|
+
# Revenue share (Validators 35% | Stakers 30% | Burn 25% | Treasury 10%)
|
|
138
|
+
revenue = await client.tokenomics.get_revenue_share()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Staking & Governance
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
# List validators
|
|
145
|
+
validators = await client.staking.get_validators()
|
|
146
|
+
|
|
147
|
+
# Governance proposals
|
|
148
|
+
proposals = await client.staking.get_proposals()
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Explorer
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
# Get batch by height
|
|
155
|
+
batch = await client.explorer.get_batch(12345)
|
|
156
|
+
|
|
157
|
+
# Get transaction
|
|
158
|
+
tx = await client.explorer.get_transaction("0x...")
|
|
159
|
+
|
|
160
|
+
# Address info
|
|
161
|
+
balance = await client.explorer.get_address_balance("0x...")
|
|
162
|
+
txs = await client.explorer.get_address_transactions("0x...")
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Configuration
|
|
166
|
+
|
|
167
|
+
| Parameter | Default | Description |
|
|
168
|
+
|-----------|---------|-------------|
|
|
169
|
+
| `api_url` | `https://api.armascan.io` | REST API base URL |
|
|
170
|
+
| `rpc_url` | `https://rpc.armascan.io` | JSON-RPC endpoint URL |
|
|
171
|
+
| `timeout` | `10.0` | Request timeout in seconds |
|
|
172
|
+
|
|
173
|
+
## Error Handling
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from armachain import ArmaChainError
|
|
177
|
+
|
|
178
|
+
try:
|
|
179
|
+
balance = await client.rpc.get_balance("0xinvalid")
|
|
180
|
+
except ArmaChainError as e:
|
|
181
|
+
print(f"Error [{e.code}]: {e.message}")
|
|
182
|
+
if e.status_code:
|
|
183
|
+
print(f"HTTP status: {e.status_code}")
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Testing
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
pip install -e ".[dev]"
|
|
190
|
+
pytest
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Chain Info
|
|
194
|
+
|
|
195
|
+
- **Chain ID**: 2028
|
|
196
|
+
- **Total Supply**: 1,000,000,000 ARMA
|
|
197
|
+
- **Order Types**: Market, Limit, ReduceOnly, PostOnly, plus the advanced orders TWAP, Iceberg, OCO and the Mark-triggered conditional order (`POST /api/dex/advanced-orders/v2/conditional`). StopLimit, StopMarket, TrailingStop, TakeLimit and TakeMarket trigger on the last trade price and cannot be placed on any market: they are retired on perpetual markets (the node refuses them with 400), and spot markets take resting GTC limit orders only. For a stop-loss or take-profit on a perpetual market, use the Mark-triggered conditional order.
|
|
198
|
+
- **Fee Tiers**: 9 (Base 8/4 bps to VIP3 2/-3 bps)
|
|
199
|
+
|
|
200
|
+
### Native ML-DSA library
|
|
201
|
+
|
|
202
|
+
Offline ML-DSA-65 signing loads `libarmadilithium3.dylib` / `.so` from the package directory, or from the path in
|
|
203
|
+
`ARMA_DILITHIUM3_LIB`. Without it, key generation and signing raise `ImportError` and nothing is signed.
|
|
204
|
+
|
|
205
|
+
CI and release gates must set `ARMA_DILITHIUM3_REQUIRED=1` and `ARMA_DILITHIUM3_LIB`: then a missing library fails the
|
|
206
|
+
signature tests. Unset (or `0`), they skip and the session ends with a `native-skipped` count.
|
|
207
|
+
|
|
208
|
+
### Signed atomic ARMA money bodies (version 3)
|
|
209
|
+
|
|
210
|
+
`dex.withdraw` requires explicit keyword arguments `chain_id`, `nonce`,
|
|
211
|
+
`pq_signature` and `pq_pubkey`. Old unsigned calls fail locally before HTTP.
|
|
212
|
+
The amount is **atomic ARMA units**, supplied as a positive Python integer or
|
|
213
|
+
ASCII decimal string (up to u128); floats and booleans are rejected. Only ARMA
|
|
214
|
+
is supported. There is no automatic nonce allocation, signing, key acquisition,
|
|
215
|
+
key storage or retry in `DexModule`.
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from armachain import build_signed_money
|
|
219
|
+
|
|
220
|
+
# Read accepted time with await client.dex.get_committed_clock().
|
|
221
|
+
# Get an advisory quote with client.dex.get_opening_quote(submitter, gross).
|
|
222
|
+
# Choose max_open_fee/expires_at_ms explicitly from the quote and your policy.
|
|
223
|
+
# Every signature binds the 32-byte network id N (GET /health dex_bridge_network_id).
|
|
224
|
+
# Missing, malformed or all-zero raises NetworkBindingError; there is no default and no v1 form.
|
|
225
|
+
network_id = await client.bridge.network_id() # or pin: network_id(pin="0x...")
|
|
226
|
+
body = build_signed_money(
|
|
227
|
+
"deposit", submitter=submitter, chain_id=2028, nonce=nonce, asset=0,
|
|
228
|
+
amount=gross_atomic, source_ref=source_ref, timestamp_ms=chain_time_ms,
|
|
229
|
+
max_open_fee=max_open_fee, expires_at_ms=expires_at_ms,
|
|
230
|
+
public_key=public_key, signer=offline_signer, network_id=network_id,
|
|
231
|
+
)
|
|
232
|
+
await client.dex.deposit(network_id=network_id, **body)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Fresh money requests contain `submitter` and no claimed `trader_id` or `address`.
|
|
236
|
+
WithdrawV3 additionally signs `vault_address=None` for self or the owned Sub address.
|
|
237
|
+
Legacy Fund/Deposit/Withdraw-v2 forms are retired and refused locally.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
Use `secret_key=caller_owned_bytes` instead of `signer` only when the native
|
|
241
|
+
Dilithium library is available. Keys are neither acquired nor stored by the SDK.
|
|
242
|
+
The signing key must derive `submitter`; chain ID remains explicitly 2028.
|
|
243
|
+
`source_ref` is an explicit 32-byte caller reference, never a registry identity.
|
|
244
|
+
|
|
245
|
+
Responses describe admission, not committed balance movement. A transport failure
|
|
246
|
+
has an unknown outcome; reconcile the exact attempt before allocating another
|
|
247
|
+
nonce. The existing lost-transaction nonce guard remains active for final bodies.
|
|
248
|
+
|
|
249
|
+
Faucet requests are address requests that the server signs; send no amount. One claim gives 100 ARMA on L1 and 1,000 mock USDC on the exchange.
|
|
250
|
+
|
|
251
|
+
### Keyless Sub creation and DEX transfers
|
|
252
|
+
|
|
253
|
+
`build_signed_action("create_sub_account", ...)` encodes tag35 and
|
|
254
|
+
`build_signed_action("dex_transfer", ...)` encodes tag36. Both require all final
|
|
255
|
+
fields explicitly, use `signature_scheme=0` for ML-DSA-65 or `2` for EIP712,
|
|
256
|
+
and support caller-owned ephemeral key bytes or an offline digest signer.
|
|
257
|
+
For EIP712 supply the independently trusted consensus domain salt; use
|
|
258
|
+
`account_action_typed_data` to present the exact typed fields in a wallet.
|
|
259
|
+
|
|
260
|
+
`derive_sub_address(trusted_network, master, index)` hashes the approved domain,
|
|
261
|
+
N, full master address, and BE32 index. Its Borsh index remains LE32. Read N only
|
|
262
|
+
from a caller-trusted configured node's `get_subaccount_network_id()` result
|
|
263
|
+
(`/health/ready.dex_bridge_network_id`), or independently trusted local identity.
|
|
264
|
+
Do not substitute a genesis hash, anchor, chain ID or signing-session salt.
|
|
265
|
+
|
|
266
|
+
Submit the built bodies with `dex.create_sub_account(**body)` and
|
|
267
|
+
`dex.transfer(**body)`. `get_sub_accounts`, `get_sub_account` and
|
|
268
|
+
`get_account_action_quote` require an `authorize` callback producing ArmaSignedRead
|
|
269
|
+
for the exact target. No master override is sent. Quotes remain advisory;
|
|
270
|
+
the SDK validates the node's eligible/blocked capacity and reason without choosing a quota
|
|
271
|
+
equation. A transfer's signed source vault is distinct from its signer/nonce owner.
|
|
272
|
+
|
|
273
|
+
### Durable receipt reconciliation
|
|
274
|
+
|
|
275
|
+
Freeze a `TransferExpectation` with the original transaction/signing hashes,
|
|
276
|
+
master nonce, kind and expected monetary source/destination. Use
|
|
277
|
+
`dex.get_transfer_status(expected)` for the original ID, or
|
|
278
|
+
`dex.get_transfer_attempts(expected)` for the master's nonce slot. These perform
|
|
279
|
+
GET requests only. Repeating the read never signs or automatically posts anything.
|
|
280
|
+
|
|
281
|
+
A returned per-attempt `outcome.final` releases the corresponding lost nonce.
|
|
282
|
+
Refusal names alone do not determine this: consumed Insufficient/NotYetValid can
|
|
283
|
+
be final, an unused opening refusal can remain nonfinal, and historical v2 nonce
|
|
284
|
+
facts remain `None`. Every inclusion retains its own `trader_id`; an applied vault
|
|
285
|
+
withdrawal and a later duplicate rendered against master can coexist for one ID.
|
|
286
|
+
The final monetary `source_account` and `beneficiary` are distinct from signer.
|
|
287
|
+
|
|
288
|
+
`dex.get_transfer_history(authorize=...)` reads the existing private history
|
|
289
|
+
endpoint with an exact ArmaSignedRead target. New create/transfer kinds and nullable
|
|
290
|
+
legacy effects are preserved. Every signature (ML-DSA and EIP-712) binds the network id N:
|
|
291
|
+
the EIP-712 domain salt IS N, and `create_sub_account` / `transfer` take `network_id=N`.
|
|
292
|
+
Sub details support explicit `positions_cursor`/`positions_limit` and retain the
|
|
293
|
+
returned `positions_next_cursor` instead of silently dropping a later page.
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
### Master trading on a keyless Sub
|
|
297
|
+
|
|
298
|
+
Use the master trading envelope for an existing own Sub. The actual master signs and allocates its own nonce; `vaultAddress` / `vault_address` selects the economic account and is signed together with the complete original action bytes. The server independently checks current ownership, nonce and expiry. A trading agent has no authority through this API.
|
|
299
|
+
|
|
300
|
+
The codec supports place4, cancel5, amend6, advanced create7/cancel8/amend9, cancel-action18, TP/SL19, leverage20 and amend-v2 22. Use the existing canonical signable body with `unsignedMasterTradeAction` / `unsigned_master_trade_action`, or an existing full tagged body with the master builder: only the decoded signature/key containers are cleared. All semantic fields and the original inner scheme stay unchanged. Cancel-action18 uses its existing EIP712 scheme1; leverage20/amend22 use2. Place version2 is invalid. Current cancel-action/leverage bodies are version3 signed timestamps; old height/deadline encodings must not be relabeled.
|
|
301
|
+
|
|
302
|
+
TypeScript exports `buildMasterTrade`, `buildUnsignedMasterPlaceOrder`, `signMasterTrade`, `encodeMasterTrade`, `decodeMasterTrade` and `DexModule.submitMasterTrade`. Large values are bigint or canonical decimal strings. Python exports `MasterTrade`, `build_master_trade`, `sign_master_trade`, `encode_master_trade`, `decode_master_trade` and `DexModule.submit_master_trade`. Both Rust SDKs export `MasterTradeTx` and `submit_master_trade`; the maintained Rust SDK also provides existing local-key MLDSA/ECDSA signing adapters. Pure encoders never invent an account key, nonce, timestamp, source reference or leverage value.
|
|
303
|
+
|
|
304
|
+
Submit the full original tagged bytes to `POST /api/dex/master-trade` as the sole JSON field `tx`. A response with `accepted:true,pending:true` confirms the action was received, not that it was applied. Retry the same signed bytes while following the original outer transaction hash. EIP712 uses the network id N (GET /health `dex_bridge_network_id`) as its domain salt; the ML-DSA scheme signs the domain hash with the same N (`sign_master_trade(..., network_id=N)`).
|
|
305
|
+
|
|
306
|
+
Private reads append canonical lowercase `vault_address=0x<40 hex digits>` before authorizing the exact target. The signer/session remains the master; the server checks current own-Sub read authority. TypeScript `selectedAccountReadQuery`, Python `selected_account_read_query`, and Rust selected-target/query helpers preserve this boundary. Outcome `economic_account` and `wire` may be null for legacy Unknown records; never infer a selected Sub from `address`. `signing_nonce` is a lossless decimal string. `master_verified_refusal` and `master_consumed_refusal` remain distinct; terminal state follows the response's explicit finality and nonce-consumption fields.
|