aftermath-ts-sdk 2.2.1-dev.5bbac96 → 2.3.0-dev.719b327
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 +168 -53
- package/dist/index.js +356 -105
- 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.
|
|
@@ -14973,15 +15198,11 @@ var init_dca = __esm({
|
|
|
14973
15198
|
* The user can sign this message (converted to bytes) locally, then submit the signature to
|
|
14974
15199
|
* `closeDcaOrder`.
|
|
14975
15200
|
*
|
|
15201
|
+
* @deprecated af-fe no longer accepts this per-action message. Sign
|
|
15202
|
+
* `UserData.createTermsAndConditionsMessage` and pass `orderObjectIds` in the
|
|
15203
|
+
* `closeDcaOrder` body instead (AFX-382).
|
|
14976
15204
|
* @param inputs - An object containing `orderIds`, an array of order object IDs to cancel.
|
|
14977
15205
|
* @returns An object with `action: "CANCEL_DCA_ORDERS"` and the `order_object_ids`.
|
|
14978
|
-
*
|
|
14979
|
-
* @example
|
|
14980
|
-
* ```typescript
|
|
14981
|
-
* const msg = dca.closeDcaOrdersMessageToSign({ orderIds: ["0x<order1>", "0x<order2>"] });
|
|
14982
|
-
* console.log(msg);
|
|
14983
|
-
* // sign this as JSON or string-encode, then pass to closeDcaOrder
|
|
14984
|
-
* ```
|
|
14985
15206
|
*/
|
|
14986
15207
|
closeDcaOrdersMessageToSign(inputs) {
|
|
14987
15208
|
return {
|
|
@@ -15165,16 +15386,11 @@ var init_limitOrders = __esm({
|
|
|
15165
15386
|
* signs this message (converted to bytes), and the resulting signature is passed
|
|
15166
15387
|
* to `cancelLimitOrder`.
|
|
15167
15388
|
*
|
|
15389
|
+
* @deprecated af-fe no longer accepts this per-action message. Sign
|
|
15390
|
+
* `UserData.createTermsAndConditionsMessage` and pass `orderObjectIds` in the
|
|
15391
|
+
* `cancelLimitOrder` body instead (AFX-382).
|
|
15168
15392
|
* @param inputs - Object with `orderIds`, an array of order object IDs to cancel.
|
|
15169
15393
|
* @returns A JSON structure with the action and order IDs to be canceled.
|
|
15170
|
-
*
|
|
15171
|
-
* @example
|
|
15172
|
-
* ```typescript
|
|
15173
|
-
* const msg = limitOrders.cancelLimitOrdersMessageToSign({
|
|
15174
|
-
* orderIds: ["0x<order1>", "0x<order2>"]
|
|
15175
|
-
* });
|
|
15176
|
-
* // user signs this JSON
|
|
15177
|
-
* ```
|
|
15178
15394
|
*/
|
|
15179
15395
|
cancelLimitOrdersMessageToSign(inputs) {
|
|
15180
15396
|
return {
|
|
@@ -15341,6 +15557,11 @@ var init_referrals = __esm({
|
|
|
15341
15557
|
// date: Date.now(),
|
|
15342
15558
|
// };
|
|
15343
15559
|
// }
|
|
15560
|
+
/**
|
|
15561
|
+
* @deprecated af-fe no longer accepts this per-action message. Sign
|
|
15562
|
+
* `UserData.createTermsAndConditionsMessage` and pass `refCode` in the
|
|
15563
|
+
* `createReferralLink` body instead (AFX-382).
|
|
15564
|
+
*/
|
|
15344
15565
|
createReferralLinkMessageToSign(inputs) {
|
|
15345
15566
|
return {
|
|
15346
15567
|
action: "CREATE_REFERRAL",
|
|
@@ -15348,6 +15569,11 @@ var init_referrals = __esm({
|
|
|
15348
15569
|
date: Math.round(Date.now() / 1e3)
|
|
15349
15570
|
};
|
|
15350
15571
|
}
|
|
15572
|
+
/**
|
|
15573
|
+
* @deprecated af-fe no longer accepts this per-action message. Sign
|
|
15574
|
+
* `UserData.createTermsAndConditionsMessage` and pass `refCode` in the
|
|
15575
|
+
* `setReferrer` body instead (AFX-382).
|
|
15576
|
+
*/
|
|
15351
15577
|
setReferrerMessageToSign(inputs) {
|
|
15352
15578
|
return {
|
|
15353
15579
|
action: "LINK_REFERRAL",
|
|
@@ -15424,12 +15650,12 @@ var init_rewards = __esm({
|
|
|
15424
15650
|
});
|
|
15425
15651
|
|
|
15426
15652
|
// src/packages/userData/userData.ts
|
|
15427
|
-
var UserData;
|
|
15653
|
+
var _UserData, UserData;
|
|
15428
15654
|
var init_userData = __esm({
|
|
15429
15655
|
"src/packages/userData/userData.ts"() {
|
|
15430
15656
|
"use strict";
|
|
15431
15657
|
init_caller();
|
|
15432
|
-
|
|
15658
|
+
_UserData = class _UserData extends Caller {
|
|
15433
15659
|
// =========================================================================
|
|
15434
15660
|
// Constructor
|
|
15435
15661
|
// =========================================================================
|
|
@@ -15511,25 +15737,48 @@ var init_userData = __esm({
|
|
|
15511
15737
|
};
|
|
15512
15738
|
}
|
|
15513
15739
|
/**
|
|
15514
|
-
*
|
|
15515
|
-
*
|
|
15740
|
+
* Returns the canonical Terms and Conditions message to sign. Sign it as a
|
|
15741
|
+
* personal message over its UTF-8 bytes and reuse the signature for the whole
|
|
15742
|
+
* session: it is the one credential af-fe verifies for referrals, rewards,
|
|
15743
|
+
* stop/twap order datas, collateral/order history, the websocket `user`
|
|
15744
|
+
* subscription, and gas-pool sponsorship (AFX-382).
|
|
15516
15745
|
*
|
|
15517
|
-
* @returns
|
|
15746
|
+
* @returns The exact string to sign.
|
|
15518
15747
|
*
|
|
15519
15748
|
* @example
|
|
15520
15749
|
* ```typescript
|
|
15521
|
-
* const
|
|
15522
|
-
* const
|
|
15523
|
-
*
|
|
15524
|
-
*
|
|
15750
|
+
* const message = new UserData().createTermsAndConditionsMessage();
|
|
15751
|
+
* const { bytes, signature } = await signPersonalMessage(
|
|
15752
|
+
* new TextEncoder().encode(message)
|
|
15753
|
+
* );
|
|
15525
15754
|
* ```
|
|
15526
15755
|
*/
|
|
15756
|
+
createTermsAndConditionsMessage() {
|
|
15757
|
+
return _UserData.termsAndConditionsMessage;
|
|
15758
|
+
}
|
|
15759
|
+
/**
|
|
15760
|
+
* Generates a simple message object that the user should sign to confirm their agreement
|
|
15761
|
+
* with the Terms and Conditions of the service.
|
|
15762
|
+
*
|
|
15763
|
+
* @deprecated af-fe no longer accepts the `{action:...}` wrapper and rejects
|
|
15764
|
+
* it with error 2034. Sign {@link createTermsAndConditionsMessage} instead
|
|
15765
|
+
* (AFX-382).
|
|
15766
|
+
* @returns An object with an `action` property set to "SIGN_TERMS_AND_CONDITIONS".
|
|
15767
|
+
*/
|
|
15527
15768
|
createSignTermsAndConditionsMessageToSign() {
|
|
15528
15769
|
return {
|
|
15529
15770
|
action: "SIGN_TERMS_AND_CONDITIONS"
|
|
15530
15771
|
};
|
|
15531
15772
|
}
|
|
15532
15773
|
};
|
|
15774
|
+
/**
|
|
15775
|
+
* The single message every wallet signs once per session to prove ownership.
|
|
15776
|
+
* af-fe decodes the personal-message bytes and compares this text byte for
|
|
15777
|
+
* byte, so it must stay exactly this string: no JSON wrapper, action, date,
|
|
15778
|
+
* or trailing whitespace (AFX-382).
|
|
15779
|
+
*/
|
|
15780
|
+
_UserData.termsAndConditionsMessage = "Aftermath Terms and Conditions";
|
|
15781
|
+
UserData = _UserData;
|
|
15533
15782
|
}
|
|
15534
15783
|
});
|
|
15535
15784
|
|
|
@@ -23552,22 +23801,22 @@ var init_aftermath = __esm({
|
|
|
23552
23801
|
* returns a ready-to-use instance. Pass `addresses` or `api` to skip
|
|
23553
23802
|
* the corresponding bootstrap steps.
|
|
23554
23803
|
*/
|
|
23555
|
-
static async create(options = {}) {
|
|
23804
|
+
static async create(options = {}, abortSignal) {
|
|
23556
23805
|
const af = new _Aftermath(options);
|
|
23557
|
-
await af.bootstrap();
|
|
23806
|
+
await af.bootstrap(abortSignal);
|
|
23558
23807
|
return af;
|
|
23559
23808
|
}
|
|
23560
23809
|
/**
|
|
23561
23810
|
* Resolves addresses and wires up the internal `AftermathApi`. Called
|
|
23562
23811
|
* exactly once by the {@link Aftermath.create} factory.
|
|
23563
23812
|
*/
|
|
23564
|
-
async bootstrap() {
|
|
23813
|
+
async bootstrap(abortSignal) {
|
|
23565
23814
|
if (this.options.api) {
|
|
23566
23815
|
this.api = this.options.api;
|
|
23567
23816
|
return;
|
|
23568
23817
|
}
|
|
23569
23818
|
const network = this.network;
|
|
23570
|
-
const addresses = this.options.addresses ?? await this.getAddresses();
|
|
23819
|
+
const addresses = this.options.addresses ?? await this.getAddresses(abortSignal);
|
|
23571
23820
|
const fullnodeUrl = this.options.fullnodeUrl ?? Caller.defaultFullnodeUrl(network);
|
|
23572
23821
|
const client = new SuiGrpcClient({
|
|
23573
23822
|
network: network.toLowerCase(),
|
|
@@ -23599,8 +23848,8 @@ var init_aftermath = __esm({
|
|
|
23599
23848
|
* directly from the API. Typically you don't need to call this — the
|
|
23600
23849
|
* `create` factory handles it. Useful for cache warmers or tooling.
|
|
23601
23850
|
*/
|
|
23602
|
-
getAddresses() {
|
|
23603
|
-
return this.fetchApi("addresses");
|
|
23851
|
+
getAddresses(abortSignal) {
|
|
23852
|
+
return this.fetchApi("addresses", void 0, abortSignal);
|
|
23604
23853
|
}
|
|
23605
23854
|
/**
|
|
23606
23855
|
* Attempts to decode a raw Move abort/error string into a structured
|
|
@@ -23647,6 +23896,7 @@ init_index();
|
|
|
23647
23896
|
export {
|
|
23648
23897
|
Aftermath,
|
|
23649
23898
|
AftermathApi,
|
|
23899
|
+
AftermathTransportError,
|
|
23650
23900
|
Auth,
|
|
23651
23901
|
Casting,
|
|
23652
23902
|
Coin,
|
|
@@ -23676,6 +23926,7 @@ export {
|
|
|
23676
23926
|
SuiFren,
|
|
23677
23927
|
SuiFrens,
|
|
23678
23928
|
SuiFrensSortOption,
|
|
23929
|
+
isAftermathTransportError,
|
|
23679
23930
|
isAllocatedCollateralEvent,
|
|
23680
23931
|
isCanceledOrderEvent,
|
|
23681
23932
|
isDeallocatedCollateralEvent,
|