@trinaryex/sdk 1.0.0
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.
- package/DESIGN.md +577 -0
- package/README.md +239 -0
- package/dist/ReadOnlyClient.d.ts +26 -0
- package/dist/TriexClient.d.ts +81 -0
- package/dist/book.d.ts +27 -0
- package/dist/config.d.ts +6 -0
- package/dist/errors.d.ts +29 -0
- package/dist/execute.d.ts +12 -0
- package/dist/funding.d.ts +15 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1608 -0
- package/dist/money.d.ts +18 -0
- package/dist/onchain.d.ts +45 -0
- package/dist/paging.d.ts +8 -0
- package/dist/queries.d.ts +26 -0
- package/dist/schemas.d.ts +1146 -0
- package/dist/transactions.d.ts +76 -0
- package/dist/types.d.ts +172 -0
- package/dist/wait.d.ts +5 -0
- package/package.json +108 -0
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# @trinaryex/sdk
|
|
2
|
+
|
|
3
|
+
The trading SDK for **Trinary Exchange** — a Sui-based, DeepBook-style market
|
|
4
|
+
for the EVE Frontier game economy. Players and bots read market + account data
|
|
5
|
+
through the [Trinary Exchange API](https://api.trinary.exchange) and trade by
|
|
6
|
+
signing on-chain transactions with their own wallet or keypair.
|
|
7
|
+
|
|
8
|
+
Built for exactly the things you'd want to build on an exchange:
|
|
9
|
+
|
|
10
|
+
- **market analytics** — discovery feed, order books, spreads, VWAP, history streaming
|
|
11
|
+
- **trading bots** — atomic order placement with automatic funding, fills, settled-proceeds claiming, cancels
|
|
12
|
+
- **CLI tools** — everything is plain async TypeScript with typed errors
|
|
13
|
+
- **agentic trading** — stable error codes plus human-readable on-chain abort translation
|
|
14
|
+
|
|
15
|
+
> **Status: pre-release.** Reads and the full write surface (deposits,
|
|
16
|
+
> withdrawals, orders, cancels, claims) are implemented and unit-tested
|
|
17
|
+
> against the production app's transaction composition. Targets **testnet**
|
|
18
|
+
> (the `stillness` world). See [DESIGN.md](./DESIGN.md).
|
|
19
|
+
|
|
20
|
+
## Two planes, two auth models
|
|
21
|
+
|
|
22
|
+
| Plane | Auth | What |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| **Reads** | API key (`x-api-key`) | discovery, order books, hubs, item balances, order status — billed per-request in compute units |
|
|
25
|
+
| **Writes** | Your Sui signature | create account, deposit, withdraw, place/cancel orders — the API key never moves funds |
|
|
26
|
+
|
|
27
|
+
One deliberate exception: **currency (CRED) balances are fullnode reads**, not
|
|
28
|
+
API reads — order funding math needs head-current values.
|
|
29
|
+
|
|
30
|
+
Get an API key at <https://trinary.exchange/settings> (docs:
|
|
31
|
+
<https://docs.trinary.exchange/docs/api-keys>). The docs' samples use the
|
|
32
|
+
`TRINARY_API_KEY` env var; this README follows that convention.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @trinaryex/sdk @mysten/sui zod
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`@mysten/sui` (v2) and `zod` are peer dependencies.
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc'
|
|
46
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
|
|
47
|
+
import { TriexClient } from '@trinaryex/sdk'
|
|
48
|
+
|
|
49
|
+
const suiClient = new SuiGrpcClient({
|
|
50
|
+
network: 'testnet',
|
|
51
|
+
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
52
|
+
})
|
|
53
|
+
const keypair = Ed25519Keypair.fromSecretKey(process.env.SUI_PRIVATE_KEY!)
|
|
54
|
+
|
|
55
|
+
const client = new TriexClient({
|
|
56
|
+
suiClient,
|
|
57
|
+
apiKey: process.env.TRINARY_API_KEY!,
|
|
58
|
+
address: keypair.toSuiAddress(),
|
|
59
|
+
// The SDK normalizes v2 core-client results AND legacy {digest, objectChanges}
|
|
60
|
+
// shapes, and surfaces on-chain aborts as typed errors. Include effects +
|
|
61
|
+
// objectTypes so created objects (e.g. your trading account) are captured.
|
|
62
|
+
executor: (tx) =>
|
|
63
|
+
suiClient.signAndExecuteTransaction({
|
|
64
|
+
transaction: tx,
|
|
65
|
+
signer: keypair,
|
|
66
|
+
include: { effects: true, objectTypes: true },
|
|
67
|
+
}),
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Reads
|
|
71
|
+
const feed = await client.market.discover({ limit: 20 })
|
|
72
|
+
const book = await client.market.orderbook({ storageUnitId, assetId: '70810' })
|
|
73
|
+
|
|
74
|
+
// Writes (atomic PTBs; the trading account is created on demand)
|
|
75
|
+
await client.orders.limit({
|
|
76
|
+
storageUnitId,
|
|
77
|
+
assetId: '70810',
|
|
78
|
+
side: 'buy',
|
|
79
|
+
price: 2_500_000_000n, // CRED base units per item
|
|
80
|
+
quantity: 10n,
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Browser wallets work the same way — pass dapp-kit's `signAndExecuteTransaction`
|
|
85
|
+
as the `executor`.
|
|
86
|
+
|
|
87
|
+
### Read-only (no wallet, no fullnode)
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { ReadOnlyClient } from '@trinaryex/sdk'
|
|
91
|
+
|
|
92
|
+
const ro = new ReadOnlyClient({ apiKey: process.env.TRINARY_API_KEY! })
|
|
93
|
+
const feed = await ro.discover({ assetId: '70810', side: 'sell' })
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Recipes
|
|
97
|
+
|
|
98
|
+
### Market analytics
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { aggregateLevels, midPrice, spread, vwap, bucketTrades, iterateTrades } from '@trinaryex/sdk'
|
|
102
|
+
|
|
103
|
+
const book = await ro.orderbook({ storageUnitId, assetId })
|
|
104
|
+
console.log('mid', midPrice(book), 'spread', spread(book)?.bps, 'bps')
|
|
105
|
+
console.log('bid levels', aggregateLevels(book.bids))
|
|
106
|
+
|
|
107
|
+
// Stream a balance manager's full trade history (auto-pagination) …
|
|
108
|
+
const history = []
|
|
109
|
+
for await (const trade of iterateTrades(ro.indexer, balanceManagerId)) {
|
|
110
|
+
history.push(trade) // { price, baseQuantity, quoteQuantity, fee, side, tradedAt, … }
|
|
111
|
+
}
|
|
112
|
+
// … and chart it: the API has no price-history endpoint, so build candles
|
|
113
|
+
// client-side.
|
|
114
|
+
const hourly = bucketTrades(history, 60 * 60 * 1000) // OHLCV Candle[]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Trading bot loop
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { estimateMarketBuyCost } from '@trinaryex/sdk'
|
|
121
|
+
|
|
122
|
+
// 1. Fund + place in ONE atomic transaction: the SDK deposits only the
|
|
123
|
+
// deficit (existing balance-manager funds are consumed first), creates
|
|
124
|
+
// the trading account if missing, and rolls everything back on failure.
|
|
125
|
+
await client.orders.limit({ storageUnitId, assetId, side: 'sell', price, quantity })
|
|
126
|
+
|
|
127
|
+
// Market buys need a worst-case budget from the current book:
|
|
128
|
+
const est = estimateMarketBuyCost(book.asks, quantity, meta.feeRateScaled)
|
|
129
|
+
await client.orders.market({ storageUnitId, assetId, side: 'buy', quantity, quoteBudget: est.total })
|
|
130
|
+
|
|
131
|
+
// 2. Watch state. The indexer trails the chain by seconds — untilIndexed()
|
|
132
|
+
// packages the poll-until-visible pattern (typed Timeout on give-up).
|
|
133
|
+
import { untilIndexed } from '@trinaryex/sdk'
|
|
134
|
+
const placed = await untilIndexed(async () => {
|
|
135
|
+
const { orders } = await client.orders.openOrders({ limit: 20 })
|
|
136
|
+
return orders.find((o) => o.assetId === assetId && o.side === 'sell')
|
|
137
|
+
}, { label: 'the resting order' })
|
|
138
|
+
const { fills } = await client.orders.fills({ after: lastSeen })
|
|
139
|
+
|
|
140
|
+
// 3. After fills: proceeds sit SETTLED in the pool until claimed.
|
|
141
|
+
const claimable = await client.account.sweepable()
|
|
142
|
+
if (claimable.pools.length) await client.account.claimSettled()
|
|
143
|
+
|
|
144
|
+
// 4. Withdraw to the wallet / hangar when done.
|
|
145
|
+
await client.account.withdrawCurrency()
|
|
146
|
+
await client.account.withdrawItems({ storageUnitId, items: [{ assetId }] })
|
|
147
|
+
|
|
148
|
+
// Housekeeping.
|
|
149
|
+
await client.orders.cancel({ storageUnitId, assetId, orderId })
|
|
150
|
+
await client.orders.cancelAll({ storageUnitId, assetId })
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Agentic / CLI error handling
|
|
154
|
+
|
|
155
|
+
Every SDK failure is a `TriexClientError` with a stable `code` — each method's
|
|
156
|
+
`@throws` JSDoc lists exactly which codes it can raise, and on-chain aborts are
|
|
157
|
+
translated into actionable text:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { TriexClientError, TriexError, explainMoveAbort } from '@trinaryex/sdk'
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
await client.orders.limit(params)
|
|
164
|
+
} catch (e) {
|
|
165
|
+
if (!(e instanceof TriexClientError)) throw e
|
|
166
|
+
switch (e.code) {
|
|
167
|
+
case TriexError.RateLimited: // CU budget hit — wait e.retryAfterMs
|
|
168
|
+
case TriexError.InsufficientBalance: // top up and retry
|
|
169
|
+
case TriexError.PoolNotFound: // no market for this item at this hub
|
|
170
|
+
case TriexError.TransactionFailed: // on-chain abort, e.message explains why
|
|
171
|
+
console.error(e.message) // e.g. "…Max 100 open orders per balance manager…"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Or translate raw Sui errors from anywhere:
|
|
176
|
+
explainMoveAbort(rawError) // "No liquidity available (EEmptyOrderbook)" | null
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
| Code | Raised when | Recovery |
|
|
180
|
+
|---|---|---|
|
|
181
|
+
| `Unauthorized` | API key missing/revoked/wrong tier (HTTP 401/403) | fix `TRINARY_API_KEY` |
|
|
182
|
+
| `RateLimited` | compute-unit budget exhausted (HTTP 429) | wait `e.retryAfterMs`, retry |
|
|
183
|
+
| `IndexerError` | 5xx / unexpected HTTP failure (`e.status` set) | retry with backoff |
|
|
184
|
+
| `UnexpectedResponse` | response didn't match the pinned schema | report — API drift |
|
|
185
|
+
| `HubNotFound` / `PoolNotFound` / `BalanceManagerNotFound` | unknown id for the target resource | check inputs |
|
|
186
|
+
| `InsufficientBalance` | wallet/hangar/BM can't fund the operation | deposit / top up |
|
|
187
|
+
| `CollectionMismatch` | item receipts from a different deployment | wrong network/receipts |
|
|
188
|
+
| `CharacterNotFound` | hangar flows need an on-chain character | pass `characterId` / create one |
|
|
189
|
+
| `TransactionFailed` | on-chain abort (message carries the translated reason) | act on the message |
|
|
190
|
+
| `AddressRequired` / `ExecutorRequired` / `ApiKeyRequired` / `ValidationFailed` | client-side config/input problems | fix locally |
|
|
191
|
+
|
|
192
|
+
## API surface
|
|
193
|
+
|
|
194
|
+
| Group | Methods |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `account` | `get` · `ensure` · `depositCurrency` · `depositItems` · `withdrawCurrency` · `withdrawItems` · `sweepable` · `claimSettled` |
|
|
197
|
+
| `balances` | `atHub` (items: warehouse/marketplace/hangar) · `currency` (CRED wallet + BM, fullnode) |
|
|
198
|
+
| `market` | `discover` · `hub` · `itemsAtHub` · `resolvePool` · `orderbook` · `poolMetadata` |
|
|
199
|
+
| `orders` | `limit` · `market` · `cancel` · `cancelAll` · `modify` · `openOrders` · `fills` · `trades` |
|
|
200
|
+
| helpers | `aggregateLevels` · `midPrice` · `spread` · `depth` · `vwap` · `bucketTrades` (OHLCV) · `estimateMarketBuyCost` · `iterateDiscovery/Fills/Trades` · `untilIndexed` · `explainMoveAbort` · `toBase` / `fromBase` |
|
|
201
|
+
|
|
202
|
+
Runnable examples live in [`examples/`](./examples).
|
|
203
|
+
|
|
204
|
+
## Units & money
|
|
205
|
+
|
|
206
|
+
- All prices, quantities, and amounts are **`bigint` in raw base units**;
|
|
207
|
+
timestamps are epoch **milliseconds**. Items are identified by `assetId`
|
|
208
|
+
(numeric item-type id as a string).
|
|
209
|
+
- Item pools price in CRED base units per item (no price scaling). Pool
|
|
210
|
+
metadata carries `feeRateScaled` (× 1e9; `20_000_000` = 2%) and the
|
|
211
|
+
base/quote `decimals` for display conversion via `toBase`/`fromBase`.
|
|
212
|
+
- Only buyers pay fees. A limit bid deposits
|
|
213
|
+
`quote × (1e9 + feeRateScaled) / 1e9` — computed for you.
|
|
214
|
+
- Order expiry defaults to good-til-cancelled (`GTC_EXPIRE`).
|
|
215
|
+
|
|
216
|
+
## Consistency model
|
|
217
|
+
|
|
218
|
+
The indexer is eventually-consistent (seconds behind head). On-chain writes
|
|
219
|
+
are authoritative and atomic — a stale read can only make a transaction abort
|
|
220
|
+
and roll back, never lose funds. The SDK reads everything that funds
|
|
221
|
+
transactions (balance-manager resolution, currency balances, receipts, hangar
|
|
222
|
+
slots) from the **fullnode**, head-current. Prefer ids returned from writes
|
|
223
|
+
(`TxResult.createdObjects`) over immediate re-reads.
|
|
224
|
+
|
|
225
|
+
## Develop
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
npm install
|
|
229
|
+
npm run tscheck && npm test # 70 unit tests
|
|
230
|
+
npm run build
|
|
231
|
+
|
|
232
|
+
# Live verification (needs .env — see .env.sample):
|
|
233
|
+
node --env-file=.env scripts/smoke.mjs # read surface vs the live gateway
|
|
234
|
+
node --env-file=.env scripts/integration.mjs # write paths on testnet (uses gas)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IndexerClient } from './queries';
|
|
2
|
+
import { BalancesAtHubParams, DiscoveryFilters, DiscoveryResult, FillsPage, FillsParams, HistoryPageParams, HubItemsPage, InventoryBalances, OpenOrdersPage, Orderbook, PackageIds, PoolMetadata, ReadOnlyClientConfig, Sweepable, TradeHubDetail, TradesPage, TradesParams } from './types';
|
|
3
|
+
export declare class ReadOnlyClient {
|
|
4
|
+
readonly ids: PackageIds;
|
|
5
|
+
readonly indexer: IndexerClient;
|
|
6
|
+
constructor(config: ReadOnlyClientConfig);
|
|
7
|
+
discover(filters?: DiscoveryFilters): Promise<DiscoveryResult>;
|
|
8
|
+
hub(hubId: string): Promise<TradeHubDetail>;
|
|
9
|
+
itemsAtHub(hubId: string): Promise<HubItemsPage>;
|
|
10
|
+
resolvePool(params: {
|
|
11
|
+
storageUnitId: string;
|
|
12
|
+
assetId: string;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
orderbook(params: {
|
|
15
|
+
storageUnitId: string;
|
|
16
|
+
assetId: string;
|
|
17
|
+
}): Promise<Orderbook>;
|
|
18
|
+
poolMetadata(poolId: string): Promise<PoolMetadata>;
|
|
19
|
+
balancesAtHub(params: BalancesAtHubParams & {
|
|
20
|
+
balanceManagerId?: string;
|
|
21
|
+
}): Promise<InventoryBalances>;
|
|
22
|
+
openOrders(balanceManagerId: string, params?: HistoryPageParams): Promise<OpenOrdersPage>;
|
|
23
|
+
fills(balanceManagerId: string, params?: FillsParams): Promise<FillsPage>;
|
|
24
|
+
trades(balanceManagerId: string, params?: TradesParams): Promise<TradesPage>;
|
|
25
|
+
sweepable(balanceManagerId: string): Promise<Sweepable>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
2
|
+
import { ClientWithCoreApi } from '@mysten/sui/client';
|
|
3
|
+
import { IndexerClient } from './queries';
|
|
4
|
+
import { BalancesAtHubParams, CancelAllOrdersParams, CancelOrderParams, ClaimSettledParams, CurrencyBalances, DepositCurrencyParams, DepositItemsParams, DiscoveryFilters, DiscoveryResult, EnsureAccountResult, FillsPage, FillsParams, HistoryPageParams, HubItemsPage, InventoryBalances, LimitOrderParams, MarketOrderParams, ModifyOrderParams, OpenOrdersPage, Orderbook, PackageIds, PoolMetadata, Sweepable, TradeHubDetail, TradesPage, TradesParams, TradingAccount, TransactionExecutor, TriexClientConfig, TxResult, WithdrawCurrencyParams, WithdrawItemsParams } from './types';
|
|
5
|
+
export declare class TriexClient {
|
|
6
|
+
readonly suiClient: ClientWithCoreApi;
|
|
7
|
+
readonly ids: PackageIds;
|
|
8
|
+
readonly indexer: IndexerClient;
|
|
9
|
+
private readonly executor?;
|
|
10
|
+
private readonly address?;
|
|
11
|
+
private cachedBalanceManagerId?;
|
|
12
|
+
readonly account: AccountApi;
|
|
13
|
+
readonly balances: BalancesApi;
|
|
14
|
+
readonly market: MarketApi;
|
|
15
|
+
readonly orders: OrdersApi;
|
|
16
|
+
constructor(config: TriexClientConfig);
|
|
17
|
+
requireExecutor(): TransactionExecutor;
|
|
18
|
+
requireAddress(override?: string): string;
|
|
19
|
+
resolveBalanceManagerId(address: string): Promise<string | null>;
|
|
20
|
+
rememberBalanceManagerId(id: string): void;
|
|
21
|
+
beginBmTx(owner: string): Promise<{
|
|
22
|
+
tx: Transaction;
|
|
23
|
+
bm: TransactionObjectArgument;
|
|
24
|
+
existingBmId: string | null;
|
|
25
|
+
}>;
|
|
26
|
+
finishBmTx(tx: Transaction, bm: TransactionObjectArgument, existingBmId: string | null, owner: string): Promise<TxResult>;
|
|
27
|
+
requireBalanceManagerId(owner: string): Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
declare class AccountApi {
|
|
30
|
+
private readonly c;
|
|
31
|
+
constructor(c: TriexClient);
|
|
32
|
+
get(address?: string): Promise<TradingAccount | null>;
|
|
33
|
+
ensure(address?: string): Promise<EnsureAccountResult>;
|
|
34
|
+
depositCurrency(params: DepositCurrencyParams): Promise<TxResult>;
|
|
35
|
+
depositItems(params: DepositItemsParams): Promise<TxResult>;
|
|
36
|
+
withdrawCurrency(params?: WithdrawCurrencyParams): Promise<TxResult>;
|
|
37
|
+
withdrawItems(params: WithdrawItemsParams): Promise<TxResult>;
|
|
38
|
+
sweepable(): Promise<Sweepable>;
|
|
39
|
+
claimSettled(params?: ClaimSettledParams): Promise<TxResult>;
|
|
40
|
+
}
|
|
41
|
+
declare class BalancesApi {
|
|
42
|
+
private readonly c;
|
|
43
|
+
constructor(c: TriexClient);
|
|
44
|
+
atHub(params: BalancesAtHubParams & {
|
|
45
|
+
includeHangar?: boolean;
|
|
46
|
+
}): Promise<InventoryBalances>;
|
|
47
|
+
currency(address?: string): Promise<CurrencyBalances>;
|
|
48
|
+
}
|
|
49
|
+
declare class MarketApi {
|
|
50
|
+
private readonly c;
|
|
51
|
+
constructor(c: TriexClient);
|
|
52
|
+
discover(filters?: DiscoveryFilters): Promise<DiscoveryResult>;
|
|
53
|
+
hub(hubId: string): Promise<TradeHubDetail>;
|
|
54
|
+
itemsAtHub(hubId: string): Promise<HubItemsPage>;
|
|
55
|
+
resolvePool(params: {
|
|
56
|
+
storageUnitId: string;
|
|
57
|
+
assetId: string;
|
|
58
|
+
}): Promise<string>;
|
|
59
|
+
orderbook(params: {
|
|
60
|
+
storageUnitId: string;
|
|
61
|
+
assetId: string;
|
|
62
|
+
}): Promise<Orderbook>;
|
|
63
|
+
poolMetadata(poolId: string): Promise<PoolMetadata>;
|
|
64
|
+
}
|
|
65
|
+
declare class OrdersApi {
|
|
66
|
+
private readonly c;
|
|
67
|
+
constructor(c: TriexClient);
|
|
68
|
+
limit(params: LimitOrderParams): Promise<TxResult>;
|
|
69
|
+
market(params: MarketOrderParams): Promise<TxResult>;
|
|
70
|
+
cancel(params: CancelOrderParams): Promise<TxResult>;
|
|
71
|
+
cancelAll(params: CancelAllOrdersParams): Promise<TxResult>;
|
|
72
|
+
modify(params: ModifyOrderParams): Promise<TxResult>;
|
|
73
|
+
openOrders(params?: HistoryPageParams): Promise<OpenOrdersPage>;
|
|
74
|
+
fills(params?: FillsParams): Promise<FillsPage>;
|
|
75
|
+
trades(params?: TradesParams): Promise<TradesPage>;
|
|
76
|
+
private ownBm;
|
|
77
|
+
private requirePool;
|
|
78
|
+
private depositQuoteDeficit;
|
|
79
|
+
private beginCancelTx;
|
|
80
|
+
}
|
|
81
|
+
export type { AccountApi, BalancesApi, MarketApi, OrdersApi };
|
package/dist/book.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Fill, Orderbook, OrderbookOrder, Trade } from './types';
|
|
2
|
+
export interface BookLevel {
|
|
3
|
+
price: bigint;
|
|
4
|
+
quantity: bigint;
|
|
5
|
+
orderCount: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function aggregateLevels(orders: OrderbookOrder[]): BookLevel[];
|
|
8
|
+
export declare function bestBid(book: Orderbook): OrderbookOrder | null;
|
|
9
|
+
export declare function bestAsk(book: Orderbook): OrderbookOrder | null;
|
|
10
|
+
export declare function midPrice(book: Orderbook): bigint | null;
|
|
11
|
+
export declare function spread(book: Orderbook): {
|
|
12
|
+
absolute: bigint;
|
|
13
|
+
bps: number;
|
|
14
|
+
} | null;
|
|
15
|
+
export declare function depth(orders: OrderbookOrder[]): bigint;
|
|
16
|
+
export declare function vwap(executions: ReadonlyArray<Pick<Fill | Trade, 'baseQuantity' | 'quoteQuantity'>>): bigint | null;
|
|
17
|
+
export interface Candle {
|
|
18
|
+
openTime: number;
|
|
19
|
+
open: bigint;
|
|
20
|
+
high: bigint;
|
|
21
|
+
low: bigint;
|
|
22
|
+
close: bigint;
|
|
23
|
+
baseVolume: bigint;
|
|
24
|
+
quoteVolume: bigint;
|
|
25
|
+
tradeCount: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function bucketTrades(trades: ReadonlyArray<Pick<Trade, 'price' | 'baseQuantity' | 'quoteQuantity' | 'tradedAt'>>, intervalMs: number): Candle[];
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PackageIds, TriexNetwork } from './types';
|
|
2
|
+
export declare const DEFAULT_INDEXER_URL = "https://api.trinary.exchange";
|
|
3
|
+
export declare const CLOCK_ID = "0x6";
|
|
4
|
+
export declare const STILLNESS_PACKAGE_IDS: PackageIds;
|
|
5
|
+
export declare const NETWORK_PRESETS: Record<TriexNetwork, PackageIds>;
|
|
6
|
+
export declare function resolvePackageIds(network?: TriexNetwork, overrides?: Partial<PackageIds>): PackageIds;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum TriexError {
|
|
2
|
+
ExecutorRequired = "TRIEX_EXECUTOR_REQUIRED",
|
|
3
|
+
AddressRequired = "TRIEX_ADDRESS_REQUIRED",
|
|
4
|
+
ApiKeyRequired = "TRIEX_API_KEY_REQUIRED",
|
|
5
|
+
Unauthorized = "TRIEX_UNAUTHORIZED",
|
|
6
|
+
RateLimited = "TRIEX_RATE_LIMITED",
|
|
7
|
+
IndexerError = "TRIEX_INDEXER_ERROR",
|
|
8
|
+
UnexpectedResponse = "TRIEX_UNEXPECTED_RESPONSE",
|
|
9
|
+
ValidationFailed = "TRIEX_VALIDATION_FAILED",
|
|
10
|
+
InsufficientBalance = "TRIEX_INSUFFICIENT_BALANCE",
|
|
11
|
+
CollectionMismatch = "TRIEX_COLLECTION_MISMATCH",
|
|
12
|
+
BalanceManagerNotFound = "TRIEX_BALANCE_MANAGER_NOT_FOUND",
|
|
13
|
+
PoolNotFound = "TRIEX_POOL_NOT_FOUND",
|
|
14
|
+
HubNotFound = "TRIEX_HUB_NOT_FOUND",
|
|
15
|
+
CharacterNotFound = "TRIEX_CHARACTER_NOT_FOUND",
|
|
16
|
+
TransactionFailed = "TRIEX_TRANSACTION_FAILED",
|
|
17
|
+
Timeout = "TRIEX_TIMEOUT",
|
|
18
|
+
NotImplemented = "TRIEX_NOT_IMPLEMENTED"
|
|
19
|
+
}
|
|
20
|
+
export declare class TriexClientError extends Error {
|
|
21
|
+
readonly code: TriexError;
|
|
22
|
+
readonly cause?: unknown | undefined;
|
|
23
|
+
readonly status?: number | undefined;
|
|
24
|
+
readonly retryAfterMs?: number | undefined;
|
|
25
|
+
constructor(code: TriexError, message: string, cause?: unknown | undefined, status?: number | undefined, retryAfterMs?: number | undefined);
|
|
26
|
+
}
|
|
27
|
+
export declare function fail(code: TriexError, message: string, cause?: unknown): never;
|
|
28
|
+
export declare function notImplemented(what: string): never;
|
|
29
|
+
export declare function explainMoveAbort(error: unknown): string | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CreatedObject {
|
|
2
|
+
objectId: string;
|
|
3
|
+
objectType: string;
|
|
4
|
+
}
|
|
5
|
+
export interface NormalizedExecution {
|
|
6
|
+
digest: string;
|
|
7
|
+
createdObjects: CreatedObject[];
|
|
8
|
+
raw: unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare function executeAndNormalize<T>(executor: (tx: T) => Promise<unknown>, tx: T): Promise<NormalizedExecution>;
|
|
11
|
+
export declare function normalizeExecuteResult(raw: unknown): NormalizedExecution;
|
|
12
|
+
export declare function findCreatedObject(result: NormalizedExecution, typeSubstring: string): CreatedObject | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClientWithCoreApi } from '@mysten/sui/client';
|
|
2
|
+
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
3
|
+
import { PackageIds } from './types';
|
|
4
|
+
export declare function prepareWalletCoinInput(suiClient: ClientWithCoreApi, tx: Transaction, owner: string, coinType: string, amount: bigint, insufficientMessage?: string): Promise<TransactionObjectArgument>;
|
|
5
|
+
export interface SourceItemsParams {
|
|
6
|
+
owner: string;
|
|
7
|
+
ssuObjectId: string;
|
|
8
|
+
vaultConfigId: string;
|
|
9
|
+
vaultCollectionId: string;
|
|
10
|
+
assetId: bigint;
|
|
11
|
+
amount: bigint;
|
|
12
|
+
balanceManagerId: string | null;
|
|
13
|
+
deficitMode?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function sourceItemsIntoBalanceManager(suiClient: ClientWithCoreApi, tx: Transaction, ids: PackageIds, bm: TransactionObjectArgument, params: SourceItemsParams): Promise<void>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { TriexClient } from './TriexClient';
|
|
2
|
+
export type { AccountApi, BalancesApi, MarketApi, OrdersApi, } from './TriexClient';
|
|
3
|
+
export { ReadOnlyClient } from './ReadOnlyClient';
|
|
4
|
+
export { TriexError, TriexClientError, explainMoveAbort } from './errors';
|
|
5
|
+
export { DEFAULT_INDEXER_URL, CLOCK_ID, STILLNESS_PACKAGE_IDS, NETWORK_PRESETS, resolvePackageIds, } from './config';
|
|
6
|
+
export { toBase, fromBase, computeItemQuote, computeBidQuoteDeposit, estimateMarketBuyCost, marketBuyRoundingBuffer, TRIEXBOOK_PRICE_SCALING, MULTICOIN_PRICE_SCALING, FEE_RATE_SCALING, GTC_EXPIRE, } from './money';
|
|
7
|
+
export { IndexerClient } from './queries';
|
|
8
|
+
export * as transactions from './transactions';
|
|
9
|
+
export { getWalletCurrencyBalance, getBalanceManagerCurrencyBalance, getBalanceManagerItemBalance, getRegistryMulticoinCollectionId, findOwnedItemReceipts, fetchCharacterInfo, fetchSsuOwnerInfo, fetchInventorySlotQuantity, toSsuObjectId, getObjectRef, } from './onchain';
|
|
10
|
+
export { prepareWalletCoinInput, sourceItemsIntoBalanceManager, } from './funding';
|
|
11
|
+
export { normalizeExecuteResult, executeAndNormalize, findCreatedObject, } from './execute';
|
|
12
|
+
export type { NormalizedExecution, CreatedObject } from './execute';
|
|
13
|
+
export { aggregateLevels, bestBid, bestAsk, midPrice, spread, depth, vwap, bucketTrades, } from './book';
|
|
14
|
+
export type { BookLevel, Candle } from './book';
|
|
15
|
+
export { iterateDiscovery, iterateFills, iterateTrades } from './paging';
|
|
16
|
+
export type { IterateOptions } from './paging';
|
|
17
|
+
export { untilIndexed } from './wait';
|
|
18
|
+
export type { TriexNetwork, PackageIds, TriexClientConfig, ReadOnlyClientConfig, TransactionExecutor, ObjectChange, TxResult, OrderSide, TradingAccount, CurrencyBalances, AssetBalance, InventoryBalances, TradeHubDetail, HubVaultInfo, HubLocation, HubItem, HubItemsPage, CollectionHub, Orderbook, OrderbookOrder, PoolMetadata, DiscoveryOrder, DiscoveryResult, DiscoveryFilters, OpenOrder, OpenOrdersPage, Fill, FillsPage, Trade, TradesPage, BalancesAtHubParams, HistoryPageParams, FillsParams, TradesParams, Sweepable, SweepablePool, SweepableItem, EnsureAccountResult, DepositCurrencyParams, DepositItemsParams, WithdrawCurrencyParams, WithdrawItemsParams, LimitOrderParams, MarketOrderParams, CancelOrderParams, CancelAllOrdersParams, ModifyOrderParams, ClaimSettledParams, } from './types';
|
|
19
|
+
export type { OwnedItemReceipt, CharacterInfo, SsuOwnerInfo, ObjectRef, } from './onchain';
|