aftermath-ts-sdk 2.2.0 → 2.2.1-dev.32c4013
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 +34 -0
- package/dist/index.d.ts +94 -26
- package/dist/index.js +310 -83
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1868,6 +1868,148 @@ var init_helpers = __esm({
|
|
|
1868
1868
|
}
|
|
1869
1869
|
});
|
|
1870
1870
|
|
|
1871
|
+
// src/general/utils/transportError.ts
|
|
1872
|
+
function defaultMessage(kind, status) {
|
|
1873
|
+
if (kind === "http") {
|
|
1874
|
+
return status === void 0 ? "Aftermath HTTP request failed" : `Aftermath HTTP request failed with status ${status}`;
|
|
1875
|
+
}
|
|
1876
|
+
if (kind === "network") {
|
|
1877
|
+
return "Aftermath network request failed";
|
|
1878
|
+
}
|
|
1879
|
+
if (kind === "abort") {
|
|
1880
|
+
return "Aftermath request was aborted";
|
|
1881
|
+
}
|
|
1882
|
+
if (kind === "timeout") {
|
|
1883
|
+
return "Aftermath request timed out";
|
|
1884
|
+
}
|
|
1885
|
+
return "Aftermath response could not be decoded";
|
|
1886
|
+
}
|
|
1887
|
+
function isAftermathTransportError(error) {
|
|
1888
|
+
return error instanceof AftermathTransportError;
|
|
1889
|
+
}
|
|
1890
|
+
function getProperty(value, property) {
|
|
1891
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") {
|
|
1892
|
+
return void 0;
|
|
1893
|
+
}
|
|
1894
|
+
try {
|
|
1895
|
+
return value[property];
|
|
1896
|
+
} catch {
|
|
1897
|
+
return void 0;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
function getStringProperty(value, property) {
|
|
1901
|
+
const propertyValue = getProperty(value, property);
|
|
1902
|
+
return typeof propertyValue === "string" ? propertyValue : void 0;
|
|
1903
|
+
}
|
|
1904
|
+
function getStringCode(value) {
|
|
1905
|
+
return getStringProperty(value, "code");
|
|
1906
|
+
}
|
|
1907
|
+
function isTimeoutCode(code) {
|
|
1908
|
+
return code !== void 0 && TIMEOUT_CODES.has(code);
|
|
1909
|
+
}
|
|
1910
|
+
function isTimeoutReason(reason) {
|
|
1911
|
+
if (isAftermathTransportError(reason) && (reason.kind === "timeout" || reason.abortSource === "timeout")) {
|
|
1912
|
+
return true;
|
|
1913
|
+
}
|
|
1914
|
+
return getProperty(reason, "name") === "TimeoutError" || isTimeoutCode(getStringCode(reason));
|
|
1915
|
+
}
|
|
1916
|
+
function parseRetryAfter(headerValue, nowMs = Date.now()) {
|
|
1917
|
+
if (headerValue === null) {
|
|
1918
|
+
return void 0;
|
|
1919
|
+
}
|
|
1920
|
+
const value = headerValue.trim();
|
|
1921
|
+
if (value === "") {
|
|
1922
|
+
return void 0;
|
|
1923
|
+
}
|
|
1924
|
+
if (DELTA_SECONDS_REGEX.test(value)) {
|
|
1925
|
+
const milliseconds = BigInt(value) * 1000n;
|
|
1926
|
+
return milliseconds <= MAX_SAFE_INTEGER_BIGINT ? Number(milliseconds) : void 0;
|
|
1927
|
+
}
|
|
1928
|
+
if (!HTTP_DATE_REGEX.test(value)) {
|
|
1929
|
+
return void 0;
|
|
1930
|
+
}
|
|
1931
|
+
const dateMs = Date.parse(value);
|
|
1932
|
+
if (!Number.isFinite(dateMs)) {
|
|
1933
|
+
return void 0;
|
|
1934
|
+
}
|
|
1935
|
+
const retryAfterMs = dateMs - nowMs;
|
|
1936
|
+
return retryAfterMs >= 0 && Number.isSafeInteger(retryAfterMs) ? retryAfterMs : void 0;
|
|
1937
|
+
}
|
|
1938
|
+
function normalizeAftermathTransportError(error, signal) {
|
|
1939
|
+
if (isAftermathTransportError(error)) {
|
|
1940
|
+
return error;
|
|
1941
|
+
}
|
|
1942
|
+
const errorCode = getStringCode(error);
|
|
1943
|
+
const signalReason = signal?.aborted ? signal.reason : void 0;
|
|
1944
|
+
const signalReasonCode = getStringCode(signalReason);
|
|
1945
|
+
const code = errorCode ?? signalReasonCode;
|
|
1946
|
+
if (signal?.aborted) {
|
|
1947
|
+
const timeout = isTimeoutReason(signalReason) || isTimeoutReason(error);
|
|
1948
|
+
return new AftermathTransportError(timeout ? "timeout" : "abort", {
|
|
1949
|
+
abortSource: timeout ? "timeout" : "caller",
|
|
1950
|
+
cause: error,
|
|
1951
|
+
code
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
if (isTimeoutReason(error)) {
|
|
1955
|
+
return new AftermathTransportError("timeout", {
|
|
1956
|
+
abortSource: "timeout",
|
|
1957
|
+
cause: error,
|
|
1958
|
+
code: errorCode
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
return new AftermathTransportError("network", {
|
|
1962
|
+
cause: error,
|
|
1963
|
+
code: errorCode
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
var MAX_SAFE_INTEGER_BIGINT, DELTA_SECONDS_REGEX, HTTP_DATE_REGEX, TIMEOUT_CODES, AftermathTransportError;
|
|
1967
|
+
var init_transportError = __esm({
|
|
1968
|
+
"src/general/utils/transportError.ts"() {
|
|
1969
|
+
"use strict";
|
|
1970
|
+
MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
1971
|
+
DELTA_SECONDS_REGEX = /^\d+$/;
|
|
1972
|
+
HTTP_DATE_REGEX = /^(?:[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT|[A-Za-z]+, \d{2}-[A-Za-z]{3}-\d{2} \d{2}:\d{2}:\d{2} GMT|[A-Za-z]{3} [A-Za-z]{3} {1,2}\d{1,2} \d{2}:\d{2}:\d{2} \d{4})$/;
|
|
1973
|
+
TIMEOUT_CODES = /* @__PURE__ */ new Set([
|
|
1974
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
1975
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
1976
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
1977
|
+
"ETIMEDOUT"
|
|
1978
|
+
]);
|
|
1979
|
+
AftermathTransportError = class extends Error {
|
|
1980
|
+
constructor(kind, options = {}) {
|
|
1981
|
+
const causeMessage = getStringProperty(options.cause, "message");
|
|
1982
|
+
super(
|
|
1983
|
+
options.message ?? causeMessage ?? defaultMessage(kind, options.status)
|
|
1984
|
+
);
|
|
1985
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
1986
|
+
this.name = options.name ?? getStringProperty(options.cause, "name") ?? "AftermathTransportError";
|
|
1987
|
+
this.kind = kind;
|
|
1988
|
+
if (options.status !== void 0) {
|
|
1989
|
+
this.status = options.status;
|
|
1990
|
+
}
|
|
1991
|
+
if (options.retryAfterMs !== void 0) {
|
|
1992
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
1993
|
+
}
|
|
1994
|
+
if (options.code !== void 0) {
|
|
1995
|
+
this.code = options.code;
|
|
1996
|
+
}
|
|
1997
|
+
if (options.abortSource !== void 0) {
|
|
1998
|
+
this.abortSource = options.abortSource;
|
|
1999
|
+
}
|
|
2000
|
+
if (options.cause !== void 0) {
|
|
2001
|
+
Object.defineProperty(this, "cause", {
|
|
2002
|
+
configurable: true,
|
|
2003
|
+
enumerable: false,
|
|
2004
|
+
value: options.cause,
|
|
2005
|
+
writable: false
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
|
|
1871
2013
|
// src/general/utils/caller.ts
|
|
1872
2014
|
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
1873
2015
|
function bigIntReplacer(_key, value) {
|
|
@@ -1881,6 +2023,7 @@ var init_caller = __esm({
|
|
|
1881
2023
|
"src/general/utils/caller.ts"() {
|
|
1882
2024
|
"use strict";
|
|
1883
2025
|
init_helpers();
|
|
2026
|
+
init_transportError();
|
|
1884
2027
|
_Caller = class _Caller {
|
|
1885
2028
|
// =========================================================================
|
|
1886
2029
|
// Constructor
|
|
@@ -1908,11 +2051,26 @@ var init_caller = __esm({
|
|
|
1908
2051
|
static async fetchResponseToType(response, disableBigIntJsonParsing) {
|
|
1909
2052
|
if (!response.ok) {
|
|
1910
2053
|
const status = response.status;
|
|
2054
|
+
const retryAfterMs = parseRetryAfter(response.headers.get("Retry-After"));
|
|
2055
|
+
const statusText = response.statusText;
|
|
1911
2056
|
const body = await response.text();
|
|
1912
|
-
throw new
|
|
2057
|
+
throw new AftermathTransportError("http", {
|
|
2058
|
+
message: `HTTP ${status} ${statusText}: ${body}`,
|
|
2059
|
+
name: "Error",
|
|
2060
|
+
retryAfterMs,
|
|
2061
|
+
status
|
|
2062
|
+
});
|
|
1913
2063
|
}
|
|
1914
2064
|
const text = await response.text();
|
|
1915
|
-
|
|
2065
|
+
let output;
|
|
2066
|
+
try {
|
|
2067
|
+
output = disableBigIntJsonParsing ? JSON.parse(
|
|
2068
|
+
text,
|
|
2069
|
+
(_key, value) => value === null ? void 0 : value
|
|
2070
|
+
) : Helpers.parseJsonWithBigint(text);
|
|
2071
|
+
} catch (cause) {
|
|
2072
|
+
throw new AftermathTransportError("decode", { cause });
|
|
2073
|
+
}
|
|
1916
2074
|
return output ?? void 0;
|
|
1917
2075
|
}
|
|
1918
2076
|
/**
|
|
@@ -1937,21 +2095,25 @@ var init_caller = __esm({
|
|
|
1937
2095
|
// Api Calling
|
|
1938
2096
|
// =========================================================================
|
|
1939
2097
|
async fetchApi(url, body, signal, options) {
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
2098
|
+
try {
|
|
2099
|
+
const apiCallUrl = this.urlForApiCall(url);
|
|
2100
|
+
const headers = {
|
|
2101
|
+
"Content-Type": "application/json",
|
|
2102
|
+
...this.config.accessToken ? { Authorization: `Bearer ${this.config.accessToken}` } : {}
|
|
2103
|
+
};
|
|
2104
|
+
const uncastResponse = await (body === void 0 ? fetch(apiCallUrl, { headers, signal }) : fetch(apiCallUrl, {
|
|
2105
|
+
method: "POST",
|
|
2106
|
+
body: JSON.stringify(body, bigIntReplacer),
|
|
2107
|
+
headers,
|
|
2108
|
+
signal
|
|
2109
|
+
}));
|
|
2110
|
+
return await _Caller.fetchResponseToType(
|
|
2111
|
+
uncastResponse,
|
|
2112
|
+
!!options?.disableBigIntJsonParsing
|
|
2113
|
+
);
|
|
2114
|
+
} catch (error) {
|
|
2115
|
+
throw normalizeAftermathTransportError(error, signal);
|
|
2116
|
+
}
|
|
1955
2117
|
}
|
|
1956
2118
|
async fetchApiTransaction(url, body, signal, options) {
|
|
1957
2119
|
const txKind = await this.fetchApi(
|
|
@@ -2117,10 +2279,13 @@ var init_prices = __esm({
|
|
|
2117
2279
|
* console.log(suiPriceInfo.price, suiPriceInfo.priceChange24HoursPercentage);
|
|
2118
2280
|
* ```
|
|
2119
2281
|
*/
|
|
2120
|
-
async getCoinPriceInfo(inputs) {
|
|
2121
|
-
const coinsToPriceInfo = await this.getCoinsToPriceInfo(
|
|
2122
|
-
|
|
2123
|
-
|
|
2282
|
+
async getCoinPriceInfo(inputs, abortSignal) {
|
|
2283
|
+
const coinsToPriceInfo = await this.getCoinsToPriceInfo(
|
|
2284
|
+
{
|
|
2285
|
+
coins: [inputs.coin]
|
|
2286
|
+
},
|
|
2287
|
+
abortSignal
|
|
2288
|
+
);
|
|
2124
2289
|
return Object.values(coinsToPriceInfo)[0];
|
|
2125
2290
|
}
|
|
2126
2291
|
/**
|
|
@@ -2139,8 +2304,8 @@ var init_prices = __esm({
|
|
|
2139
2304
|
* console.log(info);
|
|
2140
2305
|
* ```
|
|
2141
2306
|
*/
|
|
2142
|
-
async getCoinsToPriceInfo(inputs) {
|
|
2143
|
-
return this.fetchApi("", inputs);
|
|
2307
|
+
async getCoinsToPriceInfo(inputs, abortSignal) {
|
|
2308
|
+
return this.fetchApi("", inputs, abortSignal);
|
|
2144
2309
|
}
|
|
2145
2310
|
/**
|
|
2146
2311
|
* Fetches only the current price in USD for a single coin.
|
|
@@ -2155,8 +2320,8 @@ var init_prices = __esm({
|
|
|
2155
2320
|
* console.log("SUI price in USD:", suiPrice);
|
|
2156
2321
|
* ```
|
|
2157
2322
|
*/
|
|
2158
|
-
async getCoinPrice(inputs) {
|
|
2159
|
-
const priceInfo = await this.getCoinPriceInfo(inputs);
|
|
2323
|
+
async getCoinPrice(inputs, abortSignal) {
|
|
2324
|
+
const priceInfo = await this.getCoinPriceInfo(inputs, abortSignal);
|
|
2160
2325
|
return priceInfo.price;
|
|
2161
2326
|
}
|
|
2162
2327
|
/**
|
|
@@ -2172,8 +2337,11 @@ var init_prices = __esm({
|
|
|
2172
2337
|
* console.log(multiPrices["0x2::sui::SUI"]); // e.g. 1.23
|
|
2173
2338
|
* ```
|
|
2174
2339
|
*/
|
|
2175
|
-
async getCoinsToPrice(inputs) {
|
|
2176
|
-
const coinsToPriceInfo = await this.getCoinsToPriceInfo(
|
|
2340
|
+
async getCoinsToPrice(inputs, abortSignal) {
|
|
2341
|
+
const coinsToPriceInfo = await this.getCoinsToPriceInfo(
|
|
2342
|
+
inputs,
|
|
2343
|
+
abortSignal
|
|
2344
|
+
);
|
|
2177
2345
|
const coinsToPrice = Object.entries(coinsToPriceInfo).reduce(
|
|
2178
2346
|
(acc, [coinType, info]) => ({
|
|
2179
2347
|
...acc,
|
|
@@ -2234,9 +2402,9 @@ var init_coin = __esm({
|
|
|
2234
2402
|
* console.log(decimals); // { "0x2::sui::SUI": 9, "0x<...>": 6 }
|
|
2235
2403
|
* ```
|
|
2236
2404
|
*/
|
|
2237
|
-
async getCoinsToDecimals(inputs) {
|
|
2405
|
+
async getCoinsToDecimals(inputs, abortSignal) {
|
|
2238
2406
|
const { coins } = inputs;
|
|
2239
|
-
const metadatas = await this.getCoinMetadatas(inputs);
|
|
2407
|
+
const metadatas = await this.getCoinMetadatas(inputs, abortSignal);
|
|
2240
2408
|
const coinsToDecimals = metadatas.map((data) => data.decimals).reduce((acc, decimals, index) => {
|
|
2241
2409
|
return { ...acc, [coins[index]]: decimals };
|
|
2242
2410
|
}, {});
|
|
@@ -2256,7 +2424,7 @@ var init_coin = __esm({
|
|
|
2256
2424
|
* console.log(metadata.name, metadata.symbol, metadata.decimals);
|
|
2257
2425
|
* ```
|
|
2258
2426
|
*/
|
|
2259
|
-
async getCoinMetadata(coin) {
|
|
2427
|
+
async getCoinMetadata(coin, abortSignal) {
|
|
2260
2428
|
if (this.metadata) {
|
|
2261
2429
|
return this.metadata;
|
|
2262
2430
|
}
|
|
@@ -2264,7 +2432,10 @@ var init_coin = __esm({
|
|
|
2264
2432
|
if (!coinType) {
|
|
2265
2433
|
throw new Error("no valid coin type");
|
|
2266
2434
|
}
|
|
2267
|
-
const [metadata] = await this.getCoinMetadatas(
|
|
2435
|
+
const [metadata] = await this.getCoinMetadatas(
|
|
2436
|
+
{ coins: [coinType] },
|
|
2437
|
+
abortSignal
|
|
2438
|
+
);
|
|
2268
2439
|
this.setCoinMetadata(metadata);
|
|
2269
2440
|
return metadata;
|
|
2270
2441
|
}
|
|
@@ -2283,12 +2454,13 @@ var init_coin = __esm({
|
|
|
2283
2454
|
* console.log(metas[0].symbol, metas[1].symbol);
|
|
2284
2455
|
* ```
|
|
2285
2456
|
*/
|
|
2286
|
-
async getCoinMetadatas(inputs) {
|
|
2457
|
+
async getCoinMetadatas(inputs, abortSignal) {
|
|
2287
2458
|
return this.fetchApi(
|
|
2288
2459
|
"metadata",
|
|
2289
2460
|
{
|
|
2290
2461
|
coins: inputs.coins.map((coin) => Helpers.addLeadingZeroesToType(coin))
|
|
2291
|
-
}
|
|
2462
|
+
},
|
|
2463
|
+
abortSignal
|
|
2292
2464
|
);
|
|
2293
2465
|
}
|
|
2294
2466
|
/**
|
|
@@ -2313,7 +2485,7 @@ var init_coin = __esm({
|
|
|
2313
2485
|
* console.log(priceInfo.price, priceInfo.priceChange24HoursPercentage);
|
|
2314
2486
|
* ```
|
|
2315
2487
|
*/
|
|
2316
|
-
async getPrice(coin) {
|
|
2488
|
+
async getPrice(coin, abortSignal) {
|
|
2317
2489
|
if (this.priceInfo !== void 0) {
|
|
2318
2490
|
return this.priceInfo;
|
|
2319
2491
|
}
|
|
@@ -2321,9 +2493,12 @@ var init_coin = __esm({
|
|
|
2321
2493
|
if (!coinType) {
|
|
2322
2494
|
throw new Error("no valid coin type");
|
|
2323
2495
|
}
|
|
2324
|
-
const priceInfo = await new Prices(this.config).getCoinPriceInfo(
|
|
2325
|
-
|
|
2326
|
-
|
|
2496
|
+
const priceInfo = await new Prices(this.config).getCoinPriceInfo(
|
|
2497
|
+
{
|
|
2498
|
+
coin: coinType
|
|
2499
|
+
},
|
|
2500
|
+
abortSignal
|
|
2501
|
+
);
|
|
2327
2502
|
this.setPriceInfo(priceInfo);
|
|
2328
2503
|
return priceInfo;
|
|
2329
2504
|
}
|
|
@@ -4794,6 +4969,7 @@ var init_utils = __esm({
|
|
|
4794
4969
|
init_casting();
|
|
4795
4970
|
init_grpcCasting();
|
|
4796
4971
|
init_helpers();
|
|
4972
|
+
init_transportError();
|
|
4797
4973
|
}
|
|
4798
4974
|
});
|
|
4799
4975
|
|
|
@@ -5292,10 +5468,13 @@ var init_farmsStakingPool = __esm({
|
|
|
5292
5468
|
* console.log(poolTvl);
|
|
5293
5469
|
* ```
|
|
5294
5470
|
*/
|
|
5295
|
-
async getTVL() {
|
|
5296
|
-
return new Farms(this.config, this.api).getTVL(
|
|
5297
|
-
|
|
5298
|
-
|
|
5471
|
+
async getTVL(abortSignal) {
|
|
5472
|
+
return new Farms(this.config, this.api).getTVL(
|
|
5473
|
+
{
|
|
5474
|
+
farmIds: [this.stakingPool.objectId]
|
|
5475
|
+
},
|
|
5476
|
+
abortSignal
|
|
5477
|
+
);
|
|
5299
5478
|
}
|
|
5300
5479
|
/**
|
|
5301
5480
|
* Fetches the total value locked (TVL) of the reward coins in this specific staking pool.
|
|
@@ -5308,10 +5487,13 @@ var init_farmsStakingPool = __esm({
|
|
|
5308
5487
|
* console.log(rewardTvl);
|
|
5309
5488
|
* ```
|
|
5310
5489
|
*/
|
|
5311
|
-
async getRewardsTVL() {
|
|
5312
|
-
return new Farms(this.config, this.api).getRewardsTVL(
|
|
5313
|
-
|
|
5314
|
-
|
|
5490
|
+
async getRewardsTVL(abortSignal) {
|
|
5491
|
+
return new Farms(this.config, this.api).getRewardsTVL(
|
|
5492
|
+
{
|
|
5493
|
+
farmIds: [this.stakingPool.objectId]
|
|
5494
|
+
},
|
|
5495
|
+
abortSignal
|
|
5496
|
+
);
|
|
5315
5497
|
}
|
|
5316
5498
|
// =========================================================================
|
|
5317
5499
|
// Transactions
|
|
@@ -6031,9 +6213,11 @@ var init_farms = __esm({
|
|
|
6031
6213
|
* console.log(pool.stakingPool);
|
|
6032
6214
|
* ```
|
|
6033
6215
|
*/
|
|
6034
|
-
async getStakingPool(inputs) {
|
|
6216
|
+
async getStakingPool(inputs, abortSignal) {
|
|
6035
6217
|
const stakingPool = await this.fetchApi(
|
|
6036
|
-
inputs.objectId
|
|
6218
|
+
inputs.objectId,
|
|
6219
|
+
void 0,
|
|
6220
|
+
abortSignal
|
|
6037
6221
|
);
|
|
6038
6222
|
return new FarmsStakingPool(stakingPool, this.config, this.api);
|
|
6039
6223
|
}
|
|
@@ -6051,10 +6235,14 @@ var init_farms = __esm({
|
|
|
6051
6235
|
* console.log(pools[0].stakingPool, pools[1].stakingPool);
|
|
6052
6236
|
* ```
|
|
6053
6237
|
*/
|
|
6054
|
-
async getStakingPools(inputs) {
|
|
6055
|
-
const stakingPools = await this.fetchApi(
|
|
6056
|
-
|
|
6057
|
-
|
|
6238
|
+
async getStakingPools(inputs, abortSignal) {
|
|
6239
|
+
const stakingPools = await this.fetchApi(
|
|
6240
|
+
"",
|
|
6241
|
+
{
|
|
6242
|
+
farmIds: inputs.objectIds
|
|
6243
|
+
},
|
|
6244
|
+
abortSignal
|
|
6245
|
+
);
|
|
6058
6246
|
return stakingPools.map(
|
|
6059
6247
|
(stakingPool) => new FarmsStakingPool(stakingPool, this.config, this.api)
|
|
6060
6248
|
);
|
|
@@ -6070,8 +6258,12 @@ var init_farms = __esm({
|
|
|
6070
6258
|
* console.log(allPools.map(pool => pool.stakingPool));
|
|
6071
6259
|
* ```
|
|
6072
6260
|
*/
|
|
6073
|
-
async getAllStakingPools() {
|
|
6074
|
-
const stakingPools = await this.fetchApi(
|
|
6261
|
+
async getAllStakingPools(abortSignal) {
|
|
6262
|
+
const stakingPools = await this.fetchApi(
|
|
6263
|
+
"",
|
|
6264
|
+
{},
|
|
6265
|
+
abortSignal
|
|
6266
|
+
);
|
|
6075
6267
|
return stakingPools.map(
|
|
6076
6268
|
(pool) => new FarmsStakingPool(pool, this.config, this.api)
|
|
6077
6269
|
);
|
|
@@ -6150,8 +6342,8 @@ var init_farms = __esm({
|
|
|
6150
6342
|
* console.log("Specific farm's TVL:", tvlForSpecificFarm);
|
|
6151
6343
|
* ```
|
|
6152
6344
|
*/
|
|
6153
|
-
async getTVL(inputs) {
|
|
6154
|
-
return this.fetchApi("tvl", inputs ?? {});
|
|
6345
|
+
async getTVL(inputs, abortSignal) {
|
|
6346
|
+
return this.fetchApi("tvl", inputs ?? {}, abortSignal);
|
|
6155
6347
|
}
|
|
6156
6348
|
/**
|
|
6157
6349
|
* Retrieves the total value locked (TVL) of reward coins across specified farm IDs or all farms if none are specified.
|
|
@@ -6168,8 +6360,19 @@ var init_farms = __esm({
|
|
|
6168
6360
|
* console.log("Single farm's rewards TVL:", singleFarmRewardsTvl);
|
|
6169
6361
|
* ```
|
|
6170
6362
|
*/
|
|
6171
|
-
async getRewardsTVL(inputs) {
|
|
6172
|
-
return this.fetchApi("rewards-tvl", inputs ?? {});
|
|
6363
|
+
async getRewardsTVL(inputs, abortSignal) {
|
|
6364
|
+
return this.fetchApi("rewards-tvl", inputs ?? {}, abortSignal);
|
|
6365
|
+
}
|
|
6366
|
+
/**
|
|
6367
|
+
* Fetches TVL and reward TVL for multiple farms in a single batch response.
|
|
6368
|
+
* When `farmIds` is omitted, the API returns summaries for all farms.
|
|
6369
|
+
*
|
|
6370
|
+
* @param inputs - Optionally provide the farm IDs to include.
|
|
6371
|
+
* @param abortSignal - An optional signal for cancelling the request.
|
|
6372
|
+
* @returns TVL and reward TVL metrics for each requested farm.
|
|
6373
|
+
*/
|
|
6374
|
+
async getFarmSummaries(inputs, abortSignal) {
|
|
6375
|
+
return this.fetchApi("summary", inputs ?? {}, abortSignal);
|
|
6173
6376
|
}
|
|
6174
6377
|
// =========================================================================
|
|
6175
6378
|
// Transactions
|
|
@@ -8569,10 +8772,13 @@ var init_pools = __esm({
|
|
|
8569
8772
|
* console.log(poolId);
|
|
8570
8773
|
* ```
|
|
8571
8774
|
*/
|
|
8572
|
-
this.getPoolObjectIdForLpCoinType = (inputs) => {
|
|
8573
|
-
return this.getPoolObjectIdsForLpCoinTypes(
|
|
8574
|
-
|
|
8575
|
-
|
|
8775
|
+
this.getPoolObjectIdForLpCoinType = (inputs, abortSignal) => {
|
|
8776
|
+
return this.getPoolObjectIdsForLpCoinTypes(
|
|
8777
|
+
{
|
|
8778
|
+
lpCoinTypes: [inputs.lpCoinType]
|
|
8779
|
+
},
|
|
8780
|
+
abortSignal
|
|
8781
|
+
);
|
|
8576
8782
|
};
|
|
8577
8783
|
/**
|
|
8578
8784
|
* Checks if a given coin type is recognized as an LP coin.
|
|
@@ -8581,8 +8787,8 @@ var init_pools = __esm({
|
|
|
8581
8787
|
* @param inputs - Contains the `lpCoinType` to check.
|
|
8582
8788
|
* @returns `true` if the coin is an LP token, `false` otherwise.
|
|
8583
8789
|
*/
|
|
8584
|
-
this.isLpCoinType = async (inputs) => {
|
|
8585
|
-
const result = await this.getPoolObjectIdForLpCoinType(inputs);
|
|
8790
|
+
this.isLpCoinType = async (inputs, abortSignal) => {
|
|
8791
|
+
const result = await this.getPoolObjectIdForLpCoinType(inputs, abortSignal);
|
|
8586
8792
|
return result.some((id) => id !== void 0);
|
|
8587
8793
|
};
|
|
8588
8794
|
/**
|
|
@@ -8632,8 +8838,12 @@ var init_pools = __esm({
|
|
|
8632
8838
|
* console.log(pool.pool.lpCoinType, pool.pool.name);
|
|
8633
8839
|
* ```
|
|
8634
8840
|
*/
|
|
8635
|
-
async getPool(inputs) {
|
|
8636
|
-
const pool = await this.fetchApi(
|
|
8841
|
+
async getPool(inputs, abortSignal) {
|
|
8842
|
+
const pool = await this.fetchApi(
|
|
8843
|
+
inputs.objectId,
|
|
8844
|
+
void 0,
|
|
8845
|
+
abortSignal
|
|
8846
|
+
);
|
|
8637
8847
|
return new Pool(pool, this.config, this.api);
|
|
8638
8848
|
}
|
|
8639
8849
|
/**
|
|
@@ -8648,10 +8858,14 @@ var init_pools = __esm({
|
|
|
8648
8858
|
* console.log(poolArray.length);
|
|
8649
8859
|
* ```
|
|
8650
8860
|
*/
|
|
8651
|
-
async getPools(inputs) {
|
|
8652
|
-
const pools = await this.fetchApi(
|
|
8653
|
-
|
|
8654
|
-
|
|
8861
|
+
async getPools(inputs, abortSignal) {
|
|
8862
|
+
const pools = await this.fetchApi(
|
|
8863
|
+
"",
|
|
8864
|
+
{
|
|
8865
|
+
poolIds: inputs.objectIds
|
|
8866
|
+
},
|
|
8867
|
+
abortSignal
|
|
8868
|
+
);
|
|
8655
8869
|
return pools.map((pool) => new Pool(pool, this.config, this.api));
|
|
8656
8870
|
}
|
|
8657
8871
|
/**
|
|
@@ -8665,8 +8879,8 @@ var init_pools = __esm({
|
|
|
8665
8879
|
* console.log(allPools.map(p => p.pool.name));
|
|
8666
8880
|
* ```
|
|
8667
8881
|
*/
|
|
8668
|
-
async getAllPools() {
|
|
8669
|
-
const pools = await this.fetchApi("", {});
|
|
8882
|
+
async getAllPools(abortSignal) {
|
|
8883
|
+
const pools = await this.fetchApi("", {}, abortSignal);
|
|
8670
8884
|
return pools.map((pool) => new Pool(pool, this.config, this.api));
|
|
8671
8885
|
}
|
|
8672
8886
|
/**
|
|
@@ -8756,8 +8970,8 @@ var init_pools = __esm({
|
|
|
8756
8970
|
* console.log(poolIds);
|
|
8757
8971
|
* ```
|
|
8758
8972
|
*/
|
|
8759
|
-
async getPoolObjectIdsForLpCoinTypes(inputs) {
|
|
8760
|
-
return this.fetchApi("pool-object-ids", inputs);
|
|
8973
|
+
async getPoolObjectIdsForLpCoinTypes(inputs, abortSignal) {
|
|
8974
|
+
return this.fetchApi("pool-object-ids", inputs, abortSignal);
|
|
8761
8975
|
}
|
|
8762
8976
|
/**
|
|
8763
8977
|
* Retrieves the total value locked (TVL) across all or specific pool IDs.
|
|
@@ -8787,8 +9001,19 @@ var init_pools = __esm({
|
|
|
8787
9001
|
* console.log(stats[0].volume, stats[1].tvl);
|
|
8788
9002
|
* ```
|
|
8789
9003
|
*/
|
|
8790
|
-
async getPoolsStats(inputs) {
|
|
8791
|
-
return this.fetchApi("stats", inputs);
|
|
9004
|
+
async getPoolsStats(inputs, abortSignal) {
|
|
9005
|
+
return this.fetchApi("stats", inputs, abortSignal);
|
|
9006
|
+
}
|
|
9007
|
+
/**
|
|
9008
|
+
* Fetches pool objects and their statistics in a single batch response.
|
|
9009
|
+
* When `poolIds` is omitted, the API returns summaries for all pools.
|
|
9010
|
+
*
|
|
9011
|
+
* @param inputs - Optionally provide the pool IDs to include.
|
|
9012
|
+
* @param abortSignal - An optional signal for cancelling the request.
|
|
9013
|
+
* @returns Pool objects paired with their current statistics.
|
|
9014
|
+
*/
|
|
9015
|
+
async getPoolSummaries(inputs, abortSignal) {
|
|
9016
|
+
return this.fetchApi("summary", inputs ?? {}, abortSignal);
|
|
8792
9017
|
}
|
|
8793
9018
|
/**
|
|
8794
9019
|
* Returns all DAO fee pool owner capabilities owned by a particular user.
|
|
@@ -15396,11 +15621,11 @@ var init_rewards = __esm({
|
|
|
15396
15621
|
/**
|
|
15397
15622
|
* Preview a single account's expected rewards for an epoch, broken down by
|
|
15398
15623
|
* domain (trading, referral, AFLP, integrator) plus totals. Backed by the
|
|
15399
|
-
* newer `rewards/
|
|
15624
|
+
* newer `rewards/expected-rewards` endpoint. Provide exactly one of `address`
|
|
15400
15625
|
* or `accountId`; omit `epoch` for the current epoch.
|
|
15401
15626
|
*/
|
|
15402
15627
|
async getExpectedRewards(inputs) {
|
|
15403
|
-
return this.fetchApi("
|
|
15628
|
+
return this.fetchApi("expected-rewards", inputs);
|
|
15404
15629
|
}
|
|
15405
15630
|
// =========================================================================
|
|
15406
15631
|
// Transactions
|
|
@@ -23552,22 +23777,22 @@ var init_aftermath = __esm({
|
|
|
23552
23777
|
* returns a ready-to-use instance. Pass `addresses` or `api` to skip
|
|
23553
23778
|
* the corresponding bootstrap steps.
|
|
23554
23779
|
*/
|
|
23555
|
-
static async create(options = {}) {
|
|
23780
|
+
static async create(options = {}, abortSignal) {
|
|
23556
23781
|
const af = new _Aftermath(options);
|
|
23557
|
-
await af.bootstrap();
|
|
23782
|
+
await af.bootstrap(abortSignal);
|
|
23558
23783
|
return af;
|
|
23559
23784
|
}
|
|
23560
23785
|
/**
|
|
23561
23786
|
* Resolves addresses and wires up the internal `AftermathApi`. Called
|
|
23562
23787
|
* exactly once by the {@link Aftermath.create} factory.
|
|
23563
23788
|
*/
|
|
23564
|
-
async bootstrap() {
|
|
23789
|
+
async bootstrap(abortSignal) {
|
|
23565
23790
|
if (this.options.api) {
|
|
23566
23791
|
this.api = this.options.api;
|
|
23567
23792
|
return;
|
|
23568
23793
|
}
|
|
23569
23794
|
const network = this.network;
|
|
23570
|
-
const addresses = this.options.addresses ?? await this.getAddresses();
|
|
23795
|
+
const addresses = this.options.addresses ?? await this.getAddresses(abortSignal);
|
|
23571
23796
|
const fullnodeUrl = this.options.fullnodeUrl ?? Caller.defaultFullnodeUrl(network);
|
|
23572
23797
|
const client = new SuiGrpcClient({
|
|
23573
23798
|
network: network.toLowerCase(),
|
|
@@ -23599,8 +23824,8 @@ var init_aftermath = __esm({
|
|
|
23599
23824
|
* directly from the API. Typically you don't need to call this — the
|
|
23600
23825
|
* `create` factory handles it. Useful for cache warmers or tooling.
|
|
23601
23826
|
*/
|
|
23602
|
-
getAddresses() {
|
|
23603
|
-
return this.fetchApi("addresses");
|
|
23827
|
+
getAddresses(abortSignal) {
|
|
23828
|
+
return this.fetchApi("addresses", void 0, abortSignal);
|
|
23604
23829
|
}
|
|
23605
23830
|
/**
|
|
23606
23831
|
* Attempts to decode a raw Move abort/error string into a structured
|
|
@@ -23647,6 +23872,7 @@ init_index();
|
|
|
23647
23872
|
export {
|
|
23648
23873
|
Aftermath,
|
|
23649
23874
|
AftermathApi,
|
|
23875
|
+
AftermathTransportError,
|
|
23650
23876
|
Auth,
|
|
23651
23877
|
Casting,
|
|
23652
23878
|
Coin,
|
|
@@ -23676,6 +23902,7 @@ export {
|
|
|
23676
23902
|
SuiFren,
|
|
23677
23903
|
SuiFrens,
|
|
23678
23904
|
SuiFrensSortOption,
|
|
23905
|
+
isAftermathTransportError,
|
|
23679
23906
|
isAllocatedCollateralEvent,
|
|
23680
23907
|
isCanceledOrderEvent,
|
|
23681
23908
|
isDeallocatedCollateralEvent,
|