@ar.io/sdk 1.2.2 → 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 (68) hide show
  1. package/README.md +148 -60
  2. package/bundles/web.bundle.min.js +132 -331
  3. package/lib/cjs/common/ant.js +147 -206
  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 -5
  7. package/lib/cjs/common/io.js +39 -31
  8. package/lib/cjs/common/logger.js +31 -19
  9. package/lib/cjs/types.js +0 -1
  10. package/lib/cjs/utils/arweave.js +1 -15
  11. package/lib/cjs/utils/http-client.js +1 -1
  12. package/lib/cjs/utils/index.js +1 -2
  13. package/lib/cjs/utils/{graphql/processes.js → processes.js} +35 -10
  14. package/lib/cjs/version.js +1 -1
  15. package/lib/esm/common/ant.js +144 -203
  16. package/lib/esm/common/contracts/ao-process.js +2 -2
  17. package/lib/esm/common/http.js +2 -3
  18. package/lib/esm/common/index.js +0 -5
  19. package/lib/esm/common/io.js +39 -28
  20. package/lib/esm/common/logger.js +29 -14
  21. package/lib/esm/types.js +0 -1
  22. package/lib/esm/utils/arweave.js +0 -12
  23. package/lib/esm/utils/http-client.js +2 -2
  24. package/lib/esm/utils/index.js +1 -2
  25. package/lib/esm/utils/{graphql/processes.js → processes.js} +33 -9
  26. package/lib/esm/version.js +1 -1
  27. package/lib/types/common/ant.d.ts +53 -175
  28. package/lib/types/common/contracts/ao-process.d.ts +2 -2
  29. package/lib/types/common/http.d.ts +3 -2
  30. package/lib/types/common/index.d.ts +0 -4
  31. package/lib/types/common/io.d.ts +5 -4
  32. package/lib/types/common/logger.d.ts +10 -3
  33. package/lib/types/common.d.ts +1 -145
  34. package/lib/types/io.d.ts +28 -3
  35. package/lib/types/types.d.ts +0 -1
  36. package/lib/types/utils/arweave.d.ts +0 -5
  37. package/lib/types/utils/http-client.d.ts +2 -2
  38. package/lib/types/utils/index.d.ts +1 -2
  39. package/lib/types/utils/{graphql/processes.d.ts → processes.d.ts} +4 -1
  40. package/lib/types/version.d.ts +1 -1
  41. package/package.json +8 -13
  42. package/lib/cjs/arns-service.js +0 -2
  43. package/lib/cjs/common/ant-ao.js +0 -297
  44. package/lib/cjs/common/ar-io.js +0 -741
  45. package/lib/cjs/common/contracts/remote-contract.js +0 -55
  46. package/lib/cjs/common/contracts/warp-contract.js +0 -176
  47. package/lib/cjs/common/warp.js +0 -25
  48. package/lib/cjs/utils/graphql/index.js +0 -34
  49. package/lib/cjs/utils/graphql/smartweave.js +0 -309
  50. package/lib/cjs/utils/smartweave.js +0 -58
  51. package/lib/esm/arns-service.js +0 -1
  52. package/lib/esm/common/ant-ao.js +0 -292
  53. package/lib/esm/common/ar-io.js +0 -735
  54. package/lib/esm/common/contracts/remote-contract.js +0 -51
  55. package/lib/esm/common/contracts/warp-contract.js +0 -172
  56. package/lib/esm/common/warp.js +0 -22
  57. package/lib/esm/utils/graphql/index.js +0 -18
  58. package/lib/esm/utils/graphql/smartweave.js +0 -303
  59. package/lib/esm/utils/smartweave.js +0 -50
  60. package/lib/types/arns-service.d.ts +0 -23
  61. package/lib/types/common/ant-ao.d.ts +0 -194
  62. package/lib/types/common/ar-io.d.ts +0 -551
  63. package/lib/types/common/contracts/remote-contract.d.ts +0 -38
  64. package/lib/types/common/contracts/warp-contract.d.ts +0 -43
  65. package/lib/types/common/warp.d.ts +0 -1
  66. package/lib/types/utils/graphql/index.d.ts +0 -18
  67. package/lib/types/utils/graphql/smartweave.d.ts +0 -47
  68. package/lib/types/utils/smartweave.d.ts +0 -41
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)
@@ -147,7 +156,8 @@ const io = IO.init();
147
156
  const gateways = await io.getGateways();
