aftermath-ts-sdk 3.3.3 → 4.0.0-dev.2abb49e

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/README.md CHANGED
@@ -1,151 +1,300 @@
1
- # Aftermath SDK
1
+ # Aftermath TypeScript SDK
2
2
 
3
- The Aftermath SDK provides easy access to Aftermath Finance's protocols on the Sui blockchain. Please note that not all of our protocols are on Testnet, but all of them are Mainnet.
3
+ The Aftermath TypeScript SDK provides typed access to Aftermath Finance
4
+ protocols and Sui on-chain data. It supports the Sui `MAINNET`, `TESTNET`,
5
+ `DEVNET`, and `LOCAL` networks. A protocol can be unavailable on a selected
6
+ network.
4
7
 
5
- ## Installation
8
+ Use the high-level `Aftermath` provider for most applications. Use
9
+ `AftermathApi` when you need direct control of Sui clients, package addresses,
10
+ or low-level transaction and object helpers.
11
+
12
+ ## Choose a path
13
+
14
+ For a first integration, follow the [high-level provider quick start](#create-the-high-level-provider).
15
+
16
+ For a focused task, use these guides:
17
+
18
+ - [Configure and bootstrap the SDK](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/guides/configure-and-bootstrap.md)
19
+ - [Build and execute a transaction](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/guides/build-and-execute-transactions.md)
20
+ - [Handle cancellation and transport errors](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/guides/handle-cancellation-and-errors.md)
21
+ - [Query Sui data](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/guides/query-sui-data.md)
22
+
23
+ For the provider and transport model, read [Understand the provider layers](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/explanation/provider-layers.md).
24
+ For complete symbol-level facts, open the [generated API reference](https://aftermathfinance.github.io/aftermath-ts-sdk/).
25
+ For documentation maintenance rules, see the [SDK documentation guide](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/DOCUMENTATION_GUIDE.md).
26
+
27
+ ## Install the package
28
+
29
+ Install the SDK and its `@mysten/sui` peer dependency in the application that
30
+ imports them:
6
31
 
7
32
  ```bash
8
- npm i aftermath-ts-sdk
33
+ npm install aftermath-ts-sdk @mysten/sui@^2
9
34
  ```
10
35
 
11
- ## Quick Start (Aftermath SDK)
36
+ The SDK supports `@mysten/sui` versions `>=2.0.0` and `<3.0.0`.
37
+
38
+ ## Create the high-level provider
12
39
 
13
- For most integrations, use the Aftermath SDK for simplified access:
40
+ ```ts
41
+ import { Aftermath } from "aftermath-ts-sdk";
14
42
 
15
- ```typescript
16
- // "MAINNET" | "TESTNET" | "DEVNET" | "LOCAL"
17
- const afSdk = await Aftermath.create({ network: "MAINNET" });
43
+ const sdk = await Aftermath.create({ network: "MAINNET" });
44
+ const supportedCoins = await sdk.Router().getSupportedCoins();
18
45
 
19
- // Access protocols
20
- const router = afSdk.Router();
21
- const pools = afSdk.Pools();
22
- const staking = afSdk.Staking();
23
- const farms = afSdk.Farms();
24
- const dca = afSdk.Dca();
46
+ console.log(supportedCoins);
25
47
  ```
26
48
 
27
- ## Cancellation and transport errors
28
-
29
- `Aftermath.create(config, abortSignal)` accepts a caller-owned `AbortSignal`
30
- for cancellation during address discovery. The same final positional
31
- `abortSignal` is available on the SDK's pool, farm, price, coin metadata, and
32
- decimal read methods. Signals are runtime inputs and are not serialized into
33
- configuration or request bodies; supplying `addresses` or `api` keeps the
34
- existing no-network initialization fast path.
35
-
36
- Transport failures are exposed as `AftermathTransportError` with structured
37
- `kind`, optional `status`, `retryAfterMs`, `code`, `cause`, and `abortSource`
38
- fields. These fields are additive: existing error messages and names are
39
- preserved, including the legacy HTTP format
40
- `HTTP <status> <statusText>: <body>`. Caller cancellation uses
41
- `kind: "abort"` and `abortSource: "caller"`; timeout facts use
42
- `kind: "timeout"` and `abortSource: "timeout"`. Arbitrary response headers
43
- are not exposed.
44
-
45
- ```typescript
46
- const controller = new AbortController();
47
- const sdk = await Aftermath.create({ network: "MAINNET" }, controller.signal);
49
+ The call to `Aftermath.create` is asynchronous because the factory discovers
50
+ the selected network's Aftermath addresses. The factory skips address
51
+ discovery when you provide `addresses` or a pre-built `api`.
48
52
 
49
- try {
50
- await sdk.Pools().getAllPools(controller.signal);
51
- } catch (error) {
52
- if (isAftermathTransportError(error)) {
53
- if (error.kind === "abort" && error.abortSource === "caller") {
54
- return;
55
- }
56
- console.error(error.kind, error.status, error.retryAfterMs);
57
- }
58
- }
53
+ The quick start calls the Aftermath HTTP API and returns an array of Sui coin
54
+ type strings. Check protocol availability before using an accessor on a
55
+ network that does not publish that protocol's address section.
56
+
57
+ ### Configure a network or endpoint
58
+
59
+ Pass `network` to use the SDK's canonical Aftermath API and Sui fullnode URLs:
60
+
61
+ ```ts
62
+ const sdk = await Aftermath.create({ network: "TESTNET" });
59
63
  ```
60
64
 
61
- ## Advanced Usage (AftermathApi)
65
+ Use `baseUrl` for the Aftermath API host. Use `fullnodeUrl` for the Sui fullnode
66
+ host. When the factory creates the clients, it passes `fullnodeUrl` to
67
+ `SuiGrpcClient` as `baseUrl` and to `SuiJsonRpcClient` as `url`.
62
68
 
63
- For complex transaction construction, use AftermathApi for direct control:
69
+ ```ts
70
+ const sdk = await Aftermath.create({
71
+ network: "MAINNET",
72
+ baseUrl: "https://api.example.test",
73
+ fullnodeUrl: "https://fullnode.example.test",
74
+ });
75
+ ```
64
76
 
65
- ```typescript
66
- import { SuiGrpcClient } from "@mysten/sui/grpc";
67
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
77
+ Use `apiEndpoint` for the path segment between `baseUrl` and a provider path.
78
+ It defaults to `api`. Keep the host in `baseUrl` and the path segment in
79
+ `apiEndpoint`.
80
+
81
+ Use `addresses` when your application already has a trusted
82
+ `ConfigAddresses` value for the selected network. Use `api` when your
83
+ application owns the Sui client lifecycle. The `api` option also supplies the
84
+ address configuration, so the factory skips address discovery and client
85
+ construction.
68
86
 
69
- const afSdk = await Aftermath.create({ network: "MAINNET" });
70
- const addresses = await afSdk.getAddresses();
87
+ See [Configure and bootstrap the SDK](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/guides/configure-and-bootstrap.md)
88
+ for complete setup variants.
71
89
 
72
- const fullnodeUrl = "https://fullnode.mainnet.sui.io";
90
+ ## Select a protocol or utility
73
91
 
74
- const afApi = new AftermathApi(
75
- new SuiGrpcClient({ network: "mainnet", baseUrl: fullnodeUrl }),
76
- addresses, // Configuration addresses
77
- // Still required by the few helpers that have no gRPC equivalent — see below
78
- new SuiJsonRpcClient({ network: "mainnet", url: fullnodeUrl })
79
- );
92
+ Each accessor returns a configured object. Call the accessor before calling a
93
+ package method.
80
94
 
81
- // Access protocol APIs
82
- const poolsApi = afApi.Pools();
83
- const stakingApi = afApi.Staking();
84
- const farmsApi = afApi.Farms();
95
+ | Accessor | Purpose |
96
+ | --- | --- |
97
+ | `sdk.Pools()` | AMM pool reads, liquidity transactions, and pool math. |
98
+ | `sdk.Router()` | Multi-pool trade routes and router transactions. |
99
+ | `sdk.Staking()` | afSUI staking, unstaking, validator data, and staking transactions. |
100
+ | `sdk.Farms()` | Staking pools, farm positions, lock periods, and rewards. |
101
+ | `sdk.Dca()` | Dollar-cost averaging orders and DCA transactions. |
102
+ | `sdk.LimitOrders()` | Limit-order reads and transaction builders. |
103
+ | `sdk.Perpetuals()` | Perpetual markets, accounts, orders, previews, and vaults. |
104
+ | `sdk.NftAmm()` | NFT AMM markets, NFT reads, and NFT transactions. |
105
+ | `sdk.SuiFrens()` | SuiFren objects, accessories, staking, and related events. |
106
+ | `sdk.Faucet()` | Faucet reads and mint transactions on supported networks. |
107
+ | `sdk.GasPools()` | Shared gas-pool reads and sponsored transactions. |
108
+ | `sdk.Multisig()` | Multisig address data and transaction-related requests. |
109
+ | `sdk.Referrals()` | Referral-program reads and transactions. |
110
+ | `sdk.Rewards()` | User reward data and claim transactions. |
111
+ | `sdk.UserData()` | User public-key and account message flows. |
112
+ | `sdk.Coin(coinType?)` | Coin metadata, decimals, prices, and verified coins. |
113
+ | `sdk.Wallet(address)` | Balance and transaction-history reads for an address. |
114
+ | `sdk.Sui()` | Sui chain data and system operations. |
115
+ | `sdk.Prices()` | Coin price and price-info reads. |
116
+ | `sdk.DynamicGas()` | Dynamic-gas transaction preparation through the Aftermath API. |
117
+ | `sdk.Auth()` | Authentication and access-token flows. |
118
+
119
+ `sdk.ReferralVault()` remains available for compatibility and is deprecated.
120
+ Use `sdk.Referrals()` for new code.
121
+
122
+ ## Build a transaction
123
+
124
+ Transaction builders are package-specific. For example,
125
+ `sdk.Staking().getStakeTransaction` returns an unsigned Sui `Transaction`,
126
+ performs gRPC coin selection, and does not sign or execute the transaction.
127
+ The `walletAddress` becomes the transaction sender and recipient. The selected
128
+ validator must be active on the target network.
129
+
130
+ ```ts
131
+ import { Aftermath } from "aftermath-ts-sdk";
132
+
133
+ const sdk = await Aftermath.create({ network: "MAINNET" });
134
+
135
+ // Replace these example addresses with addresses on the selected network.
136
+ const walletAddress = "0x1";
137
+ const validatorAddress = "0x4";
138
+
139
+ const stakeTx = await sdk.Staking().getStakeTransaction({
140
+ walletAddress,
141
+ suiStakeAmount: 1_000_000_000n,
142
+ validatorAddress,
143
+ });
144
+
145
+ // Sign and execute `stakeTx` with the wallet integration used by your app.
85
146
  ```
86
147
 
87
- `Aftermath.create`'s `fullnodeUrl` option takes a **gRPC base URL** (it is passed
88
- to `SuiGrpcClient` as `baseUrl`, and to `SuiJsonRpcClient` as `url`). Sui
89
- fullnodes serve both protocols from the same host, so a single URL is enough.
148
+ `suiStakeAmount` is a raw SUI amount in MIST. `1_000_000_000n` represents 1
149
+ SUI. Read the method's reference entry before using another transaction
150
+ builder because inputs, return types, and network requirements differ by
151
+ package.
152
+
153
+ See [Build and execute a transaction](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/guides/build-and-execute-transactions.md)
154
+ for sender, exact-amount, and sponsored-transaction guidance.
155
+
156
+ ## Use the low-level API provider
157
+
158
+ `AftermathApi` accepts a `SuiGrpcClient`, the resolved `ConfigAddresses`, and an
159
+ optional `SuiJsonRpcClient`:
160
+
161
+ ```ts
162
+ import { Aftermath, AftermathApi } from "aftermath-ts-sdk";
163
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
164
+
165
+ const bootstrap = await Aftermath.create({ network: "MAINNET" });
166
+ const addresses = await bootstrap.getAddresses();
167
+ const fullnodeUrl = "https://fullnode.mainnet.sui.io:443";
168
+
169
+ const client = new SuiGrpcClient({
170
+ network: "mainnet",
171
+ baseUrl: fullnodeUrl,
172
+ });
173
+
174
+ const api = new AftermathApi(client, addresses);
175
+ const poolsApi = api.Pools();
176
+ ```
90
177
 
91
- ### Remaining JSON-RPC surface
178
+ The low-level provider exposes `DynamicFields()`, `Events()`, `Inspections()`,
179
+ `Objects()`, `Transactions()`, `Wallet()`, `Nfts()`, `Coin()`, `Sui()`,
180
+ `Pools()`, `Faucet()`, `SuiFrens()`, `Staking()`, `NftAmm()`,
181
+ `ReferralVault()`, `Perpetuals()`, `Farms()`, `Dca()`, `Multisig()`,
182
+ `LimitOrders()`, and `Router()`.
92
183
 
93
- Sui JSON-RPC is deprecated and scheduled for removal from fullnodes in
94
- mid-October 2026. Every fullnode call this SDK makes goes over gRPC **except**
95
- the following, which cannot be expressed with `SuiGrpcClient` without changing
96
- what they return:
184
+ These accessors are low-level helpers. They use the configured Sui client,
185
+ build Move transactions, or run local conversions. They are not the same
186
+ surface as the high-level HTTP accessors on `Aftermath`.
97
187
 
98
- | Helper | Why |
188
+ ## Understand the remaining JSON-RPC calls
189
+
190
+ Most `AftermathApi` fullnode operations use `SuiGrpcClient`. These direct
191
+ helpers require the optional `SuiJsonRpcClient` in the current source:
192
+
193
+ | Helper | Reason |
99
194
  | --- | --- |
100
- | `Events().fetchCastEventsWithCursor` | `suix_queryEvents` has no `SuiGrpcClient` equivalent; `ledgerService.ListEvents` has a different filter model and BCS-only payloads |
101
- | `Transactions().fetchTransactionsWithCursor` | `suix_queryTransactionBlocks` has no gRPC equivalent at all |
102
- | `Objects().fetchObject` / `fetchObjectGeneral` / `fetchObjectBatch` / `fetchOwnedObjects` | gRPC returns Move object contents as BCS bytes or as a differently-shaped `json` view, so the parsed `content.fields` these helpers' casters consume cannot be reproduced |
103
- | `DynamicFields().fetchDynamicFieldObject` | same; gRPC returns the field value as BCS bytes |
104
- | `Sui().fetchSystemState` (deprecated) | gRPC has no `SuiSystemStateSummary` equivalent |
195
+ | `api.Events().fetchCastEventsWithCursor` | `suix_queryEvents` has no equivalent on `SuiGrpcClient`. |
196
+ | `api.Transactions().fetchTransactionsWithCursor` | `suix_queryTransactionBlocks` has no equivalent on `SuiGrpcClient`. |
197
+ | `api.Sui().fetchSystemState` | The gRPC API does not return `SuiSystemStateSummary`. This compatibility method is deprecated. |
198
+
199
+ Construct `AftermathApi` with a `SuiJsonRpcClient` only when your application
200
+ uses one of those helpers or a low-level wrapper that delegates to one. The
201
+ following wrappers also need the optional client:
202
+
203
+ - `api.Wallet().fetchPastTransactions`
204
+ - `api.Faucet().fetchMintCoinEvents`, `api.Faucet().fetchAddCoinEvents`, and
205
+ `api.Faucet().fetchSupportedCoins`
206
+ - `api.SuiFrens().fetchHarvestSuiFrenFeesEvents`,
207
+ `api.SuiFrens().fetchMixSuiFrensEvents`,
208
+ `api.SuiFrens().fetchStakeSuiFrenEvents`,
209
+ `api.SuiFrens().fetchUnstakeSuiFrenEvents`, and
210
+ `api.SuiFrens().fetchSuiFrenStats`
211
+
212
+ Without that third constructor argument, these methods throw a configuration
213
+ `Error`. The factory creates both clients when it performs its own bootstrap.
214
+ If you pass a pre-built `api`, the factory uses the clients already present in
215
+ that instance.
216
+
217
+ The high-level `sdk.Sui().getSystemState()` method is a different HTTP API
218
+ call. Do not confuse it with the low-level `api.Sui().fetchSystemState`
219
+ compatibility method.
220
+
221
+ ## Cancel requests and handle transport errors
222
+
223
+ Pass a caller-owned `AbortSignal` to `Aftermath.create` to cancel address
224
+ discovery. Pass a signal only to methods whose signature accepts a final
225
+ `AbortSignal` parameter. The signal is a runtime input. The SDK does not
226
+ serialize it into configuration or request bodies.
227
+
228
+ ```ts
229
+ import {
230
+ Aftermath,
231
+ isAftermathTransportError,
232
+ } from "aftermath-ts-sdk";
233
+
234
+ const sdk = await Aftermath.create({ network: "MAINNET" });
235
+ const controller = new AbortController();
236
+ const request = sdk.Pools().getAllPools(controller.signal);
105
237
 
106
- Prefer the Aftermath API (`Aftermath.create(...)`'s high-level providers) for
107
- events, transaction history and system state — those already avoid the fullnode
108
- entirely.
238
+ controller.abort();
109
239
 
110
- ## Available Protocols
240
+ try {
241
+ await request;
242
+ } catch (error) {
243
+ if (!isAftermathTransportError(error)) throw error;
111
244
 
112
- ### Pools (AMM)
245
+ if (error.kind === "abort" && error.abortSource === "caller") {
246
+ console.log("The caller cancelled the request.");
247
+ } else {
248
+ console.error(error.kind, error.status, error.retryAfterMs);
249
+ }
250
+ }
251
+ ```
113
252
 
114
- - Automated Market Maker pools for trading
115
- - Support for stable and uncorrelated assets
116
- - Up to 8 assets per pool
117
- - [View Pools Documentation](https://docs.aftermath.finance/developers/aftermath-ts-sdk/products/pools)
253
+ `AftermathTransportError` normalizes failures from the SDK's HTTP caller:
118
254
 
119
- ### Router
255
+ - `kind` is `http`, `network`, `abort`, `timeout`, or `decode`.
256
+ - `status` contains the HTTP status for an HTTP failure, when available.
257
+ - `retryAfterMs` contains a parsed, safe delay from `Retry-After`, when available.
258
+ - `code` contains an underlying transport code, when one exists.
259
+ - `cause` contains the original thrown value, when one exists.
260
+ - `abortSource` distinguishes caller cancellation from timeout cancellation.
120
261
 
121
- - Smart order routing across multiple pools
122
- - Optimal trade execution via split routes
123
- - [View Router Documentation](https://docs.aftermath.finance/developers/aftermath-ts-sdk/products/router)
262
+ The gRPC and optional JSON-RPC clients used by `AftermathApi` do not normalize
263
+ their errors to `AftermathTransportError`. Sui Move execution errors and errors
264
+ from a wallet or signer also remain outside this HTTP error boundary.
124
265
 
125
- ### Staking
266
+ See [Handle cancellation and transport errors](https://github.com/AftermathFinance/aftermath-ts-sdk/blob/main/docs/guides/handle-cancellation-and-errors.md)
267
+ for the error-handling flow.
126
268
 
127
- - Liquid staking for SUI tokens
128
- - Earn yield with afSUI
129
- - [View Staking Documentation](https://docs.aftermath.finance/developers/aftermath-ts-sdk/products/liquid-staking)
269
+ ## Work with pagination and typed values
130
270
 
131
- ### Farms
271
+ Cursor-returning methods expose a page and a cursor. Pass `nextCursor` to the
272
+ next request while it is not `null`. Cursor shapes differ by API. Event pages
273
+ use `EventId`, transaction pages use a transaction digest, and dynamic-field
274
+ pages use a field object ID.
132
275
 
133
- - Yield farming opportunities
134
- - Stake LP tokens and earn rewards
135
- - [View Farms Documentation](https://docs.aftermath.finance/developers/aftermath-ts-sdk/products/farms)
276
+ `Balance` is `bigint` and usually represents the coin's smallest unit. Check
277
+ the method or field documentation when a value uses another unit. `Timestamp`
278
+ is a `number` and can represent milliseconds or seconds. A field name ending
279
+ in `Ms` identifies milliseconds, but the containing method remains the final
280
+ authority.
136
281
 
137
- ### DCA (Dollar-Cost Averaging)
282
+ `Slippage`, `Percentage`, `Apr`, and `Apy` are decimal fractions in the SDK's
283
+ general type aliases. For example, `0.01` represents 1%. `Bps` uses integer
284
+ basis points, so `100` represents 1%.
138
285
 
139
- - Automated periodic investments
140
- - Reduce impact of market volatility
141
- - [View DCA Documentation](https://docs.aftermath.finance/developers/aftermath-ts-sdk/products/DCA)
286
+ The package root re-exports the request and response interfaces listed in
287
+ `src/index.ts`. Let TypeScript infer a method's return type when possible, and
288
+ use the generated reference to look up an exported named type before
289
+ constructing an input object.
142
290
 
143
- ## Rate Limits
291
+ ## Rate limits and support
144
292
 
145
- Default rate limit: 1000 requests per 10 seconds
293
+ The default Aftermath API rate limit is 1,000 requests per 10 seconds. Contact
294
+ Aftermath if your application needs a higher limit:
146
295
 
147
- For higher limits, contact us via:
296
+ - [Telegram](https://t.me/aftermath_fi)
297
+ - [Discord](https://discord.gg/VFqMUqKHF3)
298
+ - [X](https://x.com/AftermathFi)
148
299
 
149
- - [Telegram](https://t.me/aftermath_fi)
150
- - [Discord](https://discord.gg/VFqMUqKHF3)
151
- - [X/Twitter](https://x.com/AftermathFi)
300
+ Report SDK issues in the [GitHub issue tracker](https://github.com/AftermathFinance/aftermath-ts-sdk/issues).