@ar.io/sdk 3.0.1-alpha.1 → 3.1.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 +38 -0
- package/bundles/web.bundle.min.js +64 -64
- package/lib/cjs/cli/cli.js +8 -2
- package/lib/cjs/cli/commands/readCommands.js +22 -22
- package/lib/cjs/cli/options.js +6 -0
- package/lib/cjs/cli/utils.js +21 -1
- package/lib/cjs/common/contracts/ao-process.js +7 -3
- package/lib/cjs/common/io.js +47 -1
- package/lib/cjs/types/io.js +6 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +9 -3
- package/lib/esm/cli/commands/readCommands.js +21 -22
- package/lib/esm/cli/options.js +6 -0
- package/lib/esm/cli/utils.js +20 -1
- package/lib/esm/common/contracts/ao-process.js +7 -3
- package/lib/esm/common/io.js +47 -1
- package/lib/esm/types/io.js +4 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/readCommands.d.ts +24 -2
- package/lib/types/cli/options.d.ts +4 -0
- package/lib/types/cli/utils.d.ts +9 -1
- package/lib/types/common/contracts/ao-process.d.ts +2 -1
- package/lib/types/common/io.d.ts +2 -1
- package/lib/types/types/io.d.ts +31 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/cli/cli.js
CHANGED
|
@@ -154,10 +154,16 @@ const utils_js_1 = require("./utils.js");
|
|
|
154
154
|
});
|
|
155
155
|
(0, utils_js_1.makeCommand)({
|
|
156
156
|
name: 'get-token-cost',
|
|
157
|
-
description: 'Get token cost',
|
|
157
|
+
description: 'Get token cost for an intended action',
|
|
158
158
|
options: options_js_1.tokenCostOptions,
|
|
159
159
|
action: readCommands_js_1.getTokenCost,
|
|
160
160
|
});
|
|
161
|
+
(0, utils_js_1.makeCommand)({
|
|
162
|
+
name: 'get-cost-details',
|
|
163
|
+
description: 'Get expanded cost details for an intended action',
|
|
164
|
+
options: options_js_1.tokenCostOptions,
|
|
165
|
+
action: readCommands_js_1.getCostDetails,
|
|
166
|
+
});
|
|
161
167
|
(0, utils_js_1.makeCommand)({
|
|
162
168
|
name: 'list-vaults',
|
|
163
169
|
description: 'Get all wallet vaults',
|
|
@@ -209,7 +215,7 @@ const utils_js_1 = require("./utils.js");
|
|
|
209
215
|
.getBalance({ address: (0, utils_js_1.requiredAddressFromOptions)(options) })
|
|
210
216
|
.then((result) => ({
|
|
211
217
|
address: (0, utils_js_1.requiredAddressFromOptions)(options),
|
|
212
|
-
|
|
218
|
+
mARIOBalance: result,
|
|
213
219
|
message: `Provided address current has a balance of ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(result).toARIO())} ARIO`,
|
|
214
220
|
})),
|
|
215
221
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.listArNSReturnedNames = exports.getArNSReturnedName = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listGateways = exports.getGateway = void 0;
|
|
3
|
+
exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getCostDetails = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.listArNSReturnedNames = exports.getArNSReturnedName = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listGateways = exports.getGateway = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
6
|
*
|
|
@@ -132,33 +132,33 @@ async function getPrescribedNames(o) {
|
|
|
132
132
|
}
|
|
133
133
|
exports.getPrescribedNames = getPrescribedNames;
|
|
134
134
|
async function getTokenCost(o) {
|
|
135
|
-
o.
|
|
136
|
-
o.type ??= 'lease';
|
|
137
|
-
if (!(0, io_js_1.isValidIntent)(o.intent)) {
|
|
138
|
-
throw new Error(`Invalid intent. Valid intents are: ${io_js_1.validIntents.join(', ')}`);
|
|
139
|
-
}
|
|
140
|
-
if (o.type !== 'lease' && o.type !== 'permabuy') {
|
|
141
|
-
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
142
|
-
}
|
|
143
|
-
if (o.type === 'lease' &&
|
|
144
|
-
io_js_1.intentsUsingYears.includes(o.intent) &&
|
|
145
|
-
o.years === undefined) {
|
|
146
|
-
throw new Error('Years is required for lease type');
|
|
147
|
-
}
|
|
148
|
-
const tokenCost = await (0, utils_js_1.readARIOFromOptions)(o).getTokenCost({
|
|
149
|
-
type: o.type,
|
|
150
|
-
quantity: o.quantity !== undefined ? +o.quantity : undefined,
|
|
151
|
-
years: o.years !== undefined ? +o.years : undefined,
|
|
152
|
-
intent: o.intent,
|
|
153
|
-
name: (0, utils_js_1.requiredStringFromOptions)(o, 'name'),
|
|
154
|
-
});
|
|
135
|
+
const tokenCost = await (0, utils_js_1.readARIOFromOptions)(o).getTokenCost((0, utils_js_1.getTokenCostParamsFromOptions)(o));
|
|
155
136
|
const output = {
|
|
156
|
-
|
|
137
|
+
mARIOTokenCost: tokenCost,
|
|
157
138
|
message: `The cost of the provided action is ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(tokenCost).toARIO())} ARIO`,
|
|
158
139
|
};
|
|
159
140
|
return output;
|
|
160
141
|
}
|
|
161
142
|
exports.getTokenCost = getTokenCost;
|
|
143
|
+
async function getCostDetails(o) {
|
|
144
|
+
if (o.fundFrom !== undefined) {
|
|
145
|
+
if (!(0, io_js_1.isValidFundFrom)(o.fundFrom)) {
|
|
146
|
+
throw new Error(`Invalid fund from: ${o.fundFrom}. Please use one of ${io_js_1.fundFromOptions.join(', ')}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const costDetails = await (0, utils_js_1.readARIOFromOptions)(o).getCostDetails({
|
|
150
|
+
...(0, utils_js_1.getTokenCostParamsFromOptions)(o),
|
|
151
|
+
fundFrom: o.fundFrom,
|
|
152
|
+
});
|
|
153
|
+
const output = {
|
|
154
|
+
...costDetails,
|
|
155
|
+
message: `The cost of the provided action is ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(costDetails.tokenCost).toARIO())} ARIO${costDetails.fundingPlan && costDetails.fundingPlan.shortfall > 0
|
|
156
|
+
? `. Insufficient funds for action. There is a shortfall of ${(0, utils_js_1.formatARIOWithCommas)(new token_js_1.mARIOToken(costDetails.fundingPlan.shortfall).toARIO())} ARIO`
|
|
157
|
+
: ''}`,
|
|
158
|
+
};
|
|
159
|
+
return output;
|
|
160
|
+
}
|
|
161
|
+
exports.getCostDetails = getCostDetails;
|
|
162
162
|
async function getPrimaryName(o) {
|
|
163
163
|
const address = (0, utils_js_1.addressFromOptions)(o);
|
|
164
164
|
const name = o.name;
|
package/lib/cjs/cli/options.js
CHANGED
|
@@ -237,6 +237,10 @@ exports.optionMap = {
|
|
|
237
237
|
description: 'Include failed gateways in the list',
|
|
238
238
|
type: 'array',
|
|
239
239
|
},
|
|
240
|
+
fundFrom: {
|
|
241
|
+
alias: '--fund-from <fundFrom>',
|
|
242
|
+
description: 'Where to fund the action from. e.g. "balance", "stakes", or "any',
|
|
243
|
+
},
|
|
240
244
|
};
|
|
241
245
|
exports.walletOptions = [
|
|
242
246
|
exports.optionMap.walletFile,
|
|
@@ -274,6 +278,8 @@ exports.tokenCostOptions = [
|
|
|
274
278
|
exports.optionMap.type,
|
|
275
279
|
exports.optionMap.years,
|
|
276
280
|
exports.optionMap.quantity,
|
|
281
|
+
exports.optionMap.address,
|
|
282
|
+
exports.optionMap.fundFrom,
|
|
277
283
|
];
|
|
278
284
|
exports.transferOptions = [
|
|
279
285
|
...exports.writeActionOptions,
|
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.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughBalance = exports.requiredMIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.writeActionTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatARIOWithCommas = exports.writeARIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = void 0;
|
|
6
|
+
exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughBalance = exports.requiredMIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.writeActionTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatARIOWithCommas = exports.writeARIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
9
|
*
|
|
@@ -405,3 +405,23 @@ function getANTStateFromOptions(options) {
|
|
|
405
405
|
});
|
|
406
406
|
}
|
|
407
407
|
exports.getANTStateFromOptions = getANTStateFromOptions;
|
|
408
|
+
function getTokenCostParamsFromOptions(o) {
|
|
409
|
+
o.intent ??= 'Buy-Record';
|
|
410
|
+
o.type ??= 'lease';
|
|
411
|
+
o.years ??= '1';
|
|
412
|
+
if (!(0, index_js_1.isValidIntent)(o.intent)) {
|
|
413
|
+
throw new Error(`Invalid intent. Valid intents are: ${index_js_1.validIntents.join(', ')}`);
|
|
414
|
+
}
|
|
415
|
+
if (o.type !== 'lease' && o.type !== 'permabuy') {
|
|
416
|
+
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
type: o.type,
|
|
420
|
+
quantity: o.quantity !== undefined ? +o.quantity : undefined,
|
|
421
|
+
years: +o.years,
|
|
422
|
+
intent: o.intent,
|
|
423
|
+
name: requiredStringFromOptions(o, 'name'),
|
|
424
|
+
fromAddress: addressFromOptions(o),
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
exports.getTokenCostParamsFromOptions = getTokenCostParamsFromOptions;
|
|
@@ -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() {
|
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
|
@@ -20,7 +20,7 @@ import { spawnANT } from '../node/index.js';
|
|
|
20
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, getArNSRecord, getArNSReservedName, getArNSReturnedName, getDelegations, getEpoch, getGateway, getGatewayDelegates, getGatewayVaults, getPrescribedNames, getPrescribedObservers, getPrimaryName, getTokenCost, getVault, listArNSRecords, listArNSReservedNames, listArNSReturnedNames, listGateways, } from './commands/readCommands.js';
|
|
23
|
+
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
24
|
import { transfer } from './commands/transfer.js';
|
|
25
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
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';
|
|
@@ -152,10 +152,16 @@ makeCommand({
|
|
|
152
152
|
});
|
|
153
153
|
makeCommand({
|
|
154
154
|
name: 'get-token-cost',
|
|
155
|
-
description: 'Get token cost',
|
|
155
|
+
description: 'Get token cost for an intended action',
|
|
156
156
|
options: tokenCostOptions,
|
|
157
157
|
action: getTokenCost,
|
|
158
158
|
});
|
|
159
|
+
makeCommand({
|
|
160
|
+
name: 'get-cost-details',
|
|
161
|
+
description: 'Get expanded cost details for an intended action',
|
|
162
|
+
options: tokenCostOptions,
|
|
163
|
+
action: getCostDetails,
|
|
164
|
+
});
|
|
159
165
|
makeCommand({
|
|
160
166
|
name: 'list-vaults',
|
|
161
167
|
description: 'Get all wallet vaults',
|
|
@@ -207,7 +213,7 @@ makeCommand({
|
|
|
207
213
|
.getBalance({ address: requiredAddressFromOptions(options) })
|
|
208
214
|
.then((result) => ({
|
|
209
215
|
address: requiredAddressFromOptions(options),
|
|
210
|
-
|
|
216
|
+
mARIOBalance: result,
|
|
211
217
|
message: `Provided address current has a balance of ${formatARIOWithCommas(new mARIOToken(result).toARIO())} ARIO`,
|
|
212
218
|
})),
|
|
213
219
|
});
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { fundFromOptions, isValidFundFrom, } from '../../types/io.js';
|
|
17
17
|
import { mARIOToken } from '../../types/token.js';
|
|
18
|
-
import { addressFromOptions, epochInputFromOptions, formatARIOWithCommas, paginationParamsFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredStringFromOptions, } from '../utils.js';
|
|
18
|
+
import { addressFromOptions, epochInputFromOptions, formatARIOWithCommas, getTokenCostParamsFromOptions, paginationParamsFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredStringFromOptions, } from '../utils.js';
|
|
19
19
|
export async function getGateway(o) {
|
|
20
20
|
const address = requiredAddressFromOptions(o);
|
|
21
21
|
const gateway = await readARIOFromOptions(o).getGateway({
|
|
@@ -115,29 +115,28 @@ export async function getPrescribedNames(o) {
|
|
|
115
115
|
: { message: `No prescribed names found for epoch ${epoch}` };
|
|
116
116
|
}
|
|
117
117
|
export async function getTokenCost(o) {
|
|
118
|
-
o.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (o.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
const tokenCost = await readARIOFromOptions(o).getTokenCost(getTokenCostParamsFromOptions(o));
|
|
119
|
+
const output = {
|
|
120
|
+
mARIOTokenCost: tokenCost,
|
|
121
|
+
message: `The cost of the provided action is ${formatARIOWithCommas(new mARIOToken(tokenCost).toARIO())} ARIO`,
|
|
122
|
+
};
|
|
123
|
+
return output;
|
|
124
|
+
}
|
|
125
|
+
export async function getCostDetails(o) {
|
|
126
|
+
if (o.fundFrom !== undefined) {
|
|
127
|
+
if (!isValidFundFrom(o.fundFrom)) {
|
|
128
|
+
throw new Error(`Invalid fund from: ${o.fundFrom}. Please use one of ${fundFromOptions.join(', ')}`);
|
|
129
|
+
}
|
|
130
130
|
}
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
years: o.years !== undefined ? +o.years : undefined,
|
|
135
|
-
intent: o.intent,
|
|
136
|
-
name: requiredStringFromOptions(o, 'name'),
|
|
131
|
+
const costDetails = await readARIOFromOptions(o).getCostDetails({
|
|
132
|
+
...getTokenCostParamsFromOptions(o),
|
|
133
|
+
fundFrom: o.fundFrom,
|
|
137
134
|
});
|
|
138
135
|
const output = {
|
|
139
|
-
|
|
140
|
-
message: `The cost of the provided action is ${formatARIOWithCommas(new mARIOToken(tokenCost).toARIO())} ARIO
|
|
136
|
+
...costDetails,
|
|
137
|
+
message: `The cost of the provided action is ${formatARIOWithCommas(new mARIOToken(costDetails.tokenCost).toARIO())} ARIO${costDetails.fundingPlan && costDetails.fundingPlan.shortfall > 0
|
|
138
|
+
? `. Insufficient funds for action. There is a shortfall of ${formatARIOWithCommas(new mARIOToken(costDetails.fundingPlan.shortfall).toARIO())} ARIO`
|
|
139
|
+
: ''}`,
|
|
141
140
|
};
|
|
142
141
|
return output;
|
|
143
142
|
}
|
package/lib/esm/cli/options.js
CHANGED
|
@@ -234,6 +234,10 @@ export const optionMap = {
|
|
|
234
234
|
description: 'Include failed gateways in the list',
|
|
235
235
|
type: 'array',
|
|
236
236
|
},
|
|
237
|
+
fundFrom: {
|
|
238
|
+
alias: '--fund-from <fundFrom>',
|
|
239
|
+
description: 'Where to fund the action from. e.g. "balance", "stakes", or "any',
|
|
240
|
+
},
|
|
237
241
|
};
|
|
238
242
|
export const walletOptions = [
|
|
239
243
|
optionMap.walletFile,
|
|
@@ -271,6 +275,8 @@ export const tokenCostOptions = [
|
|
|
271
275
|
optionMap.type,
|
|
272
276
|
optionMap.years,
|
|
273
277
|
optionMap.quantity,
|
|
278
|
+
optionMap.address,
|
|
279
|
+
optionMap.fundFrom,
|
|
274
280
|
];
|
|
275
281
|
export const transferOptions = [
|
|
276
282
|
...writeActionOptions,
|
package/lib/esm/cli/utils.js
CHANGED
|
@@ -17,7 +17,7 @@ import { connect } from '@permaweb/aoconnect';
|
|
|
17
17
|
import { program } from 'commander';
|
|
18
18
|
import { readFileSync } from 'fs';
|
|
19
19
|
import prompts from 'prompts';
|
|
20
|
-
import { ANT, AOProcess, ARIO, ARIOToken, ARIO_DEVNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID, ArweaveSigner, Logger, createAoSigner, fromB64Url, initANTStateForAddress, mARIOToken, sha256B64Url, } from '../node/index.js';
|
|
20
|
+
import { ANT, AOProcess, ARIO, ARIOToken, ARIO_DEVNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID, ArweaveSigner, Logger, createAoSigner, fromB64Url, initANTStateForAddress, isValidIntent, mARIOToken, sha256B64Url, validIntents, } from '../node/index.js';
|
|
21
21
|
import { globalOptions } from './options.js';
|
|
22
22
|
export function stringifyJsonForCLIDisplay(json) {
|
|
23
23
|
return JSON.stringify(json, null, 2);
|
|
@@ -364,3 +364,22 @@ export function getANTStateFromOptions(options) {
|
|
|
364
364
|
ttlSeconds: options.ttlSeconds !== undefined ? +options.ttlSeconds : 3600,
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
|
+
export function getTokenCostParamsFromOptions(o) {
|
|
368
|
+
o.intent ??= 'Buy-Record';
|
|
369
|
+
o.type ??= 'lease';
|
|
370
|
+
o.years ??= '1';
|
|
371
|
+
if (!isValidIntent(o.intent)) {
|
|
372
|
+
throw new Error(`Invalid intent. Valid intents are: ${validIntents.join(', ')}`);
|
|
373
|
+
}
|
|
374
|
+
if (o.type !== 'lease' && o.type !== 'permabuy') {
|
|
375
|
+
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
type: o.type,
|
|
379
|
+
quantity: o.quantity !== undefined ? +o.quantity : undefined,
|
|
380
|
+
years: +o.years,
|
|
381
|
+
intent: o.intent,
|
|
382
|
+
name: requiredStringFromOptions(o, 'name'),
|
|
383
|
+
fromAddress: addressFromOptions(o),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
@@ -28,7 +28,7 @@ export class AOProcess {
|
|
|
28
28
|
this.logger = logger;
|
|
29
29
|
this.ao = ao;
|
|
30
30
|
}
|
|
31
|
-
async read({ tags, retries = 3, }) {
|
|
31
|
+
async read({ tags, retries = 3, fromAddress, }) {
|
|
32
32
|
let attempts = 0;
|
|
33
33
|
let lastError;
|
|
34
34
|
while (attempts < retries) {
|
|
@@ -37,10 +37,14 @@ export class AOProcess {
|
|
|
37
37
|
tags,
|
|
38
38
|
});
|
|
39
39
|
// map tags to inputs
|
|
40
|
-
const
|
|
40
|
+
const dryRunInput = {
|
|
41
41
|
process: this.processId,
|
|
42
42
|
tags,
|
|
43
|
-
}
|
|
43
|
+
};
|
|
44
|
+
if (fromAddress !== undefined) {
|
|
45
|
+
dryRunInput['Owner'] = fromAddress;
|
|
46
|
+
}
|
|
47
|
+
const result = await this.ao.dryrun(dryRunInput);
|
|
44
48
|
this.logger.debug(`Read interaction result`, {
|
|
45
49
|
result,
|
|
46
50
|
});
|
package/lib/esm/common/io.js
CHANGED
|
@@ -261,7 +261,7 @@ export class ARIOReadable {
|
|
|
261
261
|
tags: pruneTags(allTags),
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
|
-
async getTokenCost({ intent, type, years, name, quantity, }) {
|
|
264
|
+
async getTokenCost({ intent, type, years, name, quantity, fromAddress, }) {
|
|
265
265
|
const allTags = [
|
|
266
266
|
{ name: 'Action', value: 'Token-Cost' },
|
|
267
267
|
{
|
|
@@ -298,6 +298,52 @@ export class ARIOReadable {
|
|
|
298
298
|
];
|
|
299
299
|
return this.process.read({
|
|
300
300
|
tags: pruneTags(allTags),
|
|
301
|
+
fromAddress,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
// TODO: Can overload this function to refine different types of cost details params
|
|
305
|
+
async getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }) {
|
|
306
|
+
const allTags = [
|
|
307
|
+
{ name: 'Action', value: 'Get-Cost-Details-For-Action' },
|
|
308
|
+
{
|
|
309
|
+
name: 'Intent',
|
|
310
|
+
value: intent,
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
name: 'Name',
|
|
314
|
+
value: name,
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: 'Years',
|
|
318
|
+
value: years?.toString(),
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
name: 'Quantity',
|
|
322
|
+
value: quantity?.toString(),
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: 'Purchase-Type',
|
|
326
|
+
value: type,
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
name: 'Fund-From',
|
|
330
|
+
value: fundFrom,
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
name: 'Timestamp',
|
|
334
|
+
value: (await this.arweave.blocks
|
|
335
|
+
.getCurrent()
|
|
336
|
+
.then((block) => {
|
|
337
|
+
return { timestamp: block.timestamp * 1000 };
|
|
338
|
+
})
|
|
339
|
+
.catch(() => {
|
|
340
|
+
return { timestamp: Date.now() }; // fallback to current time
|
|
341
|
+
})).timestamp.toString(),
|
|
342
|
+
},
|
|
343
|
+
];
|
|
344
|
+
return this.process.read({
|
|
345
|
+
tags: pruneTags(allTags),
|
|
346
|
+
fromAddress,
|
|
301
347
|
});
|
|
302
348
|
}
|
|
303
349
|
async getRegistrationFees() {
|
package/lib/esm/types/io.js
CHANGED
|
@@ -10,6 +10,10 @@ export const intentsUsingYears = ['Buy-Record', 'Extend-Lease'];
|
|
|
10
10
|
export const isValidIntent = (intent) => {
|
|
11
11
|
return validIntents.indexOf(intent) !== -1;
|
|
12
12
|
};
|
|
13
|
+
export const fundFromOptions = ['balance', 'stakes', 'any'];
|
|
14
|
+
export const isValidFundFrom = (fundFrom) => {
|
|
15
|
+
return fundFromOptions.indexOf(fundFrom) !== -1;
|
|
16
|
+
};
|
|
13
17
|
// Typeguard functions
|
|
14
18
|
export function isProcessConfiguration(config) {
|
|
15
19
|
return 'process' in config;
|
package/lib/esm/version.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
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 { AoGetCostDetailsParams } from '../../types/io.js';
|
|
17
|
+
import { AddressAndNameCLIOptions, AddressAndVaultIdCLIOptions, AddressCLIOptions, CLIOptionsFromAoParams, EpochCLIOptions, GetTokenCostCLIOptions, GlobalCLIOptions, NameCLIOptions, PaginationAddressCLIOptions, PaginationCLIOptions } from '../types.js';
|
|
2
18
|
export declare function getGateway(o: AddressCLIOptions): Promise<import("../../types/io.js").AoGateway | {
|
|
3
19
|
message: string;
|
|
4
20
|
}>;
|
|
@@ -42,9 +58,15 @@ export declare function getPrescribedNames(o: EpochCLIOptions): Promise<string[]
|
|
|
42
58
|
message: string;
|
|
43
59
|
}>;
|
|
44
60
|
export declare function getTokenCost(o: GetTokenCostCLIOptions): Promise<{
|
|
45
|
-
|
|
61
|
+
mARIOTokenCost: number;
|
|
46
62
|
message: string;
|
|
47
63
|
}>;
|
|
64
|
+
export declare function getCostDetails(o: GlobalCLIOptions & CLIOptionsFromAoParams<AoGetCostDetailsParams>): Promise<{
|
|
65
|
+
message: string;
|
|
66
|
+
tokenCost: number;
|
|
67
|
+
discounts: import("../../types/io.js").CostDiscount[];
|
|
68
|
+
fundingPlan?: import("../../types/io.js").AoFundingPlan | undefined;
|
|
69
|
+
}>;
|
|
48
70
|
export declare function getPrimaryName(o: AddressAndNameCLIOptions): Promise<import("../../types/common.js").AoPrimaryName | {
|
|
49
71
|
message: string;
|
|
50
72
|
}>;
|
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JWKInterface } from 'arweave/node/lib/wallet.js';
|
|
2
2
|
import { Command, OptionValues } from 'commander';
|
|
3
3
|
import { ARIOToken, AoANTRead, AoANTWrite, AoARIORead, AoARIOWrite, AoRedelegateStakeParams, AoSigner, AoUpdateGatewaySettingsParams, ContractSigner, EpochInput, Logger, PaginationParams, SpawnANTState, WriteOptions, mARIOToken } from '../node/index.js';
|
|
4
|
-
import { ANTStateCLIOptions, AddressCLIOptions, EpochCLIOptions, GlobalCLIOptions, InitiatorCLIOptions, JsonSerializable, PaginationCLIOptions, ProcessIdCLIOptions, RedelegateStakeCLIOptions, TransferCLIOptions, UpdateGatewaySettingsCLIOptions, WalletCLIOptions, WriteActionCLIOptions } from './types.js';
|
|
4
|
+
import { ANTStateCLIOptions, AddressCLIOptions, EpochCLIOptions, GetTokenCostCLIOptions, GlobalCLIOptions, InitiatorCLIOptions, JsonSerializable, PaginationCLIOptions, ProcessIdCLIOptions, RedelegateStakeCLIOptions, TransferCLIOptions, UpdateGatewaySettingsCLIOptions, WalletCLIOptions, WriteActionCLIOptions } from './types.js';
|
|
5
5
|
export declare function stringifyJsonForCLIDisplay(json: JsonSerializable | unknown): string;
|
|
6
6
|
export declare function runCommand<O extends OptionValues>(command: Command, action: (options: O) => Promise<JsonSerializable>): Promise<void>;
|
|
7
7
|
export interface CommanderOption {
|
|
@@ -65,3 +65,11 @@ export declare function requiredStringArrayFromOptions<O extends GlobalCLIOption
|
|
|
65
65
|
export declare function positiveIntegerFromOptions<O extends GlobalCLIOptions>(options: O, key: string): number | undefined;
|
|
66
66
|
export declare function requiredPositiveIntegerFromOptions<O extends GlobalCLIOptions>(options: O, key: string): number;
|
|
67
67
|
export declare function getANTStateFromOptions(options: ANTStateCLIOptions): SpawnANTState;
|
|
68
|
+
export declare function getTokenCostParamsFromOptions(o: GetTokenCostCLIOptions): {
|
|
69
|
+
type: "lease" | "permabuy";
|
|
70
|
+
quantity: number | undefined;
|
|
71
|
+
years: number;
|
|
72
|
+
intent: "Buy-Record" | "Extend-Lease" | "Increase-Undername-Limit" | "Upgrade-Name" | "Primary-Name-Request";
|
|
73
|
+
name: string;
|
|
74
|
+
fromAddress: string | undefined;
|
|
75
|
+
};
|
|
@@ -9,12 +9,13 @@ export declare class AOProcess implements AOContract {
|
|
|
9
9
|
ao?: AoClient;
|
|
10
10
|
logger?: ILogger;
|
|
11
11
|
});
|
|
12
|
-
read<K>({ tags, retries, }: {
|
|
12
|
+
read<K>({ tags, retries, fromAddress, }: {
|
|
13
13
|
tags?: Array<{
|
|
14
14
|
name: string;
|
|
15
15
|
value: string;
|
|
16
16
|
}>;
|
|
17
17
|
retries?: number;
|
|
18
|
+
fromAddress?: string;
|
|
18
19
|
}): Promise<K>;
|
|
19
20
|
send<K>({ tags, data, signer, retries, }: {
|
|
20
21
|
tags: Array<{
|
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, ContractSigner, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
|
|
18
|
-
import { AoARIORead, AoARIOWrite, AoArNSNameData, AoArNSReservedNameDataWithName, AoDelegation, AoEpochData, AoEpochSettings, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoPaginatedAddressParams, AoRegistrationFees, AoVaultData, AoWalletVault, DemandFactorSettings, EpochInput } from '../types/io.js';
|
|
18
|
+
import { AoARIORead, AoARIOWrite, AoArNSNameData, AoArNSReservedNameDataWithName, AoDelegation, AoEpochData, AoEpochSettings, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoPaginatedAddressParams, AoRegistrationFees, AoVaultData, 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
|
export declare class ARIO {
|
|
@@ -107,6 +107,7 @@ export declare class ARIOReadable implements AoARIORead {
|
|
|
107
107
|
intent: 'Primary-Name-Request';
|
|
108
108
|
name: string;
|
|
109
109
|
}): Promise<number>;
|
|
110
|
+
getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }: AoGetCostDetailsParams): Promise<CostDetailsResult>;
|
|
110
111
|
getRegistrationFees(): Promise<AoRegistrationFees>;
|
|
111
112
|
getDemandFactor(): Promise<number>;
|
|
112
113
|
getDemandFactorSettings(): Promise<DemandFactorSettings>;
|