@ar.io/sdk 3.2.0 → 3.3.0-alpha.10

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.
@@ -64,6 +64,12 @@ const utils_js_1 = require("./utils.js");
64
64
  options: options_js_1.paginationOptions,
65
65
  action: readCommands_js_1.listGateways,
66
66
  });
67
+ (0, utils_js_1.makeCommand)({
68
+ name: 'list-all-delegates',
69
+ description: 'List all paginated delegates from all gateways',
70
+ options: options_js_1.paginationOptions,
71
+ action: readCommands_js_1.listAllDelegatesCLICommand,
72
+ });
67
73
  (0, utils_js_1.makeCommand)({
68
74
  name: 'get-gateway-delegates',
69
75
  description: 'Get the delegates of a gateway',
@@ -145,13 +151,17 @@ const utils_js_1 = require("./utils.js");
145
151
  name: 'get-observations',
146
152
  description: 'Get observations for an epoch',
147
153
  options: options_js_1.epochOptions,
148
- action: (o) => (0, utils_js_1.readARIOFromOptions)(o).getObservations((0, utils_js_1.epochInputFromOptions)(o)),
154
+ action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
155
+ .getObservations((0, utils_js_1.epochInputFromOptions)(o))
156
+ .then((result) => result ?? { message: 'No observations found for epoch' }),
149
157
  });
150
158
  (0, utils_js_1.makeCommand)({
151
159
  name: 'get-distributions',
152
160
  description: 'Get distributions for an epoch',
153
161
  options: options_js_1.epochOptions,
154
- action: (o) => (0, utils_js_1.readARIOFromOptions)(o).getDistributions((0, utils_js_1.epochInputFromOptions)(o)),
162
+ action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
163
+ .getDistributions((0, utils_js_1.epochInputFromOptions)(o))
164
+ .then((result) => result ?? { message: 'No distributions found for epoch' }),
155
165
  });
156
166
  (0, utils_js_1.makeCommand)({
157
167
  name: 'get-token-cost',
@@ -654,6 +664,20 @@ const utils_js_1 = require("./utils.js");
654
664
  }, (0, utils_js_1.writeActionTagsFromOptions)(options));
655
665
  },
656
666
  });
667
+ (0, utils_js_1.makeCommand)({
668
+ name: 'write-action',
669
+ description: 'Send a write action to an AO Process',
670
+ options: [...options_js_1.writeActionOptions, options_js_1.optionMap.processId],
671
+ action: async (options) => {
672
+ const process = new index_js_1.AOProcess({
673
+ processId: (0, utils_js_1.requiredProcessIdFromOptions)(options),
674
+ });
675
+ return process.send({
676
+ tags: (0, utils_js_1.writeActionTagsFromOptions)(options).tags ?? [],
677
+ signer: (0, utils_js_1.requiredAoSignerFromOptions)(options),
678
+ });
679
+ },
680
+ });
657
681
  if (process.argv[1].includes('bin/ar.io') || // Running from global .bin
658
682
  process.argv[1].includes('cli/cli') // Running from source
659
683
  ) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getCostDetails = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.listArNSReturnedNames = exports.getArNSReturnedName = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listGateways = exports.getGateway = void 0;
3
+ exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getCostDetails = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.listArNSReturnedNames = exports.getArNSReturnedName = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listAllDelegatesCLICommand = exports.listGateways = exports.getGateway = void 0;
4
4
  const token_js_1 = require("../../types/token.js");
5
5
  const utils_js_1 = require("../utils.js");