148
157
  ```
149
158
 
150
- > _**Note**: polyfills are only provided when using the named `@ar.io/sdk/web` export (which requires `moduleResolution: nodenext` in `tsconfig.json`). If you are using the default export within a Typescript project (e.g. `moduleResolution: node`), you will need to provide your own polyfills - specifically `crypto`, `fs` and `buffer`. Refer to [examples/webpack] and [examples/vite] for references in how to properly provide those polyfills. For other project configurations, refer to your bundler's documentation for more information on how to provide the necessary polyfills._
159
+ > [!WARNING]
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.
151
161
 
152
162
  #### Browser
153
163
 
@@ -190,6 +200,9 @@ const gateways = await io.getGateways();
190
200
 
191
201
  The SDK provides TypeScript types. When you import the SDK in a TypeScript project types are exported from `./lib/types/[node/web]/index.d.ts` and should be automatically recognized by package managers, offering benefits such as type-checking and autocompletion.
192
202
 
203
+ > [!NOTE]
204
+ > Typescript version 5.3 or higher is recommended.
205
+
193
206
  ## IOToken & mIOToken
194
207
 
195
208
  The IO process stores all values as mIO (milli-IO) to avoid floating-point arithmetic issues. The SDK provides an `IOToken` and `mIOToken` classes to handle the conversion between IO and mIO, along with rounding logic for precision.
@@ -247,7 +260,7 @@ const info = await io.getInfo();
247
260
  "name": "Testnet IO",
248
261
  "ticker": "tIO",
249
262
  "owner": "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ",
250
- "denomination": "IO"
263
+ "denomination": "6"
251
264
  }
252
265
  ```
253
266
 
@@ -264,45 +277,50 @@ const balance = await io
264
277
  .getBalance({
265
278
  address: 'INSERT_WALLET_ADDRESS',
266
279
  })
267
- .then((balance) => new mIOToken().toIO());
268
-
269
- console.log(balance.valueOf());
280
+ .then((balance) => new mIOToken().toIO()); // convert it to IO for readability
270
281
  ```
271
282
 
272
283
  <details>
273
284
  <summary>Output</summary>
274
285
 
275
286
  ```json
276
- // value in IO
277
- 1_000_000
287
+ 100000
278
288
  ```
279
289
 
280
290
  </details>
281
291
 
282
- #### `getBalances()`
283
-
284
- Retrieves the balances of the IO process in `mIO`
292
+ #### `getBalances({ cursor, limit, sortBy, sortOrder })`
285
293
 
286
- <!--
287
- // ALM - A part of me wonders whether streaming JSON might be beneficial in the future
288
- // and if providing streaming versions of these APIs will scale nicely longer term, e.g.
289
- // io.streamBalances({ sortingCriteria: BALANCE_DESC });
290
- -->
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.
291
295
 
292
296
  ```typescript
293
297
  const io = IO.init();
294
- 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
+ });
295
304
  ```
296
305
 
297
306
  <details>
298
307
  <summary>Output</summary>
299
308
 
300
309
  ```json
301
- {
302
- "-4xgjroXENKYhTWqrBo57HQwvDL51mMvSxJy6Y2Z_sA": 5000000000, // value in mIO
303
- "-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck": 5000000000, // value in mIO
304
- "-9JU3W8g9nOAB1OrJQ8FxkaWCpv5slBET2HppTItbmk": 5000000000 // value in mIO
305
- }
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
+ ]
306
324
  ```
307
325
 
308
326
  </details>
@@ -325,7 +343,7 @@ const gateway = await io.getGateway({
325
343
  {
326
344
  "end": 0,
327
345
  "observerWallet": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
328
- "operatorStake": 250000000000, // value in mIO
346
+ "operatorStake": 250000000000,
329
347
  "settings": {
330
348
  "fqdn": "ar-io.dev",
331
349
  "label": "AR.IO Test",
@@ -349,24 +367,53 @@ const gateway = await io.getGateway({
349
367
 
350
368
  </details>
351
369
 
352
- #### `getGateways()`
370
+ #### `getGateways({ cursor, limit, sortBy, sortOrder })`
353
371
 
354
- 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.
355
373
 
356
374
  ```typescript
357
375
  const io = IO.init();
358
- const gateways = await io.getGateways();
376
+ const gateways = await io.getGateways({
377
+ limit: 10,
378
+ sortOrder: 'desc',
379
+ sortBy: 'operatorStake',
380
+ });
359
381
  ```
360
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
+
361
385
  <details>
362
386
  <summary>Output</summary>
363
387
 
364
388
  ```json
365
- {
366
- "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ": {
367
- "end": 0,
368
- "observerWallet": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
369
- "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,
370
417
  "settings": {
371
418
  "fqdn": "ar-io.dev",
372
419
  "label": "AR.IO Test",
@@ -386,7 +433,7 @@ const gateways = await io.getGateways();
386
433
  "status": "joined",
387
434
  "vaults": {}
388
435
  }
389
- }
436
+ ]
390
437
  ```
391
438
 
392
439
  </details>
@@ -415,35 +462,44 @@ const record = await io.getArNSRecord({ name: 'ardrive' });
415
462
 
416
463
  </details>
417
464
 
418
- #### `getArNSRecords()`
465
+ #### `getArNSRecords({ cursor, limit, sortBy, sortOrder })`
419
466
 
420
- 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.
421
468
 
422
469
  ```typescript
