@ar.io/sdk 2.7.0-alpha.7 → 3.0.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 +186 -186
- package/bundles/web.bundle.min.js +2 -2
- package/lib/cjs/cli/cli.js +26 -26
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +39 -39
- package/lib/cjs/cli/commands/readCommands.js +19 -19
- package/lib/cjs/cli/commands/transfer.js +7 -7
- package/lib/cjs/cli/options.js +4 -4
- package/lib/cjs/cli/utils.js +25 -25
- package/lib/cjs/common/ant.js +18 -14
- package/lib/cjs/common/io.js +11 -11
- package/lib/cjs/constants.js +5 -5
- package/lib/cjs/types/token.js +14 -14
- package/lib/cjs/utils/processes.js +4 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +28 -28
- package/lib/esm/cli/commands/gatewayWriteCommands.js +41 -41
- package/lib/esm/cli/commands/readCommands.js +21 -21
- package/lib/esm/cli/commands/transfer.js +8 -8
- package/lib/esm/cli/options.js +4 -4
- package/lib/esm/cli/utils.js +21 -21
- package/lib/esm/common/ant.js +18 -14
- package/lib/esm/common/io.js +8 -8
- package/lib/esm/constants.js +4 -4
- package/lib/esm/types/token.js +12 -12
- package/lib/esm/utils/processes.js +6 -6
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/options.d.ts +1 -1
- package/lib/types/cli/types.d.ts +1 -1
- package/lib/types/cli/utils.d.ts +10 -10
- package/lib/types/common/ant.d.ts +14 -14
- package/lib/types/common/io.d.ts +16 -16
- package/lib/types/constants.d.ts +4 -4
- package/lib/types/types/ant.d.ts +8 -8
- package/lib/types/types/io.d.ts +9 -9
- package/lib/types/types/token.d.ts +8 -8
- package/lib/types/utils/processes.d.ts +4 -4
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import prompts from 'prompts';
|
|
17
|
-
import {
|
|
18
|
-
import { assertConfirmationPrompt, assertEnoughBalance,
|
|
17
|
+
import { mARIOToken } from '../../node/index.js';
|
|
18
|
+
import { assertConfirmationPrompt, assertEnoughBalance, formatARIOWithCommas, gatewaySettingsFromOptions, redelegateParamsFromOptions, requiredAddressFromOptions, requiredMIOFromOptions as requiredMARIOFromOptions, requiredStringArrayFromOptions, requiredStringFromOptions, requiredTargetAndQuantityFromOptions, stringifyJsonForCLIDisplay, writeARIOFromOptions, writeActionTagsFromOptions, } from '../utils.js';
|
|
19
19
|
export async function joinNetwork(options) {
|
|
20
|
-
const {
|
|
20
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
21
21
|
const mARIOQuantity = requiredMARIOFromOptions(options, 'operatorStake');
|
|
22
22
|
const settings = {
|
|
23
23
|
...gatewaySettingsFromOptions(options),
|
|
@@ -30,14 +30,14 @@ export async function joinNetwork(options) {
|
|
|
30
30
|
throw new Error('FQDN is required. Please provide a --fqdn for your node.');
|
|
31
31
|
}
|
|
32
32
|
if (!options.skipConfirmation) {
|
|
33
|
-
const settings = await
|
|
33
|
+
const settings = await ario.getGatewayRegistrySettings();
|
|
34
34
|
if (settings.operators.minStake > mARIOQuantity.valueOf()) {
|
|
35
|
-
throw new Error(`The minimum operator stake is ${
|
|
35
|
+
throw new Error(`The minimum operator stake is ${formatARIOWithCommas(new mARIOToken(settings.operators.minStake).toARIO())} ARIO. Please provide a higher stake.`);
|
|
36
36
|
}
|
|
37
|
-
await assertEnoughBalance(
|
|
38
|
-
await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${
|
|
37
|
+
await assertEnoughBalance(ario, signerAddress, mARIOQuantity.toARIO());
|
|
38
|
+
await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${formatARIOWithCommas(mARIOQuantity.toARIO())} ARIO to join the AR.IO network\nAre you sure?\n`, options);
|
|
39
39
|
}
|
|
40
|
-
const result = await
|
|
40
|
+
const result = await ario.joinNetwork(settings, writeActionTagsFromOptions(options));
|
|
41
41
|
const output = {
|
|
42
42
|
joinNetworkResult: result,
|
|
43
43
|
joinedAddress: signerAddress,
|
|
@@ -46,14 +46,14 @@ export async function joinNetwork(options) {
|
|
|
46
46
|
return output;
|
|
47
47
|
}
|
|
48
48
|
export async function updateGatewaySettings(options) {
|
|
49
|
-
const {
|
|
49
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
50
50
|
const gatewaySettings = gatewaySettingsFromOptions(options);
|
|
51
51
|
if (Object.keys(gatewaySettings).length === 0) {
|
|
52
52
|
// TODO: The contract accepts empty Update-Gateway-Settings actions, but we'll throw in the CLI for now
|
|
53
53
|
throw new Error('No gateway settings provided');
|
|
54
54
|
}
|
|
55
55
|
await assertConfirmationPrompt(`Gateway Settings:\n\n${stringifyJsonForCLIDisplay(gatewaySettings)}\n\nYou are about to update your gateway settings to the above\nAre you sure?\n`, options);
|
|
56
|
-
const result = await
|
|
56
|
+
const result = await ario.updateGatewaySettings(gatewaySettings, writeActionTagsFromOptions(options));
|
|
57
57
|
const output = {
|
|
58
58
|
updateGatewaySettingsResult: result,
|
|
59
59
|
updatedGatewayAddress: signerAddress,
|
|
@@ -62,9 +62,9 @@ export async function updateGatewaySettings(options) {
|
|
|
62
62
|
return output;
|
|
63
63
|
}
|
|
64
64
|
export async function leaveNetwork(options) {
|
|
65
|
-
const {
|
|
65
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
66
66
|
if (!options.skipConfirmation) {
|
|
67
|
-
const gateway = await
|
|
67
|
+
const gateway = await ario.getGateway({ address: signerAddress });
|
|
68
68
|
if (!gateway) {
|
|
69
69
|
throw new Error(`Gateway not found for address: ${signerAddress}`);
|
|
70
70
|
}
|
|
@@ -73,21 +73,21 @@ export async function leaveNetwork(options) {
|
|
|
73
73
|
'\n\n' +
|
|
74
74
|
'Are you sure you want to leave the AR.IO network?', options);
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return writeARIOFromOptions(options).ario.leaveNetwork(writeActionTagsFromOptions(options));
|
|
77
77
|
}
|
|
78
78
|
export async function saveObservations(o) {
|
|
79
79
|
const failedGateways = requiredStringArrayFromOptions(o, 'failedGateways');
|
|
80
80
|
const reportTxId = requiredStringFromOptions(o, 'transactionId');
|
|
81
81
|
await assertConfirmationPrompt(`You are about to save the following failed gateways to the AR.IO network:\n\n${failedGateways.join('\n')}\n\nTransaction ID: ${reportTxId}\n\nAre you sure?`, o);
|
|
82
|
-
return
|
|
82
|
+
return writeARIOFromOptions(o).ario.saveObservations({
|
|
83
83
|
failedGateways: requiredStringArrayFromOptions(o, 'failedGateways'),
|
|
84
84
|
reportTxId: requiredStringFromOptions(o, 'transactionId'),
|
|
85
85
|
}, writeActionTagsFromOptions(o));
|
|
86
86
|
}
|
|
87
87
|
export async function increaseOperatorStake(o) {
|
|
88
88
|
const increaseQty = requiredMARIOFromOptions(o, 'operatorStake');
|
|
89
|
-
await assertConfirmationPrompt(`You are about to increase your operator stake by ${
|
|
90
|
-
return (
|
|
89
|
+
await assertConfirmationPrompt(`You are about to increase your operator stake by ${formatARIOWithCommas(increaseQty.toARIO())} ARIO\nAre you sure?`, o);
|
|
90
|
+
return (writeARIOFromOptions(o).ario.increaseOperatorStake({
|
|
91
91
|
increaseQty,
|
|
92
92
|
}),
|
|
93
93
|
writeActionTagsFromOptions(o));
|
|
@@ -95,8 +95,8 @@ export async function increaseOperatorStake(o) {
|
|
|
95
95
|
export async function decreaseOperatorStake(o) {
|
|
96
96
|
const decreaseQty = requiredMARIOFromOptions(o, 'operatorStake');
|
|
97
97
|
// TODO: Can assert stake is sufficient for action, and new target stake meets contract minimum
|
|
98
|
-
await assertConfirmationPrompt(`You are about to decrease your operator stake by ${
|
|
99
|
-
return
|
|
98
|
+
await assertConfirmationPrompt(`You are about to decrease your operator stake by ${formatARIOWithCommas(decreaseQty.toARIO())} ARIO\nAre you sure?`, o);
|
|
99
|
+
return writeARIOFromOptions(o).ario.decreaseOperatorStake({
|
|
100
100
|
decreaseQty,
|
|
101
101
|
}, writeActionTagsFromOptions(o));
|
|
102
102
|
}
|
|
@@ -104,7 +104,7 @@ export async function instantWithdrawal(o) {
|
|
|
104
104
|
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
105
105
|
const gatewayAddress = requiredAddressFromOptions(o);
|
|
106
106
|
await assertConfirmationPrompt(`You are about to instantly withdraw from vault ${vaultId} for with gateway address ${gatewayAddress}\nAre you sure?`, o);
|
|
107
|
-
return
|
|
107
|
+
return writeARIOFromOptions(o).ario.instantWithdrawal({
|
|
108
108
|
vaultId,
|
|
109
109
|
gatewayAddress,
|
|
110
110
|
}, writeActionTagsFromOptions(o));
|
|
@@ -113,21 +113,21 @@ export async function cancelWithdrawal(o) {
|
|
|
113
113
|
const vaultId = requiredStringFromOptions(o, 'vaultId');
|
|
114
114
|
const gatewayAddress = requiredAddressFromOptions(o);
|
|
115
115
|
await assertConfirmationPrompt(`You are about to cancel the pending withdrawal from vault ${vaultId} for with gateway address ${gatewayAddress}\nAre you sure?`, o);
|
|
116
|
-
return
|
|
116
|
+
return writeARIOFromOptions(o).ario.cancelWithdrawal({
|
|
117
117
|
vaultId,
|
|
118
118
|
gatewayAddress,
|
|
119
119
|
}, writeActionTagsFromOptions(o));
|
|
120
120
|
}
|
|
121
121
|
export async function delegateStake(options) {
|
|
122
|
-
const {
|
|
123
|
-
const { target,
|
|
124
|
-
const
|
|
122
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
123
|
+
const { target, arioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
124
|
+
const mARIOQuantity = arioQuantity.toMARIO();
|
|
125
125
|
if (!options.skipConfirmation) {
|
|
126
|
-
const balance = await
|
|
127
|
-
if (balance <
|
|
128
|
-
throw new Error(`Insufficient
|
|
126
|
+
const balance = await ario.getBalance({ address: signerAddress });
|
|
127
|
+
if (balance < mARIOQuantity.valueOf()) {
|
|
128
|
+
throw new Error(`Insufficient ARIO balance for delegating stake. Balance available: ${new mARIOToken(balance).toARIO()} ARIO`);
|
|
129
129
|
}
|
|
130
|
-
const targetGateway = await
|
|
130
|
+
const targetGateway = await ario.getGateway({ address: target });
|
|
131
131
|
if (targetGateway === undefined) {
|
|
132
132
|
throw new Error(`Gateway not found for address: ${target}`);
|
|
133
133
|
}
|
|
@@ -139,56 +139,56 @@ export async function delegateStake(options) {
|
|
|
139
139
|
const { confirm } = await prompts({
|
|
140
140
|
type: 'confirm',
|
|
141
141
|
name: 'confirm',
|
|
142
|
-
message: `Target Gateway:\n${JSON.stringify(targetGateway, null, 2)}\n\nAre you sure you want to delegate ${
|
|
142
|
+
message: `Target Gateway:\n${JSON.stringify(targetGateway, null, 2)}\n\nAre you sure you want to delegate ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}?`,
|
|
143
143
|
});
|
|
144
144
|
if (!confirm) {
|
|
145
145
|
return { message: 'Delegate stake aborted by user' };
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
const result = await
|
|
148
|
+
const result = await ario.delegateStake({
|
|
149
149
|
target,
|
|
150
|
-
stakeQty:
|
|
150
|
+
stakeQty: arioQuantity.toMARIO(),
|
|
151
151
|
}, writeActionTagsFromOptions(options));
|
|
152
152
|
const output = {
|
|
153
153
|
senderAddress: signerAddress,
|
|
154
154
|
transferResult: result,
|
|
155
|
-
message: `Successfully delegated ${
|
|
155
|
+
message: `Successfully delegated ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}`,
|
|
156
156
|
};
|
|
157
157
|
return output;
|
|
158
158
|
}
|
|
159
159
|
export async function decreaseDelegateStake(options) {
|
|
160
|
-
const
|
|
161
|
-
const { target,
|
|
160
|
+
const ario = writeARIOFromOptions(options).ario;
|
|
161
|
+
const { target, arioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
162
162
|
const instant = options.instant ?? false;
|
|
163
163
|
// TODO: Could assert sender is a delegate with enough stake to decrease
|
|
164
164
|
// TODO: Could assert new target stake meets contract and target gateway minimums
|
|
165
165
|
// TODO: Could present confirmation prompt with any fee for instant withdrawal (50% of the stake is put back into protocol??)
|
|
166
|
-
await assertConfirmationPrompt(`Are you sure you'd like to decrease delegated stake of ${
|
|
167
|
-
const result = await
|
|
166
|
+
await assertConfirmationPrompt(`Are you sure you'd like to decrease delegated stake of ${formatARIOWithCommas(arioQuantity)} ARIO on gateway ${target}?`, options);
|
|
167
|
+
const result = await ario.decreaseDelegateStake({
|
|
168
168
|
target,
|
|
169
|
-
decreaseQty:
|
|
169
|
+
decreaseQty: arioQuantity.toMARIO(),
|
|
170
170
|
instant,
|
|
171
171
|
});
|
|
172
172
|
const output = {
|
|
173
173
|
targetGateway: target,
|
|
174
174
|
decreaseDelegateStakeResult: result,
|
|
175
|
-
message: `Successfully decreased delegated stake of ${
|
|
175
|
+
message: `Successfully decreased delegated stake of ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}`,
|
|
176
176
|
};
|
|
177
177
|
return output;
|
|
178
178
|
}
|
|
179
179
|
export async function redelegateStake(options) {
|
|
180
|
-
const
|
|
180
|
+
const ario = writeARIOFromOptions(options).ario;
|
|
181
181
|
const params = redelegateParamsFromOptions(options);
|
|
182
182
|
// TODO: Could assert target gateway exists
|
|
183
183
|
// TODO: Could do assertion on source has enough stake to redelegate
|
|
184
184
|
// TODO: Could do assertions on source/target min delegate stakes are met
|
|
185
|
-
await assertConfirmationPrompt(`Are you sure you'd like to redelegate stake of ${
|
|
186
|
-
const result = await
|
|
185
|
+
await assertConfirmationPrompt(`Are you sure you'd like to redelegate stake of ${formatARIOWithCommas(params.stakeQty.toARIO())} ARIO from ${params.source} to ${params.target}?`, options);
|
|
186
|
+
const result = await ario.redelegateStake(params);
|
|
187
187
|
const output = {
|
|
188
188
|
sourceGateway: params.source,
|
|
189
189
|
targetGateway: params.target,
|
|
190
190
|
redelegateStakeResult: result,
|
|
191
|
-
message: `Successfully re-delegated stake of ${
|
|
191
|
+
message: `Successfully re-delegated stake of ${formatARIOWithCommas(params.stakeQty.toARIO())} ARIO from ${params.source} to ${params.target}`,
|
|
192
192
|
};
|
|
193
193
|
return output;
|
|
194
194
|
}
|
|
@@ -14,22 +14,22 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { intentsUsingYears, isValidIntent, validIntents, } from '../../types/io.js';
|
|
17
|
-
import {
|
|
18
|
-
import { addressFromOptions, epochInputFromOptions,
|
|
17
|
+
import { mARIOToken } from '../../types/token.js';
|
|
18
|
+
import { addressFromOptions, epochInputFromOptions, formatARIOWithCommas, paginationParamsFromOptions, readARIOFromOptions, requiredAddressFromOptions, requiredStringFromOptions, } from '../utils.js';
|
|
19
19
|
export async function getGateway(o) {
|
|
20
20
|
const address = requiredAddressFromOptions(o);
|
|
21
|
-
const gateway = await
|
|
21
|
+
const gateway = await readARIOFromOptions(o).getGateway({
|
|
22
22
|
address,
|
|
23
23
|
});
|
|
24
24
|
return gateway ?? { message: `No gateway found for address ${address}` };
|
|
25
25
|
}
|
|
26
26
|
export async function listGateways(o) {
|
|
27
|
-
const gateways = await
|
|
27
|
+
const gateways = await readARIOFromOptions(o).getGateways(paginationParamsFromOptions(o));
|
|
28
28
|
return gateways.items.length ? gateways : { message: 'No gateways found' };
|
|
29
29
|
}
|
|
30
30
|
export async function getGatewayDelegates(o) {
|
|
31
31
|
const address = requiredAddressFromOptions(o);
|
|
32
|
-
const result = await
|
|
32
|
+
const result = await readARIOFromOptions(o).getGatewayDelegates({
|
|
33
33
|
address,
|
|
34
34
|
...paginationParamsFromOptions(o),
|
|
35
35
|
});
|
|
@@ -41,7 +41,7 @@ export async function getGatewayDelegates(o) {
|
|
|
41
41
|
}
|
|
42
42
|
export async function getDelegations(o) {
|
|
43
43
|
const address = requiredAddressFromOptions(o);
|
|
44
|
-
const result = await
|
|
44
|
+
const result = await readARIOFromOptions(o).getDelegations({
|
|
45
45
|
address,
|
|
46
46
|
...paginationParamsFromOptions(o),
|
|
47
47
|
});
|
|
@@ -53,7 +53,7 @@ export async function getDelegations(o) {
|
|
|
53
53
|
}
|
|
54
54
|
export async function getAllowedDelegates(o) {
|
|
55
55
|
const address = requiredAddressFromOptions(o);
|
|
56
|
-
const result = await
|
|
56
|
+
const result = await readARIOFromOptions(o).getAllowedDelegates({
|
|
57
57
|
address,
|
|
58
58
|
...paginationParamsFromOptions(o),
|
|
59
59
|
});
|
|
@@ -65,51 +65,51 @@ export async function getAllowedDelegates(o) {
|
|
|
65
65
|
}
|
|
66
66
|
export async function getArNSRecord(o) {
|
|
67
67
|
const name = requiredStringFromOptions(o, 'name');
|
|
68
|
-
return ((await
|
|
68
|
+
return ((await readARIOFromOptions(o).getArNSRecord({
|
|
69
69
|
name,
|
|
70
70
|
})) ?? { message: `No record found for name ${name}` });
|
|
71
71
|
}
|
|
72
72
|
export async function listArNSRecords(o) {
|
|
73
|
-
const records = await
|
|
73
|
+
const records = await readARIOFromOptions(o).getArNSRecords(paginationParamsFromOptions(o));
|
|
74
74
|
return records.items.length ? records : { message: 'No records found' };
|
|
75
75
|
}
|
|
76
76
|
export async function getArNSReservedName(o) {
|
|
77
77
|
const name = requiredStringFromOptions(o, 'name');
|
|
78
|
-
return ((await
|
|
78
|
+
return ((await readARIOFromOptions(o).getArNSReservedName({
|
|
79
79
|
name,
|
|
80
80
|
})) ?? { message: `No reserved name found for name ${name}` });
|
|
81
81
|
}
|
|
82
82
|
export async function listArNSReservedNames(o) {
|
|
83
|
-
const reservedNames = await
|
|
83
|
+
const reservedNames = await readARIOFromOptions(o).getArNSReservedNames(paginationParamsFromOptions(o));
|
|
84
84
|
return reservedNames.items.length
|
|
85
85
|
? reservedNames
|
|
86
86
|
: { message: 'No reserved names found' };
|
|
87
87
|
}
|
|
88
88
|
export async function getArNSReturnedName(o) {
|
|
89
89
|
const name = requiredStringFromOptions(o, 'name');
|
|
90
|
-
const result = await
|
|
90
|
+
const result = await readARIOFromOptions(o).getArNSReturnedName({ name });
|
|
91
91
|
return result ?? { message: `No returned name found for name ${name}` };
|
|
92
92
|
}
|
|
93
93
|
export async function listArNSReturnedNames(o) {
|
|
94
|
-
const returnedNames = await
|
|
94
|
+
const returnedNames = await readARIOFromOptions(o).getArNSReturnedNames(paginationParamsFromOptions(o));
|
|
95
95
|
return returnedNames.items.length
|
|
96
96
|
? returnedNames
|
|
97
97
|
: { message: 'No returned names found' };
|
|
98
98
|
}
|
|
99
99
|
export async function getEpoch(o) {
|
|
100
|
-
const epoch = await
|
|
100
|
+
const epoch = await readARIOFromOptions(o).getEpoch(epochInputFromOptions(o));
|
|
101
101
|
return epoch ?? { message: `No epoch found for provided input` };
|
|
102
102
|
}
|
|
103
103
|
export async function getPrescribedObservers(o) {
|
|
104
104
|
const epoch = epochInputFromOptions(o);
|
|
105
|
-
const result = await
|
|
105
|
+
const result = await readARIOFromOptions(o).getPrescribedObservers(epoch);
|
|
106
106
|
return result?.length
|
|
107
107
|
? result
|
|
108
108
|
: { message: `No prescribed observers found for epoch ${epoch}` };
|
|
109
109
|
}
|
|
110
110
|
export async function getPrescribedNames(o) {
|
|
111
111
|
const epoch = epochInputFromOptions(o);
|
|
112
|
-
const result = await
|
|
112
|
+
const result = await readARIOFromOptions(o).getPrescribedNames(epochInputFromOptions(o));
|
|
113
113
|
return result?.length
|
|
114
114
|
? result
|
|
115
115
|
: { message: `No prescribed names found for epoch ${epoch}` };
|
|
@@ -128,7 +128,7 @@ export async function getTokenCost(o) {
|
|
|
128
128
|
o.years === undefined) {
|
|
129
129
|
throw new Error('Years is required for lease type');
|
|
130
130
|
}
|
|
131
|
-
const tokenCost = await
|
|
131
|
+
const tokenCost = await readARIOFromOptions(o).getTokenCost({
|
|
132
132
|
type: o.type,
|
|
133
133
|
quantity: o.quantity !== undefined ? +o.quantity : undefined,
|
|
134
134
|
years: o.years !== undefined ? +o.years : undefined,
|
|
@@ -137,7 +137,7 @@ export async function getTokenCost(o) {
|
|
|
137
137
|
});
|
|
138
138
|
const output = {
|
|
139
139
|
mIOTokenCost: tokenCost,
|
|
140
|
-
message: `The cost of the provided action is ${
|
|
140
|
+
message: `The cost of the provided action is ${formatARIOWithCommas(new mARIOToken(tokenCost).toARIO())} ARIO`,
|
|
141
141
|
};
|
|
142
142
|
return output;
|
|
143
143
|
}
|
|
@@ -152,14 +152,14 @@ export async function getPrimaryName(o) {
|
|
|
152
152
|
if (params === undefined) {
|
|
153
153
|
throw new Error('Either --address or --name is required');
|
|
154
154
|
}
|
|
155
|
-
const result = await
|
|
155
|
+
const result = await readARIOFromOptions(o).getPrimaryName(params);
|
|
156
156
|
return (result ?? {
|
|
157
157
|
message: `No primary name found`,
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
export async function getGatewayVaults(o) {
|
|
161
161
|
const address = requiredAddressFromOptions(o);
|
|
162
|
-
const result = await
|
|
162
|
+
const result = await readARIOFromOptions(o).getGatewayVaults({
|
|
163
163
|
address,
|
|
164
164
|
...paginationParamsFromOptions(o),
|
|
165
165
|
});
|
|
@@ -170,7 +170,7 @@ export async function getGatewayVaults(o) {
|
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
172
|
export async function getVault(o) {
|
|
173
|
-
return
|
|
173
|
+
return readARIOFromOptions(o)
|
|
174
174
|
.getVault({
|
|
175
175
|
address: requiredAddressFromOptions(o),
|
|
176
176
|
vaultId: requiredStringFromOptions(o, 'vaultId'),
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { assertEnoughBalance, confirmationPrompt,
|
|
1
|
+
import { assertEnoughBalance, confirmationPrompt, formatARIOWithCommas, requiredTargetAndQuantityFromOptions, writeARIOFromOptions, writeActionTagsFromOptions, } from '../utils.js';
|
|
2
2
|
export async function transfer(options) {
|
|
3
|
-
const { target,
|
|
4
|
-
const {
|
|
3
|
+
const { target, arioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
4
|
+
const { ario, signerAddress } = writeARIOFromOptions(options);
|
|
5
5
|
if (!options.skipConfirmation) {
|
|
6
|
-
await assertEnoughBalance(
|
|
7
|
-
const confirm = await confirmationPrompt(`Are you sure you want to transfer ${
|
|
6
|
+
await assertEnoughBalance(ario, signerAddress, arioQuantity);
|
|
7
|
+
const confirm = await confirmationPrompt(`Are you sure you want to transfer ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}?`);
|
|
8
8
|
if (!confirm) {
|
|
9
9
|
return { message: 'Transfer aborted by user' };
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
const result = await
|
|
12
|
+
const result = await ario.transfer({
|
|
13
13
|
target,
|
|
14
|
-
qty:
|
|
14
|
+
qty: arioQuantity.toMARIO().valueOf(),
|
|
15
15
|
}, writeActionTagsFromOptions(options));
|
|
16
16
|
const output = {
|
|
17
17
|
senderAddress: signerAddress,
|
|
18
18
|
transferResult: result,
|
|
19
|
-
message: `Successfully transferred ${
|
|
19
|
+
message: `Successfully transferred ${formatARIOWithCommas(arioQuantity)} ARIO to ${target}`,
|
|
20
20
|
};
|
|
21
21
|
return output;
|
|
22
22
|
}
|
package/lib/esm/cli/options.js
CHANGED
|
@@ -31,8 +31,8 @@ export const optionMap = {
|
|
|
31
31
|
description: 'Run against the AR.IO devnet process',
|
|
32
32
|
type: 'boolean',
|
|
33
33
|
},
|
|
34
|
-
|
|
35
|
-
alias: '--
|
|
34
|
+
arioProcessId: {
|
|
35
|
+
alias: '--ario-process-id <arioProcessId>',
|
|
36
36
|
description: 'Run against a custom AR.IO process id',
|
|
37
37
|
},
|
|
38
38
|
cuUrl: {
|
|
@@ -62,7 +62,7 @@ export const optionMap = {
|
|
|
62
62
|
},
|
|
63
63
|
quantity: {
|
|
64
64
|
alias: '-q, --quantity <quantity>',
|
|
65
|
-
description: 'The quantity of
|
|
65
|
+
description: 'The quantity of ARIO to interact with',
|
|
66
66
|
},
|
|
67
67
|
autoStake: {
|
|
68
68
|
alias: '--auto-stake',
|
|
@@ -244,7 +244,7 @@ export const globalOptions = [
|
|
|
244
244
|
...walletOptions,
|
|
245
245
|
optionMap.dev,
|
|
246
246
|
optionMap.debug,
|
|
247
|
-
optionMap.
|
|
247
|
+
optionMap.arioProcessId,
|
|
248
248
|
optionMap.cuUrl,
|
|
249
249
|
];
|
|
250
250
|
export const writeActionOptions = [optionMap.skipConfirmation, optionMap.tags];
|
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,
|
|
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';
|
|
21
21
|
import { globalOptions } from './options.js';
|
|
22
22
|
export function stringifyJsonForCLIDisplay(json) {
|
|
23
23
|
return JSON.stringify(json, null, 2);
|
|
@@ -64,12 +64,12 @@ export function makeCommand({ description, name, options = [], action, }) {
|
|
|
64
64
|
}
|
|
65
65
|
return appliedCommand;
|
|
66
66
|
}
|
|
67
|
-
export function
|
|
68
|
-
return
|
|
69
|
-
?
|
|
67
|
+
export function arioProcessIdFromOptions({ arioProcessId, dev, }) {
|
|
68
|
+
return arioProcessId !== undefined
|
|
69
|
+
? arioProcessId
|
|
70
70
|
: dev
|
|
71
|
-
?
|
|
72
|
-
:
|
|
71
|
+
? ARIO_DEVNET_PROCESS_ID
|
|
72
|
+
: ARIO_TESTNET_PROCESS_ID;
|
|
73
73
|
}
|
|
74
74
|
function jwkFromOptions({ privateKey, walletFile, }) {
|
|
75
75
|
if (privateKey !== undefined) {
|
|
@@ -101,15 +101,15 @@ export function getLoggerFromOptions(options) {
|
|
|
101
101
|
}
|
|
102
102
|
function aoProcessFromOptions(options) {
|
|
103
103
|
return new AOProcess({
|
|
104
|
-
processId:
|
|
104
|
+
processId: arioProcessIdFromOptions(options),
|
|
105
105
|
ao: connect({
|
|
106
106
|
CU_URL: options.cuUrl,
|
|
107
107
|
}),
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
-
export function
|
|
110
|
+
export function readARIOFromOptions(options) {
|
|
111
111
|
setLoggerIfDebug(options);
|
|
112
|
-
return
|
|
112
|
+
return ARIO.init({
|
|
113
113
|
process: aoProcessFromOptions(options),
|
|
114
114
|
});
|
|
115
115
|
}
|
|
@@ -122,18 +122,18 @@ export function requiredContractSignerFromOptions(options) {
|
|
|
122
122
|
export function requiredAoSignerFromOptions(options) {
|
|
123
123
|
return createAoSigner(requiredContractSignerFromOptions(options).signer);
|
|
124
124
|
}
|
|
125
|
-
export function
|
|
125
|
+
export function writeARIOFromOptions(options) {
|
|
126
126
|
const { signer, signerAddress } = requiredContractSignerFromOptions(options);
|
|
127
127
|
setLoggerIfDebug(options);
|
|
128
128
|
return {
|
|
129
|
-
|
|
129
|
+
ario: ARIO.init({
|
|
130
130
|
process: aoProcessFromOptions(options),
|
|
131
131
|
signer,
|
|
132
132
|
}),
|
|
133
133
|
signerAddress,
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
export function
|
|
136
|
+
export function formatARIOWithCommas(value) {
|
|
137
137
|
const [integerPart, decimalPart] = value.toString().split('.');
|
|
138
138
|
const integerWithCommas = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
139
139
|
if (decimalPart === undefined) {
|
|
@@ -242,11 +242,11 @@ export function requiredTargetAndQuantityFromOptions(options) {
|
|
|
242
242
|
}
|
|
243
243
|
return {
|
|
244
244
|
target: options.target,
|
|
245
|
-
|
|
245
|
+
arioQuantity: new ARIOToken(+options.quantity),
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
248
|
export function redelegateParamsFromOptions(options) {
|
|
249
|
-
const { target,
|
|
249
|
+
const { target, arioQuantity: aRIOQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
250
250
|
const source = options.source;
|
|
251
251
|
if (source === undefined) {
|
|
252
252
|
throw new Error('No source provided. Use --source');
|
|
@@ -255,7 +255,7 @@ export function redelegateParamsFromOptions(options) {
|
|
|
255
255
|
target,
|
|
256
256
|
source,
|
|
257
257
|
vaultId: options.vaultId,
|
|
258
|
-
stakeQty:
|
|
258
|
+
stakeQty: aRIOQuantity.toMARIO(),
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
261
|
export function recordTypeFromOptions(options) {
|
|
@@ -267,14 +267,14 @@ export function recordTypeFromOptions(options) {
|
|
|
267
267
|
}
|
|
268
268
|
export function requiredMIOFromOptions(options, key) {
|
|
269
269
|
if (options[key] === undefined) {
|
|
270
|
-
throw new Error(`No ${key} provided. Use --${key} denominated in
|
|
270
|
+
throw new Error(`No ${key} provided. Use --${key} denominated in ARIO`);
|
|
271
271
|
}
|
|
272
|
-
return new
|
|
272
|
+
return new ARIOToken(+options[key]).toMARIO();
|
|
273
273
|
}
|
|
274
|
-
export async function assertEnoughBalance(
|
|
275
|
-
const balance = await
|
|
276
|
-
if (balance <
|
|
277
|
-
throw new Error(`Insufficient
|
|
274
|
+
export async function assertEnoughBalance(ario, address, arioQuantity) {
|
|
275
|
+
const balance = await ario.getBalance({ address });
|
|
276
|
+
if (balance < arioQuantity.toMARIO().valueOf()) {
|
|
277
|
+
throw new Error(`Insufficient ARIO balance for action. Balance available: ${new mARIOToken(balance).toARIO()} ARIO`);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
export async function confirmationPrompt(message) {
|
package/lib/esm/common/ant.js
CHANGED
|
@@ -407,43 +407,45 @@ export class AoANTWriteable extends AoANTReadable {
|
|
|
407
407
|
});
|
|
408
408
|
}
|
|
409
409
|
/**
|
|
410
|
-
* @param name @type {string} The name you want to release. The name will be put up for as a recently returned name on the
|
|
411
|
-
* @param
|
|
410
|
+
* @param name @type {string} The name you want to release. The name will be put up for as a recently returned name on the ARIO contract. 50% of the winning bid will be distributed to the ANT owner at the time of purchase. If no purchase in the recently returned name period (14 epochs), the name will be released and can be reregistered by anyone.
|
|
411
|
+
* @param arioProcessId @type {string} The processId of the ARIO contract. This is where the ANT will send the message to release the name.
|
|
412
412
|
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
413
413
|
* @example
|
|
414
414
|
* ```ts
|
|
415
|
-
* ant.releaseName({ name: "ardrive",
|
|
415
|
+
* ant.releaseName({ name: "ardrive", arioProcessId: AR_TESTNET_PROCESS_ID });
|
|
416
416
|
* ```
|
|
417
417
|
*/
|
|
418
|
-
async releaseName({ name,
|
|
418
|
+
async releaseName({ name, arioProcessId }, options) {
|
|
419
419
|
return this.process.send({
|
|
420
420
|
tags: [
|
|
421
421
|
...(options?.tags ?? []),
|
|
422
422
|
{ name: 'Action', value: 'Release-Name' },
|
|
423
423
|
{ name: 'Name', value: name },
|
|
424
|
-
{ name: 'IO-Process-Id', value:
|
|
424
|
+
{ name: 'IO-Process-Id', value: arioProcessId },
|
|
425
|
+
{ name: 'ARIO-Process-Id', value: arioProcessId },
|
|
425
426
|
],
|
|
426
427
|
signer: this.signer,
|
|
427
428
|
});
|
|
428
429
|
}
|
|
429
430
|
/**
|
|
430
|
-
* Sends a message to the
|
|
431
|
+
* Sends a message to the ARIO contract to reassign the name to a new ANT. This can only be done by the current owner of the ANT.
|
|
431
432
|
* @param name @type {string} The name you want to reassign.
|
|
432
|
-
* @param
|
|
433
|
+
* @param arioProcessId @type {string} The processId of the ARIO contract.
|
|
433
434
|
* @param antProcessId @type {string} The processId of the ANT contract.
|
|
434
435
|
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
435
436
|
* @example
|
|
436
437
|
* ```ts
|
|
437
|
-
* ant.reassignName({ name: "ardrive",
|
|
438
|
+
* ant.reassignName({ name: "ardrive", arioProcessId: ARIO_TESTNET_PROCESS_ID, antProcessId: NEW_ANT_PROCESS_ID });
|
|
438
439
|
* ```
|
|
439
440
|
*/
|
|
440
|
-
async reassignName({ name,
|
|
441
|
+
async reassignName({ name, arioProcessId, antProcessId, }, options) {
|
|
441
442
|
return this.process.send({
|
|
442
443
|
tags: [
|
|
443
444
|
...(options?.tags ?? []),
|
|
444
445
|
{ name: 'Action', value: 'Reassign-Name' },
|
|
445
446
|
{ name: 'Name', value: name },
|
|
446
|
-
{ name: 'IO-Process-Id', value:
|
|
447
|
+
{ name: 'IO-Process-Id', value: arioProcessId },
|
|
448
|
+
{ name: 'ARIO-Process-Id', value: arioProcessId },
|
|
447
449
|
{ name: 'Process-Id', value: antProcessId },
|
|
448
450
|
],
|
|
449
451
|
signer: this.signer,
|
|
@@ -452,25 +454,27 @@ export class AoANTWriteable extends AoANTReadable {
|
|
|
452
454
|
/**
|
|
453
455
|
* Approves a primary name request for a given name or address.
|
|
454
456
|
*/
|
|
455
|
-
async approvePrimaryNameRequest({ name, address,
|
|
457
|
+
async approvePrimaryNameRequest({ name, address, arioProcessId, }, options) {
|
|
456
458
|
return this.process.send({
|
|
457
459
|
tags: [
|
|
458
460
|
...(options?.tags ?? []),
|
|
459
461
|
{ name: 'Action', value: 'Approve-Primary-Name' },
|
|
460
462
|
{ name: 'Name', value: name },
|
|
461
463
|
{ name: 'Recipient', value: address },
|
|
462
|
-
{ name: 'IO-Process-Id', value:
|
|
464
|
+
{ name: 'IO-Process-Id', value: arioProcessId },
|
|
465
|
+
{ name: 'ARIO-Process-Id', value: arioProcessId },
|
|
463
466
|
],
|
|
464
467
|
signer: this.signer,
|
|
465
468
|
});
|
|
466
469
|
}
|
|
467
|
-
async removePrimaryNames({ names,
|
|
470
|
+
async removePrimaryNames({ names, arioProcessId }, options) {
|
|
468
471
|
return this.process.send({
|
|
469
472
|
tags: [
|
|
470
473
|
...(options?.tags ?? []),
|
|
471
474
|
{ name: 'Action', value: 'Remove-Primary-Names' },
|
|
472
475
|
{ name: 'Names', value: names.join(',') },
|
|
473
|
-
{ name: 'IO-Process-Id', value:
|
|
476
|
+
{ name: 'IO-Process-Id', value: arioProcessId },
|
|
477
|
+
{ name: 'ARIO-Process-Id', value: arioProcessId },
|
|
474
478
|
],
|
|
475
479
|
signer: this.signer,
|
|
476
480
|
});
|