@ar.io/sdk 2.7.0-alpha.6 → 3.0.0-alpha.1
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 +155 -239
- package/bundles/web.bundle.min.js +74 -74
- package/lib/cjs/cli/cli.js +32 -38
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +39 -39
- package/lib/cjs/cli/commands/readCommands.js +28 -45
- package/lib/cjs/cli/commands/transfer.js +7 -7
- package/lib/cjs/cli/options.js +4 -11
- package/lib/cjs/cli/utils.js +22 -22
- package/lib/cjs/common/ant.js +18 -14
- package/lib/cjs/common/io.js +15 -68
- package/lib/cjs/constants.js +5 -5
- package/lib/cjs/types/token.js +14 -14
- package/lib/cjs/utils/processes.js +4 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +36 -42
- package/lib/esm/cli/commands/gatewayWriteCommands.js +41 -41
- package/lib/esm/cli/commands/readCommands.js +27 -43
- package/lib/esm/cli/commands/transfer.js +8 -8
- package/lib/esm/cli/options.js +3 -10
- package/lib/esm/cli/utils.js +18 -18
- package/lib/esm/common/ant.js +18 -14
- package/lib/esm/common/io.js +12 -65
- package/lib/esm/constants.js +4 -4
- package/lib/esm/types/token.js +12 -12
- package/lib/esm/utils/processes.js +6 -6
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/readCommands.d.ts +3 -4
- package/lib/types/cli/options.d.ts +1 -5
- package/lib/types/cli/types.d.ts +2 -4
- package/lib/types/cli/utils.d.ts +10 -10
- package/lib/types/common/ant.d.ts +14 -14
- package/lib/types/common/io.d.ts +20 -45
- package/lib/types/constants.d.ts +4 -4
- package/lib/types/types/ant.d.ts +8 -8
- package/lib/types/types/io.d.ts +14 -49
- package/lib/types/types/token.d.ts +8 -8
- package/lib/types/utils/processes.d.ts +4 -4
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/esm/cli/cli.js
CHANGED
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
// eslint-disable-next-line header/header -- This is a CLI file
|
|
18
18
|
import { program } from 'commander';
|
|
19
19
|
import { spawnANT } from '../node/index.js';
|
|
20
|
-
import {
|
|
20
|
+
import { mARIOToken } from '../types/token.js';
|
|
21
21
|
import { version } from '../version.js';
|
|
22
22
|
import { cancelWithdrawal, decreaseDelegateStake, decreaseOperatorStake, delegateStake, increaseOperatorStake, instantWithdrawal, joinNetwork, leaveNetwork, redelegateStake, saveObservations, updateGatewaySettings, } from './commands/gatewayWriteCommands.js';
|
|
23
|
-
import { getAllowedDelegates,
|
|
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
24
|
import { transfer } from './commands/transfer.js';
|
|
25
|
-
import { addressAndVaultIdOptions, addressOptions, antStateOptions,
|
|
26
|
-
import { applyOptions, assertConfirmationPrompt, epochInputFromOptions,
|
|
25
|
+
import { addressAndVaultIdOptions, addressOptions, antStateOptions, buyRecordOptions, decreaseDelegateStakeOptions, delegateStakeOptions, epochOptions, getVaultOptions, globalOptions, initiatorOptions, joinNetworkOptions, nameOptions, nameWriteOptions, operatorStakeOptions, optionMap, paginationAddressOptions, paginationOptions, redelegateStakeOptions, tokenCostOptions, transferOptions, updateGatewaySettingsOptions, writeActionOptions, } from './options.js';
|
|
26
|
+
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, positiveIntegerFromOptions, readANTFromOptions, readARIOFromOptions, recordTypeFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredPositiveIntegerFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, writeARIOFromOptions, writeActionTagsFromOptions, } from './utils.js';
|
|
27
27
|
applyOptions(program
|
|
28
28
|
.name('ar.io')
|
|
29
29
|
.version(version)
|
|
@@ -32,22 +32,22 @@ applyOptions(program
|
|
|
32
32
|
makeCommand({
|
|
33
33
|
name: 'info',
|
|
34
34
|
description: 'Get network info',
|
|
35
|
-
action: (options) =>
|
|
35
|
+
action: (options) => readARIOFromOptions(options).getInfo(),
|
|
36
36
|
});
|
|
37
37
|
makeCommand({
|
|
38
38
|
name: 'token-supply',
|
|
39
39
|
description: 'Get the total token supply',
|
|
40
|
-
action: (options) =>
|
|
40
|
+
action: (options) => readARIOFromOptions(options).getTokenSupply(),
|
|
41
41
|
});
|
|
42
42
|
makeCommand({
|
|
43
43
|
name: 'get-registration-fees',
|
|
44
44
|
description: 'Get registration fees',
|
|
45
|
-
action: (options) =>
|
|
45
|
+
action: (options) => readARIOFromOptions(options).getRegistrationFees(),
|
|
46
46
|
});
|
|
47
47
|
makeCommand({
|
|
48
48
|
name: 'get-demand-factor',
|
|
49
49
|
description: 'Get demand factor',
|
|
50
|
-
action: (options) =>
|
|
50
|
+
action: (options) => readARIOFromOptions(options).getDemandFactor(),
|
|
51
51
|
});
|
|
52
52
|
makeCommand({
|
|
53
53
|
name: 'get-gateway',
|
|
@@ -104,22 +104,16 @@ makeCommand({
|
|
|
104
104
|
action: listArNSReservedNames,
|
|
105
105
|
});
|
|
106
106
|
makeCommand({
|
|
107
|
-
name: 'get-arns-
|
|
108
|
-
description: 'Get an ArNS
|
|
107
|
+
name: 'get-arns-returned-name',
|
|
108
|
+
description: 'Get an ArNS returned name by name',
|
|
109
109
|
options: nameOptions,
|
|
110
|
-
action:
|
|
110
|
+
action: getArNSReturnedName,
|
|
111
111
|
});
|
|
112
112
|
makeCommand({
|
|
113
|
-
name: 'list-arns-
|
|
114
|
-
description: 'Get all ArNS
|
|
113
|
+
name: 'list-arns-returned-names',
|
|
114
|
+
description: 'Get all ArNS recently returned names',
|
|
115
115
|
options: paginationOptions,
|
|
116
|
-
action:
|
|
117
|
-
});
|
|
118
|
-
makeCommand({
|
|
119
|
-
name: 'get-arns-auction-prices',
|
|
120
|
-
description: 'Get ArNS auction prices',
|
|
121
|
-
options: arNSAuctionPricesOptions,
|
|
122
|
-
action: getArNSAuctionPrices,
|
|
116
|
+
action: listArNSReturnedNames,
|
|
123
117
|
});
|
|
124
118
|
makeCommand({
|
|
125
119
|
name: 'get-epoch',
|
|
@@ -130,7 +124,7 @@ makeCommand({
|
|
|
130
124
|
makeCommand({
|
|
131
125
|
name: 'get-current-epoch',
|
|
132
126
|
description: 'Get current epoch data',
|
|
133
|
-
action: (options) =>
|
|
127
|
+
action: (options) => readARIOFromOptions(options).getCurrentEpoch(),
|
|
134
128
|
});
|
|
135
129
|
makeCommand({
|
|
136
130
|
name: 'get-prescribed-observers',
|
|
@@ -148,13 +142,13 @@ makeCommand({
|
|
|
148
142
|
name: 'get-observations',
|
|
149
143
|
description: 'Get observations for an epoch',
|
|
150
144
|
options: epochOptions,
|
|
151
|
-
action: (o) =>
|
|
145
|
+
action: (o) => readARIOFromOptions(o).getObservations(epochInputFromOptions(o)),
|
|
152
146
|
});
|
|
153
147
|
makeCommand({
|
|
154
148
|
name: 'get-distributions',
|
|
155
149
|
description: 'Get distributions for an epoch',
|
|
156
150
|
options: epochOptions,
|
|
157
|
-
action: (o) =>
|
|
151
|
+
action: (o) => readARIOFromOptions(o).getDistributions(epochInputFromOptions(o)),
|
|
158
152
|
});
|
|
159
153
|
makeCommand({
|
|
160
154
|
name: 'get-token-cost',
|
|
@@ -166,7 +160,7 @@ makeCommand({
|
|
|
166
160
|
name: 'list-vaults',
|
|
167
161
|
description: 'Get all wallet vaults',
|
|
168
162
|
options: paginationOptions,
|
|
169
|
-
action: (o) =>
|
|
163
|
+
action: (o) => readARIOFromOptions(o)
|
|
170
164
|
.getVaults(paginationParamsFromOptions(o))
|
|
171
165
|
.then((result) => result.items.length ? result : { message: 'No vaults found' }),
|
|
172
166
|
});
|
|
@@ -175,7 +169,7 @@ makeCommand({
|
|
|
175
169
|
name: 'get-primary-name-request',
|
|
176
170
|
description: 'Get primary name request',
|
|
177
171
|
options: initiatorOptions,
|
|
178
|
-
action: (o) =>
|
|
172
|
+
action: (o) => readARIOFromOptions(o)
|
|
179
173
|
.getPrimaryNameRequest({
|
|
180
174
|
initiator: requiredStringFromOptions(o, 'initiator'),
|
|
181
175
|
})
|
|
@@ -187,7 +181,7 @@ makeCommand({
|
|
|
187
181
|
name: 'list-primary-name-requests',
|
|
188
182
|
description: 'Get primary name requests',
|
|
189
183
|
options: paginationOptions,
|
|
190
|
-
action: (o) =>
|
|
184
|
+
action: (o) => readARIOFromOptions(o)
|
|
191
185
|
.getPrimaryNameRequests(paginationParamsFromOptions(o))
|
|
192
186
|
.then((result) => result.items.length ? result : { message: 'No requests found' }),
|
|
193
187
|
});
|
|
@@ -201,7 +195,7 @@ makeCommand({
|
|
|
201
195
|
name: 'list-primary-names',
|
|
202
196
|
description: 'Get primary names',
|
|
203
197
|
options: paginationOptions,
|
|
204
|
-
action: (o) =>
|
|
198
|
+
action: (o) => readARIOFromOptions(o)
|
|
205
199
|
.getPrimaryNames(paginationParamsFromOptions(o))
|
|
206
200
|
.then((result) => result.items.length ? result : { message: 'No names found' }),
|
|
207
201
|
});
|
|
@@ -209,19 +203,19 @@ makeCommand({
|
|
|
209
203
|
name: 'balance',
|
|
210
204
|
description: 'Get the balance of an address',
|
|
211
205
|
options: addressOptions,
|
|
212
|
-
action: (options) =>
|
|
206
|
+
action: (options) => readARIOFromOptions(options)
|
|
213
207
|
.getBalance({ address: requiredAddressFromOptions(options) })
|
|
214
208
|
.then((result) => ({
|
|
215
209
|
address: requiredAddressFromOptions(options),
|
|
216
210
|
mIOBalance: result,
|
|
217
|
-
message: `Provided address current has a balance of ${
|
|
211
|
+
message: `Provided address current has a balance of ${formatARIOWithCommas(new mARIOToken(result).toARIO())} ARIO`,
|
|
218
212
|
})),
|
|
219
213
|
});
|
|
220
214
|
makeCommand({
|
|
221
215
|
name: 'list-balances',
|
|
222
216
|
description: 'List all balances',
|
|
223
217
|
options: paginationOptions,
|
|
224
|
-
action: (o) =>
|
|
218
|
+
action: (o) => readARIOFromOptions(o)
|
|
225
219
|
.getBalances(paginationParamsFromOptions(o))
|
|
226
220
|
.then((result) => result.items.length ? result : { message: 'No balances found' }),
|
|
227
221
|
});
|
|
@@ -229,7 +223,7 @@ makeCommand({
|
|
|
229
223
|
name: 'get-redelegation-fee',
|
|
230
224
|
description: 'Get redelegation fee',
|
|
231
225
|
options: addressOptions,
|
|
232
|
-
action: (options) =>
|
|
226
|
+
action: (options) => readARIOFromOptions(options).getRedelegationFee({
|
|
233
227
|
address: requiredAddressFromOptions(options),
|
|
234
228
|
}),
|
|
235
229
|
});
|
|
@@ -247,7 +241,7 @@ makeCommand({
|
|
|
247
241
|
});
|
|
248
242
|
makeCommand({
|
|
249
243
|
name: 'transfer',
|
|
250
|
-
description: 'Transfer
|
|
244
|
+
description: 'Transfer ARIO to another address',
|
|
251
245
|
options: transferOptions,
|
|
252
246
|
action: transfer,
|
|
253
247
|
});
|
|
@@ -325,7 +319,7 @@ makeCommand({
|
|
|
325
319
|
description: 'Buy a record',
|
|
326
320
|
options: buyRecordOptions,
|
|
327
321
|
action: async (options) => {
|
|
328
|
-
const
|
|
322
|
+
const ario = writeARIOFromOptions(options).ario;
|
|
329
323
|
const name = requiredStringFromOptions(options, 'name');
|
|
330
324
|
const type = recordTypeFromOptions(options);
|
|
331
325
|
const years = positiveIntegerFromOptions(options, 'years');
|
|
@@ -337,7 +331,7 @@ makeCommand({
|
|
|
337
331
|
throw new Error('Process ID must be provided for buy-record');
|
|
338
332
|
}
|
|
339
333
|
await assertConfirmationPrompt(`Are you sure you want to ${type} the record ${name}?`, options);
|
|
340
|
-
return
|
|
334
|
+
return ario.buyRecord({
|
|
341
335
|
name: requiredStringFromOptions(options, 'name'),
|
|
342
336
|
processId,
|
|
343
337
|
type,
|
|
@@ -353,7 +347,7 @@ makeCommand({
|
|
|
353
347
|
action: async (options) => {
|
|
354
348
|
const name = requiredStringFromOptions(options, 'name');
|
|
355
349
|
await assertConfirmationPrompt(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, options);
|
|
356
|
-
return
|
|
350
|
+
return writeARIOFromOptions(options).ario.upgradeRecord({
|
|
357
351
|
name,
|
|
358
352
|
});
|
|
359
353
|
},
|
|
@@ -366,7 +360,7 @@ makeCommand({
|
|
|
366
360
|
const name = requiredStringFromOptions(options, 'name');
|
|
367
361
|
const years = requiredPositiveIntegerFromOptions(options, 'years');
|
|
368
362
|
await assertConfirmationPrompt(`Are you sure you want to extend the lease of ${name} by ${years}?`, options);
|
|
369
|
-
return
|
|
363
|
+
return writeARIOFromOptions(options).ario.extendLease({
|
|
370
364
|
name,
|
|
371
365
|
years,
|
|
372
366
|
}, writeActionTagsFromOptions(options));
|
|
@@ -380,7 +374,7 @@ makeCommand({
|
|
|
380
374
|
const name = requiredStringFromOptions(options, 'name');
|
|
381
375
|
const increaseCount = requiredPositiveIntegerFromOptions(options, 'increaseCount');
|
|
382
376
|
await assertConfirmationPrompt(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, options);
|
|
383
|
-
return
|
|
377
|
+
return writeARIOFromOptions(options).ario.increaseUndernameLimit({
|
|
384
378
|
name,
|
|
385
379
|
increaseCount,
|
|
386
380
|
}, writeActionTagsFromOptions(options));
|
|
@@ -396,7 +390,7 @@ makeCommand({
|
|
|
396
390
|
// TODO: More assertions?
|
|
397
391
|
const name = requiredStringFromOptions(options, 'name');
|
|
398
392
|
await assertConfirmationPrompt(`Are you sure you want to request the primary name ${name}?`, options);
|
|
399
|
-
return
|
|
393
|
+
return writeARIOFromOptions(options).ario.requestPrimaryName({
|
|
400
394
|
name,
|
|
401
395
|
});
|
|
402
396
|
},
|
|
@@ -645,7 +639,7 @@ makeCommand({
|
|
|
645
639
|
await assertConfirmationPrompt(`Are you sure you want to release the name ${name} back to the protocol?`, options);
|
|
646
640
|
return writeANTFromOptions(options).releaseName({
|
|
647
641
|
name,
|
|
648
|
-
|
|
642
|
+
arioProcessId: arioProcessIdFromOptions(options),
|
|
649
643
|
}, writeActionTagsFromOptions(options));
|
|
650
644
|
},
|
|
651
645
|
});
|
|
@@ -664,7 +658,7 @@ makeCommand({
|
|
|
664
658
|
await assertConfirmationPrompt(`Are you sure you want to reassign the name ${name} to ANT process ${targetProcess}?`, options);
|
|
665
659
|
return writeANTFromOptions(options).reassignName({
|
|
666
660
|
name,
|
|
667
|
-
|
|
661
|
+
arioProcessId: arioProcessIdFromOptions(options),
|
|
668
662
|
antProcessId: targetProcess,
|
|
669
663
|
}, writeActionTagsFromOptions(options));
|
|
670
664
|
},
|
|
@@ -685,7 +679,7 @@ makeCommand({
|
|
|
685
679
|
return writeANTFromOptions(options).approvePrimaryNameRequest({
|
|
686
680
|
name,
|
|
687
681
|
address,
|
|
688
|
-
|
|
682
|
+
arioProcessId: arioProcessIdFromOptions(options),
|
|
689
683
|
}, writeActionTagsFromOptions(options));
|
|
690
684
|
},
|
|
691
685
|
});
|
|
@@ -698,7 +692,7 @@ makeCommand({
|
|
|
698
692
|
await assertConfirmationPrompt(`Are you sure you want to remove the primary names ${names}?`, options);
|
|
699
693
|
return writeANTFromOptions(options).removePrimaryNames({
|
|
700
694
|
names,
|
|
701
|
-
|
|
695
|
+
arioProcessId: arioProcessIdFromOptions(options),
|
|
702
696
|
}, writeActionTagsFromOptions(options));
|
|
703
697
|
},
|
|
704
698
|
});
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import prompts from 'prompts';
|
|
17
|
-
import {
|
|
18
|
-
import { assertConfirmationPrompt, assertEnoughBalance,
|
|
17
|
+
import { mARIOToken } from '../../node/index.js';
|
|
18
|
+
import { assertConfirmationPrompt, assertEnoughBalance, formatARIOWithCommas, gatewaySettingsFromOptions, redelegateParamsFromOptions, requiredAddressFromOptions, requiredMIOFromOptions as requiredMARIOFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, stringifyJsonForCLIDisplay, writeARIOFromOptions, writeActionTagsFromOptions, } from '../utils.js';
|
|
19
19
|
export async function joinNetwork(options) {
|
|
20
|
-
const {
|
|
20
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
21
21
|
const mARIOQuantity = requiredMARIOFromOptions(options, 'operatorStake');
|
|
22
22
|
const settings = {
|
|
23
23
|
...gatewaySettingsFromOptions(options),
|
|
@@ -30,14 +30,14 @@ export async function joinNetwork(options) {
|
|
|
30
30
|
throw new Error('FQDN is required. Please provide a --fqdn for your node.');
|
|
31
31
|
}
|
|
32
32
|
if (!options.skipConfirmation) {
|
|
33
|
-
const settings = await
|
|
33
|
+
const settings = await ario.getGatewayRegistrySettings();
|
|
34
34
|
if (settings.operators.minStake > mARIOQuantity.valueOf()) {
|
|
35
|
-
throw new Error(`The minimum operator stake is ${
|
|
35
|
+
throw new Error(`The minimum operator stake is ${formatARIOWithCommas(new mARIOToken(settings.operators.minStake).toARIO())} IO. Please provide a higher stake.`);
|
|
36
36
|
}
|
|
37
|
-
await assertEnoughBalance(
|
|
38
|
-
await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${
|
|
37
|
+
await assertEnoughBalance(ario, signerAddress, mARIOQuantity.toARIO());
|
|
38
|
+
await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${formatARIOWithCommas(mARIOQuantity.toARIO())} IO to join the AR.IO network\nAre you sure?\n`, options);
|
|
39
39
|
}
|
|
40
|
-
const result = await
|
|
40
|
+
const result = await ario.joinNetwork(settings, writeActionTagsFromOptions(options));
|
|
41
41
|
const output = {
|
|
42
42
|
joinNetworkResult: result,
|
|
43
43
|
joinedAddress: signerAddress,
|
|
@@ -46,14 +46,14 @@ export async function joinNetwork(options) {
|
|
|
46
46
|
return output;
|
|
47
47
|
}
|
|
48
48
|
export async function updateGatewaySettings(options) {
|
|
49
|
-
const {
|
|
49
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
50
50
|
const gatewaySettings = gatewaySettingsFromOptions(options);
|
|
51
51
|
if (Object.keys(gatewaySettings).length === 0) {
|
|
52
52
|
// TODO: The contract accepts empty Update-Gateway-Settings actions, but we'll throw in the CLI for now
|
|
53
53
|
throw new Error('No gateway settings provided');
|
|
54
54
|
}
|
|
55
55
|
await assertConfirmationPrompt(`Gateway Settings:\n\n${stringifyJsonForCLIDisplay(gatewaySettings)}\n\nYou are about to update your gateway settings to the above\nAre you sure?\n`, options);
|
|
56
|
-
const result = await
|
|
56
|
+
const result = await ario.updateGatewaySettings(gatewaySettings, writeActionTagsFromOptions(options));
|
|
57
57
|
const output = {
|
|
58
58
|
updateGatewaySettingsResult: result,
|
|
59
59
|
updatedGatewayAddress: signerAddress,
|
|
@@ -62,9 +62,9 @@ export async function updateGatewaySettings(options) {
|
|
|
62
62
|
return output;
|
|
63
63
|
}
|
|
64
64
|
export async function leaveNetwork(options) {
|
|
65
|
-
const {
|
|
65
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
66
66
|
if (!options.skipConfirmation) {
|
|
67
|
-
const gateway = await
|
|
67
|
+
const gateway = await ario.getGateway({ address: signerAddress });
|
|
68
68
|
if (!gateway) {
|
|
69
69
|
throw new Error(`Gateway not found for address: ${signerAddress}`);
|
|
70
70
|
}
|
|
@@ -73,21 +73,21 @@ export async function leaveNetwork(options) {
|
|
|
73
73
|
'\n\n' +
|
|
74
74
|
'Are you sure you want to leave the AR.IO network?', options);
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return writeARIOFromOptions(options).ario.leaveNetwork(writeActionTagsFromOptions(options));
|
|
77
77
|
}
|
|
78
78
|
export async function saveObservations(o) {
|
|
79
79
|
const failedGateways = requiredStringArrayFromOptions(o, 'failedGateways');
|
|
80
80
|
const reportTxId = requiredStringFromOptions(o, 'transactionId');
|
|
81
81
|
await assertConfirmationPrompt(`You are about to save the following failed gateways to the AR.IO network:\n\n${failedGateways.join('\n')}\n\nTransaction ID: ${reportTxId}\n\nAre you sure?`, o);
|
|
82
|
-
return
|
|
82
|
+
return writeARIOFromOptions(o).ario.saveObservations({
|
|
83
83
|
failedGateways: requiredStringArrayFromOptions(o, 'failedGateways'),
|
|
84
84
|
reportTxId: requiredStringFromOptions(o, 'transactionId'),
|
|
85
85
|
}, writeActionTagsFromOptions(o));
|
|
86
86
|
}
|
|
87
87
|
export async function increaseOperatorStake(o) {
|
|
88
88
|
const increaseQty = requiredMARIOFromOptions(o, 'operatorStake');
|
|
89
|
-
await assertConfirmationPrompt(`You are about to increase your operator stake by ${
|
|
90
|
-
return (
|
|
89
|
+
await assertConfirmationPrompt(`You are about to increase your operator stake by ${formatARIOWithCommas(increaseQty.toARIO())} IO\nAre you sure?`, o);
|
|
90
|
+
return (writeARIOFromOptions(o).ario.increaseOperatorStake({
|
|
91
91
|
increaseQty,
|
|
92
92
|
}),
|
|
93
93
|
writeActionTagsFromOptions(o));
|
|
@@ -95,8 +95,8 @@ export async function increaseOperatorStake(o) {
|
|
|
95
95
|
export async function decreaseOperatorStake(o) {
|
|
96
96
|
const decreaseQty = requiredMARIOFromOptions(o, 'operatorStake');
|
|
97
97
|
// TODO: Can assert stake is sufficient for action, and new target stake meets contract minimum
|
|
98
|
-
await assertConfirmationPrompt(`You are about to decrease your operator stake by ${
|
|
99
|
-
return
|
|
98
|
+
await assertConfirmationPrompt(`You are about to decrease your operator stake by ${formatARIOWithCommas(decreaseQty.toARIO())} IO\nAre you sure?`, o);
|
|
99
|
+
return writeARIOFromOptions(o).ario.decreaseOperatorStake({
|
|
100
100
|
decreaseQty,
|
|
101
101
|
}, writeActionTagsFromOptions(o));
|
|
102
102
|
}
|
|
@@ -104,7 +104,7 @@ export async function instantWithdrawal(o) {
|
|
|
104
104
|
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
105
105
|
const gatewayAddress = requiredAddressFromOptions(o);
|
|
106
106
|
await assertConfirmationPrompt(`You are about to instantly withdraw from vault ${vaultId} for with gateway address ${gatewayAddress}\nAre you sure?`, o);
|
|
107
|
-
return
|
|
107
|
+
return writeARIOFromOptions(o).ario.instantWithdrawal({
|
|
108
108
|
vaultId,
|
|
109
109
|
gatewayAddress,
|
|
110
110
|
}, writeActionTagsFromOptions(o));
|
|
@@ -113,21 +113,21 @@ export async function cancelWithdrawal(o) {
|
|
|
113
113
|
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
114
114
|
const gatewayAddress = requiredAddressFromOptions(o);
|
|
115
115
|
await assertConfirmationPrompt(`You are about to cancel the pending withdrawal from vault ${vaultId} for with gateway address ${gatewayAddress}\nAre you sure?`, o);
|
|
116
|
-
return
|
|
116
|
+
return writeARIOFromOptions(o).ario.cancelWithdrawal({
|
|
117
117
|
vaultId,
|
|
118
118
|
gatewayAddress,
|
|
119
119
|
}, writeActionTagsFromOptions(o));
|
|
120
120
|
}
|
|
121
121
|
export async function delegateStake(options) {
|
|
122
|
-
const {
|
|
123
|
-
const { target,
|
|
124
|
-
const
|
|
122
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
123
|
+
const { target, arioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
124
|
+
const mARIOQuantity = arioQuantity.toMARIO();
|
|
125
125
|
if (!options.skipConfirmation) {
|
|
126
|
-
const balance = await
|
|
127
|
-
if (balance <
|
|
128
|
-
throw new Error(`Insufficient
|
|
126
|
+
const balance = await ario.getBalance({ address: signerAddress });
|
|
127
|
+
if (balance < mARIOQuantity.valueOf()) {
|
|
128
|
+
throw new Error(`Insufficient ARIO balance for delegating stake. Balance available: ${new mARIOToken(balance).toARIO()} ARIO`);
|
|
129
129
|
}
|
|
130
|
-
const targetGateway = await
|
|
130
|
+
const targetGateway = await ario.getGateway({ address: target });
|
|
131
131
|
if (targetGateway === undefined) {
|
|
132
132
|
throw new Error(`Gateway not found for address: ${target}`);
|
|
133
133
|
}
|
|
@@ -139,56 +139,56 @@ export async function delegateStake(options) {
|
|
|
139
139
|
const { confirm } = await prompts({
|
|
140
140
|
type: 'confirm',
|
|
141
141
|
name: 'confirm',
|
|
142
|
-
message: `Target Gateway:\n${JSON.stringify(targetGateway, null, 2)}\n\nAre you sure you want to delegate ${
|
|
142
|
+
message: `Target Gateway:\n${JSON.stringify(targetGateway, null, 2)}\n\nAre you sure you want to delegate ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}?`,
|
|
143
143
|
});
|
|
144
144
|
if (!confirm) {
|
|
145
145
|
return { message: 'Delegate stake aborted by user' };
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
const result = await
|
|
148
|
+
const result = await ario.delegateStake({
|
|
149
149
|
target,
|
|
150
|
-
stakeQty:
|
|
150
|
+
stakeQty: arioQuantity.toMARIO(),
|
|
151
151
|
}, writeActionTagsFromOptions(options));
|
|
152
152
|
const output = {
|
|
153
153
|
senderAddress: signerAddress,
|
|
154
154
|
transferResult: result,
|
|
155
|
-
message: `Successfully delegated ${
|
|
155
|
+
message: `Successfully delegated ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}`,
|
|
156
156
|
};
|
|
157
157
|
return output;
|
|
158
158
|
}
|
|
159
159
|
export async function decreaseDelegateStake(options) {
|
|
160
|
-
const
|
|
161
|
-
const { target,
|
|
160
|
+
const ario = writeARIOFromOptions(options).ario;
|
|
161
|
+
const { target, arioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
162
162
|
const instant = options.instant ?? false;
|
|
163
163
|
// TODO: Could assert sender is a delegate with enough stake to decrease
|
|
164
164
|
// TODO: Could assert new target stake meets contract and target gateway minimums
|
|
165
165
|
// TODO: Could present confirmation prompt with any fee for instant withdrawal (50% of the stake is put back into protocol??)
|
|
166
|
-
await assertConfirmationPrompt(`Are you sure you'd like to decrease delegated stake of ${
|
|
167
|
-
const result = await
|
|
166
|
+
await assertConfirmationPrompt(`Are you sure you'd like to decrease delegated stake of ${formatARIOWithCommas(arioQuantity)} ARIO on gateway ${target}?`, options);
|
|
167
|
+
const result = await ario.decreaseDelegateStake({
|
|
168
168
|
target,
|
|
169
|
-
decreaseQty:
|
|
169
|
+
decreaseQty: arioQuantity.toMARIO(),
|
|
170
170
|
instant,
|
|
171
171
|
});
|
|
172
172
|
const output = {
|
|
173
173
|
targetGateway: target,
|
|
174
174
|
decreaseDelegateStakeResult: result,
|
|
175
|
-
message: `Successfully decreased delegated stake of ${
|
|
175
|
+
message: `Successfully decreased delegated stake of ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}`,
|
|
176
176
|
};
|
|
177
177
|
return output;
|
|
178
178
|
}
|
|
179
179
|
export async function redelegateStake(options) {
|
|
180
|
-
const
|
|
180
|
+
const ario = writeARIOFromOptions(options).ario;
|
|
181
181
|
const params = redelegateParamsFromOptions(options);
|
|
182
182
|
// TODO: Could assert target gateway exists
|
|
183
183
|
// TODO: Could do assertion on source has enough stake to redelegate
|
|
184
184
|
// TODO: Could do assertions on source/target min delegate stakes are met
|
|
185
|
-
await assertConfirmationPrompt(`Are you sure you'd like to redelegate stake of ${
|
|
186
|
-
const result = await
|
|
185
|
+
await assertConfirmationPrompt(`Are you sure you'd like to redelegate stake of ${formatARIOWithCommas(params.stakeQty.toARIO())} ARIO from ${params.source} to ${params.target}?`, options);
|
|
186
|
+
const result = await ario.redelegateStake(params);
|
|
187
187
|
const output = {
|
|
188
188
|
sourceGateway: params.source,
|
|
189
189
|
targetGateway: params.target,
|
|
190
190
|
redelegateStakeResult: result,
|
|
191
|
-
message: `Successfully re-delegated stake of ${
|
|
191
|
+
message: `Successfully re-delegated stake of ${formatARIOWithCommas(params.stakeQty.toARIO())} ARIO from ${params.source} to ${params.target}`,
|
|
192
192
|
};
|
|
193
193
|
return output;
|
|
194
194
|
}
|
|
@@ -14,22 +14,22 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { intentsUsingYears, isValidIntent, validIntents, } from '../../types/io.js';
|
|
17
|
-
import {
|
|
18
|
-
import { addressFromOptions, epochInputFromOptions,
|
|
17
|
+
import { mARIOToken } from '../../types/token.js';
|
|
18
|
+
import { addressFromOptions, epochInputFromOptions, formatARIOWithCommas, paginationParamsFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredStringFromOptions, } from '../utils.js';
|
|
19
19
|
export async function getGateway(o) {
|
|
20
20
|
const address = requiredAddressFromOptions(o);
|
|
21
|
-
const gateway = await
|
|
21
|
+
const gateway = await readARIOFromOptions(o).getGateway({
|
|
22
22
|
address,
|
|
23
23
|
});
|
|
24
24
|
return gateway ?? { message: `No gateway found for address ${address}` };
|
|
25
25
|
}
|
|
26
26
|
export async function listGateways(o) {
|
|
27
|
-
const gateways = await
|
|
27
|
+
const gateways = await readARIOFromOptions(o).getGateways(paginationParamsFromOptions(o));
|
|
28
28
|
return gateways.items.length ? gateways : { message: 'No gateways found' };
|
|
29
29
|
}
|
|
30
30
|
export async function getGatewayDelegates(o) {
|
|
31
31
|
const address = requiredAddressFromOptions(o);
|
|
32
|
-
const result = await
|
|
32
|
+
const result = await readARIOFromOptions(o).getGatewayDelegates({
|
|
33
33
|
address,
|
|
34
34
|
...paginationParamsFromOptions(o),
|
|
35
35
|
});
|
|
@@ -41,7 +41,7 @@ export async function getGatewayDelegates(o) {
|
|
|
41
41
|
}
|
|
42
42
|
export async function getDelegations(o) {
|
|
43
43
|
const address = requiredAddressFromOptions(o);
|
|
44
|
-
const result = await
|
|
44
|
+
const result = await readARIOFromOptions(o).getDelegations({
|
|
45
45
|
address,
|
|
46
46
|
...paginationParamsFromOptions(o),
|
|
47
47
|
});
|
|
@@ -53,7 +53,7 @@ export async function getDelegations(o) {
|
|
|
53
53
|
}
|
|
54
54
|
export async function getAllowedDelegates(o) {
|
|
55
55
|
const address = requiredAddressFromOptions(o);
|
|
56
|
-
const result = await
|
|
56
|
+
const result = await readARIOFromOptions(o).getAllowedDelegates({
|
|
57
57
|
address,
|
|
58
58
|
...paginationParamsFromOptions(o),
|
|
59
59
|
});
|
|
@@ -65,67 +65,51 @@ export async function getAllowedDelegates(o) {
|
|
|
65
65
|
}
|
|
66
66
|
export async function getArNSRecord(o) {
|
|
67
67
|
const name = requiredStringFromOptions(o, 'name');
|
|
68
|
-
return ((await
|
|
68
|
+
return ((await readARIOFromOptions(o).getArNSRecord({
|
|
69
69
|
name,
|
|
70
70
|
})) ?? { message: `No record found for name ${name}` });
|
|
71
71
|
}
|
|
72
72
|
export async function listArNSRecords(o) {
|
|
73
|
-
const records = await
|
|
73
|
+
const records = await readARIOFromOptions(o).getArNSRecords(paginationParamsFromOptions(o));
|
|
74
74
|
return records.items.length ? records : { message: 'No records found' };
|
|
75
75
|
}
|
|
76
76
|
export async function getArNSReservedName(o) {
|
|
77
77
|
const name = requiredStringFromOptions(o, 'name');
|
|
78
|
-
return ((await
|
|
78
|
+
return ((await readARIOFromOptions(o).getArNSReservedName({
|
|
79
79
|
name,
|
|
80
80
|
})) ?? { message: `No reserved name found for name ${name}` });
|
|
81
81
|
}
|
|
82
82
|
export async function listArNSReservedNames(o) {
|
|
83
|
-
const reservedNames = await
|
|
83
|
+
const reservedNames = await readARIOFromOptions(o).getArNSReservedNames(paginationParamsFromOptions(o));
|
|
84
84
|
return reservedNames.items.length
|
|
85
85
|
? reservedNames
|
|
86
86
|
: { message: 'No reserved names found' };
|
|
87
87
|
}
|
|
88
|
-
export async function
|
|
88
|
+
export async function getArNSReturnedName(o) {
|
|
89
89
|
const name = requiredStringFromOptions(o, 'name');
|
|
90
|
-
const result = await
|
|
91
|
-
return result ?? { message: `No
|
|
90
|
+
const result = await readARIOFromOptions(o).getArNSReturnedName({ name });
|
|
91
|
+
return result ?? { message: `No returned name found for name ${name}` };
|
|
92
92
|
}
|
|
93
|
-
export async function
|
|
94
|
-
const
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
o.type ??= 'lease';
|
|
99
|
-
if (o.type !== 'lease' && o.type !== 'permabuy') {
|
|
100
|
-
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
101
|
-
// TODY: type and years helper
|
|
102
|
-
}
|
|
103
|
-
const result = await readIOFromOptions(o).getArNSAuctionPrices({
|
|
104
|
-
name: requiredStringFromOptions(o, 'name'),
|
|
105
|
-
type: o.type,
|
|
106
|
-
// TODO: intervalMS helper, assert and format
|
|
107
|
-
intervalMs: o.intervalMs !== undefined ? +o.intervalMs : undefined,
|
|
108
|
-
// TODO: timestamp helper, assert and format
|
|
109
|
-
timestamp: o.timestamp !== undefined ? +o.timestamp : undefined,
|
|
110
|
-
// todo: assert years if 'lease'
|
|
111
|
-
years: positiveIntegerFromOptions(o, 'years'),
|
|
112
|
-
});
|
|
113
|
-
return result ?? { message: `No auction prices found` };
|
|
93
|
+
export async function listArNSReturnedNames(o) {
|
|
94
|
+
const returnedNames = await readARIOFromOptions(o).getArNSReturnedNames(paginationParamsFromOptions(o));
|
|
95
|
+
return returnedNames.items.length
|
|
96
|
+
? returnedNames
|
|
97
|
+
: { message: 'No returned names found' };
|
|
114
98
|
}
|
|
115
99
|
export async function getEpoch(o) {
|
|
116
|
-
const epoch = await
|
|
100
|
+
const epoch = await readARIOFromOptions(o).getEpoch(epochInputFromOptions(o));
|
|
117
101
|
return epoch ?? { message: `No epoch found for provided input` };
|
|
118
102
|
}
|
|
119
103
|
export async function getPrescribedObservers(o) {
|
|
120
104
|
const epoch = epochInputFromOptions(o);
|
|
121
|
-
const result = await
|
|
105
|
+
const result = await readARIOFromOptions(o).getPrescribedObservers(epoch);
|
|
122
106
|
return result?.length
|
|
123
107
|
? result
|
|
124
108
|
: { message: `No prescribed observers found for epoch ${epoch}` };
|
|
125
109
|
}
|
|
126
110
|
export async function getPrescribedNames(o) {
|
|
127
111
|
const epoch = epochInputFromOptions(o);
|
|
128
|
-
const result = await
|
|
112
|
+
const result = await readARIOFromOptions(o).getPrescribedNames(epochInputFromOptions(o));
|
|
129
113
|
return result?.length
|
|
130
114
|
? result
|
|
131
115
|
: { message: `No prescribed names found for epoch ${epoch}` };
|
|
@@ -144,7 +128,7 @@ export async function getTokenCost(o) {
|
|
|
144
128
|
o.years === undefined) {
|
|
145
129
|
throw new Error('Years is required for lease type');
|
|
146
130
|
}
|
|
147
|
-
const tokenCost = await
|
|
131
|
+
const tokenCost = await readARIOFromOptions(o).getTokenCost({
|
|
148
132
|
type: o.type,
|
|
149
133
|
quantity: o.quantity !== undefined ? +o.quantity : undefined,
|
|
150
134
|
years: o.years !== undefined ? +o.years : undefined,
|
|
@@ -153,7 +137,7 @@ export async function getTokenCost(o) {
|
|
|
153
137
|
});
|
|
154
138
|
const output = {
|
|
155
139
|
mIOTokenCost: tokenCost,
|
|
156
|
-
message: `The cost of the provided action is ${
|
|
140
|
+
message: `The cost of the provided action is ${formatARIOWithCommas(new mARIOToken(tokenCost).toARIO())} ARIO`,
|
|
157
141
|
};
|
|
158
142
|
return output;
|
|
159
143
|
}
|
|
@@ -168,14 +152,14 @@ export async function getPrimaryName(o) {
|
|
|
168
152
|
if (params === undefined) {
|
|
169
153
|
throw new Error('Either --address or --name is required');
|
|
170
154
|
}
|
|
171
|
-
const result = await
|
|
155
|
+
const result = await readARIOFromOptions(o).getPrimaryName(params);
|
|
172
156
|
return (result ?? {
|
|
173
157
|
message: `No primary name found`,
|
|
174
158
|
});
|
|
175
159
|
}
|
|
176
160
|
export async function getGatewayVaults(o) {
|
|
177
161
|
const address = requiredAddressFromOptions(o);
|
|
178
|
-
const result = await
|
|
162
|
+
const result = await readARIOFromOptions(o).getGatewayVaults({
|
|
179
163
|
address,
|
|
180
164
|
...paginationParamsFromOptions(o),
|
|
181
165
|
});
|
|
@@ -186,7 +170,7 @@ export async function getGatewayVaults(o) {
|
|
|
186
170
|
};
|
|
187
171
|
}
|
|
188
172
|
export async function getVault(o) {
|
|
189
|
-
return
|
|
173
|
+
return readARIOFromOptions(o)
|
|
190
174
|
.getVault({
|
|
191
175
|
address: requiredAddressFromOptions(o),
|
|
192
176
|
vaultId: requiredStringFromOptions(o, 'vaultId'),
|