@ar.io/sdk 3.2.0 → 3.3.0-alpha.2
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 +89 -69
- package/lib/cjs/cli/cli.js +6 -2
- package/lib/cjs/common/contracts/ao-process.js +1 -1
- package/lib/cjs/common/io.js +56 -21
- package/lib/cjs/constants.js +1 -1
- package/lib/cjs/utils/ao.js +22 -22
- package/lib/cjs/utils/arweave.js +51 -16
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +6 -2
- package/lib/esm/common/contracts/ao-process.js +1 -1
- package/lib/esm/common/io.js +57 -22
- package/lib/esm/constants.js +1 -1
- package/lib/esm/utils/ao.js +20 -21
- package/lib/esm/utils/arweave.js +49 -16
- package/lib/esm/version.js +1 -1
- package/lib/types/common/contracts/ao-process.d.ts +1 -1
- package/lib/types/common/io.d.ts +28 -6
- package/lib/types/constants.d.ts +1 -1
- package/lib/types/types/io.d.ts +2 -2
- package/lib/types/utils/ao.d.ts +13 -3
- package/lib/types/utils/arweave.d.ts +31 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/cli/cli.js
CHANGED
|
@@ -145,13 +145,17 @@ const utils_js_1 = require("./utils.js");
|
|
|
145
145
|
name: 'get-observations',
|
|
146
146
|
description: 'Get observations for an epoch',
|
|
147
147
|
options: options_js_1.epochOptions,
|
|
148
|
-
action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
|
|
148
|
+
action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
|
|
149
|
+
.getObservations((0, utils_js_1.epochInputFromOptions)(o))
|
|
150
|
+
.then((result) => result ?? { message: 'No observations found for epoch' }),
|
|
149
151
|
});
|
|
150
152
|
(0, utils_js_1.makeCommand)({
|
|
151
153
|
name: 'get-distributions',
|
|
152
154
|
description: 'Get distributions for an epoch',
|
|
153
155
|
options: options_js_1.epochOptions,
|
|
154
|
-
action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
|
|
156
|
+
action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
|
|
157
|
+
.getDistributions((0, utils_js_1.epochInputFromOptions)(o))
|
|
158
|
+
.then((result) => result ?? { message: 'No distributions found for epoch' }),
|
|
155
159
|
});
|
|
156
160
|
(0, utils_js_1.makeCommand)({
|
|
157
161
|
name: 'get-token-cost',
|
|
@@ -24,8 +24,8 @@ const error_js_1 = require("../error.js");
|
|
|
24
24
|
const logger_js_1 = require("../logger.js");
|
|
25
25
|
class AOProcess {
|
|
26
26
|
logger;
|
|
27
|
-
processId;
|
|
28
27
|
ao;
|
|
28
|
+
processId;
|
|
29
29
|
constructor({ processId, ao = (0, aoconnect_1.connect)(), logger = logger_js_1.Logger.default, }) {
|
|
30
30
|
this.processId = processId;
|
|
31
31
|
this.logger = logger;
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -1,45 +1,36 @@
|
|
|
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
|
-
*/
|
|
19
4
|
const constants_js_1 = require("../constants.js");
|
|
20
5
|
const io_js_1 = require("../types/io.js");
|
|
21
6
|
const ao_js_1 = require("../utils/ao.js");
|
|
22
7
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
8
|
+
const arweave_js_2 = require("./arweave.js");
|
|
23
9
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
24
10
|
const error_js_1 = require("./error.js");
|
|
25
11
|
class ARIO {
|
|
26
|
-
static init(config) {
|
|
27
|
-
if (config && config.signer) {
|
|
12
|
+
static init({ arweave, ...config } = {}) {
|
|
13
|
+
if (config !== undefined && config.signer) {
|
|
28
14
|
const { signer, ...rest } = config;
|
|
29
15
|
return new ARIOWriteable({
|
|
30
16
|
...rest,
|
|
31
17
|
signer,
|
|
18
|
+
arweave,
|
|
32
19
|
});
|
|
33
20
|
}
|
|
34
|
-
return new ARIOReadable(
|
|
21
|
+
return new ARIOReadable({
|
|
22
|
+
arweave,
|
|
23
|
+
...config,
|
|
24
|
+
});
|
|
35
25
|
}
|
|
36
26
|
}
|
|
37
27
|
exports.ARIO = ARIO;
|
|
38
28
|
class ARIOReadable {
|
|
39
29
|
process;
|
|
40
30
|
epochSettings;
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
arweave;
|
|
32
|
+
constructor({ arweave = arweave_js_2.defaultArweave, ...config }) {
|
|
33
|
+
if (config === undefined) {
|
|
43
34
|
this.process = new ao_process_js_1.AOProcess({
|
|
44
35
|
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
45
36
|
});
|
|
@@ -55,6 +46,7 @@ class ARIOReadable {
|
|
|
55
46
|
else {
|
|
56
47
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
57
48
|
}
|
|
49
|
+
this.arweave = arweave;
|
|
58
50
|
}
|
|
59
51
|
async getInfo() {
|
|
60
52
|
return this.process.read({
|
|
@@ -72,6 +64,13 @@ class ARIOReadable {
|
|
|
72
64
|
const epochLengthMs = epochSettings.durationMs;
|
|
73
65
|
return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
|
|
74
66
|
}
|
|
67
|
+
async computeCurrentEpochIndex() {
|
|
68
|
+
const epochSettings = await this.getEpochSettings();
|
|
69
|
+
const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
|
|
70
|
+
const epochLengthMs = epochSettings.durationMs;
|
|
71
|
+
const currentTimestamp = Date.now();
|
|
72
|
+
return Math.floor((currentTimestamp - epochZeroStartTimestamp) / epochLengthMs);
|
|
73
|
+
}
|
|
75
74
|
async computeEpochIndex(params) {
|
|
76
75
|
const epochIndex = params?.epochIndex;
|
|
77
76
|
if (epochIndex !== undefined) {
|
|
@@ -89,6 +88,17 @@ class ARIOReadable {
|
|
|
89
88
|
}));
|
|
90
89
|
}
|
|
91
90
|
async getEpoch(epoch) {
|
|
91
|
+
const epochIndex = await this.computeEpochIndex(epoch);
|
|
92
|
+
const currentIndex = await this.computeCurrentEpochIndex();
|
|
93
|
+
if (epochIndex !== undefined && +epochIndex < currentIndex) {
|
|
94
|
+
const epochData = await (0, arweave_js_1.getEpochDataFromGql)({
|
|
95
|
+
arweave: this.arweave,
|
|
96
|
+
epochIndex: +epochIndex,
|
|
97
|
+
processId: this.process.processId,
|
|
98
|
+
});
|
|
99
|
+
return epochData;
|
|
100
|
+
}
|
|
101
|
+
// go to the process epoch and fetch the epoch data
|
|
92
102
|
const allTags = [
|
|
93
103
|
{ name: 'Action', value: 'Epoch' },
|
|
94
104
|
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
@@ -219,7 +229,19 @@ class ARIOReadable {
|
|
|
219
229
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
220
230
|
});
|
|
221
231
|
}
|
|
232
|
+
// we need to find the epoch index for the epoch that is currently being distributed and fetch it from gql
|
|
222
233
|
async getObservations(epoch) {
|
|
234
|
+
const epochIndex = await this.computeEpochIndex(epoch);
|
|
235
|
+
const currentIndex = await this.computeCurrentEpochIndex();
|
|
236
|
+
if (epochIndex !== undefined && +epochIndex < currentIndex) {
|
|
237
|
+
const epochData = await (0, arweave_js_1.getEpochDataFromGql)({
|
|
238
|
+
arweave: this.arweave,
|
|
239
|
+
epochIndex: +epochIndex,
|
|
240
|
+
processId: this.process.processId,
|
|
241
|
+
});
|
|
242
|
+
return epochData?.observations;
|
|
243
|
+
}
|
|
244
|
+
// go to the process epoch and fetch the observations
|
|
223
245
|
const allTags = [
|
|
224
246
|
{ name: 'Action', value: 'Epoch-Observations' },
|
|
225
247
|
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
@@ -229,6 +251,17 @@ class ARIOReadable {
|
|
|
229
251
|
});
|
|
230
252
|
}
|
|
231
253
|
async getDistributions(epoch) {
|
|
254
|
+
const epochIndex = await this.computeEpochIndex(epoch);
|
|
255
|
+
const currentIndex = await this.computeCurrentEpochIndex();
|
|
256
|
+
if (epochIndex !== undefined && +epochIndex < currentIndex) {
|
|
257
|
+
const epochData = await (0, arweave_js_1.getEpochDataFromGql)({
|
|
258
|
+
arweave: this.arweave,
|
|
259
|
+
epochIndex: +epochIndex,
|
|
260
|
+
processId: this.process.processId,
|
|
261
|
+
});
|
|
262
|
+
return epochData?.distributions;
|
|
263
|
+
}
|
|
264
|
+
// go to the process epoch and fetch the distributions
|
|
232
265
|
const allTags = [
|
|
233
266
|
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
234
267
|
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
@@ -419,12 +452,13 @@ class ARIOReadable {
|
|
|
419
452
|
exports.ARIOReadable = ARIOReadable;
|
|
420
453
|
class ARIOWriteable extends ARIOReadable {
|
|
421
454
|
signer;
|
|
422
|
-
constructor({ signer, ...config }) {
|
|
455
|
+
constructor({ signer, arweave, ...config }) {
|
|
423
456
|
if (Object.keys(config).length === 0) {
|
|
424
457
|
super({
|
|
425
458
|
process: new ao_process_js_1.AOProcess({
|
|
426
459
|
processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
|
|
427
460
|
}),
|
|
461
|
+
arweave: arweave,
|
|
428
462
|
});
|
|
429
463
|
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
430
464
|
}
|
|
@@ -437,6 +471,7 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
437
471
|
process: new ao_process_js_1.AOProcess({
|
|
438
472
|
processId: config.processId,
|
|
439
473
|
}),
|
|
474
|
+
arweave: arweave,
|
|
440
475
|
});
|
|
441
476
|
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
442
477
|
}
|
package/lib/cjs/constants.js
CHANGED
|
@@ -29,6 +29,6 @@ exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID;
|
|
|
29
29
|
exports.ARIO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
30
30
|
exports.ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
|
|
31
31
|
exports.MARIO_PER_ARIO = 1_000_000;
|
|
32
|
-
exports.AOS_MODULE_ID = '
|
|
32
|
+
exports.AOS_MODULE_ID = 'tyojTpJ9fIva_7BjTA9ruGM4uk2vyTfhVUulnbVxR8I';
|
|
33
33
|
exports.ANT_LUA_ID = '16_FyX-V2QU0RPSh1GIaEETSaUjNb0oVjCFpVbAfQq4';
|
|
34
34
|
exports.DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initANTStateForAddress = exports.defaultTargetManifestId = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
|
|
3
|
+
exports.parseAoEpochData = exports.initANTStateForAddress = exports.defaultTargetManifestId = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
6
|
*
|
|
@@ -22,12 +22,8 @@ const zod_1 = require("zod");
|
|
|
22
22
|
const arweave_js_1 = require("../common/arweave.js");
|
|
23
23
|
const index_js_1 = require("../common/index.js");
|
|
24
24
|
const constants_js_1 = require("../constants.js");
|
|
25
|
-
async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID,
|
|
26
|
-
//TODO:
|
|
27
|
-
const luaString = (await arweave.transactions.getData(luaCodeTxId, {
|
|
28
|
-
decode: true,
|
|
29
|
-
string: true,
|
|
30
|
-
}));
|
|
25
|
+
async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = constants_js_1.ANT_REGISTRY_ID, logger = index_js_1.Logger.default, }) {
|
|
26
|
+
// TODO: use On-Boot data handler for bootstrapping state instead of initialize-state
|
|
31
27
|
const processId = await ao.spawn({
|
|
32
28
|
module,
|
|
33
29
|
scheduler,
|
|
@@ -37,10 +33,6 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
37
33
|
name: 'ANT-Registry-Id',
|
|
38
34
|
value: antRegistryId,
|
|
39
35
|
},
|
|
40
|
-
{
|
|
41
|
-
name: 'Source-Code-TX-ID', // utility for understanding what the original source id of the lua code was
|
|
42
|
-
value: luaCodeTxId,
|
|
43
|
-
},
|
|
44
36
|
],
|
|
45
37
|
});
|
|
46
38
|
const aosClient = new index_js_1.AOProcess({
|
|
@@ -48,21 +40,10 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
48
40
|
ao,
|
|
49
41
|
logger,
|
|
50
42
|
});
|
|
51
|
-
const { id: evalId } = await aosClient.send({
|
|
52
|
-
tags: [
|
|
53
|
-
{ name: 'Action', value: 'Eval' },
|
|
54
|
-
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
55
|
-
{ name: 'Source-Code-TX-ID', value: luaCodeTxId },
|
|
56
|
-
],
|
|
57
|
-
data: luaString,
|
|
58
|
-
signer,
|
|
59
|
-
});
|
|
60
43
|
logger.debug(`Spawned ANT`, {
|
|
61
44
|
processId,
|
|
62
45
|
module,
|
|
63
46
|
scheduler,
|
|
64
|
-
luaCodeTxId,
|
|
65
|
-
evalId,
|
|
66
47
|
});
|
|
67
48
|
if (state) {
|
|
68
49
|
const { id: initializeMsgId } = await aosClient.send({
|
|
@@ -82,6 +63,7 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
82
63
|
initializeMsgId,
|
|
83
64
|
});
|
|
84
65
|
}
|
|
66
|
+
// This could be done by the ANT in On-Boot to self-register with its tagged ANT registry
|
|
85
67
|
const registryClient = index_js_1.ANTRegistry.init({
|
|
86
68
|
process: new index_js_1.AOProcess({
|
|
87
69
|
processId: antRegistryId,
|
|
@@ -200,3 +182,21 @@ function initANTStateForAddress({ owner, targetId, ttlSeconds = 3600, keywords =
|
|
|
200
182
|
};
|
|
201
183
|
}
|
|
202
184
|
exports.initANTStateForAddress = initANTStateForAddress;
|
|
185
|
+
/**
|
|
186
|
+
* Uses zod schema to parse the epoch data
|
|
187
|
+
*/
|
|
188
|
+
function parseAoEpochData(value) {
|
|
189
|
+
const epochDataSchema = zod_1.z.object({
|
|
190
|
+
startTimestamp: zod_1.z.number(),
|
|
191
|
+
startHeight: zod_1.z.number(),
|
|
192
|
+
distributions: zod_1.z.any(),
|
|
193
|
+
endTimestamp: zod_1.z.number(),
|
|
194
|
+
prescribedObservers: zod_1.z.any(),
|
|
195
|
+
prescribedNames: zod_1.z.array(zod_1.z.string()),
|
|
196
|
+
observations: zod_1.z.any(),
|
|
197
|
+
distributionTimestamp: zod_1.z.number(),
|
|
198
|
+
epochIndex: zod_1.z.number(),
|
|
199
|
+
});
|
|
200
|
+
return epochDataSchema.parse(value);
|
|
201
|
+
}
|
|
202
|
+
exports.parseAoEpochData = parseAoEpochData;
|
package/lib/cjs/utils/arweave.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
-
*/
|
|
3
|
+
exports.epochDistributionNoticeGqlQuery = exports.getEpochDataFromGql = exports.paginationParamsToTags = exports.pruneTags = exports.isBlockHeight = exports.validateArweaveId = void 0;
|
|
19
4
|
const constants_js_1 = require("../constants.js");
|
|
5
|
+
const ao_js_1 = require("./ao.js");
|
|
20
6
|
const validateArweaveId = (id) => {
|
|
21
7
|
return constants_js_1.ARWEAVE_TX_REGEX.test(id);
|
|
22
8
|
};
|
|
@@ -44,3 +30,52 @@ const paginationParamsToTags = (params) => {
|
|
|
44
30
|
return (0, exports.pruneTags)(tags);
|
|
45
31
|
};
|
|
46
32
|
exports.paginationParamsToTags = paginationParamsToTags;
|
|
33
|
+
/**
|
|
34
|
+
* Get the epoch with distribution data for the current epoch
|
|
35
|
+
* @param arweave - The Arweave instance
|
|
36
|
+
* @returns The epoch with distribution data
|
|
37
|
+
*/
|
|
38
|
+
const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, }) => {
|
|
39
|
+
// fetch from gql
|
|
40
|
+
const query = (0, exports.epochDistributionNoticeGqlQuery)({ epochIndex, processId });
|
|
41
|
+
const response = await arweave.api.post('graphql', query);
|
|
42
|
+
// parse the nodes to get the id
|
|
43
|
+
if (response.data.data.transactions?.edges?.length === 0) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const id = response.data.data.transactions.edges[0].node.id;
|
|
47
|
+
// fetch the transaction from arweave
|
|
48
|
+
const transaction = await arweave.api.get(id);
|
|
49
|
+
const data = transaction.data;
|
|
50
|
+
// assert it is the correct type
|
|
51
|
+
return (0, ao_js_1.parseAoEpochData)(data);
|
|
52
|
+
};
|
|
53
|
+
exports.getEpochDataFromGql = getEpochDataFromGql;
|
|
54
|
+
const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, }) => {
|
|
55
|
+
// write the query
|
|
56
|
+
const gqlQuery = JSON.stringify({
|
|
57
|
+
query: `
|
|
58
|
+
query {
|
|
59
|
+
transactions(
|
|
60
|
+
tags: [
|
|
61
|
+
{ name: "From-Process", values: ["${processId}"] }
|
|
62
|
+
{ name: "Action", values: ["Epoch-Distribution-Notice"] }
|
|
63
|
+
{ name: "Epoch-Index", values: ["${epochIndex}"] }
|
|
64
|
+
{ name: "Data-Protocol", values: ["ao"] }
|
|
65
|
+
],
|
|
66
|
+
owners: ["fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY"],
|
|
67
|
+
first: 1,
|
|
68
|
+
sort: HEIGHT_DESC
|
|
69
|
+
) {
|
|
70
|
+
edges {
|
|
71
|
+
node {
|
|
72
|
+
id
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`,
|
|
78
|
+
});
|
|
79
|
+
return gqlQuery;
|
|
80
|
+
};
|
|
81
|
+
exports.epochDistributionNoticeGqlQuery = epochDistributionNoticeGqlQuery;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/cli/cli.js
CHANGED
|
@@ -143,13 +143,17 @@ makeCommand({
|
|
|
143
143
|
name: 'get-observations',
|
|
144
144
|
description: 'Get observations for an epoch',
|
|
145
145
|
options: epochOptions,
|
|
146
|
-
action: (o) => readARIOFromOptions(o)
|
|
146
|
+
action: (o) => readARIOFromOptions(o)
|
|
147
|
+
.getObservations(epochInputFromOptions(o))
|
|
148
|
+
.then((result) => result ?? { message: 'No observations found for epoch' }),
|
|
147
149
|
});
|
|
148
150
|
makeCommand({
|
|
149
151
|
name: 'get-distributions',
|
|
150
152
|
description: 'Get distributions for an epoch',
|
|
151
153
|
options: epochOptions,
|
|
152
|
-
action: (o) => readARIOFromOptions(o)
|
|
154
|
+
action: (o) => readARIOFromOptions(o)
|
|
155
|
+
.getDistributions(epochInputFromOptions(o))
|
|
156
|
+
.then((result) => result ?? { message: 'No distributions found for epoch' }),
|
|
153
157
|
});
|
|
154
158
|
makeCommand({
|
|
155
159
|
name: 'get-token-cost',
|
|
@@ -21,8 +21,8 @@ import { WriteInteractionError } from '../error.js';
|
|
|
21
21
|
import { Logger } from '../logger.js';
|
|
22
22
|
export class AOProcess {
|
|
23
23
|
logger;
|
|
24
|
-
processId;
|
|
25
24
|
ao;
|
|
25
|
+
processId;
|
|
26
26
|
constructor({ processId, ao = connect(), logger = Logger.default, }) {
|
|
27
27
|
this.processId = processId;
|
|
28
28
|
this.logger = logger;
|
package/lib/esm/common/io.js
CHANGED
|
@@ -1,41 +1,32 @@
|
|
|
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
1
|
import { ARIO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
17
2
|
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/io.js';
|
|
18
3
|
import { createAoSigner } from '../utils/ao.js';
|
|
19
|
-
import { paginationParamsToTags, pruneTags } from '../utils/arweave.js';
|
|
4
|
+
import { getEpochDataFromGql, paginationParamsToTags, pruneTags, } from '../utils/arweave.js';
|
|
5
|
+
import { defaultArweave } from './arweave.js';
|
|
20
6
|
import { AOProcess } from './contracts/ao-process.js';
|
|
21
7
|
import { InvalidContractConfigurationError } from './error.js';
|
|
22
8
|
export class ARIO {
|
|
23
|
-
static init(config) {
|
|
24
|
-
if (config && config.signer) {
|
|
9
|
+
static init({ arweave, ...config } = {}) {
|
|
10
|
+
if (config !== undefined && config.signer) {
|
|
25
11
|
const { signer, ...rest } = config;
|
|
26
12
|
return new ARIOWriteable({
|
|
27
13
|
...rest,
|
|
28
14
|
signer,
|
|
15
|
+
arweave,
|
|
29
16
|
});
|
|
30
17
|
}
|
|
31
|
-
return new ARIOReadable(
|
|
18
|
+
return new ARIOReadable({
|
|
19
|
+
arweave,
|
|
20
|
+
...config,
|
|
21
|
+
});
|
|
32
22
|
}
|
|
33
23
|
}
|
|
34
24
|
export class ARIOReadable {
|
|
35
25
|
process;
|
|
36
26
|
epochSettings;
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
arweave;
|
|
28
|
+
constructor({ arweave = defaultArweave, ...config }) {
|
|
29
|
+
if (config === undefined) {
|
|
39
30
|
this.process = new AOProcess({
|
|
40
31
|
processId: ARIO_TESTNET_PROCESS_ID,
|
|
41
32
|
});
|
|
@@ -51,6 +42,7 @@ export class ARIOReadable {
|
|
|
51
42
|
else {
|
|
52
43
|
throw new InvalidContractConfigurationError();
|
|
53
44
|
}
|
|
45
|
+
this.arweave = arweave;
|
|
54
46
|
}
|
|
55
47
|
async getInfo() {
|
|
56
48
|
return this.process.read({
|
|
@@ -68,6 +60,13 @@ export class ARIOReadable {
|
|
|
68
60
|
const epochLengthMs = epochSettings.durationMs;
|
|
69
61
|
return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
|
|
70
62
|
}
|
|
63
|
+
async computeCurrentEpochIndex() {
|
|
64
|
+
const epochSettings = await this.getEpochSettings();
|
|
65
|
+
const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
|
|
66
|
+
const epochLengthMs = epochSettings.durationMs;
|
|
67
|
+
const currentTimestamp = Date.now();
|
|
68
|
+
return Math.floor((currentTimestamp - epochZeroStartTimestamp) / epochLengthMs);
|
|
69
|
+
}
|
|
71
70
|
async computeEpochIndex(params) {
|
|
72
71
|
const epochIndex = params?.epochIndex;
|
|
73
72
|
if (epochIndex !== undefined) {
|
|
@@ -85,6 +84,17 @@ export class ARIOReadable {
|
|
|
85
84
|
}));
|
|
86
85
|
}
|
|
87
86
|
async getEpoch(epoch) {
|
|
87
|
+
const epochIndex = await this.computeEpochIndex(epoch);
|
|
88
|
+
const currentIndex = await this.computeCurrentEpochIndex();
|
|
89
|
+
if (epochIndex !== undefined && +epochIndex < currentIndex) {
|
|
90
|
+
const epochData = await getEpochDataFromGql({
|
|
91
|
+
arweave: this.arweave,
|
|
92
|
+
epochIndex: +epochIndex,
|
|
93
|
+
processId: this.process.processId,
|
|
94
|
+
});
|
|
95
|
+
return epochData;
|
|
96
|
+
}
|
|
97
|
+
// go to the process epoch and fetch the epoch data
|
|
88
98
|
const allTags = [
|
|
89
99
|
{ name: 'Action', value: 'Epoch' },
|
|
90
100
|
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
@@ -215,7 +225,19 @@ export class ARIOReadable {
|
|
|
215
225
|
tags: pruneTags(allTags),
|
|
216
226
|
});
|
|
217
227
|
}
|
|
228
|
+
// we need to find the epoch index for the epoch that is currently being distributed and fetch it from gql
|
|
218
229
|
async getObservations(epoch) {
|
|
230
|
+
const epochIndex = await this.computeEpochIndex(epoch);
|
|
231
|
+
const currentIndex = await this.computeCurrentEpochIndex();
|
|
232
|
+
if (epochIndex !== undefined && +epochIndex < currentIndex) {
|
|
233
|
+
const epochData = await getEpochDataFromGql({
|
|
234
|
+
arweave: this.arweave,
|
|
235
|
+
epochIndex: +epochIndex,
|
|
236
|
+
processId: this.process.processId,
|
|
237
|
+
});
|
|
238
|
+
return epochData?.observations;
|
|
239
|
+
}
|
|
240
|
+
// go to the process epoch and fetch the observations
|
|
219
241
|
const allTags = [
|
|
220
242
|
{ name: 'Action', value: 'Epoch-Observations' },
|
|
221
243
|
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
@@ -225,6 +247,17 @@ export class ARIOReadable {
|
|
|
225
247
|
});
|
|
226
248
|
}
|
|
227
249
|
async getDistributions(epoch) {
|
|
250
|
+
const epochIndex = await this.computeEpochIndex(epoch);
|
|
251
|
+
const currentIndex = await this.computeCurrentEpochIndex();
|
|
252
|
+
if (epochIndex !== undefined && +epochIndex < currentIndex) {
|
|
253
|
+
const epochData = await getEpochDataFromGql({
|
|
254
|
+
arweave: this.arweave,
|
|
255
|
+
epochIndex: +epochIndex,
|
|
256
|
+
processId: this.process.processId,
|
|
257
|
+
});
|
|
258
|
+
return epochData?.distributions;
|
|
259
|
+
}
|
|
260
|
+
// go to the process epoch and fetch the distributions
|
|
228
261
|
const allTags = [
|
|
229
262
|
{ name: 'Action', value: 'Epoch-Distributions' },
|
|
230
263
|
{ name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
|
|
@@ -414,12 +447,13 @@ export class ARIOReadable {
|
|
|
414
447
|
}
|
|
415
448
|
export class ARIOWriteable extends ARIOReadable {
|
|
416
449
|
signer;
|
|
417
|
-
constructor({ signer, ...config }) {
|
|
450
|
+
constructor({ signer, arweave, ...config }) {
|
|
418
451
|
if (Object.keys(config).length === 0) {
|
|
419
452
|
super({
|
|
420
453
|
process: new AOProcess({
|
|
421
454
|
processId: ARIO_TESTNET_PROCESS_ID,
|
|
422
455
|
}),
|
|
456
|
+
arweave: arweave,
|
|
423
457
|
});
|
|
424
458
|
this.signer = createAoSigner(signer);
|
|
425
459
|
}
|
|
@@ -432,6 +466,7 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
432
466
|
process: new AOProcess({
|
|
433
467
|
processId: config.processId,
|
|
434
468
|
}),
|
|
469
|
+
arweave: arweave,
|
|
435
470
|
});
|
|
436
471
|
this.signer = createAoSigner(signer);
|
|
437
472
|
}
|
package/lib/esm/constants.js
CHANGED
|
@@ -26,6 +26,6 @@ export const arioDevnetProcessId = ARIO_DEVNET_PROCESS_ID;
|
|
|
26
26
|
export const ARIO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
27
27
|
export const ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
|
|
28
28
|
export const MARIO_PER_ARIO = 1_000_000;
|
|
29
|
-
export const AOS_MODULE_ID = '
|
|
29
|
+
export const AOS_MODULE_ID = 'tyojTpJ9fIva_7BjTA9ruGM4uk2vyTfhVUulnbVxR8I';
|
|
30
30
|
export const ANT_LUA_ID = '16_FyX-V2QU0RPSh1GIaEETSaUjNb0oVjCFpVbAfQq4';
|
|
31
31
|
export const DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
package/lib/esm/utils/ao.js
CHANGED
|
@@ -19,12 +19,8 @@ import { z } from 'zod';
|
|
|
19
19
|
import { defaultArweave } from '../common/arweave.js';
|
|
20
20
|
import { ANTRegistry, AOProcess, Logger } from '../common/index.js';
|
|
21
21
|
import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
|
|
22
|
-
export async function spawnANT({ signer, module = AOS_MODULE_ID,
|
|
23
|
-
//TODO:
|
|
24
|
-
const luaString = (await arweave.transactions.getData(luaCodeTxId, {
|
|
25
|
-
decode: true,
|
|
26
|
-
string: true,
|
|
27
|
-
}));
|
|
22
|
+
export async function spawnANT({ signer, module = AOS_MODULE_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = ANT_REGISTRY_ID, logger = Logger.default, }) {
|
|
23
|
+
// TODO: use On-Boot data handler for bootstrapping state instead of initialize-state
|
|
28
24
|
const processId = await ao.spawn({
|
|
29
25
|
module,
|
|
30
26
|
scheduler,
|
|
@@ -34,10 +30,6 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
|
|
|
34
30
|
name: 'ANT-Registry-Id',
|
|
35
31
|
value: antRegistryId,
|
|
36
32
|
},
|
|
37
|
-
{
|
|
38
|
-
name: 'Source-Code-TX-ID', // utility for understanding what the original source id of the lua code was
|
|
39
|
-
value: luaCodeTxId,
|
|
40
|
-
},
|
|
41
33
|
],
|
|
42
34
|
});
|
|
43
35
|
const aosClient = new AOProcess({
|
|
@@ -45,21 +37,10 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
|
|
|
45
37
|
ao,
|
|
46
38
|
logger,
|
|
47
39
|
});
|
|
48
|
-
const { id: evalId } = await aosClient.send({
|
|
49
|
-
tags: [
|
|
50
|
-
{ name: 'Action', value: 'Eval' },
|
|
51
|
-
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
52
|
-
{ name: 'Source-Code-TX-ID', value: luaCodeTxId },
|
|
53
|
-
],
|
|
54
|
-
data: luaString,
|
|
55
|
-
signer,
|
|
56
|
-
});
|
|
57
40
|
logger.debug(`Spawned ANT`, {
|
|
58
41
|
processId,
|
|
59
42
|
module,
|
|
60
43
|
scheduler,
|
|
61
|
-
luaCodeTxId,
|
|
62
|
-
evalId,
|
|
63
44
|
});
|
|
64
45
|
if (state) {
|
|
65
46
|
const { id: initializeMsgId } = await aosClient.send({
|
|
@@ -79,6 +60,7 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
|
|
|
79
60
|
initializeMsgId,
|
|
80
61
|
});
|
|
81
62
|
}
|
|
63
|
+
// This could be done by the ANT in On-Boot to self-register with its tagged ANT registry
|
|
82
64
|
const registryClient = ANTRegistry.init({
|
|
83
65
|
process: new AOProcess({
|
|
84
66
|
processId: antRegistryId,
|
|
@@ -192,3 +174,20 @@ export function initANTStateForAddress({ owner, targetId, ttlSeconds = 3600, key
|
|
|
192
174
|
},
|
|
193
175
|
};
|
|
194
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Uses zod schema to parse the epoch data
|
|
179
|
+
*/
|
|
180
|
+
export function parseAoEpochData(value) {
|
|
181
|
+
const epochDataSchema = z.object({
|
|
182
|
+
startTimestamp: z.number(),
|
|
183
|
+
startHeight: z.number(),
|
|
184
|
+
distributions: z.any(),
|
|
185
|
+
endTimestamp: z.number(),
|
|
186
|
+
prescribedObservers: z.any(),
|
|
187
|
+
prescribedNames: z.array(z.string()),
|
|
188
|
+
observations: z.any(),
|
|
189
|
+
distributionTimestamp: z.number(),
|
|
190
|
+
epochIndex: z.number(),
|
|
191
|
+
});
|
|
192
|
+
return epochDataSchema.parse(value);
|
|
193
|
+
}
|