@autonomys/auto-utils 1.5.17 → 1.5.18
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/dist/constants/token.d.ts +1 -0
- package/dist/constants/token.d.ts.map +1 -1
- package/dist/constants/token.js +2 -1
- package/dist/number.d.ts +76 -0
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +83 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const DEFAULT_TOKEN_DECIMALS = 18;
|
|
2
2
|
export declare const DEFAULT_TOKEN_SYMBOL = "AI3";
|
|
3
3
|
export declare const DEFAULT_TOKEN_NAME = "Auto Token";
|
|
4
|
+
export declare const DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS: bigint;
|
|
4
5
|
export declare const DEFAULT_TOKEN: {
|
|
5
6
|
decimals: number;
|
|
6
7
|
symbol: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/constants/token.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,eAAO,MAAM,oBAAoB,QAAQ,CAAA;AAEzC,eAAO,MAAM,kBAAkB,eAAe,CAAA;AAE9C,eAAO,MAAM,aAAa;;;;CAIzB,CAAA;AAED,eAAO,MAAM,aAAa;;;;CAIzB,CAAA"}
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/constants/token.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,eAAO,MAAM,oBAAoB,QAAQ,CAAA;AAEzC,eAAO,MAAM,kBAAkB,eAAe,CAAA;AAE9C,eAAO,MAAM,oCAAoC,QAAwB,CAAA;AAEzE,eAAO,MAAM,aAAa;;;;CAIzB,CAAA;AAED,eAAO,MAAM,aAAa;;;;CAIzB,CAAA"}
|
package/dist/constants/token.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TESTNET_TOKEN = exports.DEFAULT_TOKEN = exports.DEFAULT_TOKEN_NAME = exports.DEFAULT_TOKEN_SYMBOL = exports.DEFAULT_TOKEN_DECIMALS = void 0;
|
|
3
|
+
exports.TESTNET_TOKEN = exports.DEFAULT_TOKEN = exports.DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS = exports.DEFAULT_TOKEN_NAME = exports.DEFAULT_TOKEN_SYMBOL = exports.DEFAULT_TOKEN_DECIMALS = void 0;
|
|
4
4
|
exports.DEFAULT_TOKEN_DECIMALS = 18;
|
|
5
5
|
exports.DEFAULT_TOKEN_SYMBOL = 'AI3';
|
|
6
6
|
exports.DEFAULT_TOKEN_NAME = 'Auto Token';
|
|
7
|
+
exports.DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS = BigInt(1000000000000);
|
|
7
8
|
exports.DEFAULT_TOKEN = {
|
|
8
9
|
decimals: exports.DEFAULT_TOKEN_DECIMALS,
|
|
9
10
|
symbol: exports.DEFAULT_TOKEN_SYMBOL,
|
package/dist/number.d.ts
CHANGED
|
@@ -171,4 +171,80 @@ export declare const ai3ToShannons: (ai3Amount: string, options?: {
|
|
|
171
171
|
export declare const shannonsToAi3: (shannons: bigint | string, options?: {
|
|
172
172
|
trimTrailingZeros?: boolean;
|
|
173
173
|
}) => string;
|
|
174
|
+
/**
|
|
175
|
+
* Checks if an AI3 amount meets the Autonomys Network existential deposit requirement.
|
|
176
|
+
*
|
|
177
|
+
* The existential deposit (ED) is the minimum balance required to keep an account active
|
|
178
|
+
* on the Autonomys Network. Accounts with balances below the ED may be reaped (removed)
|
|
179
|
+
* by the network, and their funds will be destroyed to prevent storage bloat.
|
|
180
|
+
*
|
|
181
|
+
* This function accepts AI3 amounts as strings and performs string-to-BigInt conversion.
|
|
182
|
+
* For direct Shannon (BigInt) validation, use `meetsExistentialDepositShannons` instead.
|
|
183
|
+
*
|
|
184
|
+
* For Autonomys Network, the existential deposit is 0.000001 AI3 (1,000,000,000,000 Shannons).
|
|
185
|
+
*
|
|
186
|
+
* @param amount - AI3 amount as a decimal string (e.g., "1.5", "0.000001")
|
|
187
|
+
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
188
|
+
* @throws Error if the amount format is invalid (same validation as ai3ToShannons)
|
|
189
|
+
* @see meetsExistentialDepositShannons - for direct Shannon (BigInt) validation
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* import { meetsExistentialDepositAi3 } from '@autonomys/auto-utils'
|
|
193
|
+
*
|
|
194
|
+
* // Check if amount meets ED requirement
|
|
195
|
+
* const amount = "0.000001"
|
|
196
|
+
* if (meetsExistentialDepositAi3(amount)) {
|
|
197
|
+
* console.log('Amount meets existential deposit requirement')
|
|
198
|
+
* } else {
|
|
199
|
+
* console.log(`Amount too low. Minimum required: 0.000001 AI3`)
|
|
200
|
+
* }
|
|
201
|
+
*
|
|
202
|
+
* // Examples of different amounts
|
|
203
|
+
* console.log(meetsExistentialDepositAi3("0.0000005")) // false - below ED
|
|
204
|
+
* console.log(meetsExistentialDepositAi3("0.000001")) // true - exactly at ED
|
|
205
|
+
* console.log(meetsExistentialDepositAi3("0.000002")) // true - above ED
|
|
206
|
+
* console.log(meetsExistentialDepositAi3("1")) // true - well above ED
|
|
207
|
+
*
|
|
208
|
+
* // Will throw error for invalid formats
|
|
209
|
+
* try {
|
|
210
|
+
* meetsExistentialDepositAi3("invalid")
|
|
211
|
+
* } catch (error) {
|
|
212
|
+
* console.error("Invalid amount format")
|
|
213
|
+
* }
|
|
214
|
+
*/
|
|
215
|
+
export declare const meetsExistentialDepositAi3: (amount: string) => boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Checks if a Shannon amount meets the Autonomys Network existential deposit requirement.
|
|
218
|
+
*
|
|
219
|
+
* This is the Shannon-based version of `meetsExistentialDepositAi3` that works directly with
|
|
220
|
+
* BigInt values in the smallest units (Shannons). It's more efficient when you already
|
|
221
|
+
* have amounts in Shannon units and don't need string parsing.
|
|
222
|
+
*
|
|
223
|
+
* For Autonomys Network, the existential deposit is 1,000,000,000,000 Shannons (0.000001 AI3).
|
|
224
|
+
*
|
|
225
|
+
* @param amount - Shannon amount as BigInt (smallest units)
|
|
226
|
+
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* import { meetsExistentialDepositShannons, DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS } from '@autonomys/auto-utils'
|
|
230
|
+
*
|
|
231
|
+
* // Check if Shannon amount meets ED requirement
|
|
232
|
+
* const shannons = BigInt('1000000000000') // 0.000001 AI3
|
|
233
|
+
* if (meetsExistentialDepositShannons(shannons)) {
|
|
234
|
+
* console.log('Amount meets existential deposit requirement')
|
|
235
|
+
* }
|
|
236
|
+
*
|
|
237
|
+
* // Examples with different Shannon amounts
|
|
238
|
+
* console.log(meetsExistentialDepositShannons(BigInt('999999999999'))) // false - below ED
|
|
239
|
+
* console.log(meetsExistentialDepositShannons(BigInt('1000000000000'))) // true - exactly at ED
|
|
240
|
+
* console.log(meetsExistentialDepositShannons(BigInt('2000000000000'))) // true - above ED
|
|
241
|
+
* console.log(meetsExistentialDepositShannons(BigInt('1000000000000000000'))) // true - 1 AI3
|
|
242
|
+
*
|
|
243
|
+
* // Works with the constant directly
|
|
244
|
+
* console.log(meetsExistentialDepositShannons(DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS)) // true
|
|
245
|
+
*
|
|
246
|
+
* // Handles negative amounts
|
|
247
|
+
* console.log(meetsExistentialDepositShannons(BigInt('-1000000000000'))) // false
|
|
248
|
+
*/
|
|
249
|
+
export declare const meetsExistentialDepositShannons: (amount: bigint) => boolean;
|
|
174
250
|
//# sourceMappingURL=number.d.ts.map
|
package/dist/number.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,MAAM,GAAG,MAAM,EACvB,WAAU,MAA+B,oBAI1C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,GAAG,MAAM,EACvB,WAAU,MAA+B,oBAI1C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,iBAAY,WAU7D,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,MAAM,EACb,WAAU,MAA+B,EACzC,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;CAAO,KACnE,MA2DF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,OAAO,MAAM,GAAG,MAAM,EACtB,WAAU,MAA+B,EACzC,UAAS;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,KAC5C,MAkBF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,MAAM,EACjB,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;CAAO,KACnE,MAAgE,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,GAAG,MAAM,EACzB,UAAS;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,KAC5C,MAAgE,CAAA"}
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,+BAA+B,GAAI,QAAQ,MAAM,KAAG,OAEhE,CAAA"}
|
package/dist/number.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shannonsToAi3 = exports.ai3ToShannons = exports.formatUnits = exports.parseUnits = exports.formatSpacePledged = exports.formatTokenAmount = exports.parseTokenAmount = void 0;
|
|
3
|
+
exports.meetsExistentialDepositShannons = exports.meetsExistentialDepositAi3 = exports.shannonsToAi3 = exports.ai3ToShannons = exports.formatUnits = exports.parseUnits = exports.formatSpacePledged = exports.formatTokenAmount = exports.parseTokenAmount = void 0;
|
|
4
4
|
const number_1 = require("./constants/number");
|
|
5
5
|
const token_1 = require("./constants/token");
|
|
6
6
|
/**
|
|
@@ -263,3 +263,85 @@ exports.ai3ToShannons = ai3ToShannons;
|
|
|
263
263
|
*/
|
|
264
264
|
const shannonsToAi3 = (shannons, options = {}) => (0, exports.formatUnits)(shannons, token_1.DEFAULT_TOKEN_DECIMALS, options);
|
|
265
265
|
exports.shannonsToAi3 = shannonsToAi3;
|
|
266
|
+
/**
|
|
267
|
+
* Checks if an AI3 amount meets the Autonomys Network existential deposit requirement.
|
|
268
|
+
*
|
|
269
|
+
* The existential deposit (ED) is the minimum balance required to keep an account active
|
|
270
|
+
* on the Autonomys Network. Accounts with balances below the ED may be reaped (removed)
|
|
271
|
+
* by the network, and their funds will be destroyed to prevent storage bloat.
|
|
272
|
+
*
|
|
273
|
+
* This function accepts AI3 amounts as strings and performs string-to-BigInt conversion.
|
|
274
|
+
* For direct Shannon (BigInt) validation, use `meetsExistentialDepositShannons` instead.
|
|
275
|
+
*
|
|
276
|
+
* For Autonomys Network, the existential deposit is 0.000001 AI3 (1,000,000,000,000 Shannons).
|
|
277
|
+
*
|
|
278
|
+
* @param amount - AI3 amount as a decimal string (e.g., "1.5", "0.000001")
|
|
279
|
+
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
280
|
+
* @throws Error if the amount format is invalid (same validation as ai3ToShannons)
|
|
281
|
+
* @see meetsExistentialDepositShannons - for direct Shannon (BigInt) validation
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* import { meetsExistentialDepositAi3 } from '@autonomys/auto-utils'
|
|
285
|
+
*
|
|
286
|
+
* // Check if amount meets ED requirement
|
|
287
|
+
* const amount = "0.000001"
|
|
288
|
+
* if (meetsExistentialDepositAi3(amount)) {
|
|
289
|
+
* console.log('Amount meets existential deposit requirement')
|
|
290
|
+
* } else {
|
|
291
|
+
* console.log(`Amount too low. Minimum required: 0.000001 AI3`)
|
|
292
|
+
* }
|
|
293
|
+
*
|
|
294
|
+
* // Examples of different amounts
|
|
295
|
+
* console.log(meetsExistentialDepositAi3("0.0000005")) // false - below ED
|
|
296
|
+
* console.log(meetsExistentialDepositAi3("0.000001")) // true - exactly at ED
|
|
297
|
+
* console.log(meetsExistentialDepositAi3("0.000002")) // true - above ED
|
|
298
|
+
* console.log(meetsExistentialDepositAi3("1")) // true - well above ED
|
|
299
|
+
*
|
|
300
|
+
* // Will throw error for invalid formats
|
|
301
|
+
* try {
|
|
302
|
+
* meetsExistentialDepositAi3("invalid")
|
|
303
|
+
* } catch (error) {
|
|
304
|
+
* console.error("Invalid amount format")
|
|
305
|
+
* }
|
|
306
|
+
*/
|
|
307
|
+
const meetsExistentialDepositAi3 = (amount) => {
|
|
308
|
+
return (0, exports.meetsExistentialDepositShannons)((0, exports.ai3ToShannons)(amount));
|
|
309
|
+
};
|
|
310
|
+
exports.meetsExistentialDepositAi3 = meetsExistentialDepositAi3;
|
|
311
|
+
/**
|
|
312
|
+
* Checks if a Shannon amount meets the Autonomys Network existential deposit requirement.
|
|
313
|
+
*
|
|
314
|
+
* This is the Shannon-based version of `meetsExistentialDepositAi3` that works directly with
|
|
315
|
+
* BigInt values in the smallest units (Shannons). It's more efficient when you already
|
|
316
|
+
* have amounts in Shannon units and don't need string parsing.
|
|
317
|
+
*
|
|
318
|
+
* For Autonomys Network, the existential deposit is 1,000,000,000,000 Shannons (0.000001 AI3).
|
|
319
|
+
*
|
|
320
|
+
* @param amount - Shannon amount as BigInt (smallest units)
|
|
321
|
+
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* import { meetsExistentialDepositShannons, DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS } from '@autonomys/auto-utils'
|
|
325
|
+
*
|
|
326
|
+
* // Check if Shannon amount meets ED requirement
|
|
327
|
+
* const shannons = BigInt('1000000000000') // 0.000001 AI3
|
|
328
|
+
* if (meetsExistentialDepositShannons(shannons)) {
|
|
329
|
+
* console.log('Amount meets existential deposit requirement')
|
|
330
|
+
* }
|
|
331
|
+
*
|
|
332
|
+
* // Examples with different Shannon amounts
|
|
333
|
+
* console.log(meetsExistentialDepositShannons(BigInt('999999999999'))) // false - below ED
|
|
334
|
+
* console.log(meetsExistentialDepositShannons(BigInt('1000000000000'))) // true - exactly at ED
|
|
335
|
+
* console.log(meetsExistentialDepositShannons(BigInt('2000000000000'))) // true - above ED
|
|
336
|
+
* console.log(meetsExistentialDepositShannons(BigInt('1000000000000000000'))) // true - 1 AI3
|
|
337
|
+
*
|
|
338
|
+
* // Works with the constant directly
|
|
339
|
+
* console.log(meetsExistentialDepositShannons(DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS)) // true
|
|
340
|
+
*
|
|
341
|
+
* // Handles negative amounts
|
|
342
|
+
* console.log(meetsExistentialDepositShannons(BigInt('-1000000000000'))) // false
|
|
343
|
+
*/
|
|
344
|
+
const meetsExistentialDepositShannons = (amount) => {
|
|
345
|
+
return amount >= token_1.DEFAULT_EXISTENTIAL_DEPOSIT_SHANNONS;
|
|
346
|
+
};
|
|
347
|
+
exports.meetsExistentialDepositShannons = meetsExistentialDepositShannons;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-utils",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"ts-jest": "^29.3.1",
|
|
40
40
|
"typescript": "^5.8.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "b339864e15c46187ddcc75ebeed3d8170fbe7c9e"
|
|
43
43
|
}
|