aftermath-ts-sdk 1.2.64 → 1.2.65

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.
Files changed (114) hide show
  1. package/dist/general/dynamicGas/dynamicGas.d.ts +34 -0
  2. package/dist/general/dynamicGas/dynamicGas.d.ts.map +1 -1
  3. package/dist/general/dynamicGas/dynamicGas.js +34 -0
  4. package/dist/general/dynamicGas/dynamicGasTypes.d.ts +25 -0
  5. package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +1 -1
  6. package/dist/general/prices/prices.d.ts +73 -0
  7. package/dist/general/prices/prices.d.ts.map +1 -1
  8. package/dist/general/prices/prices.js +73 -0
  9. package/dist/general/providers/aftermath.d.ts +106 -25
  10. package/dist/general/providers/aftermath.d.ts.map +1 -1
  11. package/dist/general/providers/aftermath.js +108 -27
  12. package/dist/general/providers/aftermathApi.d.ts +127 -8
  13. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  14. package/dist/general/providers/aftermathApi.js +132 -12
  15. package/dist/general/types/castingTypes.d.ts +0 -7
  16. package/dist/general/types/castingTypes.d.ts.map +1 -1
  17. package/dist/general/types/castingTypes.js +6 -0
  18. package/dist/general/types/generalTypes.d.ts +228 -7
  19. package/dist/general/types/generalTypes.d.ts.map +1 -1
  20. package/dist/general/types/suiTypes.d.ts +0 -16
  21. package/dist/general/types/suiTypes.d.ts.map +1 -1
  22. package/dist/general/types/suiTypes.js +3 -25
  23. package/dist/general/utils/casting.d.ts +159 -3
  24. package/dist/general/utils/casting.d.ts.map +1 -1
  25. package/dist/general/utils/casting.js +162 -16
  26. package/dist/general/utils/fixedUtils.d.ts +89 -2
  27. package/dist/general/utils/fixedUtils.d.ts.map +1 -1
  28. package/dist/general/utils/fixedUtils.js +81 -4
  29. package/dist/general/utils/helpers.d.ts +320 -9
  30. package/dist/general/utils/helpers.d.ts.map +1 -1
  31. package/dist/general/utils/helpers.js +350 -89
  32. package/dist/general/utils/iFixedUtils.d.ts +64 -0
  33. package/dist/general/utils/iFixedUtils.d.ts.map +1 -1
  34. package/dist/general/utils/iFixedUtils.js +64 -0
  35. package/dist/general/wallet/wallet.d.ts +75 -0
  36. package/dist/general/wallet/wallet.d.ts.map +1 -1
  37. package/dist/general/wallet/wallet.js +75 -5
  38. package/dist/packages/auth/auth.d.ts +113 -0
  39. package/dist/packages/auth/auth.d.ts.map +1 -1
  40. package/dist/packages/auth/auth.js +129 -15
  41. package/dist/packages/auth/authTypes.d.ts +66 -0
  42. package/dist/packages/auth/authTypes.d.ts.map +1 -1
  43. package/dist/packages/coin/coin.d.ts +250 -0
  44. package/dist/packages/coin/coin.d.ts.map +1 -1
  45. package/dist/packages/coin/coin.js +238 -14
  46. package/dist/packages/coin/coinTypes.d.ts +93 -0
  47. package/dist/packages/coin/coinTypes.d.ts.map +1 -1
  48. package/dist/packages/dca/dca.d.ts +124 -35
  49. package/dist/packages/dca/dca.d.ts.map +1 -1
  50. package/dist/packages/dca/dca.js +127 -37
  51. package/dist/packages/dca/dcaTypes.d.ts +213 -28
  52. package/dist/packages/dca/dcaTypes.d.ts.map +1 -1
  53. package/dist/packages/farms/farms.d.ts +184 -1
  54. package/dist/packages/farms/farms.d.ts.map +1 -1
  55. package/dist/packages/farms/farms.js +185 -11
  56. package/dist/packages/farms/farmsStakedPosition.d.ts +140 -6
  57. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  58. package/dist/packages/farms/farmsStakedPosition.js +189 -144
  59. package/dist/packages/farms/farmsStakingPool.d.ts +161 -1
  60. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  61. package/dist/packages/farms/farmsStakingPool.js +176 -70
  62. package/dist/packages/farms/farmsTypes.d.ts +283 -2
  63. package/dist/packages/farms/farmsTypes.d.ts.map +1 -1
  64. package/dist/packages/farms/farmsTypes.js +18 -0
  65. package/dist/packages/limitOrders/limitOrders.d.ts +108 -21
  66. package/dist/packages/limitOrders/limitOrders.d.ts.map +1 -1
  67. package/dist/packages/limitOrders/limitOrders.js +110 -22
  68. package/dist/packages/limitOrders/limitOrdersTypes.d.ts +142 -0
  69. package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +1 -1
  70. package/dist/packages/multisig/multisig.d.ts +33 -4
  71. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  72. package/dist/packages/multisig/multisig.js +33 -4
  73. package/dist/packages/multisig/multisigTypes.d.ts +17 -0
  74. package/dist/packages/multisig/multisigTypes.d.ts.map +1 -1
  75. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  76. package/dist/packages/pools/pool.d.ts +327 -85
  77. package/dist/packages/pools/pool.d.ts.map +1 -1
  78. package/dist/packages/pools/pool.js +333 -91
  79. package/dist/packages/pools/pools.d.ts +299 -37
  80. package/dist/packages/pools/pools.d.ts.map +1 -1
  81. package/dist/packages/pools/pools.js +306 -52
  82. package/dist/packages/pools/poolsTypes.d.ts +267 -2
  83. package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
  84. package/dist/packages/referralVault/referralVault.d.ts +37 -0
  85. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  86. package/dist/packages/referralVault/referralVault.js +37 -0
  87. package/dist/packages/router/router.d.ts +213 -17
  88. package/dist/packages/router/router.d.ts.map +1 -1
  89. package/dist/packages/router/router.js +214 -18
  90. package/dist/packages/router/routerTypes.d.ts +198 -14
  91. package/dist/packages/router/routerTypes.d.ts.map +1 -1
  92. package/dist/packages/staking/staking.d.ts +301 -43
  93. package/dist/packages/staking/staking.d.ts.map +1 -1
  94. package/dist/packages/staking/staking.js +308 -51
  95. package/dist/packages/staking/stakingTypes.d.ts +426 -6
  96. package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
  97. package/dist/packages/staking/stakingTypes.js +19 -0
  98. package/dist/packages/sui/sui.d.ts +39 -0
  99. package/dist/packages/sui/sui.d.ts.map +1 -1
  100. package/dist/packages/sui/sui.js +39 -0
  101. package/dist/packages/userData/userData.d.ts +66 -12
  102. package/dist/packages/userData/userData.d.ts.map +1 -1
  103. package/dist/packages/userData/userData.js +66 -12
  104. package/dist/packages/userData/userDataTypes.d.ts +19 -0
  105. package/dist/packages/userData/userDataTypes.d.ts.map +1 -1
  106. package/dist/types.d.ts.map +1 -1
  107. package/dist/types.js +0 -1
  108. package/package.json +1 -1
  109. package/dist/general/historicalData/historicalData.d.ts +0 -15
  110. package/dist/general/historicalData/historicalData.d.ts.map +0 -1
  111. package/dist/general/historicalData/historicalData.js +0 -45
  112. package/dist/general/historicalData/historicalDataTypes.d.ts +0 -10
  113. package/dist/general/historicalData/historicalDataTypes.d.ts.map +0 -1
  114. package/dist/general/historicalData/historicalDataTypes.js +0 -2
