@ar.io/sdk 2.0.0-alpha.1 → 2.0.0-alpha.10

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 (41) hide show
  1. package/README.md +144 -60
  2. package/bundles/web.bundle.min.js +131 -98
  3. package/lib/cjs/common/ant.js +294 -3
  4. package/lib/cjs/common/contracts/ao-process.js +1 -1
  5. package/lib/cjs/common/http.js +1 -2
  6. package/lib/cjs/common/index.js +0 -1
  7. package/lib/cjs/common/io.js +87 -39
  8. package/lib/cjs/common/logger.js +31 -19
  9. package/lib/cjs/utils/http-client.js +1 -1
  10. package/lib/cjs/utils/index.js +1 -1
  11. package/lib/cjs/utils/{graphql/processes.js → processes.js} +35 -10
  12. package/lib/cjs/version.js +1 -1
  13. package/lib/esm/common/ant.js +290 -1
  14. package/lib/esm/common/contracts/ao-process.js +2 -2
  15. package/lib/esm/common/http.js +2 -3
  16. package/lib/esm/common/index.js +0 -1
  17. package/lib/esm/common/io.js +87 -36
  18. package/lib/esm/common/logger.js +29 -14
  19. package/lib/esm/utils/http-client.js +2 -2
  20. package/lib/esm/utils/index.js +1 -1
  21. package/lib/esm/utils/{graphql/processes.js → processes.js} +33 -9
  22. package/lib/esm/version.js +1 -1
  23. package/lib/types/common/ant.d.ts +174 -23
  24. package/lib/types/common/contracts/ao-process.d.ts +2 -2
  25. package/lib/types/common/http.d.ts +3 -2
  26. package/lib/types/common/index.d.ts +0 -1
  27. package/lib/types/common/io.d.ts +5 -4
  28. package/lib/types/common/logger.d.ts +10 -3
  29. package/lib/types/common.d.ts +0 -7
  30. package/lib/types/io.d.ts +28 -3
  31. package/lib/types/utils/http-client.d.ts +2 -2
  32. package/lib/types/utils/index.d.ts +1 -1
  33. package/lib/types/utils/{graphql/processes.d.ts → processes.d.ts} +4 -1
  34. package/lib/types/version.d.ts +1 -1
  35. package/package.json +6 -6
  36. package/lib/cjs/common/ant-ao.js +0 -297
  37. package/lib/cjs/utils/graphql/index.js +0 -33
  38. package/lib/esm/common/ant-ao.js +0 -292
  39. package/lib/esm/utils/graphql/index.js +0 -17
  40. package/lib/types/common/ant-ao.d.ts +0 -194
  41. package/lib/types/utils/graphql/index.d.ts +0 -17
