@ar.io/sdk 3.0.1-alpha.1 → 3.1.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.
Files changed (34) hide show
  1. package/README.md +38 -0
  2. package/bundles/web.bundle.min.js +76 -76
  3. package/lib/cjs/cli/cli.js +27 -71
  4. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +167 -0
  5. package/lib/cjs/cli/commands/gatewayWriteCommands.js +8 -4
  6. package/lib/cjs/cli/commands/readCommands.js +17 -38
  7. package/lib/cjs/cli/commands/transfer.js +5 -1
  8. package/lib/cjs/cli/options.js +14 -7
  9. package/lib/cjs/cli/utils.js +59 -7
  10. package/lib/cjs/common/contracts/ao-process.js +7 -3
  11. package/lib/cjs/common/io.js +79 -23
  12. package/lib/cjs/types/io.js +6 -1
  13. package/lib/cjs/version.js +1 -1
  14. package/lib/esm/cli/cli.js +30 -74
  15. package/lib/esm/cli/commands/arnsPurchaseCommands.js +159 -0
  16. package/lib/esm/cli/commands/gatewayWriteCommands.js +6 -2
  17. package/lib/esm/cli/commands/readCommands.js +16 -38
  18. package/lib/esm/cli/commands/transfer.js +6 -2
  19. package/lib/esm/cli/options.js +13 -6
  20. package/lib/esm/cli/utils.js +53 -5
  21. package/lib/esm/common/contracts/ao-process.js +7 -3
  22. package/lib/esm/common/io.js +79 -23
  23. package/lib/esm/types/io.js +4 -0
  24. package/lib/esm/version.js +1 -1
  25. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +22 -0
  26. package/lib/types/cli/commands/readCommands.d.ts +24 -2
  27. package/lib/types/cli/options.d.ts +5 -9
  28. package/lib/types/cli/types.d.ts +3 -5
  29. package/lib/types/cli/utils.d.ts +25 -4
  30. package/lib/types/common/contracts/ao-process.d.ts +2 -1
  31. package/lib/types/common/io.d.ts +7 -21
  32. package/lib/types/types/io.d.ts +39 -10
  33. package/lib/types/version.d.ts +1 -1
  34. package/package.json +1 -1
@@ -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)({
@@ -154,10 +155,16 @@ const utils_js_1 = require("./utils.js");
154
155
  });
155
156
  (0, utils_js_1.makeCommand)({
156
157
  name: 'get-token-cost',
157
- description: 'Get token cost',
158
+ description: 'Get token cost for an intended action',
158
159
  options: options_js_1.tokenCostOptions,
159
160
  action: readCommands_js_1.getTokenCost,
160
161
  });
