@ar.io/sdk 3.1.0-alpha.8 → 3.1.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/bundles/web.bundle.min.js +58 -58
- package/lib/cjs/common/io.js +44 -94
- package/lib/cjs/utils/arweave.js +16 -12
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/io.js +45 -95
- package/lib/esm/utils/arweave.js +15 -10
- package/lib/esm/version.js +1 -1
- package/lib/types/common/io.d.ts +5 -19
- package/lib/types/types/io.d.ts +4 -2
- package/lib/types/utils/arweave.d.ts +1 -18
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/common/io.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ARIOWriteable = exports.ARIOReadable = exports.ARIO = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
4
19
|
const constants_js_1 = require("../constants.js");
|
|
5
20
|
const io_js_1 = require("../types/io.js");
|
|
6
21
|
const ao_js_1 = require("../utils/ao.js");
|
|
7
22
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
8
|
-
const arweave_js_2 = require("./arweave.js");
|
|
9
23
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
10
24
|
const error_js_1 = require("./error.js");
|
|
11
25
|
class ARIO {
|
|
@@ -23,8 +37,8 @@ class ARIO {
|
|
|
23
37
|
exports.ARIO = ARIO;
|
|
24
38
|
class ARIOReadable {
|
|
25
39
|
process;
|
|
26
|
-
|
|
27
|
-
constructor(config
|
|
40
|
+
epochSettings;
|
|
41
|
+
constructor(config) {
|
|
28
42
|
if (!config) {
|
|
29
43
|
this.process = new ao_process_js_1.AOProcess({
|
|
30
44
|
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
@@ -41,7 +55,6 @@ class ARIOReadable {
|
|
|
41
55
|
else {
|
|
42
56
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
43
57
|
}
|
|
44
|
-
this.arweave = arweave;
|
|
45
58
|
}
|
|
46
59
|
async getInfo() {
|
|
47
60
|
return this.process.read({
|
|
@@ -53,35 +66,32 @@ class ARIOReadable {
|
|
|
53
66
|
tags: [{ name: 'Action', value: 'Total-Token-Supply' }],
|
|
54
67
|
});
|
|
55
68
|
}
|
|
56
|
-
async
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
async computeEpochIndexForTimestamp(timestamp) {
|
|
70
|
+
const epochSettings = await this.getEpochSettings();
|
|
71
|
+
const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
|
|
72
|
+
const epochLengthMs = epochSettings.durationMs;
|
|
73
|
+
return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
|
|
74
|
+
}
|
|
75
|
+
async computeEpochIndex(params) {
|
|
76
|
+
const epochIndex = params?.epochIndex;
|
|
77
|
+
if (epochIndex !== undefined) {
|
|
78
|
+
return epochIndex.toString();
|
|
79
|
+
}
|
|
80
|
+
const timestamp = params?.timestamp;
|
|
81
|
+
if (timestamp !== undefined) {
|
|
82
|
+
return (await this.computeEpochIndexForTimestamp(timestamp)).toString();
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
async getEpochSettings() {
|
|
87
|
+
return (this.epochSettings ??= await this.process.read({
|
|
88
|
+
tags: [{ name: 'Action', value: 'Epoch-Settings' }],
|
|
89
|
+
}));
|
|
72
90
|
}
|
|
73
91
|
async getEpoch(epoch) {
|
|
74
92
|
const allTags = [
|
|
75
93
|
{ name: 'Action', value: 'Epoch' },
|
|
76
|
-
{
|
|
77
|
-
name: 'Timestamp',
|
|
78
|
-
value: epoch?.timestamp?.toString() ??
|
|
79
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: 'Epoch-Index',
|
|
83
|
-
value: epoch?.epochIndex?.toString(),
|
|
84
|
-
},
|
|
94
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
85
95
|
];
|
|
86
96
|
return this.process.read({
|
|
87
97
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -188,27 +198,13 @@ class ARIOReadable {
|
|
|
188
198
|
}
|
|
189
199
|
async getCurrentEpoch() {
|
|
190
200
|
return this.process.read({
|
|
191
|
-
tags: [
|
|
192
|
-
{ name: 'Action', value: 'Epoch' },
|
|
193
|
-
{
|
|
194
|
-
name: 'Timestamp',
|
|
195
|
-
value: (await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
196
|
-
},
|
|
197
|
-
],
|
|
201
|
+
tags: [{ name: 'Action', value: 'Epoch' }],
|
|
198
202
|
});
|
|
199
203
|
}
|
|
200
204
|
async getPrescribedObservers(epoch) {
|
|
201
205
|
const allTags = [
|
|
202
206
|
{ name: 'Action', value: 'Epoch-Prescribed-Observers' },
|
|
203
|
-
{
|
|
204
|
-
name: 'Timestamp',
|
|
205
|
-
value: epoch?.timestamp?.toString() ??
|
|
206
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
name: 'Epoch-Index',
|
|
210
|
-
value: epoch?.epochIndex?.toString(),
|
|
211
|
-
},
|
|
207
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
212
208
|
];
|
|
213
209
|
return this.process.read({
|
|
214
210
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -217,15 +213,7 @@ class ARIOReadable {
|
|
|
217
213
|
async getPrescribedNames(epoch) {
|
|
218
214
|
const allTags = [
|
|
219
215
|
{ name: 'Action', value: 'Epoch-Prescribed-Names' },
|
|
220
|
-
{
|
|
221
|
-
name: 'Timestamp',
|
|
222
|
-
value: epoch?.timestamp?.toString() ??
|
|
223
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: 'Epoch-Index',
|
|
227
|
-
value: epoch?.epochIndex?.toString(),
|
|
228
|
-
},
|
|
216
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
229
217
|
];
|
|
230
218
|
return this.process.read({
|
|
231
219
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -234,15 +222,7 @@ class ARIOReadable {
|
|
|
234
222
|
async getObservations(epoch) {
|
|
235
223
|
const allTags = [
|
|
236
224
|
{ name: 'Action', value: 'Epoch-Observations' },
|
|
237
|
-
{
|
|
238
|
-
name: 'Timestamp',
|
|
239
|
-
value: epoch?.timestamp?.toString() ??
|
|
240
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
name: 'Epoch-Index',
|
|
244
|
-
value: epoch?.epochIndex?.toString(),
|
|
245
|
-
},
|
|
225
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
246
226
|
];
|
|
247
227
|
return this.process.read({
|
|
248
228
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -251,15 +231,7 @@ class ARIOReadable {
|
|
|
251
231
|
async getDistributions(epoch) {
|
|
252
232
|
const allTags = [
|
|
253
233
|
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
254
|
-
{
|
|
255
|
-
name: 'Timestamp',
|
|
256
|
-
value: epoch?.timestamp?.toString() ??
|
|
257
|
-
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
name: 'Epoch-Index',
|
|
261
|
-
value: epoch?.epochIndex?.toString(),
|
|
262
|
-
},
|
|
234
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
263
235
|
];
|
|
264
236
|
return this.process.read({
|
|
265
237
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -288,17 +260,6 @@ class ARIOReadable {
|
|
|
288
260
|
name: 'Purchase-Type',
|
|
289
261
|
value: type,
|
|
290
262
|
},
|
|
291
|
-
{
|
|
292
|
-
name: 'Timestamp',
|
|
293
|
-
value: (await this.arweave.blocks
|
|
294
|
-
.getCurrent()
|
|
295
|
-
.then((block) => {
|
|
296
|
-
return { timestamp: block.timestamp * 1000 };
|
|
297
|
-
})
|
|
298
|
-
.catch(() => {
|
|
299
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
300
|
-
})).timestamp.toString(),
|
|
301
|
-
},
|
|
302
263
|
];
|
|
303
264
|
return this.process.read({
|
|
304
265
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
@@ -333,17 +294,6 @@ class ARIOReadable {
|
|
|
333
294
|
name: 'Fund-From',
|
|
334
295
|
value: fundFrom,
|
|
335
296
|
},
|
|
336
|
-
{
|
|
337
|
-
name: 'Timestamp',
|
|
338
|
-
value: (await this.arweave.blocks
|
|
339
|
-
.getCurrent()
|
|
340
|
-
.then((block) => {
|
|
341
|
-
return { timestamp: block.timestamp * 1000 };
|
|
342
|
-
})
|
|
343
|
-
.catch(() => {
|
|
344
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
345
|
-
})).timestamp.toString(),
|
|
346
|
-
},
|
|
347
297
|
];
|
|
348
298
|
return this.process.read({
|
|
349
299
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
package/lib/cjs/utils/arweave.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.paginationParamsToTags = exports.
|
|
3
|
+
exports.paginationParamsToTags = exports.pruneTags = exports.isBlockHeight = exports.validateArweaveId = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
4
19
|
const constants_js_1 = require("../constants.js");
|
|
5
20
|
const validateArweaveId = (id) => {
|
|
6
21
|
return constants_js_1.ARWEAVE_TX_REGEX.test(id);
|
|
@@ -19,17 +34,6 @@ const pruneTags = (tags) => {
|
|
|
19
34
|
return tags.filter((tag) => tag.value !== undefined && tag.value !== '');
|
|
20
35
|
};
|
|
21
36
|
exports.pruneTags = pruneTags;
|
|
22
|
-
const getCurrentBlockUnixTimestampMs = async (arweave) => {
|
|
23
|
-
return await arweave.blocks
|
|
24
|
-
.getCurrent()
|
|
25
|
-
.then((block) => {
|
|
26
|
-
return block.timestamp * 1000;
|
|
27
|
-
})
|
|
28
|
-
.catch(() => {
|
|
29
|
-
return Date.now(); // fallback to current time
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
exports.getCurrentBlockUnixTimestampMs = getCurrentBlockUnixTimestampMs;
|
|
33
37
|
const paginationParamsToTags = (params) => {
|
|
34
38
|
const tags = [
|
|
35
39
|
{ name: 'Cursor', value: params?.cursor?.toString() },
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/common/io.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
1
16
|
import { ARIO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
2
17
|
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/io.js';
|
|
3
18
|
import { createAoSigner } from '../utils/ao.js';
|
|
4
|
-
import {
|
|
5
|
-
import { defaultArweave } from './arweave.js';
|
|
19
|
+
import { paginationParamsToTags, pruneTags } from '../utils/arweave.js';
|
|
6
20
|
import { AOProcess } from './contracts/ao-process.js';
|
|
7
21
|
import { InvalidContractConfigurationError } from './error.js';
|
|
8
22
|
export class ARIO {
|
|
@@ -19,8 +33,8 @@ export class ARIO {
|
|
|
19
33
|
}
|
|
20
34
|
export class ARIOReadable {
|
|
21
35
|
process;
|
|
22
|
-
|
|
23
|
-
constructor(config
|
|
36
|
+
epochSettings;
|
|
37
|
+
constructor(config) {
|
|
24
38
|
if (!config) {
|
|
25
39
|
this.process = new AOProcess({
|
|
26
40
|
processId: ARIO_TESTNET_PROCESS_ID,
|
|
@@ -37,7 +51,6 @@ export class ARIOReadable {
|
|
|
37
51
|
else {
|
|
38
52
|
throw new InvalidContractConfigurationError();
|
|
39
53
|
}
|
|
40
|
-
this.arweave = arweave;
|
|
41
54
|
}
|
|
42
55
|
async getInfo() {
|
|
43
56
|
return this.process.read({
|
|
@@ -49,35 +62,32 @@ export class ARIOReadable {
|
|
|
49
62
|
tags: [{ name: 'Action', value: 'Total-Token-Supply' }],
|
|
50
63
|
});
|
|
51
64
|
}
|
|
52
|
-
async
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
async computeEpochIndexForTimestamp(timestamp) {
|
|
66
|
+
const epochSettings = await this.getEpochSettings();
|
|
67
|
+
const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
|
|
68
|
+
const epochLengthMs = epochSettings.durationMs;
|
|
69
|
+
return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
|
|
70
|
+
}
|
|
71
|
+
async computeEpochIndex(params) {
|
|
72
|
+
const epochIndex = params?.epochIndex;
|
|
73
|
+
if (epochIndex !== undefined) {
|
|
74
|
+
return epochIndex.toString();
|
|
75
|
+
}
|
|
76
|
+
const timestamp = params?.timestamp;
|
|
77
|
+
if (timestamp !== undefined) {
|
|
78
|
+
return (await this.computeEpochIndexForTimestamp(timestamp)).toString();
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
async getEpochSettings() {
|
|
83
|
+
return (this.epochSettings ??= await this.process.read({
|
|
84
|
+
tags: [{ name: 'Action', value: 'Epoch-Settings' }],
|
|
85
|
+
}));
|
|
68
86
|
}
|
|
69
87
|
async getEpoch(epoch) {
|
|
70
88
|
const allTags = [
|
|
71
89
|
{ name: 'Action', value: 'Epoch' },
|
|
72
|
-
{
|
|
73
|
-
name: 'Timestamp',
|
|
74
|
-
value: epoch?.timestamp?.toString() ??
|
|
75
|
-
(await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: 'Epoch-Index',
|
|
79
|
-
value: epoch?.epochIndex?.toString(),
|
|
80
|
-
},
|
|
90
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
81
91
|
];
|
|
82
92
|
return this.process.read({
|
|
83
93
|
tags: pruneTags(allTags),
|
|
@@ -184,27 +194,13 @@ export class ARIOReadable {
|
|
|
184
194
|
}
|
|
185
195
|
async getCurrentEpoch() {
|
|
186
196
|
return this.process.read({
|
|
187
|
-
tags: [
|
|
188
|
-
{ name: 'Action', value: 'Epoch' },
|
|
189
|
-
{
|
|
190
|
-
name: 'Timestamp',
|
|
191
|
-
value: (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
192
|
-
},
|
|
193
|
-
],
|
|
197
|
+
tags: [{ name: 'Action', value: 'Epoch' }],
|
|
194
198
|
});
|
|
195
199
|
}
|
|
196
200
|
async getPrescribedObservers(epoch) {
|
|
197
201
|
const allTags = [
|
|
198
202
|
{ name: 'Action', value: 'Epoch-Prescribed-Observers' },
|
|
199
|
-
{
|
|
200
|
-
name: 'Timestamp',
|
|
201
|
-
value: epoch?.timestamp?.toString() ??
|
|
202
|
-
(await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
name: 'Epoch-Index',
|
|
206
|
-
value: epoch?.epochIndex?.toString(),
|
|
207
|
-
},
|
|
203
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
208
204
|
];
|
|
209
205
|
return this.process.read({
|
|
210
206
|
tags: pruneTags(allTags),
|
|
@@ -213,15 +209,7 @@ export class ARIOReadable {
|
|
|
213
209
|
async getPrescribedNames(epoch) {
|
|
214
210
|
const allTags = [
|
|
215
211
|
{ name: 'Action', value: 'Epoch-Prescribed-Names' },
|
|
216
|
-
{
|
|
217
|
-
name: 'Timestamp',
|
|
218
|
-
value: epoch?.timestamp?.toString() ??
|
|
219
|
-
(await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
name: 'Epoch-Index',
|
|
223
|
-
value: epoch?.epochIndex?.toString(),
|
|
224
|
-
},
|
|
212
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
225
213
|
];
|
|
226
214
|
return this.process.read({
|
|
227
215
|
tags: pruneTags(allTags),
|
|
@@ -230,15 +218,7 @@ export class ARIOReadable {
|
|
|
230
218
|
async getObservations(epoch) {
|
|
231
219
|
const allTags = [
|
|
232
220
|
{ name: 'Action', value: 'Epoch-Observations' },
|
|
233
|
-
{
|
|
234
|
-
name: 'Timestamp',
|
|
235
|
-
value: epoch?.timestamp?.toString() ??
|
|
236
|
-
(await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
name: 'Epoch-Index',
|
|
240
|
-
value: epoch?.epochIndex?.toString(),
|
|
241
|
-
},
|
|
221
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
242
222
|
];
|
|
243
223
|
return this.process.read({
|
|
244
224
|
tags: pruneTags(allTags),
|
|
@@ -247,15 +227,7 @@ export class ARIOReadable {
|
|
|
247
227
|
async getDistributions(epoch) {
|
|
248
228
|
const allTags = [
|
|
249
229
|
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
250
|
-
{
|
|
251
|
-
name: 'Timestamp',
|
|
252
|
-
value: epoch?.timestamp?.toString() ??
|
|
253
|
-
(await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
name: 'Epoch-Index',
|
|
257
|
-
value: epoch?.epochIndex?.toString(),
|
|
258
|
-
},
|
|
230
|
+
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
259
231
|
];
|
|
260
232
|
return this.process.read({
|
|
261
233
|
tags: pruneTags(allTags),
|
|
@@ -284,17 +256,6 @@ export class ARIOReadable {
|
|
|
284
256
|
name: 'Purchase-Type',
|
|
285
257
|
value: type,
|
|
286
258
|
},
|
|
287
|
-
{
|
|
288
|
-
name: 'Timestamp',
|
|
289
|
-
value: (await this.arweave.blocks
|
|
290
|
-
.getCurrent()
|
|
291
|
-
.then((block) => {
|
|
292
|
-
return { timestamp: block.timestamp * 1000 };
|
|
293
|
-
})
|
|
294
|
-
.catch(() => {
|
|
295
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
296
|
-
})).timestamp.toString(),
|
|
297
|
-
},
|
|
298
259
|
];
|
|
299
260
|
return this.process.read({
|
|
300
261
|
tags: pruneTags(allTags),
|
|
@@ -329,17 +290,6 @@ export class ARIOReadable {
|
|
|
329
290
|
name: 'Fund-From',
|
|
330
291
|
value: fundFrom,
|
|
331
292
|
},
|
|
332
|
-
{
|
|
333
|
-
name: 'Timestamp',
|
|
334
|
-
value: (await this.arweave.blocks
|
|
335
|
-
.getCurrent()
|
|
336
|
-
.then((block) => {
|
|
337
|
-
return { timestamp: block.timestamp * 1000 };
|
|
338
|
-
})
|
|
339
|
-
.catch(() => {
|
|
340
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
341
|
-
})).timestamp.toString(),
|
|
342
|
-
},
|
|
343
293
|
];
|
|
344
294
|
return this.process.read({
|
|
345
295
|
tags: pruneTags(allTags),
|
package/lib/esm/utils/arweave.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
1
16
|
import { ARWEAVE_TX_REGEX } from '../constants.js';
|
|
2
17
|
export const validateArweaveId = (id) => {
|
|
3
18
|
return ARWEAVE_TX_REGEX.test(id);
|
|
@@ -13,16 +28,6 @@ export function isBlockHeight(height) {
|
|
|
13
28
|
export const pruneTags = (tags) => {
|
|
14
29
|
return tags.filter((tag) => tag.value !== undefined && tag.value !== '');
|
|
15
30
|
};
|
|
16
|
-
export const getCurrentBlockUnixTimestampMs = async (arweave) => {
|
|
17
|
-
return await arweave.blocks
|
|
18
|
-
.getCurrent()
|
|
19
|
-
.then((block) => {
|
|
20
|
-
return block.timestamp * 1000;
|
|
21
|
-
})
|
|
22
|
-
.catch(() => {
|
|
23
|
-
return Date.now(); // fallback to current time
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
31
|
export const paginationParamsToTags = (params) => {
|
|
27
32
|
const tags = [
|
|
28
33
|
{ name: 'Cursor', value: params?.cursor?.toString() },
|
package/lib/esm/version.js
CHANGED
package/lib/types/common/io.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import Arweave from 'arweave';
|
|
17
1
|
import { AoArNSNameDataWithName, AoArNSReservedNameData, AoBalanceWithAddress, AoEpochDistributionData, AoEpochObservationData, AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoReturnedName, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, ContractSigner, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
|
|
18
2
|
import { AoARIORead, AoARIOWrite, AoArNSNameData, AoArNSPurchaseParams, AoArNSReservedNameDataWithName, AoBuyRecordParams, AoDelegation, AoEpochData, AoEpochSettings, AoExtendLeaseParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoPaginatedAddressParams, AoRegistrationFees, AoVaultData, AoWalletVault, CostDetailsResult, DemandFactorSettings, EpochInput } from '../types/io.js';
|
|
19
3
|
import { mARIOToken } from '../types/token.js';
|
|
@@ -39,8 +23,8 @@ export declare class ARIO {
|
|
|
39
23
|
}
|
|
40
24
|
export declare class ARIOReadable implements AoARIORead {
|
|
41
25
|
protected process: AOProcess;
|
|
42
|
-
|
|
43
|
-
constructor(config?: ProcessConfiguration
|
|
26
|
+
protected epochSettings: AoEpochSettings | undefined;
|
|
27
|
+
constructor(config?: ProcessConfiguration);
|
|
44
28
|
getInfo(): Promise<{
|
|
45
29
|
Name: string;
|
|
46
30
|
Ticker: string;
|
|
@@ -50,7 +34,9 @@ export declare class ARIOReadable implements AoARIORead {
|
|
|
50
34
|
LastTickedEpochIndex: number;
|
|
51
35
|
}>;
|
|
52
36
|
getTokenSupply(): Promise<AoTokenSupplyData>;
|
|
53
|
-
|
|
37
|
+
private computeEpochIndexForTimestamp;
|
|
38
|
+
private computeEpochIndex;
|
|
39
|
+
getEpochSettings(): Promise<AoEpochSettings>;
|
|
54
40
|
getEpoch(epoch?: EpochInput): Promise<AoEpochData>;
|
|
55
41
|
getArNSRecord({ name, }: {
|
|
56
42
|
name: string;
|
package/lib/types/types/io.d.ts
CHANGED
|
@@ -105,6 +105,8 @@ export type AoEpochSettings = {
|
|
|
105
105
|
rewardPercentage: number;
|
|
106
106
|
maxObservers: number;
|
|
107
107
|
distributionDelayMs: number;
|
|
108
|
+
epochZeroTimestamp: Timestamp;
|
|
109
|
+
pruneEpochsCount: number;
|
|
108
110
|
};
|
|
109
111
|
export type AoEpochData = {
|
|
110
112
|
epochIndex: AoEpochIndex;
|
|
@@ -277,7 +279,7 @@ export type AoFundingPlan = {
|
|
|
277
279
|
address: WalletAddress;
|
|
278
280
|
balance: number;
|
|
279
281
|
stakes: Record<WalletAddress, {
|
|
280
|
-
vaults: string[];
|
|
282
|
+
vaults: Record<string, number>[];
|
|
281
283
|
delegatedStake: number;
|
|
282
284
|
}>;
|
|
283
285
|
/** Any remaining shortfall will indicate an insufficient balance for the action */
|
|
@@ -351,7 +353,7 @@ export interface AoARIORead {
|
|
|
351
353
|
LastTickedEpochIndex: number;
|
|
352
354
|
}>;
|
|
353
355
|
getTokenSupply(): Promise<AoTokenSupplyData>;
|
|
354
|
-
getEpochSettings(
|
|
356
|
+
getEpochSettings(): Promise<AoEpochSettings>;
|
|
355
357
|
getGateway({ address }: AoAddressParams): Promise<AoGateway | undefined>;
|
|
356
358
|
getGatewayDelegates({ address, ...pageParams }: AoAddressParams & PaginationParams<AoGatewayDelegateWithAddress>): Promise<PaginationResult<AoGatewayDelegateWithAddress>>;
|
|
357
359
|
getGatewayDelegateAllowList(params: AoPaginatedAddressParams): Promise<PaginationResult<WalletAddress>>;
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import Arweave from 'arweave';
|
|
17
|
-
import { BlockHeight, Timestamp } from '../types/common.js';
|
|
1
|
+
import { BlockHeight } from '../types/common.js';
|
|
18
2
|
import { PaginationParams } from '../types/io.js';
|
|
19
3
|
export declare const validateArweaveId: (id: string) => boolean;
|
|
20
4
|
export declare function isBlockHeight(height: string | number): height is BlockHeight;
|
|
@@ -30,7 +14,6 @@ export declare const pruneTags: (tags: {
|
|
|
30
14
|
name: string;
|
|
31
15
|
value: string;
|
|
32
16
|
}[];
|
|
33
|
-
export declare const getCurrentBlockUnixTimestampMs: (arweave: Arweave) => Promise<Timestamp>;
|
|
34
17
|
export declare const paginationParamsToTags: <T>(params?: PaginationParams<T>) => {
|
|
35
18
|
name: string;
|
|
36
19
|
value: string;
|
package/lib/types/version.d.ts
CHANGED