package/README.md CHANGED
@@ -21,27 +21,31 @@ This is the home of [ar.io] SDK. This SDK provides functionality for interacting
21
21
  - [`init({ signer })`](#init-signer-)
22
22
  - [`getInfo()`](#getinfo)
23
23
  - [`getBalance({ address })`](#getbalance-address-)
24
- - [`getBalances()`](#getbalances)
24
+ - [`getBalances({ cursor, limit, sortBy, sortOrder })`](#getbalances-cursor-limit-sortby-sortorder-)
25
25
  - [`getGateway({ address })`](#getgateway-address-)
26
- - [`getGateways()`](#getgateways)
26
+ - [`getGateways({ cursor, limit, sortBy, sortOrder })`](#getgateways-cursor-limit-sortby-sortorder-)
27
27
  - [`getArNSRecord({ name })`](#getarnsrecord-name-)
28
- - [`getArNSRecords()`](#getarnsrecords)
28
+ - [`getArNSRecords({ page, pageSize, sortBy, sortOrder })`](#getarnsrecords-cursor-limit-sortby-sortorder-)
29
29
  - [`getObservations({ epochIndex })`](#getobservations-epochindex-)
30
30
  - [`getDistributions({ epochIndex })`](#getdistributions-epochindex-)
31
31
  - [`getEpoch({ epochIndex })`](#getepoch-epochindex-)
32
32
  - [`getCurrentEpoch()`](#getcurrentepoch)
33
33
  - [`getPrescribedObservers({ epochIndex })`](#getprescribedobservers-epochindex-)
34
34
  - [`joinNetwork(params)`](#joinnetworkparams)
35
+ - [`leaveNetwork()`](#leavenetwork)
35
36
  - [`updateGatewaySettings(gatewaySettings)`](#updategatewaysettingsgatewaysettings)
36
37
  - [`increaseDelegateStake({ target, qty })`](#increasedelegatestake-target-qty-)
37
38
  - [`decreaseDelegateStake({ target, qty })`](#decreasedelegatestake-target-qty-)
38
39
  - [`increaseOperatorStake({ qty })`](#increaseoperatorstake-qty-)
39
40
  - [`decreaseOperatorStake({ qty })`](#decreaseoperatorstake-qty-)
40
41
  - [`saveObservations({ reportTxId, failedGateways })`](#saveobservations-reporttxid-failedgateways-)
41
- - [`transfer({ target, qty, denomination })`](#transfer-target-qty-denomination-)
42
+ - [`transfer({ target, qty })`](#transfer-target-qty-)
43
+ - [`increaseUndernameLimit({ name, qty })`](#increaseundernamelimit-name-qty-)
44
+ - [`extendLease({ name, years })`](#extendlease-name-years-)
42
45
  - [Configuration](#custom-configuration)
43
46
 
44
47
  - [Arweave Name Tokens (ANT's)](#arweave-name-tokens-ants)
48
+
45
49
  - [ANT APIs](#ant-apis)
46
50
  - [`init({ signer})`](#init-signer-)
47
51
  - [`getInfo()`](#getinfo)
@@ -56,6 +60,11 @@ This is the home of [ar.io] SDK. This SDK provides functionality for interacting
56
60
  - [`setName({ name })`](#setname-name-)
57
61
  - [`setTicker({ ticker })`](#setticker-ticker-)
58
62
  - [Configuration](#configuration)
63
+
64
+ - [Logging](#logging)
65
+
66
+ - [Configuration](#configuration)
67
+
59
68
  - [Developers](#developers)
60
69
  - [Requirements](#requirements)
61
70
  - [Setup \& Build](#setup--build)
@@ -148,7 +157,7 @@ const gateways = await io.getGateways();
148
157
  ```
149
158
 
150
159
  > [!WARNING]
151
- > Polyfills are not provided by default for ESM exports. Depending on your apps bundler configuration and plugins, you will need to provide polyfills for various imports including `crypto`, `process` and `buffer`. Refer to [examples/webpack] and [examples/vite] for examples. For other project configurations, refer to your bundler's documentation for more information on how to provide the necessary polyfills.
160
+ > Polyfills are not provided by default for bundled web projects (Vite, ESBuild, Webpack, Rollup, etc.) . Depending on your apps bundler configuration and plugins, you will need to provide polyfills for various imports including `crypto`, `process` and `buffer`. Refer to [examples/webpack] and [examples/vite] for examples. For other project configurations, refer to your bundler's documentation for more information on how to provide the necessary polyfills.
152
161
 
153
162
  #### Browser
154
163
 
@@ -251,7 +260,7 @@ const info = await io.getInfo();
251
260
  "name": "Testnet IO",
252
261
  "ticker": "tIO",
253
262
  "owner": "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ",
254
- "denomination": "IO"
263
+ "denomination": "6"
255
264
  }
256
265
  ```
257
266
 
@@ -268,45 +277,50 @@ const balance = await io
268
277
  .getBalance({
269
278
  address: 'INSERT_WALLET_ADDRESS',
270
279
  })
271
- .then((balance) => new mIOToken().toIO());
272
-
273
- console.log(balance.valueOf());
280
+ .then((balance) => new mIOToken().toIO()); // convert it to IO for readability
274
281
  ```
275
282
 
276
283
  <details>
277
284
  <summary>Output</summary>
278
285
 
279
286
  ```json
280
- // value in IO
281
- 1_000_000
287
+ 100000
282
288
  ```
283
289
 
284
290
  </details>
285
291
 
286
- #### `getBalances()`
292
+ #### `getBalances({ cursor, limit, sortBy, sortOrder })`
287
293
 
288
- Retrieves the balances of the IO process in `mIO`
289
-
290
- <!--
291
- // ALM - A part of me wonders whether streaming JSON might be beneficial in the future
292
- // and if providing streaming versions of these APIs will scale nicely longer term, e.g.
293
- // io.streamBalances({ sortingCriteria: BALANCE_DESC });
294
- -->
294
+ Retrieves the balances of the IO process in `mIO`, paginated and sorted by the specified criteria. The `cursor` used for pagination is the last wallet address from the previous page.
295
295
 
296
296
  ```typescript
297
297
  const io = IO.init();
298
- const balances = await io.getBalances();
298
+ const balances = await io.getBalances({
299
+ cursor: '-4xgjroXENKYhTWqrBo57HQwvDL51mMdfsdsxJy6Y2Z_sA',
300
+ limit: 1,
301
+ sortBy: 'balance',
302
+ sortOrder: 'desc',
303
+ });
299
304
  ```
300
305
 
301
306
  <details>
302
307
  <summary>Output</summary>
303
308
 
304
309
  ```json
305
- {
306
- "-4xgjroXENKYhTWqrBo57HQwvDL51mMvSxJy6Y2Z_sA": 5000000000, // value in mIO
307
- "-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck": 5000000000, // value in mIO
308
- "-9JU3W8g9nOAB1OrJQ8FxkaWCpv5slBET2HppTItbmk": 5000000000 // value in mIO
309
- }
310
+ [
311
+ {
312
+ "address": "-4xgjroXENKYhTWqrBo57HQwvDL51mMvSxJy6Y2Z_sA",
313
+ "balance": 1000000
314
+ },
315
+ {
316
+ "address": "-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck",
317
+ "balance": 500000
318
+ },
319
+ {
320
+ "address": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
321
+ "balance": 10000
322
+ }
323
+ ]
310
324
  ```
311
325
 
312
326
  </details>
@@ -329,7 +343,7 @@ const gateway = await io.getGateway({
329
343
  {
330
344
  "end": 0,
331
345
  "observerWallet": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
332
- "operatorStake": 250000000000, // value in mIO
346
+ "operatorStake": 250000000000,
333
347
  "settings": {
334
348
  "fqdn": "ar-io.dev",
335
349
  "label": "AR.IO Test",
@@ -353,24 +367,53 @@ const gateway = await io.getGateway({
353
367
 
354
368
  </details>
355
369
 
356
- #### `getGateways()`
370
+ #### `getGateways({ cursor, limit, sortBy, sortOrder })`
357
371
 
358
- Retrieves the registered gateways of the IO process.
372
+ Retrieves registered gateways of the IO process, using pagination and sorting by the specified criteria. The `cursor` used for pagination is the last gateway address from the previous page.
359
373
 
360
374
  ```typescript
361
375
  const io = IO.init();
362
- const gateways = await io.getGateways();
376
+ const gateways = await io.getGateways({
377
+ limit: 10,
378
+ sortOrder: 'desc',
379
+ sortBy: 'operatorStake',
380
+ });
363
381
  ```
364
382
 
383
+ Available `sortBy` options are any of the keys on the gateway object, e.g. `operatorStake`, `start`, `status`, `settings.fqdn`, `settings.label`, `settings.note`, `settings.port`, `settings.protocol`, `stats.failedConsecutiveEpochs`, `stats.passedConsecutiveEpochs`, etc.
384
+
365
385
  <details>
366
386
  <summary>Output</summary>
367
387
 
368
388
  ```json
369
- {
370
- "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ": {
371
- "end": 0,
372
- "observerWallet": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
373
- "operatorStake": 250000000000, // value in mIO
389
+ [
390
+ {
391
+ "gatewayAddress": "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ",
392
+ "observerAddress": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
393
+ "operatorStake": 250000000000,
394
+ "settings": {
395
+ "fqdn": "ar-io.dev",
396
+ "label": "AR.IO Test",
397
+ "note": "Test Gateway operated by PDS for the AR.IO ecosystem.",
398
+ "port": 443,
399
+ "properties": "raJgvbFU-YAnku-WsupIdbTsqqGLQiYpGzoqk9SCVgY",
400
+ "protocol": "https"
401
+ },
402
+ "start": 1256694,
403
+ "stats": {
404
+ "failedConsecutiveEpochs": 0,
405
+ "passedEpochCount": 30,
406
+ "submittedEpochCount": 30,
407
+ "totalEpochParticipationCount": 31,
408
+ "totalEpochsPrescribedCount": 31
409
+ },
410
+ "status": "joined",
411
+ "vaults": {}
412
+ },
413
+ {
414
+ "gatewayAddress": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
415
+ "observerAddress": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
416
+ "operatorStake": 100000000,
374
417
  "settings": {
375
418
  "fqdn": "ar-io.dev",
376
419
  "label": "AR.IO Test",
@@ -390,7 +433,7 @@ const gateways = await io.getGateways();
390
433
  "status": "joined",
391
434
  "vaults": {}
392
435
  }
393
- }
436
+ ]
394
437
  ```
395
438
 
396
439
  </details>
@@ -419,35 +462,44 @@ const record = await io.getArNSRecord({ name: 'ardrive' });
419
462
 
420
463
  </details>
421
464
 
422
- #### `getArNSRecords()`
465
+ #### `getArNSRecords({ cursor, limit, sortBy, sortOrder })`
423
466
 
424
- Retrieves all registered ArNS records of the IO process.
467
+ Retrieves all registered ArNS records of the IO process, paginated and sorted by the specified criteria. The `cursor` used for pagination is the last ArNS name from the previous page.
425
468
 
426
469
  ```typescript
427
470
  const io = IO.init();
428
- const records = await io.getArNSRecords();
471
+ const records = await io.getArNSRecords({
472
+ cursor: 'ar-io',
473
+ pageSize: 10,
474
+ sortBy: 'startTimestamp',
475
+ sortOrder: 'desc',
476
+ });
429
477
  ```
430
478
 
479
+ Available `sortBy` options are any of the keys on the record object, e.g. `name`, `processId`, `endTimestamp`, `startTimestamp`, `type`, `undernames`.
480
+
431
481
  <details>
432
482
  <summary>Output</summary>
433
483
 
434
484
  ```json
435
- {
436
- "ardrive": {
485
+ [
486
+ {
487
+ "name": "ao",
488
+ "processId": "eNey-H9RB9uCdoJUvPULb35qhZVXZcEXv8xds4aHhkQ",
489
+ "purchasePrice": 75541282285,
490
+ "startTimestamp": 1706747215,
491
+ "type": "permabuy",
492
+ "undernames": 10
493
+ },
494
+ {
495
+ "name": "ardrive",
437
496
  "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
438
497
  "endTimestamp": 1711122739,
439
498
  "startTimestamp": 1694101828,
440
499
  "type": "lease",
441
500
  "undernames": 100
442
- },
443
- "ar-io": {
444
- "processId": "eNey-H9RB9uCdoJUvPULb35qhZVXZcEXv8xds4aHhkQ",
445
- "purchasePrice": 75541282285, // value in mIO
446
- "startTimestamp": 1706747215,
447
- "type": "permabuy",
448
- "undernames": 10
449
501
  }
450
- }
502
+ ]
451
503
  ```
452
504
 
453
505
  </details>
@@ -499,11 +551,12 @@ const distributions = await io.getDistributions();
499
551
 
500
552
  ```json
501
553
  {
502
- "epochEndHeight": 1382379,
503
- "epochPeriod": 43,
504
- "epochStartHeight": 1381660,
505
- "epochZeroStartHeight": 1350700,
506
- "nextDistributionHeight": 1382394
554
+ "totalEligibleRewards": 100000000,
555
+ "totalDistributedRewards": 100000000,
556
+ "distributedTimestamp": 1711122739,
557
+ "rewards": {
558
+ "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
559
+ }
507
560
  }
508
561
  ```
509
562
 
@@ -556,6 +609,7 @@ const epoch = await io.getEpoch({ epochIndex: 0 });
556
609
  "distributions": {
557
610
  "distributedTimestamp": 1711122739,
558
611
  "totalEligibleRewards": 100000000,
612
+ "totoalDistributedRewards": 100000000,
559
613
  "rewards": {
560
614
  "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
561
615
  }
@@ -599,7 +653,7 @@ const epoch = await io.getCurrentEpoch();
599
653
  {
600
654
  "gatewayAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
601
655
  "observerAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
602
- "stake": 10000000000, // value in mIO
656
+ "stake": 10000000000,
603
657
  "start": 1292450,
604
658
  "stakeWeight": 1,
605
659
  "tenureWeight": 0.4494598765432099,
@@ -663,16 +717,14 @@ const price = await io
663
717
  name: 'ar-io',
664
718
  type: 'permabuy',
665
719
  })
666
- .then((p) => new mIOToken(p).toIO());
667
- // Price is returned as mio, convert to IO and log it out
668
- console.log({ price: price.valueOf() });
720
+ .then((p) => new mIOToken(p).toIO()); // convert to IO for readability
669
721
  ```
670
722
 
671
723
  <details>
672
724
  <summary>Output</summary>
673
725
 
674
726
  ```json
675
- { "price": 1642.62 }
727
+ 1642.34
676
728
  ```
677
729
 
678
730
  </details>
@@ -705,6 +757,21 @@ const { id: txId } = await io.joinNetwork(
705
757
  );
706
758
  ```
707
759
 
760
+ #### `leaveNetwork()`
761
+
762
+ Sets the gateway as `leaving` on the ar.io network. Requires `signer` to be provided on `IO.init` to sign the transaction. The gateways operator and delegate stakes are vaulted and will be returned after leave periods. The gateway will be removed from the network after the leave period.
763
+
764
+ _Note: Requires `signer` to be provided on `IO.init` to sign the transaction._
765
+
766
+ ```typescript
767
+ const io = IO.init({ signer: new ArweaveSigner(jwk) });
768
+
769
+ const { id: txId } = await io.leaveNetwork(
770
+ // optional additional tags
771
+ { tags: [{ name: 'App-Name', value: 'My-Awesome-App' }] },
772
+ );
773
+ ```
774
+
708
775
  #### `updateGatewaySettings(gatewaySettings)`
709
776
 
710
777
  Writes new gateway settings to the callers gateway configuration.
@@ -815,9 +882,9 @@ const { id: txId } = await io.saveObservations(
815
882
  );
816
883
  ```
817
884
 
818
- #### `transfer({ target, qty, denomination })`
885
+ #### `transfer({ target, qty })`
819
886
 
820
- Transfers `IO` or `mIO` depending on the `denomination` selected, defaulting as `IO`, to the designated `target` recipient address. Requires `signer` to be provided on `IO.init` to sign the transaction.
887
+ Transfers `mIO` to the designated `target` recipient address. Requires `signer` to be provided on `IO.init` to sign the transaction.
821
888
 
822
889
  _Note: Requires `signer` to be provided on `IO.init` to sign the transaction._
823
890
 
@@ -1136,6 +1203,22 @@ const ant = ANT.init({
1136
1203
  });
1137
1204
  ```
1138
1205
 
1206
+ ## Logging
1207
+
1208
+ The library uses the [Winston] logger for node based projects, and `console` logger for web based projects by default. You can configure the log level via `setLogLevel()` API. Alternatively you can set a custom logger as the default logger so long as it satisfes the `ILogger` interface.
1209
+
1210
+ ### Configuration
1211
+
1212
+ ```typescript
1213
+ import { Logger } from '@ar.io/sdk';
1214
+
1215
+ // set the log level
1216
+ Logger.default.setLogLevel('debug');
1217
+
1218
+ // provide your own logger
1219
+ Logger.default = winston.createLogger({ ...loggerConfigs }); // or some other logger that satisifes ILogger interface
1220
+ ```
1221
+
1139
1222
  ## Developers
1140
1223
 
1141
1224
  ### Requirements
@@ -1184,3 +1267,4 @@ For more information on how to contribute, please see [CONTRIBUTING.md].
1184
1267
  [AO Connect]: https://github.com/permaweb/ao/tree/main/connect
1185
1268
  [IO testnet process]: https://www.ao.link/#/entity/agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA
1186
1269
  [IO Network spec]: https://github.com/ar-io/ar-io-network-process?tab=readme-ov-file#contract-spec
1270
+ [Winston]: https://www.npmjs.com/package/winston