@ar.io/sdk 3.3.0-alpha.8 → 3.3.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.
@@ -258,6 +258,12 @@ const utils_js_1 = require("./utils.js");
258
258
  options: options_js_1.paginationAddressOptions,
259
259
  action: readCommands_js_1.getGatewayVaults,
260
260
  });
261
+ (0, utils_js_1.makeCommand)({
262
+ name: 'list-all-gateway-vaults',
263
+ description: 'List vaults from all gateways',
264
+ options: options_js_1.paginationAddressOptions,
265
+ action: readCommands_js_1.getAllGatewayVaults,
266
+ });
261
267
  (0, utils_js_1.makeCommand)({
262
268
  name: 'transfer',
263
269
  description: 'Transfer ARIO to another address',
@@ -671,6 +677,7 @@ const utils_js_1 = require("./utils.js");
671
677
  action: async (options) => {
672
678
  const process = new index_js_1.AOProcess({
673
679
  processId: (0, utils_js_1.requiredProcessIdFromOptions)(options),
680
+ logger: (0, utils_js_1.getLoggerFromOptions)(options),
674
681
  });
675
682
  return process.send({
676
683
  tags: (0, utils_js_1.writeActionTagsFromOptions)(options).tags ?? [],
@@ -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.listAllDelegatesCLICommand = exports.listGateways = exports.getGateway = void 0;
3
+ exports.getVault = exports.getAllGatewayVaults = 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) {
@@ -173,6 +173,15 @@ async function getGatewayVaults(o) {
173
173
  };
174
174
  }
175
175
  exports.getGatewayVaults = getGatewayVaults;
176
+ async function getAllGatewayVaults(o) {
177
+ const result = await (0, utils_js_1.readARIOFromOptions)(o).getAllGatewayVaults((0, utils_js_1.paginationParamsFromOptions)(o));
178
+ return result.items?.length
179
+ ? result
180
+ : {
181
+ message: `No vaults found`,
182
+ };
183
+ }
184
+ exports.getAllGatewayVaults = getAllGatewayVaults;
176
185
  async function getVault(o) {
177
186
  return (0, utils_js_1.readARIOFromOptions)(o)
178
187
  .getVault({
@@ -198,7 +198,7 @@ function paginationParamsFromOptions(options) {
198
198
  return {
199
199
  cursor,
200
200
  limit: numberLimit,
201
- sortBy,
201
+ sortBy: sortBy,
202
202
  sortOrder,
203
203
  };
204
204
  }
@@ -18,6 +18,7 @@ exports.AOProcess = void 0;
18
18
  */
19
19
  const aoconnect_1 = require("@permaweb/aoconnect");
20
20
  const base64_js_1 = require("../../utils/base64.js");
21
+ const index_js_1 = require("../../utils/index.js");
21
22
  const json_js_1 = require("../../utils/json.js");
22
23
  const version_js_1 = require("../../version.js");
23
24
  const error_js_1 = require("../error.js");
@@ -59,7 +60,7 @@ class AOProcess {
59
60
  result,
60
61
  processId: this.processId,
61
62
  });
62
- const error = errorMessageFromOutput(result);
63
+ const error = (0, index_js_1.errorMessageFromOutput)(result);
63
64
  if (error !== undefined) {
64
65
  throw new Error(error);
65
66
  }
@@ -131,7 +132,7 @@ class AOProcess {
131
132
  messageId,
132
133
  processId: this.processId,
133
134
  });
134
- const error = errorMessageFromOutput(output);
135
+ const error = (0, index_js_1.errorMessageFromOutput)(output);
135
136
  if (error !== undefined) {
136
137
  throw new error_js_1.WriteInteractionError(error);
137
138
  }
@@ -181,18 +182,3 @@ class AOProcess {
181
182
  }
182
183
  }
183
184
  exports.AOProcess = AOProcess;
184
- function errorMessageFromOutput(output) {
185
- const errorData = output.Error;
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;
189
- if (error !== undefined) {
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
- }
196
- }
197
- return undefined;
198
- }
@@ -449,6 +449,14 @@ class ARIOReadable {
449
449
  ],
450
450
  });
451
451
  }