423
470
  const io = IO.init();
424
- 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
+ });
425
477
  ```
426
478
 
479
+ Available `sortBy` options are any of the keys on the record object, e.g. `name`, `processId`, `endTimestamp`, `startTimestamp`, `type`, `undernames`.
480
+
427
481
  <details>
428
482
  <summary>Output</summary>
429
483
 
430
484
  ```json
431
- {
432
- "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",
433
496
  "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
434
497
  "endTimestamp": 1711122739,
435
498
  "startTimestamp": 1694101828,
436
499
  "type": "lease",
437
500
  "undernames": 100
438
- },
439
- "ar-io": {
440
- "processId": "eNey-H9RB9uCdoJUvPULb35qhZVXZcEXv8xds4aHhkQ",
441
- "purchasePrice": 75541282285, // value in mIO
442
- "startTimestamp": 1706747215,
443
- "type": "permabuy",
444
- "undernames": 10
445
501
  }
446
- }
502
+ ]
447
503
  ```
448
504
 
449
505
  </details>
@@ -495,11 +551,12 @@ const distributions = await io.getDistributions();
495
551
 
496
552
  ```json
497
553
  {
498
- "epochEndHeight": 1382379,
499
- "epochPeriod": 43,
500
- "epochStartHeight": 1381660,
501
- "epochZeroStartHeight": 1350700,
502
- "nextDistributionHeight": 1382394
554
+ "totalEligibleRewards": 100000000,
555
+ "totalDistributedRewards": 100000000,
556
+ "distributedTimestamp": 1711122739,
557
+ "rewards": {
558
+ "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
559
+ }
503
560
  }
504
561
  ```
505
562
 
@@ -552,6 +609,7 @@ const epoch = await io.getEpoch({ epochIndex: 0 });
552
609
  "distributions": {
553
610
  "distributedTimestamp": 1711122739,
554
611
  "totalEligibleRewards": 100000000,
612
+ "totoalDistributedRewards": 100000000,
555
613
  "rewards": {
556
614
  "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
557
615
  }
@@ -595,7 +653,7 @@ const epoch = await io.getCurrentEpoch();
595
653
  {
596
654
  "gatewayAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
597
655
  "observerAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
598
- "stake": 10000000000, // value in mIO
656
+ "stake": 10000000000,
599
657
  "start": 1292450,
600
658
  "stakeWeight": 1,
601
659
  "tenureWeight": 0.4494598765432099,
@@ -659,16 +717,14 @@ const price = await io
659
717
  name: 'ar-io',
660
718
  type: 'permabuy',
661
719
  })
662
- .then((p) => new mIOToken(p).toIO());
663
- // Price is returned as mio, convert to IO and log it out
664
- console.log({ price: price.valueOf() });
720
+ .then((p) => new mIOToken(p).toIO()); // convert to IO for readability
665
721
  ```
666
722
 
667
723
  <details>
668
724
  <summary>Output</summary>
669
725
 
670
726
  ```json
671
- { "price": 1642.62 }
727
+ 1642.34
672
728
  ```
673
729
 
674
730
  </details>
@@ -701,6 +757,21 @@ const { id: txId } = await io.joinNetwork(
701
757
  );
702
758
  ```
703
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
+
704
775
  #### `updateGatewaySettings(gatewaySettings)`
705
776
 
706
777
  Writes new gateway settings to the callers gateway configuration.
@@ -811,9 +882,9 @@ const { id: txId } = await io.saveObservations(
811
882
  );
812
883
  ```
813
884
 
814
- #### `transfer({ target, qty, denomination })`
885
+ #### `transfer({ target, qty })`
815
886
 
816
- 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.
817
888
 
818
889
  _Note: Requires `signer` to be provided on `IO.init` to sign the transaction._
819
890
 
@@ -1132,6 +1203,22 @@ const ant = ANT.init({
1132
1203
  });
1133
1204
  ```
1134
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
+
1135
1222
  ## Developers
1136
1223
 
1137
1224
  ### Requirements
@@ -1180,3 +1267,4 @@ For more information on how to contribute, please see [CONTRIBUTING.md].
1180
1267
  [AO Connect]: https://github.com/permaweb/ao/tree/main/connect
1181
1268
  [IO testnet process]: https://www.ao.link/#/entity/agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA
1182
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