@ar.io/sdk 2.6.0 → 2.7.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/bundles/web.bundle.min.js +65 -65
  2. package/lib/cjs/cli/cli.js +712 -0
  3. package/lib/cjs/cli/commands/gatewayWriteCommands.js +211 -0
  4. package/lib/cjs/cli/commands/readCommands.js +219 -0
  5. package/lib/cjs/cli/commands/transfer.js +26 -0
  6. package/lib/cjs/cli/options.js +336 -0
  7. package/lib/cjs/cli/types.js +2 -0
  8. package/lib/cjs/cli/utils.js +406 -0
  9. package/lib/cjs/common/io.js +2 -7
  10. package/lib/cjs/types/io.js +13 -1
  11. package/lib/cjs/utils/ao.js +32 -13
  12. package/lib/cjs/utils/base64.js +1 -1
  13. package/lib/cjs/version.js +1 -1
  14. package/lib/esm/cli/cli.js +710 -0
  15. package/lib/esm/cli/commands/gatewayWriteCommands.js +194 -0
  16. package/lib/esm/cli/commands/readCommands.js +197 -0
  17. package/lib/esm/cli/commands/transfer.js +22 -0
  18. package/lib/esm/cli/options.js +333 -0
  19. package/lib/esm/cli/types.js +1 -0
  20. package/lib/esm/cli/utils.js +366 -0
  21. package/lib/esm/common/io.js +2 -7
  22. package/lib/esm/types/io.js +11 -0
  23. package/lib/esm/utils/ao.js +30 -12
  24. package/lib/esm/utils/base64.js +1 -1
  25. package/lib/esm/version.js +1 -1
  26. package/lib/types/cli/cli.d.ts +2 -0
  27. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +38 -0
  28. package/lib/types/cli/commands/readCommands.d.ts +57 -0
  29. package/lib/types/cli/commands/transfer.d.ts +23 -0
  30. package/lib/types/cli/options.d.ts +326 -0
  31. package/lib/types/cli/types.d.ts +106 -0
  32. package/lib/types/cli/utils.d.ts +66 -0
  33. package/lib/types/common/io.d.ts +4 -7
  34. package/lib/types/types/io.d.ts +81 -60
  35. package/lib/types/utils/ao.d.ts +20 -10
  36. package/lib/types/version.d.ts +1 -1
  37. package/package.json +7 -1
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.redelegateStake = exports.decreaseDelegateStake = exports.delegateStake = exports.cancelWithdrawal = exports.instantWithdrawal = exports.decreaseOperatorStake = exports.increaseOperatorStake = exports.saveObservations = exports.leaveNetwork = exports.updateGatewaySettings = exports.joinNetwork = void 0;
7
+ /**
8
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const prompts_1 = __importDefault(require("prompts"));
23
+ const index_js_1 = require("../../node/index.js");
24
+ const utils_js_1 = require("../utils.js");
25
+ async function joinNetwork(options) {
26
+ const { io, signerAddress } = (0, utils_js_1.writeIOFromOptions)(options);
27
+ const mARIOQuantity = (0, utils_js_1.requiredMIOFromOptions)(options, 'operatorStake');
28
+ const settings = {
29
+ ...(0, utils_js_1.gatewaySettingsFromOptions)(options),
30
+ operatorStake: mARIOQuantity.valueOf(),
31
+ };
32
+ if (settings.label === undefined) {
33
+ throw new Error('Label is required. Please provide a --label for your node.');
34
+ }
35
+ if (settings.fqdn === undefined) {
36
+ throw new Error('FQDN is required. Please provide a --fqdn for your node.');
37
+ }
38
+ if (!options.skipConfirmation) {
39
+ const settings = await io.getGatewayRegistrySettings();
40
+ if (settings.operators.minStake > mARIOQuantity.valueOf()) {
41
+ throw new Error(`The minimum operator stake is ${(0, utils_js_1.formatIOWithCommas)(new index_js_1.mIOToken(settings.operators.minStake).toIO())} IO. Please provide a higher stake.`);
42
+ }
43
+ await (0, utils_js_1.assertEnoughBalance)(io, signerAddress, mARIOQuantity.toIO());
44
+ await (0, utils_js_1.assertConfirmationPrompt)(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${(0, utils_js_1.formatIOWithCommas)(mARIOQuantity.toIO())} IO to join the AR.IO network\nAre you sure?\n`, options);
45
+ }
46
+ const result = await io.joinNetwork(settings, (0, utils_js_1.writeActionTagsFromOptions)(options));
47
+ const output = {
48
+ joinNetworkResult: result,
49
+ joinedAddress: signerAddress,
50
+ message: `Congratulations! You have successfully joined the AR.IO network (;`,
51
+ };
52
+ return output;
53
+ }
54
+ exports.joinNetwork = joinNetwork;
55
+ async function updateGatewaySettings(options) {
56
+ const { io, signerAddress } = (0, utils_js_1.writeIOFromOptions)(options);
57
+ const gatewaySettings = (0, utils_js_1.gatewaySettingsFromOptions)(options);
58
+ if (Object.keys(gatewaySettings).length === 0) {
59
+ // TODO: The contract accepts empty Update-Gateway-Settings actions, but we'll throw in the CLI for now
60
+ throw new Error('No gateway settings provided');
61
+ }
62
+ await (0, utils_js_1.assertConfirmationPrompt)(`Gateway Settings:\n\n${(0, utils_js_1.stringifyJsonForCLIDisplay)(gatewaySettings)}\n\nYou are about to update your gateway settings to the above\nAre you sure?\n`, options);
63
+ const result = await io.updateGatewaySettings(gatewaySettings, (0, utils_js_1.writeActionTagsFromOptions)(options));
64
+ const output = {
65
+ updateGatewaySettingsResult: result,
66
+ updatedGatewayAddress: signerAddress,
67
+ message: `Gateway settings updated successfully`,
68
+ };
69
+ return output;
70
+ }
71
+ exports.updateGatewaySettings = updateGatewaySettings;
72
+ async function leaveNetwork(options) {
73
+ const { io, signerAddress } = (0, utils_js_1.writeIOFromOptions)(options);
74
+ if (!options.skipConfirmation) {
75
+ const gateway = await io.getGateway({ address: signerAddress });
76
+ if (!gateway) {
77
+ throw new Error(`Gateway not found for address: ${signerAddress}`);
78
+ }
79
+ await (0, utils_js_1.assertConfirmationPrompt)('Gateway Details:\n\n' +
80
+ (0, utils_js_1.stringifyJsonForCLIDisplay)(gateway) +
81
+ '\n\n' +
82
+ 'Are you sure you want to leave the AR.IO network?', options);
83
+ }
84
+ return (0, utils_js_1.writeIOFromOptions)(options).io.leaveNetwork((0, utils_js_1.writeActionTagsFromOptions)(options));
85
+ }
86
+ exports.leaveNetwork = leaveNetwork;
87
+ async function saveObservations(o) {
88
+ const failedGateways = (0, utils_js_1.requiredStringArrayFromOptions)(o, 'failedGateways');
89
+ const reportTxId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId');
90
+ await (0, utils_js_1.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);
91
+ return (0, utils_js_1.writeIOFromOptions)(o).io.saveObservations({
92
+ failedGateways: (0, utils_js_1.requiredStringArrayFromOptions)(o, 'failedGateways'),
93
+ reportTxId: (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId'),
94
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
95
+ }
96
+ exports.saveObservations = saveObservations;
97
+ async function increaseOperatorStake(o) {
98
+ const increaseQty = (0, utils_js_1.requiredMIOFromOptions)(o, 'operatorStake');
99
+ await (0, utils_js_1.assertConfirmationPrompt)(`You are about to increase your operator stake by ${(0, utils_js_1.formatIOWithCommas)(increaseQty.toIO())} IO\nAre you sure?`, o);
100
+ return ((0, utils_js_1.writeIOFromOptions)(o).io.increaseOperatorStake({
101
+ increaseQty,
102
+ }),
103
+ (0, utils_js_1.writeActionTagsFromOptions)(o));
104
+ }
105
+ exports.increaseOperatorStake = increaseOperatorStake;
106
+ async function decreaseOperatorStake(o) {
107
+ const decreaseQty = (0, utils_js_1.requiredMIOFromOptions)(o, 'operatorStake');
108
+ // TODO: Can assert stake is sufficient for action, and new target stake meets contract minimum
109
+ await (0, utils_js_1.assertConfirmationPrompt)(`You are about to decrease your operator stake by ${(0, utils_js_1.formatIOWithCommas)(decreaseQty.toIO())} IO\nAre you sure?`, o);
110
+ return (0, utils_js_1.writeIOFromOptions)(o).io.decreaseOperatorStake({
111
+ decreaseQty,
112
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
113
+ }
114
+ exports.decreaseOperatorStake = decreaseOperatorStake;
115
+ async function instantWithdrawal(o) {
116
+ const vaultId = (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId');
117
+ const gatewayAddress = (0, utils_js_1.requiredAddressFromOptions)(o);
118
+ await (0, utils_js_1.assertConfirmationPrompt)(`You are about to instantly withdraw from vault ${vaultId} for with gateway address ${gatewayAddress}\nAre you sure?`, o);
119
+ return (0, utils_js_1.writeIOFromOptions)(o).io.instantWithdrawal({
120
+ vaultId,
121
+ gatewayAddress,
122
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
123
+ }
124
+ exports.instantWithdrawal = instantWithdrawal;
125
+ async function cancelWithdrawal(o) {
126
+ const vaultId = (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId');
127
+ const gatewayAddress = (0, utils_js_1.requiredAddressFromOptions)(o);
128
+ await (0, utils_js_1.assertConfirmationPrompt)(`You are about to cancel the pending withdrawal from vault ${vaultId} for with gateway address ${gatewayAddress}\nAre you sure?`, o);
129
+ return (0, utils_js_1.writeIOFromOptions)(o).io.cancelWithdrawal({
130
+ vaultId,
131
+ gatewayAddress,
132
+ }, (0, utils_js_1.writeActionTagsFromOptions)(o));
133
+ }
134
+ exports.cancelWithdrawal = cancelWithdrawal;
135
+ async function delegateStake(options) {
136
+ const { io, signerAddress } = (0, utils_js_1.writeIOFromOptions)(options);
137
+ const { target, ioQuantity } = (0, utils_js_1.requiredTargetAndQuantityFromOptions)(options);
138
+ const mIOQuantity = ioQuantity.toMIO();
139
+ if (!options.skipConfirmation) {
140
+ const balance = await io.getBalance({ address: signerAddress });
141
+ if (balance < mIOQuantity.valueOf()) {
142
+ throw new Error(`Insufficient IO balance for delegating stake. Balance available: ${new index_js_1.mIOToken(balance).toIO()} IO`);
143
+ }
144
+ const targetGateway = await io.getGateway({ address: target });
145
+ if (targetGateway === undefined) {
146
+ throw new Error(`Gateway not found for address: ${target}`);
147
+ }
148
+ if (targetGateway.settings.allowDelegatedStaking === false) {
149
+ throw new Error(`Gateway does not allow delegated staking: ${target}`);
150
+ }
151
+ // TODO: could get allow list and assert doesn't exist or user is on it
152
+ // TODO: could read from contract to get current delegated stake if there is none, get contract minimum delegated stake. Then see if the new stake value will satisfy minimum delegated stake for both the target gateway settings min delegate stake and contract min delegated amounts
153
+ const { confirm } = await (0, prompts_1.default)({
154
+ type: 'confirm',
155
+ name: 'confirm',
156
+ message: `Target Gateway:\n${JSON.stringify(targetGateway, null, 2)}\n\nAre you sure you want to delegate ${(0, utils_js_1.formatIOWithCommas)(ioQuantity)} IO to ${target}?`,
157
+ });
158
+ if (!confirm) {
159
+ return { message: 'Delegate stake aborted by user' };
160
+ }
161
+ }
162
+ const result = await io.delegateStake({
163
+ target,
164
+ stakeQty: ioQuantity.toMIO(),
165
+ }, (0, utils_js_1.writeActionTagsFromOptions)(options));
166
+ const output = {
167
+ senderAddress: signerAddress,
168
+ transferResult: result,
169
+ message: `Successfully delegated ${(0, utils_js_1.formatIOWithCommas)(ioQuantity)} IO to ${target}`,
170
+ };
171
+ return output;
172
+ }
173
+ exports.delegateStake = delegateStake;
174
+ async function decreaseDelegateStake(options) {
175
+ const io = (0, utils_js_1.writeIOFromOptions)(options).io;
176
+ const { target, ioQuantity } = (0, utils_js_1.requiredTargetAndQuantityFromOptions)(options);
177
+ const instant = options.instant ?? false;
178
+ // TODO: Could assert sender is a delegate with enough stake to decrease
179
+ // TODO: Could assert new target stake meets contract and target gateway minimums
180
+ // TODO: Could present confirmation prompt with any fee for instant withdrawal (50% of the stake is put back into protocol??)
181
+ await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you'd like to decrease delegated stake of ${(0, utils_js_1.formatIOWithCommas)(ioQuantity)} IO on gateway ${target}?`, options);
182
+ const result = await io.decreaseDelegateStake({
183
+ target,
184
+ decreaseQty: ioQuantity.toMIO(),
185
+ instant,
186
+ });
187
+ const output = {
188
+ targetGateway: target,
189
+ decreaseDelegateStakeResult: result,
190
+ message: `Successfully decreased delegated stake of ${(0, utils_js_1.formatIOWithCommas)(ioQuantity)} IO to ${target}`,
191
+ };
192
+ return output;
193
+ }
194
+ exports.decreaseDelegateStake = decreaseDelegateStake;
195
+ async function redelegateStake(options) {
196
+ const io = (0, utils_js_1.writeIOFromOptions)(options).io;
197
+ const params = (0, utils_js_1.redelegateParamsFromOptions)(options);
198
+ // TODO: Could assert target gateway exists
199
+ // TODO: Could do assertion on source has enough stake to redelegate
200
+ // TODO: Could do assertions on source/target min delegate stakes are met
201
+ await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you'd like to redelegate stake of ${(0, utils_js_1.formatIOWithCommas)(params.stakeQty.toIO())} IO from ${params.source} to ${params.target}?`, options);
202
+ const result = await io.redelegateStake(params);
203
+ const output = {
204
+ sourceGateway: params.source,
205
+ targetGateway: params.target,
206
+ redelegateStakeResult: result,
207
+ message: `Successfully re-delegated stake of ${(0, utils_js_1.formatIOWithCommas)(params.stakeQty.toIO())} IO from ${params.source} to ${params.target}`,
208
+ };
209
+ return output;
210
+ }
211
+ exports.redelegateStake = redelegateStake;
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVault = exports.getGatewayVaults = exports.getPrimaryName = exports.getTokenCost = exports.getPrescribedNames = exports.getPrescribedObservers = exports.getEpoch = exports.getArNSAuctionPrices = exports.listArNSAuctions = exports.getArNSAuction = exports.listArNSReservedNames = exports.getArNSReservedName = exports.listArNSRecords = exports.getArNSRecord = exports.getAllowedDelegates = exports.getDelegations = exports.getGatewayDelegates = exports.listGateways = exports.getGateway = void 0;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const io_js_1 = require("../../types/io.js");
20
+ const token_js_1 = require("../../types/token.js");
21
+ const utils_js_1 = require("../utils.js");
22
+ async function getGateway(o) {
23
+ const address = (0, utils_js_1.requiredAddressFromOptions)(o);
24
+ const gateway = await (0, utils_js_1.readIOFromOptions)(o).getGateway({
25
+ address,
26
+ });
27
+ return gateway ?? { message: `No gateway found for address ${address}` };
28
+ }
29
+ exports.getGateway = getGateway;
30
+ async function listGateways(o) {
31
+ const gateways = await (0, utils_js_1.readIOFromOptions)(o).getGateways((0, utils_js_1.paginationParamsFromOptions)(o));
32
+ return gateways.items.length ? gateways : { message: 'No gateways found' };
33
+ }
34
+ exports.listGateways = listGateways;
35
+ async function getGatewayDelegates(o) {
36
+ const address = (0, utils_js_1.requiredAddressFromOptions)(o);
37
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getGatewayDelegates({
38
+ address,
39
+ ...(0, utils_js_1.paginationParamsFromOptions)(o),
40
+ });
41
+ return result.items?.length
42
+ ? result
43
+ : {
44
+ message: `No delegates found for gateway ${address}`,
45
+ };
46
+ }
47
+ exports.getGatewayDelegates = getGatewayDelegates;
48
+ async function getDelegations(o) {
49
+ const address = (0, utils_js_1.requiredAddressFromOptions)(o);
50
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getDelegations({
51
+ address,
52
+ ...(0, utils_js_1.paginationParamsFromOptions)(o),
53
+ });
54
+ return result.items?.length
55
+ ? result
56
+ : {
57
+ message: `No delegations found for address ${address}`,
58
+ };
59
+ }
60
+ exports.getDelegations = getDelegations;
61
+ async function getAllowedDelegates(o) {
62
+ const address = (0, utils_js_1.requiredAddressFromOptions)(o);
63
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getAllowedDelegates({
64
+ address,
65
+ ...(0, utils_js_1.paginationParamsFromOptions)(o),
66
+ });
67
+ return result.items?.length
68
+ ? result
69
+ : {
70
+ message: `No allow list found for gateway delegate ${address}`,
71
+ };
72
+ }
73
+ exports.getAllowedDelegates = getAllowedDelegates;
74
+ async function getArNSRecord(o) {
75
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
76
+ return ((await (0, utils_js_1.readIOFromOptions)(o).getArNSRecord({
77
+ name,
78
+ })) ?? { message: `No record found for name ${name}` });
79
+ }
80
+ exports.getArNSRecord = getArNSRecord;
81
+ async function listArNSRecords(o) {
82
+ const records = await (0, utils_js_1.readIOFromOptions)(o).getArNSRecords((0, utils_js_1.paginationParamsFromOptions)(o));
83
+ return records.items.length ? records : { message: 'No records found' };
84
+ }
85
+ exports.listArNSRecords = listArNSRecords;
86
+ async function getArNSReservedName(o) {
87
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
88
+ return ((await (0, utils_js_1.readIOFromOptions)(o).getArNSReservedName({
89
+ name,
90
+ })) ?? { message: `No reserved name found for name ${name}` });
91
+ }
92
+ exports.getArNSReservedName = getArNSReservedName;
93
+ async function listArNSReservedNames(o) {
94
+ const reservedNames = await (0, utils_js_1.readIOFromOptions)(o).getArNSReservedNames((0, utils_js_1.paginationParamsFromOptions)(o));
95
+ return reservedNames.items.length
96
+ ? reservedNames
97
+ : { message: 'No reserved names found' };
98
+ }
99
+ exports.listArNSReservedNames = listArNSReservedNames;
100
+ async function getArNSAuction(o) {
101
+ const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
102
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getArNSAuction({ name });
103
+ return result ?? { message: `No auction found for name ${name}` };
104
+ }
105
+ exports.getArNSAuction = getArNSAuction;
106
+ async function listArNSAuctions(o) {
107
+ const auctions = await (0, utils_js_1.readIOFromOptions)(o).getArNSAuctions((0, utils_js_1.paginationParamsFromOptions)(o));
108
+ return auctions.items.length ? auctions : { message: 'No auctions found' };
109
+ }
110
+ exports.listArNSAuctions = listArNSAuctions;
111
+ async function getArNSAuctionPrices(o) {
112
+ o.type ??= 'lease';
113
+ if (o.type !== 'lease' && o.type !== 'permabuy') {
114
+ throw new Error(`Invalid type. Valid types are: lease, permabuy`);
115
+ // TODY: type and years helper
116
+ }
117
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getArNSAuctionPrices({
118
+ name: (0, utils_js_1.requiredStringFromOptions)(o, 'name'),
119
+ type: o.type,
120
+ // TODO: intervalMS helper, assert and format
121
+ intervalMs: o.intervalMs !== undefined ? +o.intervalMs : undefined,
122
+ // TODO: timestamp helper, assert and format
123
+ timestamp: o.timestamp !== undefined ? +o.timestamp : undefined,
124
+ // todo: assert years if 'lease'
125
+ years: (0, utils_js_1.positiveIntegerFromOptions)(o, 'years'),
126
+ });
127
+ return result ?? { message: `No auction prices found` };
128
+ }
129
+ exports.getArNSAuctionPrices = getArNSAuctionPrices;
130
+ async function getEpoch(o) {
131
+ const epoch = await (0, utils_js_1.readIOFromOptions)(o).getEpoch((0, utils_js_1.epochInputFromOptions)(o));
132
+ return epoch ?? { message: `No epoch found for provided input` };
133
+ }
134
+ exports.getEpoch = getEpoch;
135
+ async function getPrescribedObservers(o) {
136
+ const epoch = (0, utils_js_1.epochInputFromOptions)(o);
137
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getPrescribedObservers(epoch);
138
+ return result?.length
139
+ ? result
140
+ : { message: `No prescribed observers found for epoch ${epoch}` };
141
+ }
142
+ exports.getPrescribedObservers = getPrescribedObservers;
143
+ async function getPrescribedNames(o) {
144
+ const epoch = (0, utils_js_1.epochInputFromOptions)(o);
145
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getPrescribedNames((0, utils_js_1.epochInputFromOptions)(o));
146
+ return result?.length
147
+ ? result
148
+ : { message: `No prescribed names found for epoch ${epoch}` };
149
+ }
150
+ exports.getPrescribedNames = getPrescribedNames;
151
+ async function getTokenCost(o) {
152
+ o.intent ??= 'Buy-Record';
153
+ o.type ??= 'lease';
154
+ if (!(0, io_js_1.isValidIntent)(o.intent)) {
155
+ throw new Error(`Invalid intent. Valid intents are: ${io_js_1.validIntents.join(', ')}`);
156
+ }
157
+ if (o.type !== 'lease' && o.type !== 'permabuy') {
158
+ throw new Error(`Invalid type. Valid types are: lease, permabuy`);
159
+ }
160
+ if (o.type === 'lease' &&
161
+ io_js_1.intentsUsingYears.includes(o.intent) &&
162
+ o.years === undefined) {
163
+ throw new Error('Years is required for lease type');
164
+ }
165
+ const tokenCost = await (0, utils_js_1.readIOFromOptions)(o).getTokenCost({
166
+ type: o.type,
167
+ quantity: o.quantity !== undefined ? +o.quantity : undefined,
168
+ years: o.years !== undefined ? +o.years : undefined,
169
+ intent: o.intent,
170
+ name: (0, utils_js_1.requiredStringFromOptions)(o, 'name'),
171
+ });
172
+ const output = {
173
+ mIOTokenCost: tokenCost,
174
+ message: `The cost of the provided action is ${(0, utils_js_1.formatIOWithCommas)(new token_js_1.mIOToken(tokenCost).toIO())} IO`,
175
+ };
176
+ return output;
177
+ }
178
+ exports.getTokenCost = getTokenCost;
179
+ async function getPrimaryName(o) {
180
+ const address = (0, utils_js_1.addressFromOptions)(o);
181
+ const name = o.name;
182
+ const params = name !== undefined
183
+ ? { name }
184
+ : address !== undefined
185
+ ? { address }
186
+ : undefined;
187
+ if (params === undefined) {
188
+ throw new Error('Either --address or --name is required');
189
+ }
190
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getPrimaryName(params);
191
+ return (result ?? {
192
+ message: `No primary name found`,
193
+ });
194
+ }
195
+ exports.getPrimaryName = getPrimaryName;
196
+ async function getGatewayVaults(o) {
197
+ const address = (0, utils_js_1.requiredAddressFromOptions)(o);
198
+ const result = await (0, utils_js_1.readIOFromOptions)(o).getGatewayVaults({
199
+ address,
200
+ ...(0, utils_js_1.paginationParamsFromOptions)(o),
201
+ });
202
+ return result.items?.length
203
+ ? result
204
+ : {
205
+ message: `No vaults found for gateway ${address}`,
206
+ };
207
+ }
208
+ exports.getGatewayVaults = getGatewayVaults;
209
+ async function getVault(o) {
210
+ return (0, utils_js_1.readIOFromOptions)(o)
211
+ .getVault({
212
+ address: (0, utils_js_1.requiredAddressFromOptions)(o),
213
+ vaultId: (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId'),
214
+ })
215
+ .then((r) => r ?? {
216
+ message: `No vault found for provided address and vault ID`,
217
+ });
218
+ }
219
+ exports.getVault = getVault;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transfer = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ async function transfer(options) {
6
+ const { target, ioQuantity } = (0, utils_js_1.requiredTargetAndQuantityFromOptions)(options);
7
+ const { io, signerAddress } = (0, utils_js_1.writeIOFromOptions)(options);
8
+ if (!options.skipConfirmation) {
9
+ await (0, utils_js_1.assertEnoughBalance)(io, signerAddress, ioQuantity);
10
+ const confirm = await (0, utils_js_1.confirmationPrompt)(`Are you sure you want to transfer ${(0, utils_js_1.formatIOWithCommas)(ioQuantity)} IO to ${target}?`);
11
+ if (!confirm) {
12
+ return { message: 'Transfer aborted by user' };
13
+ }
14
+ }
15
+ const result = await io.transfer({
16
+ target,
17
+ qty: ioQuantity.toMIO().valueOf(),
18
+ }, (0, utils_js_1.writeActionTagsFromOptions)(options));
19
+ const output = {
20
+ senderAddress: signerAddress,
21
+ transferResult: result,
22
+ message: `Successfully transferred ${(0, utils_js_1.formatIOWithCommas)(ioQuantity)} IO to ${target}`,
23
+ };
24
+ return output;
25
+ }
26
+ exports.transfer = transfer;