452
+ async getAllGatewayVaults(params) {
453
+ return this.process.read({
454
+ tags: [
455
+ { name: 'Action', value: 'All-Gateway-Vaults' },
456
+ ...(0, arweave_js_1.paginationParamsToTags)(params),
457
+ ],
458
+ });
459
+ }
452
460
  }
453
461
  exports.ARIOReadable = ARIOReadable;
454
462
  class ARIOWriteable extends ARIOReadable {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_SCHEDULER_ID = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MARIO_PER_ARIO = exports.ANT_REGISTRY_ID = exports.ARIO_TESTNET_PROCESS_ID = exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
3
+ exports.DEFAULT_SCHEDULER_ID = exports.AO_AUTHORITY = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MARIO_PER_ARIO = exports.ANT_REGISTRY_ID = exports.ARIO_TESTNET_PROCESS_ID = exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
6
  *
@@ -31,4 +31,5 @@ exports.ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
31
31
  exports.MARIO_PER_ARIO = 1_000_000;
32
32
  exports.AOS_MODULE_ID = 'BRyNPIJWZaQ4IudfNnsfvMrZBO2YDPjgKqg_wCYT2U8';
33
33
  exports.ANT_LUA_ID = 'k9tQkbnFYZOGp6ist1yFuaqk_wOkzM5KUSNDtWzCLtg';
34
+ exports.AO_AUTHORITY = 'fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY';
34
35
  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.parseAoEpochData = exports.initANTStateForAddress = exports.defaultTargetManifestId = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
3
+ exports.removeUnicodeFromError = exports.errorMessageFromOutput = 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,13 +22,18 @@ 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, 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, }) {
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, authority = constants_js_1.AO_AUTHORITY, }) {
26
26
  // TODO: use On-Boot data handler for bootstrapping state instead of initialize-state
27
27
  const processId = await ao.spawn({
28
28
  module,
29
29
  scheduler,
30
30
  signer,
31
31
  tags: [
32
+ // Required for AOS to initialize the authorities table
33
+ {
34
+ name: 'Authority',
35
+ value: authority,
36
+ },
32
37
  {
33
38
  name: 'ANT-Registry-Id',
34
39
  value: antRegistryId,
@@ -153,6 +158,20 @@ function createAoSigner(signer) {
153
158
  typeof signer.setPublicKey === 'function') {
154
159
  await signer.setPublicKey();
155
160
  }
161
+ if (signer instanceof arbundles_1.ArconnectSigner) {
162
+ // Sign using Arconnect signDataItem API
163
+ const signedDataItem = await signer['signer'].signDataItem({
164
+ data,
165
+ tags,
166
+ target,
167
+ anchor,
168
+ });
169
+ const dataItem = new arbundles_1.DataItem(Buffer.from(signedDataItem));
170
+ return {
171
+ id: await dataItem.id,
172
+ raw: await dataItem.getRaw(),
173
+ };
174
+ }
156
175
  const dataItem = (0, arbundles_1.createData)(data, signer, { tags, target, anchor });
157
176
  const signedData = dataItem.sign(signer).then(async () => ({
158
177
  id: await dataItem.id,
@@ -200,3 +219,30 @@ function parseAoEpochData(value) {
200
219
  return epochDataSchema.parse(value);
201
220
  }
202
221
  exports.parseAoEpochData = parseAoEpochData;
222
+ function errorMessageFromOutput(output) {
223
+ const errorData = output.Error;
224
+ // Attempt to extract error details from Messages.Tags if Error is undefined
225
+ const error = errorData ??
226
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
227
+ if (error !== undefined) {
228
+ // Consolidated regex to match and extract line number and AO error message or Error Tags
229
+ const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
230
+ if (match) {
231
+ const [, lineNumber, errorMessage] = match;
232
+ const cleanError = removeUnicodeFromError(errorMessage);
233
+ return `${cleanError.trim()} (line ${lineNumber.trim()})`.trim();
234
+ }
235
+ // With no match, just remove unicode
236
+ return removeUnicodeFromError(error);
237
+ }
238
+ return undefined;
239
+ }
240
+ exports.errorMessageFromOutput = errorMessageFromOutput;
241
+ function removeUnicodeFromError(error) {
242
+ //The regular expression /[\u001b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g is designed to match ANSI escape codes used for terminal formatting. These are sequences that begin with \u001b (ESC character) and are often followed by [ and control codes.
243
+ const ESC = String.fromCharCode(27); // Represents '\u001b' or '\x1b'
244
+ return error
245
+ .replace(new RegExp(`${ESC}[\\[\\]()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`, 'g'), '')
246
+ .trim();
247
+ }
248
+ exports.removeUnicodeFromError = removeUnicodeFromError;
@@ -35,22 +35,40 @@ exports.paginationParamsToTags = paginationParamsToTags;
35
35
  * @param arweave - The Arweave instance
36
36
  * @returns The epoch with distribution data
37
37
  */
38
- const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, }) => {
38
+ const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, retries = 3, }) => {
39
39
  // fetch from gql
40
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;
41
+ // add three retries with exponential backoff
42
+ for (let i = 0; i < retries; i++) {
43
+ try {
44
+ const response = await arweave.api.post('graphql', query);
45
+ // parse the nodes to get the id
46
+ if (response.data?.data?.transactions?.edges?.length === 0) {
47
+ return undefined;
48
+ }
49
+ const id = response.data.data.transactions.edges[0].node.id;
50
+ // fetch the transaction from arweave
51
+ const transaction = await arweave.api.get(id);
52
+ // assert it is the correct type
53
+ return (0, ao_js_1.parseAoEpochData)(transaction.data);
54
+ }
55
+ catch (error) {
56
+ if (i === retries - 1)
57
+ throw error; // Re-throw on final attempt
58
+ // exponential backoff
59
+ await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
60
+ }
45
61
  }
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);
62
+ return undefined;
52
63
  };
53
64
  exports.getEpochDataFromGql = getEpochDataFromGql;
65
+ /**
66
+ * Get the epoch with distribution data for the current epoch
67
+ * @param arweave - The Arweave instance
68
+ * @param epochIndex - The index of the epoch
69
+ * @param processId - The process ID (optional, defaults to ARIO_TESTNET_PROCESS_ID)
70
+ * @returns string - The stringified GQL query
71
+ */
54
72
  const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, }) => {
55
73
  // write the query
56
74
  const gqlQuery = JSON.stringify({
@@ -16,10 +16,12 @@ exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcesses
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
+ const aoconnect_1 = require("@permaweb/aoconnect");
19
20
  const eventemitter3_1 = require("eventemitter3");
20
21
  const plimit_lit_1 = require("plimit-lit");
21
22
  const ant_registry_js_1 = require("../common/ant-registry.js");
22
23
  const ant_js_1 = require("../common/ant.js");
24
+ const index_js_1 = require("../common/index.js");
23
25
  const io_js_1 = require("../common/io.js");
24
26
  const logger_js_1 = require("../common/logger.js");
25
27
  const constants_js_1 = require("../constants.js");
@@ -53,15 +55,17 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
53
55
  throttle;
54
56
  logger;
55
57
  strict;
58
+ antAoClient;
56
59
  constructor({ contract = io_js_1.ARIO.init({
57
60
  processId: constants_js_1.ARIO_TESTNET_PROCESS_ID,
58
- }), timeoutMs = 60_000, concurrency = 30, logger = logger_js_1.Logger.default, strict = false, } = {}) {
61
+ }), timeoutMs = 60_000, concurrency = 30, logger = logger_js_1.Logger.default, strict = false, antAoClient = (0, aoconnect_1.connect)(), } = {}) {
59
62
  super();
60
63
  this.contract = contract;
61
64
  this.timeoutMs = timeoutMs;
62
65
  this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
63
66
  this.logger = logger;
64
67
  this.strict = strict;
68
+ this.antAoClient = antAoClient;
65
69
  }
66
70
  async fetchProcessesOwnedByWallet({ address, pageSize, antRegistry = ant_registry_js_1.ANTRegistry.init(), }) {
67
71
  const uniqueContractProcessIds = {};
@@ -99,7 +103,10 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
99
103
  return;
100
104
  }
101
105
  const ant = ant_js_1.ANT.init({
102
- processId,
106
+ process: new index_js_1.AOProcess({
107
+ processId,
108
+ ao: this.antAoClient,
109
+ }),
103
110
  strict: this.strict,
104
111
  });
105
112
  const state = (await timeout(this.timeoutMs, ant.getState()).catch((e) => {
@@ -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.3.0-alpha.8';
20
+ exports.version = '3.3.0';
@@ -21,7 +21,7 @@ import { mARIOToken } from '../types/token.js';
21
21
  import { version } from '../version.js';
22
22
  import { buyRecordCLICommand, extendLeaseCLICommand, increaseUndernameLimitCLICommand, requestPrimaryNameCLICommand, upgradeRecordCLICommand, } from './commands/arnsPurchaseCommands.js';
23
23
  import { cancelWithdrawal, decreaseDelegateStake, decreaseOperatorStake, delegateStake, increaseOperatorStake, instantWithdrawal, joinNetwork, leaveNetwork, redelegateStake, saveObservations, updateGatewaySettings, } from './commands/gatewayWriteCommands.js';
24
- import { getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listAllDelegatesCLICommand, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
24
+ import { getAllGatewayVaults, getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listAllDelegatesCLICommand, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
25
25
  import { transfer } from './commands/transfer.js';
26
26
  import { addressAndVaultIdOptions, antStateOptions, arnsPurchaseOptions, buyRecordOptions, decreaseDelegateStakeOptions, delegateStakeOptions, epochOptions, getVaultOptions, globalOptions, joinNetworkOptions, operatorStakeOptions, optionMap, paginationAddressOptions, paginationOptions, redelegateStakeOptions, tokenCostOptions, transferOptions, updateGatewaySettingsOptions, writeActionOptions, } from './options.js';
27
27
  import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredProcessIdFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, writeActionTagsFromOptions, } from './utils.js';
@@ -256,6 +256,12 @@ makeCommand({
256
256
  options: paginationAddressOptions,
257
257
  action: getGatewayVaults,
258
258
  });
259
+ makeCommand({
260
+ name: 'list-all-gateway-vaults',
261
+ description: 'List vaults from all gateways',
262
+ options: paginationAddressOptions,
263
+ action: getAllGatewayVaults,
264
+ });
259
265
  makeCommand({
260
266
  name: 'transfer',
261
267
  description: 'Transfer ARIO to another address',
@@ -669,6 +675,7 @@ makeCommand({
669
675
  action: async (options) => {
670
676
  const process = new AOProcess({
671
677
  processId: requiredProcessIdFromOptions(options),
678
+ logger: getLoggerFromOptions(options),
672
679
  });
673
680
  return process.send({
674
681
  tags: writeActionTagsFromOptions(options).tags ?? [],
@@ -151,6 +151,14 @@ export async function getGatewayVaults(o) {
151
151
  message: `No vaults found for gateway ${address}`,
152
152
  };
153
153
  }
154
+ export async function getAllGatewayVaults(o) {
155
+ const result = await readARIOFromOptions(o).getAllGatewayVaults(paginationParamsFromOptions(o));
156
+ return result.items?.length
157
+ ? result
158
+ : {
159
+ message: `No vaults found`,
160
+ };
161
+ }
154
162
  export async function getVault(o) {
155
163
  return readARIOFromOptions(o)
156
164
  .getVault({
@@ -176,7 +176,7 @@ export function paginationParamsFromOptions(options) {
176
176
  return {
177
177
  cursor,
178
178
  limit: numberLimit,
179
- sortBy,
179
+ sortBy: sortBy,
180
180
  sortOrder,
181
181
  };
182
182
  }
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { connect } from '@permaweb/aoconnect';
17
17
  import { getRandomText } from '../../utils/base64.js';
18
+ import { errorMessageFromOutput } from '../../utils/index.js';
18
19
  import { safeDecode } from '../../utils/json.js';
19
20
  import { version } from '../../version.js';
20
21
  import { WriteInteractionError } from '../error.js';
@@ -177,18 +178,3 @@ export class AOProcess {
177
178
  throw lastError;
178
179
  }
179
180
  }
180
- function errorMessageFromOutput(output) {
181
- const errorData = output.Error;
182
- // Attempt to extract error details from Messages.Tags if Error is undefined
183
- const error = errorData ??
184
- output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
185
- if (error !== undefined) {
186
- // Consolidated regex to match and extract line number and AO error message or Error Tags
187
- const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
188
- if (match) {
189
- const [, lineNumber, errorMessage] = match;
190
- return `${errorMessage.trim()} (line ${lineNumber.trim()})`.trim();
191
- }
192
- }
193
- return undefined;
194
- }
@@ -445,6 +445,14 @@ export class ARIOReadable {
445
445
  ],
446
446
  });
447
447
  }
448
+ async getAllGatewayVaults(params) {
449
+ return this.process.read({
450
+ tags: [
451
+ { name: 'Action', value: 'All-Gateway-Vaults' },
452
+ ...paginationParamsToTags(params),
453
+ ],
454
+ });
455
+ }
448
456
  }
449
457
  export class ARIOWriteable extends ARIOReadable {
450
458
  signer;
@@ -28,4 +28,5 @@ export const ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
28
28
  export const MARIO_PER_ARIO = 1_000_000;
29
29
  export const AOS_MODULE_ID = 'BRyNPIJWZaQ4IudfNnsfvMrZBO2YDPjgKqg_wCYT2U8';
30
30
  export const ANT_LUA_ID = 'k9tQkbnFYZOGp6ist1yFuaqk_wOkzM5KUSNDtWzCLtg';
31
+ export const AO_AUTHORITY = 'fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY';
31
32
  export const DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
@@ -13,19 +13,24 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { createData } from '@dha-team/arbundles';
16
+ import { ArconnectSigner, DataItem, createData } from '@dha-team/arbundles';
17
17
  import { connect, createDataItemSigner } from '@permaweb/aoconnect';
18
18
  import { z } from 'zod';
19
19
  import { defaultArweave } from '../common/arweave.js';
20
20
  import { ANTRegistry, AOProcess, Logger } from '../common/index.js';
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, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = ANT_REGISTRY_ID, logger = Logger.default, }) {
21
+ import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, AO_AUTHORITY, DEFAULT_SCHEDULER_ID, } from '../constants.js';
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, authority = AO_AUTHORITY, }) {
23
23
  // TODO: use On-Boot data handler for bootstrapping state instead of initialize-state
24
24
  const processId = await ao.spawn({
25
25
  module,
26
26
  scheduler,
27
27
  signer,
28
28
  tags: [
29
+ // Required for AOS to initialize the authorities table
30
+ {
31
+ name: 'Authority',
32
+ value: authority,
33
+ },
29
34
  {
30
35
  name: 'ANT-Registry-Id',
31
36
  value: antRegistryId,
@@ -147,6 +152,20 @@ export function createAoSigner(signer) {
147
152
  typeof signer.setPublicKey === 'function') {
148
153
  await signer.setPublicKey();
149
154
  }
155
+ if (signer instanceof ArconnectSigner) {
156
+ // Sign using Arconnect signDataItem API
157
+ const signedDataItem = await signer['signer'].signDataItem({
158
+ data,
159
+ tags,
160
+ target,
161
+ anchor,
162
+ });
163
+ const dataItem = new DataItem(Buffer.from(signedDataItem));
164
+ return {
165
+ id: await dataItem.id,
166
+ raw: await dataItem.getRaw(),
167
+ };
168
+ }
150
169
  const dataItem = createData(data, signer, { tags, target, anchor });
151
170
  const signedData = dataItem.sign(signer).then(async () => ({
152
171
  id: await dataItem.id,
@@ -191,3 +210,28 @@ export function parseAoEpochData(value) {
191
210
  });
192
211
  return epochDataSchema.parse(value);
193
212
  }
213
+ export function errorMessageFromOutput(output) {
214
+ const errorData = output.Error;
215
+ // Attempt to extract error details from Messages.Tags if Error is undefined
216
+ const error = errorData ??
217
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
218
+ if (error !== undefined) {
219
+ // Consolidated regex to match and extract line number and AO error message or Error Tags
220
+ const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
221
+ if (match) {
222
+ const [, lineNumber, errorMessage] = match;
223
+ const cleanError = removeUnicodeFromError(errorMessage);
224
+ return `${cleanError.trim()} (line ${lineNumber.trim()})`.trim();
225
+ }
226
+ // With no match, just remove unicode
227
+ return removeUnicodeFromError(error);
228
+ }
229
+ return undefined;
230
+ }
231
+ export function removeUnicodeFromError(error) {
232
+ //The regular expression /[\u001b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g is designed to match ANSI escape codes used for terminal formatting. These are sequences that begin with \u001b (ESC character) and are often followed by [ and control codes.
233
+ const ESC = String.fromCharCode(27); // Represents '\u001b' or '\x1b'
234
+ return error
235
+ .replace(new RegExp(`${ESC}[\\[\\]()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`, 'g'), '')
236
+ .trim();
237
+ }
@@ -28,21 +28,39 @@ export const paginationParamsToTags = (params) => {
28
28
  * @param arweave - The Arweave instance
29
29
  * @returns The epoch with distribution data
30
30
  */
31
- export const getEpochDataFromGql = async ({ arweave, epochIndex, processId = ARIO_TESTNET_PROCESS_ID, }) => {
31
+ export const getEpochDataFromGql = async ({ arweave, epochIndex, processId = ARIO_TESTNET_PROCESS_ID, retries = 3, }) => {
32
32
  // fetch from gql
33
33
  const query = epochDistributionNoticeGqlQuery({ epochIndex, processId });
34
- const response = await arweave.api.post('graphql', query);
35
- // parse the nodes to get the id
36
- if (response.data.data.transactions?.edges?.length === 0) {
37
- return undefined;
34
+ // add three retries with exponential backoff
35
+ for (let i = 0; i < retries; i++) {
36
+ try {
37
+ const response = await arweave.api.post('graphql', query);
38
+ // parse the nodes to get the id
39
+ if (response.data?.data?.transactions?.edges?.length === 0) {
40
+ return undefined;
41
+ }
42
+ const id = response.data.data.transactions.edges[0].node.id;
43
+ // fetch the transaction from arweave
44
+ const transaction = await arweave.api.get(id);
45
+ // assert it is the correct type
46
+ return parseAoEpochData(transaction.data);
47
+ }
48
+ catch (error) {
49
+ if (i === retries - 1)
50
+ throw error; // Re-throw on final attempt
51
+ // exponential backoff
52
+ await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
53
+ }
38
54
  }
39
- const id = response.data.data.transactions.edges[0].node.id;
40
- // fetch the transaction from arweave
41
- const transaction = await arweave.api.get(id);
42
- const data = transaction.data;
43
- // assert it is the correct type
44
- return parseAoEpochData(data);
55
+ return undefined;
45
56
  };
57
+ /**
58
+ * Get the epoch with distribution data for the current epoch
59
+ * @param arweave - The Arweave instance
60
+ * @param epochIndex - The index of the epoch
61
+ * @param processId - The process ID (optional, defaults to ARIO_TESTNET_PROCESS_ID)
62
+ * @returns string - The stringified GQL query
63
+ */
46
64
  export const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = ARIO_TESTNET_PROCESS_ID, }) => {
47
65
  // write the query
48
66
  const gqlQuery = JSON.stringify({
@@ -13,10 +13,12 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { connect } from '@permaweb/aoconnect';
16
17
  import { EventEmitter } from 'eventemitter3';
17
18
  import { pLimit } from 'plimit-lit';
18
19
  import { ANTRegistry } from '../common/ant-registry.js';
19
20
  import { ANT } from '../common/ant.js';
21
+ import { AOProcess } from '../common/index.js';
20
22
  import { ARIO } from '../common/io.js';
21
23
  import { Logger } from '../common/logger.js';
22
24
  import { ARIO_TESTNET_PROCESS_ID } from '../constants.js';
@@ -49,15 +51,17 @@ export class ArNSEventEmitter extends EventEmitter {
49
51
  throttle;
50
52
  logger;
51
53
  strict;
54
+ antAoClient;
52
55
  constructor({ contract = ARIO.init({
53
56
  processId: ARIO_TESTNET_PROCESS_ID,
54
- }), timeoutMs = 60_000, concurrency = 30, logger = Logger.default, strict = false, } = {}) {
57
+ }), timeoutMs = 60_000, concurrency = 30, logger = Logger.default, strict = false, antAoClient = connect(), } = {}) {
55
58
  super();
56
59
  this.contract = contract;
57
60
  this.timeoutMs = timeoutMs;
58
61
  this.throttle = pLimit(concurrency);
59
62
  this.logger = logger;
60
63
  this.strict = strict;
64
+ this.antAoClient = antAoClient;
61
65
  }
62
66
  async fetchProcessesOwnedByWallet({ address, pageSize, antRegistry = ANTRegistry.init(), }) {
63
67
  const uniqueContractProcessIds = {};
@@ -95,7 +99,10 @@ export class ArNSEventEmitter extends EventEmitter {
95
99
  return;
96
100
  }
97
101
  const ant = ANT.init({
98
- processId,
102
+ process: new AOProcess({
103
+ processId,
104
+ ao: this.antAoClient,
105
+ }),
99
106
  strict: this.strict,
100
107
  });
101
108
  const state = (await timeout(this.timeoutMs, ant.getState()).catch((e) => {
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.3.0-alpha.8';
17
+ export const version = '3.3.0';
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AoGetCostDetailsParams } from '../../types/io.js';
16
+ import { AoDelegation, AoGatewayDelegateWithAddress, AoGatewayVault, AoGetCostDetailsParams } from '../../types/io.js';
17
17
  import { AddressAndNameCLIOptions, AddressAndVaultIdCLIOptions, AddressCLIOptions, CLIOptionsFromAoParams, EpochCLIOptions, GetTokenCostCLIOptions, GlobalCLIOptions, NameCLIOptions, PaginationAddressCLIOptions, PaginationCLIOptions } from '../types.js';
18
18
  export declare function getGateway(o: AddressCLIOptions): Promise<import("../../types/io.js").AoGateway | {
19
19
  message: string;
@@ -24,10 +24,10 @@ export declare function listGateways(o: PaginationCLIOptions): Promise<import(".
24
24
  export declare function listAllDelegatesCLICommand(o: PaginationCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoAllDelegates> | {
25
25
  message: string;
26
26
  }>;
27
- export declare function getGatewayDelegates(o: AddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoGatewayDelegateWithAddress> | {
27
+ export declare function getGatewayDelegates(o: AddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoGatewayDelegateWithAddress> | {
28
28
  message: string;
29
29
  }>;
30
- export declare function getDelegations(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoDelegation> | {
30
+ export declare function getDelegations(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoDelegation> | {
31
31
  message: string;
32
32
  }>;
33
33
  export declare function getAllowedDelegates(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<string> | {
@@ -76,7 +76,10 @@ export declare function getCostDetails(o: GlobalCLIOptions & CLIOptionsFromAoPar
76
76
  export declare function getPrimaryName(o: AddressAndNameCLIOptions): Promise<import("../../types/common.js").AoPrimaryName | {
77
77
  message: string;
78
78
  }>;
79
- export declare function getGatewayVaults(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoGatewayVault> | {
79
+ export declare function getGatewayVaults(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoGatewayVault> | {
80
+ message: string;
81
+ }>;
82
+ export declare function getAllGatewayVaults(o: PaginationCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoAllGatewayVaults> | {
80
83
  message: string;
81
84
  }>;
82
85
  export declare function getVault(o: AddressAndVaultIdCLIOptions): Promise<import("../../types/io.js").AoVaultData | {