@ar.io/sdk 3.1.0-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.
- package/bundles/web.bundle.min.js +60 -60
- package/lib/cjs/cli/cli.js +19 -69
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +167 -0
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +8 -4
- package/lib/cjs/cli/commands/readCommands.js +1 -22
- package/lib/cjs/cli/commands/transfer.js +5 -1
- package/lib/cjs/cli/options.js +8 -7
- package/lib/cjs/cli/utils.js +39 -7
- package/lib/cjs/common/io.js +32 -22
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +21 -71
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +159 -0
- package/lib/esm/cli/commands/gatewayWriteCommands.js +6 -2
- package/lib/esm/cli/commands/readCommands.js +2 -23
- package/lib/esm/cli/commands/transfer.js +6 -2
- package/lib/esm/cli/options.js +7 -6
- package/lib/esm/cli/utils.js +34 -5
- package/lib/esm/common/io.js +32 -22
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +22 -0
- package/lib/types/cli/options.d.ts +1 -9
- package/lib/types/cli/types.d.ts +3 -5
- package/lib/types/cli/utils.d.ts +16 -3
- package/lib/types/common/io.d.ts +6 -21
- package/lib/types/types/io.d.ts +8 -7
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/cli/cli.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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: [
|
|
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.
|
|
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.
|
|
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:
|
|
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:
|
|
354
|
-
|
|
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.
|
|
367
|
-
action:
|
|
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.
|
|
381
|
-
action:
|
|
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.
|
|
395
|
-
action:
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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' };
|
package/lib/cjs/cli/options.js
CHANGED
|
@@ -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.
|
|
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.
|
|
259
|
-
exports.
|
|
260
|
-
exports.
|
|
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 = [
|
|
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.
|
|
320
|
-
exports.optionMap.name,
|
|
321
|
+
...exports.arnsPurchaseOptions,
|
|
321
322
|
exports.optionMap.quantity,
|
|
322
323
|
exports.optionMap.type,
|
|
323
324
|
exports.optionMap.years,
|
package/lib/cjs/cli/utils.js
CHANGED
|
@@ -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.
|
|
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
|
|
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.
|
|
304
|
-
async function
|
|
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 <
|
|
307
|
-
throw new Error(`Insufficient ARIO balance for action. Balance available: ${new index_js_1.mARIOToken(balance)
|
|
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.
|
|
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;
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -713,6 +713,7 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
713
713
|
{ name: 'Years', value: params.years?.toString() ?? '1' },
|
|
714
714
|
{ name: 'Process-Id', value: params.processId },
|
|
715
715
|
{ name: 'Purchase-Type', value: params.type || 'lease' },
|
|
716
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
716
717
|
];
|
|
717
718
|
return this.process.send({
|
|
718
719
|
signer: this.signer,
|
|
@@ -729,13 +730,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
729
730
|
*/
|
|
730
731
|
async upgradeRecord(params, options) {
|
|
731
732
|
const { tags = [] } = options || {};
|
|
733
|
+
const allTags = [
|
|
734
|
+
...tags,
|
|
735
|
+
{ name: 'Action', value: 'Upgrade-Name' }, // TODO: align on Update-Record vs. Upgrade-Name (contract currently uses Upgrade-Name)
|
|
736
|
+
{ name: 'Name', value: params.name },
|
|
737
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
738
|
+
];
|
|
732
739
|
return this.process.send({
|
|
733
740
|
signer: this.signer,
|
|
734
|
-
tags:
|
|
735
|
-
...tags,
|
|
736
|
-
{ name: 'Action', value: 'Upgrade-Name' }, // TODO: align on Update-Record vs. Upgrade-Name (contract currently uses Upgrade-Name)
|
|
737
|
-
{ name: 'Name', value: params.name },
|
|
738
|
-
],
|
|
741
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
739
742
|
});
|
|
740
743
|
}
|
|
741
744
|
/**
|
|
@@ -749,26 +752,30 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
749
752
|
*/
|
|
750
753
|
async extendLease(params, options) {
|
|
751
754
|
const { tags = [] } = options || {};
|
|
755
|
+
const allTags = [
|
|
756
|
+
...tags,
|
|
757
|
+
{ name: 'Action', value: 'Extend-Lease' },
|
|
758
|
+
{ name: 'Name', value: params.name },
|
|
759
|
+
{ name: 'Years', value: params.years.toString() },
|
|
760
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
761
|
+
];
|
|
752
762
|
return this.process.send({
|
|
753
763
|
signer: this.signer,
|
|
754
|
-
tags:
|
|
755
|
-
...tags,
|
|
756
|
-
{ name: 'Action', value: 'Extend-Lease' },
|
|
757
|
-
{ name: 'Name', value: params.name },
|
|
758
|
-
{ name: 'Years', value: params.years.toString() },
|
|
759
|
-
],
|
|
764
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
760
765
|
});
|
|
761
766
|
}
|
|
762
767
|
async increaseUndernameLimit(params, options) {
|
|
763
768
|
const { tags = [] } = options || {};
|
|
769
|
+
const allTags = [
|
|
770
|
+
...tags,
|
|
771
|
+
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
772
|
+
{ name: 'Name', value: params.name },
|
|
773
|
+
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
774
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
775
|
+
];
|
|
764
776
|
return this.process.send({
|
|
765
777
|
signer: this.signer,
|
|
766
|
-
tags:
|
|
767
|
-
...tags,
|
|
768
|
-
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
769
|
-
{ name: 'Name', value: params.name },
|
|
770
|
-
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
771
|
-
],
|
|
778
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
772
779
|
});
|
|
773
780
|
}
|
|
774
781
|
/**
|
|
@@ -793,13 +800,16 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
793
800
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
794
801
|
});
|
|
795
802
|
}
|
|
796
|
-
async requestPrimaryName(params) {
|
|
803
|
+
async requestPrimaryName(params, options) {
|
|
804
|
+
const { tags = [] } = options || {};
|
|
805
|
+
const allTags = [
|
|
806
|
+
...tags,
|
|
807
|
+
{ name: 'Action', value: 'Request-Primary-Name' },
|
|
808
|
+
{ name: 'Name', value: params.name },
|
|
809
|
+
];
|
|
797
810
|
return this.process.send({
|
|
798
811
|
signer: this.signer,
|
|
799
|
-
tags:
|
|
800
|
-
{ name: 'Action', value: 'Request-Primary-Name' },
|
|
801
|
-
{ name: 'Name', value: params.name },
|
|
802
|
-
],
|
|
812
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
803
813
|
});
|
|
804
814
|
}
|
|
805
815
|
/**
|
package/lib/cjs/version.js
CHANGED