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

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 +253 -129
  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} +40 -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} +38 -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} +6 -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,29 +21,33 @@ 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({ cursor, limit, 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
- - [`init({ signer})`](#init-signer-)
50
+ - [`init({ processId, signer })`](#init-processid-signer-)
47
51
  - [`getInfo()`](#getinfo)
48
52
  - [`getOwner()`](#getowner)
49
53
  - [`getControllers()`](#getcontrollers)
@@ -56,6 +60,13 @@ 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
+
68
+ - [Pagination](#pagination)
69
+
59
70
  - [Developers](#developers)
60
71
  - [Requirements](#requirements)
61
72
  - [Setup \& Build](#setup--build)
@@ -94,37 +105,36 @@ const gateways = await io.getGateways();
94
105
 
95
106
  ```json
96
107
  {
97
- "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ": {
98
- "end": 0,
99
- "observerWallet": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
100
- "operatorStake": 250000000000, // value in mIO
101
- "settings": {
102
- "fqdn": "ar-io.dev",
103
- "label": "AR.IO Test",
104
- "note": "Test Gateway operated by PDS for the AR.IO ecosystem.",
105
- "port": 443,
106
- "properties": "raJgvbFU-YAnku-WsupIdbTsqqGLQiYpGzoqk9SCVgY",
107
- "protocol": "https"
108
- },
109
- "start": 1256694,
110
- "stats": {
111
- "failedConsecutiveEpochs": 0,
112
- "passedEpochCount": 30,
113
- "submittedEpochCount": 30,
114
- "totalEpochParticipationCount": 31,
115
- "totalEpochsPrescribedCount": 31
116
- },
117
- "status": "joined",
118
- "vaults": {},
119
- "weights": {
120
- "stakeWeight": 25,
121
- "tenureWeight": 0.9031327160493827,
122
- "gatewayRewardRatioWeight": 0.96875,
123
- "observerRewardRatioWeight": 0.96875,
124
- "compositeWeight": 21.189222170982834,
125
- "normalizedCompositeWeight": 0.27485583057217183
108
+ "items": [
109
+ {
110
+ "gatewayAddress": "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ",
111
+ "observerAddress": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
112
+ "operatorStake": 250000000000,
113
+ "settings": {
114
+ "fqdn": "ar-io.dev",
115
+ "label": "AR.IO Test",
116
+ "note": "Test Gateway operated by PDS for the AR.IO ecosystem.",
117
+ "port": 443,
118
+ "properties": "raJgvbFU-YAnku-WsupIdbTsqqGLQiYpGzoqk9SCVgY",
119
+ "protocol": "https"
120
+ },
121
+ "startTimestamp": 1720720621424,
122
+ "stats": {
123
+ "failedConsecutiveEpochs": 0,
124
+ "passedEpochCount": 30,
125
+ "submittedEpochCount": 30,
126
+ "totalEpochParticipationCount": 31,
127
+ "totalEpochsPrescribedCount": 31
128
+ },
129
+ "status": "joined",
130
+ "vaults": {}
126
131
  }
127
- }
132
+ ],
133
+ "hasMore": true,
134
+ "nextCursor": "-4xgjroXENKYhTWqrBo57HQwvDL51mMdfsdsxJy6Y2Z_sA",
135
+ "totalItems": 316,
136
+ "sortBy": "startTimestamp",
137
+ "sortOrder": "desc"
128
138
  }
129
139
  ```
130
140
 
@@ -148,7 +158,7 @@ const gateways = await io.getGateways();
148
158
  ```
149
159
 
150
160
  > [!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.
161
+ > 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
162
 
153
163
  #### Browser
154
164
 
@@ -207,11 +217,9 @@ import { IOToken, mIOToken } from '@ar.io/sdk';
207
217
 
208
218
  const ioValue = 1;
209
219
  const mIOValue = new IOToken(ioValue).toMIO();
210
- console.log(mIOValue); // 1000000 (mIO)
211
220
 
212
221
  const mIOValue = 1_000_000;
213
222
  const ioValue = new mIOToken(mIOValue).toIO();
214
- console.log(ioValue); // 1 (IO)
215
223
  ```
216
224
 
217
225
  ## IO Process
@@ -251,7 +259,7 @@ const info = await io.getInfo();
251
259
  "name": "Testnet IO",
252
260
  "ticker": "tIO",
253
261
  "owner": "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ",
254
- "denomination": "IO"
262
+ "denomination": "6"
255
263
  }
256
264
  ```
257
265
 
@@ -266,36 +274,32 @@ const io = IO.init();
266
274
  // the balance will be returned in mIO as a value
267
275
  const balance = await io
268
276
  .getBalance({
269
- address: 'INSERT_WALLET_ADDRESS',
277
+ address: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ',
270
278
  })
271
- .then((balance) => new mIOToken().toIO());
272
-
273
- console.log(balance.valueOf());
279
+ .then((balance) => new mIOToken().toIO()); // convert it to IO for readability
274
280
  ```
275
281
 
276
282
  <details>
277
283
  <summary>Output</summary>
278
284
 
279
285
  ```json
280
- // value in IO
281
- 1_000_000
286
+ 100000
282
287
  ```
283
288
 
284
289
  </details>
285
290
 
286
- #### `getBalances()`
287
-
288
- Retrieves the balances of the IO process in `mIO`
291
+ #### `getBalances({ cursor, limit, sortBy, sortOrder })`
289
292
 
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
- -->
293
+ 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 request.
295
294
 
296
295
  ```typescript
297
296
  const io = IO.init();
298
- const balances = await io.getBalances();
297
+ const balances = await io.getBalances({
298
+ cursor: '-4xgjroXENKYhTWqrBo57HQwvDL51mMdfsdsxJy6Y2Z_sA',
299
+ limit: 1,
300
+ sortBy: 'balance',
301
+ sortOrder: 'desc',
302
+ });
299
303
  ```
300
304
 
301
305
  <details>
@@ -303,9 +307,17 @@ const balances = await io.getBalances();
303
307
 
304
308
  ```json
305
309
  {
306
- "-4xgjroXENKYhTWqrBo57HQwvDL51mMvSxJy6Y2Z_sA": 5000000000, // value in mIO
307
- "-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck": 5000000000, // value in mIO
308
- "-9JU3W8g9nOAB1OrJQ8FxkaWCpv5slBET2HppTItbmk": 5000000000 // value in mIO
310
+ "items": [
311
+ {
312
+ "address": "-4xgjroXENKYhTWqrBo57HQwvDL51mMvSxJy6Y2Z_sA",
313
+ "balance": 1000000
314
+ }
315
+ ],
316
+ "hasMore": true,
317
+ "nextCursor": "-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck",
318
+ "totalItems": 1789,
319
+ "sortBy": "balance",
320
+ "sortOrder": "desc"
309
321
  }
310
322
  ```
311
323
 
@@ -318,7 +330,7 @@ Retrieves a gateway's info by its staking wallet address.
318
330
  ```typescript
319
331
  const io = IO.init();
320
332
  const gateway = await io.getGateway({
321
- address: 'INSERT_GATEWAY_ADDRESS',
333
+ address: '-7vXsQZQDk8TMDlpiSLy3CnLi5PDPlAaN2DaynORpck',
322
334
  });
323
335
  ```
324
336
 
@@ -327,9 +339,8 @@ const gateway = await io.getGateway({
327
339
 
328
340
  ```json
329
341
  {
330
- "end": 0,
331
- "observerWallet": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
332
- "operatorStake": 250000000000, // value in mIO
342
+ "observerAddress": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
343
+ "operatorStake": 250000000000,
333
344
  "settings": {
334
345
  "fqdn": "ar-io.dev",
335
346
  "label": "AR.IO Test",
@@ -338,7 +349,7 @@ const gateway = await io.getGateway({
338
349
  "properties": "raJgvbFU-YAnku-WsupIdbTsqqGLQiYpGzoqk9SCVgY",
339
350
  "protocol": "https"
340
351
  },
341
- "start": 1256694,
352
+ "startTimestamp": 1720720620813,
342
353
  "stats": {
343
354
  "failedConsecutiveEpochs": 0,
344
355
  "passedEpochCount": 30,
@@ -353,43 +364,56 @@ const gateway = await io.getGateway({
353
364
 
354
365
  </details>
355
366
 
356
- #### `getGateways()`
367
+ #### `getGateways({ cursor, limit, sortBy, sortOrder })`
357
368
 
358
- Retrieves the registered gateways of the IO process.
369
+ 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 request.
359
370
 
360
371
  ```typescript
361
372
  const io = IO.init();
362
- const gateways = await io.getGateways();
373
+ const gateways = await io.getGateways({
374
+ limit: 1,
375
+ sortOrder: 'desc',
376
+ sortBy: 'operatorStake',
377
+ });
363
378
  ```
364
379
 
380
+ 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.
381
+
365
382
  <details>
366
383
  <summary>Output</summary>
367
384
 
368
385
  ```json
369
386
  {
370
- "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ": {
371
- "end": 0,
372
- "observerWallet": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
373
- "operatorStake": 250000000000, // value in mIO
374
- "settings": {
375
- "fqdn": "ar-io.dev",
376
- "label": "AR.IO Test",
377
- "note": "Test Gateway operated by PDS for the AR.IO ecosystem.",
378
- "port": 443,
379
- "properties": "raJgvbFU-YAnku-WsupIdbTsqqGLQiYpGzoqk9SCVgY",
380
- "protocol": "https"
381
- },
382
- "start": 1256694,
383
- "stats": {
384
- "failedConsecutiveEpochs": 0,
385
- "passedEpochCount": 30,
386
- "submittedEpochCount": 30,
387
- "totalEpochParticipationCount": 31,
388
- "totalEpochsPrescribedCount": 31
389
- },
390
- "status": "joined",
391
- "vaults": {}
392
- }
387
+ "items": [
388
+ {
389
+ "gatewayAddress": "QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ",
390
+ "observerAddress": "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
391
+ "operatorStake": 250000000000,
392
+ "settings": {
393
+ "fqdn": "ar-io.dev",
394
+ "label": "AR.IO Test",
395
+ "note": "Test Gateway operated by PDS for the AR.IO ecosystem.",
396
+ "port": 443,
397
+ "properties": "raJgvbFU-YAnku-WsupIdbTsqqGLQiYpGzoqk9SCVgY",
398
+ "protocol": "https"
399
+ },
400
+ "startTimestamp": 1720720620813,
401
+ "stats": {
402
+ "failedConsecutiveEpochs": 0,
403
+ "passedEpochCount": 30,
404
+ "submittedEpochCount": 30,
405
+ "totalEpochParticipationCount": 31,
406
+ "totalEpochsPrescribedCount": 31
407
+ },
408
+ "status": "joined",
409
+ "vaults": {}
410
+ }
411
+ ],
412
+ "hasMore": true,
413
+ "nextCursor": "-4xgjroXENKYhTWqrBo57HQwvDL51mMdfsdsxJy6Y2Z_sA",
414
+ "totalItems": 316,
415
+ "sortBy": "operatorStake",
416
+ "sortOrder": "desc"
393
417
  }
394
418
  ```
395
419
 
@@ -410,8 +434,8 @@ const record = await io.getArNSRecord({ name: 'ardrive' });
410
434
  ```json
411
435
  {
412
436
  "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
413
- "endTimestamp": 1711122739,
414
- "startTimestamp": 1694101828,
437
+ "endTimestamp": 1752256702026,
438
+ "startTimestamp": 1720720819969,
415
439
  "type": "lease",
416
440
  "undernames": 100
417
441
  }
@@ -419,34 +443,74 @@ const record = await io.getArNSRecord({ name: 'ardrive' });
419
443
 
420
444
  </details>
421
445
 
422
- #### `getArNSRecords()`
446
+ #### `getArNSRecords({ cursor, limit, sortBy, sortOrder })`
423
447
 
424
- Retrieves all registered ArNS records of the IO process.
448
+ 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 request.
425
449
 
426
450
  ```typescript
427
451
  const io = IO.init();
428
- const records = await io.getArNSRecords();
452
+ // get the 5 newest names
453
+ const records = await io.getArNSRecords({
454
+ limit: 5,
455
+ sortBy: 'startTimestamp',
456
+ sortOrder: 'desc',
457
+ });
429
458
  ```
430
459
 
460
+ Available `sortBy` options are any of the keys on the record object, e.g. `name`, `processId`, `endTimestamp`, `startTimestamp`, `type`, `undernames`.
461
+
431
462
  <details>
432
463
  <summary>Output</summary>
433
464
 
434
465
  ```json
435
466
  {
436
- "ardrive": {
437
- "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
438
- "endTimestamp": 1711122739,
439
- "startTimestamp": 1694101828,
440
- "type": "lease",
441
- "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
- }
467
+ "items": [
468
+ {
469
+ "name": "ao",
470
+ "processId": "eNey-H9RB9uCdoJUvPULb35qhZVXZcEXv8xds4aHhkQ",
471
+ "purchasePrice": 75541282285,
472
+ "startTimestamp": 1720720621424,
473
+ "type": "permabuy",
474
+ "undernames": 10
475
+ },
476
+ {
477
+ "name": "ardrive",
478
+ "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
479
+ "endTimestamp": 1720720819969,
480
+ "startTimestamp": 1720720620813,
481
+ "type": "lease",
482
+ "undernames": 100
483
+ },
484
+ {
485
+ "name": "arweave",
486
+ "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
487
+ "endTimestamp": 1720720819969,
488
+ "startTimestamp": 1720720620800,
489
+ "type": "lease",
490
+ "undernames": 100
491
+ },
492
+ {
493
+ "name": "ar-io",
494
+ "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
495
+ "endTimestamp": 1720720819969,
496
+ "startTimestamp": 1720720619000,
497
+ "type": "lease",
498
+ "undernames": 100
499
+ },
500
+ {
501
+ "name": "fwd",
502
+ "processId": "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
503
+ "endTimestamp": 1720720819969,
504
+ "startTimestamp": 1720720220811,
505
+ "type": "lease",
506
+ "undernames": 100
507
+ }
508
+ ],
509
+ "hasMore": true,
510
+ "nextCursor": "fwdresearch",
511
+ "totalItems": 21740,
512
+ "sortBy": "startTimestamp",
513
+ "sortOrder": "desc"
450
514
  }
451
515
  ```
452
516
 
@@ -499,11 +563,12 @@ const distributions = await io.getDistributions();
499
563
 
500
564
  ```json
501
565
  {
502
- "epochEndHeight": 1382379,
503
- "epochPeriod": 43,
504
- "epochStartHeight": 1381660,
505
- "epochZeroStartHeight": 1350700,
506
- "nextDistributionHeight": 1382394
566
+ "totalEligibleRewards": 100000000,
567
+ "totalDistributedRewards": 100000000,
568
+ "distributedTimestamp": 1720720621424,
569
+ "rewards": {
570
+ "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
571
+ }
507
572
  }
508
573
  ```
509
574
 
@@ -524,10 +589,10 @@ const epoch = await io.getEpoch({ epochIndex: 0 });
524
589
  ```json
525
590
  {
526
591
  "epochIndex": 0,
527
- "startTimestamp": 1694101828,
528
- "endTimestamp": 1711122739,
592
+ "startTimestamp": 1720720620813,
593
+ "endTimestamp": 1752256702026,
529
594
  "startHeight": 1350700,
530
- "distributionTimestamp": 1711122739,
595
+ "distributionTimestamp": 1752256702026,
531
596
  "observations": {
532
597
  "failureSummaries": {
533
598
  "-Tk2DDk8k4zkwtppp_XFKKI5oUgh6IEHygAoN7mD-w8": [
@@ -544,7 +609,7 @@ const epoch = await io.getEpoch({ epochIndex: 0 });
544
609
  "gatewayAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
545
610
  "observerAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
546
611
  "stake": 10000000000, // value in mIO
547
- "start": 1292450,
612
+ "startTimestamp": 1720720620813,
548
613
  "stakeWeight": 1,
549
614
  "tenureWeight": 0.4494598765432099,
550
615
  "gatewayRewardRatioWeight": 1,
@@ -554,8 +619,9 @@ const epoch = await io.getEpoch({ epochIndex: 0 });
554
619
  }
555
620
  ],
556
621
  "distributions": {
557
- "distributedTimestamp": 1711122739,
622
+ "distributedTimestamp": 1752256702026,
558
623
  "totalEligibleRewards": 100000000,
624
+ "totoalDistributedRewards": 100000000,
559
625
  "rewards": {
560
626
  "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs": 100000000
561
627
  }
@@ -580,8 +646,8 @@ const epoch = await io.getCurrentEpoch();
580
646
  ```json
581
647
  {
582
648
  "epochIndex": 0,
583
- "startTimestamp": 1694101828,
584
- "endTimestamp": 1711122739,
649
+ "startTimestamp": 1720720621424,
650
+ "endTimestamp": 1752256702026,
585
651
  "startHeight": 1350700,
586
652
  "distributionTimestamp": 1711122739,
587
653
  "observations": {
@@ -599,7 +665,7 @@ const epoch = await io.getCurrentEpoch();
599
665
  {
600
666
  "gatewayAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
601
667
  "observerAddress": "2Fk8lCmDegPg6jjprl57-UCpKmNgYiKwyhkU4vMNDnE",
602
- "stake": 10000000000, // value in mIO
668
+ "stake": 10000000000,
603
669
  "start": 1292450,
604
670
  "stakeWeight": 1,
605
671
  "tenureWeight": 0.4494598765432099,
@@ -663,16 +729,14 @@ const price = await io
663
729
  name: 'ar-io',
664
730
  type: 'permabuy',
665
731
  })
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() });
732
+ .then((p) => new mIOToken(p).toIO()); // convert to IO for readability
669
733
  ```
670
734
 
671
735
  <details>
672
736
  <summary>Output</summary>
673
737
 
674
738
  ```json
675
- { "price": 1642.62 }
739
+ 1642.34
676
740
  ```
677
741
 
678
742
  </details>
@@ -705,6 +769,21 @@ const { id: txId } = await io.joinNetwork(
705
769
  );
706
770
  ```
707
771
 
772
+ #### `leaveNetwork()`
773
+
774
+ 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.
775
+
776
+ _Note: Requires `signer` to be provided on `IO.init` to sign the transaction._
777
+
778
+ ```typescript
779
+ const io = IO.init({ signer: new ArweaveSigner(jwk) });
780
+
781
+ const { id: txId } = await io.leaveNetwork(
782
+ // optional additional tags
783
+ { tags: [{ name: 'App-Name', value: 'My-Awesome-App' }] },
784
+ );
785
+ ```
786
+
708
787
  #### `updateGatewaySettings(gatewaySettings)`
709
788
 
710
789
  Writes new gateway settings to the callers gateway configuration.
@@ -815,9 +894,9 @@ const { id: txId } = await io.saveObservations(
815
894
  );
816
895
  ```
817
896
 
818
- #### `transfer({ target, qty, denomination })`
897
+ #### `transfer({ target, qty })`
819
898
 
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.
899
+ Transfers `mIO` to the designated `target` recipient address. Requires `signer` to be provided on `IO.init` to sign the transaction.
821
900
 
822
901
  _Note: Requires `signer` to be provided on `IO.init` to sign the transaction._
823
902
 
@@ -827,7 +906,6 @@ const { id: txId } = await io.transfer(
827
906
  {
828
907
  target: '-5dV7nk7waR8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5',
829
908
  qty: new IOToken(1000).toMIO(),
830
- denomination: 'IO',
831
909
  },
832
910
  // optional additional tags
833
911
  { tags: [{ name: 'App-Name', value: 'My-Awesome-App' }] },
@@ -893,7 +971,7 @@ The ANT client class exposes APIs relevant to compliant Arweave Name Token proce
893
971
 
894
972
  ### ANT APIs
895
973
 
896
- #### `init({ signer )`
974
+ #### `init({ processId, signer )`
897
975
 
898
976
  Factory function to that creates a read-only or writeable client. By providing a `signer` additional write APIs that require signing, like `setRecord` and `transfer` are available. By default, a read-only client is returned and no write APIs are available.
899
977
 
@@ -1136,6 +1214,49 @@ const ant = ANT.init({
1136
1214
  });
1137
1215
  ```
1138
1216
 
1217
+ ## Logging
1218
+
1219
+ 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.
1220
+
1221
+ ### Configuration
1222
+
1223
+ ```typescript
1224
+ import { Logger } from '@ar.io/sdk';
1225
+
1226
+ // set the log level
1227
+ Logger.default.setLogLevel('debug');
1228
+
1229
+ // provide your own logger
1230
+ Logger.default = winston.createLogger({ ...loggerConfigs }); // or some other logger that satisifes ILogger interface
1231
+ ```
1232
+
1233
+ ## Pagination
1234
+
1235
+ Certain APIs that could return a large amount of data are paginated using cursors. The SDK uses the `cursor` pattern (as opposed to pages) to better protect against changing data while paginating through a list of items. For more information on pagination strategies refer to [this article](https://www.getknit.dev/blog/api-pagination-best-practices#api-pagination-techniques-).
1236
+
1237
+ Paginated results include the following properties:
1238
+
1239
+ - `items`: the list of items on the current request, defaulted to 100 items.
1240
+ - `nextCursor`: the cursor to use for the next batch of items. This is `undefined` if there are no more items to fetch.
1241
+ - `hasMore`: a boolean indicating if there are more items to fetch. This is `false` if there are no more items to fetch.
1242
+ - `totalItems`: the total number of items available. This may change as new items are added to the list, only use this for informational purposes.
1243
+ - `sortBy`: the field used to sort the items, by default this is `startTimestamp`.
1244
+ - `sortOrder`: the order used to sort the items, by default this is `desc`.
1245
+
1246
+ To request all the items in a list, you can iterate through the list using the `nextCursor` until `hasMore` is `false`.
1247
+
1248
+ ```typescript
1249
+ let hasMore = true;
1250
+ let cursor: string | undefined;
1251
+ const gateaways = [];
1252
+ while (hasMore) {
1253
+ const page = await io.getGateways({ limit: 10, cursor });
1254
+ gateaways.push(...items);
1255
+ cursor = page.nextCursor;
1256
+ hasMore = page.hasMore;
1257
+ }
1258
+ ```
1259
+
1139
1260
  ## Developers
1140
1261
 
1141
1262
  ### Requirements
@@ -1152,7 +1273,9 @@ const ant = ANT.init({
1152
1273
 
1153
1274
  ### Testing
1154
1275
 
1155
- - `yarn test:integration` - runs integration tests against a local AO testnet
1276
+ - `yarn test` - runs e2e tests and unit tests
1277
+ - `yarn test:e2e` - runs e2e tests
1278
+ - `yarn test:unit` - runs unit tests
1156
1279
  - `yarn example:web` - opens up the example web page
1157
1280
  - `yarn example:cjs` - runs example CJS node script
1158
1281
  - `yarn example:esm` - runs example ESM node script
@@ -1184,3 +1307,4 @@ For more information on how to contribute, please see [CONTRIBUTING.md].
1184
1307
  [AO Connect]: https://github.com/permaweb/ao/tree/main/connect
1185
1308
  [IO testnet process]: https://www.ao.link/#/entity/agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA
1186
1309
  [IO Network spec]: https://github.com/ar-io/ar-io-network-process?tab=readme-ov-file#contract-spec
1310
+ [Winston]: https://www.npmjs.com/package/winston