@ar.io/sdk 3.18.2 → 3.19.0-alpha.1

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.
@@ -37,7 +37,12 @@ class ANT {
37
37
  * Spawn a new ANT.
38
38
  */
39
39
  static spawn = ao_js_1.spawnANT;
40
- // implementation
40
+ /**
41
+ * Fork an ANT to a new process.
42
+ *
43
+ * @param config
44
+ */
45
+ static fork = ao_js_1.forkANT;
41
46
  static init(config) {
42
47
  if (config !== undefined && 'signer' in config) {
43
48
  return new AoANTWriteable(config);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultANTLogoId = exports.defaultTargetManifestId = void 0;
4
4
  exports.spawnANT = spawnANT;
5
+ exports.forkANT = forkANT;
5
6
  exports.evolveANT = evolveANT;
6
7
  exports.isAoSigner = isAoSigner;
7
8
  exports.createAoSigner = createAoSigner;
@@ -222,7 +223,40 @@ async function spawnANT({ signer, module, ao = (0, aoconnect_1.connect)({
222
223
  }
223
224
  return processId;
224
225
  }
225
- // TODO: add a utility for forking an ANT to the latest module that leverages getState and spawnANT
226
+ async function forkANT({ signer, antProcessId, logger = index_js_1.Logger.default, ao, antRegistryId = constants_js_1.ANT_REGISTRY_ID, onSigningProgress = (name, payload) => {
227
+ logger.debug('Forking ANT', { name, payload });
228
+ }, }) {
229
+ // get the state of the current ANT and use it to spawn a new ANT
230
+ const ant = index_js_1.ANT.init({
231
+ process: new index_js_1.AOProcess({
232
+ processId: antProcessId,
233
+ ao,
234
+ logger,
235
+ }),
236
+ });
237
+ const state = await ant.getState();
238
+ if (state === undefined) {
239
+ throw new Error(`ANT state (${antProcessId}) is undefined and cannot be upgraded`);
240
+ }
241
+ const forkedProcessId = await spawnANT({
242
+ signer,
243
+ antRegistryId,
244
+ logger,
245
+ onSigningProgress,
246
+ state: {
247
+ owner: state.Owner,
248
+ name: state.Name,
249
+ ticker: state.Ticker,
250
+ description: state.Description,
251
+ keywords: state.Keywords,
252
+ controllers: state.Controllers,
253
+ records: state.Records,
254
+ balances: state.Balances,
255
+ logo: state.Logo,
256
+ },
257
+ });
258
+ return forkedProcessId;
259
+ }
226
260
  /**
227
261
  * @deprecated
228
262
  * Direct Evals are not encouraged when dealing with ANTs.
@@ -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.18.2';
20
+ exports.version = '3.19.0-alpha.1';
@@ -17,7 +17,7 @@ import { z } from 'zod';
17
17
  import { AntBalancesSchema, AntControllersSchema, AntInfoSchema, AntRecordSchema, AntRecordsSchema, AntStateSchema, } from '../types/ant.js';
18
18
  import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
19
19
  import { convertHyperBeamStateToAoANTState, isHyperBeamANTState, sortANTRecords, } from '../utils/ant.js';
20
- import { createAoSigner, spawnANT } from '../utils/ao.js';
20
+ import { createAoSigner, forkANT, spawnANT } from '../utils/ao.js';
21
21
  import { parseSchemaResult } from '../utils/schema.js';
22
22
  import { ANTVersions } from './ant-versions.js';
23
23
  import { AOProcess, InvalidContractConfigurationError, Logger, } from './index.js';
@@ -34,7 +34,12 @@ export class ANT {
34
34
  * Spawn a new ANT.
35
35
  */
36
36
  static spawn = spawnANT;
37
- // implementation
37
+ /**
38
+ * Fork an ANT to a new process.
39
+ *
40
+ * @param config
41
+ */
42
+ static fork = forkANT;
38
43
  static init(config) {
39
44
  if (config !== undefined && 'signer' in config) {
40
45
  return new AoANTWriteable(config);
@@ -19,7 +19,7 @@ import { z } from 'zod';
19
19
  import { ANTRegistry } from '../common/ant-registry.js';
20
20
  import { ANTVersions } from '../common/ant-versions.js';
21
21
  import { defaultArweave } from '../common/arweave.js';
22
- import { AOProcess, Logger } from '../common/index.js';
22
+ import { ANT, AOProcess, Logger } from '../common/index.js';
23
23
  import { ANT_LUA_ID, ANT_REGISTRY_ID, AO_AUTHORITY, DEFAULT_SCHEDULER_ID, } from '../constants.js';
24
24
  import { SpawnANTStateSchema } from '../types/ant.js';
25
25
  import { parseSchemaResult } from './schema.js';
@@ -211,7 +211,40 @@ export async function spawnANT({ signer, module, ao = connect({
211
211
  }
212
212
  return processId;
213
213
  }
214
- // TODO: add a utility for forking an ANT to the latest module that leverages getState and spawnANT
214
+ export async function forkANT({ signer, antProcessId, logger = Logger.default, ao, antRegistryId = ANT_REGISTRY_ID, onSigningProgress = (name, payload) => {
215
+ logger.debug('Forking ANT', { name, payload });
216
+ }, }) {
217
+ // get the state of the current ANT and use it to spawn a new ANT
218
+ const ant = ANT.init({
219
+ process: new AOProcess({
220
+ processId: antProcessId,
221
+ ao,
222
+ logger,
223
+ }),
224
+ });
225
+ const state = await ant.getState();
226
+ if (state === undefined) {
227
+ throw new Error(`ANT state (${antProcessId}) is undefined and cannot be upgraded`);
228
+ }
229
+ const forkedProcessId = await spawnANT({
230
+ signer,
231
+ antRegistryId,
232
+ logger,
233
+ onSigningProgress,
234
+ state: {
235
+ owner: state.Owner,
236
+ name: state.Name,
237
+ ticker: state.Ticker,
238
+ description: state.Description,
239
+ keywords: state.Keywords,
240
+ controllers: state.Controllers,
241
+ records: state.Records,
242
+ balances: state.Balances,
243
+ logo: state.Logo,
244
+ },
245
+ });
246
+ return forkedProcessId;
247
+ }
215
248
  /**
216
249
  * @deprecated
217
250
  * Direct Evals are not encouraged when dealing with ANTs.
@@ -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.18.2';
17
+ export const version = '3.19.0-alpha.1';
@@ -1,6 +1,6 @@
1
1
  import { AntReadOptions, AoANTHandler, AoANTInfo, AoANTRead, AoANTRecord, AoANTSetBaseNameRecordParams, AoANTSetUndernameRecordParams, AoANTState, AoANTWrite, SortedANTRecords } from '../types/ant.js';
2
2
  import { AoMessageResult, ProcessConfiguration, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
3
- import { spawnANT } from '../utils/ao.js';
3
+ import { forkANT, spawnANT } from '../utils/ao.js';
4
4
  import { AOProcess } from './index.js';
5
5
  type ANTConfigOptionalStrict = Required<ProcessConfiguration> & {
6
6
  strict?: boolean;
@@ -19,6 +19,17 @@ export declare class ANT {
19
19
  * Spawn a new ANT.
20
20
  */
21
21
  static spawn: typeof spawnANT;
22
+ /**
23
+ * Fork an ANT to a new process.
24
+ *
25
+ * @param config
26
+ */
27
+ static fork: typeof forkANT;
28
+ /**
29
+ * Initialize overloads.
30
+ *
31
+ * @param config
32
+ */
22
33
  static init(config: ANTConfigNoSigner): AoANTRead;
23
34
  static init(config: ANTConfigWithSigner): AoANTWrite;
24
35
  }
@@ -30,6 +30,14 @@ export type SpawnANTParams = {
30
30
  onSigningProgress?: (name: keyof SpawnAntProgressEvent, payload: SpawnAntProgressEvent[keyof SpawnAntProgressEvent]) => void;
31
31
  };
32
32
  export declare function spawnANT({ signer, module, ao, scheduler, state, tags, antRegistryId, logger, authority, onSigningProgress, }: SpawnANTParams): Promise<ProcessId>;
33
+ export declare function forkANT({ signer, antProcessId, logger, ao, antRegistryId, onSigningProgress, }: {
34
+ signer: AoSigner;
35
+ antProcessId: string;
36
+ logger?: Logger;
37
+ ao?: AoClient;
38
+ antRegistryId?: string;
39
+ onSigningProgress?: (name: keyof SpawnAntProgressEvent, payload: SpawnAntProgressEvent[keyof SpawnAntProgressEvent]) => void;
40
+ }): Promise<string>;
33
41
  /**
34
42
  * @deprecated
35
43
  * Direct Evals are not encouraged when dealing with ANTs.
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.18.2-alpha.1";
16
+ export declare const version = "3.18.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.18.2",
3
+ "version": "3.19.0-alpha.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"