@ar.io/sdk 3.19.0-alpha.1 → 3.19.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 +88 -72
- package/lib/cjs/cli/cli.js +6 -0
- package/lib/cjs/cli/commands/antCommands.js +33 -0
- package/lib/cjs/cli/options.js +2 -1
- package/lib/cjs/cli/utils.js +11 -11
- package/lib/cjs/common/ant.js +309 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/utils/ant.js +4 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +8 -2
- package/lib/esm/cli/commands/antCommands.js +33 -1
- package/lib/esm/cli/options.js +1 -0
- package/lib/esm/cli/utils.js +11 -11
- package/lib/esm/common/ant.js +310 -1
- package/lib/esm/constants.js +1 -0
- package/lib/esm/utils/ant.js +4 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +5 -0
- package/lib/types/cli/options.d.ts +4 -0
- package/lib/types/cli/utils.d.ts +2 -2
- package/lib/types/common/ant.d.ts +121 -2
- package/lib/types/constants.d.ts +1 -0
- package/lib/types/types/ant.d.ts +26 -1
- package/lib/types/types/common.d.ts +15 -0
- package/lib/types/utils/ant.d.ts +4 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/esm/common/ant.js
CHANGED
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
+
import { ARIO_MAINNET_PROCESS_ID } from '../constants.js';
|
|
18
|
+
import { ANT_REGISTRY_ID } from '../constants.js';
|
|
17
19
|
import { AntBalancesSchema, AntControllersSchema, AntInfoSchema, AntRecordSchema, AntRecordsSchema, AntStateSchema, } from '../types/ant.js';
|
|
18
20
|
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
|
|
19
21
|
import { convertHyperBeamStateToAoANTState, isHyperBeamANTState, sortANTRecords, } from '../utils/ant.js';
|
|
20
22
|
import { createAoSigner, forkANT, spawnANT } from '../utils/ao.js';
|
|
21
23
|
import { parseSchemaResult } from '../utils/schema.js';
|
|
22
24
|
import { ANTVersions } from './ant-versions.js';
|
|
23
|
-
import { AOProcess, InvalidContractConfigurationError, Logger, } from './index.js';
|
|
25
|
+
import { AOProcess, ARIO, InvalidContractConfigurationError, Logger, } from './index.js';
|
|
24
26
|
export class ANT {
|
|
25
27
|
/**
|
|
26
28
|
* Versions of ANTs according to the ANT registry.
|
|
@@ -40,6 +42,97 @@ export class ANT {
|
|
|
40
42
|
* @param config
|
|
41
43
|
*/
|
|
42
44
|
static fork = forkANT;
|
|
45
|
+
/**
|
|
46
|
+
* Upgrade an ANT by forking it to the latest version and reassigning names.
|
|
47
|
+
*
|
|
48
|
+
*
|
|
49
|
+
* @param config Configuration object for the upgrade process
|
|
50
|
+
* @returns Promise resolving to the forked process ID and successfully reassigned names
|
|
51
|
+
*/
|
|
52
|
+
static async upgrade({ signer, antProcessId, reassignAffiliatedNames = true, // if true, will reassign all affiliated names, otherwise will use the names parameter
|
|
53
|
+
names = [], arioProcessId = ARIO_MAINNET_PROCESS_ID, antRegistryId = ANT_REGISTRY_ID, ao, logger = Logger.default, skipVersionCheck = false, onSigningProgress, hyperbeamUrl, }) {
|
|
54
|
+
// if names is not empty but reassignAffiliatedNames it true, throw
|
|
55
|
+
if (names.length > 0 && reassignAffiliatedNames) {
|
|
56
|
+
throw new Error('Cannot reassign all affiliated names and provide specific names');
|
|
57
|
+
}
|
|
58
|
+
// get all the affiliated names if reassign all affiliated names is true
|
|
59
|
+
if (reassignAffiliatedNames) {
|
|
60
|
+
const ario = ARIO.init({
|
|
61
|
+
process: new AOProcess({ processId: arioProcessId, ao }),
|
|
62
|
+
});
|
|
63
|
+
onSigningProgress?.('fetching-affiliated-names', {
|
|
64
|
+
arioProcessId,
|
|
65
|
+
antProcessId,
|
|
66
|
+
});
|
|
67
|
+
const allAffiliatedNames = await ario.getArNSRecords({
|
|
68
|
+
filters: {
|
|
69
|
+
processId: antProcessId,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
names.push(...allAffiliatedNames.items.map((record) => record.name));
|
|
73
|
+
}
|
|
74
|
+
// if names is empty and reassign all affiliated names is false, throw an error
|
|
75
|
+
if (names.length === 0) {
|
|
76
|
+
throw new Error('There are no names to reassign for this ANT.');
|
|
77
|
+
}
|
|
78
|
+
const existingAntProcess = ANT.init({
|
|
79
|
+
process: new AOProcess({
|
|
80
|
+
processId: antProcessId,
|
|
81
|
+
ao,
|
|
82
|
+
logger,
|
|
83
|
+
}),
|
|
84
|
+
hyperbeamUrl,
|
|
85
|
+
signer,
|
|
86
|
+
});
|
|
87
|
+
if (!skipVersionCheck) {
|
|
88
|
+
onSigningProgress?.('checking-version', {
|
|
89
|
+
antProcessId,
|
|
90
|
+
antRegistryId,
|
|
91
|
+
});
|
|
92
|
+
const isLatestVersion = await existingAntProcess.isLatestVersion({
|
|
93
|
+
antRegistryId,
|
|
94
|
+
});
|
|
95
|
+
if (isLatestVersion) {
|
|
96
|
+
return {
|
|
97
|
+
forkedProcessId: antProcessId,
|
|
98
|
+
reassignedNames: [],
|
|
99
|
+
failedReassignedNames: [],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const forkedProcessId = await ANT.fork({
|
|
104
|
+
signer,
|
|
105
|
+
antProcessId,
|
|
106
|
+
ao,
|
|
107
|
+
logger,
|
|
108
|
+
antRegistryId,
|
|
109
|
+
onSigningProgress,
|
|
110
|
+
});
|
|
111
|
+
// we could parallelize this, but then signing progress would be harder to track
|
|
112
|
+
const reassignedNames = [];
|
|
113
|
+
const failedReassignedNames = [];
|
|
114
|
+
for (const name of names) {
|
|
115
|
+
try {
|
|
116
|
+
onSigningProgress?.('reassigning-name', {
|
|
117
|
+
name,
|
|
118
|
+
arioProcessId,
|
|
119
|
+
antProcessId: forkedProcessId,
|
|
120
|
+
});
|
|
121
|
+
await existingAntProcess.reassignName({
|
|
122
|
+
name,
|
|
123
|
+
arioProcessId,
|
|
124
|
+
antProcessId: forkedProcessId,
|
|
125
|
+
});
|
|
126
|
+
reassignedNames.push(name);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
logger.error(`Failed to reassign name ${name}:`, { error });
|
|
130
|
+
// Continue with other names rather than failing completely
|
|
131
|
+
failedReassignedNames.push(name);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { forkedProcessId, reassignedNames, failedReassignedNames };
|
|
135
|
+
}
|
|
43
136
|
static init(config) {
|
|
44
137
|
if (config !== undefined && 'signer' in config) {
|
|
45
138
|
return new AoANTWriteable(config);
|
|
@@ -53,6 +146,8 @@ export class AoANTReadable {
|
|
|
53
146
|
strict;
|
|
54
147
|
hyperbeamUrl;
|
|
55
148
|
checkHyperBeamPromise;
|
|
149
|
+
moduleId;
|
|
150
|
+
moduleIdPromise;
|
|
56
151
|
logger = Logger.default;
|
|
57
152
|
constructor(config) {
|
|
58
153
|
this.strict = config.strict || false;
|
|
@@ -185,6 +280,184 @@ export class AoANTReadable {
|
|
|
185
280
|
const info = await this.getInfo();
|
|
186
281
|
return info.Logo;
|
|
187
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Gets the module ID of the current ANT process by querying its spawn transaction tags.
|
|
285
|
+
* Results are cached after the first successful fetch.
|
|
286
|
+
*
|
|
287
|
+
* @param graphqlUrl The GraphQL endpoint URL (defaults to Arweave's GraphQL endpoint)
|
|
288
|
+
* @param retries Number of retry attempts (defaults to 3)
|
|
289
|
+
* @returns Promise<string> The module ID used to spawn this ANT process
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const moduleId = await ant.getModuleId();
|
|
293
|
+
* console.log(`ANT was spawned with module: ${moduleId}`);
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
async getModuleId({
|
|
297
|
+
// TODO: we could use wayfinder for this
|
|
298
|
+
graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
|
|
299
|
+
// Return cached result if available
|
|
300
|
+
if (this.moduleId !== undefined) {
|
|
301
|
+
this.logger.debug('Returning cached module ID', {
|
|
302
|
+
processId: this.processId,
|
|
303
|
+
moduleId: this.moduleId,
|
|
304
|
+
});
|
|
305
|
+
return this.moduleId;
|
|
306
|
+
}
|
|
307
|
+
// Return existing promise if already in flight
|
|
308
|
+
if (this.moduleIdPromise) {
|
|
309
|
+
this.logger.debug('Returning in-flight module ID promise', {
|
|
310
|
+
processId: this.processId,
|
|
311
|
+
});
|
|
312
|
+
return this.moduleIdPromise;
|
|
313
|
+
}
|
|
314
|
+
// Create and cache the promise to prevent multiple concurrent requests
|
|
315
|
+
this.moduleIdPromise = this.fetchModuleId({ graphqlUrl, retries });
|
|
316
|
+
try {
|
|
317
|
+
const moduleId = await this.moduleIdPromise;
|
|
318
|
+
this.moduleId = moduleId;
|
|
319
|
+
this.logger.debug('Successfully fetched and cached module ID', {
|
|
320
|
+
processId: this.processId,
|
|
321
|
+
moduleId,
|
|
322
|
+
});
|
|
323
|
+
return moduleId;
|
|
324
|
+
}
|
|
325
|
+
finally {
|
|
326
|
+
// Clear the promise so future calls can retry if this one failed
|
|
327
|
+
this.moduleIdPromise = undefined;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Internal method to fetch the module ID from GraphQL.
|
|
332
|
+
*
|
|
333
|
+
* TODO: this could be more like get process headers/metadata and fetch additional details.
|
|
334
|
+
*
|
|
335
|
+
* It seems like module is the only relevant one, but scheduler and authority are also available.
|
|
336
|
+
*/
|
|
337
|
+
async fetchModuleId({ graphqlUrl, retries, }) {
|
|
338
|
+
const query = JSON.stringify({
|
|
339
|
+
query: `
|
|
340
|
+
query {
|
|
341
|
+
transactions(
|
|
342
|
+
ids: ["${this.processId}"]
|
|
343
|
+
first: 1,
|
|
344
|
+
) {
|
|
345
|
+
edges {
|
|
346
|
+
node {
|
|
347
|
+
tags {
|
|
348
|
+
name
|
|
349
|
+
value
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
`,
|
|
356
|
+
});
|
|
357
|
+
for (let i = 0; i < retries; i++) {
|
|
358
|
+
try {
|
|
359
|
+
const response = await fetch(graphqlUrl, {
|
|
360
|
+
method: 'POST',
|
|
361
|
+
body: query,
|
|
362
|
+
headers: {
|
|
363
|
+
'Content-Type': 'application/json',
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
if (!response.ok) {
|
|
367
|
+
throw new Error(`GraphQL request failed: ${response.statusText}`);
|
|
368
|
+
}
|
|
369
|
+
const result = (await response.json());
|
|
370
|
+
if (result.errors) {
|
|
371
|
+
throw new Error(`GraphQL errors: ${result.errors.map((e) => e.message).join(', ')}`);
|
|
372
|
+
}
|
|
373
|
+
const edges = result.data?.transactions?.edges;
|
|
374
|
+
if (!edges || edges.length === 0) {
|
|
375
|
+
throw new Error(`No transaction found for process ID: ${this.processId}`);
|
|
376
|
+
}
|
|
377
|
+
const tags = edges[0].node.tags;
|
|
378
|
+
const moduleTag = tags.find((tag) => tag.name === 'Module');
|
|
379
|
+
if (!moduleTag) {
|
|
380
|
+
throw new Error(`No Module tag found for process ID: ${this.processId}`);
|
|
381
|
+
}
|
|
382
|
+
return moduleTag.value;
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
if (i === retries - 1) {
|
|
386
|
+
// Final attempt failed
|
|
387
|
+
this.logger.error('Failed to get ANT module ID after all retries:', {
|
|
388
|
+
error,
|
|
389
|
+
});
|
|
390
|
+
throw new Error(`Unable to determine module ID for ANT process ${this.processId}: ${error.message}`);
|
|
391
|
+
}
|
|
392
|
+
// Exponential backoff
|
|
393
|
+
await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
throw new Error(`Unexpected error getting module ID for process ${this.processId}`);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Gets the version string of the current ANT by matching its module ID
|
|
400
|
+
* with versions from the ANT registry.
|
|
401
|
+
*
|
|
402
|
+
* @param antRegistryId The ANT registry process ID (defaults to mainnet registry)
|
|
403
|
+
* @param graphqlUrl The GraphQL endpoint URL for getModuleId (defaults to Arweave's GraphQL endpoint)
|
|
404
|
+
* @param retries Number of retry attempts for getModuleId (defaults to 3)
|
|
405
|
+
* @returns Promise<string> The version string (e.g., "1.0.15") or "unknown" if not found
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* const version = await ant.getVersion();
|
|
409
|
+
* console.log(`ANT is running version: ${version}`);
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
async getVersion({ antRegistryId = ANT_REGISTRY_ID, graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
|
|
413
|
+
// Get the current ANT's module ID
|
|
414
|
+
const currentModuleId = await this.getModuleId({ graphqlUrl, retries });
|
|
415
|
+
// Get all versions from the ANT registry
|
|
416
|
+
const antVersions = ANTVersions.init({
|
|
417
|
+
processId: antRegistryId,
|
|
418
|
+
});
|
|
419
|
+
const versions = await antVersions.getANTVersions();
|
|
420
|
+
// Find the version that matches our module ID
|
|
421
|
+
for (const [version, versionInfo] of Object.entries(versions)) {
|
|
422
|
+
if (versionInfo.moduleId === currentModuleId) {
|
|
423
|
+
this.logger.debug('Found matching ANT version', {
|
|
424
|
+
processId: this.processId,
|
|
425
|
+
moduleId: currentModuleId,
|
|
426
|
+
version,
|
|
427
|
+
});
|
|
428
|
+
return version;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const versionForModuleId = Object.entries(versions)
|
|
432
|
+
.map(([version, versionInfo]) => ({
|
|
433
|
+
version,
|
|
434
|
+
...versionInfo,
|
|
435
|
+
}))
|
|
436
|
+
.find((obj) => obj.moduleId === currentModuleId);
|
|
437
|
+
return versionForModuleId?.version ?? 'unknown';
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Checks if the current ANT version is the latest according to the ANT registry.
|
|
441
|
+
*
|
|
442
|
+
* @param antRegistryId Optional ANT registry process ID. Defaults to mainnet ANT registry.
|
|
443
|
+
* @param graphqlUrl Optional GraphQL endpoint. Defaults to https://arweave.net/graphql.
|
|
444
|
+
* @param retries Optional number of retries for fetching module ID. Defaults to 3.
|
|
445
|
+
* @returns {Promise<boolean>} True if current ANT version is the latest, false otherwise.
|
|
446
|
+
*/
|
|
447
|
+
async isLatestVersion({ antRegistryId = ANT_REGISTRY_ID, graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
|
|
448
|
+
// Get the current ANT's version
|
|
449
|
+
const currentVersion = await this.getVersion({
|
|
450
|
+
antRegistryId,
|
|
451
|
+
graphqlUrl,
|
|
452
|
+
retries,
|
|
453
|
+
});
|
|
454
|
+
// Get all versions from the ANT registry
|
|
455
|
+
const antVersions = ANTVersions.init({
|
|
456
|
+
processId: antRegistryId,
|
|
457
|
+
});
|
|
458
|
+
const latestVersion = await antVersions.getLatestANTVersion();
|
|
459
|
+
return currentVersion === latestVersion.version;
|
|
460
|
+
}
|
|
188
461
|
/**
|
|
189
462
|
* @param undername @type {string} The domain name.
|
|
190
463
|
* @returns {Promise<ANTRecord>} The record of the undername domain.
|
|
@@ -716,4 +989,40 @@ export class AoANTWriteable extends AoANTReadable {
|
|
|
716
989
|
signer: this.signer,
|
|
717
990
|
});
|
|
718
991
|
}
|
|
992
|
+
/**
|
|
993
|
+
* Upgrade this ANT by forking it to the latest version and reassigning names.
|
|
994
|
+
*
|
|
995
|
+
* This is a convenience method that calls the static ANT.upgrade() method
|
|
996
|
+
* using this instance's process ID and signer.
|
|
997
|
+
*
|
|
998
|
+
* TODO: Add version checking by implementing a getVersion API on ANTs to compare
|
|
999
|
+
* current version with latest ANT registry version and skip if already up to date.
|
|
1000
|
+
*
|
|
1001
|
+
* @param names @type {string[]} The ArNS names to reassign to the upgraded ANT.
|
|
1002
|
+
* @param arioProcessId @type {string} The processId of the ARIO contract.
|
|
1003
|
+
* @param antRegistryId @type {string} Optional ANT registry ID.
|
|
1004
|
+
* @param onSigningProgress Progress callback function.
|
|
1005
|
+
* @returns {Promise} The upgrade results.
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```ts
|
|
1008
|
+
* const result = await ant.upgrade({
|
|
1009
|
+
* names: ["example", "test"],
|
|
1010
|
+
* arioProcessId: ARIO_MAINNET_PROCESS_ID
|
|
1011
|
+
* });
|
|
1012
|
+
* console.log(`Upgraded to process: ${result.forkedProcessId}`);
|
|
1013
|
+
* ```
|
|
1014
|
+
*/
|
|
1015
|
+
async upgrade({ names, reassignAffiliatedNames, arioProcessId, antRegistryId, onSigningProgress, skipVersionCheck = false, }) {
|
|
1016
|
+
return ANT.upgrade({
|
|
1017
|
+
signer: this.signer,
|
|
1018
|
+
antProcessId: this.processId,
|
|
1019
|
+
ao: this.process.ao,
|
|
1020
|
+
names,
|
|
1021
|
+
reassignAffiliatedNames,
|
|
1022
|
+
arioProcessId,
|
|
1023
|
+
antRegistryId,
|
|
1024
|
+
onSigningProgress,
|
|
1025
|
+
skipVersionCheck,
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
719
1028
|
}
|
package/lib/esm/constants.js
CHANGED
|
@@ -21,6 +21,7 @@ export const ARIO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGr
|
|
|
21
21
|
export const arioDevnetProcessId = ARIO_DEVNET_PROCESS_ID;
|
|
22
22
|
export const ARIO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
23
23
|
export const ARIO_MAINNET_PROCESS_ID = 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE';
|
|
24
|
+
export const ANT_REGISTRY_TESTNET_ID = 'RR0vheYqtsKuJCWh6xj0beE35tjaEug5cejMw9n2aa8';
|
|
24
25
|
export const ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
|
|
25
26
|
export const MARIO_PER_ARIO = 1_000_000;
|
|
26
27
|
/**
|
package/lib/esm/utils/ant.js
CHANGED
|
@@ -37,6 +37,9 @@ export const sortANTRecords = (antRecords) => {
|
|
|
37
37
|
// now that they are sorted, add the index to each record - this is their position in the sorted list and is used to enforce undername limits
|
|
38
38
|
return Object.fromEntries(sortedEntries.map(([a, aRecord], index) => [a, { ...aRecord, index }]));
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated - this is no longer necessary because HyperBeam now uses the AoANTState type
|
|
42
|
+
*/
|
|
40
43
|
export const isHyperBeamANTState = (state) => {
|
|
41
44
|
return ('name' in state &&
|
|
42
45
|
'ticker' in state &&
|
|
@@ -54,6 +57,7 @@ export const isHyperBeamANTState = (state) => {
|
|
|
54
57
|
/**
|
|
55
58
|
* Convert HyperBeam serialized ANT state to backwards compatible format.
|
|
56
59
|
*
|
|
60
|
+
* @deprecated - this is no longer necessary because HyperBeam now uses the AOANTState type
|
|
57
61
|
* @param state - The HyperBeam serialized ANT state.
|
|
58
62
|
*/
|
|
59
63
|
export const convertHyperBeamStateToAoANTState = (initialState) => {
|
package/lib/esm/version.js
CHANGED
|
@@ -19,3 +19,8 @@ import { CLIWriteOptionsFromAoAntParams } from '../types.js';
|
|
|
19
19
|
export declare function setAntRecordCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
20
20
|
export declare function setAntBaseNameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetBaseNameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
21
21
|
export declare function setAntUndernameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
22
|
+
export declare function upgradeAntCLICommand(o: CLIWriteOptionsFromAoAntParams<Record<string, unknown>>): Promise<{
|
|
23
|
+
forkedProcessId: string;
|
|
24
|
+
reassignedNames: string[];
|
|
25
|
+
failedReassignedNames: string[];
|
|
26
|
+
}>;
|
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JWKInterface } from 'arweave/node/lib/wallet.js';
|
|
2
2
|
import { Command, OptionValues } from 'commander';
|
|
3
|
-
import {
|
|
3
|
+
import { ARIOToken, AoANTRead, AoANTRegistryRead, AoANTWrite, AoARIORead, AoARIOWrite, AoGetCostDetailsParams, AoRedelegateStakeParams, AoSigner, AoUpdateGatewaySettingsParams, ContractSigner, EpochInput, FundFrom, Logger, PaginationParams, SpawnANTState, WriteOptions, mARIOToken } from '../node/index.js';
|
|
4
4
|
import { ANTStateCLIOptions, AddressCLIOptions, EpochCLIOptions, GetTokenCostCLIOptions, GlobalCLIOptions, InitiatorCLIOptions, JsonSerializable, PaginationCLIOptions, ProcessIdCLIOptions, RedelegateStakeCLIOptions, TransferCLIOptions, UpdateGatewaySettingsCLIOptions, WalletCLIOptions, WriteActionCLIOptions } from './types.js';
|
|
5
5
|
export declare const defaultTtlSecondsCLI = 3600;
|
|
6
6
|
export declare function stringifyJsonForCLIDisplay(json: JsonSerializable | unknown): string;
|
|
@@ -18,11 +18,11 @@ export declare function makeCommand<O extends OptionValues = GlobalCLIOptions>({
|
|
|
18
18
|
options?: CommanderOption[];
|
|
19
19
|
}): Command;
|
|
20
20
|
export declare function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }: GlobalCLIOptions): string;
|
|
21
|
+
export declare function antRegistryIdFromOptions({ antRegistryProcessId, testnet, }: GlobalCLIOptions): string;
|
|
21
22
|
export declare function requiredJwkFromOptions(options: WalletCLIOptions): JWKInterface;
|
|
22
23
|
export declare function jwkToAddress(jwk: JWKInterface): string;
|
|
23
24
|
export declare function getLoggerFromOptions(options: GlobalCLIOptions): Logger;
|
|
24
25
|
export declare function readARIOFromOptions(options: GlobalCLIOptions): AoARIORead;
|
|
25
|
-
export declare function ANTRegistryProcessFromOptions(options: ProcessIdCLIOptions): AOProcess;
|
|
26
26
|
export declare function readANTRegistryFromOptions(options: ProcessIdCLIOptions): AoANTRegistryRead;
|
|
27
27
|
export declare function contractSignerFromOptions(options: WalletCLIOptions): {
|
|
28
28
|
signer: ContractSigner;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AntReadOptions, AoANTHandler, AoANTInfo, AoANTRead, AoANTRecord, AoANTSetBaseNameRecordParams, AoANTSetUndernameRecordParams, AoANTState, AoANTWrite, SortedANTRecords } from '../types/ant.js';
|
|
2
|
-
import { AoMessageResult, ProcessConfiguration, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
|
|
2
|
+
import { AoClient, AoMessageResult, AoSigner, ProcessConfiguration, UpgradeAntProgressEvent, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
|
|
3
3
|
import { forkANT, spawnANT } from '../utils/ao.js';
|
|
4
|
-
import { AOProcess } from './index.js';
|
|
4
|
+
import { AOProcess, Logger } from './index.js';
|
|
5
5
|
type ANTConfigOptionalStrict = Required<ProcessConfiguration> & {
|
|
6
6
|
strict?: boolean;
|
|
7
7
|
hyperbeamUrl?: string;
|
|
@@ -25,6 +25,31 @@ export declare class ANT {
|
|
|
25
25
|
* @param config
|
|
26
26
|
*/
|
|
27
27
|
static fork: typeof forkANT;
|
|
28
|
+
/**
|
|
29
|
+
* Upgrade an ANT by forking it to the latest version and reassigning names.
|
|
30
|
+
*
|
|
31
|
+
*
|
|
32
|
+
* @param config Configuration object for the upgrade process
|
|
33
|
+
* @returns Promise resolving to the forked process ID and successfully reassigned names
|
|
34
|
+
*/
|
|
35
|
+
static upgrade({ signer, antProcessId, reassignAffiliatedNames, // if true, will reassign all affiliated names, otherwise will use the names parameter
|
|
36
|
+
names, arioProcessId, antRegistryId, ao, logger, skipVersionCheck, onSigningProgress, hyperbeamUrl, }: {
|
|
37
|
+
signer: AoSigner;
|
|
38
|
+
antProcessId: string;
|
|
39
|
+
names?: string[];
|
|
40
|
+
reassignAffiliatedNames?: boolean;
|
|
41
|
+
arioProcessId?: string;
|
|
42
|
+
skipVersionCheck?: boolean;
|
|
43
|
+
ao?: AoClient;
|
|
44
|
+
logger?: Logger;
|
|
45
|
+
antRegistryId?: string;
|
|
46
|
+
hyperbeamUrl?: string;
|
|
47
|
+
onSigningProgress?: (name: keyof UpgradeAntProgressEvent, payload: UpgradeAntProgressEvent[keyof UpgradeAntProgressEvent]) => void;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
forkedProcessId: string;
|
|
50
|
+
reassignedNames: string[];
|
|
51
|
+
failedReassignedNames: string[];
|
|
52
|
+
}>;
|
|
28
53
|
/**
|
|
29
54
|
* Initialize overloads.
|
|
30
55
|
*
|
|
@@ -39,6 +64,8 @@ export declare class AoANTReadable implements AoANTRead {
|
|
|
39
64
|
private strict;
|
|
40
65
|
private hyperbeamUrl;
|
|
41
66
|
private checkHyperBeamPromise;
|
|
67
|
+
private moduleId;
|
|
68
|
+
private moduleIdPromise;
|
|
42
69
|
private logger;
|
|
43
70
|
constructor(config: ANTConfigOptionalStrict);
|
|
44
71
|
/**
|
|
@@ -53,6 +80,63 @@ export declare class AoANTReadable implements AoANTRead {
|
|
|
53
80
|
* Returns the TX ID of the logo set for the ANT.
|
|
54
81
|
*/
|
|
55
82
|
getLogo(): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the module ID of the current ANT process by querying its spawn transaction tags.
|
|
85
|
+
* Results are cached after the first successful fetch.
|
|
86
|
+
*
|
|
87
|
+
* @param graphqlUrl The GraphQL endpoint URL (defaults to Arweave's GraphQL endpoint)
|
|
88
|
+
* @param retries Number of retry attempts (defaults to 3)
|
|
89
|
+
* @returns Promise<string> The module ID used to spawn this ANT process
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const moduleId = await ant.getModuleId();
|
|
93
|
+
* console.log(`ANT was spawned with module: ${moduleId}`);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
getModuleId({ graphqlUrl, retries, }?: {
|
|
97
|
+
graphqlUrl?: string;
|
|
98
|
+
retries?: number;
|
|
99
|
+
}): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Internal method to fetch the module ID from GraphQL.
|
|
102
|
+
*
|
|
103
|
+
* TODO: this could be more like get process headers/metadata and fetch additional details.
|
|
104
|
+
*
|
|
105
|
+
* It seems like module is the only relevant one, but scheduler and authority are also available.
|
|
106
|
+
*/
|
|
107
|
+
private fetchModuleId;
|
|
108
|
+
/**
|
|
109
|
+
* Gets the version string of the current ANT by matching its module ID
|
|
110
|
+
* with versions from the ANT registry.
|
|
111
|
+
*
|
|
112
|
+
* @param antRegistryId The ANT registry process ID (defaults to mainnet registry)
|
|
113
|
+
* @param graphqlUrl The GraphQL endpoint URL for getModuleId (defaults to Arweave's GraphQL endpoint)
|
|
114
|
+
* @param retries Number of retry attempts for getModuleId (defaults to 3)
|
|
115
|
+
* @returns Promise<string> The version string (e.g., "1.0.15") or "unknown" if not found
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const version = await ant.getVersion();
|
|
119
|
+
* console.log(`ANT is running version: ${version}`);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
getVersion({ antRegistryId, graphqlUrl, retries, }?: {
|
|
123
|
+
antRegistryId?: string;
|
|
124
|
+
graphqlUrl?: string;
|
|
125
|
+
retries?: number;
|
|
126
|
+
}): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the current ANT version is the latest according to the ANT registry.
|
|
129
|
+
*
|
|
130
|
+
* @param antRegistryId Optional ANT registry process ID. Defaults to mainnet ANT registry.
|
|
131
|
+
* @param graphqlUrl Optional GraphQL endpoint. Defaults to https://arweave.net/graphql.
|
|
132
|
+
* @param retries Optional number of retries for fetching module ID. Defaults to 3.
|
|
133
|
+
* @returns {Promise<boolean>} True if current ANT version is the latest, false otherwise.
|
|
134
|
+
*/
|
|
135
|
+
isLatestVersion({ antRegistryId, graphqlUrl, retries, }?: {
|
|
136
|
+
antRegistryId?: string;
|
|
137
|
+
graphqlUrl?: string;
|
|
138
|
+
retries?: number;
|
|
139
|
+
}): Promise<boolean>;
|
|
56
140
|
/**
|
|
57
141
|
* @param undername @type {string} The domain name.
|
|
58
142
|
* @returns {Promise<ANTRecord>} The record of the undername domain.
|
|
@@ -373,5 +457,40 @@ export declare class AoANTWriteable extends AoANTReadable implements AoANTWrite
|
|
|
373
457
|
arioProcessId: string;
|
|
374
458
|
notifyOwners?: boolean;
|
|
375
459
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
460
|
+
/**
|
|
461
|
+
* Upgrade this ANT by forking it to the latest version and reassigning names.
|
|
462
|
+
*
|
|
463
|
+
* This is a convenience method that calls the static ANT.upgrade() method
|
|
464
|
+
* using this instance's process ID and signer.
|
|
465
|
+
*
|
|
466
|
+
* TODO: Add version checking by implementing a getVersion API on ANTs to compare
|
|
467
|
+
* current version with latest ANT registry version and skip if already up to date.
|
|
468
|
+
*
|
|
469
|
+
* @param names @type {string[]} The ArNS names to reassign to the upgraded ANT.
|
|
470
|
+
* @param arioProcessId @type {string} The processId of the ARIO contract.
|
|
471
|
+
* @param antRegistryId @type {string} Optional ANT registry ID.
|
|
472
|
+
* @param onSigningProgress Progress callback function.
|
|
473
|
+
* @returns {Promise} The upgrade results.
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* const result = await ant.upgrade({
|
|
477
|
+
* names: ["example", "test"],
|
|
478
|
+
* arioProcessId: ARIO_MAINNET_PROCESS_ID
|
|
479
|
+
* });
|
|
480
|
+
* console.log(`Upgraded to process: ${result.forkedProcessId}`);
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
upgrade({ names, reassignAffiliatedNames, arioProcessId, antRegistryId, onSigningProgress, skipVersionCheck, }: {
|
|
484
|
+
names?: string[];
|
|
485
|
+
arioProcessId?: string;
|
|
486
|
+
antRegistryId?: string;
|
|
487
|
+
skipVersionCheck?: boolean;
|
|
488
|
+
reassignAffiliatedNames?: boolean;
|
|
489
|
+
onSigningProgress?: (name: keyof UpgradeAntProgressEvent, payload: UpgradeAntProgressEvent[keyof UpgradeAntProgressEvent]) => void;
|
|
490
|
+
}): Promise<{
|
|
491
|
+
forkedProcessId: string;
|
|
492
|
+
reassignedNames: string[];
|
|
493
|
+
failedReassignedNames: string[];
|
|
494
|
+
}>;
|
|
376
495
|
}
|
|
377
496
|
export {};
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare const ARIO_DEVNET_PROCESS_ID = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelV
|
|
|
20
20
|
export declare const arioDevnetProcessId = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc";
|
|
21
21
|
export declare const ARIO_TESTNET_PROCESS_ID = "agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA";
|
|
22
22
|
export declare const ARIO_MAINNET_PROCESS_ID = "qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE";
|
|
23
|
+
export declare const ANT_REGISTRY_TESTNET_ID = "RR0vheYqtsKuJCWh6xj0beE35tjaEug5cejMw9n2aa8";
|
|
23
24
|
export declare const ANT_REGISTRY_ID = "i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc";
|
|
24
25
|
export declare const MARIO_PER_ARIO = 1000000;
|
|
25
26
|
/**
|
package/lib/types/types/ant.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
-
import { AoWriteAction, WalletAddress } from './common.js';
|
|
17
|
+
import { AoWriteAction, UpgradeAntProgressEvent, WalletAddress } from './common.js';
|
|
18
18
|
/**
|
|
19
19
|
* example error:
|
|
20
20
|
* {
|
|
@@ -264,6 +264,20 @@ export interface AoANTRead {
|
|
|
264
264
|
}, opts?: AntReadOptions): Promise<number>;
|
|
265
265
|
getBalances(opts?: AntReadOptions): Promise<Record<WalletAddress, number>>;
|
|
266
266
|
getHandlers(): Promise<AoANTHandler[]>;
|
|
267
|
+
getModuleId(opts?: {
|
|
268
|
+
graphqlUrl?: string;
|
|
269
|
+
retries?: number;
|
|
270
|
+
}): Promise<string>;
|
|
271
|
+
getVersion(opts?: {
|
|
272
|
+
antRegistryId?: string;
|
|
273
|
+
graphqlUrl?: string;
|
|
274
|
+
retries?: number;
|
|
275
|
+
}): Promise<string>;
|
|
276
|
+
isLatestVersion(opts?: {
|
|
277
|
+
antRegistryId?: string;
|
|
278
|
+
graphqlUrl?: string;
|
|
279
|
+
retries?: number;
|
|
280
|
+
}): Promise<boolean>;
|
|
267
281
|
}
|
|
268
282
|
export interface AoANTWrite extends AoANTRead {
|
|
269
283
|
transfer: AoWriteAction<{
|
|
@@ -320,6 +334,17 @@ export interface AoANTWrite extends AoANTRead {
|
|
|
320
334
|
arioProcessId: string;
|
|
321
335
|
notifyOwners?: boolean;
|
|
322
336
|
}>;
|
|
337
|
+
upgrade(params: {
|
|
338
|
+
names?: string[];
|
|
339
|
+
reassignAffiliatedNames?: boolean;
|
|
340
|
+
arioProcessId?: string;
|
|
341
|
+
antRegistryId?: string;
|
|
342
|
+
onSigningProgress?: (name: keyof UpgradeAntProgressEvent, payload: UpgradeAntProgressEvent[keyof UpgradeAntProgressEvent]) => void;
|
|
343
|
+
}): Promise<{
|
|
344
|
+
forkedProcessId: string;
|
|
345
|
+
reassignedNames: string[];
|
|
346
|
+
failedReassignedNames: string[];
|
|
347
|
+
}>;
|
|
323
348
|
}
|
|
324
349
|
export type AoANTSetBaseNameRecordParams = {
|
|
325
350
|
transactionId: string;
|
|
@@ -126,6 +126,21 @@ export type SpawnAntProgressEvent = {
|
|
|
126
126
|
owner: WalletAddress;
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
|
+
export type UpgradeAntProgressEvent = SpawnAntProgressEvent & {
|
|
130
|
+
'checking-version': {
|
|
131
|
+
antProcessId: string;
|
|
132
|
+
antRegistryId: string;
|
|
133
|
+
};
|
|
134
|
+
'fetching-affiliated-names': {
|
|
135
|
+
arioProcessId: string;
|
|
136
|
+
antProcessId: string;
|
|
137
|
+
};
|
|
138
|
+
'reassigning-name': {
|
|
139
|
+
name: string;
|
|
140
|
+
arioProcessId: string;
|
|
141
|
+
antProcessId: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
129
144
|
export type BuyArNSNameProgressEvents = SpawnAntProgressEvent & {
|
|
130
145
|
'buying-name': AoBuyRecordParams;
|
|
131
146
|
};
|
package/lib/types/utils/ant.d.ts
CHANGED
|
@@ -24,10 +24,14 @@ import { ANTRecords, AoANTState, HyperBeamANTState, SortedANTRecords } from '../
|
|
|
24
24
|
* @param antRecords - The ANT records to sort.
|
|
25
25
|
*/
|
|
26
26
|
export declare const sortANTRecords: (antRecords: ANTRecords) => SortedANTRecords;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated - this is no longer necessary because HyperBeam now uses the AoANTState type
|
|
29
|
+
*/
|
|
27
30
|
export declare const isHyperBeamANTState: (state: any) => state is HyperBeamANTState;
|
|
28
31
|
/**
|
|
29
32
|
* Convert HyperBeam serialized ANT state to backwards compatible format.
|
|
30
33
|
*
|
|
34
|
+
* @deprecated - this is no longer necessary because HyperBeam now uses the AOANTState type
|
|
31
35
|
* @param state - The HyperBeam serialized ANT state.
|
|
32
36
|
*/
|
|
33
37
|
export declare const convertHyperBeamStateToAoANTState: (initialState: HyperBeamANTState) => AoANTState;
|