@ar.io/sdk 3.1.0-alpha.1 → 3.1.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/bundles/web.bundle.min.js +68 -68
  2. package/lib/cjs/cli/cli.js +19 -69
  3. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +167 -0
  4. package/lib/cjs/cli/commands/gatewayWriteCommands.js +8 -4
  5. package/lib/cjs/cli/commands/readCommands.js +1 -22
  6. package/lib/cjs/cli/commands/transfer.js +5 -1
  7. package/lib/cjs/cli/options.js +8 -7
  8. package/lib/cjs/cli/utils.js +39 -7
  9. package/lib/cjs/common/contracts/ao-process.js +34 -16
  10. package/lib/cjs/common/io.js +76 -116
  11. package/lib/cjs/utils/arweave.js +22 -13
  12. package/lib/cjs/version.js +1 -1
  13. package/lib/esm/cli/cli.js +21 -71
  14. package/lib/esm/cli/commands/arnsPurchaseCommands.js +159 -0
  15. package/lib/esm/cli/commands/gatewayWriteCommands.js +6 -2
  16. package/lib/esm/cli/commands/readCommands.js +2 -23
  17. package/lib/esm/cli/commands/transfer.js +6 -2
  18. package/lib/esm/cli/options.js +7 -6
  19. package/lib/esm/cli/utils.js +34 -5
  20. package/lib/esm/common/contracts/ao-process.js +34 -16
  21. package/lib/esm/common/io.js +77 -117
  22. package/lib/esm/utils/arweave.js +21 -11
  23. package/lib/esm/version.js +1 -1
  24. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +22 -0
  25. package/lib/types/cli/options.d.ts +1 -9
  26. package/lib/types/cli/types.d.ts +3 -5
  27. package/lib/types/cli/utils.d.ts +16 -3
  28. package/lib/types/common/contracts/ao-process.d.ts +1 -0
  29. package/lib/types/common/io.d.ts +14 -43
  30. package/lib/types/types/common.d.ts +1 -0
  31. package/lib/types/types/io.d.ts +15 -9
  32. package/lib/types/utils/arweave.d.ts +6 -18
  33. package/lib/types/version.d.ts +1 -1
  34. package/package.json +2 -2
@@ -21,6 +21,7 @@ const commander_1 = require("commander");
21
21
  const index_js_1 = require("../node/index.js");
22
22
  const token_js_1 = require("../types/token.js");
23
23
  const version_js_1 = require("../version.js");
24
+ const arnsPurchaseCommands_js_1 = require("./commands/arnsPurchaseCommands.js");
24
25
  const gatewayWriteCommands_js_1 = require("./commands/gatewayWriteCommands.js");
25
26
  const readCommands_js_1 = require("./commands/readCommands.js");
26
27
  const transfer_js_1 = require("./commands/transfer.js");
@@ -54,7 +55,7 @@ const utils_js_1 = require("./utils.js");
54
55
  (0, utils_js_1.makeCommand)({
55
56
  name: 'get-gateway',
56
57
  description: 'Get the gateway of an address',
57
- options: options_js_1.addressOptions,
58
+ options: [options_js_1.optionMap.address],
58
59
  action: readCommands_js_1.getGateway,
59
60
  });