162
+ (0, utils_js_1.makeCommand)({
163
+ name: 'get-cost-details',
164
+ description: 'Get expanded cost details for an intended action',
165
+ options: options_js_1.tokenCostOptions,
166
+ action: readCommands_js_1.getCostDetails,
167
+ });
161
168
  (0, utils_js_1.makeCommand)({
162
169
  name: 'list-vaults',
163
170
  description: 'Get all wallet vaults',
@@ -170,7 +177,7 @@ const utils_js_1 = require("./utils.js");
170
177
  (0, utils_js_1.makeCommand)({
171
178
  name: 'get-primary-name-request',
172
179
  description: 'Get primary name request',
173
- options: options_js_1.initiatorOptions,
180
+ options: [options_js_1.optionMap.initiator],
174
181
  action: (o) => (0, utils_js_1.readARIOFromOptions)(o)
175
182
  .getPrimaryNameRequest({
176
183
  initiator: (0, utils_js_1.requiredStringFromOptions)(o, 'initiator'),
@@ -190,7 +197,7 @@ const utils_js_1 = require("./utils.js");
190
197
  (0, utils_js_1.makeCommand)({
191
198
  name: 'get-primary-name',
192
199
  description: 'Get primary name',
193
- options: [...options_js_1.addressOptions, options_js_1.optionMap.name],
200
+ options: [options_js_1.optionMap.address, options_js_1.optionMap.name],
194
201
  action: readCommands_js_1.getPrimaryName,
195
202
  });
196
203
  (0, utils_js_1.makeCommand)({
@@ -204,12 +211,12 @@ const utils_js_1 = require("./utils.js");
204
211
  (0, utils_js_1.makeCommand)({
205
212
  name: 'balance',
206
213
  description: 'Get the balance of an address',
207
- options: options_js_1.addressOptions,
214
+ options: [options_js_1.optionMap.address],
208
215
  action: (options) => (0, utils_js_1.readARIOFromOptions)(options)
209
216
  .getBalance({ address: (0, utils_js_1.requiredAddressFromOptions)(options) })
210
217
  .then((result) => ({
211
218
  address: (0, utils_js_1.requiredAddressFromOptions)(options),
212
- mIOBalance: result,
219
+ mARIOBalance: result,
213
220
  message: `Provided address current has a balance of ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(result).toARIO())} ARIO`,
214
221
  })),
215
222
  });
@@ -224,7 +231,7 @@ const utils_js_1 = require("./utils.js");
224
231
  (0, utils_js_1.makeCommand)({
225
232
  name: 'get-redelegation-fee',
226
233
  description: 'Get redelegation fee',
227
- options: options_js_1.addressOptions,
234
+ options: [options_js_1.optionMap.address],
228
235
  action: (options) => (0, utils_js_1.readARIOFromOptions)(options).getRedelegationFee({
229
236
  address: (0, utils_js_1.requiredAddressFromOptions)(options),
230
237
  }),
@@ -320,82 +327,31 @@ const utils_js_1 = require("./utils.js");
320
327
  name: 'buy-record',
321
328
  description: 'Buy a record',
322
329
  options: options_js_1.buyRecordOptions,
323
- action: async (options) => {
324
- const ario = (0, utils_js_1.writeARIOFromOptions)(options).ario;
325
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
326
- const type = (0, utils_js_1.recordTypeFromOptions)(options);
327
- const years = (0, utils_js_1.positiveIntegerFromOptions)(options, 'years');
328
- // TODO: Assert balance is sufficient for action
329
- // TODO: Assert record is not already owned
330
- const processId = options.processId;
331
- if (processId === undefined) {
332
- // TODO: Spawn ANT process, register it to ANT registry, get process ID
333
- throw new Error('Process ID must be provided for buy-record');
334
- }
335
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to ${type} the record ${name}?`, options);
336
- return ario.buyRecord({
337
- name: (0, utils_js_1.requiredStringFromOptions)(options, 'name'),
338
- processId,
339
- type,
340
- years,
341
- });
342
- },
330
+ action: arnsPurchaseCommands_js_1.buyRecordCLICommand,
343
331
  });
344
332
  (0, utils_js_1.makeCommand)({
345
333
  name: 'upgrade-record',
346
334
  description: 'Upgrade the lease of a record to a permabuy',
347
- options: [...options_js_1.nameOptions, ...options_js_1.writeActionOptions],
348
- // TODO: could assert record is leased by sender, assert balance is sufficient
349
- action: async (options) => {
350
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
351
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, options);
352
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.upgradeRecord({
353
- name,
354
- });
355
- },
335
+ options: options_js_1.arnsPurchaseOptions,
336
+ action: arnsPurchaseCommands_js_1.upgradeRecordCLICommand,
356
337
  });
357
338
  (0, utils_js_1.makeCommand)({
358
339
  name: 'extend-lease',
359
340
  description: 'Extend the lease of a record',
360
- options: [...options_js_1.writeActionOptions, options_js_1.optionMap.name, options_js_1.optionMap.years],
361
- action: async (options) => {
362
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
363
- const years = (0, utils_js_1.requiredPositiveIntegerFromOptions)(options, 'years');
364
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to extend the lease of ${name} by ${years}?`, options);
365
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.extendLease({
366
- name,
367
- years,
368
- }, (0, utils_js_1.writeActionTagsFromOptions)(options));
369
- },
341
+ options: [...options_js_1.arnsPurchaseOptions, options_js_1.optionMap.years],
342
+ action: arnsPurchaseCommands_js_1.extendLeaseCLICommand,
370
343
  });
371
344
  (0, utils_js_1.makeCommand)({
372
345
  name: 'increase-undername-limit',
373
346
  description: 'Increase the limit of a name',
374
- options: [...options_js_1.writeActionOptions, options_js_1.optionMap.name, options_js_1.optionMap.increaseCount],
375
- action: async (options) => {
376
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
377
- const increaseCount = (0, utils_js_1.requiredPositiveIntegerFromOptions)(options, 'increaseCount');
378
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, options);
379
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.increaseUndernameLimit({
380
- name,
381
- increaseCount,
382
- }, (0, utils_js_1.writeActionTagsFromOptions)(options));
383
- },
347
+ options: [...options_js_1.arnsPurchaseOptions, options_js_1.optionMap.increaseCount],
348
+ action: arnsPurchaseCommands_js_1.increaseUndernameLimitCLICommand,
384
349
  });
385
350
  (0, utils_js_1.makeCommand)({
386
351
  name: 'request-primary-name',
387
352
  description: 'Request a primary name',
388
- options: options_js_1.nameWriteOptions,
389
- action: async (options) => {
390
- // TODO: Assert balance is sufficient for action?
391
- // TODO: Assert name requested is not already owned
392
- // TODO: More assertions?
393
- const name = (0, utils_js_1.requiredStringFromOptions)(options, 'name');
394
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to request the primary name ${name}?`, options);
395
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.requestPrimaryName({
396
- name,
397
- });
398
- },
353
+ options: options_js_1.arnsPurchaseOptions,
354
+ action: arnsPurchaseCommands_js_1.requestPrimaryNameCLICommand,
399
355
  });
400
356
  (0, utils_js_1.makeCommand)({
401
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
- exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = 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");
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;
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) {
@@ -132,33 +116,28 @@ async function getPrescribedNames(o) {
132
116
  }
133
117
  exports.getPrescribedNames = getPrescribedNames;
134
118
  async function getTokenCost(o) {
135
- o.intent ??= 'Buy-Record';
136
- o.type ??= 'lease';
137
- if (!(0, io_js_1.isValidIntent)(o.intent)) {
138
- throw new Error(`Invalid intent. Valid intents are: ${io_js_1.validIntents.join(', ')}`);
139
- }
140
- if (o.type !== 'lease' && o.type !== 'permabuy') {
141
- throw new Error(`Invalid type. Valid types are: lease, permabuy`);
142
- }
143
- if (o.type === 'lease' &&
144
- io_js_1.intentsUsingYears.includes(o.intent) &&
145
- o.years === undefined) {
146
- throw new Error('Years is required for lease type');
147
- }
148
- const tokenCost = await (0, utils_js_1.readARIOFromOptions)(o).getTokenCost({
149
- type: o.type,
150
- quantity: o.quantity !== undefined ? +o.quantity : undefined,
151
- years: o.years !== undefined ? +o.years : undefined,
152
- intent: o.intent,
153
- name: (0, utils_js_1.requiredStringFromOptions)(o, 'name'),
154
- });
119
+ const tokenCost = await (0, utils_js_1.readARIOFromOptions)(o).getTokenCost((0, utils_js_1.getTokenCostParamsFromOptions)(o));
155
120
  const output = {
156
- mIOTokenCost: tokenCost,
121
+ mARIOTokenCost: tokenCost,
157
122
  message: `The cost of the provided action is ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(tokenCost).toARIO())} ARIO`,
158
123
  };
159
124
  return output;
160
125
  }
161
126
  exports.getTokenCost = getTokenCost;
127
+ async function getCostDetails(o) {
128
+ const costDetails = await (0, utils_js_1.readARIOFromOptions)(o).getCostDetails({
129
+ ...(0, utils_js_1.getTokenCostParamsFromOptions)(o),
130
+ fundFrom: (0, utils_js_1.fundFromFromOptions)(o),
131
+ });
132
+ const output = {
133
+ ...costDetails,
134
+ message: `The cost of the provided action is ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(costDetails.tokenCost).toARIO())} ARIO${costDetails.fundingPlan && costDetails.fundingPlan.shortfall > 0
135
+ ? `. Insufficient funds for action. There is a shortfall of ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(costDetails.fundingPlan.shortfall).toARIO())} ARIO`
136
+ : ''}`,
137
+ };
138
+ return output;
139
+ }
140
+ exports.getCostDetails = getCostDetails;
162
141
  async function getPrimaryName(o) {
163
142
  const address = (0, utils_js_1.addressFromOptions)(o);
164
143
  const name = o.name;
@@ -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>',
@@ -237,6 +237,10 @@ exports.optionMap = {
237
237
  description: 'Include failed gateways in the list',
238
238
  type: 'array',
239
239
  },
240
+ fundFrom: {
241
+ alias: '--fund-from <fundFrom>',
242
+ description: 'Where to fund the action from. e.g. "balance", "stakes", or "any',
243
+ },
240
244
  };
241
245
  exports.walletOptions = [
242
246
  exports.optionMap.walletFile,
@@ -251,11 +255,13 @@ exports.globalOptions = [
251
255
  exports.optionMap.cuUrl,
252
256
  ];
253
257
  exports.writeActionOptions = [exports.optionMap.skipConfirmation, exports.optionMap.tags];
254
- exports.addressOptions = [exports.optionMap.address];
255
- exports.nameOptions = [exports.optionMap.name];
256
- exports.initiatorOptions = [exports.optionMap.initiator];
258
+ exports.arnsPurchaseOptions = [
259
+ ...exports.writeActionOptions,
260
+ exports.optionMap.name,
261
+ exports.optionMap.fundFrom,
262
+ ];
257
263
  exports.epochOptions = [exports.optionMap.epochIndex, exports.optionMap.timestamp];
258
- exports.addressAndVaultIdOptions = [...exports.addressOptions, exports.optionMap.vaultId];
264
+ exports.addressAndVaultIdOptions = [exports.optionMap.address, exports.optionMap.vaultId];
259
265
  exports.nameWriteOptions = [...exports.writeActionOptions, exports.optionMap.name];
260
266
  exports.paginationOptions = [
261
267
  exports.optionMap.cursor,
@@ -274,6 +280,8 @@ exports.tokenCostOptions = [
274
280
  exports.optionMap.type,
275
281
  exports.optionMap.years,
276
282
  exports.optionMap.quantity,
283
+ exports.optionMap.address,
284
+ exports.optionMap.fundFrom,
277
285
  ];
278
286
  exports.transferOptions = [
279
287
  ...exports.writeActionOptions,
@@ -310,8 +318,7 @@ exports.joinNetworkOptions = [
310
318
  exports.optionMap.operatorStake,
311
319
  ];
312
320
  exports.buyRecordOptions = [
313
- ...exports.writeActionOptions,
314
- exports.optionMap.name,
321
+ ...exports.arnsPurchaseOptions,
315
322
  exports.optionMap.quantity,
316
323
  exports.optionMap.type,
317
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.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',
@@ -405,3 +428,32 @@ function getANTStateFromOptions(options) {
405
428
  });
406
429
  }
407
430
  exports.getANTStateFromOptions = getANTStateFromOptions;
431
+ function getTokenCostParamsFromOptions(o) {
432
+ o.intent ??= 'Buy-Record';
433
+ o.type ??= 'lease';
434
+ o.years ??= '1';
435
+ if (!(0, index_js_1.isValidIntent)(o.intent)) {
436
+ throw new Error(`Invalid intent. Valid intents are: ${index_js_1.validIntents.join(', ')}`);
437
+ }
438
+ if (o.type !== 'lease' && o.type !== 'permabuy') {
439
+ throw new Error(`Invalid type. Valid types are: lease, permabuy`);
440
+ }
441
+ return {
442
+ type: o.type,
443
+ quantity: o.quantity !== undefined ? +o.quantity : undefined,
444
+ years: +o.years,
445
+ intent: o.intent,
446
+ name: requiredStringFromOptions(o, 'name'),
447
+ fromAddress: addressFromOptions(o),
448
+ };
449
+ }
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;