6
6
  async function getGateway(o) {
@@ -16,6 +16,11 @@ async function listGateways(o) {
16
16
  return gateways.items.length ? gateways : { message: 'No gateways found' };
17
17
  }
18
18
  exports.listGateways = listGateways;
19
+ async function listAllDelegatesCLICommand(o) {
20
+ const delegates = await (0, utils_js_1.readARIOFromOptions)(o).getAllDelegates((0, utils_js_1.paginationParamsFromOptions)(o));
21
+ return delegates.items.length ? delegates : { message: 'No delegates found' };
22
+ }
23
+ exports.listAllDelegatesCLICommand = listAllDelegatesCLICommand;
19
24
  async function getGatewayDelegates(o) {
20
25
  const address = (0, utils_js_1.requiredAddressFromOptions)(o);
21
26
  const result = await (0, utils_js_1.readARIOFromOptions)(o).getGatewayDelegates({
@@ -22,12 +22,8 @@ const ao_js_1 = require("../utils/ao.js");
22
22
  const index_js_2 = require("./index.js");
23
23
  class ANTRegistry {
24
24
  static init(config) {
25
- if (config && config.signer) {
26
- const { signer, ...rest } = config;
27
- return new AoANTRegistryWriteable({
28
- ...rest,
29
- signer,
30
- });
25
+ if (config !== undefined && 'signer' in config) {
26
+ return new AoANTRegistryWriteable(config);
31
27
  }
32
28
  return new AoANTRegistryReadable(config);
33
29
  }
@@ -36,25 +32,22 @@ exports.ANTRegistry = ANTRegistry;
36
32
  class AoANTRegistryReadable {
37
33
  process;
38
34
  constructor(config) {
39
- if (config &&
40
- ((0, index_js_1.isProcessIdConfiguration)(config) || (0, index_js_1.isProcessConfiguration)(config))) {
41
- if ((0, index_js_1.isProcessConfiguration)(config)) {
42
- this.process = config.process;
43
- }
44
- else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
45
- this.process = new index_js_2.AOProcess({
46
- processId: config.processId,
47
- });
48
- }
49
- else {
50
- throw new index_js_2.InvalidContractConfigurationError();
51
- }
52
- }
53
- else {
35
+ if (config === undefined || Object.keys(config).length === 0) {
54
36
  this.process = new index_js_2.AOProcess({
55
37
  processId: constants_js_1.ANT_REGISTRY_ID,
56
38
  });
57
39
  }
40
+ else if ((0, index_js_1.isProcessConfiguration)(config)) {
41
+ this.process = config.process;
42
+ }
43
+ else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
44
+ this.process = new index_js_2.AOProcess({
45
+ processId: config.processId,
46
+ });
47
+ }
48
+ else {
49
+ throw new index_js_2.InvalidContractConfigurationError();
50
+ }
58
51
  }
59
52
  // Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
60
53
  async accessControlList({ address, }) {
@@ -23,15 +23,12 @@ const ao_js_1 = require("../utils/ao.js");
23
23
  const schema_js_1 = require("../utils/schema.js");
24
24
  const index_js_2 = require("./index.js");
25
25
  class ANT {
26
- static init({ signer, strict = false, ...config }) {
27
- // ao supported implementation
28
- if ((0, index_js_1.isProcessConfiguration)(config) || (0, index_js_1.isProcessIdConfiguration)(config)) {
29
- if (!signer) {
30
- return new AoANTReadable({ strict, ...config });
31
- }
32
- return new AoANTWriteable({ signer, strict, ...config });
26
+ // implementation
27
+ static init(config) {
28
+ if (config !== undefined && 'signer' in config) {
29
+ return new AoANTWriteable(config);
33
30
  }
34
- throw new index_js_2.InvalidContractConfigurationError();
31
+ return new AoANTReadable(config);
35
32
  }
36
33
  }
37
34
  exports.ANT = ANT;
@@ -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;
@@ -42,8 +42,9 @@ class AOProcess {
42
42
  let lastError;
43
43
  while (attempts < retries) {
44
44
  try {
45
- this.logger.debug(`Evaluating read interaction on contract`, {
45
+ this.logger.debug(`Evaluating read interaction on process`, {
46
46
  tags,
47
+ processId: this.processId,
47
48
  });
48
49
  // map tags to inputs
49
50
  const dryRunInput = {
@@ -56,13 +57,18 @@ class AOProcess {
56
57
  const result = await this.ao.dryrun(dryRunInput);
57
58
  this.logger.debug(`Read interaction result`, {
58
59
  result,
60
+ processId: this.processId,
59
61
  });
60
62
  const error = errorMessageFromOutput(result);
61
63
  if (error !== undefined) {
62
64
  throw new Error(error);
63
65
  }
64
66
  if (result.Messages === undefined || result.Messages.length === 0) {
65
- this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
67
+ this.logger.debug(`Process ${this.processId} does not support provided action.`, {
68
+ result,
69
+ tags,
70
+ processId: this.processId,
71
+ });
66
72
  throw new Error(`Process ${this.processId} does not support provided action.`);
67
73
  }
68
74
  const messageData = result.Messages?.[0]?.Data;
@@ -70,16 +76,18 @@ class AOProcess {
70
76
  if (this.isMessageDataEmpty(messageData)) {
71
77
  return undefined;
72
78
  }
73
- const response = (0, json_js_1.safeDecode)(result.Messages[0].Data);
79
+ const response = (0, json_js_1.safeDecode)(messageData);
74
80
  return response;
75
81
  }
76
- catch (e) {
82
+ catch (error) {
77
83
  attempts++;
78
84
  this.logger.debug(`Read attempt ${attempts} failed`, {
79
- error: e instanceof Error ? e.message : e,
85
+ error: error?.message,
86
+ stack: error?.stack,
80
87
  tags,
88
+ processId: this.processId,
81
89
  });
82
- lastError = e;
90
+ lastError = error;
83
91
  // exponential backoff
84
92
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
85
93
  }
@@ -147,16 +155,17 @@ class AOProcess {
147
155
  }
148
156
  catch (error) {
149
157
  this.logger.error('Error sending message to process', {
150
- error: error.message,
158
+ error: error?.message,
159
+ stack: error?.stack,
151
160
  processId: this.processId,
152
161
  tags,
153
162
  });
154
- // throw on write interaction errors. No point retrying wr ite interactions, waste of gas.
163
+ // throw on write interaction errors. No point retrying write interactions, waste of gas.
155
164
  if (error.message.includes('500')) {
156
165
  this.logger.debug('Retrying send interaction', {
157
166
  attempts,
158
167
  retries,
159
- error: error.message,
168
+ error: error?.message,
160
169
  processId: this.processId,
161
170
  });
162
171
  // exponential backoff
@@ -174,18 +183,16 @@ class AOProcess {
174
183
  exports.AOProcess = AOProcess;
175
184
  function errorMessageFromOutput(output) {
176
185
  const errorData = output.Error;
177
- if (errorData !== undefined) {
178
- // TODO: Could clean this one up too, current error is verbose, but not always deterministic for parsing
179
- // Throw the whole raw error if AO process level error
180
- return errorData;
181
- }
182
- const error = output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
186
+ // Attempt to extract error details from Messages.Tags if Error is undefined
187
+ const error = errorData ??
188
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
183
189
  if (error !== undefined) {
184
- // from [string "aos"]:6846: Name is already registered
185
- const lineNumber = error.match(/\d+/)?.[0];
186
- const message = error.replace(/\[string "aos"\]:\d+:/, '');
187
- // to more user friendly: Name is already registered (line 6846)
188
- return `${message} (line ${lineNumber})`.trim();
190
+ // Consolidated regex to match and extract line number and AO error message or Error Tags
191
+ const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
192
+ if (match) {
193
+ const [, lineNumber, errorMessage] = match;
194
+ return `${errorMessage.trim()} (line ${lineNumber.trim()})`.trim();
195
+ }
189
196
  }
190
197
  return undefined;
191
198
  }
@@ -1,35 +1,18 @@
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 {
12
+ // Implementation
26
13
  static init(config) {
27
- if (config && config.signer) {
28
- const { signer, ...rest } = config;
29
- return new ARIOWriteable({
30
- ...rest,
31
- signer,
32
- });
14
+ if (config !== undefined && 'signer' in config) {
15
+ return new ARIOWriteable(config);
33
16
  }
34
17
  return new ARIOReadable(config);
35
18
  }
@@ -38,8 +21,10 @@ exports.ARIO = ARIO;
38
21
  class ARIOReadable {
39
22
  process;
40
23
  epochSettings;
24
+ arweave;
41
25
  constructor(config) {
42
- if (!config) {
26
+ this.arweave = config?.arweave ?? arweave_js_2.defaultArweave;
27
+ if (config === undefined || Object.keys(config).length === 0) {
43
28
  this.process = new ao_process_js_1.AOProcess({
44
29
  processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
45
30
  });
@@ -72,6 +57,13 @@ class ARIOReadable {
72
57
  const epochLengthMs = epochSettings.durationMs;
73
58
  return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
74
59
  }
60
+ async computeCurrentEpochIndex() {
61
+ const epochSettings = await this.getEpochSettings();
62
+ const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
63
+ const epochLengthMs = epochSettings.durationMs;
64
+ const currentTimestamp = Date.now();
65
+ return Math.floor((currentTimestamp - epochZeroStartTimestamp) / epochLengthMs);
66
+ }
75
67
  async computeEpochIndex(params) {
76
68
  const epochIndex = params?.epochIndex;
77
69
  if (epochIndex !== undefined) {
@@ -89,6 +81,17 @@ class ARIOReadable {
89
81
  }));
90
82
  }
91
83
  async getEpoch(epoch) {
84
+ const epochIndex = await this.computeEpochIndex(epoch);
85
+ const currentIndex = await this.computeCurrentEpochIndex();
86
+ if (epochIndex !== undefined && +epochIndex < currentIndex) {
87
+ const epochData = await (0, arweave_js_1.getEpochDataFromGql)({
88
+ arweave: this.arweave,
89
+ epochIndex: +epochIndex,
90
+ processId: this.process.processId,
91
+ });
92
+ return epochData;
93
+ }
94
+ // go to the process epoch and fetch the epoch data
92
95
  const allTags = [
93
96
  { name: 'Action', value: 'Epoch' },
94
97
  { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
@@ -219,7 +222,19 @@ class ARIOReadable {
219
222
  tags: (0, arweave_js_1.pruneTags)(allTags),
220
223
  });
221
224
  }
225
+ // we need to find the epoch index for the epoch that is currently being distributed and fetch it from gql
222
226
  async getObservations(epoch) {
227
+ const epochIndex = await this.computeEpochIndex(epoch);
228
+ const currentIndex = await this.computeCurrentEpochIndex();
229
+ if (epochIndex !== undefined && +epochIndex < currentIndex) {
230
+ const epochData = await (0, arweave_js_1.getEpochDataFromGql)({
231
+ arweave: this.arweave,
232
+ epochIndex: +epochIndex,
233
+ processId: this.process.processId,
234
+ });
235
+ return epochData?.observations;
236
+ }
237
+ // go to the process epoch and fetch the observations
223
238
  const allTags = [
224
239
  { name: 'Action', value: 'Epoch-Observations' },
225
240
  { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
@@ -229,6 +244,17 @@ class ARIOReadable {
229
244
  });
230
245
  }
231
246
  async getDistributions(epoch) {
247
+ const epochIndex = await this.computeEpochIndex(epoch);
248
+ const currentIndex = await this.computeCurrentEpochIndex();
249
+ if (epochIndex !== undefined && +epochIndex < currentIndex) {
250
+ const epochData = await (0, arweave_js_1.getEpochDataFromGql)({
251
+ arweave: this.arweave,
252
+ epochIndex: +epochIndex,
253
+ processId: this.process.processId,
254
+ });
255
+ return epochData?.distributions;
256
+ }
257
+ // go to the process epoch and fetch the distributions
232
258
  const allTags = [
233
259
  { name: 'Action', value: 'Epoch-Distributions' },
234
260
  { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
@@ -415,34 +441,30 @@ class ARIOReadable {
415
441
  tags: [{ name: 'Action', value: 'Gateway-Registry-Settings' }],
416
442
  });
417
443
  }
444
+ async getAllDelegates(params) {
445
+ return this.process.read({
446
+ tags: [
447
+ { name: 'Action', value: 'All-Paginated-Delegates' },
448
+ ...(0, arweave_js_1.paginationParamsToTags)(params),
449
+ ],
450
+ });
451
+ }
418
452
  }
419
453
  exports.ARIOReadable = ARIOReadable;
420
454
  class ARIOWriteable extends ARIOReadable {
421
455
  signer;
422
456
  constructor({ signer, ...config }) {
423
- if (Object.keys(config).length === 0) {
457
+ if (config === undefined) {
424
458
  super({
425
459
  process: new ao_process_js_1.AOProcess({
426
460
  processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
427
461
  }),
428
462
  });
429
- this.signer = (0, ao_js_1.createAoSigner)(signer);
430
- }
431
- else if ((0, io_js_1.isProcessConfiguration)(config)) {
432
- super({ process: config.process });
433
- this.signer = (0, ao_js_1.createAoSigner)(signer);
434
- }
435
- else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
436
- super({
437
- process: new ao_process_js_1.AOProcess({
438
- processId: config.processId,
439
- }),
440
- });
441
- this.signer = (0, ao_js_1.createAoSigner)(signer);
442
463
  }
443
464
  else {
444
- throw new error_js_1.InvalidContractConfigurationError();
465
+ super(config);
445
466
  }
467
+ this.signer = (0, ao_js_1.createAoSigner)(signer);
446
468
  }
447
469
  async transfer({ target, qty, }, options) {
448
470
  const { tags = [] } = options || {};
@@ -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 = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
33
- exports.ANT_LUA_ID = '16_FyX-V2QU0RPSh1GIaEETSaUjNb0oVjCFpVbAfQq4';
32
+ exports.AOS_MODULE_ID = 'BRyNPIJWZaQ4IudfNnsfvMrZBO2YDPjgKqg_wCYT2U8';
33
+ exports.ANT_LUA_ID = 'k9tQkbnFYZOGp6ist1yFuaqk_wOkzM5KUSNDtWzCLtg';
34
34
  exports.DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
@@ -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, luaCodeTxId = constants_js_1.ANT_LUA_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, arweave = arweave_js_1.defaultArweave, }) {
26
- //TODO: cache locally and only fetch if not cached
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,
@@ -171,6 +153,20 @@ function createAoSigner(signer) {
171
153
  typeof signer.setPublicKey === 'function') {
172
154
  await signer.setPublicKey();
173
155
  }
156
+ if (signer instanceof arbundles_1.ArconnectSigner) {
157
+ // Sign using Arconnect signDataItem API
158
+ const signedDataItem = await signer['signer'].signDataItem({
159
+ data,
160
+ tags,
161
+ target,
162
+ anchor,
163
+ });
164
+ const dataItem = new arbundles_1.DataItem(Buffer.from(signedDataItem));
165
+ return {
166
+ id: await dataItem.id,
167
+ raw: await dataItem.getRaw(),
168
+ };
169
+ }
174
170
  const dataItem = (0, arbundles_1.createData)(data, signer, { tags, target, anchor });
175
171
  const signedData = dataItem.sign(signer).then(async () => ({
176
172
  id: await dataItem.id,
@@ -200,3 +196,21 @@ function initANTStateForAddress({ owner, targetId, ttlSeconds = 3600, keywords =
200
196
  };
201
197
  }
202
198
  exports.initANTStateForAddress = initANTStateForAddress;
199
+ /**
200
+ * Uses zod schema to parse the epoch data
201
+ */
202
+ function parseAoEpochData(value) {
203
+ const epochDataSchema = zod_1.z.object({
204
+ startTimestamp: zod_1.z.number(),
205
+ startHeight: zod_1.z.number(),
206
+ distributions: zod_1.z.any(),
207
+ endTimestamp: zod_1.z.number(),
208
+ prescribedObservers: zod_1.z.any(),
209
+ prescribedNames: zod_1.z.array(zod_1.z.string()),
210
+ observations: zod_1.z.any(),
211
+ distributionTimestamp: zod_1.z.number(),
212
+ epochIndex: zod_1.z.number(),
213
+ });
214
+ return epochDataSchema.parse(value);
215
+ }
216
+ exports.parseAoEpochData = parseAoEpochData;
@@ -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;
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.2.0';
20
+ exports.version = '3.3.0-alpha.10';