@ar.io/sdk 3.4.0-alpha.3 → 3.4.0
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 +42 -0
- package/bundles/web.bundle.min.js +65 -65
- package/lib/cjs/cli/cli.js +18 -0
- package/lib/cjs/cli/commands/transfer.js +83 -1
- package/lib/cjs/cli/options.js +5 -1
- package/lib/cjs/cli/utils.js +15 -1
- package/lib/cjs/common/io.js +36 -0
- package/lib/cjs/types/io.js +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +19 -1
- package/lib/esm/cli/commands/transfer.js +80 -1
- package/lib/esm/cli/options.js +5 -1
- package/lib/esm/cli/utils.js +13 -0
- package/lib/esm/common/io.js +36 -0
- package/lib/esm/types/io.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/transfer.d.ts +16 -1
- package/lib/types/cli/options.d.ts +4 -0
- package/lib/types/cli/utils.d.ts +1 -0
- package/lib/types/common/io.d.ts +4 -1
- package/lib/types/types/ant.d.ts +18 -21
- package/lib/types/types/common.d.ts +2 -0
- package/lib/types/types/io.d.ts +43 -31
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/cli/cli.js
CHANGED
|
@@ -283,6 +283,24 @@ const utils_js_1 = require("./utils.js");
|
|
|
283
283
|
options: [...options_js_1.writeActionOptions, options_js_1.optionMap.vaultId, options_js_1.optionMap.recipient],
|
|
284
284
|
action: transfer_js_1.revokeVaultCLICommand,
|
|
285
285
|
});
|
|
286
|
+
(0, utils_js_1.makeCommand)({
|
|
287
|
+
name: 'create-vault',
|
|
288
|
+
description: 'Create a locked vault with balance from the sender',
|
|
289
|
+
options: [...options_js_1.writeActionOptions, options_js_1.optionMap.lockLengthMs, options_js_1.optionMap.quantity],
|
|
290
|
+
action: transfer_js_1.createVaultCLICommand,
|
|
291
|
+
});
|
|
292
|
+
(0, utils_js_1.makeCommand)({
|
|
293
|
+
name: 'extend-vault',
|
|
294
|
+
description: 'Extend the lock length of a vault as the recipient',
|
|
295
|
+
options: [...options_js_1.writeActionOptions, options_js_1.optionMap.vaultId, options_js_1.optionMap.extendLengthMs],
|
|
296
|
+
action: transfer_js_1.extendVaultCLICommand,
|
|
297
|
+
});
|
|
298
|
+
(0, utils_js_1.makeCommand)({
|
|
299
|
+
name: 'increase-vault',
|
|
300
|
+
description: 'Increase the balance of a locked vault as the recipient',
|
|
301
|
+
options: [...options_js_1.writeActionOptions, options_js_1.optionMap.vaultId, options_js_1.optionMap.quantity],
|
|
302
|
+
action: transfer_js_1.increaseVaultCLICommand,
|
|
303
|
+
});
|
|
286
304
|
(0, utils_js_1.makeCommand)({
|
|
287
305
|
name: 'join-network',
|
|
288
306
|
description: 'Join a gateway to the AR.IO network',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.revokeVaultCLICommand = exports.vaultedTransferCLICommand = exports.transferCLICommand = void 0;
|
|
3
|
+
exports.increaseVaultCLICommand = exports.extendVaultCLICommand = exports.createVaultCLICommand = exports.revokeVaultCLICommand = exports.vaultedTransferCLICommand = exports.transferCLICommand = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
async function transferCLICommand(options) {
|
|
6
6
|
const { target, arioQuantity } = (0, utils_js_1.requiredTargetAndQuantityFromOptions)(options);
|
|
@@ -33,6 +33,7 @@ async function vaultedTransferCLICommand(o) {
|
|
|
33
33
|
const recipient = (0, utils_js_1.requiredStringFromOptions)(o, 'recipient');
|
|
34
34
|
const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
|
|
35
35
|
const lockLengthMs = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'lockLengthMs');
|
|
36
|
+
(0, utils_js_1.assertLockLengthInRange)(lockLengthMs);
|
|
36
37
|
if (!o.skipConfirmation) {
|
|
37
38
|
await (0, utils_js_1.assertEnoughMARIOBalance)({
|
|
38
39
|
ario,
|
|
@@ -84,3 +85,84 @@ async function revokeVaultCLICommand(o) {
|
|
|
84
85
|
return output;
|
|
85
86
|
}
|
|
86
87
|
exports.revokeVaultCLICommand = revokeVaultCLICommand;
|
|
88
|
+
async function createVaultCLICommand(o) {
|
|
89
|
+
const mARIOQuantity = (0, utils_js_1.requiredMARIOFromOptions)(o, 'quantity');
|
|
90
|
+
const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
|
|
91
|
+
const lockLengthMs = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'lockLengthMs');
|
|
92
|
+
(0, utils_js_1.assertLockLengthInRange)(lockLengthMs);
|
|
93
|
+
if (!o.skipConfirmation) {
|
|
94
|
+
await (0, utils_js_1.assertEnoughMARIOBalance)({
|
|
95
|
+
ario,
|
|
96
|
+
address: signerAddress,
|
|
97
|
+
mARIOQuantity,
|
|
98
|
+
});
|
|
99
|
+
const confirm = await (0, utils_js_1.confirmationPrompt)(`Are you sure you want to create a vault with ${(0, utils_js_1.formatMARIOToARIOWithCommas)(mARIOQuantity)} ARIO, locked for ${lockLengthMs}ms?`);
|
|
100
|
+
if (!confirm) {
|
|
101
|
+
return { message: 'Vault creation aborted by user' };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const result = await ario.createVault({
|
|
105
|
+
quantity: mARIOQuantity,
|
|
106
|
+
lockLengthMs,
|
|
107
|
+
}, (0, utils_js_1.writeActionTagsFromOptions)(o));
|
|
108
|
+
const output = {
|
|
109
|
+
senderAddress: signerAddress,
|
|
110
|
+
transferResult: result,
|
|
111
|
+
message: `Successfully created vault with ${(0, utils_js_1.formatMARIOToARIOWithCommas)(mARIOQuantity)} ARIO`,
|
|
112
|
+
};
|
|
113
|
+
return output;
|
|
114
|
+
}
|
|
115
|
+
exports.createVaultCLICommand = createVaultCLICommand;
|
|
116
|
+
async function extendVaultCLICommand(o) {
|
|
117
|
+
const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
|
|
118
|
+
const vaultId = (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId');
|
|
119
|
+
const extendLengthMs = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'extendLengthMs');
|
|
120
|
+
(0, utils_js_1.assertLockLengthInRange)(extendLengthMs, false);
|
|
121
|
+
if (!o.skipConfirmation) {
|
|
122
|
+
const vault = await ario.getVault({ vaultId, address: signerAddress });
|
|
123
|
+
if (!vault) {
|
|
124
|
+
throw new Error(`Vault for signer '${signerAddress}' with vault id '${vaultId}' not found`);
|
|
125
|
+
}
|
|
126
|
+
const confirm = await (0, utils_js_1.confirmationPrompt)(`Are you sure you want to extend vault with id ${vaultId} for ${extendLengthMs}ms?`);
|
|
127
|
+
if (!confirm) {
|
|
128
|
+
return { message: 'Vault extension aborted by user' };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const result = await ario.extendVault({
|
|
132
|
+
vaultId,
|
|
133
|
+
extendLengthMs,
|
|
134
|
+
}, (0, utils_js_1.writeActionTagsFromOptions)(o));
|
|
135
|
+
const output = {
|
|
136
|
+
senderAddress: signerAddress,
|
|
137
|
+
transferResult: result,
|
|
138
|
+
message: `Successfully extended vault with id ${vaultId}`,
|
|
139
|
+
};
|
|
140
|
+
return output;
|
|
141
|
+
}
|
|
142
|
+
exports.extendVaultCLICommand = extendVaultCLICommand;
|
|
143
|
+
async function increaseVaultCLICommand(o) {
|
|
144
|
+
const mARIOQuantity = (0, utils_js_1.requiredMARIOFromOptions)(o, 'quantity');
|
|
145
|
+
const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
|
|
146
|
+
const vaultId = (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId');
|
|
147
|
+
if (!o.skipConfirmation) {
|
|
148
|
+
const vault = await ario.getVault({ vaultId, address: signerAddress });
|
|
149
|
+
if (!vault) {
|
|
150
|
+
throw new Error(`Vault for signer '${signerAddress}' with vault id '${vaultId}' not found`);
|
|
151
|
+
}
|
|
152
|
+
const confirm = await (0, utils_js_1.confirmationPrompt)(`Are you sure you want to increase vault with id ${vaultId} by ${(0, utils_js_1.formatMARIOToARIOWithCommas)(mARIOQuantity)} ARIO?`);
|
|
153
|
+
if (!confirm) {
|
|
154
|
+
return { message: 'Vault increase aborted by user' };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const result = await ario.increaseVault({
|
|
158
|
+
vaultId,
|
|
159
|
+
quantity: mARIOQuantity,
|
|
160
|
+
}, (0, utils_js_1.writeActionTagsFromOptions)(o));
|
|
161
|
+
const output = {
|
|
162
|
+
senderAddress: signerAddress,
|
|
163
|
+
transferResult: result,
|
|
164
|
+
message: `Successfully increased vault with id ${vaultId} by ${(0, utils_js_1.formatMARIOToARIOWithCommas)(mARIOQuantity)} ARIO`,
|
|
165
|
+
};
|
|
166
|
+
return output;
|
|
167
|
+
}
|
|
168
|
+
exports.increaseVaultCLICommand = increaseVaultCLICommand;
|
package/lib/cjs/cli/options.js
CHANGED
|
@@ -248,7 +248,11 @@ exports.optionMap = {
|
|
|
248
248
|
},
|
|
249
249
|
lockLengthMs: {
|
|
250
250
|
alias: '--lock-length-ms <lockLengthMs>',
|
|
251
|
-
description: 'The length of time in milliseconds to lock the
|
|
251
|
+
description: 'The length of time in milliseconds to lock the vault for',
|
|
252
|
+
},
|
|
253
|
+
extendLengthMs: {
|
|
254
|
+
alias: '--extend-length-ms <extendLengthMs>',
|
|
255
|
+
description: 'The length of time in milliseconds to extend the vault for',
|
|
252
256
|
},
|
|
253
257
|
recipient: {
|
|
254
258
|
alias: '--recipient <recipient>',
|
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.fundFromFromOptions = exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.booleanFromOptions = 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 = exports.defaultTtlSecondsCLI = void 0;
|
|
6
|
+
exports.assertLockLengthInRange = exports.fundFromFromOptions = exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.booleanFromOptions = 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 = exports.defaultTtlSecondsCLI = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
9
|
*
|
|
@@ -464,3 +464,17 @@ function fundFromFromOptions(o) {
|
|
|
464
464
|
return o.fundFrom ?? 'balance';
|
|
465
465
|
}
|
|
466
466
|
exports.fundFromFromOptions = fundFromFromOptions;
|
|
467
|
+
function assertLockLengthInRange(lockLengthMs, assertMin = true) {
|
|
468
|
+
const minLockLengthMs = 1209600000; // 14 days
|
|
469
|
+
const maxLockLengthMs = 378432000000; // ~12 years
|
|
470
|
+
if (lockLengthMs > maxLockLengthMs) {
|
|
471
|
+
throw new Error(`Lock length must be at most 12 years (378432000000 ms). Provided lock length: ${lockLengthMs} ms`);
|
|
472
|
+
}
|
|
473
|
+
if (!assertMin) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (lockLengthMs < minLockLengthMs) {
|
|
477
|
+
throw new Error(`Lock length must be at least 14 days (1209600000 ms). Provided lock length: ${lockLengthMs} ms`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
exports.assertLockLengthInRange = assertLockLengthInRange;
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -518,6 +518,42 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
518
518
|
signer: this.signer,
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
|
+
async createVault({ lockLengthMs, quantity }, options) {
|
|
522
|
+
const { tags = [] } = options || {};
|
|
523
|
+
return this.process.send({
|
|
524
|
+
tags: [
|
|
525
|
+
...tags,
|
|
526
|
+
{ name: 'Action', value: 'Create-Vault' },
|
|
527
|
+
{ name: 'Lock-Length', value: lockLengthMs.toString() },
|
|
528
|
+
{ name: 'Quantity', value: quantity.toString() },
|
|
529
|
+
],
|
|
530
|
+
signer: this.signer,
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
async extendVault({ vaultId, extendLengthMs }, options) {
|
|
534
|
+
const { tags = [] } = options || {};
|
|
535
|
+
return this.process.send({
|
|
536
|
+
tags: [
|
|
537
|
+
...tags,
|
|
538
|
+
{ name: 'Action', value: 'Extend-Vault' },
|
|
539
|
+
{ name: 'Vault-Id', value: vaultId },
|
|
540
|
+
{ name: 'Extend-Length', value: extendLengthMs.toString() },
|
|
541
|
+
],
|
|
542
|
+
signer: this.signer,
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
async increaseVault({ vaultId, quantity }, options) {
|
|
546
|
+
const { tags = [] } = options || {};
|
|
547
|
+
return this.process.send({
|
|
548
|
+
tags: [
|
|
549
|
+
...tags,
|
|
550
|
+
{ name: 'Action', value: 'Increase-Vault' },
|
|
551
|
+
{ name: 'Vault-Id', value: vaultId },
|
|
552
|
+
{ name: 'Quantity', value: quantity.toString() },
|
|
553
|
+
],
|
|
554
|
+
signer: this.signer,
|
|
555
|
+
});
|
|
556
|
+
}
|
|
521
557
|
async joinNetwork({ operatorStake, allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }, options) {
|
|
522
558
|
const { tags = [] } = options || {};
|
|
523
559
|
const allTags = [
|
package/lib/cjs/types/io.js
CHANGED
|
@@ -24,7 +24,7 @@ const isValidFundFrom = (fundFrom) => {
|
|
|
24
24
|
return exports.fundFromOptions.indexOf(fundFrom) !== -1;
|
|
25
25
|
};
|
|
26
26
|
exports.isValidFundFrom = isValidFundFrom;
|
|
27
|
-
//
|
|
27
|
+
// Type-guard functions
|
|
28
28
|
function isProcessConfiguration(config) {
|
|
29
29
|
return 'process' in config;
|
|
30
30
|
}
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/cli/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ import { setAntBaseNameCLICommand, setAntRecordCLICommand, } from './commands/an
|
|
|
23
23
|
import { buyRecordCLICommand, extendLeaseCLICommand, increaseUndernameLimitCLICommand, requestPrimaryNameCLICommand, upgradeRecordCLICommand, } from './commands/arnsPurchaseCommands.js';
|
|
24
24
|
import { cancelWithdrawal, decreaseDelegateStake, decreaseOperatorStake, delegateStake, increaseOperatorStake, instantWithdrawal, joinNetwork, leaveNetwork, redelegateStake, saveObservations, updateGatewaySettings, } from './commands/gatewayWriteCommands.js';
|
|
25
25
|
import { getAllGatewayVaults, getAllowedDelegates, getArNSRecord, getArNSReservedName, getArNSReturnedName, getCostDetails, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listAllDelegatesCLICommand, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
|
|
26
|
-
import { revokeVaultCLICommand, transferCLICommand, vaultedTransferCLICommand, } from './commands/transfer.js';
|
|
26
|
+
import { createVaultCLICommand, extendVaultCLICommand, increaseVaultCLICommand, revokeVaultCLICommand, transferCLICommand, vaultedTransferCLICommand, } from './commands/transfer.js';
|
|
27
27
|
import { addressAndVaultIdOptions, antStateOptions, arnsPurchaseOptions, buyRecordOptions, decreaseDelegateStakeOptions, delegateStakeOptions, epochOptions, getVaultOptions, globalOptions, joinNetworkOptions, operatorStakeOptions, optionMap, paginationAddressOptions, paginationOptions, redelegateStakeOptions, setAntBaseNameOptions, setAntUndernameOptions, tokenCostOptions, transferOptions, updateGatewaySettingsOptions, vaultedTransferOptions, writeActionOptions, } from './options.js';
|
|
28
28
|
import { applyOptions, arioProcessIdFromOptions, assertConfirmationPrompt, epochInputFromOptions, formatARIOWithCommas, getANTStateFromOptions, getLoggerFromOptions, makeCommand, paginationParamsFromOptions, readANTFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredAoSignerFromOptions, requiredProcessIdFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, writeANTFromOptions, writeActionTagsFromOptions, } from './utils.js';
|
|
29
29
|
applyOptions(program
|
|
@@ -281,6 +281,24 @@ makeCommand({
|
|
|
281
281
|
options: [...writeActionOptions, optionMap.vaultId, optionMap.recipient],
|
|
282
282
|
action: revokeVaultCLICommand,
|
|
283
283
|
});
|
|
284
|
+
makeCommand({
|
|
285
|
+
name: 'create-vault',
|
|
286
|
+
description: 'Create a locked vault with balance from the sender',
|
|
287
|
+
options: [...writeActionOptions, optionMap.lockLengthMs, optionMap.quantity],
|
|
288
|
+
action: createVaultCLICommand,
|
|
289
|
+
});
|
|
290
|
+
makeCommand({
|
|
291
|
+
name: 'extend-vault',
|
|
292
|
+
description: 'Extend the lock length of a vault as the recipient',
|
|
293
|
+
options: [...writeActionOptions, optionMap.vaultId, optionMap.extendLengthMs],
|
|
294
|
+
action: extendVaultCLICommand,
|
|
295
|
+
});
|
|
296
|
+
makeCommand({
|
|
297
|
+
name: 'increase-vault',
|
|
298
|
+
description: 'Increase the balance of a locked vault as the recipient',
|
|
299
|
+
options: [...writeActionOptions, optionMap.vaultId, optionMap.quantity],
|
|
300
|
+
action: increaseVaultCLICommand,
|
|
301
|
+
});
|
|
284
302
|
makeCommand({
|
|
285
303
|
name: 'join-network',
|
|
286
304
|
description: 'Join a gateway to the AR.IO network',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertEnoughMARIOBalance, confirmationPrompt, formatARIOWithCommas, formatMARIOToARIOWithCommas, requiredMARIOFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, writeARIOFromOptions, writeActionTagsFromOptions, } from '../utils.js';
|
|
1
|
+
import { assertEnoughMARIOBalance, assertLockLengthInRange, confirmationPrompt, formatARIOWithCommas, formatMARIOToARIOWithCommas, requiredMARIOFromOptions, requiredPositiveIntegerFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, writeARIOFromOptions, writeActionTagsFromOptions, } from '../utils.js';
|
|
2
2
|
export async function transferCLICommand(options) {
|
|
3
3
|
const { target, arioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
4
4
|
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
@@ -29,6 +29,7 @@ export async function vaultedTransferCLICommand(o) {
|
|
|
29
29
|
const recipient = requiredStringFromOptions(o, 'recipient');
|
|
30
30
|
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
31
31
|
const lockLengthMs = requiredPositiveIntegerFromOptions(o, 'lockLengthMs');
|
|
32
|
+
assertLockLengthInRange(lockLengthMs);
|
|
32
33
|
if (!o.skipConfirmation) {
|
|
33
34
|
await assertEnoughMARIOBalance({
|
|
34
35
|
ario,
|
|
@@ -78,3 +79,81 @@ export async function revokeVaultCLICommand(o) {
|
|
|
78
79
|
};
|
|
79
80
|
return output;
|
|
80
81
|
}
|
|
82
|
+
export async function createVaultCLICommand(o) {
|
|
83
|
+
const mARIOQuantity = requiredMARIOFromOptions(o, 'quantity');
|
|
84
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
85
|
+
const lockLengthMs = requiredPositiveIntegerFromOptions(o, 'lockLengthMs');
|
|
86
|
+
assertLockLengthInRange(lockLengthMs);
|
|
87
|
+
if (!o.skipConfirmation) {
|
|
88
|
+
await assertEnoughMARIOBalance({
|
|
89
|
+
ario,
|
|
90
|
+
address: signerAddress,
|
|
91
|
+
mARIOQuantity,
|
|
92
|
+
});
|
|
93
|
+
const confirm = await confirmationPrompt(`Are you sure you want to create a vault with ${formatMARIOToARIOWithCommas(mARIOQuantity)} ARIO, locked for ${lockLengthMs}ms?`);
|
|
94
|
+
if (!confirm) {
|
|
95
|
+
return { message: 'Vault creation aborted by user' };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const result = await ario.createVault({
|
|
99
|
+
quantity: mARIOQuantity,
|
|
100
|
+
lockLengthMs,
|
|
101
|
+
}, writeActionTagsFromOptions(o));
|
|
102
|
+
const output = {
|
|
103
|
+
senderAddress: signerAddress,
|
|
104
|
+
transferResult: result,
|
|
105
|
+
message: `Successfully created vault with ${formatMARIOToARIOWithCommas(mARIOQuantity)} ARIO`,
|
|
106
|
+
};
|
|
107
|
+
return output;
|
|
108
|
+
}
|
|
109
|
+
export async function extendVaultCLICommand(o) {
|
|
110
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
111
|
+
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
112
|
+
const extendLengthMs = requiredPositiveIntegerFromOptions(o, 'extendLengthMs');
|
|
113
|
+
assertLockLengthInRange(extendLengthMs, false);
|
|
114
|
+
if (!o.skipConfirmation) {
|
|
115
|
+
const vault = await ario.getVault({ vaultId, address: signerAddress });
|
|
116
|
+
if (!vault) {
|
|
117
|
+
throw new Error(`Vault for signer '${signerAddress}' with vault id '${vaultId}' not found`);
|
|
118
|
+
}
|
|
119
|
+
const confirm = await confirmationPrompt(`Are you sure you want to extend vault with id ${vaultId} for ${extendLengthMs}ms?`);
|
|
120
|
+
if (!confirm) {
|
|
121
|
+
return { message: 'Vault extension aborted by user' };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const result = await ario.extendVault({
|
|
125
|
+
vaultId,
|
|
126
|
+
extendLengthMs,
|
|
127
|
+
}, writeActionTagsFromOptions(o));
|
|
128
|
+
const output = {
|
|
129
|
+
senderAddress: signerAddress,
|
|
130
|
+
transferResult: result,
|
|
131
|
+
message: `Successfully extended vault with id ${vaultId}`,
|
|
132
|
+
};
|
|
133
|
+
return output;
|
|
134
|
+
}
|
|
135
|
+
export async function increaseVaultCLICommand(o) {
|
|
136
|
+
const mARIOQuantity = requiredMARIOFromOptions(o, 'quantity');
|
|
137
|
+
const { ario, signerAddress } = writeARIOFromOptions(o);
|
|
138
|
+
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
139
|
+
if (!o.skipConfirmation) {
|
|
140
|
+
const vault = await ario.getVault({ vaultId, address: signerAddress });
|
|
141
|
+
if (!vault) {
|
|
142
|
+
throw new Error(`Vault for signer '${signerAddress}' with vault id '${vaultId}' not found`);
|
|
143
|
+
}
|
|
144
|
+
const confirm = await confirmationPrompt(`Are you sure you want to increase vault with id ${vaultId} by ${formatMARIOToARIOWithCommas(mARIOQuantity)} ARIO?`);
|
|
145
|
+
if (!confirm) {
|
|
146
|
+
return { message: 'Vault increase aborted by user' };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const result = await ario.increaseVault({
|
|
150
|
+
vaultId,
|
|
151
|
+
quantity: mARIOQuantity,
|
|
152
|
+
}, writeActionTagsFromOptions(o));
|
|
153
|
+
const output = {
|
|
154
|
+
senderAddress: signerAddress,
|
|
155
|
+
transferResult: result,
|
|
156
|
+
message: `Successfully increased vault with id ${vaultId} by ${formatMARIOToARIOWithCommas(mARIOQuantity)} ARIO`,
|
|
157
|
+
};
|
|
158
|
+
return output;
|
|
159
|
+
}
|
package/lib/esm/cli/options.js
CHANGED
|
@@ -245,7 +245,11 @@ export const optionMap = {
|
|
|
245
245
|
},
|
|
246
246
|
lockLengthMs: {
|
|
247
247
|
alias: '--lock-length-ms <lockLengthMs>',
|
|
248
|
-
description: 'The length of time in milliseconds to lock the
|
|
248
|
+
description: 'The length of time in milliseconds to lock the vault for',
|
|
249
|
+
},
|
|
250
|
+
extendLengthMs: {
|
|
251
|
+
alias: '--extend-length-ms <extendLengthMs>',
|
|
252
|
+
description: 'The length of time in milliseconds to extend the vault for',
|
|
249
253
|
},
|
|
250
254
|
recipient: {
|
|
251
255
|
alias: '--recipient <recipient>',
|
package/lib/esm/cli/utils.js
CHANGED
|
@@ -418,3 +418,16 @@ export function fundFromFromOptions(o) {
|
|
|
418
418
|
}
|
|
419
419
|
return o.fundFrom ?? 'balance';
|
|
420
420
|
}
|
|
421
|
+
export function assertLockLengthInRange(lockLengthMs, assertMin = true) {
|
|
422
|
+
const minLockLengthMs = 1209600000; // 14 days
|
|
423
|
+
const maxLockLengthMs = 378432000000; // ~12 years
|
|
424
|
+
if (lockLengthMs > maxLockLengthMs) {
|
|
425
|
+
throw new Error(`Lock length must be at most 12 years (378432000000 ms). Provided lock length: ${lockLengthMs} ms`);
|
|
426
|
+
}
|
|
427
|
+
if (!assertMin) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (lockLengthMs < minLockLengthMs) {
|
|
431
|
+
throw new Error(`Lock length must be at least 14 days (1209600000 ms). Provided lock length: ${lockLengthMs} ms`);
|
|
432
|
+
}
|
|
433
|
+
}
|
package/lib/esm/common/io.js
CHANGED
|
@@ -513,6 +513,42 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
513
513
|
signer: this.signer,
|
|
514
514
|
});
|
|
515
515
|
}
|
|
516
|
+
async createVault({ lockLengthMs, quantity }, options) {
|
|
517
|
+
const { tags = [] } = options || {};
|
|
518
|
+
return this.process.send({
|
|
519
|
+
tags: [
|
|
520
|
+
...tags,
|
|
521
|
+
{ name: 'Action', value: 'Create-Vault' },
|
|
522
|
+
{ name: 'Lock-Length', value: lockLengthMs.toString() },
|
|
523
|
+
{ name: 'Quantity', value: quantity.toString() },
|
|
524
|
+
],
|
|
525
|
+
signer: this.signer,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
async extendVault({ vaultId, extendLengthMs }, options) {
|
|
529
|
+
const { tags = [] } = options || {};
|
|
530
|
+
return this.process.send({
|
|
531
|
+
tags: [
|
|
532
|
+
...tags,
|
|
533
|
+
{ name: 'Action', value: 'Extend-Vault' },
|
|
534
|
+
{ name: 'Vault-Id', value: vaultId },
|
|
535
|
+
{ name: 'Extend-Length', value: extendLengthMs.toString() },
|
|
536
|
+
],
|
|
537
|
+
signer: this.signer,
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
async increaseVault({ vaultId, quantity }, options) {
|
|
541
|
+
const { tags = [] } = options || {};
|
|
542
|
+
return this.process.send({
|
|
543
|
+
tags: [
|
|
544
|
+
...tags,
|
|
545
|
+
{ name: 'Action', value: 'Increase-Vault' },
|
|
546
|
+
{ name: 'Vault-Id', value: vaultId },
|
|
547
|
+
{ name: 'Quantity', value: quantity.toString() },
|
|
548
|
+
],
|
|
549
|
+
signer: this.signer,
|
|
550
|
+
});
|
|
551
|
+
}
|
|
516
552
|
async joinNetwork({ operatorStake, allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }, options) {
|
|
517
553
|
const { tags = [] } = options || {};
|
|
518
554
|
const allTags = [
|
package/lib/esm/types/io.js
CHANGED
|
@@ -19,7 +19,7 @@ export const fundFromOptions = ['balance', 'stakes', 'any'];
|
|
|
19
19
|
export const isValidFundFrom = (fundFrom) => {
|
|
20
20
|
return fundFromOptions.indexOf(fundFrom) !== -1;
|
|
21
21
|
};
|
|
22
|
-
//
|
|
22
|
+
// Type-guard functions
|
|
23
23
|
export function isProcessConfiguration(config) {
|
|
24
24
|
return 'process' in config;
|
|
25
25
|
}
|
package/lib/esm/version.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { AoRevokeVaultParams, AoVaultedTransferParams } from '../../types/io.js';
|
|
16
|
+
import { AoCreateVaultParams, AoExtendVaultParams, AoIncreaseVaultParams, AoRevokeVaultParams, AoVaultedTransferParams } from '../../types/io.js';
|
|
17
17
|
import { CLIWriteOptionsFromAoParams, JsonSerializable, TransferCLIOptions } from '../types.js';
|
|
18
18
|
export declare function transferCLICommand(options: TransferCLIOptions): Promise<{
|
|
19
19
|
senderAddress: string;
|
|
@@ -24,3 +24,18 @@ export declare function transferCLICommand(options: TransferCLIOptions): Promise
|
|
|
24
24
|
}>;
|
|
25
25
|
export declare function vaultedTransferCLICommand(o: CLIWriteOptionsFromAoParams<AoVaultedTransferParams>): Promise<JsonSerializable>;
|
|
26
26
|
export declare function revokeVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoRevokeVaultParams>): Promise<JsonSerializable>;
|
|
27
|
+
export declare function createVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoCreateVaultParams>): Promise<JsonSerializable>;
|
|
28
|
+
export declare function extendVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoExtendVaultParams>): Promise<{
|
|
29
|
+
senderAddress: string;
|
|
30
|
+
transferResult: import("../../types/common.js").AoMessageResult;
|
|
31
|
+
message: string;
|
|
32
|
+
} | {
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function increaseVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoIncreaseVaultParams>): Promise<{
|
|
36
|
+
senderAddress: string;
|
|
37
|
+
transferResult: import("../../types/common.js").AoMessageResult;
|
|
38
|
+
message: string;
|
|
39
|
+
} | {
|
|
40
|
+
message: string;
|
|
41
|
+
}>;
|
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -86,3 +86,4 @@ export declare function getTokenCostParamsFromOptions(o: GetTokenCostCLIOptions)
|
|
|
86
86
|
export declare function fundFromFromOptions<O extends {
|
|
87
87
|
fundFrom?: string;
|
|
88
88
|
}>(o: O): FundFrom;
|
|
89
|
+
export declare function assertLockLengthInRange(lockLengthMs: number, assertMin?: boolean): void;
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import Arweave from 'arweave';
|
|
17
17
|
import { AoArNSNameDataWithName, AoArNSReservedNameData, AoBalanceWithAddress, AoEpochDistributionData, AoEpochObservationData, AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoReturnedName, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, OptionalArweave, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
|
|
18
|
-
import { AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSPurchaseParams, AoArNSReservedNameDataWithName, AoBuyRecordParams, AoDelegation, AoEpochData, AoEpochSettings, AoExtendLeaseParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoPaginatedAddressParams, AoRegistrationFees, AoRevokeVaultParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, CostDetailsResult, DemandFactorSettings, EpochInput } from '../types/io.js';
|
|
18
|
+
import { AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSPurchaseParams, AoArNSReservedNameDataWithName, AoBuyRecordParams, AoCreateVaultParams, AoDelegation, AoEpochData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoPaginatedAddressParams, AoRegistrationFees, AoRevokeVaultParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, CostDetailsResult, DemandFactorSettings, EpochInput } from '../types/io.js';
|
|
19
19
|
import { mARIOToken } from '../types/token.js';
|
|
20
20
|
import { AOProcess } from './contracts/ao-process.js';
|
|
21
21
|
type ARIOConfigNoSigner = OptionalArweave<ProcessConfiguration>;
|
|
@@ -149,6 +149,9 @@ export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
|
|
|
149
149
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
150
150
|
vaultedTransfer({ recipient, quantity, lockLengthMs, revokable, }: AoVaultedTransferParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
151
151
|
revokeVault({ vaultId, recipient }: AoRevokeVaultParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
152
|
+
createVault({ lockLengthMs, quantity }: AoCreateVaultParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
153
|
+
extendVault({ vaultId, extendLengthMs }: AoExtendVaultParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
154
|
+
increaseVault({ vaultId, quantity }: AoIncreaseVaultParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
152
155
|
joinNetwork({ operatorStake, allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }: AoJoinNetworkParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
153
156
|
leaveNetwork(options?: WriteOptions): Promise<AoMessageResult>;
|
|
154
157
|
updateGatewaySettings({ allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }: AoUpdateGatewaySettingsParams, options?: WriteOptions): Promise<AoMessageResult>;
|
package/lib/types/types/ant.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
-
import {
|
|
17
|
+
import { AoWriteAction, WalletAddress } from './common.js';
|
|
18
18
|
/**
|
|
19
19
|
* example error:
|
|
20
20
|
* {
|
|
@@ -180,62 +180,60 @@ export interface AoANTRead {
|
|
|
180
180
|
getHandlers(): Promise<AoANTHandler[]>;
|
|
181
181
|
}
|
|
182
182
|
export interface AoANTWrite extends AoANTRead {
|
|
183
|
-
transfer:
|
|
183
|
+
transfer: AoWriteAction<{
|
|
184
184
|
target: WalletAddress;
|
|
185
185
|
}>;
|
|
186
|
-
addController:
|
|
186
|
+
addController: AoWriteAction<{
|
|
187
187
|
controller: WalletAddress;
|
|
188
188
|
}>;
|
|
189
|
-
removeController:
|
|
189
|
+
removeController: AoWriteAction<{
|
|
190
190
|
controller: WalletAddress;
|
|
191
191
|
}>;
|
|
192
192
|
/** @deprecated Use setUndernameRecord instead for undernames, and setBaseNameRecord instead for the top level name (e.g. "@") */
|
|
193
|
-
setRecord:
|
|
194
|
-
removeRecord:
|
|
193
|
+
setRecord: AoWriteAction<AoANTSetUndernameRecordParams>;
|
|
194
|
+
removeRecord: AoWriteAction<{
|
|
195
195
|
undername: string;
|
|
196
196
|
}>;
|
|
197
|
-
setBaseNameRecord:
|
|
198
|
-
setUndernameRecord:
|
|
199
|
-
removeUndernameRecord:
|
|
197
|
+
setBaseNameRecord: AoWriteAction<AoANTSetBaseNameRecordParams>;
|
|
198
|
+
setUndernameRecord: AoWriteAction<AoANTSetUndernameRecordParams>;
|
|
199
|
+
removeUndernameRecord: AoWriteAction<{
|
|
200
200
|
undername: string;
|
|
201
201
|
}>;
|
|
202
|
-
setTicker:
|
|
202
|
+
setTicker: AoWriteAction<{
|
|
203
203
|
ticker: string;
|
|
204
204
|
}>;
|
|
205
|
-
setDescription:
|
|
205
|
+
setDescription: AoWriteAction<{
|
|
206
206
|
description: string;
|
|
207
207
|
}>;
|
|
208
|
-
setKeywords:
|
|
208
|
+
setKeywords: AoWriteAction<{
|
|
209
209
|
keywords: string[];
|
|
210
210
|
}>;
|
|
211
|
-
setName:
|
|
211
|
+
setName: AoWriteAction<{
|
|
212
212
|
name: string;
|
|
213
213
|
}>;
|
|
214
|
-
setLogo:
|
|
214
|
+
setLogo: AoWriteAction<{
|
|
215
215
|
txId: string;
|
|
216
216
|
}>;
|
|
217
|
-
releaseName:
|
|
217
|
+
releaseName: AoWriteAction<{
|
|
218
218
|
name: string;
|
|
219
219
|
arioProcessId: string;
|
|
220
220
|
}>;
|
|
221
|
-
reassignName:
|
|
221
|
+
reassignName: AoWriteAction<{
|
|
222
222
|
name: string;
|
|
223
223
|
arioProcessId: string;
|
|
224
224
|
antProcessId: string;
|
|
225
225
|
}>;
|
|
226
|
-
approvePrimaryNameRequest:
|
|
226
|
+
approvePrimaryNameRequest: AoWriteAction<{
|
|
227
227
|
name: string;
|
|
228
228
|
address: string;
|
|
229
229
|
arioProcessId: string;
|
|
230
230
|
}>;
|
|
231
|
-
removePrimaryNames:
|
|
231
|
+
removePrimaryNames: AoWriteAction<{
|
|
232
232
|
names: string[];
|
|
233
233
|
arioProcessId: string;
|
|
234
234
|
notifyOwners?: boolean;
|
|
235
235
|
}>;
|
|
236
236
|
}
|
|
237
|
-
/** utility type to ensure WriteOptions are appended to each parameter set */
|
|
238
|
-
type WriteAction<P, R = AoMessageResult> = (params: P, options?: WriteOptions) => Promise<R>;
|
|
239
237
|
export type AoANTSetBaseNameRecordParams = {
|
|
240
238
|
transactionId: string;
|
|
241
239
|
ttlSeconds: number;
|
|
@@ -243,4 +241,3 @@ export type AoANTSetBaseNameRecordParams = {
|
|
|
243
241
|
export type AoANTSetUndernameRecordParams = AoANTSetBaseNameRecordParams & {
|
|
244
242
|
undername: string;
|
|
245
243
|
};
|
|
246
|
-
export {};
|