@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.
- package/README.md +38 -0
- package/bundles/web.bundle.min.js +76 -76
- package/lib/cjs/cli/cli.js +27 -71
- 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 +17 -38
- package/lib/cjs/cli/commands/transfer.js +5 -1
- package/lib/cjs/cli/options.js +14 -7
- package/lib/cjs/cli/utils.js +59 -7
- package/lib/cjs/common/contracts/ao-process.js +7 -3
- package/lib/cjs/common/io.js +79 -23
- package/lib/cjs/types/io.js +6 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +30 -74
- 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 +16 -38
- package/lib/esm/cli/commands/transfer.js +6 -2
- package/lib/esm/cli/options.js +13 -6
- package/lib/esm/cli/utils.js +53 -5
- package/lib/esm/common/contracts/ao-process.js +7 -3
- package/lib/esm/common/io.js +79 -23
- package/lib/esm/types/io.js +4 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +22 -0
- package/lib/types/cli/commands/readCommands.d.ts +24 -2
- package/lib/types/cli/options.d.ts +5 -9
- package/lib/types/cli/types.d.ts +3 -5
- package/lib/types/cli/utils.d.ts +25 -4
- package/lib/types/common/contracts/ao-process.d.ts +2 -1
- package/lib/types/common/io.d.ts +7 -21
- package/lib/types/types/io.d.ts +39 -10
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -31,7 +31,7 @@ class AOProcess {
|
|
|
31
31
|
this.logger = logger;
|
|
32
32
|
this.ao = ao;
|
|
33
33
|
}
|
|
34
|
-
async read({ tags, retries = 3, }) {
|
|
34
|
+
async read({ tags, retries = 3, fromAddress, }) {
|
|
35
35
|
let attempts = 0;
|
|
36
36
|
let lastError;
|
|
37
37
|
while (attempts < retries) {
|
|
@@ -40,10 +40,14 @@ class AOProcess {
|
|
|
40
40
|
tags,
|
|
41
41
|
});
|
|
42
42
|
// map tags to inputs
|
|
43
|
-
const
|
|
43
|
+
const dryRunInput = {
|
|
44
44
|
process: this.processId,
|
|
45
45
|
tags,
|
|
46
|
-
}
|
|
46
|
+
};
|
|
47
|
+
if (fromAddress !== undefined) {
|
|
48
|
+
dryRunInput['Owner'] = fromAddress;
|
|
49
|
+
}
|
|
50
|
+
const result = await this.ao.dryrun(dryRunInput);
|
|
47
51
|
this.logger.debug(`Read interaction result`, {
|
|
48
52
|
result,
|
|
49
53
|
});
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -265,7 +265,7 @@ class ARIOReadable {
|
|
|
265
265
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
|
-
async getTokenCost({ intent, type, years, name, quantity, }) {
|
|
268
|
+
async getTokenCost({ intent, type, years, name, quantity, fromAddress, }) {
|
|
269
269
|
const allTags = [
|
|
270
270
|
{ name: 'Action', value: 'Token-Cost' },
|
|
271
271
|
{
|
|
@@ -302,6 +302,52 @@ class ARIOReadable {
|
|
|
302
302
|
];
|
|
303
303
|
return this.process.read({
|
|
304
304
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
305
|
+
fromAddress,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
// TODO: Can overload this function to refine different types of cost details params
|
|
309
|
+
async getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }) {
|
|
310
|
+
const allTags = [
|
|
311
|
+
{ name: 'Action', value: 'Get-Cost-Details-For-Action' },
|
|
312
|
+
{
|
|
313
|
+
name: 'Intent',
|
|
314
|
+
value: intent,
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: 'Name',
|
|
318
|
+
value: name,
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
name: 'Years',
|
|
322
|
+
value: years?.toString(),
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: 'Quantity',
|
|
326
|
+
value: quantity?.toString(),
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
name: 'Purchase-Type',
|
|
330
|
+
value: type,
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
name: 'Fund-From',
|
|
334
|
+
value: fundFrom,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
name: 'Timestamp',
|
|
338
|
+
value: (await this.arweave.blocks
|
|
339
|
+
.getCurrent()
|
|
340
|
+
.then((block) => {
|
|
341
|
+
return { timestamp: block.timestamp * 1000 };
|
|
342
|
+
})
|
|
343
|
+
.catch(() => {
|
|
344
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
345
|
+
})).timestamp.toString(),
|
|
346
|
+
},
|
|
347
|
+
];
|
|
348
|
+
return this.process.read({
|
|
349
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
350
|
+
fromAddress,
|
|
305
351
|
});
|
|
306
352
|
}
|
|
307
353
|
async getRegistrationFees() {
|
|
@@ -667,6 +713,7 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
667
713
|
{ name: 'Years', value: params.years?.toString() ?? '1' },
|
|
668
714
|
{ name: 'Process-Id', value: params.processId },
|
|
669
715
|
{ name: 'Purchase-Type', value: params.type || 'lease' },
|
|
716
|
+
{ name: 'Fund-From', value: params.fundFrom },
|
|
670
717
|
];
|
|
671
718
|
return this.process.send({
|
|
672
719
|
signer: this.signer,
|
|
@@ -683,13 +730,15 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
683
730
|
*/
|
|
684
731
|
async upgradeRecord(params, options) {
|
|
685
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
|
+
];
|
|
686
739
|
return this.process.send({
|
|
687
740
|
signer: this.signer,
|
|
688
|
-
tags:
|
|
689
|
-
...tags,
|
|
690
|
-
{ name: 'Action', value: 'Upgrade-Name' }, // TODO: align on Update-Record vs. Upgrade-Name (contract currently uses Upgrade-Name)
|
|
691
|
-
{ name: 'Name', value: params.name },
|
|
692
|
-
],
|
|
741
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
693
742
|
});
|
|
694
743
|
}
|
|
695
744
|
/**
|
|
@@ -703,26 +752,30 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
703
752
|
*/
|
|
704
753
|
async extendLease(params, options) {
|
|
705
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
|
+
];
|
|
706
762
|
return this.process.send({
|
|
707
763
|
signer: this.signer,
|
|
708
|
-
tags:
|
|
709
|
-
...tags,
|
|
710
|
-
{ name: 'Action', value: 'Extend-Lease' },
|
|
711
|
-
{ name: 'Name', value: params.name },
|
|
712
|
-
{ name: 'Years', value: params.years.toString() },
|
|
713
|
-
],
|
|
764
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
714
765
|
});
|
|
715
766
|
}
|
|
716
767
|
async increaseUndernameLimit(params, options) {
|
|
717
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
|
+
];
|
|
718
776
|
return this.process.send({
|
|
719
777
|
signer: this.signer,
|
|
720
|
-
tags:
|
|
721
|
-
...tags,
|
|
722
|
-
{ name: 'Action', value: 'Increase-Undername-Limit' },
|
|
723
|
-
{ name: 'Name', value: params.name },
|
|
724
|
-
{ name: 'Quantity', value: params.increaseCount.toString() },
|
|
725
|
-
],
|
|
778
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
726
779
|
});
|
|
727
780
|
}
|
|
728
781
|
/**
|
|
@@ -747,13 +800,16 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
747
800
|
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
748
801
|
});
|
|
749
802
|
}
|
|
750
|
-
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
|
+
];
|
|
751
810
|
return this.process.send({
|
|
752
811
|
signer: this.signer,
|
|
753
|
-
tags:
|
|
754
|
-
{ name: 'Action', value: 'Request-Primary-Name' },
|
|
755
|
-
{ name: 'Name', value: params.name },
|
|
756
|
-
],
|
|
812
|
+
tags: (0, arweave_js_1.pruneTags)(allTags),
|
|
757
813
|
});
|
|
758
814
|
}
|
|
759
815
|
/**
|
package/lib/cjs/types/io.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = exports.isValidIntent = exports.intentsUsingYears = exports.validIntents = void 0;
|
|
3
|
+
exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = exports.isValidFundFrom = exports.fundFromOptions = exports.isValidIntent = exports.intentsUsingYears = exports.validIntents = void 0;
|
|
4
4
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
5
5
|
exports.validIntents = [
|
|
6
6
|
'Buy-Record',
|
|
@@ -14,6 +14,11 @@ const isValidIntent = (intent) => {
|
|
|
14
14
|
return exports.validIntents.indexOf(intent) !== -1;
|
|
15
15
|
};
|
|
16
16
|
exports.isValidIntent = isValidIntent;
|
|
17
|
+
exports.fundFromOptions = ['balance', 'stakes', 'any'];
|
|
18
|
+
const isValidFundFrom = (fundFrom) => {
|
|
19
|
+
return exports.fundFromOptions.indexOf(fundFrom) !== -1;
|
|
20
|
+
};
|
|
21
|
+
exports.isValidFundFrom = isValidFundFrom;
|
|
17
22
|
// Typeguard functions
|
|
18
23
|
function isProcessConfiguration(config) {
|
|
19
24
|
return 'process' in config;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/cli/cli.js
CHANGED
|
@@ -19,11 +19,12 @@ import { program } from 'commander';
|
|
|
19
19
|
import { spawnANT } from '../node/index.js';
|
|
20
20
|
import { mARIOToken } from '../types/token.js';
|
|
21
21
|
import { version } from '../version.js';
|
|
22
|
+
import { buyRecordCLICommand, extendLeaseCLICommand, increaseUndernameLimitCLICommand, requestPrimaryNameCLICommand, upgradeRecordCLICommand, } from './commands/arnsPurchaseCommands.js';
|
|
22
23
|
import { cancelWithdrawal, decreaseDelegateStake, decreaseOperatorStake, delegateStake, increaseOperatorStake, instantWithdrawal, joinNetwork, leaveNetwork, redelegateStake, saveObservations, updateGatewaySettings, } from './commands/gatewayWriteCommands.js';
|
|
23
|
-
import { getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
|
|
24
|
+
import { getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
|
|
24
25
|
import { transfer } from './commands/transfer.js';
|
|
25
|
-
import { addressAndVaultIdOptions,
|
|
26
|
-
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions,
|
|
26
|
+
import { addressAndVaultIdOptions, antStateOptions, arnsPurchaseOptions, buyRecordOptions, decreaseDelegateStakeOptions, delegateStakeOptions, epochOptions, getVaultOptions, globalOptions, joinNetworkOptions, operatorStakeOptions, optionMap, paginationAddressOptions, paginationOptions, redelegateStakeOptions, tokenCostOptions, transferOptions, updateGatewaySettingsOptions, writeActionOptions, } from './options.js';
|
|
27
|
+
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, writeActionTagsFromOptions, } from './utils.js';
|
|
27
28
|
applyOptions(program
|
|
28
29
|
.name('ar.io')
|
|
29
30
|
.version(version)
|
|
@@ -52,7 +53,7 @@ makeCommand({
|
|
|
52
53
|
makeCommand({
|
|
53
54
|
name: 'get-gateway',
|
|
54
55
|
description: 'Get the gateway of an address',
|
|
55
|
-
options:
|
|
56
|
+
options: [optionMap.address],
|
|
56
57
|
action: getGateway,
|
|
57
58
|
});
|
|
58
59
|
makeCommand({
|
|
@@ -70,7 +71,7 @@ makeCommand({
|
|
|
70
71
|
makeCommand({
|
|
71
72
|
name: 'get-delegations',
|
|
72
73
|
description: 'Get all stake delegated to gateways from this address',
|
|
73
|
-
options:
|
|
74
|
+
options: [optionMap.address],
|
|
74
75
|
action: getDelegations,
|
|
75
76
|
});
|
|
76
77
|
makeCommand({
|
|
@@ -82,7 +83,7 @@ makeCommand({
|
|
|
82
83
|
makeCommand({
|
|
83
84
|
name: 'get-arns-record',
|
|
84
85
|
description: 'Get an ArNS record by name',
|
|
85
|
-
options:
|
|
86
|
+
options: [optionMap.name],
|
|
86
87
|
action: getArNSRecord,
|
|
87
88
|
});
|
|
88
89
|
makeCommand({
|
|
@@ -94,7 +95,7 @@ makeCommand({
|
|
|
94
95
|
makeCommand({
|
|
95
96
|
name: 'get-arns-reserved-name',
|
|
96
97
|
description: 'Get a reserved ArNS name',
|
|
97
|
-
options:
|
|
98
|
+
options: [optionMap.name],
|
|
98
99
|
action: getArNSReservedName,
|
|
99
100
|
});
|
|
100
101
|
makeCommand({
|
|
@@ -106,7 +107,7 @@ makeCommand({
|
|
|
106
107
|
makeCommand({
|
|
107
108
|
name: 'get-arns-returned-name',
|
|
108
109
|
description: 'Get an ArNS returned name by name',
|
|
109
|
-
options:
|
|
110
|
+
options: [optionMap.name],
|
|
110
111
|
action: getArNSReturnedName,
|
|
111
112
|
});
|
|
112
113
|
makeCommand({
|
|
@@ -152,10 +153,16 @@ makeCommand({
|
|
|
152
153
|
});
|
|
153
154
|
makeCommand({
|
|
154
155
|
name: 'get-token-cost',
|
|
155
|
-
description: 'Get token cost',
|
|
156
|
+
description: 'Get token cost for an intended action',
|
|
156
157
|
options: tokenCostOptions,
|
|
157
158
|
action: getTokenCost,
|
|
158
159
|
});
|
|
160
|
+
makeCommand({
|
|
161
|
+
name: 'get-cost-details',
|
|
162
|
+
description: 'Get expanded cost details for an intended action',
|
|
163
|
+
options: tokenCostOptions,
|
|
164
|
+
action: getCostDetails,
|
|
165
|
+
});
|
|
159
166
|
makeCommand({
|
|
160
167
|
name: 'list-vaults',
|
|
161
168
|
description: 'Get all wallet vaults',
|
|
@@ -168,7 +175,7 @@ makeCommand({
|
|
|
168
175
|
makeCommand({
|
|
169
176
|
name: 'get-primary-name-request',
|
|
170
177
|
description: 'Get primary name request',
|
|
171
|
-
options:
|
|
178
|
+
options: [optionMap.initiator],
|
|
172
179
|
action: (o) => readARIOFromOptions(o)
|
|
173
180
|
.getPrimaryNameRequest({
|
|
174
181
|
initiator: requiredStringFromOptions(o, 'initiator'),
|
|
@@ -188,7 +195,7 @@ makeCommand({
|
|
|
188
195
|
makeCommand({
|
|
189
196
|
name: 'get-primary-name',
|
|
190
197
|
description: 'Get primary name',
|
|
191
|
-
options: [
|
|
198
|
+
options: [optionMap.address, optionMap.name],
|
|
192
199
|
action: getPrimaryName,
|
|
193
200
|
});
|
|
194
201
|
makeCommand({
|
|
@@ -202,12 +209,12 @@ makeCommand({
|
|
|
202
209
|
makeCommand({
|
|
203
210
|
name: 'balance',
|
|
204
211
|
description: 'Get the balance of an address',
|
|
205
|
-
options:
|
|
212
|
+
options: [optionMap.address],
|
|
206
213
|
action: (options) => readARIOFromOptions(options)
|
|
207
214
|
.getBalance({ address: requiredAddressFromOptions(options) })
|
|
208
215
|
.then((result) => ({
|
|
209
216
|
address: requiredAddressFromOptions(options),
|
|
210
|
-
|
|
217
|
+
mARIOBalance: result,
|
|
211
218
|
message: `Provided address current has a balance of ${formatARIOWithCommas(new mARIOToken(result).toARIO())} ARIO`,
|
|
212
219
|
})),
|
|
213
220
|
});
|
|
@@ -222,7 +229,7 @@ makeCommand({
|
|
|
222
229
|
makeCommand({
|
|
223
230
|
name: 'get-redelegation-fee',
|
|
224
231
|
description: 'Get redelegation fee',
|
|
225
|
-
options:
|
|
232
|
+
options: [optionMap.address],
|
|
226
233
|
action: (options) => readARIOFromOptions(options).getRedelegationFee({
|
|
227
234
|
address: requiredAddressFromOptions(options),
|
|
228
235
|
}),
|
|
@@ -318,82 +325,31 @@ makeCommand({
|
|
|
318
325
|
name: 'buy-record',
|
|
319
326
|
description: 'Buy a record',
|
|
320
327
|
options: buyRecordOptions,
|
|
321
|
-
action:
|
|
322
|
-
const ario = writeARIOFromOptions(options).ario;
|
|
323
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
324
|
-
const type = recordTypeFromOptions(options);
|
|
325
|
-
const years = positiveIntegerFromOptions(options, 'years');
|
|
326
|
-
// TODO: Assert balance is sufficient for action
|
|
327
|
-
// TODO: Assert record is not already owned
|
|
328
|
-
const processId = options.processId;
|
|
329
|
-
if (processId === undefined) {
|
|
330
|
-
// TODO: Spawn ANT process, register it to ANT registry, get process ID
|
|
331
|
-
throw new Error('Process ID must be provided for buy-record');
|
|
332
|
-
}
|
|
333
|
-
await assertConfirmationPrompt(`Are you sure you want to ${type} the record ${name}?`, options);
|
|
334
|
-
return ario.buyRecord({
|
|
335
|
-
name: requiredStringFromOptions(options, 'name'),
|
|
336
|
-
processId,
|
|
337
|
-
type,
|
|
338
|
-
years,
|
|
339
|
-
});
|
|
340
|
-
},
|
|
328
|
+
action: buyRecordCLICommand,
|
|
341
329
|
});
|
|
342
330
|
makeCommand({
|
|
343
331
|
name: 'upgrade-record',
|
|
344
332
|
description: 'Upgrade the lease of a record to a permabuy',
|
|
345
|
-
options:
|
|
346
|
-
|
|
347
|
-
action: async (options) => {
|
|
348
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
349
|
-
await assertConfirmationPrompt(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, options);
|
|
350
|
-
return writeARIOFromOptions(options).ario.upgradeRecord({
|
|
351
|
-
name,
|
|
352
|
-
});
|
|
353
|
-
},
|
|
333
|
+
options: arnsPurchaseOptions,
|
|
334
|
+
action: upgradeRecordCLICommand,
|
|
354
335
|
});
|
|
355
336
|
makeCommand({
|
|
356
337
|
name: 'extend-lease',
|
|
357
338
|
description: 'Extend the lease of a record',
|
|
358
|
-
options: [...
|
|
359
|
-
action:
|
|
360
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
361
|
-
const years = requiredPositiveIntegerFromOptions(options, 'years');
|
|
362
|
-
await assertConfirmationPrompt(`Are you sure you want to extend the lease of ${name} by ${years}?`, options);
|
|
363
|
-
return writeARIOFromOptions(options).ario.extendLease({
|
|
364
|
-
name,
|
|
365
|
-
years,
|
|
366
|
-
}, writeActionTagsFromOptions(options));
|
|
367
|
-
},
|
|
339
|
+
options: [...arnsPurchaseOptions, optionMap.years],
|
|
340
|
+
action: extendLeaseCLICommand,
|
|
368
341
|
});
|
|
369
342
|
makeCommand({
|
|
370
343
|
name: 'increase-undername-limit',
|
|
371
344
|
description: 'Increase the limit of a name',
|
|
372
|
-
options: [...
|
|
373
|
-
action:
|
|
374
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
375
|
-
const increaseCount = requiredPositiveIntegerFromOptions(options, 'increaseCount');
|
|
376
|
-
await assertConfirmationPrompt(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, options);
|
|
377
|
-
return writeARIOFromOptions(options).ario.increaseUndernameLimit({
|
|
378
|
-
name,
|
|
379
|
-
increaseCount,
|
|
380
|
-
}, writeActionTagsFromOptions(options));
|
|
381
|
-
},
|
|
345
|
+
options: [...arnsPurchaseOptions, optionMap.increaseCount],
|
|
346
|
+
action: increaseUndernameLimitCLICommand,
|
|
382
347
|
});
|
|
383
348
|
makeCommand({
|
|
384
349
|
name: 'request-primary-name',
|
|
385
350
|
description: 'Request a primary name',
|
|
386
|
-
options:
|
|
387
|
-
action:
|
|
388
|
-
// TODO: Assert balance is sufficient for action?
|
|
389
|
-
// TODO: Assert name requested is not already owned
|
|
390
|
-
// TODO: More assertions?
|
|
391
|
-
const name = requiredStringFromOptions(options, 'name');
|
|
392
|
-
await assertConfirmationPrompt(`Are you sure you want to request the primary name ${name}?`, options);
|
|
393
|
-
return writeARIOFromOptions(options).ario.requestPrimaryName({
|
|
394
|
-
name,
|
|
395
|
-
});
|
|
396
|
-
},
|
|
351
|
+
options: arnsPurchaseOptions,
|
|
352
|
+
action: requestPrimaryNameCLICommand,
|
|
397
353
|
});
|
|
398
354
|
makeCommand({
|
|
399
355
|
name: 'spawn-ant',
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { assertConfirmationPrompt, assertEnoughBalanceForArNSPurchase, fundFromFromOptions, positiveIntegerFromOptions, recordTypeFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, writeARIOFromOptions, writeActionTagsFromOptions, } from '../utils.js';
|
|
2
|
+
export async function buyRecordCLICommand(o) {
|
|
3
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
4
|
+
const name = requiredStringFromOptions(o, 'name');
|
|
5
|
+
const type = recordTypeFromOptions(o);
|
|
6
|
+
const years = positiveIntegerFromOptions(o, 'years');
|
|
7
|
+
const fundFrom = fundFromFromOptions(o);
|
|
8
|
+
const processId = o.processId;
|
|
9
|
+
if (processId === undefined) {
|
|
10
|
+
// TODO: Spawn ANT process, register it to ANT registry, get process ID
|
|
11
|
+
throw new Error('Process ID must be provided for buy-record');
|
|
12
|
+
}
|
|
13
|
+
if (!o.skipConfirmation) {
|
|
14
|
+
const existingRecord = await ario.getArNSRecord({
|
|
15
|
+
name,
|
|
16
|
+
});
|
|
17
|
+
if (existingRecord !== undefined) {
|
|
18
|
+
throw new Error(`ArNS Record ${name} is already owned`);
|
|
19
|
+
}
|
|
20
|
+
await assertEnoughBalanceForArNSPurchase({
|
|
21
|
+
ario,
|
|
22
|
+
address: signerAddress,
|
|
23
|
+
costDetailsParams: {
|
|
24
|
+
intent: 'Buy-Record',
|
|
25
|
+
type,
|
|
26
|
+
name,
|
|
27
|
+
years,
|
|
28
|
+
fundFrom,
|
|
29
|
+
fromAddress: signerAddress,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
await assertConfirmationPrompt(`Are you sure you want to ${type} the record ${name}?`, o);
|
|
33
|
+
}
|
|
34
|
+
return ario.buyRecord({
|
|
35
|
+
name: requiredStringFromOptions(o, 'name'),
|
|
36
|
+
processId,
|
|
37
|
+
type,
|
|
38
|
+
years,
|
|
39
|
+
fundFrom: fundFromFromOptions(o),
|
|
40
|
+
}, writeActionTagsFromOptions(o));
|
|
41
|
+
}
|
|
42
|
+
export async function upgradeRecordCLICommand(o) {
|
|
43
|
+
const name = requiredStringFromOptions(o, 'name');
|
|
44
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
45
|
+
const fundFrom = fundFromFromOptions(o);
|
|
46
|
+
if (!o.skipConfirmation) {
|
|
47
|
+
const existingRecord = await ario.getArNSRecord({
|
|
48
|
+
name,
|
|
49
|
+
});
|
|
50
|
+
if (existingRecord === undefined) {
|
|
51
|
+
throw new Error(`ArNS Record ${name} does not exist`);
|
|
52
|
+
}
|
|
53
|
+
if (existingRecord.type === 'permabuy') {
|
|
54
|
+
throw new Error(`ArNS Record ${name} is already a permabuy`);
|
|
55
|
+
}
|
|
56
|
+
await assertEnoughBalanceForArNSPurchase({
|
|
57
|
+
ario,
|
|
58
|
+
address: signerAddress,
|
|
59
|
+
costDetailsParams: {
|
|
60
|
+
intent: 'Upgrade-Name',
|
|
61
|
+
name,
|
|
62
|
+
fundFrom,
|
|
63
|
+
fromAddress: signerAddress,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
await assertConfirmationPrompt(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, o);
|
|
67
|
+
}
|
|
68
|
+
return ario.upgradeRecord({
|
|
69
|
+
name,
|
|
70
|
+
fundFrom,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export async function extendLeaseCLICommand(o) {
|
|
74
|
+
const name = requiredStringFromOptions(o, 'name');
|
|
75
|
+
const years = requiredPositiveIntegerFromOptions(o, 'years');
|
|
76
|
+
const fundFrom = fundFromFromOptions(o);
|
|
77
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
78
|
+
if (!o.skipConfirmation) {
|
|
79
|
+
const existingRecord = await ario.getArNSRecord({
|
|
80
|
+
name,
|
|
81
|
+
});
|
|
82
|
+
if (existingRecord === undefined) {
|
|
83
|
+
throw new Error(`ArNS Record ${name} does not exist`);
|
|
84
|
+
}
|
|
85
|
+
if (existingRecord.type === 'permabuy') {
|
|
86
|
+
throw new Error(`ArNS Record ${name} is a permabuy and cannot be extended`);
|
|
87
|
+
}
|
|
88
|
+
await assertEnoughBalanceForArNSPurchase({
|
|
89
|
+
ario: ario,
|
|
90
|
+
address: signerAddress,
|
|
91
|
+
costDetailsParams: {
|
|
92
|
+
intent: 'Extend-Lease',
|
|
93
|
+
name,
|
|
94
|
+
years,
|
|
95
|
+
fundFrom,
|
|
96
|
+
fromAddress: signerAddress,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
await assertConfirmationPrompt(`Are you sure you want to extend the lease of ${name} by ${years}?`, o);
|
|
100
|
+
}
|
|
101
|
+
return ario.extendLease({
|
|
102
|
+
name,
|
|
103
|
+
years,
|
|
104
|
+
}, writeActionTagsFromOptions(o));
|
|
105
|
+
}
|
|
106
|
+
export async function increaseUndernameLimitCLICommand(o) {
|
|
107
|
+
const name = requiredStringFromOptions(o, 'name');
|
|
108
|
+
const increaseCount = requiredPositiveIntegerFromOptions(o, 'increaseCount');
|
|
109
|
+
const fundFrom = fundFromFromOptions(o);
|
|
110
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
111
|
+
if (!o.skipConfirmation) {
|
|
112
|
+
const existingRecord = await ario.getArNSRecord({
|
|
113
|
+
name,
|
|
114
|
+
});
|
|
115
|
+
if (existingRecord === undefined) {
|
|
116
|
+
throw new Error(`ArNS Record ${name} does not exist`);
|
|
117
|
+
}
|
|
118
|
+
await assertEnoughBalanceForArNSPurchase({
|
|
119
|
+
ario,
|
|
120
|
+
address: signerAddress,
|
|
121
|
+
costDetailsParams: {
|
|
122
|
+
intent: 'Increase-Undername-Limit',
|
|
123
|
+
name,
|
|
124
|
+
quantity: increaseCount,
|
|
125
|
+
fundFrom,
|
|
126
|
+
fromAddress: signerAddress,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
await assertConfirmationPrompt(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, o);
|
|
130
|
+
}
|
|
131
|
+
return ario.increaseUndernameLimit({
|
|
132
|
+
name,
|
|
133
|
+
increaseCount,
|
|
134
|
+
}, writeActionTagsFromOptions(o));
|
|
135
|
+
}
|
|
136
|
+
export async function requestPrimaryNameCLICommand(o) {
|
|
137
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
138
|
+
const fundFrom = fundFromFromOptions(o);
|
|
139
|
+
const name = requiredStringFromOptions(o, 'name');
|
|
140
|
+
if (!o.skipConfirmation) {
|
|
141
|
+
// TODO: Assert name requested is not already owned?
|
|
142
|
+
// TODO: More assertions?
|
|
143
|
+
await assertEnoughBalanceForArNSPurchase({
|
|
144
|
+
ario,
|
|
145
|
+
address: signerAddress,
|
|
146
|
+
costDetailsParams: {
|
|
147
|
+
intent: 'Primary-Name-Request',
|
|
148
|
+
name,
|
|
149
|
+
fromAddress: signerAddress,
|
|
150
|
+
fundFrom,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
await assertConfirmationPrompt(`Are you sure you want to request the primary name ${name}?`, o);
|
|
154
|
+
}
|
|
155
|
+
return ario.requestPrimaryName({
|
|
156
|
+
name,
|
|
157
|
+
fundFrom,
|
|
158
|
+
}, writeActionTagsFromOptions(o));
|
|
159
|
+
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import prompts from 'prompts';
|
|
17
17
|
import { mARIOToken } from '../../node/index.js';
|
|
18
|
-
import { assertConfirmationPrompt,
|
|
18
|
+
import { assertConfirmationPrompt, assertEnoughMARIOBalance, formatARIOWithCommas, gatewaySettingsFromOptions, redelegateParamsFromOptions, requiredAddressFromOptions, requiredMARIOFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, stringifyJsonForCLIDisplay, writeARIOFromOptions, writeActionTagsFromOptions, } from '../utils.js';
|
|
19
19
|
export async function joinNetwork(options) {
|
|
20
20
|
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
21
21
|
const mARIOQuantity = requiredMARIOFromOptions(options, 'operatorStake');
|
|
@@ -34,7 +34,11 @@ export async function joinNetwork(options) {
|
|
|
34
34
|
if (settings.operators.minStake > mARIOQuantity.valueOf()) {
|
|
35
35
|
throw new Error(`The minimum operator stake is ${formatARIOWithCommas(new mARIOToken(settings.operators.minStake).toARIO())} ARIO. Please provide a higher stake.`);
|
|
36
36
|
}
|
|
37
|
-
await
|
|
37
|
+
await assertEnoughMARIOBalance({
|
|
38
|
+
ario,
|
|
39
|
+
address: signerAddress,
|
|
40
|
+
mARIOQuantity,
|
|
41
|
+
});
|
|
38
42
|
await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${formatARIOWithCommas(mARIOQuantity.toARIO())} ARIO to join the AR.IO network\nAre you sure?\n`, options);
|
|
39
43
|
}
|
|
40
44
|
const result = await ario.joinNetwork(settings, writeActionTagsFromOptions(options));
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { intentsUsingYears, isValidIntent, validIntents, } from '../../types/io.js';
|
|
17
1
|
import { mARIOToken } from '../../types/token.js';
|
|
18
|
-
import { addressFromOptions, epochInputFromOptions, formatARIOWithCommas, paginationParamsFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredStringFromOptions, } from '../utils.js';
|
|
2
|
+
import { addressFromOptions, epochInputFromOptions, formatARIOWithCommas, fundFromFromOptions, getTokenCostParamsFromOptions, paginationParamsFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredStringFromOptions, } from '../utils.js';
|
|
19
3
|
export async function getGateway(o) {
|
|
20
4
|
const address = requiredAddressFromOptions(o);
|
|
21
5
|
const gateway = await readARIOFromOptions(o).getGateway({
|
|
@@ -115,32 +99,26 @@ export async function getPrescribedNames(o) {
|
|
|
115
99
|
: { message: `No prescribed names found for epoch ${epoch}` };
|
|
116
100
|
}
|
|
117
101
|
export async function getTokenCost(o) {
|
|
118
|
-
o.
|
|
119
|
-
o.type ??= 'lease';
|
|
120
|
-
if (!isValidIntent(o.intent)) {
|
|
121
|
-
throw new Error(`Invalid intent. Valid intents are: ${validIntents.join(', ')}`);
|
|
122
|
-
}
|
|
123
|
-
if (o.type !== 'lease' && o.type !== 'permabuy') {
|
|
124
|
-
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
125
|
-
}
|
|
126
|
-
if (o.type === 'lease' &&
|
|
127
|
-
intentsUsingYears.includes(o.intent) &&
|
|
128
|
-
o.years === undefined) {
|
|
129
|
-
throw new Error('Years is required for lease type');
|
|
130
|
-
}
|
|
131
|
-
const tokenCost = await readARIOFromOptions(o).getTokenCost({
|
|
132
|
-
type: o.type,
|
|
133
|
-
quantity: o.quantity !== undefined ? +o.quantity : undefined,
|
|
134
|
-
years: o.years !== undefined ? +o.years : undefined,
|
|
135
|
-
intent: o.intent,
|
|
136
|
-
name: requiredStringFromOptions(o, 'name'),
|
|
137
|
-
});
|
|
102
|
+
const tokenCost = await readARIOFromOptions(o).getTokenCost(getTokenCostParamsFromOptions(o));
|
|
138
103
|
const output = {
|
|
139
|
-
|
|
104
|
+
mARIOTokenCost: tokenCost,
|
|
140
105
|
message: `The cost of the provided action is ${formatARIOWithCommas(new mARIOToken(tokenCost).toARIO())} ARIO`,
|
|
141
106
|
};
|
|
142
107
|
return output;
|
|
143
108
|
}
|
|
109
|
+
export async function getCostDetails(o) {
|
|
110
|
+
const costDetails = await readARIOFromOptions(o).getCostDetails({
|
|
111
|
+
...getTokenCostParamsFromOptions(o),
|
|
112
|
+
fundFrom: fundFromFromOptions(o),
|
|
113
|
+
});
|
|
114
|
+
const output = {
|
|
115
|
+
...costDetails,
|
|
116
|
+
message: `The cost of the provided action is ${formatARIOWithCommas(new mARIOToken(costDetails.tokenCost).toARIO())} ARIO${costDetails.fundingPlan && costDetails.fundingPlan.shortfall > 0
|
|
117
|
+
? `. Insufficient funds for action. There is a shortfall of ${formatARIOWithCommas(new mARIOToken(costDetails.fundingPlan.shortfall).toARIO())} ARIO`
|
|
118
|
+
: ''}`,
|
|
119
|
+
};
|
|
120
|
+
return output;
|
|
121
|
+
}
|
|
144
122
|
export async function getPrimaryName(o) {
|
|
145
123
|
const address = addressFromOptions(o);
|
|
146
124
|
const name = o.name;
|