@ar.io/sdk 1.2.0-alpha.8 → 1.2.0
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 +362 -634
- package/bundles/web.bundle.min.js +83 -83
- 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 +121 -97
- package/lib/cjs/constants.js +7 -4
- package/lib/cjs/utils/ao.js +1 -1
- package/lib/cjs/utils/graphql/processes.js +87 -7
- 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 +121 -97
- package/lib/esm/constants.js +6 -3
- package/lib/esm/utils/ao.js +1 -1
- package/lib/esm/utils/graphql/processes.js +85 -6
- 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 +24 -1
- package/lib/types/constants.d.ts +4 -2
- package/lib/types/io.d.ts +35 -2
- package/lib/types/utils/ao.d.ts +5 -5
- 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
|
@@ -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(),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Epoch-Index',
|
|
77
|
+
value: params?.epochIndex?.toString(),
|
|
67
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' },
|
|
68
88
|
{
|
|
69
|
-
name: '
|
|
70
|
-
value: epoch?.
|
|
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,118 +158,126 @@ 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
|
|
195
|
+
value: epoch?.timestamp?.toString() ??
|
|
196
|
+
(await this.arweave.blocks.getCurrent().catch(() => {
|
|
197
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
198
|
+
})).timestamp.toString(),
|
|
183
199
|
},
|
|
184
200
|
{
|
|
185
|
-
name: '
|
|
186
|
-
value: epoch?.blockHeight?.toString(),
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
name: 'EpochIndex',
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
246
|
+
return this.process.read({
|
|
247
|
+
tags: prunedTags,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
async getTokenCost({ intent, purchaseType, years, name, quantity, }) {
|
|
251
|
+
const allTags = [
|
|
252
|
+
{ name: 'Action', value: 'Token-Cost' },
|
|
253
|
+
{
|
|
254
|
+
name: 'Intent',
|
|
255
|
+
value: intent,
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: 'Name',
|
|
259
|
+
value: name,
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: 'Years',
|
|
263
|
+
value: years?.toString(),
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: 'Quantity',
|
|
267
|
+
value: quantity?.toString(),
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: 'Purchase-Type',
|
|
271
|
+
value: purchaseType,
|
|
272
|
+
},
|
|
273
|
+
{
|
|
253
274
|
name: 'Timestamp',
|
|
254
|
-
value: (await this.arweave.blocks.getCurrent()
|
|
255
|
-
|
|
256
|
-
|
|
275
|
+
value: (await this.arweave.blocks.getCurrent().catch(() => {
|
|
276
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
277
|
+
})).timestamp.toString(),
|
|
278
|
+
},
|
|
279
|
+
];
|
|
280
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
257
281
|
return this.process.read({
|
|
258
282
|
tags: prunedTags,
|
|
259
283
|
});
|
|
@@ -308,17 +332,17 @@ export class IOWriteable extends IOReadable {
|
|
|
308
332
|
const { tags = [] } = options || {};
|
|
309
333
|
const allTags = [
|
|
310
334
|
...tags,
|
|
311
|
-
{ name: 'Action', value: '
|
|
335
|
+
{ name: 'Action', value: 'Join-Network' },
|
|
312
336
|
{
|
|
313
|
-
name: '
|
|
337
|
+
name: 'Operator-Stake',
|
|
314
338
|
value: operatorStake.valueOf().toString(),
|
|
315
339
|
},
|
|
316
340
|
{
|
|
317
|
-
name: '
|
|
341
|
+
name: 'Allow-Delegated-Staking',
|
|
318
342
|
value: allowDelegatedStaking.toString(),
|
|
319
343
|
},
|
|
320
344
|
{
|
|
321
|
-
name: '
|
|
345
|
+
name: 'Delegate-Reward-Share-Ratio',
|
|
322
346
|
value: delegateRewardShareRatio.toString(),
|
|
323
347
|
},
|
|
324
348
|
{
|
|
@@ -330,7 +354,7 @@ export class IOWriteable extends IOReadable {
|
|
|
330
354
|
value: label,
|
|
331
355
|
},
|
|
332
356
|
{
|
|
333
|
-
name: '
|
|
357
|
+
name: 'Min-Delegated-Stake',
|
|
334
358
|
value: minDelegatedStake.valueOf().toString(),
|
|
335
359
|
},
|
|
336
360
|
{
|
|
@@ -350,11 +374,11 @@ export class IOWriteable extends IOReadable {
|
|
|
350
374
|
value: protocol,
|
|
351
375
|
},
|
|
352
376
|
{
|
|
353
|
-
name: '
|
|
377
|
+
name: 'Auto-Stake',
|
|
354
378
|
value: autoStake.toString(),
|
|
355
379
|
},
|
|
356
380
|
{
|
|
357
|
-
name: '
|
|
381
|
+
name: 'Observer-Address',
|
|
358
382
|
value: observerAddress,
|
|
359
383
|
},
|
|
360
384
|
];
|
|
@@ -368,27 +392,27 @@ export class IOWriteable extends IOReadable {
|
|
|
368
392
|
const { tags = [] } = options || {};
|
|
369
393
|
const allTags = [
|
|
370
394
|
...tags,
|
|
371
|
-
{ name: 'Action', value: '
|
|
395
|
+
{ name: 'Action', value: 'Update-Gateway-Settings' },
|
|
372
396
|
{ name: 'Label', value: label },
|
|
373
397
|
{ name: 'Note', value: note },
|
|
374
398
|
{ name: 'FQDN', value: fqdn },
|
|
375
399
|
{ name: 'Port', value: port?.toString() },
|
|
376
400
|
{ name: 'Properties', value: properties },
|
|
377
401
|
{ name: 'Protocol', value: protocol },
|
|
378
|
-
{ name: '
|
|
402
|
+
{ name: 'Observer-Address', value: observerAddress },
|
|
379
403
|
{
|
|
380
|
-
name: '
|
|
404
|
+
name: 'Allow-Delegated-Staking',
|
|
381
405
|
value: allowDelegatedStaking?.toString(),
|
|
382
406
|
},
|
|
383
407
|
{
|
|
384
|
-
name: '
|
|
408
|
+
name: 'Delegate-Reward-Share-Ratio',
|
|
385
409
|
value: delegateRewardShareRatio?.toString(),
|
|
386
410
|
},
|
|
387
411
|
{
|
|
388
|
-
name: '
|
|
412
|
+
name: 'Min-Delegated-Stake',
|
|
389
413
|
value: minDelegatedStake?.valueOf().toString(),
|
|
390
414
|
},
|
|
391
|
-
{ name: '
|
|
415
|
+
{ name: 'Auto-Stake', value: autoStake?.toString() },
|
|
392
416
|
];
|
|
393
417
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
394
418
|
return this.process.send({
|
|
@@ -402,7 +426,7 @@ export class IOWriteable extends IOReadable {
|
|
|
402
426
|
signer: this.signer,
|
|
403
427
|
tags: [
|
|
404
428
|
...tags,
|
|
405
|
-
{ name: 'Action', value: '
|
|
429
|
+
{ name: 'Action', value: 'Delegate-Stake' },
|
|
406
430
|
{ name: 'Target', value: params.target },
|
|
407
431
|
{ name: 'Quantity', value: params.stakeQty.valueOf().toString() },
|
|
408
432
|
],
|
|
@@ -414,7 +438,7 @@ export class IOWriteable extends IOReadable {
|
|
|
414
438
|
signer: this.signer,
|
|
415
439
|
tags: [
|
|
416
440
|
...tags,
|
|
417
|
-
{ name: 'Action', value: '
|
|
441
|
+
{ name: 'Action', value: 'Decrease-Delegate-Stake' },
|
|
418
442
|
{ name: 'Target', value: params.target },
|
|
419
443
|
{ name: 'Quantity', value: params.decreaseQty.valueOf().toString() },
|
|
420
444
|
],
|
|
@@ -426,7 +450,7 @@ export class IOWriteable extends IOReadable {
|
|
|
426
450
|
signer: this.signer,
|
|
427
451
|
tags: [
|
|
428
452
|
...tags,
|
|
429
|
-
{ name: 'Action', value: '
|
|
453
|
+
{ name: 'Action', value: 'Increase-Operator-Stake' },
|
|
430
454
|
{ name: 'Quantity', value: params.increaseQty.valueOf().toString() },
|
|
431
455
|
],
|
|
432
456
|
});
|
|
@@ -437,7 +461,7 @@ export class IOWriteable extends IOReadable {
|
|
|
437
461
|
signer: this.signer,
|
|
438
462
|
tags: [
|
|
439
463
|
...tags,
|
|
440
|
-
{ name: 'Action', value: '
|
|
464
|
+
{ name: 'Action', value: 'Decrease-Operator-Stake' },
|
|
441
465
|
{ name: 'Quantity', value: params.decreaseQty.valueOf().toString() },
|
|
442
466
|
],
|
|
443
467
|
});
|
|
@@ -448,13 +472,13 @@ export class IOWriteable extends IOReadable {
|
|
|
448
472
|
signer: this.signer,
|
|
449
473
|
tags: [
|
|
450
474
|
...tags,
|
|
451
|
-
{ name: 'Action', value: '
|
|
475
|
+
{ name: 'Action', value: 'Save-Observations' },
|
|
452
476
|
{
|
|
453
|
-
name: '
|
|
477
|
+
name: 'Report-Tx-Id',
|
|
454
478
|
value: params.reportTxId,
|
|
455
479
|
},
|
|
456
480
|
{
|
|
457
|
-
name: '
|
|
481
|
+
name: 'Failed-Gateways',
|
|
458
482
|
value: params.failedGateways.join(','),
|
|
459
483
|
},
|
|
460
484
|
],
|
|
@@ -468,11 +492,11 @@ export class IOWriteable extends IOReadable {
|
|
|
468
492
|
const { tags = [] } = options || {};
|
|
469
493
|
const allTags = [
|
|
470
494
|
...tags,
|
|
471
|
-
{ name: 'Action', value: '
|
|
495
|
+
{ name: 'Action', value: 'Buy-Record' },
|
|
472
496
|
{ name: 'Name', value: params.name },
|
|
473
497
|
{ name: 'Years', value: params.years?.toString() ?? '1' },
|
|
474
|
-
{ name: '
|
|
475
|
-
{ name: '
|
|
498
|
+
{ name: 'Process-Id', value: params.processId },
|
|
499
|
+
{ name: 'Purchase-Type', value: params.type || 'lease' },
|
|
476
500
|
];
|
|
477
501
|
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
478
502
|
return this.process.send({
|
|
@@ -486,7 +510,7 @@ export class IOWriteable extends IOReadable {
|
|
|
486
510
|
signer: this.signer,
|
|
487
511
|
tags: [
|
|
488
512
|
...tags,
|
|
489
|
-
{ name: 'Action', value: '
|
|
513
|
+
{ name: 'Action', value: 'Extend-Lease' },
|
|
490
514
|
{ name: 'Name', value: params.name },
|
|
491
515
|
{ name: 'Years', value: params.years.toString() },
|
|
492
516
|
],
|
|
@@ -498,7 +522,7 @@ export class IOWriteable extends IOReadable {
|
|
|
498
522
|
signer: this.signer,
|
|
499
523
|
tags: [
|
|
500
524
|
...tags,
|
|
501
|
-
{ name: 'Action', value: '
|
|
525
|
+
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
502
526
|
{ name: 'Name', value: params.name },
|
|
503
527
|
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
504
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';
|
package/lib/esm/utils/ao.js
CHANGED
|
@@ -18,7 +18,7 @@ import { connect } from '@permaweb/aoconnect';
|
|
|
18
18
|
import { defaultArweave } from '../common/arweave.js';
|
|
19
19
|
import { AOProcess } from '../common/index.js';
|
|
20
20
|
import { ANT_LUA_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
|
|
21
|
-
export async function spawnANT({ module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID,
|
|
21
|
+
export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, }) {
|
|
22
22
|
//TODO: cache locally and only fetch if not cached
|
|
23
23
|
const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, {
|
|
24
24
|
decode: true,
|
|
@@ -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
21
|
import { ioDevnetProcessId } from '../../constants.js';
|
|
21
|
-
// throttle the requests to avoid rate limiting
|
|
22
|
-
const throttle = pLimit(50);
|
|
23
22
|
export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init({
|
|
24
23
|
processId: ioDevnetProcessId,
|
|
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: ioDevnetProcessId,
|
|
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;
|
|
@@ -65,6 +72,22 @@ export declare class IOReadable implements AoIORead {
|
|
|
65
72
|
getPrescribedNames(epoch?: EpochInput): Promise<string[]>;
|
|
66
73
|
getObservations(epoch?: EpochInput): Promise<EpochObservations>;
|
|
67
74
|
getDistributions(epoch?: EpochInput): Promise<EpochDistributionData>;
|
|
75
|
+
getTokenCost(params: {
|
|
76
|
+
intent: 'Buy-Record';
|
|
77
|
+
purchaseType: 'permabuy' | 'lease';
|
|
78
|
+
years: number;
|
|
79
|
+
name: string;
|
|
80
|
+
}): Promise<number>;
|
|
81
|
+
getTokenCost(params: {
|
|
82
|
+
intent: 'Extend-Lease';
|
|
83
|
+
years: number;
|
|
84
|
+
name: string;
|
|
85
|
+
}): Promise<number>;
|
|
86
|
+
getTokenCost(params: {
|
|
87
|
+
intent: 'Increase-Undername-Limit';
|
|
88
|
+
quantity: number;
|
|
89
|
+
name: string;
|
|
90
|
+
}): Promise<number>;
|
|
68
91
|
}
|
|
69
92
|
export declare class IOWriteable extends IOReadable implements AoIOWrite {
|
|
70
93
|
protected process: AOProcess;
|