@ardrive/turbo-sdk 1.42.0-alpha.12 → 1.42.0-alpha.13

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.
@@ -147,6 +147,37 @@ const utils_js_1 = require("./utils.js");
147
147
  .description('Remove a resolution record (undername) from a Turbo-custodied ANT'), options_js_1.removeArNSRecordOptions).action(async (_commandOptions, command) => {
148
148
  await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSRecord);
149
149
  });
150
+ (0, utils_js_1.applyOptions)(commander_1.program
151
+ .command('add-arns-controller')
152
+ .description('Grant controller rights on a Turbo-custodied ANT'), options_js_1.addArNSControllerOptions).action(async (_commandOptions, command) => {
153
+ await (0, utils_js_1.runCommand)(command, arns_js_1.addArNSController);
154
+ });
155
+ (0, utils_js_1.applyOptions)(commander_1.program
156
+ .command('remove-arns-controller')
157
+ .description('Revoke controller rights on a Turbo-custodied ANT'), options_js_1.removeArNSControllerOptions).action(async (_commandOptions, command) => {
158
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSController);
159
+ });
160
+ (0, utils_js_1.applyOptions)(commander_1.program
161
+ .command('transfer-arns-record')
162
+ .description('Transfer one record (undername) on a Turbo-custodied ANT to another address'), options_js_1.transferArNSRecordOptions).action(async (_commandOptions, command) => {
163
+ await (0, utils_js_1.runCommand)(command, arns_js_1.transferArNSRecord);
164
+ });
165
+ (0, utils_js_1.applyOptions)(commander_1.program
166
+ .command('set-arns-record-metadata')
167
+ .description("Set a record's display name, logo, description, or keywords on a Turbo-custodied ANT"), options_js_1.setArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
168
+ await (0, utils_js_1.runCommand)(command, arns_js_1.setArNSRecordMetadata);
169
+ });
170
+ (0, utils_js_1.applyOptions)(commander_1.program
171
+ .command('remove-arns-record-metadata')
172
+ .description("Clear a record's metadata on a Turbo-custodied ANT"), options_js_1.removeArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
173
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSRecordMetadata);
174
+ });
175
+ (0, utils_js_1.applyOptions)(commander_1.program
176
+ .command('arns-action-price')
177
+ .description('Preview the Turbo Credit price of a non-purchase ArNS action (set-record, remove-record, ' +
178
+ 'set-record-metadata, remove-record-metadata, transfer-record, add-controller, remove-controller, transfer)'), options_js_1.arnsActionPriceOptions).action(async (_commandOptions, command) => {
179
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsActionPrice);
180
+ });
150
181
  (0, utils_js_1.applyOptions)(commander_1.program
151
182
  .command('inspect-data-items')
152
183
  .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), [options_js_1.optionMap.folderPath]).action(async (_commandOptions, command) => {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requiredNameFromOptions = requiredNameFromOptions;
4
4
  exports.positiveIntFromOption = positiveIntFromOption;
5
5
  exports.typeFromOptions = typeFromOptions;
6
+ exports.actionFromOptions = actionFromOptions;
6
7
  exports.paidByFromArNSOptions = paidByFromArNSOptions;
7
8
  exports.arnsPriceParamsFromOptions = arnsPriceParamsFromOptions;
8
9
  exports.arnsPrice = arnsPrice;
@@ -15,6 +16,12 @@ exports.arnsPurchaseStatus = arnsPurchaseStatus;
15
16
  exports.transferArNSAnt = transferArNSAnt;
16
17
  exports.setArNSRecord = setArNSRecord;
17
18
  exports.removeArNSRecord = removeArNSRecord;
19
+ exports.addArNSController = addArNSController;
20
+ exports.removeArNSController = removeArNSController;
21
+ exports.transferArNSRecord = transferArNSRecord;
22
+ exports.setArNSRecordMetadata = setArNSRecordMetadata;
23
+ exports.removeArNSRecordMetadata = removeArNSRecordMetadata;
24
+ exports.arnsActionPrice = arnsActionPrice;
18
25
  /**
19
26
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
20
27
  *
@@ -33,6 +40,7 @@ exports.removeArNSRecord = removeArNSRecord;
33
40
  const bignumber_js_1 = require("bignumber.js");
34
41
  const arnsActions_js_1 = require("../../common/arnsActions.js");
35
42
  const factory_js_1 = require("../../node/factory.js");
43
+ const types_js_1 = require("../../types.js");
36
44
  const errors_js_1 = require("../../utils/errors.js");
37
45
  const constants_js_1 = require("../constants.js");
38
46
  const utils_js_1 = require("../utils.js");
@@ -51,6 +59,13 @@ function ownerFromOptions(options) {
51
59
  }
52
60
  return (0, arnsActions_js_1.solanaOwnerSigner)(options.ownerKey);
53
61
  }
62
+ /** The four ARIO-purchase actions are priced via `arnsPrice`, not this route. */
63
+ const ARNS_PURCHASE_ACTIONS = new Set([
64
+ 'buy-name',
65
+ 'extend-lease',
66
+ 'upgrade-name',
67
+ 'increase-undername-limit',
68
+ ]);
54
69
  function requiredNameFromOptions(options) {
55
70
  if (options.name === undefined || options.name.length === 0) {
56
71
  throw new Error('Must provide an ArNS --name');
@@ -73,6 +88,25 @@ function typeFromOptions(value) {
73
88
  }
74
89
  return value;
75
90
  }
91
+ /** Parses `--action` for `arns-action-price`, rejecting the four purchase actions. */
92
+ function actionFromOptions(options) {
93
+ const { action } = options;
94
+ if (action === undefined || action.length === 0) {
95
+ throw new Error(`Must provide --action. One of: ${types_js_1.arNSActions.join(', ')}`);
96
+ }
97
+ if (!types_js_1.arNSActions.includes(action)) {
98
+ throw new Error(`Invalid --action '${action}'. One of: ${types_js_1.arNSActions.join(', ')}`);
99
+ }
100
+ if (ARNS_PURCHASE_ACTIONS.has(action)) {
101
+ throw new Error(`'${action}' is priced via \`turbo arns-price\`, not \`arns-action-price\` — ` +
102
+ 'it spends ARIO, not just the flat credits margin this route quotes.');
103
+ }
104
+ return action;
105
+ }
106
+ /** `null` clears the field (Set-Record-Metadata's tri-state), `undefined` leaves it unchanged. */
107
+ function metadataFieldFromOptions(value, clear) {
108
+ return clear ? null : value;
109
+ }
76
110
  function paidByFromArNSOptions(paidBy) {
77
111
  return paidBy !== undefined && paidBy.length > 0 ? paidBy : undefined;
78
112
  }
@@ -315,3 +349,87 @@ async function removeArNSRecord(options, turbo) {
315
349
  });
316
350
  console.log(JSON.stringify({ message: 'ArNS record removed!', ...result }, null, 2));
317
351
  }
352
+ async function addArNSController(options, turbo) {
353
+ if (options.antId === undefined) {
354
+ throw new Error('Must provide an --ant-id to add a controller to');
355
+ }
356
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
357
+ const result = await client.addArNSController({
358
+ antId: options.antId,
359
+ owner: ownerFromOptions(options),
360
+ target: options.target,
361
+ });
362
+ console.log(JSON.stringify({ message: 'ArNS controller added!', ...result }, null, 2));
363
+ }
364
+ async function removeArNSController(options, turbo) {
365
+ if (options.antId === undefined) {
366
+ throw new Error('Must provide an --ant-id to remove a controller from');
367
+ }
368
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
369
+ const result = await client.removeArNSController({
370
+ antId: options.antId,
371
+ owner: ownerFromOptions(options),
372
+ target: options.target,
373
+ });
374
+ console.log(JSON.stringify({ message: 'ArNS controller removed!', ...result }, null, 2));
375
+ }
376
+ async function transferArNSRecord(options, turbo) {
377
+ if (options.antId === undefined) {
378
+ throw new Error('Must provide an --ant-id whose record to transfer');
379
+ }
380
+ if (options.undername === undefined || options.undername.length === 0) {
381
+ throw new Error('Must provide an --undername to transfer');
382
+ }
383
+ if (options.target === undefined) {
384
+ throw new Error('Must provide a --target address to transfer the record to');
385
+ }
386
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
387
+ const result = await client.transferArNSRecord({
388
+ antId: options.antId,
389
+ owner: ownerFromOptions(options),
390
+ undername: options.undername,
391
+ target: options.target,
392
+ });
393
+ console.log(JSON.stringify({ message: 'ArNS record transferred!', ...result }, null, 2));
394
+ }
395
+ async function setArNSRecordMetadata(options, turbo) {
396
+ if (options.antId === undefined) {
397
+ throw new Error('Must provide an --ant-id to set record metadata on');
398
+ }
399
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
400
+ const result = await client.setArNSRecordMetadata({
401
+ antId: options.antId,
402
+ owner: ownerFromOptions(options),
403
+ undername: options.undername ?? '@',
404
+ displayName: metadataFieldFromOptions(options.displayName, options.clearDisplayName),
405
+ recordLogo: metadataFieldFromOptions(options.recordLogo, options.clearRecordLogo),
406
+ recordDescription: metadataFieldFromOptions(options.recordDescription, options.clearRecordDescription),
407
+ recordKeywords: metadataFieldFromOptions(options.recordKeywords, options.clearRecordKeywords),
408
+ });
409
+ console.log(JSON.stringify({ message: 'ArNS record metadata set!', ...result }, null, 2));
410
+ }
411
+ async function removeArNSRecordMetadata(options, turbo) {
412
+ if (options.antId === undefined) {
413
+ throw new Error('Must provide an --ant-id to remove record metadata from');
414
+ }
415
+ if (options.undername === undefined || options.undername.length === 0) {
416
+ throw new Error('Must provide an --undername');
417
+ }
418
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
419
+ const result = await client.removeArNSRecordMetadata({
420
+ antId: options.antId,
421
+ owner: ownerFromOptions(options),
422
+ undername: options.undername,
423
+ });
424
+ console.log(JSON.stringify({ message: 'ArNS record metadata removed!', ...result }, null, 2));
425
+ }
426
+ /**
427
+ * Preview what one of the eight non-purchase actions will debit, without
428
+ * creating it.
429
+ */
430
+ async function arnsActionPrice(options, turbo) {
431
+ const action = actionFromOptions(options);
432
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
433
+ const { wincQty } = await client.getArNSActionPrice(action);
434
+ console.log(JSON.stringify({ action, wincQty, credits: creditsFromWinc(wincQty) }, null, 2));
435
+ }
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.removeArNSRecordOptions = exports.setArNSRecordOptions = exports.transferArNSAntOptions = exports.arnsPurchaseStatusOptions = exports.upgradeArNSNameOptions = exports.increaseArNSUndernamesOptions = exports.extendArNSLeaseOptions = exports.buyArNSNameOptions = exports.arnsFiatQuoteOptions = exports.arnsPriceOptions = exports.listSharesOptions = exports.revokeCreditsOptions = exports.shareCreditsOptions = exports.uploadFileOptions = exports.uploadFolderOptions = exports.uploadOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
18
+ exports.arnsActionPriceOptions = exports.removeArNSRecordMetadataOptions = exports.setArNSRecordMetadataOptions = exports.transferArNSRecordOptions = exports.removeArNSControllerOptions = exports.addArNSControllerOptions = exports.removeArNSRecordOptions = exports.setArNSRecordOptions = exports.transferArNSAntOptions = exports.arnsPurchaseStatusOptions = exports.upgradeArNSNameOptions = exports.increaseArNSUndernamesOptions = exports.extendArNSLeaseOptions = exports.buyArNSNameOptions = exports.arnsFiatQuoteOptions = exports.arnsPriceOptions = exports.listSharesOptions = exports.revokeCreditsOptions = exports.shareCreditsOptions = exports.uploadFileOptions = exports.uploadFolderOptions = exports.uploadOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
19
19
  exports.optionMap = {
20
20
  token: {
21
21
  alias: '-t, --token <type>',
@@ -234,6 +234,48 @@ exports.optionMap = {
234
234
  alias: '--ttl-seconds <ttlSeconds>',
235
235
  description: 'TTL in seconds for the ArNS record',
236
236
  },
237
+ arnsDisplayName: {
238
+ alias: '--display-name <displayName>',
239
+ description: 'Display name for the record (Set-Record-Metadata)',
240
+ },
241
+ arnsClearDisplayName: {
242
+ alias: '--clear-display-name',
243
+ description: 'Clear the record display name (Set-Record-Metadata)',
244
+ default: false,
245
+ },
246
+ arnsRecordLogo: {
247
+ alias: '--record-logo <transactionId>',
248
+ description: 'Arweave transaction ID for the record logo (Set-Record-Metadata)',
249
+ },
250
+ arnsClearRecordLogo: {
251
+ alias: '--clear-record-logo',
252
+ description: 'Clear the record logo (Set-Record-Metadata)',
253
+ default: false,
254
+ },
255
+ arnsRecordDescription: {
256
+ alias: '--record-description <description>',
257
+ description: 'Description for the record (Set-Record-Metadata)',
258
+ },
259
+ arnsClearRecordDescription: {
260
+ alias: '--clear-record-description',
261
+ description: 'Clear the record description (Set-Record-Metadata)',
262
+ default: false,
263
+ },
264
+ arnsRecordKeywords: {
265
+ alias: '--record-keywords <keywords...>',
266
+ description: 'Keywords for the record (Set-Record-Metadata)',
267
+ type: 'array',
268
+ },
269
+ arnsClearRecordKeywords: {
270
+ alias: '--clear-record-keywords',
271
+ description: 'Clear the record keywords (Set-Record-Metadata)',
272
+ default: false,
273
+ },
274
+ arnsAction: {
275
+ alias: '--action <action>',
276
+ description: 'ArNS action to price: set-record, remove-record, set-record-metadata, ' +
277
+ 'remove-record-metadata, transfer-record, add-controller, remove-controller, or transfer',
278
+ },
237
279
  // ---- Payment history ----
238
280
  limit: {
239
281
  alias: '--limit <limit>',
@@ -365,3 +407,38 @@ exports.removeArNSRecordOptions = [
365
407
  exports.optionMap.arnsAntId,
366
408
  exports.optionMap.arnsUndername,
367
409
  ];
410
+ exports.addArNSControllerOptions = [
411
+ ...exports.walletOptions,
412
+ exports.optionMap.arnsOwnerKey,
413
+ exports.optionMap.arnsAntId,
414
+ exports.optionMap.arnsTarget,
415
+ ];
416
+ exports.removeArNSControllerOptions = exports.addArNSControllerOptions;
417
+ exports.transferArNSRecordOptions = [
418
+ ...exports.walletOptions,
419
+ exports.optionMap.arnsOwnerKey,
420
+ exports.optionMap.arnsAntId,
421
+ exports.optionMap.arnsUndername,
422
+ exports.optionMap.arnsTarget,
423
+ ];
424
+ exports.setArNSRecordMetadataOptions = [
425
+ ...exports.walletOptions,
426
+ exports.optionMap.arnsOwnerKey,
427
+ exports.optionMap.arnsAntId,
428
+ exports.optionMap.arnsUndername,
429
+ exports.optionMap.arnsDisplayName,
430
+ exports.optionMap.arnsClearDisplayName,
431
+ exports.optionMap.arnsRecordLogo,
432
+ exports.optionMap.arnsClearRecordLogo,
433
+ exports.optionMap.arnsRecordDescription,
434
+ exports.optionMap.arnsClearRecordDescription,
435
+ exports.optionMap.arnsRecordKeywords,
436
+ exports.optionMap.arnsClearRecordKeywords,
437
+ ];
438
+ exports.removeArNSRecordMetadataOptions = [
439
+ ...exports.walletOptions,
440
+ exports.optionMap.arnsOwnerKey,
441
+ exports.optionMap.arnsAntId,
442
+ exports.optionMap.arnsUndername,
443
+ ];
444
+ exports.arnsActionPriceOptions = [exports.optionMap.arnsAction];
@@ -140,6 +140,24 @@ class TurboUnauthenticatedPaymentService {
140
140
  wincTotal: price.wincTotalWithAntSpawn ?? price.winc,
141
141
  };
142
142
  }
143
+ /**
144
+ * Preview the flat credits margin one of the eight non-purchase actions
145
+ * (everything except Buy-Name/Extend-Lease/Upgrade-Name/
146
+ * Increase-Undername-Limit) will debit, without creating it. Those four
147
+ * purchase actions are priced by `getArNSPriceForName` instead — their
148
+ * cost is dominated by the ARIO purchase, not this margin, so this route
149
+ * rejects them.
150
+ *
151
+ * No signature required: this mirrors `getArNSPriceForName`'s read-only,
152
+ * unauthenticated shape rather than `getArNSActionStatus`'s (which happens
153
+ * to live on the authenticated client today despite needing no signature
154
+ * either).
155
+ */
156
+ async getArNSActionPrice(action) {
157
+ return this.httpService.get({
158
+ endpoint: `/arns/actions/${action}/price`,
159
+ });
160
+ }
143
161
  /**
144
162
  * Fail fast (client-side) on malformed ArNS requests so JS callers that bypass
145
163
  * the compile-time intent unions get a clear `ProvidedInputError` instead of an
@@ -63,6 +63,14 @@ class TurboUnauthenticatedClient {
63
63
  getArNSPriceForName(params) {
64
64
  return this.paymentService.getArNSPriceForName(params);
65
65
  }
66
+ /**
67
+ * Previews what one of the eight non-purchase ArNS actions will debit,
68
+ * without creating it. Use {@link getArNSPriceForName} for the four
69
+ * ARIO-purchase actions instead.
70
+ */
71
+ getArNSActionPrice(action) {
72
+ return this.paymentService.getArNSActionPrice(action);
73
+ }
66
74
  /**
67
75
  * Returns the status of an ArNS purchase by its nonce.
68
76
  */
package/lib/cjs/types.js CHANGED
@@ -115,7 +115,7 @@ exports.arNSPurchaseIntents = [
115
115
  ];
116
116
  // ===== ArNS actions (sponsored — the current bundler surface) =====
117
117
  /**
118
- * The nine sponsored ArNS actions.
118
+ * The twelve sponsored ArNS actions.
119
119
  *
120
120
  * Sponsorship covers these twelve and NOTHING else. Everything else in the
121
121
  * ArNS, ANT and core programs stays on the direct-signer path and costs the
@@ -20,7 +20,7 @@ import { DataItem } from '@dha-team/arbundles';
20
20
  import { program } from 'commander';
21
21
  import { readFileSync, readdirSync } from 'fs';
22
22
  import { version } from '../version.js';
23
- import { arnsFiatQuote, arnsPrice, arnsPurchaseStatus, buyArNSName, extendArNSLease, increaseArNSUndernames, removeArNSRecord, setArNSRecord, transferArNSAnt, upgradeArNSName, } from './commands/arns.js';
23
+ import { addArNSController, arnsActionPrice, arnsFiatQuote, arnsPrice, arnsPurchaseStatus, buyArNSName, extendArNSLease, increaseArNSUndernames, removeArNSController, removeArNSRecord, removeArNSRecordMetadata, setArNSRecord, setArNSRecordMetadata, transferArNSAnt, transferArNSRecord, upgradeArNSName, } from './commands/arns.js';
24
24
  import { fiatEstimate } from './commands/fiatEstimate.js';
25
25
  import { balance, cryptoFund, freeStatus, paymentHistory, price, topUp, uploadFile, uploadFolder, } from './commands/index.js';
26
26
  import { listShares } from './commands/listShares.js';
@@ -28,7 +28,7 @@ import { revokeCredits } from './commands/revokeCredits.js';
28
28
  import { shareCredits } from './commands/shareCredits.js';
29
29
  import { tokenPrice } from './commands/tokenPrice.js';
30
30
  import { x402UploadUnsignedFile } from './commands/x402UploadUnsignedData.js';
31
- import { arnsFiatQuoteOptions, arnsPriceOptions, arnsPurchaseStatusOptions, buyArNSNameOptions, extendArNSLeaseOptions, globalOptions, increaseArNSUndernamesOptions, listSharesOptions, optionMap, removeArNSRecordOptions, revokeCreditsOptions, setArNSRecordOptions, shareCreditsOptions, transferArNSAntOptions, upgradeArNSNameOptions, uploadFileOptions, uploadFolderOptions, walletOptions, } from './options.js';
31
+ import { addArNSControllerOptions, arnsActionPriceOptions, arnsFiatQuoteOptions, arnsPriceOptions, arnsPurchaseStatusOptions, buyArNSNameOptions, extendArNSLeaseOptions, globalOptions, increaseArNSUndernamesOptions, listSharesOptions, optionMap, removeArNSControllerOptions, removeArNSRecordMetadataOptions, removeArNSRecordOptions, revokeCreditsOptions, setArNSRecordMetadataOptions, setArNSRecordOptions, shareCreditsOptions, transferArNSAntOptions, transferArNSRecordOptions, upgradeArNSNameOptions, uploadFileOptions, uploadFolderOptions, walletOptions, } from './options.js';
32
32
  import { applyOptions, runCommand } from './utils.js';
33
33
  applyOptions(program
34
34
  .name('turbo')
@@ -145,6 +145,37 @@ applyOptions(program
145
145
  .description('Remove a resolution record (undername) from a Turbo-custodied ANT'), removeArNSRecordOptions).action(async (_commandOptions, command) => {
146
146
  await runCommand(command, removeArNSRecord);
147
147
  });
148
+ applyOptions(program
149
+ .command('add-arns-controller')
150
+ .description('Grant controller rights on a Turbo-custodied ANT'), addArNSControllerOptions).action(async (_commandOptions, command) => {
151
+ await runCommand(command, addArNSController);
152
+ });
153
+ applyOptions(program
154
+ .command('remove-arns-controller')
155
+ .description('Revoke controller rights on a Turbo-custodied ANT'), removeArNSControllerOptions).action(async (_commandOptions, command) => {
156
+ await runCommand(command, removeArNSController);
157
+ });
158
+ applyOptions(program
159
+ .command('transfer-arns-record')
160
+ .description('Transfer one record (undername) on a Turbo-custodied ANT to another address'), transferArNSRecordOptions).action(async (_commandOptions, command) => {
161
+ await runCommand(command, transferArNSRecord);
162
+ });
163
+ applyOptions(program
164
+ .command('set-arns-record-metadata')
165
+ .description("Set a record's display name, logo, description, or keywords on a Turbo-custodied ANT"), setArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
166
+ await runCommand(command, setArNSRecordMetadata);
167
+ });
168
+ applyOptions(program
169
+ .command('remove-arns-record-metadata')
170
+ .description("Clear a record's metadata on a Turbo-custodied ANT"), removeArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
171
+ await runCommand(command, removeArNSRecordMetadata);
172
+ });
173
+ applyOptions(program
174
+ .command('arns-action-price')
175
+ .description('Preview the Turbo Credit price of a non-purchase ArNS action (set-record, remove-record, ' +
176
+ 'set-record-metadata, remove-record-metadata, transfer-record, add-controller, remove-controller, transfer)'), arnsActionPriceOptions).action(async (_commandOptions, command) => {
177
+ await runCommand(command, arnsActionPrice);
178
+ });
148
179
  applyOptions(program
149
180
  .command('inspect-data-items')
150
181
  .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), [optionMap.folderPath]).action(async (_commandOptions, command) => {
@@ -16,6 +16,7 @@
16
16
  import { BigNumber } from 'bignumber.js';
17
17
  import { solanaOwnerSigner } from '../../common/arnsActions.js';
18
18
  import { TurboFactory } from '../../node/factory.js';
19
+ import { arNSActions, } from '../../types.js';
19
20
  import { FiatPaymentsDisabledError, InsufficientCreditsError, } from '../../utils/errors.js';
20
21
  import { wincPerCredit } from '../constants.js';
21
22
  import { configFromOptions, turboFromOptions } from '../utils.js';
@@ -34,6 +35,13 @@ function ownerFromOptions(options) {
34
35
  }
35
36
  return solanaOwnerSigner(options.ownerKey);
36
37
  }
38
+ /** The four ARIO-purchase actions are priced via `arnsPrice`, not this route. */
39
+ const ARNS_PURCHASE_ACTIONS = new Set([
40
+ 'buy-name',
41
+ 'extend-lease',
42
+ 'upgrade-name',
43
+ 'increase-undername-limit',
44
+ ]);
37
45
  export function requiredNameFromOptions(options) {
38
46
  if (options.name === undefined || options.name.length === 0) {
39
47
  throw new Error('Must provide an ArNS --name');
@@ -56,6 +64,25 @@ export function typeFromOptions(value) {
56
64
  }
57
65
  return value;
58
66
  }
67
+ /** Parses `--action` for `arns-action-price`, rejecting the four purchase actions. */
68
+ export function actionFromOptions(options) {
69
+ const { action } = options;
70
+ if (action === undefined || action.length === 0) {
71
+ throw new Error(`Must provide --action. One of: ${arNSActions.join(', ')}`);
72
+ }
73
+ if (!arNSActions.includes(action)) {
74
+ throw new Error(`Invalid --action '${action}'. One of: ${arNSActions.join(', ')}`);
75
+ }
76
+ if (ARNS_PURCHASE_ACTIONS.has(action)) {
77
+ throw new Error(`'${action}' is priced via \`turbo arns-price\`, not \`arns-action-price\` — ` +
78
+ 'it spends ARIO, not just the flat credits margin this route quotes.');
79
+ }
80
+ return action;
81
+ }
82
+ /** `null` clears the field (Set-Record-Metadata's tri-state), `undefined` leaves it unchanged. */
83
+ function metadataFieldFromOptions(value, clear) {
84
+ return clear ? null : value;
85
+ }
59
86
  export function paidByFromArNSOptions(paidBy) {
60
87
  return paidBy !== undefined && paidBy.length > 0 ? paidBy : undefined;
61
88
  }
@@ -298,3 +325,87 @@ export async function removeArNSRecord(options, turbo) {
298
325
  });
299
326
  console.log(JSON.stringify({ message: 'ArNS record removed!', ...result }, null, 2));
300
327
  }
328
+ export async function addArNSController(options, turbo) {
329
+ if (options.antId === undefined) {
330
+ throw new Error('Must provide an --ant-id to add a controller to');
331
+ }
332
+ const client = turbo ?? (await turboFromOptions(options));
333
+ const result = await client.addArNSController({
334
+ antId: options.antId,
335
+ owner: ownerFromOptions(options),
336
+ target: options.target,
337
+ });
338
+ console.log(JSON.stringify({ message: 'ArNS controller added!', ...result }, null, 2));
339
+ }
340
+ export async function removeArNSController(options, turbo) {
341
+ if (options.antId === undefined) {
342
+ throw new Error('Must provide an --ant-id to remove a controller from');
343
+ }
344
+ const client = turbo ?? (await turboFromOptions(options));
345
+ const result = await client.removeArNSController({
346
+ antId: options.antId,
347
+ owner: ownerFromOptions(options),
348
+ target: options.target,
349
+ });
350
+ console.log(JSON.stringify({ message: 'ArNS controller removed!', ...result }, null, 2));
351
+ }
352
+ export async function transferArNSRecord(options, turbo) {
353
+ if (options.antId === undefined) {
354
+ throw new Error('Must provide an --ant-id whose record to transfer');
355
+ }
356
+ if (options.undername === undefined || options.undername.length === 0) {
357
+ throw new Error('Must provide an --undername to transfer');
358
+ }
359
+ if (options.target === undefined) {
360
+ throw new Error('Must provide a --target address to transfer the record to');
361
+ }
362
+ const client = turbo ?? (await turboFromOptions(options));
363
+ const result = await client.transferArNSRecord({
364
+ antId: options.antId,
365
+ owner: ownerFromOptions(options),
366
+ undername: options.undername,
367
+ target: options.target,
368
+ });
369
+ console.log(JSON.stringify({ message: 'ArNS record transferred!', ...result }, null, 2));
370
+ }
371
+ export async function setArNSRecordMetadata(options, turbo) {
372
+ if (options.antId === undefined) {
373
+ throw new Error('Must provide an --ant-id to set record metadata on');
374
+ }
375
+ const client = turbo ?? (await turboFromOptions(options));
376
+ const result = await client.setArNSRecordMetadata({
377
+ antId: options.antId,
378
+ owner: ownerFromOptions(options),
379
+ undername: options.undername ?? '@',
380
+ displayName: metadataFieldFromOptions(options.displayName, options.clearDisplayName),
381
+ recordLogo: metadataFieldFromOptions(options.recordLogo, options.clearRecordLogo),
382
+ recordDescription: metadataFieldFromOptions(options.recordDescription, options.clearRecordDescription),
383
+ recordKeywords: metadataFieldFromOptions(options.recordKeywords, options.clearRecordKeywords),
384
+ });
385
+ console.log(JSON.stringify({ message: 'ArNS record metadata set!', ...result }, null, 2));
386
+ }
387
+ export async function removeArNSRecordMetadata(options, turbo) {
388
+ if (options.antId === undefined) {
389
+ throw new Error('Must provide an --ant-id to remove record metadata from');
390
+ }
391
+ if (options.undername === undefined || options.undername.length === 0) {
392
+ throw new Error('Must provide an --undername');
393
+ }
394
+ const client = turbo ?? (await turboFromOptions(options));
395
+ const result = await client.removeArNSRecordMetadata({
396
+ antId: options.antId,
397
+ owner: ownerFromOptions(options),
398
+ undername: options.undername,
399
+ });
400
+ console.log(JSON.stringify({ message: 'ArNS record metadata removed!', ...result }, null, 2));
401
+ }
402
+ /**
403
+ * Preview what one of the eight non-purchase actions will debit, without
404
+ * creating it.
405
+ */
406
+ export async function arnsActionPrice(options, turbo) {
407
+ const action = actionFromOptions(options);
408
+ const client = turbo ?? TurboFactory.unauthenticated(configFromOptions(options));
409
+ const { wincQty } = await client.getArNSActionPrice(action);
410
+ console.log(JSON.stringify({ action, wincQty, credits: creditsFromWinc(wincQty) }, null, 2));
411
+ }
@@ -231,6 +231,48 @@ export const optionMap = {
231
231
  alias: '--ttl-seconds <ttlSeconds>',
232
232
  description: 'TTL in seconds for the ArNS record',
233
233
  },
234
+ arnsDisplayName: {
235
+ alias: '--display-name <displayName>',
236
+ description: 'Display name for the record (Set-Record-Metadata)',
237
+ },
238
+ arnsClearDisplayName: {
239
+ alias: '--clear-display-name',
240
+ description: 'Clear the record display name (Set-Record-Metadata)',
241
+ default: false,
242
+ },
243
+ arnsRecordLogo: {
244
+ alias: '--record-logo <transactionId>',
245
+ description: 'Arweave transaction ID for the record logo (Set-Record-Metadata)',
246
+ },
247
+ arnsClearRecordLogo: {
248
+ alias: '--clear-record-logo',
249
+ description: 'Clear the record logo (Set-Record-Metadata)',
250
+ default: false,
251
+ },
252
+ arnsRecordDescription: {
253
+ alias: '--record-description <description>',
254
+ description: 'Description for the record (Set-Record-Metadata)',
255
+ },
256
+ arnsClearRecordDescription: {
257
+ alias: '--clear-record-description',
258
+ description: 'Clear the record description (Set-Record-Metadata)',
259
+ default: false,
260
+ },
261
+ arnsRecordKeywords: {
262
+ alias: '--record-keywords <keywords...>',
263
+ description: 'Keywords for the record (Set-Record-Metadata)',
264
+ type: 'array',
265
+ },
266
+ arnsClearRecordKeywords: {
267
+ alias: '--clear-record-keywords',
268
+ description: 'Clear the record keywords (Set-Record-Metadata)',
269
+ default: false,
270
+ },
271
+ arnsAction: {
272
+ alias: '--action <action>',
273
+ description: 'ArNS action to price: set-record, remove-record, set-record-metadata, ' +
274
+ 'remove-record-metadata, transfer-record, add-controller, remove-controller, or transfer',
275
+ },
234
276
  // ---- Payment history ----
235
277
  limit: {
236
278
  alias: '--limit <limit>',
@@ -362,3 +404,38 @@ export const removeArNSRecordOptions = [
362
404
  optionMap.arnsAntId,
363
405
  optionMap.arnsUndername,
364
406
  ];
407
+ export const addArNSControllerOptions = [
408
+ ...walletOptions,
409
+ optionMap.arnsOwnerKey,
410
+ optionMap.arnsAntId,
411
+ optionMap.arnsTarget,
412
+ ];
413
+ export const removeArNSControllerOptions = addArNSControllerOptions;
414
+ export const transferArNSRecordOptions = [
415
+ ...walletOptions,
416
+ optionMap.arnsOwnerKey,
417
+ optionMap.arnsAntId,
418
+ optionMap.arnsUndername,
419
+ optionMap.arnsTarget,
420
+ ];
421
+ export const setArNSRecordMetadataOptions = [
422
+ ...walletOptions,
423
+ optionMap.arnsOwnerKey,
424
+ optionMap.arnsAntId,
425
+ optionMap.arnsUndername,
426
+ optionMap.arnsDisplayName,
427
+ optionMap.arnsClearDisplayName,
428
+ optionMap.arnsRecordLogo,
429
+ optionMap.arnsClearRecordLogo,
430
+ optionMap.arnsRecordDescription,
431
+ optionMap.arnsClearRecordDescription,
432
+ optionMap.arnsRecordKeywords,
433
+ optionMap.arnsClearRecordKeywords,
434
+ ];
435
+ export const removeArNSRecordMetadataOptions = [
436
+ ...walletOptions,
437
+ optionMap.arnsOwnerKey,
438
+ optionMap.arnsAntId,
439
+ optionMap.arnsUndername,
440
+ ];
441
+ export const arnsActionPriceOptions = [optionMap.arnsAction];
@@ -137,6 +137,24 @@ export class TurboUnauthenticatedPaymentService {
137
137
  wincTotal: price.wincTotalWithAntSpawn ?? price.winc,
138
138
  };
139
139
  }
140
+ /**
141
+ * Preview the flat credits margin one of the eight non-purchase actions
142
+ * (everything except Buy-Name/Extend-Lease/Upgrade-Name/
143
+ * Increase-Undername-Limit) will debit, without creating it. Those four
144
+ * purchase actions are priced by `getArNSPriceForName` instead — their
145
+ * cost is dominated by the ARIO purchase, not this margin, so this route
146
+ * rejects them.
147
+ *
148
+ * No signature required: this mirrors `getArNSPriceForName`'s read-only,
149
+ * unauthenticated shape rather than `getArNSActionStatus`'s (which happens
150
+ * to live on the authenticated client today despite needing no signature
151
+ * either).
152
+ */
153
+ async getArNSActionPrice(action) {
154
+ return this.httpService.get({
155
+ endpoint: `/arns/actions/${action}/price`,
156
+ });
157
+ }
140
158
  /**
141
159
  * Fail fast (client-side) on malformed ArNS requests so JS callers that bypass
142
160
  * the compile-time intent unions get a clear `ProvidedInputError` instead of an
@@ -60,6 +60,14 @@ export class TurboUnauthenticatedClient {
60
60
  getArNSPriceForName(params) {
61
61
  return this.paymentService.getArNSPriceForName(params);
62
62
  }
63
+ /**
64
+ * Previews what one of the eight non-purchase ArNS actions will debit,
65
+ * without creating it. Use {@link getArNSPriceForName} for the four
66
+ * ARIO-purchase actions instead.
67
+ */
68
+ getArNSActionPrice(action) {
69
+ return this.paymentService.getArNSActionPrice(action);
70
+ }
63
71
  /**
64
72
  * Returns the status of an ArNS purchase by its nonce.
65
73
  */