60
61
  (0, utils_js_1.makeCommand)({
@@ -72,7 +73,7 @@ const utils_js_1 = require("./utils.js");
72
73
  (0, utils_js_1.makeCommand)({
73
74
  name: 'get-delegations',
74
75
  description: 'Get all stake delegated to gateways from this address',
75
- options: options_js_1.addressOptions,
76
+ options: [options_js_1.optionMap.address],
76
77
  action: readCommands_js_1.getDelegations,
77
78
  });
78
79
  (0, utils_js_1.makeCommand)({
@@ -84,7 +85,7 @@ const utils_js_1 = require("./utils.js");
84
85
  (0, utils_js_1.makeCommand)({
85
86
  name: 'get-arns-record',
86
87
  description: 'Get an ArNS record by name',
87
- options: options_js_1.nameOptions,
88
+ options: [options_js_1.optionMap.name],
88
89
  action: readCommands_js_1.getArNSRecord,
89
90
  });
90
91
  (0, utils_js_1.makeCommand)({
@@ -96,7 +97,7 @@ const utils_js_1 = require("./utils.js");
96
97
  (0, utils_js_1.makeCommand)({
97
98
  name: 'get-arns-reserved-name',
98
99
  description: 'Get a reserved ArNS name',
99
- options: options_js_1.nameOptions,
100
+ options: [options_js_1.optionMap.name],
100
101
  action: readCommands_js_1.getArNSReservedName,
101
102
  });
102
103
  (0, utils_js_1.makeCommand)({
@@ -108,7 +109,7 @@ const utils_js_1 = require("./utils.js");
108
109
  (0, utils_js_1.makeCommand)({
109
110
  name: 'get-arns-returned-name',
110
111
  description: 'Get an ArNS returned name by name',
111
- options: options_js_1.nameOptions,
112
+ options: [options_js_1.optionMap.name],
112
113
  action: readCommands_js_1.getArNSReturnedName,
113
114
  });
114
115
  (0, utils_js_1.makeCommand)({
@@ -176,7 +177,7 @@ const utils_js_1 = require("./utils.js");
176
177
  (0, utils_js_1.makeCommand)({
177
178
  name: 'get-primary-name-request',
178
179
  description: 'Get primary name request',
179
- options: options_js_1.initiatorOptions,
180
+ options: [options_js_1.optionMap.initiator],
180
181
  action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
181
182
  .getPrimaryNameRequest({
182
183
  initiator: (0, utils_js_1.requiredStringFromOptions)(o, 'initiator'),
@@ -196,7 +197,7 @@ const utils_js_1 = require("./utils.js");
196
197
  (0, utils_js_1.makeCommand)({
197
198
  name: 'get-primary-name',
198
199
  description: 'Get primary name',
199
- options: [...options_js_1.addressOptions, options_js_1.optionMap.name],
200
+ options: [options_js_1.optionMap.address, options_js_1.optionMap.name],
200
201
  action: readCommands_js_1.getPrimaryName,
201
202
  });
202
203
  (0, utils_js_1.makeCommand)({
@@ -210,7 +211,7 @@ const utils_js_1 = require("./utils.js");
210
211
  (0, utils_js_1.makeCommand)({
211
212
  name: 'balance',
212
213
  description: 'Get the balance of an address',
213
- options: options_js_1.addressOptions,
214
+ options: [options_js_1.optionMap.address],
214
215
  action: (options) => (0, utils_js_1.readARIOFromOptions)(options)
215
216
  .getBalance({ address: (0, utils_js_1.requiredAddressFromOptions)(options) })
216
217
  .then((result) => ({
@@ -230,7 +231,7 @@ const utils_js_1 = require("./utils.js");
230
231
  (0, utils_js_1.makeCommand)({
231
232
  name: 'get-redelegation-fee',
232
233
  description: 'Get redelegation fee',
233
- options: options_js_1.addressOptions,
234
+ options: [options_js_1.optionMap.address],
234
235
  action: (options) => (0, utils_js_1.readARIOFromOptions)(options).getRedelegationFee({
235
236
  address: (0, utils_js_1.requiredAddressFromOptions)(options),
236
237
  }),
@@ -326,82 +327,31 @@ const utils_js_1 = require("./utils.js");
326
327
  name: 'buy-record',
327
328
  description: 'Buy a record',
328
329
  options: options_js_1.buyRecordOptions,
329
- action: async (options) => {
330
- const ario = (0, utils_js_1.writeARIOFromOptions)(options).ario;
331
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
332
- const type = (0, utils_js_1.recordTypeFromOptions)(options);
333
- const years = (0, utils_js_1.positiveIntegerFromOptions)(options, 'years');
334
- // TODO: Assert balance is sufficient for action
335
- // TODO: Assert record is not already owned
336
- const processId = options.processId;
337
- if (processId === undefined) {
338
- // TODO: Spawn ANT process, register it to ANT registry, get process ID
339
- throw new Error('Process ID must be provided for buy-record');
340
- }
341
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to ${type} the record ${name}?`, options);
342
- return ario.buyRecord({
343
- name: (0, utils_js_1.requiredStringFromOptions)(options, 'name'),
344
- processId,
345
- type,
346
- years,
347
- });
348
- },
330
+ action: arnsPurchaseCommands_js_1.buyRecordCLICommand,
349
331
  });
350
332
  (0, utils_js_1.makeCommand)({
351
333
  name: 'upgrade-record',
352
334
  description: 'Upgrade the lease of a record to a permabuy',
353
- options: [...options_js_1.nameOptions, ...options_js_1.writeActionOptions],
354
- // TODO: could assert record is leased by sender, assert balance is sufficient
355
- action: async (options) => {
356
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
357
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, options);
358
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.upgradeRecord({
359
- name,
360
- });
361
- },
335
+ options: options_js_1.arnsPurchaseOptions,
336
+ action: arnsPurchaseCommands_js_1.upgradeRecordCLICommand,
362
337
  });
363
338
  (0, utils_js_1.makeCommand)({
364
339
  name: 'extend-lease',
365
340
  description: 'Extend the lease of a record',
366
- options: [...options_js_1.writeActionOptions, options_js_1.optionMap.name, options_js_1.optionMap.years],
367
- action: async (options) => {
368
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
369
- const years = (0, utils_js_1.requiredPositiveIntegerFromOptions)(options, 'years');
370
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to extend the lease of ${name} by ${years}?`, options);
371
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.extendLease({
372
- name,
373
- years,
374
- }, (0, utils_js_1.writeActionTagsFromOptions)(options));
375
- },
341
+ options: [...options_js_1.arnsPurchaseOptions, options_js_1.optionMap.years],
342
+ action: arnsPurchaseCommands_js_1.extendLeaseCLICommand,
376
343
  });
377
344
  (0, utils_js_1.makeCommand)({
378
345
  name: 'increase-undername-limit',
379
346
  description: 'Increase the limit of a name',
380
- options: [...options_js_1.writeActionOptions, options_js_1.optionMap.name, options_js_1.optionMap.increaseCount],
381
- action: async (options) => {
382
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
383
- const increaseCount = (0, utils_js_1.requiredPositiveIntegerFromOptions)(options, 'increaseCount');
384
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, options);
385
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.increaseUndernameLimit({
386
- name,
387
- increaseCount,
388
- }, (0, utils_js_1.writeActionTagsFromOptions)(options));
389
- },
347
+ options: [...options_js_1.arnsPurchaseOptions, options_js_1.optionMap.increaseCount],
348
+ action: arnsPurchaseCommands_js_1.increaseUndernameLimitCLICommand,
390
349
  });
391
350
  (0, utils_js_1.makeCommand)({
392
351
  name: 'request-primary-name',
393
352
  description: 'Request a primary name',
394
- options: options_js_1.nameWriteOptions,
395
- action: async (options) => {
396
- // TODO: Assert balance is sufficient for action?
397
- // TODO: Assert name requested is not already owned
398
- // TODO: More assertions?
399
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
400
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to request the primary name ${name}?`, options);
401
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.requestPrimaryName({
402
- name,
403
- });
404
- },
353
+ options: options_js_1.arnsPurchaseOptions,
354
+ action: arnsPurchaseCommands_js_1.requestPrimaryNameCLICommand,
405
355
  });
406
356
  (0, utils_js_1.makeCommand)({
407
357
  name: 'spawn-ant',
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestPrimaryNameCLICommand = exports.increaseUndernameLimitCLICommand = exports.extendLeaseCLICommand = exports.upgradeRecordCLICommand = exports.buyRecordCLICommand = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ async function buyRecordCLICommand(o) {
6
+ const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
7
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
8
+ const type = (0, utils_js_1.recordTypeFromOptions)(o);
9
+ const years = (0, utils_js_1.positiveIntegerFromOptions)(o, 'years');
10
+ const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
11
+ const processId = o.processId;
12
+ if (processId === undefined) {
13
+ // TODO: Spawn ANT process, register it to ANT registry, get process ID
14
+ throw new Error('Process ID must be provided for buy-record');
15
+ }
16
+ if (!o.skipConfirmation) {
17
+ const existingRecord = await ario.getArNSRecord({
18
+ name,
19
+ });
20
+ if (existingRecord !== undefined) {
21
+ throw new Error(`ArNS Record ${name} is already owned`);
22
+ }
23
+ await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
24
+ ario,
25
+ address: signerAddress,
26
+ costDetailsParams: {
27
+ intent: 'Buy-Record',
28
+ type,
29
+ name,
30
+ years,
31
+ fundFrom,
32
+ fromAddress: signerAddress,
33
+ },
34
+ });
35
+ await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to ${type} the record ${name}?`, o);
36
+ }
37
+ return ario.buyRecord({
38
+ name: (0, utils_js_1.requiredStringFromOptions)(o, 'name'),
39
+ processId,
40
+ type,
41
+ years,
42
+ fundFrom: (0, utils_js_1.fundFromFromOptions)(o),
43
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
44
+ }
45
+ exports.buyRecordCLICommand = buyRecordCLICommand;
46
+ async function upgradeRecordCLICommand(o) {
47
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
48
+ const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
49
+ const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
50
+ if (!o.skipConfirmation) {
51
+ const existingRecord = await ario.getArNSRecord({
52
+ name,
53
+ });
54
+ if (existingRecord === undefined) {
55
+ throw new Error(`ArNS Record ${name} does not exist`);
56
+ }
57
+ if (existingRecord.type === 'permabuy') {
58
+ throw new Error(`ArNS Record ${name} is already a permabuy`);
59
+ }
60
+ await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
61
+ ario,
62
+ address: signerAddress,
63
+ costDetailsParams: {
64
+ intent: 'Upgrade-Name',
65
+ name,
66
+ fundFrom,
67
+ fromAddress: signerAddress,
68
+ },
69
+ });
70
+ await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, o);
71
+ }
72
+ return ario.upgradeRecord({
73
+ name,
74
+ fundFrom,
75
+ });
76
+ }
77
+ exports.upgradeRecordCLICommand = upgradeRecordCLICommand;
78
+ async function extendLeaseCLICommand(o) {
79
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
80
+ const years = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'years');
81
+ const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
82
+ const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
83
+ if (!o.skipConfirmation) {
84
+ const existingRecord = await ario.getArNSRecord({
85
+ name,
86
+ });
87
+ if (existingRecord === undefined) {
88
+ throw new Error(`ArNS Record ${name} does not exist`);
89
+ }
90
+ if (existingRecord.type === 'permabuy') {
91
+ throw new Error(`ArNS Record ${name} is a permabuy and cannot be extended`);
92
+ }
93
+ await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
94
+ ario: ario,
95
+ address: signerAddress,
96
+ costDetailsParams: {
97
+ intent: 'Extend-Lease',
98
+ name,
99
+ years,
100
+ fundFrom,
101
+ fromAddress: signerAddress,
102
+ },
103
+ });
104
+ await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to extend the lease of ${name} by ${years}?`, o);
105
+ }
106
+ return ario.extendLease({
107
+ name,
108
+ years,
109
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
110
+ }
111
+ exports.extendLeaseCLICommand = extendLeaseCLICommand;
112
+ async function increaseUndernameLimitCLICommand(o) {
113
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
114
+ const increaseCount = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'increaseCount');
115
+ const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
116
+ const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
117
+ if (!o.skipConfirmation) {
118
+ const existingRecord = await ario.getArNSRecord({
119
+ name,
120
+ });
121
+ if (existingRecord === undefined) {
122
+ throw new Error(`ArNS Record ${name} does not exist`);
123
+ }
124
+ await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
125
+ ario,
126
+ address: signerAddress,
127
+ costDetailsParams: {
128
+ intent: 'Increase-Undername-Limit',
129
+ name,
130
+ quantity: increaseCount,
131
+ fundFrom,
132
+ fromAddress: signerAddress,
133
+ },
134
+ });
135
+ await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, o);
136
+ }
137
+ return ario.increaseUndernameLimit({
138
+ name,
139
+ increaseCount,
140
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
141
+ }
142
+ exports.increaseUndernameLimitCLICommand = increaseUndernameLimitCLICommand;
143
+ async function requestPrimaryNameCLICommand(o) {
144
+ const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
145
+ const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
146
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
147
+ if (!o.skipConfirmation) {
148
+ // TODO: Assert name requested is not already owned?
149
+ // TODO: More assertions?
150
+ await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
151
+ ario,
152
+ address: signerAddress,
153
+ costDetailsParams: {
154
+ intent: 'Primary-Name-Request',
155
+ name,
156
+ fromAddress: signerAddress,
157
+ fundFrom,
158
+ },
159
+ });
160
+ await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to request the primary name ${name}?`, o);
161
+ }
162
+ return ario.requestPrimaryName({
163
+ name,
164
+ fundFrom,
165
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
166
+ }
167
+ exports.requestPrimaryNameCLICommand = requestPrimaryNameCLICommand;
@@ -24,7 +24,7 @@ const index_js_1 = require("../../node/index.js");
24
24
  const utils_js_1 = require("../utils.js");
25
25
  async function joinNetwork(options) {
26
26
  const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(options);
27
- const mARIOQuantity = (0, utils_js_1.requiredMIOFromOptions)(options, 'operatorStake');
27
+ const mARIOQuantity = (0, utils_js_1.requiredMARIOFromOptions)(options, 'operatorStake');
28
28
  const settings = {
29
29
  ...(0, utils_js_1.gatewaySettingsFromOptions)(options),
30
30
  operatorStake: mARIOQuantity.valueOf(),
@@ -40,7 +40,11 @@ async function joinNetwork(options) {
40
40
  if (settings.operators.minStake > mARIOQuantity.valueOf()) {
41
41
  throw new Error(`The minimum operator stake is ${(0, utils_js_1.formatARIOWithCommas)(new index_js_1.mARIOToken(settings.operators.minStake).toARIO())} ARIO. Please provide a higher stake.`);
42
42
  }
43
- await (0, utils_js_1.assertEnoughBalance)(ario, signerAddress, mARIOQuantity.toARIO());
43
+ await (0, utils_js_1.assertEnoughMARIOBalance)({
44
+ ario,
45
+ address: signerAddress,
46
+ mARIOQuantity,
47
+ });
44
48
  await (0, utils_js_1.assertConfirmationPrompt)(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${(0, utils_js_1.formatARIOWithCommas)(mARIOQuantity.toARIO())} ARIO to join the AR.IO network\nAre you sure?\n`, options);
45
49
  }
46
50
  const result = await ario.joinNetwork(settings, (0, utils_js_1.writeActionTagsFromOptions)(options));
@@ -95,7 +99,7 @@ async function saveObservations(o) {
95
99
  }
96
100
  exports.saveObservations = saveObservations;
97
101
  async function increaseOperatorStake(o) {
98
- const increaseQty = (0, utils_js_1.requiredMIOFromOptions)(o, 'operatorStake');
102
+ const increaseQty = (0, utils_js_1.requiredMARIOFromOptions)(o, 'operatorStake');
99
103
  await (0, utils_js_1.assertConfirmationPrompt)(`You are about to increase your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(increaseQty.toARIO())} ARIO\nAre you sure?`, o);
100
104
  return ((0, utils_js_1.writeARIOFromOptions)(o).ario.increaseOperatorStake({
101
105
  increaseQty,
@@ -104,7 +108,7 @@ async function increaseOperatorStake(o) {
104
108
  }
105
109
  exports.increaseOperatorStake = increaseOperatorStake;
106
110
  async function decreaseOperatorStake(o) {
107
- const decreaseQty = (0, utils_js_1.requiredMIOFromOptions)(o, 'operatorStake');
111
+ const decreaseQty = (0, utils_js_1.requiredMARIOFromOptions)(o, 'operatorStake');
108
112
  // TODO: Can assert stake is sufficient for action, and new target stake meets contract minimum
109
113
  await (0, utils_js_1.assertConfirmationPrompt)(`You are about to decrease your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(decreaseQty.toARIO())} ARIO\nAre you sure?`, o);
110
114
  return (0, utils_js_1.writeARIOFromOptions)(o).ario.decreaseOperatorStake({
@@ -1,22 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getCostDetails = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.listArNSReturnedNames = exports.getArNSReturnedName = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listGateways = exports.getGateway = void 0;
4
- /**
5
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- const io_js_1 = require("../../types/io.js");
20
4
  const token_js_1 = require("../../types/token.js");
21
5
  const utils_js_1 = require("../utils.js");
22
6
  async function getGateway(o) {
@@ -141,14 +125,9 @@ async function getTokenCost(o) {
141
125
  }
142
126
  exports.getTokenCost = getTokenCost;
143
127
  async function getCostDetails(o) {
144
- if (o.fundFrom !== undefined) {
145
- if (!(0, io_js_1.isValidFundFrom)(o.fundFrom)) {
146
- throw new Error(`Invalid fund from: ${o.fundFrom}. Please use one of ${io_js_1.fundFromOptions.join(', ')}`);
147
- }
148
- }
149
128
  const costDetails = await (0, utils_js_1.readARIOFromOptions)(o).getCostDetails({
150
129
  ...(0, utils_js_1.getTokenCostParamsFromOptions)(o),
151
- fundFrom: o.fundFrom,
130
+ fundFrom: (0, utils_js_1.fundFromFromOptions)(o),
152
131
  });
153
132
  const output = {
154
133
  ...costDetails,
@@ -6,7 +6,11 @@ async function transfer(options) {
6
6
  const { target, arioQuantity } = (0, utils_js_1.requiredTargetAndQuantityFromOptions)(options);
7
7
  const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(options);
8
8
  if (!options.skipConfirmation) {
9
- await (0, utils_js_1.assertEnoughBalance)(ario, signerAddress, arioQuantity);
9
+ await (0, utils_js_1.assertEnoughMARIOBalance)({
10
+ ario,
11
+ address: signerAddress,
12
+ mARIOQuantity: arioQuantity.toMARIO(),
13
+ });
10
14
  const confirm = await (0, utils_js_1.confirmationPrompt)(`Are you sure you want to transfer ${(0, utils_js_1.formatARIOWithCommas)(arioQuantity)} ARIO to ${target}?`);
11
15
  if (!confirm) {
12
16
  return { message: 'Transfer aborted by user' };
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.antStateOptions = exports.buyRecordOptions = exports.joinNetworkOptions = exports.updateGatewaySettingsOptions = exports.decreaseDelegateStakeOptions = exports.delegateStakeOptions = exports.redelegateStakeOptions = exports.operatorStakeOptions = exports.transferOptions = exports.tokenCostOptions = exports.getVaultOptions = exports.paginationAddressOptions = exports.paginationOptions = exports.nameWriteOptions = exports.addressAndVaultIdOptions = exports.epochOptions = exports.initiatorOptions = exports.nameOptions = exports.addressOptions = exports.writeActionOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
18
+ exports.antStateOptions = exports.buyRecordOptions = exports.joinNetworkOptions = exports.updateGatewaySettingsOptions = exports.decreaseDelegateStakeOptions = exports.delegateStakeOptions = exports.redelegateStakeOptions = exports.operatorStakeOptions = exports.transferOptions = exports.tokenCostOptions = exports.getVaultOptions = exports.paginationAddressOptions = exports.paginationOptions = exports.nameWriteOptions = exports.addressAndVaultIdOptions = exports.epochOptions = exports.arnsPurchaseOptions = exports.writeActionOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
19
19
  exports.optionMap = {
20
20
  walletFile: {
21
21
  alias: '-w, --wallet-file <walletFilePath>',
@@ -255,11 +255,13 @@ exports.globalOptions = [
255
255
  exports.optionMap.cuUrl,
256
256
  ];
257
257
  exports.writeActionOptions = [exports.optionMap.skipConfirmation, exports.optionMap.tags];
258
- exports.addressOptions = [exports.optionMap.address];
259
- exports.nameOptions = [exports.optionMap.name];
260
- exports.initiatorOptions = [exports.optionMap.initiator];
258
+ exports.arnsPurchaseOptions = [
259
+ ...exports.writeActionOptions,
260
+ exports.optionMap.name,
261
+ exports.optionMap.fundFrom,
262
+ ];
261
263
  exports.epochOptions = [exports.optionMap.epochIndex, exports.optionMap.timestamp];
262
- exports.addressAndVaultIdOptions = [...exports.addressOptions, exports.optionMap.vaultId];
264
+ exports.addressAndVaultIdOptions = [exports.optionMap.address, exports.optionMap.vaultId];
263
265
  exports.nameWriteOptions = [...exports.writeActionOptions, exports.optionMap.name];
264
266
  exports.paginationOptions = [
265
267
  exports.optionMap.cursor,
@@ -316,8 +318,7 @@ exports.joinNetworkOptions = [
316
318
  exports.optionMap.operatorStake,
317
319
  ];
318
320
  exports.buyRecordOptions = [
319
- ...exports.writeActionOptions,
320
- exports.optionMap.name,
321
+ ...exports.arnsPurchaseOptions,
321
322
  exports.optionMap.quantity,
322
323
  exports.optionMap.type,
323
324
  exports.optionMap.years,
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughBalance = exports.requiredMIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.writeActionTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatARIOWithCommas = exports.writeARIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = void 0;
6
+ exports.fundFromFromOptions = exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughMARIOBalance = exports.assertEnoughBalanceForArNSPurchase = exports.requiredMARIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.writeActionTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatMARIOToARIOWithCommas = exports.formatARIOWithCommas = exports.writeARIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = void 0;
7
7
  /**
8
8
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
9
9
  *
@@ -160,6 +160,10 @@ function formatARIOWithCommas(value) {
160
160
  return integerWithCommas + '.' + decimalPart;
161
161
  }
162
162
  exports.formatARIOWithCommas = formatARIOWithCommas;
163
+ function formatMARIOToARIOWithCommas(value) {
164
+ return formatARIOWithCommas(value.toARIO());
165
+ }
166
+ exports.formatMARIOToARIOWithCommas = formatMARIOToARIOWithCommas;
163
167
  /** helper to get address from --address option first, then check wallet options */
164
168
  function addressFromOptions(options) {
165
169
  if (options.address !== undefined) {
@@ -294,20 +298,39 @@ function recordTypeFromOptions(options) {
294
298
  return options.type;
295
299
  }
296
300
  exports.recordTypeFromOptions = recordTypeFromOptions;
297
- function requiredMIOFromOptions(options, key) {
301
+ function requiredMARIOFromOptions(options, key) {
298
302
  if (options[key] === undefined) {
299
303
  throw new Error(`No ${key} provided. Use --${key} denominated in ARIO`);
300
304
  }
301
305
  return new index_js_1.ARIOToken(+options[key]).toMARIO();
302
306
  }
303
- exports.requiredMIOFromOptions = requiredMIOFromOptions;
304
- async function assertEnoughBalance(ario, address, arioQuantity) {
307
+ exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
308
+ async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
309
+ const costDetails = await ario.getCostDetails(costDetailsParams);
310
+ if (costDetails.fundingPlan) {
311
+ if (costDetails.fundingPlan.shortfall > 0) {
312
+ throw new Error(`Insufficient balance for action. Shortfall: ${formatMARIOToARIOWithCommas(new index_js_1.mARIOToken(costDetails.fundingPlan.shortfall))}\n${JSON.stringify(costDetails, null, 2)}`);
313
+ }
314
+ }
315
+ else {
316
+ await assertEnoughMARIOBalance({
317
+ ario,
318
+ address,
319
+ mARIOQuantity: costDetails.tokenCost,
320
+ });
321
+ }
322
+ }
323
+ exports.assertEnoughBalanceForArNSPurchase = assertEnoughBalanceForArNSPurchase;
324
+ async function assertEnoughMARIOBalance({ address, ario, mARIOQuantity, }) {
325
+ if (typeof mARIOQuantity === 'number') {
326
+ mARIOQuantity = new index_js_1.mARIOToken(mARIOQuantity);
327
+ }
305
328
  const balance = await ario.getBalance({ address });
306
- if (balance < arioQuantity.toMARIO().valueOf()) {
307
- throw new Error(`Insufficient ARIO balance for action. Balance available: ${new index_js_1.mARIOToken(balance).toARIO()} ARIO`);
329
+ if (balance < mARIOQuantity.valueOf()) {
330
+ throw new Error(`Insufficient ARIO balance for action. Balance available: ${formatMARIOToARIOWithCommas(new index_js_1.mARIOToken(balance))} ARIO`);
308
331
  }
309
332
  }
310
- exports.assertEnoughBalance = assertEnoughBalance;
333
+ exports.assertEnoughMARIOBalance = assertEnoughMARIOBalance;
311
334
  async function confirmationPrompt(message) {
312
335
  const { confirm } = await (0, prompts_1.default)({
313
336
  type: 'confirm',
@@ -425,3 +448,12 @@ function getTokenCostParamsFromOptions(o) {
425
448
  };
426
449
  }
427
450
  exports.getTokenCostParamsFromOptions = getTokenCostParamsFromOptions;
451
+ function fundFromFromOptions(o) {
452
+ if (o.fundFrom !== undefined) {
453
+ if (!(0, index_js_1.isValidFundFrom)(o.fundFrom)) {
454
+ throw new Error(`Invalid fund from: ${o.fundFrom}. Please use one of ${index_js_1.fundFromOptions.join(', ')}`);
455
+ }
456
+ }
457
+ return o.fundFrom ?? 'balance';
458
+ }
459
+ exports.fundFromFromOptions = fundFromFromOptions;
@@ -31,6 +31,12 @@ class AOProcess {
31
31
  this.logger = logger;
32
32
  this.ao = ao;
33
33
  }
34
+ isMessageDataEmpty(messageData) {
35
+ return (messageData === undefined ||
36
+ messageData === 'null' || // This is what the CU returns for 'nil' values that are json.encoded
37
+ messageData === '' ||
38
+ messageData === null);
39
+ }
34
40
  async read({ tags, retries = 3, fromAddress, }) {
35
41
  let attempts = 0;
36
42
  let lastError;
@@ -51,20 +57,18 @@ class AOProcess {
51
57
  this.logger.debug(`Read interaction result`, {
52
58
  result,
53
59
  });
60
+ const error = errorMessageFromOutput(result);
61
+ if (error !== undefined) {
62
+ throw new Error(error);
63
+ }
54
64
  if (result.Messages === undefined || result.Messages.length === 0) {
55
65
  this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
56
66
  throw new Error(`Process ${this.processId} does not support provided action.`);
57
67
  }
58
- const tagsOutput = result.Messages?.[0]?.Tags;
59
68
  const messageData = result.Messages?.[0]?.Data;
60
- const errorData = result.Error;
61
- const error = errorData || tagsOutput?.find((tag) => tag.name === 'Error')?.value;
62
- if (error) {
63
- throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
64
- }
65
- // return empty object if no data is returned
66
- if (messageData === undefined) {
67
- return {};
69
+ // return undefined if no data is returned
70
+ if (this.isMessageDataEmpty(messageData)) {
71
+ return undefined;
68
72
  }
69
73
  const response = (0, json_js_1.safeDecode)(result.Messages[0].Data);
70
74
  return response;
@@ -72,7 +76,7 @@ class AOProcess {
72
76
  catch (e) {
73
77
  attempts++;
74
78
  this.logger.debug(`Read attempt ${attempts} failed`, {
75
- error: e,
79
+ error: e instanceof Error ? e.message : e,
76
80
  tags,
77
81
  });
78
82
  lastError = e;
@@ -119,11 +123,8 @@ class AOProcess {
119
123
  messageId,
120
124
  processId: this.processId,
121
125
  });
122
- const errorData = output.Error;
123
- const error = errorData ||
124
- output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
125
- ?.value;
126
- if (error) {
126
+ const error = errorMessageFromOutput(output);
127
+ if (error !== undefined) {
127
128
  throw new error_js_1.WriteInteractionError(error);
128
129
  }
129
130
  // check if there are any Messages in the output
@@ -133,7 +134,7 @@ class AOProcess {
133
134
  if (output.Messages.length === 0) {
134
135
  throw new Error(`Process ${this.processId} does not support provided action.`);
135
136
  }
136
- if (output.Messages[0].Data === undefined) {
137
+ if (this.isMessageDataEmpty(output.Messages[0].Data)) {
137
138
  return { id: messageId };
138
139
  }
139
140
  const resultData = (0, json_js_1.safeDecode)(output.Messages[0].Data);
@@ -171,3 +172,20 @@ class AOProcess {
171
172
  }
172
173
  }
173
174
  exports.AOProcess = AOProcess;
175
+ function errorMessageFromOutput(output) {
176
+ const errorData = output.Error;
177
+ if (errorData !== undefined) {
178
+ // TODO: Could clean this one up too, current error is verbose, but not always deterministic for parsing
179
+ // Throw the whole raw error if AO process level error
180
+ return errorData;
181
+ }
182
+ const error = output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
183
+ if (error !== undefined) {
184
+ // from [string "aos"]:6846: Name is already registered
185
+ const lineNumber = error.match(/\d+/)?.[0];
186
+ const message = error.replace(/\[string "aos"\]:\d+:/, '');
187
+ // to more user friendly: Name is already registered (line 6846)
188
+ return `${message} (line ${lineNumber})`.trim();
189
+ }
190
+ return undefined;
191
+ }