@ar.io/sdk 3.24.0 → 4.0.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 (169) hide show
  1. package/README.md +757 -589
  2. package/lib/esm/cli/cli.js +188 -152
  3. package/lib/esm/cli/commands/antCommands.js +23 -58
  4. package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
  5. package/lib/esm/cli/commands/escrowCommands.js +227 -0
  6. package/lib/esm/cli/commands/gatewayWriteCommands.js +140 -23
  7. package/lib/esm/cli/commands/pruneCommands.js +154 -0
  8. package/lib/esm/cli/commands/readCommands.js +22 -3
  9. package/lib/esm/cli/commands/transfer.js +6 -6
  10. package/lib/esm/cli/options.js +124 -58
  11. package/lib/esm/cli/utils.js +303 -175
  12. package/lib/esm/common/ant-registry.js +17 -143
  13. package/lib/esm/common/ant.js +44 -1167
  14. package/lib/esm/common/faucet.js +17 -6
  15. package/lib/esm/common/index.js +0 -4
  16. package/lib/esm/common/io.js +25 -1412
  17. package/lib/esm/constants.js +13 -19
  18. package/lib/esm/solana/ant-readable.js +724 -0
  19. package/lib/esm/solana/ant-registry-readable.js +133 -0
  20. package/lib/esm/solana/ant-registry-writeable.js +472 -0
  21. package/lib/esm/solana/ant-writeable.js +384 -0
  22. package/lib/esm/solana/ata.js +70 -0
  23. package/lib/esm/solana/canonical-message.js +128 -0
  24. package/lib/esm/solana/clusters.js +111 -0
  25. package/lib/esm/solana/constants.js +146 -0
  26. package/lib/esm/solana/delegation-math.js +112 -0
  27. package/lib/esm/solana/deserialize.js +711 -0
  28. package/lib/esm/solana/escrow.js +839 -0
  29. package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
  30. package/lib/esm/solana/funding-plan.js +699 -0
  31. package/lib/esm/solana/index.js +126 -0
  32. package/lib/esm/solana/instruction.js +39 -0
  33. package/lib/esm/solana/io-readable.js +2182 -0
  34. package/lib/esm/solana/io-writeable.js +3196 -0
  35. package/lib/esm/solana/json-rpc.js +90 -0
  36. package/lib/esm/solana/metadata.js +81 -0
  37. package/lib/esm/solana/mpl-core.js +192 -0
  38. package/lib/esm/solana/pda.js +332 -0
  39. package/lib/esm/solana/predict-prescribed-observers.js +110 -0
  40. package/lib/esm/solana/retry.js +117 -0
  41. package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
  42. package/lib/esm/solana/send.js +372 -0
  43. package/lib/esm/solana/spawn-ant.js +224 -0
  44. package/lib/esm/solana/types.js +1 -0
  45. package/lib/esm/types/ant.js +27 -15
  46. package/lib/esm/types/io.js +8 -11
  47. package/lib/esm/utils/ant.js +0 -63
  48. package/lib/esm/utils/index.js +0 -3
  49. package/lib/esm/version.js +1 -1
  50. package/lib/types/cli/commands/antCommands.d.ts +5 -13
  51. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
  52. package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
  53. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
  54. package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
  55. package/lib/types/cli/commands/readCommands.d.ts +27 -22
  56. package/lib/types/cli/commands/transfer.d.ts +9 -9
  57. package/lib/types/cli/options.d.ts +76 -21
  58. package/lib/types/cli/types.d.ts +11 -13
  59. package/lib/types/cli/utils.d.ts +71 -31
  60. package/lib/types/common/ant-registry.d.ts +49 -47
  61. package/lib/types/common/ant.d.ts +54 -539
  62. package/lib/types/common/faucet.d.ts +20 -8
  63. package/lib/types/common/index.d.ts +0 -3
  64. package/lib/types/common/io.d.ts +66 -258
  65. package/lib/types/constants.d.ts +11 -18
  66. package/lib/types/solana/ant-readable.d.ts +180 -0
  67. package/lib/types/solana/ant-registry-readable.d.ts +105 -0
  68. package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
  69. package/lib/types/solana/ant-writeable.d.ts +177 -0
  70. package/lib/types/solana/ata.d.ts +44 -0
  71. package/lib/types/solana/canonical-message.d.ts +121 -0
  72. package/lib/types/solana/clusters.d.ts +109 -0
  73. package/lib/types/solana/constants.d.ts +119 -0
  74. package/lib/types/solana/delegation-math.d.ts +45 -0
  75. package/lib/types/solana/deserialize.d.ts +262 -0
  76. package/lib/types/solana/escrow.d.ts +480 -0
  77. package/lib/types/solana/events.d.ts +38 -0
  78. package/lib/types/solana/funding-plan.d.ts +225 -0
  79. package/lib/types/solana/index.d.ts +87 -0
  80. package/lib/types/solana/instruction.d.ts +39 -0
  81. package/lib/types/solana/io-readable.d.ts +499 -0
  82. package/lib/types/solana/io-writeable.d.ts +893 -0
  83. package/lib/types/solana/json-rpc.d.ts +47 -0
  84. package/lib/types/solana/metadata.d.ts +84 -0
  85. package/lib/types/solana/mpl-core.d.ts +120 -0
  86. package/lib/types/solana/pda.d.ts +95 -0
  87. package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
  88. package/lib/types/solana/retry.d.ts +62 -0
  89. package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
  90. package/lib/types/solana/send.d.ts +94 -0
  91. package/lib/types/solana/spawn-ant.d.ts +145 -0
  92. package/lib/types/solana/types.d.ts +82 -0
  93. package/lib/types/types/ant-registry.d.ts +43 -4
  94. package/lib/types/types/ant.d.ts +114 -96
  95. package/lib/types/types/common.d.ts +18 -74
  96. package/lib/types/types/faucet.d.ts +2 -2
  97. package/lib/types/types/io.d.ts +244 -158
  98. package/lib/types/types/token.d.ts +0 -12
  99. package/lib/types/utils/ant.d.ts +1 -12
  100. package/lib/types/utils/index.d.ts +0 -3
  101. package/lib/types/version.d.ts +1 -1
  102. package/package.json +36 -33
  103. package/lib/cjs/cli/cli.js +0 -822
  104. package/lib/cjs/cli/commands/antCommands.js +0 -113
  105. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
  106. package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
  107. package/lib/cjs/cli/commands/readCommands.js +0 -215
  108. package/lib/cjs/cli/commands/transfer.js +0 -159
  109. package/lib/cjs/cli/options.js +0 -470
  110. package/lib/cjs/cli/types.js +0 -2
  111. package/lib/cjs/cli/utils.js +0 -639
  112. package/lib/cjs/common/ant-registry.js +0 -155
  113. package/lib/cjs/common/ant-versions.js +0 -93
  114. package/lib/cjs/common/ant.js +0 -1182
  115. package/lib/cjs/common/arweave.js +0 -27
  116. package/lib/cjs/common/contracts/ao-process.js +0 -224
  117. package/lib/cjs/common/error.js +0 -64
  118. package/lib/cjs/common/faucet.js +0 -150
  119. package/lib/cjs/common/hyperbeam/hb.js +0 -173
  120. package/lib/cjs/common/index.js +0 -42
  121. package/lib/cjs/common/io.js +0 -1423
  122. package/lib/cjs/common/logger.js +0 -83
  123. package/lib/cjs/common/loggers/winston.js +0 -68
  124. package/lib/cjs/common/marketplace.js +0 -731
  125. package/lib/cjs/common/turbo.js +0 -223
  126. package/lib/cjs/constants.js +0 -41
  127. package/lib/cjs/node/index.js +0 -39
  128. package/lib/cjs/package.json +0 -1
  129. package/lib/cjs/types/ant-registry.js +0 -2
  130. package/lib/cjs/types/ant.js +0 -168
  131. package/lib/cjs/types/common.js +0 -2
  132. package/lib/cjs/types/faucet.js +0 -2
  133. package/lib/cjs/types/index.js +0 -37
  134. package/lib/cjs/types/io.js +0 -51
  135. package/lib/cjs/types/token.js +0 -116
  136. package/lib/cjs/utils/ant.js +0 -108
  137. package/lib/cjs/utils/ao.js +0 -432
  138. package/lib/cjs/utils/arweave.js +0 -285
  139. package/lib/cjs/utils/base64.js +0 -62
  140. package/lib/cjs/utils/hash.js +0 -56
  141. package/lib/cjs/utils/index.js +0 -38
  142. package/lib/cjs/utils/processes.js +0 -173
  143. package/lib/cjs/utils/random.js +0 -30
  144. package/lib/cjs/utils/schema.js +0 -15
  145. package/lib/cjs/utils/url.js +0 -37
  146. package/lib/cjs/version.js +0 -20
  147. package/lib/cjs/web/index.js +0 -41
  148. package/lib/esm/common/ant-versions.js +0 -87
  149. package/lib/esm/common/arweave.js +0 -21
  150. package/lib/esm/common/contracts/ao-process.js +0 -220
  151. package/lib/esm/common/hyperbeam/hb.js +0 -169
  152. package/lib/esm/common/marketplace.js +0 -724
  153. package/lib/esm/common/turbo.js +0 -215
  154. package/lib/esm/node/index.js +0 -20
  155. package/lib/esm/utils/ao.js +0 -420
  156. package/lib/esm/utils/arweave.js +0 -271
  157. package/lib/esm/utils/processes.js +0 -167
  158. package/lib/esm/web/index.js +0 -20
  159. package/lib/types/common/ant-versions.d.ts +0 -39
  160. package/lib/types/common/arweave.d.ts +0 -17
  161. package/lib/types/common/contracts/ao-process.d.ts +0 -47
  162. package/lib/types/common/hyperbeam/hb.d.ts +0 -88
  163. package/lib/types/common/marketplace.d.ts +0 -568
  164. package/lib/types/common/turbo.d.ts +0 -61
  165. package/lib/types/node/index.d.ts +0 -20
  166. package/lib/types/utils/ao.d.ts +0 -80
  167. package/lib/types/utils/arweave.d.ts +0 -79
  168. package/lib/types/utils/processes.d.ts +0 -39
  169. package/lib/types/web/index.d.ts +0 -20
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setAntRecordCLICommand = setAntRecordCLICommand;
4
- exports.setAntBaseNameCLICommand = setAntBaseNameCLICommand;
5
- exports.setAntUndernameCLICommand = setAntUndernameCLICommand;
6
- exports.transferRecordOwnershipCLICommand = transferRecordOwnershipCLICommand;
7
- exports.upgradeAntCLICommand = upgradeAntCLICommand;
8
- const utils_js_1 = require("../utils.js");
9
- /** @deprecated -- use set-ant-base-name and set-ant-undername */
10
- async function setAntRecordCLICommand(o) {
11
- const ttlSeconds = +(o.ttlSeconds ?? utils_js_1.defaultTtlSecondsCLI);
12
- const undername = (0, utils_js_1.requiredStringFromOptions)(o, 'undername');
13
- const transactionId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId');
14
- const writeAnt = (0, utils_js_1.writeANTFromOptions)(o);
15
- const recordParams = {
16
- undername,
17
- transactionId,
18
- ttlSeconds,
19
- ...(0, utils_js_1.antRecordMetadataFromOptions)(o),
20
- };
21
- if (!o.skipConfirmation) {
22
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to set this record on the ANT process ${writeAnt.processId}?\n${JSON.stringify(recordParams, null, 2)}`, o);
23
- }
24
- return (0, utils_js_1.writeANTFromOptions)(o).setRecord(recordParams, (0, utils_js_1.customTagsFromOptions)(o));
25
- }
26
- async function setAntBaseNameCLICommand(o) {
27
- const ttlSeconds = +(o.ttlSeconds ?? utils_js_1.defaultTtlSecondsCLI);
28
- const transactionId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId');
29
- const params = {
30
- transactionId,
31
- ttlSeconds,
32
- ...(0, utils_js_1.antRecordMetadataFromOptions)(o),
33
- };
34
- const writeAnt = (0, utils_js_1.writeANTFromOptions)(o);
35
- if (!o.skipConfirmation) {
36
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to set this base name on the ANT process ${writeAnt.processId}?\n${JSON.stringify(params, null, 2)}`, o);
37
- }
38
- return (0, utils_js_1.writeANTFromOptions)(o).setBaseNameRecord(params, (0, utils_js_1.customTagsFromOptions)(o));
39
- }
40
- async function setAntUndernameCLICommand(o) {
41
- const ttlSeconds = +(o.ttlSeconds ?? utils_js_1.defaultTtlSecondsCLI);
42
- const undername = (0, utils_js_1.requiredStringFromOptions)(o, 'undername');
43
- const transactionId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId');
44
- const params = {
45
- undername,
46
- transactionId,
47
- ttlSeconds,
48
- ...(0, utils_js_1.antRecordMetadataFromOptions)(o),
49
- };
50
- const writeAnt = (0, utils_js_1.writeANTFromOptions)(o);
51
- if (!o.skipConfirmation) {
52
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to set this undername on the ANT process ${writeAnt.processId}?\n${JSON.stringify(params, null, 2)}`, o);
53
- }
54
- return (0, utils_js_1.writeANTFromOptions)(o).setUndernameRecord(params, (0, utils_js_1.customTagsFromOptions)(o));
55
- }
56
- async function transferRecordOwnershipCLICommand(o) {
57
- const undername = (0, utils_js_1.requiredStringFromOptions)(o, 'undername');
58
- const recipient = (0, utils_js_1.requiredStringFromOptions)(o, 'recipient');
59
- const writeAnt = (0, utils_js_1.writeANTFromOptions)(o);
60
- if (!o.skipConfirmation) {
61
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to transfer ownership of "${undername}" to "${recipient}" on ANT process ${writeAnt.processId}?\n${JSON.stringify({ undername, recipient }, null, 2)}`, o);
62
- }
63
- return (0, utils_js_1.writeANTFromOptions)(o).transferRecord({ undername, recipient }, (0, utils_js_1.customTagsFromOptions)(o));
64
- }
65
- async function upgradeAntCLICommand(o) {
66
- const writeAnt = (0, utils_js_1.writeANTFromOptions)(o);
67
- const arioProcessId = (0, utils_js_1.arioProcessIdFromOptions)(o);
68
- const ario = (0, utils_js_1.readARIOFromOptions)(o);
69
- const reassignAffiliatedNames = (0, utils_js_1.booleanFromOptions)(o, 'reassignAffiliatedNames');
70
- const names = (0, utils_js_1.stringArrayFromOptions)(o, 'names') || [];
71
- if (reassignAffiliatedNames) {
72
- // Fetch all ArNS records that point to this ANT process
73
- const allRecords = await ario.getArNSRecords({
74
- filters: {
75
- processId: writeAnt.processId,
76
- },
77
- });
78
- // Filter records that belong to this ANT
79
- const affiliatedNames = allRecords.items.map((record) => record.name);
80
- names.push(...affiliatedNames);
81
- }
82
- if (names.length === 0) {
83
- throw new Error('No names to reassign');
84
- }
85
- if (!o.skipConfirmation) {
86
- await (0, utils_js_1.assertConfirmationPrompt)(`Upgrade all names affiliated with this ANT on ARIO process?\n` +
87
- `ARIO Process ID: ${arioProcessId}\n` +
88
- `ANT Process ID: ${writeAnt.processId}\n` +
89
- `Names that will be reassigned (${names.length}): ${names.join(', ')}`, o);
90
- }
91
- const result = reassignAffiliatedNames
92
- ? await (0, utils_js_1.writeANTFromOptions)(o).upgrade({
93
- reassignAffiliatedNames,
94
- arioProcessId,
95
- })
96
- : await (0, utils_js_1.writeANTFromOptions)(o).upgrade({
97
- names,
98
- arioProcessId,
99
- });
100
- // Serialize error objects for JSON compatibility
101
- const serializedFailedReassignedNames = {};
102
- for (const [name, failure] of Object.entries(result.failedReassignedNames)) {
103
- serializedFailedReassignedNames[name] = {
104
- id: failure.id,
105
- error: failure.error.message,
106
- };
107
- }
108
- return {
109
- forkedProcessId: result.forkedProcessId,
110
- reassignedNames: result.reassignedNames,
111
- failedReassignedNames: serializedFailedReassignedNames,
112
- };
113
- }
@@ -1,212 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buyRecordCLICommand = buyRecordCLICommand;
4
- exports.upgradeRecordCLICommand = upgradeRecordCLICommand;
5
- exports.extendLeaseCLICommand = extendLeaseCLICommand;
6
- exports.increaseUndernameLimitCLICommand = increaseUndernameLimitCLICommand;
7
- exports.requestPrimaryNameCLICommand = requestPrimaryNameCLICommand;
8
- exports.setPrimaryNameCLICommand = setPrimaryNameCLICommand;
9
- /**
10
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- const ant_js_1 = require("../../common/ant.js");
25
- const utils_js_1 = require("../utils.js");
26
- async function buyRecordCLICommand(o) {
27
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
28
- const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
29
- const type = (0, utils_js_1.recordTypeFromOptions)(o);
30
- const years = (0, utils_js_1.positiveIntegerFromOptions)(o, 'years');
31
- const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
32
- const referrer = (0, utils_js_1.referrerFromOptions)(o);
33
- const processId = o.processId;
34
- if (!o.skipConfirmation) {
35
- const existingRecord = await ario.getArNSRecord({
36
- name,
37
- });
38
- if (existingRecord !== undefined) {
39
- throw new Error(`ArNS Record ${name} is already owned`);
40
- }
41
- await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
42
- ario,
43
- address: signerAddress,
44
- costDetailsParams: {
45
- intent: 'Buy-Name',
46
- type,
47
- name,
48
- years,
49
- fundFrom,
50
- fromAddress: signerAddress,
51
- },
52
- });
53
- // assert spawn new ant with module id
54
- let antSpawnConfirmation = '';
55
- if (processId === undefined) {
56
- const { moduleId, version } = await ant_js_1.ANT.versions.getLatestANTVersion();
57
- antSpawnConfirmation = `Note: A new ANT process will be spawned with module ${moduleId} (v${version}) and assigned to this name.`;
58
- }
59
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to ${type} the record ${name}? ${antSpawnConfirmation}`, o);
60
- }
61
- return ario.buyRecord({
62
- name: (0, utils_js_1.requiredStringFromOptions)(o, 'name'),
63
- processId,
64
- type,
65
- years,
66
- fundFrom: (0, utils_js_1.fundFromFromOptions)(o),
67
- paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'),
68
- referrer,
69
- }, (0, utils_js_1.customTagsFromOptions)(o));
70
- }
71
- async function upgradeRecordCLICommand(o) {
72
- const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
73
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
74
- const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
75
- const referrer = (0, utils_js_1.referrerFromOptions)(o);
76
- if (!o.skipConfirmation) {
77
- const existingRecord = await ario.getArNSRecord({
78
- name,
79
- });
80
- if (existingRecord === undefined) {
81
- throw new Error(`ArNS Record ${name} does not exist`);
82
- }
83
- if (existingRecord.type === 'permabuy') {
84
- throw new Error(`ArNS Record ${name} is already a permabuy`);
85
- }
86
- await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
87
- ario,
88
- address: signerAddress,
89
- costDetailsParams: {
90
- intent: 'Upgrade-Name',
91
- name,
92
- fundFrom,
93
- fromAddress: signerAddress,
94
- },
95
- });
96
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to upgrade the lease of ${name} to a permabuy?`, o);
97
- }
98
- return ario.upgradeRecord({
99
- name,
100
- fundFrom,
101
- paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'),
102
- referrer,
103
- });
104
- }
105
- async function extendLeaseCLICommand(o) {
106
- const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
107
- const years = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'years');
108
- const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
109
- const referrer = (0, utils_js_1.referrerFromOptions)(o);
110
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
111
- if (!o.skipConfirmation) {
112
- const existingRecord = await ario.getArNSRecord({
113
- name,
114
- });
115
- if (existingRecord === undefined) {
116
- throw new Error(`ArNS Record ${name} does not exist`);
117
- }
118
- if (existingRecord.type === 'permabuy') {
119
- throw new Error(`ArNS Record ${name} is a permabuy and cannot be extended`);
120
- }
121
- await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
122
- ario: ario,
123
- address: signerAddress,
124
- costDetailsParams: {
125
- intent: 'Extend-Lease',
126
- name,
127
- years,
128
- fundFrom,
129
- fromAddress: signerAddress,
130
- },
131
- });
132
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to extend the lease of ${name} by ${years}?`, o);
133
- }
134
- return ario.extendLease({
135
- name,
136
- years,
137
- paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'),
138
- referrer,
139
- }, (0, utils_js_1.customTagsFromOptions)(o));
140
- }
141
- async function increaseUndernameLimitCLICommand(o) {
142
- const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
143
- const increaseCount = (0, utils_js_1.requiredPositiveIntegerFromOptions)(o, 'increaseCount');
144
- const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
145
- const referrer = (0, utils_js_1.referrerFromOptions)(o);
146
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
147
- if (!o.skipConfirmation) {
148
- const existingRecord = await ario.getArNSRecord({
149
- name,
150
- });
151
- if (existingRecord === undefined) {
152
- throw new Error(`ArNS Record ${name} does not exist`);
153
- }
154
- await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
155
- ario,
156
- address: signerAddress,
157
- costDetailsParams: {
158
- intent: 'Increase-Undername-Limit',
159
- name,
160
- quantity: increaseCount,
161
- fundFrom,
162
- fromAddress: signerAddress,
163
- },
164
- });
165
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to increase the undername limit of ${name} by ${increaseCount}?`, o);
166
- }
167
- return ario.increaseUndernameLimit({
168
- name,
169
- increaseCount,
170
- paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'),
171
- referrer,
172
- }, (0, utils_js_1.customTagsFromOptions)(o));
173
- }
174
- async function requestPrimaryNameCLICommand(o) {
175
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
176
- const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
177
- const referrer = (0, utils_js_1.referrerFromOptions)(o);
178
- const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
179
- if (!o.skipConfirmation) {
180
- await (0, utils_js_1.assertEnoughBalanceForArNSPurchase)({
181
- ario,
182
- address: signerAddress,
183
- costDetailsParams: {
184
- intent: 'Primary-Name-Request',
185
- name,
186
- fromAddress: signerAddress,
187
- fundFrom,
188
- },
189
- });
190
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to request the primary name ${name}?`, o);
191
- }
192
- const { result } = await ario.requestPrimaryName({
193
- name,
194
- fundFrom,
195
- paidBy: (0, utils_js_1.stringArrayFromOptions)(o, 'paidBy'),
196
- referrer,
197
- }, (0, utils_js_1.customTagsFromOptions)(o));
198
- if (result?.request === undefined) {
199
- throw new Error('Failed to request primary name for name ' + name);
200
- }
201
- return result.request;
202
- }
203
- async function setPrimaryNameCLICommand(o) {
204
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(o);
205
- const name = (0, utils_js_1.requiredStringFromOptions)(o, 'name');
206
- const fundFrom = (0, utils_js_1.fundFromFromOptions)(o);
207
- const referrer = (0, utils_js_1.referrerFromOptions)(o);
208
- if (!o.skipConfirmation) {
209
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you want to set the primary name ${name} for address ${signerAddress}?`, o);
210
- }
211
- return ario.setPrimaryName({ name, fundFrom, referrer });
212
- }
@@ -1,210 +0,0 @@
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.joinNetwork = joinNetwork;
7
- exports.updateGatewaySettings = updateGatewaySettings;
8
- exports.leaveNetwork = leaveNetwork;
9
- exports.saveObservations = saveObservations;
10
- exports.increaseOperatorStake = increaseOperatorStake;
11
- exports.decreaseOperatorStake = decreaseOperatorStake;
12
- exports.instantWithdrawal = instantWithdrawal;
13
- exports.cancelWithdrawal = cancelWithdrawal;
14
- exports.delegateStake = delegateStake;
15
- exports.decreaseDelegateStake = decreaseDelegateStake;
16
- exports.redelegateStake = redelegateStake;
17
- /**
18
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
19
- *
20
- * Licensed under the Apache License, Version 2.0 (the "License");
21
- * you may not use this file except in compliance with the License.
22
- * You may obtain a copy of the License at
23
- *
24
- * http://www.apache.org/licenses/LICENSE-2.0
25
- *
26
- * Unless required by applicable law or agreed to in writing, software
27
- * distributed under the License is distributed on an "AS IS" BASIS,
28
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
- * See the License for the specific language governing permissions and
30
- * limitations under the License.
31
- */
32
- const prompts_1 = __importDefault(require("prompts"));
33
- const index_js_1 = require("../../node/index.js");
34
- const utils_js_1 = require("../utils.js");
35
- async function joinNetwork(options) {
36
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(options);
37
- const mARIOQuantity = (0, utils_js_1.requiredMARIOFromOptions)(options, 'operatorStake');
38
- const settings = {
39
- ...(0, utils_js_1.gatewaySettingsFromOptions)(options),
40
- operatorStake: mARIOQuantity.valueOf(),
41
- };
42
- if (settings.label === undefined) {
43
- throw new Error('Label is required. Please provide a --label for your node.');
44
- }
45
- if (settings.fqdn === undefined) {
46
- throw new Error('FQDN is required. Please provide a --fqdn for your node.');
47
- }
48
- if (!options.skipConfirmation) {
49
- const settings = await ario.getGatewayRegistrySettings();
50
- if (settings.operators.minStake > mARIOQuantity.valueOf()) {
51
- throw new Error(`The minimum operator stake is ${(0, utils_js_1.formatARIOWithCommas)(new index_js_1.mARIOToken(settings.operators.minStake).toARIO())} ARIO. Please provide a higher stake.`);
52
- }
53
- await (0, utils_js_1.assertEnoughMARIOBalance)({
54
- ario,
55
- address: signerAddress,
56
- mARIOQuantity,
57
- });
58
- 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.formatARIOWithCommas)(mARIOQuantity.toARIO())} ARIO to join the AR.IO network\nAre you sure?\n`, options);
59
- }
60
- const result = await ario.joinNetwork(settings, (0, utils_js_1.customTagsFromOptions)(options));
61
- const output = {
62
- joinNetworkResult: result,
63
- joinedAddress: signerAddress,
64
- message: `Congratulations! You have successfully joined the AR.IO network (;`,
65
- };
66
- return output;
67
- }
68
- async function updateGatewaySettings(options) {
69
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(options);
70
- const gatewaySettings = (0, utils_js_1.gatewaySettingsFromOptions)(options);
71
- if (Object.keys(gatewaySettings).length === 0) {
72
- // TODO: The contract accepts empty Update-Gateway-Settings actions, but we'll throw in the CLI for now
73
- throw new Error('No gateway settings provided');
74
- }
75
- 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);
76
- const result = await ario.updateGatewaySettings(gatewaySettings, (0, utils_js_1.customTagsFromOptions)(options));
77
- const output = {
78
- updateGatewaySettingsResult: result,
79
- updatedGatewayAddress: signerAddress,
80
- message: `Gateway settings updated successfully`,
81
- };
82
- return output;
83
- }
84
- async function leaveNetwork(options) {
85
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(options);
86
- if (!options.skipConfirmation) {
87
- const gateway = await ario.getGateway({ address: signerAddress });
88
- await (0, utils_js_1.assertConfirmationPrompt)('Gateway Details:\n\n' +
89
- (0, utils_js_1.stringifyJsonForCLIDisplay)(gateway) +
90
- '\n\n' +
91
- 'Are you sure you want to leave the AR.IO network?', options);
92
- }
93
- return (0, utils_js_1.writeARIOFromOptions)(options).ario.leaveNetwork((0, utils_js_1.customTagsFromOptions)(options));
94
- }
95
- async function saveObservations(o) {
96
- const failedGateways = (0, utils_js_1.requiredStringArrayFromOptions)(o, 'failedGateways');
97
- const reportTxId = (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId');
98
- 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);
99
- return (0, utils_js_1.writeARIOFromOptions)(o).ario.saveObservations({
100
- failedGateways: (0, utils_js_1.requiredStringArrayFromOptions)(o, 'failedGateways'),
101
- reportTxId: (0, utils_js_1.requiredStringFromOptions)(o, 'transactionId'),
102
- }, (0, utils_js_1.customTagsFromOptions)(o));
103
- }
104
- async function increaseOperatorStake(o) {
105
- const increaseQty = (0, utils_js_1.requiredMARIOFromOptions)(o, 'operatorStake');
106
- await (0, utils_js_1.assertConfirmationPrompt)(`You are about to increase your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(increaseQty.toARIO())} ARIO\nAre you sure?`, o);
107
- return (0, utils_js_1.writeARIOFromOptions)(o).ario.increaseOperatorStake({
108
- increaseQty,
109
- }, (0, utils_js_1.customTagsFromOptions)(o));
110
- }
111
- async function decreaseOperatorStake(o) {
112
- const decreaseQty = (0, utils_js_1.requiredMARIOFromOptions)(o, 'operatorStake');
113
- // TODO: Can assert stake is sufficient for action, and new target stake meets contract minimum
114
- await (0, utils_js_1.assertConfirmationPrompt)(`You are about to decrease your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(decreaseQty.toARIO())} ARIO\nAre you sure?`, o);
115
- return (0, utils_js_1.writeARIOFromOptions)(o).ario.decreaseOperatorStake({
116
- decreaseQty,
117
- }, (0, utils_js_1.customTagsFromOptions)(o));
118
- }
119
- async function instantWithdrawal(o) {
120
- const vaultId = (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId');
121
- const gatewayAddress = (0, utils_js_1.requiredAddressFromOptions)(o);
122
- await (0, utils_js_1.assertConfirmationPrompt)(`You are about to instantly withdraw from vault ${vaultId} for with gateway address ${gatewayAddress}\nAre you sure?`, o);
123
- return (0, utils_js_1.writeARIOFromOptions)(o).ario.instantWithdrawal({
124
- vaultId,
125
- gatewayAddress,
126
- }, (0, utils_js_1.customTagsFromOptions)(o));
127
- }
128
- async function cancelWithdrawal(o) {
129
- const vaultId = (0, utils_js_1.requiredStringFromOptions)(o, 'vaultId');
130
- const gatewayAddress = (0, utils_js_1.requiredAddressFromOptions)(o);
131
- 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);
132
- return (0, utils_js_1.writeARIOFromOptions)(o).ario.cancelWithdrawal({
133
- vaultId,
134
- gatewayAddress,
135
- }, (0, utils_js_1.customTagsFromOptions)(o));
136
- }
137
- async function delegateStake(options) {
138
- const { ario, signerAddress } = (0, utils_js_1.writeARIOFromOptions)(options);
139
- const { target, arioQuantity } = (0, utils_js_1.requiredTargetAndQuantityFromOptions)(options);
140
- const mARIOQuantity = arioQuantity.toMARIO();
141
- if (!options.skipConfirmation) {
142
- const balance = await ario.getBalance({ address: signerAddress });
143
- if (balance < mARIOQuantity.valueOf()) {
144
- throw new Error(`Insufficient ARIO balance for delegating stake. Balance available: ${new index_js_1.mARIOToken(balance).toARIO()} ARIO`);
145
- }
146
- const targetGateway = await ario.getGateway({ address: target });
147
- if (targetGateway === undefined) {
148
- throw new Error(`Gateway not found for address: ${target}`);
149
- }
150
- if (targetGateway.settings.allowDelegatedStaking === false) {
151
- throw new Error(`Gateway does not allow delegated staking: ${target}`);
152
- }
153
- // TODO: could get allow list and assert doesn't exist or user is on it
154
- // 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
155
- const { confirm } = await (0, prompts_1.default)({
156
- type: 'confirm',
157
- name: 'confirm',
158
- message: `Target Gateway:\n${JSON.stringify(targetGateway, null, 2)}\n\nAre you sure you want to delegate ${(0, utils_js_1.formatARIOWithCommas)(arioQuantity)} ARIO to ${target}?`,
159
- });
160
- if (!confirm) {
161
- return { message: 'Delegate stake aborted by user' };
162
- }
163
- }
164
- const result = await ario.delegateStake({
165
- target,
166
- stakeQty: arioQuantity.toMARIO(),
167
- }, (0, utils_js_1.customTagsFromOptions)(options));
168
- const output = {
169
- senderAddress: signerAddress,
170
- transferResult: result,
171
- message: `Successfully delegated ${(0, utils_js_1.formatARIOWithCommas)(arioQuantity)} ARIO to ${target}`,
172
- };
173
- return output;
174
- }
175
- async function decreaseDelegateStake(options) {
176
- const ario = (0, utils_js_1.writeARIOFromOptions)(options).ario;
177
- const { target, arioQuantity } = (0, utils_js_1.requiredTargetAndQuantityFromOptions)(options);
178
- const instant = options.instant ?? false;
179
- // TODO: Could assert sender is a delegate with enough stake to decrease
180
- // TODO: Could assert new target stake meets contract and target gateway minimums
181
- // TODO: Could present confirmation prompt with any fee for instant withdrawal (50% of the stake is put back into protocol??)
182
- await (0, utils_js_1.assertConfirmationPrompt)(`Are you sure you'd like to decrease delegated stake of ${(0, utils_js_1.formatARIOWithCommas)(arioQuantity)} ARIO on gateway ${target}?`, options);
183
- const result = await ario.decreaseDelegateStake({
184
- target,
185
- decreaseQty: arioQuantity.toMARIO(),
186
- instant,
187
- });
188
- const output = {
189
- targetGateway: target,
190
- decreaseDelegateStakeResult: result,
191
- message: `Successfully decreased delegated stake of ${(0, utils_js_1.formatARIOWithCommas)(arioQuantity)} ARIO to ${target}`,
192
- };
193
- return output;
194
- }
195
- async function redelegateStake(options) {
196
- const ario = (0, utils_js_1.writeARIOFromOptions)(options).ario;
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.formatARIOWithCommas)(params.stakeQty.toARIO())} ARIO from ${params.source} to ${params.target}?`, options);
202
- const result = await ario.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.formatARIOWithCommas)(params.stakeQty.toARIO())} ARIO from ${params.source} to ${params.target}`,
208
- };
209
- return output;
210
- }