@@ -12,42 +12,95 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Auth = void 0;
13
13
  const caller_1 = require("../../general/utils/caller");
14
14
  const utils_1 = require("../../general/utils");
15
+ /**
16
+ * The `Auth` class manages creation and refreshing of access tokens
17
+ * to obtain higher rate limits on the Aftermath API. It includes methods
18
+ * to initialize authorization either by a direct callback-based approach
19
+ * or by importing a local Sui keystore. Optionally, administrative functions
20
+ * are provided for creating specialized auth accounts.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const auth = new Auth();
25
+ * const stopAuth = await auth.init({
26
+ * walletAddress: "0x<address>",
27
+ * signMessageCallback: async ({ message }) => {
28
+ * // sign message
29
+ * },
30
+ * });
31
+ * // ... make authenticated requests ...
32
+ * stopAuth(); // stop auto refresh
33
+ * ```
34
+ */
15
35
  class Auth extends caller_1.Caller {
16
36
  // =========================================================================
17
37
  // Constructor
18
38
  // =========================================================================
39
+ /**
40
+ * Creates a new `Auth` instance for token-based rate limit increases.
41
+ *
42
+ * @param config - Optional caller configuration, including network and access token.
43
+ */
19
44
  constructor(config) {
20
45
  super(config, "auth");
21
46
  // =========================================================================
22
47
  // Private Class Members
23
48
  // =========================================================================
49
+ /**
50
+ * Holds the timer reference for scheduled token refreshes.
51
+ */
24
52
  this.refreshTimer = null;
53
+ /**
54
+ * Indicates whether the user has canceled auto token refresh.
55
+ */
25
56
  this.isCanceled = false;
26
57
  }
27
58
  // =========================================================================
28
59
  // User-Facing
29
60
  // =========================================================================
61
+ /**
62
+ * Initializes the auth system by fetching an access token for the provided wallet address.
63
+ * After obtaining the token, it automatically schedules periodic refresh calls until stopped.
64
+ *
65
+ * @param inputs - An object containing the user's `walletAddress` and a `signMessageCallback` function
66
+ * for cryptographically signing messages.
67
+ *
68
+ * @returns A function that, when called, cancels further token refresh attempts.
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const auth = new Auth();
73
+ * const stopAuth = await auth.init({
74
+ * walletAddress: "0x<address>",
75
+ * signMessageCallback: async ({ message }) => {
76
+ * // sign the message with your private key / keypair
77
+ * },
78
+ * });
79
+ *
80
+ * // ... make authorized calls ...
81
+ *
82
+ * stopAuth(); // Cancel further token refreshes
83
+ * ```
84
+ */
30
85
  init(inputs) {
31
86
  return __awaiter(this, void 0, void 0, function* () {
32
- // Step 1: Mark as "not canceled" before the new run
33
- this.isCanceled = false;
34
- // Step 2: Define a function that does the “work” + schedules next call
87
+ this.isCanceled = false; // Mark as active
35
88
  const startRefresh = () => __awaiter(this, void 0, void 0, function* () {
36
- // If canceled at the time we enter, don’t do anything
37
89
  if (this.isCanceled)
38
- return;
90
+ return; // No-op if canceled
39
91
  const { accessToken, expirationTimestamp } = yield this.getAccessToken(inputs);
40
92
  this.setAccessToken(accessToken);
41
93
  if (this.isCanceled)
42
- return; // double-check before scheduling next timer
94
+ return; // Double-check after token fetch
95
+ // Provide a margin by refreshing before actual expiration
43
96
  const TIMEOUT_REDUCTION_RATIO = 0.9;
44
97
  const interval = (expirationTimestamp - Date.now()) * TIMEOUT_REDUCTION_RATIO;
45
- // Store the timer so we can cancel it later
98
+ // Schedule next refresh
46
99
  this.refreshTimer = setTimeout(startRefresh, interval);
47
100
  });
48
- // Step 3: Kick off the first refresh
101
+ // Kick off first refresh
49
102
  yield startRefresh();
50
- // Step 4: Return a function that cancels further refreshes
103
+ // Return cancellation function
51
104
  return () => {
52
105
  this.isCanceled = true;
53
106
  if (this.refreshTimer) {
@@ -56,26 +109,48 @@ class Auth extends caller_1.Caller {
56
109
  };
57
110
  });
58
111
  }
112
+ /**
113
+ * Initializes the auth system by reading a local Sui keystore file (on the server side),
114
+ * using the private keys matching a provided address to sign messages for token creation.
115
+ * After the token is obtained, it automatically schedules periodic refresh calls until stopped.
116
+ *
117
+ * @param inputs - An object containing the target `walletAddress` and an optional path to the `.keystore`.
118
+ * If `path` is not provided, it defaults to `~/.sui/sui_config/sui.keystore`.
119
+ * @returns A function that, when called, cancels further token refresh attempts.
120
+ *
121
+ * @throws If this method is called in a browser environment (client-side).
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * // On server:
126
+ * const stopAuth = await auth.initFromSuiKeystore({
127
+ * walletAddress: "0x<address>",
128
+ * path: "/custom/path/to/keystore.json",
129
+ * });
130
+ * // authorized calls...
131
+ * stopAuth();
132
+ * ```
133
+ */
59
134
  // public async initFromSuiKeystore(inputs: {
60
135
  // walletAddress: SuiAddress;
61
136
  // path?: string;
62
137
  // }): Promise<() => void> {
63
138
  // const { walletAddress, path: pathStr } = inputs;
64
139
  // if (typeof window === "undefined") {
140
+ // // Node environment, proceed with reading a keystore
65
141
  // const fs = require("fs");
66
142
  // const path = require("path");
67
143
  // const os = require("os");
68
144
  // const keystorePath = pathStr
69
145
  // ? path.join(pathStr)
70
146
  // : (() => {
71
- // // Locate the user’s home directory
147
+ // // Default to ~/.sui/sui_config/sui.keystore
72
148
  // const homeDir = os.homedir();
73
149
  // if (!homeDir) {
74
150
  // throw new Error(
75
151
  // "cannot obtain home directory path"
76
152
  // );
77
153
  // }
78
- // // Construct the path: ~/.sui/sui_config/sui.keystore
79
154
  // return path.join(
80
155
  // homeDir,
81
156
  // ".sui",
@@ -83,7 +158,7 @@ class Auth extends caller_1.Caller {
83
158
  // "sui.keystore"
84
159
  // );
85
160
  // })();
86
- // // Read the JSON file from `keystorePath`
161
+ // // Read JSON with an array of private keys
87
162
  // let privateKeys: string[];
88
163
  // try {
89
164
  // const fileContent = fs.readFileSync(keystorePath, "utf-8");
@@ -99,6 +174,7 @@ class Auth extends caller_1.Caller {
99
174
  // if (privateKeys.length <= 0) {
100
175
  // throw new Error(`Empty keystore file`);
101
176
  // }
177
+ // // Find the matching key for the requested walletAddress
102
178
  // const foundKeypair = privateKeys
103
179
  // .map((privateKey) => Helpers.keypairFromPrivateKey(privateKey))
104
180
  // .find(
@@ -112,6 +188,7 @@ class Auth extends caller_1.Caller {
112
188
  // `No private key found in keystore file for ${walletAddress}`
113
189
  // );
114
190
  // }
191
+ // // Initialize with sign callback
115
192
  // return this.init({
116
193
  // walletAddress,
117
194
  // signMessageCallback: async ({ message }) =>
@@ -123,10 +200,24 @@ class Auth extends caller_1.Caller {
123
200
  // =========================================================================
124
201
  // Admin
125
202
  // =========================================================================
126
- // NOTE: admin only (should add docs)
203
+ /**
204
+ * **Admin-only**: Creates a new auth account with specific rate limits for a given
205
+ * `accountWalletAddress`. The `walletAddress` performing this action must have
206
+ * admin privileges, or the call will fail. Use this to create custom sub-accounts
207
+ * with limited scope or usage rates.
208
+ *
209
+ * @param inputs - Contains:
210
+ * - `walletAddress`: The admin's wallet address
211
+ * - `signMessageCallback`: The admin's signing callback
212
+ * - `accountName`: A short name or identifier for the account
213
+ * - `accountWalletAddress`: The Sui address representing this sub-account
214
+ * - `rateLimits`: An array specifying the rate limits (method-based) for the sub-account
215
+ * @returns A promise resolving to `true` if successful, otherwise throws or returns `false`.
216
+ */
127
217
  adminCreateAuthAccount(inputs) {
128
218
  return __awaiter(this, void 0, void 0, function* () {
129
219
  const { walletAddress, signMessageCallback, accountName, accountWalletAddress, rateLimits, } = inputs;
220
+ // Prepare the data to sign
130
221
  const serializedJson = Auth.createSerializedJson("AccountCreate", {
131
222
  sub: accountName,
132
223
  wallet_address: utils_1.Helpers.addLeadingZeroesToType(accountWalletAddress),
@@ -144,9 +235,17 @@ class Auth extends caller_1.Caller {
144
235
  // =========================================================================
145
236
  // Private
146
237
  // =========================================================================
238
+ /**
239
+ * Requests a new access token from the API by sending a signed message
240
+ * indicating the user wants a token.
241
+ *
242
+ * @param inputs - Contains the user's `walletAddress` and `signMessageCallback`.
243
+ * @returns A response object that includes the `accessToken` and an `expirationTimestamp`.
244
+ */
147
245
  getAccessToken(inputs) {
148
246
  return __awaiter(this, void 0, void 0, function* () {
149
247
  const { walletAddress, signMessageCallback } = inputs;
248
+ // Prepare signable data
150
249
  const serializedJson = Auth.createSerializedJson("GetAccessToken", {});
151
250
  const message = new TextEncoder().encode(serializedJson);
152
251
  const { signature } = yield signMessageCallback({ message });
@@ -160,14 +259,29 @@ class Auth extends caller_1.Caller {
160
259
  // =========================================================================
161
260
  // Private Static
162
261
  // =========================================================================
262
+ /**
263
+ * Creates a JSON string with a standard format:
264
+ * ```json
265
+ * {
266
+ * "date": <epoch-seconds>,
267
+ * "nonce": <random_number>,
268
+ * "method": <method_string>,
269
+ * "value": <passed_value>
270
+ * }
271
+ * ```
272
+ *
273
+ * @param method - A short method name describing the action ("GetAccessToken", "AccountCreate", etc.).
274
+ * @param value - The data object to embed under the `value` field.
275
+ * @returns A JSON-serialized string for signing.
276
+ */
163
277
  static createSerializedJson(method, value) {
164
278
  const timestampSeconds = Math.floor(Date.now() / 1000);
165
279
  const random = Math.floor(Math.random() * 1024 * 1024);
166
280
  const data = {
167
281
  date: timestampSeconds,
168
282
  nonce: random,
169
- method: method,
170
- value: value,
283
+ method,
284
+ value,
171
285
  };
172
286
  return JSON.stringify(data);
173
287
  }
@@ -1,6 +1,23 @@
1
1
  import { SuiAddress, Timestamp } from "../../types";
2
+ /**
3
+ * Interface specifying allowable rate limits for an auth account.
4
+ * The `p` field indicates the path or endpoint (e.g., "/pools"),
5
+ * while `m` indicates the method-based limits (GET or POST, or both).
6
+ */
2
7
  export interface RateLimit {
8
+ /**
9
+ * The path or endpoint to be rate-limited, e.g. "/pools" or "/router/trade".
10
+ */
3
11
  p: string;
12
+ /**
13
+ * The method-based limit specification.
14
+ * For example:
15
+ * ```
16
+ * { GET: { l: 100 } }
17
+ * { POST: { l: 50 } }
18
+ * { GET: { l: 100 }, POST: { l: 100 } }
19
+ * ```
20
+ */
4
21
  m: {
5
22
  GET: {
6
23
  l: number;
@@ -18,19 +35,68 @@ export interface RateLimit {
18
35
  };
19
36
  };
20
37
  }
38
+ /**
39
+ * The request body for creating a new auth account, typically
40
+ * reserved for admin usage. The admin signs a JSON containing
41
+ * an "AccountCreate" `method` plus desired sub-account data.
42
+ */
21
43
  export interface ApiCreateAuthAccountBody {
44
+ /**
45
+ * The admin's Sui address, zero-padded if necessary.
46
+ */
22
47
  walletAddress: SuiAddress;
48
+ /**
49
+ * The signature of the serialized JSON data, from the admin's private key.
50
+ */
23
51
  signature: string;
52
+ /**
53
+ * The JSON string that was signed, containing the method and sub-account details.
54
+ */
24
55
  serializedJson: string;
25
56
  }
57
+ /**
58
+ * The request body for obtaining or refreshing an access token. The user signs
59
+ * a "GetAccessToken" method message plus any relevant fields.
60
+ */
26
61
  export interface ApiGetAccessTokenBody {
62
+ /**
63
+ * The user's Sui address, zero-padded if needed.
64
+ */
27
65
  walletAddress: SuiAddress;
66
+ /**
67
+ * The signature over the JSON-serialized request data (nonce, date, etc.).
68
+ */
28
69
  signature: string;
70
+ /**
71
+ * The actual JSON string that was signed, e.g.:
72
+ * ```
73
+ * {
74
+ * "date": 1234567890,
75
+ * "nonce": 512,
76
+ * "method": "GetAccessToken",
77
+ * "value": {}
78
+ * }
79
+ * ```
80
+ */
29
81
  serializedJson: string;
30
82
  }
83
+ /**
84
+ * The response returned when a user obtains or refreshes an access token,
85
+ * containing the token string, the HTTP header name (usually "Authorization"),
86
+ * and the token's expiration timestamp in milliseconds.
87
+ */
31
88
  export interface ApiGetAccessTokenResponse {
89
+ /**
90
+ * The newly issued access token to be used in `Authorization` headers.
91
+ */
32
92
  accessToken: string;
93
+ /**
94
+ * The header key that should contain `accessToken` (e.g., "Authorization").
95
+ */
33
96
  header: string;
97
+ /**
98
+ * The UNIX timestamp (milliseconds) after which the token is invalid.
99
+ */
34
100
  expirationTimestamp: Timestamp;
35
101
  }
36
102
  //# sourceMappingURL=authTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authTypes.d.ts","sourceRoot":"","sources":["../../../src/packages/auth/authTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAUpD,MAAM,WAAW,SAAS;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EACE;QAAE,GAAG,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GACtB;QAAE,IAAI,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GACvB;QAAE,GAAG,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,IAAI,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAC/C;AAMD,MAAM,WAAW,wBAAwB;IACxC,aAAa,EAAE,UAAU,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACrC,aAAa,EAAE,UAAU,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACvB;AAMD,MAAM,WAAW,yBAAyB;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,SAAS,CAAC;CAC/B"}
1
+ {"version":3,"file":"authTypes.d.ts","sourceRoot":"","sources":["../../../src/packages/auth/authTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACzB;;OAEG;IACH,CAAC,EAAE,MAAM,CAAC;IACV;;;;;;;;OAQG;IACH,CAAC,EACE;QAAE,GAAG,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GACtB;QAAE,IAAI,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GACvB;QAAE,GAAG,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,IAAI,EAAE;YAAE,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAC/C;AAMD;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACxC;;OAEG;IACH,aAAa,EAAE,UAAU,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACrC;;OAEG;IACH,aAAa,EAAE,UAAU,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;OAUG;IACH,cAAc,EAAE,MAAM,CAAC;CACvB;AAMD;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,mBAAmB,EAAE,SAAS,CAAC;CAC/B"}
@@ -2,65 +2,315 @@ import { AnyObjectType, Balance, CallerConfig, CoinDecimal, CoinMetadaWithInfo,
2
2
  import { Caller } from "../../general/utils/caller";
3
3
  import { AftermathApi } from "../../general/providers";
4
4
  import { CoinMetadata } from "@mysten/sui/client";
5
+ /**
6
+ * The `Coin` class provides functionality to manage and inspect coin types,
7
+ * retrieve metadata and prices, and convert balances with respect to coin decimals.
8
+ * It can be instantiated with or without a specific `coinType` for convenience.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ *
13
+ * const afSdk = new Aftermath("MAINNET");
14
+ * await afSdk.init(); // initialize provider
15
+ *
16
+ * const coin = afSdk.Coin("0x2::sui::SUI");
17
+ *
18
+ * const metadata = await coin.getCoinMetadata(); // fetch metadata for SUI coin
19
+ * ```
20
+ */
5
21
  export declare class Coin extends Caller {
6
22
  readonly coinType: CoinType | undefined;
7
23
  private readonly Provider?;
24
+ /**
25
+ * Static configuration and defaults for Sui coin types, including the standard
26
+ * SUI coin type, default decimals, and coin object type path.
27
+ */
8
28
  static readonly constants: {
29
+ /**
30
+ * The canonical coin type string for SUI.
31
+ */
9
32
  suiCoinType: string;
33
+ /**
34
+ * The default number of decimals for SUI (9).
35
+ */
10
36
  suiCoinDecimals: number;
37
+ /**
38
+ * The canonical coin object type path for Sui's Move module, used in verifying coin objects.
39
+ */
11
40
  coinObjectType: string;
41
+ /**
42
+ * Default decimals for various blockchains or ecosystems. For instance,
43
+ * "sui" => 9, "evm" => 18, etc.
44
+ */
12
45
  defaultCoinDecimals: {
13
46
  sui: number;
14
47
  evm: number;
15
48
  svm: number;
16
49
  };
17
50
  };
51
+ /**
52
+ * The Move package name portion of this coin type, e.g. the middle "module" from "0x2::sui::SUI".
53
+ * Will be empty if no `coinType` is provided.
54
+ */
18
55
  readonly coinTypePackageName: string;
56
+ /**
57
+ * The final part of the coin type (the "symbol" or short name) from "0x2::sui::SUI".
58
+ * Will be empty if no `coinType` is provided.
59
+ */
19
60
  readonly coinTypeSymbol: string;
61
+ /**
62
+ * If the coin type includes a generic argument (like `Coin<0x...>`), this is extracted. Else empty.
63
+ * E.g. "0x5::coin::Coin<0x2::sui::SUI>" => "0x2::sui::SUI".
64
+ */
20
65
  readonly innerCoinType: string;
66
+ /**
67
+ * An optional cached coin metadata object retrieved by `getCoinMetadata`.
68
+ */
21
69
  metadata: CoinMetadaWithInfo | undefined;
70
+ /**
71
+ * An optional cached price info object retrieved by `getPrice`.
72
+ */
22
73
  priceInfo: CoinPriceInfo | undefined;
74
+ /**
75
+ * Creates a new instance of `Coin`.
76
+ *
77
+ * @param coinType - The coin's type string (e.g., "0x2::sui::SUI"). If omitted, methods that require a type will need it passed in manually.
78
+ * @param config - Optional caller configuration (network, access token).
79
+ * @param Provider - An optional `AftermathApi` instance for coin-specific API calls.
80
+ */
23
81
  constructor(coinType?: CoinType | undefined, config?: CallerConfig, Provider?: AftermathApi | undefined);
82
+ /**
83
+ * Retrieves the decimals for multiple coins by calling the Aftermath API for metadata
84
+ * and extracting the `decimals` property.
85
+ *
86
+ * @param inputs - An object containing an array of coin types.
87
+ * @returns An object mapping each coin type to a numeric decimal count.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const decimals = await coin.getCoinsToDecimals({ coins: ["0x2::sui::SUI", "0x<...>"] });
92
+ * console.log(decimals); // { "0x2::sui::SUI": 9, "0x<...>": 6 }
93
+ * ```
94
+ */
24
95
  getCoinsToDecimals(inputs: {
25
96
  coins: CoinType[];
26
97
  }): Promise<CoinsToDecimals>;
98
+ /**
99
+ * Fetches the metadata (name, symbol, decimals) for this coin type or a provided one,
100
+ * caching it if already requested.
101
+ *
102
+ * @param coin - Optionally override the constructor coinType.
103
+ * @returns The `CoinMetadaWithInfo` object containing metadata and optional external references.
104
+ * @throws If neither constructor nor argument coinType is available.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const metadata = await coin.getCoinMetadata("0x2::sui::SUI");
109
+ * console.log(metadata.name, metadata.symbol, metadata.decimals);
110
+ * ```
111
+ */
27
112
  getCoinMetadata(coin?: CoinType): Promise<CoinMetadaWithInfo>;
113
+ /**
114
+ * Fetches metadata for multiple coins at once, returning an array in the same order
115
+ * as the coin types requested.
116
+ *
117
+ * @param inputs - An object with `coins`, an array of coin types.
118
+ * @returns An array of `CoinMetadaWithInfo` with length matching `coins`.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const metas = await coin.getCoinMetadatas({
123
+ * coins: ["0x2::sui::SUI", "0x<custom::TOKEN>"]
124
+ * });
125
+ * console.log(metas[0].symbol, metas[1].symbol);
126
+ * ```
127
+ */
28
128
  getCoinMetadatas(inputs: {
29
129
  coins: CoinType[];
30
130
  }): Promise<CoinMetadaWithInfo[]>;
131
+ /**
132
+ * Manually sets the metadata in this Coin instance, storing it in `this.metadata`.
133
+ *
134
+ * @param metadata - A `CoinMetadaWithInfo` object to cache in this instance.
135
+ */
31
136
  setCoinMetadata(metadata: CoinMetadaWithInfo): void;
137
+ /**
138
+ * Retrieves price information (including current price and 24h change) for this coin or a provided coin.
139
+ * If already fetched, it returns the cached data.
140
+ *
141
+ * @param coin - Optionally override the constructor coinType.
142
+ * @returns A `CoinPriceInfo` with `price` and `priceChange24HoursPercentage`.
143
+ * @throws If no valid coin type is present.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const priceInfo = await coin.getPrice("0x2::sui::SUI");
148
+ * console.log(priceInfo.price, priceInfo.priceChange24HoursPercentage);
149
+ * ```
150
+ */
32
151
  getPrice(coin?: CoinType): Promise<CoinPriceInfo>;
152
+ /**
153
+ * Manually sets the price info in this Coin instance, storing it in `this.priceInfo`.
154
+ *
155
+ * @param priceInfo - A `CoinPriceInfo` object to cache in this instance.
156
+ */
33
157
  setPriceInfo(priceInfo: CoinPriceInfo): void;
158
+ /**
159
+ * Fetches a list of "verified" coin types from the Aftermath backend. Verified coins
160
+ * typically pass certain safety or liquidity checks.
161
+ *
162
+ * @returns An array of `CoinType` strings that are considered verified.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const verified = await coin.getVerifiedCoins();
167
+ * console.log(verified); // e.g. ["0x2::sui::SUI", "0x...::MYCOIN", ...]
168
+ * ```
169
+ */
34
170
  getVerifiedCoins(): Promise<string[]>;
171
+ /**
172
+ * Extracts the Move package name portion from a coin type string.
173
+ * E.g., "0x2::sui::SUI" => "sui".
174
+ *
175
+ * @param coin - The coin type string (e.g., "0x2::sui::SUI").
176
+ * @returns The middle segment of the type or empty string if not parseable.
177
+ */
35
178
  static getCoinTypePackageName: (coin: CoinType) => string;
179
+ /**
180
+ * Extracts the final part of the coin type (the symbol or short name).
181
+ * For example, "0x2::sui::SUI" => "SUI".
182
+ *
183
+ * @param coin - The coin type string.
184
+ * @returns The extracted symbol or empty string if not found.
185
+ */
36
186
  static getCoinTypeSymbol: (coin: CoinType) => string;
187
+ /**
188
+ * Extracts the inner generic argument of a coin type if present. E.g.,
189
+ * "0x2::coin::Coin<0x2::sui::SUI>" => "0x2::sui::SUI".
190
+ *
191
+ * @param coin - The coin type with a possible `<...>` suffix.
192
+ * @returns The inner type or an empty string if not found.
193
+ */
37
194
  static getInnerCoinType: (coin: CoinType) => string;
195
+ /**
196
+ * If a `KeyType` string references a type in angle brackets, extracts the type
197
+ * inside. Typically for "0x2::coin::Coin<0x2::mycoin::MYCOIN>" -> "0x2::mycoin::MYCOIN".
198
+ *
199
+ * @param keyType - The key type string to parse.
200
+ * @returns The substring inside `<...>` or the original if no brackets found.
201
+ */
38
202
  static coinTypeFromKeyType: (keyType: KeyType) => string;
203
+ /**
204
+ * Checks if a coin type string corresponds to the canonical SUI coin.
205
+ *
206
+ * @param coin - A coin type string.
207
+ * @returns `true` if it matches "0x2::sui::SUI", otherwise `false`.
208
+ */
39
209
  static isSuiCoin: (coin: CoinType) => boolean;
210
+ /**
211
+ * Checks if an object type string is a `Coin<...>` object from the standard Sui Move module.
212
+ *
213
+ * @param objectType - The object type to test.
214
+ * @returns `true` if it matches "0x2::coin::Coin<...>", otherwise `false`.
215
+ */
40
216
  static isCoinObjectType: (objectType: AnyObjectType) => boolean;
217
+ /**
218
+ * Given a record of coin types => numeric amounts, filters out those
219
+ * with zero or negative amounts, returning only the positive pairs.
220
+ *
221
+ * @param coinAmounts - A record mapping coin types to numeric amounts.
222
+ * @returns An object with `coins` array and `amounts` array in matching indexes.
223
+ */
41
224
  static coinsAndAmountsOverZero: (coinAmounts: Record<CoinType, number>) => {
42
225
  coins: string[];
43
226
  amounts: number[];
44
227
  };
228
+ /**
229
+ * Given a record of coin types => bigint balances, filters out those with zero
230
+ * or negative balances, returning only the positive pairs.
231
+ *
232
+ * @param coinsToBalance - A record mapping coin types to bigints.
233
+ * @returns An object with `coins` array and `balances` array in matching indexes.
234
+ */
45
235
  static coinsAndBalancesOverZero: (coinsToBalance: CoinsToBalance) => {
46
236
  coins: string[];
47
237
  balances: bigint[];
48
238
  };
239
+ /**
240
+ * Filters a list of `coinTypes` by a textual query, matching against both zero-padded
241
+ * and non-padded forms as well as substring checks.
242
+ *
243
+ * @param inputs - Contains `filter` (the search string) and `coinTypes`.
244
+ * @returns An array of coin types that match the filter in either raw or zero-padded form.
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * const filtered = Coin.filterCoinsByType({
249
+ * filter: "sui",
250
+ * coinTypes: ["0x2::sui::SUI", "0x<...>"]
251
+ * });
252
+ * ```
253
+ */
49
254
  static filterCoinsByType: (inputs: {
50
255
  filter: string;
51
256
  coinTypes: CoinType[];
52
257
  }) => CoinType[];
258
+ /**
259
+ * Filters a record of coin metadata by a textual query, matching both the coin type
260
+ * and the metadata's name/symbol fields.
261
+ *
262
+ * @param inputs - An object containing `filter` and a record of `coinMetadatas`.
263
+ * @returns An array of coin types that match the search criteria.
264
+ */
53
265
  static filterCoinsByMetadata: (inputs: {
54
266
  filter: string;
55
267
  coinMetadatas: Record<CoinType, CoinMetadata>;
56
268
  }) => CoinType[];
269
+ /**
270
+ * Converts a user-friendly decimal number (e.g., 1.5) to a raw on-chain
271
+ * integer representation by scaling with the given coin decimals.
272
+ * For example, `1.5` with `decimals = 9` => `1500000000n`.
273
+ *
274
+ * @param balance - The user-friendly balance as a number.
275
+ * @param decimals - Number of decimal places for this coin.
276
+ * @returns A bigint representing the raw on-chain balance.
277
+ */
57
278
  static normalizeBalance: (balance: number, decimals: CoinDecimal) => Balance;
279
+ /**
280
+ * Scales a raw bigint or numeric `amount` down by `decimals` to get a display-friendly float.
281
+ * For example, `1500000000n` with `decimals = 9` => `1.5`.
282
+ *
283
+ * @param amount - The raw on-chain amount as `bigint` or `number`.
284
+ * @param decimals - Number of decimal places for this coin.
285
+ * @returns The resulting float as an easily readable balance.
286
+ */
58
287
  static balanceWithDecimals: (amount: bigint | number, decimals: number) => number;
288
+ /**
289
+ * Scales a raw `amount` down by `decimals` and multiplies by a `price` in USD,
290
+ * returning a final USD value. E.g., `1500000000n`, `decimals=9`, `price=2.0` => `3.0`.
291
+ *
292
+ * @param amount - The raw balance as bigint or number.
293
+ * @param decimals - The coin decimals.
294
+ * @param price - The coin's price in USD.
295
+ * @returns The computed float in USD.
296
+ */
59
297
  static balanceWithDecimalsUsd: (amount: bigint | number, decimals: number, price: number) => number;
298
+ /**
299
+ * Looks up a coin's symbol if it is known in a provided `coinSymbolToCoinTypes`
300
+ * record. For instance, if "SUI" => `["0x2::sui::SUI"]`, we can find "SUI" from
301
+ * the coin type "0x2::sui::SUI".
302
+ *
303
+ * @param inputs - An object with `coinType` and `coinSymbolToCoinTypes`.
304
+ * @returns The coin symbol string or `undefined` if not found.
305
+ */
60
306
  static coinSymbolForCoinType: (inputs: {
61
307
  coinType: CoinType;
62
308
  coinSymbolToCoinTypes: CoinSymbolToCoinTypes;
63
309
  }) => CoinSymbol | undefined;
310
+ /**
311
+ * Internal method to retrieve a specialized coin-related API from `AftermathApi`.
312
+ * Throws an error if no provider is set.
313
+ */
64
314
  private useProvider;
65
315
  }
66
316
  //# sourceMappingURL=coin.d.ts.map