@ar.io/sdk 1.2.0-alpha.9 → 1.2.1
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/README.md +914 -70
- package/bundles/web.bundle.min.js +76 -76
- package/lib/cjs/common/ant-ao.js +11 -4
- package/lib/cjs/common/contracts/ao-process.js +16 -5
- package/lib/cjs/common/io.js +97 -102
- package/lib/cjs/constants.js +7 -4
- package/lib/cjs/utils/graphql/processes.js +88 -8
- package/lib/cjs/utils/index.js +1 -0
- package/lib/cjs/utils/json.js +28 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant-ao.js +11 -4
- package/lib/esm/common/contracts/ao-process.js +16 -5
- package/lib/esm/common/io.js +98 -103
- package/lib/esm/constants.js +6 -3
- package/lib/esm/utils/graphql/processes.js +87 -8
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/json.js +24 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant-ao.d.ts +2 -1
- package/lib/types/common/io.d.ts +11 -4
- package/lib/types/constants.d.ts +4 -2
- package/lib/types/io.d.ts +29 -3
- package/lib/types/utils/graphql/processes.d.ts +30 -0
- package/lib/types/utils/index.d.ts +1 -0
- package/lib/types/utils/json.d.ts +17 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +7 -1
package/lib/esm/common/io.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
import Arweave from 'arweave';
|
|
18
|
-
import {
|
|
18
|
+
import { IO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
19
19
|
import { isProcessConfiguration, isProcessIdConfiguration, } from '../io.js';
|
|
20
20
|
import { AOProcess } from './contracts/ao-process.js';
|
|
21
21
|
import { InvalidContractConfigurationError } from './error.js';
|
|
@@ -38,7 +38,7 @@ export class IOReadable {
|
|
|
38
38
|
constructor(config, arweave = Arweave.init({})) {
|
|
39
39
|
if (!config) {
|
|
40
40
|
this.process = new AOProcess({
|
|
41
|
-
processId:
|
|
41
|
+
processId: IO_TESTNET_PROCESS_ID,
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
else if (isProcessConfiguration(config)) {
|
|
@@ -57,31 +57,47 @@ export class IOReadable {
|
|
|
57
57
|
}
|
|
58
58
|
this.arweave = arweave;
|
|
59
59
|
}
|
|
60
|
-
async
|
|
60
|
+
async getInfo() {
|
|
61
|
+
return this.process.read({
|
|
62
|
+
tags: [{ name: 'Action', value: 'Info' }],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async getEpochSettings(params) {
|
|
61
66
|
const allTags = [
|
|
62
|
-
{ name: 'Action', value: 'Epoch' },
|
|
67
|
+
{ name: 'Action', value: 'Epoch-Settings' },
|
|
63
68
|
{
|
|
64
|
-
// TODO: default this to the current network time
|
|
65
69
|
name: 'Timestamp',
|
|
66
|
-
value:
|
|
70
|
+
value: params?.timestamp?.toString() ??
|
|
71
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
72
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
73
|
+
})).timestamp.toString(),
|
|
67
74
|
},
|
|
68
75
|
{
|
|
69
|
-
name: '
|
|
70
|
-
value:
|
|
76
|
+
name: 'Epoch-Index',
|
|
77
|
+
value: params?.epochIndex?.toString(),
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
81
|
+
return this.process.read({
|
|
82
|
+
tags: prunedTags,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async getEpoch(epoch) {
|
|
86
|
+
const allTags = [
|
|
87
|
+
{ name: 'Action', value: 'Epoch' },
|
|
88
|
+
{
|
|
89
|
+
name: 'Timestamp',
|
|
90
|
+
value: epoch?.timestamp?.toString() ??
|
|
91
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
92
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
93
|
+
})).timestamp.toString(),
|
|
71
94
|
},
|
|
72
95
|
{
|
|
73
|
-
name: '
|
|
96
|
+
name: 'Epoch-Index',
|
|
74
97
|
value: epoch?.epochIndex?.toString(),
|
|
75
98
|
},
|
|
76
99
|
];
|
|
77
100
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
78
|
-
// if it only contains the action, add default timestamp
|
|
79
|
-
if (prunedTags.length === 1) {
|
|
80
|
-
prunedTags.push({
|
|
81
|
-
name: 'Timestamp',
|
|
82
|
-
value: (await this.arweave.blocks.getCurrent()).timestamp.toString(),
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
101
|
return this.process.read({
|
|
86
102
|
tags: prunedTags,
|
|
87
103
|
});
|
|
@@ -101,13 +117,13 @@ export class IOReadable {
|
|
|
101
117
|
}
|
|
102
118
|
async getArNSReservedNames() {
|
|
103
119
|
return this.process.read({
|
|
104
|
-
tags: [{ name: 'Action', value: '
|
|
120
|
+
tags: [{ name: 'Action', value: 'Reserved-Names' }],
|
|
105
121
|
});
|
|
106
122
|
}
|
|
107
123
|
async getArNSReservedName({ name, }) {
|
|
108
124
|
return this.process.read({
|
|
109
125
|
tags: [
|
|
110
|
-
{ name: 'Action', value: '
|
|
126
|
+
{ name: 'Action', value: 'Reserved-Name' },
|
|
111
127
|
{ name: 'Name', value: name },
|
|
112
128
|
],
|
|
113
129
|
});
|
|
@@ -142,125 +158,98 @@ export class IOReadable {
|
|
|
142
158
|
return this.process.read({
|
|
143
159
|
tags: [
|
|
144
160
|
{ name: 'Action', value: 'Epoch' },
|
|
145
|
-
{
|
|
161
|
+
{
|
|
162
|
+
name: 'Timestamp',
|
|
163
|
+
value: (await this.arweave.blocks.getCurrent().catch(() => {
|
|
164
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
165
|
+
})).timestamp.toString(),
|
|
166
|
+
},
|
|
146
167
|
],
|
|
147
168
|
});
|
|
148
169
|
}
|
|
149
170
|
async getPrescribedObservers(epoch) {
|
|
150
171
|
const allTags = [
|
|
151
|
-
{ name: 'Action', value: '
|
|
172
|
+
{ name: 'Action', value: 'Epoch-Prescribed-Observers' },
|
|
152
173
|
{
|
|
153
174
|
name: 'Timestamp',
|
|
154
|
-
value: epoch
|
|
175
|
+
value: epoch?.timestamp?.toString() ??
|
|
176
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
177
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
178
|
+
})).timestamp.toString(),
|
|
155
179
|
},
|
|
156
180
|
{
|
|
157
|
-
name: '
|
|
158
|
-
value: epoch?.blockHeight?.toString(),
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
name: 'EpochIndex',
|
|
181
|
+
name: 'Epoch-Index',
|
|
162
182
|
value: epoch?.epochIndex?.toString(),
|
|
163
183
|
},
|
|
164
184
|
];
|
|
165
185
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
166
|
-
// if it only contains the action, add default timestamp
|
|
167
|
-
if (prunedTags.length === 1) {
|
|
168
|
-
prunedTags.push({
|
|
169
|
-
name: 'Timestamp',
|
|
170
|
-
value: `${Date.now()}`,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
186
|
return this.process.read({
|
|
174
187
|
tags: prunedTags,
|
|
175
188
|
});
|
|
176
189
|
}
|
|
177
190
|
async getPrescribedNames(epoch) {
|
|
178
191
|
const allTags = [
|
|
179
|
-
{ name: 'Action', value: '
|
|
192
|
+
{ name: 'Action', value: 'Epoch-Prescribed-Names' },
|
|
180
193
|
{
|
|
181
194
|
name: 'Timestamp',
|
|
182
|
-
value: epoch
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
value: epoch?.blockHeight?.toString(),
|
|
195
|
+
value: epoch?.timestamp?.toString() ??
|
|
196
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
197
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
198
|
+
})).timestamp.toString(),
|
|
187
199
|
},
|
|
188
200
|
{
|
|
189
|
-
name: '
|
|
201
|
+
name: 'Epoch-Index',
|
|
190
202
|
value: epoch?.epochIndex?.toString(),
|
|
191
203
|
},
|
|
192
204
|
];
|
|
193
205
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
194
|
-
// if it only contains the action, add default timestamp
|
|
195
|
-
if (prunedTags.length === 1) {
|
|
196
|
-
prunedTags.push({
|
|
197
|
-
name: 'Timestamp',
|
|
198
|
-
value: `${Date.now()}`, // TODO; replace with fetch the current network time
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
206
|
return this.process.read({
|
|
202
207
|
tags: prunedTags,
|
|
203
208
|
});
|
|
204
209
|
}
|
|
205
210
|
async getObservations(epoch) {
|
|
206
211
|
const allTags = [
|
|
207
|
-
{ name: 'Action', value: '
|
|
212
|
+
{ name: 'Action', value: 'Epoch-Observations' },
|
|
208
213
|
{
|
|
209
214
|
name: 'Timestamp',
|
|
210
|
-
value: epoch
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
value: epoch?.blockHeight?.toString(),
|
|
215
|
+
value: epoch?.timestamp?.toString() ??
|
|
216
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
217
|
+
return { timestamp: `${Date.now()}` }; // fallback to current time
|
|
218
|
+
})).timestamp.toString(),
|
|
215
219
|
},
|
|
216
220
|
{
|
|
217
|
-
name: '
|
|
221
|
+
name: 'Epoch-Index',
|
|
218
222
|
value: epoch?.epochIndex?.toString(),
|
|
219
223
|
},
|
|
220
224
|
];
|
|
221
225
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
222
|
-
// if it only contains the action, add default timestamp
|
|
223
|
-
if (prunedTags.length === 1) {
|
|
224
|
-
prunedTags.push({
|
|
225
|
-
name: 'Timestamp',
|
|
226
|
-
value: (await this.arweave.blocks.getCurrent()).timestamp.toString(),
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
226
|
return this.process.read({
|
|
230
227
|
tags: prunedTags,
|
|
231
228
|
});
|
|
232
229
|
}
|
|
233
230
|
async getDistributions(epoch) {
|
|
234
231
|
const allTags = [
|
|
235
|
-
{ name: 'Action', value: '
|
|
232
|
+
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
236
233
|
{
|
|
237
234
|
name: 'Timestamp',
|
|
238
|
-
value: epoch
|
|
235
|
+
value: epoch?.timestamp?.toString() ??
|
|
236
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
237
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
238
|
+
})).timestamp.toString(),
|
|
239
239
|
},
|
|
240
240
|
{
|
|
241
|
-
name: '
|
|
242
|
-
value: epoch?.blockHeight?.toString(),
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
name: 'EpochIndex',
|
|
241
|
+
name: 'Epoch-Index',
|
|
246
242
|
value: epoch?.epochIndex?.toString(),
|
|
247
243
|
},
|
|
248
244
|
];
|
|
249
245
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
250
|
-
// if it only contains the action, add default timestamp
|
|
251
|
-
if (prunedTags.length === 1) {
|
|
252
|
-
prunedTags.push({
|
|
253
|
-
name: 'Timestamp',
|
|
254
|
-
value: (await this.arweave.blocks.getCurrent()).timestamp.toString(),
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
246
|
return this.process.read({
|
|
258
247
|
tags: prunedTags,
|
|
259
248
|
});
|
|
260
249
|
}
|
|
261
250
|
async getTokenCost({ intent, purchaseType, years, name, quantity, }) {
|
|
262
251
|
const allTags = [
|
|
263
|
-
{ name: 'Action', value: '
|
|
252
|
+
{ name: 'Action', value: 'Token-Cost' },
|
|
264
253
|
{
|
|
265
254
|
name: 'Intent',
|
|
266
255
|
value: intent,
|
|
@@ -278,9 +267,15 @@ export class IOReadable {
|
|
|
278
267
|
value: quantity?.toString(),
|
|
279
268
|
},
|
|
280
269
|
{
|
|
281
|
-
name: '
|
|
270
|
+
name: 'Purchase-Type',
|
|
282
271
|
value: purchaseType,
|
|
283
272
|
},
|
|
273
|
+
{
|
|
274
|
+
name: 'Timestamp',
|
|
275
|
+
value: (await this.arweave.blocks.getCurrent().catch(() => {
|
|
276
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
277
|
+
})).timestamp.toString(),
|
|
278
|
+
},
|
|
284
279
|
];
|
|
285
280
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
286
281
|
return this.process.read({
|
|
@@ -294,7 +289,7 @@ export class IOWriteable extends IOReadable {
|
|
|
294
289
|
if (Object.keys(config).length === 0) {
|
|
295
290
|
super({
|
|
296
291
|
process: new AOProcess({
|
|
297
|
-
processId:
|
|
292
|
+
processId: IO_TESTNET_PROCESS_ID,
|
|
298
293
|
}),
|
|
299
294
|
});
|
|
300
295
|
this.signer = signer;
|
|
@@ -337,17 +332,17 @@ export class IOWriteable extends IOReadable {
|
|
|
337
332
|
const { tags = [] } = options || {};
|
|
338
333
|
const allTags = [
|
|
339
334
|
...tags,
|
|
340
|
-
{ name: 'Action', value: '
|
|
335
|
+
{ name: 'Action', value: 'Join-Network' },
|
|
341
336
|
{
|
|
342
|
-
name: '
|
|
337
|
+
name: 'Operator-Stake',
|
|
343
338
|
value: operatorStake.valueOf().toString(),
|
|
344
339
|
},
|
|
345
340
|
{
|
|
346
|
-
name: '
|
|
341
|
+
name: 'Allow-Delegated-Staking',
|
|
347
342
|
value: allowDelegatedStaking.toString(),
|
|
348
343
|
},
|
|
349
344
|
{
|
|
350
|
-
name: '
|
|
345
|
+
name: 'Delegate-Reward-Share-Ratio',
|
|
351
346
|
value: delegateRewardShareRatio.toString(),
|
|
352
347
|
},
|
|
353
348
|
{
|
|
@@ -359,7 +354,7 @@ export class IOWriteable extends IOReadable {
|
|
|
359
354
|
value: label,
|
|
360
355
|
},
|
|
361
356
|
{
|
|
362
|
-
name: '
|
|
357
|
+
name: 'Min-Delegated-Stake',
|
|
363
358
|
value: minDelegatedStake.valueOf().toString(),
|
|
364
359
|
},
|
|
365
360
|
{
|
|
@@ -379,11 +374,11 @@ export class IOWriteable extends IOReadable {
|
|
|
379
374
|
value: protocol,
|
|
380
375
|
},
|
|
381
376
|
{
|
|
382
|
-
name: '
|
|
377
|
+
name: 'Auto-Stake',
|
|
383
378
|
value: autoStake.toString(),
|
|
384
379
|
},
|
|
385
380
|
{
|
|
386
|
-
name: '
|
|
381
|
+
name: 'Observer-Address',
|
|
387
382
|
value: observerAddress,
|
|
388
383
|
},
|
|
389
384
|
];
|
|
@@ -397,27 +392,27 @@ export class IOWriteable extends IOReadable {
|
|
|
397
392
|
const { tags = [] } = options || {};
|
|
398
393
|
const allTags = [
|
|
399
394
|
...tags,
|
|
400
|
-
{ name: 'Action', value: '
|
|
395
|
+
{ name: 'Action', value: 'Update-Gateway-Settings' },
|
|
401
396
|
{ name: 'Label', value: label },
|
|
402
397
|
{ name: 'Note', value: note },
|
|
403
398
|
{ name: 'FQDN', value: fqdn },
|
|
404
399
|
{ name: 'Port', value: port?.toString() },
|
|
405
400
|
{ name: 'Properties', value: properties },
|
|
406
401
|
{ name: 'Protocol', value: protocol },
|
|
407
|
-
{ name: '
|
|
402
|
+
{ name: 'Observer-Address', value: observerAddress },
|
|
408
403
|
{
|
|
409
|
-
name: '
|
|
404
|
+
name: 'Allow-Delegated-Staking',
|
|
410
405
|
value: allowDelegatedStaking?.toString(),
|
|
411
406
|
},
|
|
412
407
|
{
|
|
413
|
-
name: '
|
|
408
|
+
name: 'Delegate-Reward-Share-Ratio',
|
|
414
409
|
value: delegateRewardShareRatio?.toString(),
|
|
415
410
|
},
|
|
416
411
|
{
|
|
417
|
-
name: '
|
|
412
|
+
name: 'Min-Delegated-Stake',
|
|
418
413
|
value: minDelegatedStake?.valueOf().toString(),
|
|
419
414
|
},
|
|
420
|
-
{ name: '
|
|
415
|
+
{ name: 'Auto-Stake', value: autoStake?.toString() },
|
|
421
416
|
];
|
|
422
417
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
423
418
|
return this.process.send({
|
|
@@ -431,7 +426,7 @@ export class IOWriteable extends IOReadable {
|
|
|
431
426
|
signer: this.signer,
|
|
432
427
|
tags: [
|
|
433
428
|
...tags,
|
|
434
|
-
{ name: 'Action', value: '
|
|
429
|
+
{ name: 'Action', value: 'Delegate-Stake' },
|
|
435
430
|
{ name: 'Target', value: params.target },
|
|
436
431
|
{ name: 'Quantity', value: params.stakeQty.valueOf().toString() },
|
|
437
432
|
],
|
|
@@ -443,7 +438,7 @@ export class IOWriteable extends IOReadable {
|
|
|
443
438
|
signer: this.signer,
|
|
444
439
|
tags: [
|
|
445
440
|
...tags,
|
|
446
|
-
{ name: 'Action', value: '
|
|
441
|
+
{ name: 'Action', value: 'Decrease-Delegate-Stake' },
|
|
447
442
|
{ name: 'Target', value: params.target },
|
|
448
443
|
{ name: 'Quantity', value: params.decreaseQty.valueOf().toString() },
|
|
449
444
|
],
|
|
@@ -455,7 +450,7 @@ export class IOWriteable extends IOReadable {
|
|
|
455
450
|
signer: this.signer,
|
|
456
451
|
tags: [
|
|
457
452
|
...tags,
|
|
458
|
-
{ name: 'Action', value: '
|
|
453
|
+
{ name: 'Action', value: 'Increase-Operator-Stake' },
|
|
459
454
|
{ name: 'Quantity', value: params.increaseQty.valueOf().toString() },
|
|
460
455
|
],
|
|
461
456
|
});
|
|
@@ -466,7 +461,7 @@ export class IOWriteable extends IOReadable {
|
|
|
466
461
|
signer: this.signer,
|
|
467
462
|
tags: [
|
|
468
463
|
...tags,
|
|
469
|
-
{ name: 'Action', value: '
|
|
464
|
+
{ name: 'Action', value: 'Decrease-Operator-Stake' },
|
|
470
465
|
{ name: 'Quantity', value: params.decreaseQty.valueOf().toString() },
|
|
471
466
|
],
|
|
472
467
|
});
|
|
@@ -477,13 +472,13 @@ export class IOWriteable extends IOReadable {
|
|
|
477
472
|
signer: this.signer,
|
|
478
473
|
tags: [
|
|
479
474
|
...tags,
|
|
480
|
-
{ name: 'Action', value: '
|
|
475
|
+
{ name: 'Action', value: 'Save-Observations' },
|
|
481
476
|
{
|
|
482
|
-
name: '
|
|
477
|
+
name: 'Report-Tx-Id',
|
|
483
478
|
value: params.reportTxId,
|
|
484
479
|
},
|
|
485
480
|
{
|
|
486
|
-
name: '
|
|
481
|
+
name: 'Failed-Gateways',
|
|
487
482
|
value: params.failedGateways.join(','),
|
|
488
483
|
},
|
|
489
484
|
],
|
|
@@ -497,11 +492,11 @@ export class IOWriteable extends IOReadable {
|
|
|
497
492
|
const { tags = [] } = options || {};
|
|
498
493
|
const allTags = [
|
|
499
494
|
...tags,
|
|
500
|
-
{ name: 'Action', value: '
|
|
495
|
+
{ name: 'Action', value: 'Buy-Record' },
|
|
501
496
|
{ name: 'Name', value: params.name },
|
|
502
497
|
{ name: 'Years', value: params.years?.toString() ?? '1' },
|
|
503
|
-
{ name: '
|
|
504
|
-
{ name: '
|
|
498
|
+
{ name: 'Process-Id', value: params.processId },
|
|
499
|
+
{ name: 'Purchase-Type', value: params.type || 'lease' },
|
|
505
500
|
];
|
|
506
501
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
507
502
|
return this.process.send({
|
|
@@ -515,7 +510,7 @@ export class IOWriteable extends IOReadable {
|
|
|
515
510
|
signer: this.signer,
|
|
516
511
|
tags: [
|
|
517
512
|
...tags,
|
|
518
|
-
{ name: 'Action', value: '
|
|
513
|
+
{ name: 'Action', value: 'Extend-Lease' },
|
|
519
514
|
{ name: 'Name', value: params.name },
|
|
520
515
|
{ name: 'Years', value: params.years.toString() },
|
|
521
516
|
],
|
|
@@ -527,7 +522,7 @@ export class IOWriteable extends IOReadable {
|
|
|
527
522
|
signer: this.signer,
|
|
528
523
|
tags: [
|
|
529
524
|
...tags,
|
|
530
|
-
{ name: 'Action', value: '
|
|
525
|
+
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
531
526
|
{ name: 'Name', value: params.name },
|
|
532
527
|
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
533
528
|
],
|
package/lib/esm/constants.js
CHANGED
|
@@ -21,8 +21,11 @@ export const FQDN_REGEX = new RegExp('^(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Z
|
|
|
21
21
|
export const SORT_KEY_REGEX = new RegExp('^[0-9]{12},[0-9]{13},[a-fA-F0-9]{64}$');
|
|
22
22
|
export const ARNS_TESTNET_REGISTRY_TX = process.env.ARNS_REGISTRY_TX ?? 'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';
|
|
23
23
|
export const ARNS_DEVNET_REGISTRY_TX = '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8';
|
|
24
|
-
export const
|
|
24
|
+
export const IO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
|
|
25
|
+
// backwards compatibility - TODO: remove in v2.0.0
|
|
26
|
+
export const ioDevnetProcessId = IO_DEVNET_PROCESS_ID;
|
|
27
|
+
export const IO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
25
28
|
export const MIO_PER_IO = 1_000_000;
|
|
26
|
-
export const AOS_MODULE_ID = '
|
|
27
|
-
export const ANT_LUA_ID = '
|
|
29
|
+
export const AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
|
|
30
|
+
export const ANT_LUA_ID = '3OlGzE5mrsN2GsxCYM0Tae1KzWepGOr5a94deOWmApM';
|
|
28
31
|
export const DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
* You should have received a copy of the GNU Affero General Public License
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
|
+
import { EventEmitter } from 'eventemitter3';
|
|
17
18
|
import { pLimit } from 'plimit-lit';
|
|
18
19
|
import { ANT } from '../../common/ant.js';
|
|
19
20
|
import { IO } from '../../common/io.js';
|
|
20
|
-
import {
|
|
21
|
-
// throttle the requests to avoid rate limiting
|
|
22
|
-
const throttle = pLimit(50);
|
|
21
|
+
import { IO_TESTNET_PROCESS_ID } from '../../constants.js';
|
|
23
22
|
export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init({
|
|
24
|
-
processId:
|
|
23
|
+
processId: IO_TESTNET_PROCESS_ID,
|
|
25
24
|
}), }) => {
|
|
25
|
+
const throttle = pLimit(50);
|
|
26
26
|
// get the record names of the registry - TODO: this may need to be paginated
|
|
27
27
|
const uniqueContractProcessIds = await contract
|
|
28
28
|
.getArNSRecords()
|
|
@@ -30,14 +30,93 @@ export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init
|
|
|
30
30
|
.filter((record) => record.processId !== undefined)
|
|
31
31
|
.map((record) => record.processId));
|
|
32
32
|
// check the contract owner and controllers
|
|
33
|
-
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.
|
|
33
|
+
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
|
|
34
34
|
const ant = ANT.init({
|
|
35
35
|
processId,
|
|
36
36
|
});
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const { Owner, Controllers } = await ant.getState();
|
|
38
|
+
if (Owner === address || Controllers.includes(address)) {
|
|
39
|
+
return processId;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
40
42
|
})));
|
|
43
|
+
if (ownedOrControlledByWallet.length === 0) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
41
46
|
// TODO: insert gql query to find ANT processes owned by wallet given wallet not currently in the registry
|
|
42
47
|
return [...new Set(ownedOrControlledByWallet)];
|
|
43
48
|
};
|
|
49
|
+
function timeout(ms, promise) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const timer = setTimeout(() => {
|
|
52
|
+
reject(new Error('Timeout'));
|
|
53
|
+
}, ms);
|
|
54
|
+
promise
|
|
55
|
+
.then((value) => {
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
resolve(value);
|
|
58
|
+
})
|
|
59
|
+
.catch((err) => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
reject(err);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export class ArNSEventEmitter extends EventEmitter {
|
|
66
|
+
contract;
|
|
67
|
+
timeoutMs; // timeout for each request to 3 seconds
|
|
68
|
+
throttle;
|
|
69
|
+
constructor({ contract = IO.init({
|
|
70
|
+
processId: IO_TESTNET_PROCESS_ID,
|
|
71
|
+
}), timeoutMs = 60_000, concurrency = 30, }) {
|
|
72
|
+
super();
|
|
73
|
+
this.contract = contract;
|
|
74
|
+
this.timeoutMs = timeoutMs;
|
|
75
|
+
this.throttle = pLimit(concurrency);
|
|
76
|
+
}
|
|
77
|
+
async fetchProcessesOwnedByWallet({ address }) {
|
|
78
|
+
const uniqueContractProcessIds = {};
|
|
79
|
+
await timeout(this.timeoutMs, this.contract.getArNSRecords().catch((e) => {
|
|
80
|
+
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
81
|
+
return {};
|
|
82
|
+
})).then((records) => {
|
|
83
|
+
if (!records)
|
|
84
|
+
return;
|
|
85
|
+
Object.entries(records).forEach(([name, record]) => {
|
|
86
|
+
if (record.processId === undefined) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (uniqueContractProcessIds[record.processId] === undefined) {
|
|
90
|
+
uniqueContractProcessIds[record.processId] = {
|
|
91
|
+
state: undefined,
|
|
92
|
+
names: {},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
uniqueContractProcessIds[record.processId].names[name] = record;
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
99
|
+
// check the contract owner and controllers
|
|
100
|
+
this.emit('progress', 0, idCount);
|
|
101
|
+
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => this.throttle(async () => {
|
|
102
|
+
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
103
|
+
this.emit('progress', i + 1, idCount);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const ant = ANT.init({
|
|
107
|
+
processId,
|
|
108
|
+
});
|
|
109
|
+
const state = (await timeout(this.timeoutMs, ant.getState()).catch((e) => {
|
|
110
|
+
this.emit('error', `Error getting state for process ${processId}: ${e}`);
|
|
111
|
+
return undefined;
|
|
112
|
+
}));
|
|
113
|
+
if (state?.Owner === address ||
|
|
114
|
+
state?.Controllers.includes(address)) {
|
|
115
|
+
uniqueContractProcessIds[processId].state = state;
|
|
116
|
+
this.emit('process', processId, uniqueContractProcessIds[processId]);
|
|
117
|
+
}
|
|
118
|
+
this.emit('progress', i + 1, idCount);
|
|
119
|
+
})));
|
|
120
|
+
this.emit('end', uniqueContractProcessIds);
|
|
121
|
+
}
|
|
122
|
+
}
|
package/lib/esm/utils/index.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
export function safeDecode(data) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(data);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/lib/esm/version.js
CHANGED
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
import { ANTRecord } from '../contract-state.js';
|
|
18
|
-
import { AoANTRead, AoANTWrite, ProcessConfiguration } from '../io.js';
|
|
18
|
+
import { AoANTRead, AoANTState, AoANTWrite, ProcessConfiguration } from '../io.js';
|
|
19
19
|
import { AoMessageResult, WalletAddress, WithSigner } from '../types.js';
|
|
20
20
|
import { AOProcess } from './contracts/ao-process.js';
|
|
21
21
|
export declare class AoANTReadable implements AoANTRead {
|
|
22
22
|
protected process: AOProcess;
|
|
23
23
|
constructor(config: Required<ProcessConfiguration>);
|
|
24
|
+
getState(): Promise<AoANTState>;
|
|
24
25
|
getInfo(): Promise<{
|
|
25
26
|
Name: string;
|
|
26
27
|
Ticker: string;
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import Arweave from 'arweave';
|
|
18
18
|
import { ArNSReservedNameData, EpochDistributionData, EpochObservations, WeightedObserver } from '../contract-state.js';
|
|
19
|
-
import { AoArNSNameData, AoEpochData, AoGateway, AoIORead, AoIOWrite, EpochInput } from '../io.js';
|
|
19
|
+
import { AoArNSNameData, AoEpochData, AoEpochSettings, AoGateway, AoIORead, AoIOWrite, EpochInput } from '../io.js';
|
|
20
20
|
import { mIOToken } from '../token.js';
|
|
21
21
|
import { AoMessageResult, ContractSigner, JoinNetworkParams, ProcessConfiguration, TransactionId, UpdateGatewaySettingsParams, WalletAddress, WithSigner, WriteOptions } from '../types.js';
|
|
22
22
|
import { AOProcess } from './contracts/ao-process.js';
|
|
@@ -43,6 +43,13 @@ export declare class IOReadable implements AoIORead {
|
|
|
43
43
|
protected process: AOProcess;
|
|
44
44
|
private arweave;
|
|
45
45
|
constructor(config?: ProcessConfiguration, arweave?: Arweave);
|
|
46
|
+
getInfo(): Promise<{
|
|
47
|
+
Name: string;
|
|
48
|
+
Ticker: string;
|
|
49
|
+
Logo: string;
|
|
50
|
+
Denomination: number;
|
|
51
|
+
}>;
|
|
52
|
+
getEpochSettings(params?: EpochInput): Promise<AoEpochSettings>;
|
|
46
53
|
getEpoch(epoch?: EpochInput): Promise<AoEpochData>;
|
|
47
54
|
getArNSRecord({ name, }: {
|
|
48
55
|
name: string;
|
|
@@ -66,18 +73,18 @@ export declare class IOReadable implements AoIORead {
|
|
|
66
73
|
getObservations(epoch?: EpochInput): Promise<EpochObservations>;
|
|
67
74
|
getDistributions(epoch?: EpochInput): Promise<EpochDistributionData>;
|
|
68
75
|
getTokenCost(params: {
|
|
69
|
-
intent: '
|
|
76
|
+
intent: 'Buy-Record';
|
|
70
77
|
purchaseType: 'permabuy' | 'lease';
|
|
71
78
|
years: number;
|
|
72
79
|
name: string;
|
|
73
80
|
}): Promise<number>;
|
|
74
81
|
getTokenCost(params: {
|
|
75
|
-
intent: '
|
|
82
|
+
intent: 'Extend-Lease';
|
|
76
83
|
years: number;
|
|
77
84
|
name: string;
|
|
78
85
|
}): Promise<number>;
|
|
79
86
|
getTokenCost(params: {
|
|
80
|
-
intent: '
|
|
87
|
+
intent: 'Increase-Undername-Limit';
|
|
81
88
|
quantity: number;
|
|
82
89
|
name: string;
|
|
83
90
|
}): Promise<number>;
|