@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,271 +0,0 @@
1
- import { Logger } from '../common/logger.js';
2
- import { ARIO_MAINNET_PROCESS_ID, ARWEAVE_TX_REGEX } from '../constants.js';
3
- import { isDistributedEpoch, } from '../types/io.js';
4
- import { parseAoEpochData } from './ao.js';
5
- export const validateArweaveId = (id) => {
6
- return ARWEAVE_TX_REGEX.test(id);
7
- };
8
- export function isBlockHeight(height) {
9
- return height !== undefined && !isNaN(parseInt(height.toString()));
10
- }
11
- /**
12
- * Prune tags that are undefined or empty.
13
- * @param tags - The tags to prune.
14
- * @returns The pruned tags.
15
- */
16
- export const pruneTags = (tags) => {
17
- return tags.filter((tag) => tag.value !== undefined && tag.value !== '');
18
- };
19
- export const paginationParamsToTags = (params) => {
20
- const tags = [
21
- { name: 'Cursor', value: params?.cursor?.toString() },
22
- { name: 'Limit', value: params?.limit?.toString() },
23
- { name: 'Sort-By', value: params?.sortBy?.toString() },
24
- { name: 'Sort-Order', value: params?.sortOrder?.toString() },
25
- ...(params?.filters
26
- ? [{ name: 'Filters', value: JSON.stringify(params.filters) }]
27
- : []),
28
- ];
29
- return pruneTags(tags);
30
- };
31
- /**
32
- * Get the epoch with distribution data for the current epoch
33
- * @param arweave - The Arweave instance
34
- * @returns The epoch with distribution data
35
- */
36
- export const getEpochDataFromGql = async ({ arweave, epochIndex, processId = ARIO_MAINNET_PROCESS_ID, retries = 3, gqlUrl = 'https://arweave-search.goldsky.com/graphql', }) => {
37
- // fetch from gql
38
- const query = epochDistributionNoticeGqlQuery({ epochIndex, processId });
39
- // add three retries with exponential backoff
40
- for (let i = 0; i < retries; i++) {
41
- try {
42
- const response = (await fetch(gqlUrl, {
43
- method: 'POST',
44
- body: query,
45
- headers: {
46
- 'Content-Type': 'application/json',
47
- },
48
- }).then((res) => res.json()));
49
- // parse the nodes to get the id
50
- if (response?.data?.transactions?.edges?.length === 0) {
51
- return undefined;
52
- }
53
- const id = response.data.transactions.edges[0].node.id;
54
- // fetch the transaction from arweave
55
- const transaction = await arweave.api.get(id);
56
- // assert it is the correct type
57
- return parseAoEpochData(transaction.data);
58
- }
59
- catch (error) {
60
- if (i === retries - 1)
61
- throw error; // Re-throw on final attempt
62
- // exponential backoff
63
- await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
64
- }
65
- }
66
- return undefined;
67
- };
68
- export const getEpochDataFromGqlWithCUFallback = async ({ arweave, ao, epochIndex, processId = ARIO_MAINNET_PROCESS_ID, }) => {
69
- const gqlResult = await getEpochDataFromGql({
70
- arweave,
71
- epochIndex,
72
- processId,
73
- });
74
- if (gqlResult) {
75
- return gqlResult;
76
- }
77
- const gqlFallbackResult = await getEpochDataFromGqlFallback({
78
- ao,
79
- epochIndex,
80
- processId,
81
- });
82
- if (gqlFallbackResult) {
83
- return gqlFallbackResult;
84
- }
85
- return undefined;
86
- };
87
- export const getEpochDataFromGqlFallback = async ({ ao, epochIndex, processId = ARIO_MAINNET_PROCESS_ID, gqlUrl = 'https://arweave-search.goldsky.com/graphql', }) => {
88
- const query = epochDistributionNoticeGqlQueryFallback({
89
- epochIndex,
90
- processId,
91
- });
92
- const response = await fetch(gqlUrl, {
93
- method: 'POST',
94
- body: query,
95
- headers: {
96
- 'Content-Type': 'application/json',
97
- },
98
- });
99
- const responseJson = (await response.json());
100
- if (responseJson.data.transactions.edges.length === 0) {
101
- return undefined;
102
- }
103
- for (const edge of responseJson.data.transactions.edges) {
104
- const id = edge.node.id;
105
- const messageResult = await ao
106
- .result({
107
- message: id,
108
- process: processId,
109
- })
110
- .catch(() => undefined);
111
- if (!messageResult) {
112
- continue;
113
- }
114
- for (const message of messageResult?.Messages ?? []) {
115
- if (!message.Data) {
116
- continue;
117
- }
118
- try {
119
- const tags = message.Tags;
120
- // check if the message results include epoch-distribution-notice for the requested epoch index
121
- if (tags.some((tag) => tag.name === 'Action' &&
122
- tag.value === 'Epoch-Distribution-Notice') &&
123
- tags.some((tag) => tag.name === 'Epoch-Index' && tag.value === epochIndex.toString())) {
124
- const data = JSON.parse(message.Data);
125
- return parseAoEpochData(data);
126
- }
127
- }
128
- catch (error) {
129
- // report but continue to next message
130
- Logger.default.error('Failed to parse AO epoch distribution message:', error, '\nMessage:', message);
131
- }
132
- }
133
- }
134
- return undefined;
135
- };
136
- /**
137
- * Get the epoch with distribution data for the current epoch
138
- * @param arweave - The Arweave instance
139
- * @param epochIndex - The index of the epoch
140
- * @param processId - The process ID (optional, defaults to ARIO_MAINNET_PROCESS_ID)
141
- * @returns string - The stringified GQL query
142
- */
143
- export const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = ARIO_MAINNET_PROCESS_ID, authorities = ['fcoN_xJeisVsPXA-trzVAuIiqO3ydLQxM-L4XbrQKzY'], }) => {
144
- // write the query
145
- const gqlQuery = JSON.stringify({
146
- query: `
147
- query {
148
- transactions(
149
- tags: [
150
- { name: "From-Process", values: ["${processId}"] }
151
- { name: "Action", values: ["Epoch-Distribution-Notice"] }
152
- { name: "Epoch-Index", values: ["${epochIndex}"] }
153
- { name: "Data-Protocol", values: ["ao"] }
154
- ],
155
- owners: [${authorities.map((a) => `"${a}"`).join(',')}],
156
- first: 1,
157
- sort: HEIGHT_DESC
158
- ) {
159
- edges {
160
- node {
161
- id
162
- }
163
- }
164
- }
165
- }
166
- `,
167
- });
168
- return gqlQuery;
169
- };
170
- // fallback query if the distribution notice does not get cranked
171
- export const epochDistributionNoticeGqlQueryFallback = ({ processId = ARIO_MAINNET_PROCESS_ID, owners = ['OAb-n-ZugyN598kZNpfOy0ACelGVmwCQ0kYbgNGDUK8'], // ar.io team wallet ticks once a day
172
- }) => {
173
- return JSON.stringify({
174
- query: `
175
- query {
176
- transactions(
177
- tags: [
178
- { name: "Action", values: ["Tick"] }
179
- ],
180
- first: 100,
181
- owners: [${owners.map((a) => `"${a}"`).join(',')}],
182
- recipients: ["${processId}"],
183
- sort: HEIGHT_DESC
184
- ) {
185
- edges {
186
- node {
187
- id
188
- }
189
- }
190
- }
191
- }
192
- `,
193
- });
194
- };
195
- export function sortAndPaginateEpochDataIntoEligibleDistributions(epochData, params) {
196
- const rewards = [];
197
- const sortBy = params?.sortBy ?? 'eligibleReward';
198
- const sortOrder = params?.sortOrder ?? 'desc';
199
- const limit = params?.limit ?? 100;
200
- if (!isDistributedEpoch(epochData)) {
201
- return {
202
- hasMore: false,
203
- items: [],
204
- totalItems: 0,
205
- limit,
206
- sortOrder,
207
- sortBy,
208
- };
209
- }
210
- const eligibleDistributions = epochData?.distributions.rewards.eligible;
211
- for (const [gatewayAddress, reward] of Object.entries(eligibleDistributions)) {
212
- rewards.push({
213
- type: 'operatorReward',
214
- recipient: gatewayAddress,
215
- eligibleReward: reward.operatorReward,
216
- cursorId: gatewayAddress + '_' + gatewayAddress,
217
- gatewayAddress,
218
- });
219
- for (const [delegateAddress, delegateRewardQty] of Object.entries(reward.delegateRewards)) {
220
- rewards.push({
221
- type: 'delegateReward',
222
- recipient: delegateAddress,
223
- eligibleReward: delegateRewardQty,
224
- cursorId: gatewayAddress + '_' + delegateAddress,
225
- gatewayAddress,
226
- });
227
- }
228
- }
229
- // sort the rewards by the sortBy
230
- rewards.sort((a, b) => {
231
- const aSort = a[sortBy];
232
- const bSort = b[sortBy];
233
- if (aSort === bSort || aSort === undefined || bSort === undefined) {
234
- return 0;
235
- }
236
- if (sortOrder === 'asc') {
237
- return aSort > bSort ? 1 : -1;
238
- }
239
- return aSort < bSort ? 1 : -1;
240
- });
241
- // paginate the rewards
242
- const start = params?.cursor !== undefined
243
- ? rewards.findIndex((r) => r.cursorId === params.cursor) + 1
244
- : 0;
245
- const end = limit ? start + limit : rewards.length;
246
- return {
247
- hasMore: end < rewards.length,
248
- items: rewards.slice(start, end),
249
- totalItems: rewards.length,
250
- limit,
251
- sortOrder,
252
- nextCursor: rewards[end]?.cursorId,
253
- sortBy,
254
- };
255
- }
256
- export function removeEligibleRewardsFromEpochData(epochData) {
257
- if (!isDistributedEpoch(epochData)) {
258
- return epochData;
259
- }
260
- return {
261
- ...epochData,
262
- distributions: {
263
- ...epochData.distributions,
264
- rewards: {
265
- ...epochData.distributions.rewards,
266
- // @ts-expect-error -- remove eligible rewards
267
- eligible: undefined,
268
- },
269
- },
270
- };
271
- }
@@ -1,167 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { connect } from '@permaweb/aoconnect';
17
- import { EventEmitter } from 'eventemitter3';
18
- import { ANTRegistry } from '../common/ant-registry.js';
19
- import { ANT } from '../common/ant.js';
20
- import { AOProcess } from '../common/index.js';
21
- import { ARIO } from '../common/io.js';
22
- import { Logger } from '../common/logger.js';
23
- import { ARIO_MAINNET_PROCESS_ID } from '../constants.js';
24
- /**
25
- * @deprecated Use getArNSRecordsForAddress instead
26
- */
27
- export const getANTProcessesOwnedByWallet = async ({ address, registry = ANTRegistry.init(), }) => {
28
- const res = await registry.accessControlList({ address });
29
- return [...new Set([...res.Owned, ...res.Controlled])];
30
- };
31
- function timeout(ms, promise) {
32
- return new Promise((resolve, reject) => {
33
- const timer = setTimeout(() => {
34
- reject(new Error('Timeout'));
35
- }, ms);
36
- promise
37
- .then((value) => {
38
- clearTimeout(timer);
39
- resolve(value);
40
- })
41
- .catch((err) => {
42
- clearTimeout(timer);
43
- reject(err);
44
- });
45
- });
46
- }
47
- /**
48
- * @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
49
- */
50
- export class ArNSEventEmitter extends EventEmitter {
51
- contract;
52
- timeoutMs;
53
- logger;
54
- strict;
55
- antAoClient;
56
- constructor({ contract = ARIO.init({
57
- processId: ARIO_MAINNET_PROCESS_ID,
58
- }), timeoutMs = 60_000, logger = Logger.default, strict = false, antAoClient = connect({
59
- MODE: 'legacy',
60
- }), } = {}) {
61
- super();
62
- this.contract = contract;
63
- this.timeoutMs = timeoutMs;
64
- this.logger = logger;
65
- this.strict = strict;
66
- this.antAoClient = antAoClient;
67
- }
68
- async fetchProcessesOwnedByWallet({ address, pageSize, antRegistry = ANTRegistry.init(), }) {
69
- const uniqueContractProcessIds = {};
70
- const antIdRes = await antRegistry.accessControlList({ address });
71
- const antIds = new Set([...antIdRes.Owned, ...antIdRes.Controlled]);
72
- await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract, emitter: this, pageSize }))
73
- .catch((e) => {
74
- this.emit('error', `Error getting ArNS records: ${e}`);
75
- this.logger.error(`Error getting ArNS records`, {
76
- message: e?.message,
77
- stack: e?.stack,
78
- });
79
- return {};
80
- })
81
- .then((records) => {
82
- Object.entries(records).forEach(([name, arnsRecord]) => {
83
- if (antIds.has(arnsRecord.processId)) {
84
- if (uniqueContractProcessIds[arnsRecord.processId] === undefined) {
85
- uniqueContractProcessIds[arnsRecord.processId] = {
86
- state: undefined,
87
- names: {},
88
- };
89
- }
90
- uniqueContractProcessIds[arnsRecord.processId].names[name] =
91
- arnsRecord;
92
- }
93
- });
94
- });
95
- const idCount = Object.keys(uniqueContractProcessIds).length;
96
- this.emit('progress', 0, idCount);
97
- // check the contract owner and controllers
98
- await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => {
99
- if (uniqueContractProcessIds[processId].state !== undefined) {
100
- this.emit('progress', i + 1, idCount);
101
- return;
102
- }
103
- const ant = ANT.init({
104
- process: new AOProcess({
105
- processId,
106
- ao: this.antAoClient,
107
- }),
108
- strict: this.strict,
109
- });
110
- const state = (await timeout(this.timeoutMs, ant.getState()).catch((e) => {
111
- this.emit('error', `Error getting state for process ${processId}: ${e}`);
112
- return undefined;
113
- }));
114
- if (state?.Owner === address || state?.Controllers.includes(address)) {
115
- uniqueContractProcessIds[processId].state = state;
116
- this.emit('process', processId, uniqueContractProcessIds[processId]);
117
- }
118
- this.emit('progress', i + 1, idCount);
119
- }));
120
- this.emit('end', uniqueContractProcessIds);
121
- }
122
- }
123
- export const fetchAllArNSRecords = async ({ contract = ARIO.init({
124
- processId: ARIO_MAINNET_PROCESS_ID,
125
- }), emitter, logger = Logger.default, pageSize = 1000, }) => {
126
- let cursor;
127
- const startTimestamp = Date.now();
128
- const records = {};
129
- do {
130
- const pageResult = await contract
131
- .getArNSRecords({ cursor, limit: pageSize })
132
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
- .catch((e) => {
134
- logger?.error(`Error getting ArNS records`, {
135
- message: e?.message,
136
- stack: e?.stack,
137
- });
138
- emitter?.emit('arns:error', `Error getting ArNS records: ${e}`);
139
- return undefined;
140
- });
141
- if (!pageResult) {
142
- return {};
143
- }
144
- pageResult.items.forEach((record) => {
145
- const { name, ...recordDetails } = record;
146
- records[name] = recordDetails;
147
- });
148
- logger.debug('Fetched page of ArNS records', {
149
- totalRecordCount: pageResult.totalItems,
150
- fetchedRecordCount: Object.keys(records).length,
151
- cursor: pageResult.nextCursor,
152
- });
153
- emitter?.emit('arns:pageLoaded', {
154
- totalRecordCount: pageResult.totalItems,
155
- fetchedRecordCount: Object.keys(records).length,
156
- records: pageResult.items,
157
- cursor: pageResult.nextCursor,
158
- });
159
- cursor = pageResult.nextCursor;
160
- } while (cursor !== undefined);
161
- emitter?.emit('arns:end', records);
162
- logger.debug('Fetched all ArNS records', {
163
- totalRecordCount: Object.keys(records).length,
164
- durationMs: Date.now() - startTimestamp,
165
- });
166
- return records;
167
- };
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export { ArweaveSigner, ArconnectSigner, InjectedEthereumSigner, EthereumSigner, } from '@dha-team/arbundles';
17
- export * from '../types/index.js';
18
- export * from '../common/index.js';
19
- export * from '../constants.js';
20
- export * from '../utils/index.js';
@@ -1,39 +0,0 @@
1
- import { AoANTVersionsRead, AoANTVersionsWrite } from '../types/ant.js';
2
- import { AoMessageResult, WithSigner, WriteOptions } from '../types/common.js';
3
- import { ProcessConfiguration } from '../types/io.js';
4
- import { AOProcess } from './contracts/ao-process.js';
5
- type ANTVersionsNoSigner = ProcessConfiguration;
6
- type ANTVersionsWithSigner = WithSigner<ProcessConfiguration>;
7
- export declare class ANTVersions {
8
- static init(): AoANTVersionsRead;
9
- static init(config: ANTVersionsNoSigner): AoANTVersionsRead;
10
- static init(config: ANTVersionsWithSigner): AoANTVersionsWrite;
11
- }
12
- export declare class ANTVersionsReadable implements AoANTVersionsRead {
13
- protected process: AOProcess;
14
- constructor(config?: ProcessConfiguration);
15
- getANTVersions(): Promise<Record<string, {
16
- moduleId: string;
17
- luaSourceId?: string;
18
- notes?: string;
19
- releaseTimestamp: number;
20
- }>>;
21
- getLatestANTVersion(): Promise<{
22
- version: string;
23
- moduleId: string;
24
- luaSourceId?: string;
25
- notes?: string;
26
- releaseTimestamp: number;
27
- }>;
28
- }
29
- export declare class ANTVersionsWritable extends ANTVersionsReadable implements AoANTVersionsWrite {
30
- private signer;
31
- constructor({ signer, ...config }: WithSigner<ProcessConfiguration>);
32
- addVersion(params: {
33
- version: string;
34
- moduleId: string;
35
- luaSourceId?: string;
36
- notes?: string;
37
- }, options?: WriteOptions): Promise<AoMessageResult>;
38
- }
39
- export {};
@@ -1,17 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import Arweave from 'arweave/node/index.js';
17
- export declare const defaultArweave: Arweave;
@@ -1,47 +0,0 @@
1
- import { AOContract, AoClient, AoSigner } from '../../types/index.js';
2
- import { ILogger } from '../logger.js';
3
- export declare class AOProcess implements AOContract {
4
- private logger;
5
- readonly ao: AoClient;
6
- readonly processId: string;
7
- constructor({ processId, ao, logger, }: {
8
- processId: string;
9
- ao?: AoClient;
10
- logger?: ILogger;
11
- });
12
- private isMessageDataEmpty;
13
- read<K>({ tags, retries, fromAddress, select, }: {
14
- tags?: Array<{
15
- name: string;
16
- value: string;
17
- }>;
18
- retries?: number;
19
- fromAddress?: string;
20
- select?: (message: {
21
- Data: string;
22
- Tags: Array<{
23
- name: string;
24
- value: string;
25
- }>;
26
- }) => boolean;
27
- }): Promise<K>;
28
- send<K>({ tags, data, signer, retries, select, }: {
29
- tags: Array<{
30
- name: string;
31
- value: string;
32
- }>;
33
- data?: string | undefined;
34
- signer: AoSigner;
35
- retries?: number;
36
- select?: (message: {
37
- Data: string;
38
- Tags: Array<{
39
- name: string;
40
- value: string;
41
- }>;
42
- }) => boolean;
43
- }): Promise<{
44
- id: string;
45
- result?: K;
46
- }>;
47
- }
@@ -1,88 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { JSONValue } from '../../types/common.js';
17
- import { Logger } from '../logger.js';
18
- export type HBConfig = {
19
- url: string;
20
- processId: string;
21
- logger?: Logger;
22
- hbTimeoutMs?: number;
23
- };
24
- export declare class HB {
25
- readonly url: string;
26
- readonly processId: string;
27
- protected isHyperBeamCompatible: boolean | undefined;
28
- protected checkHyperBeamPromise: Promise<boolean> | undefined;
29
- private logger;
30
- private hbTimeoutMs;
31
- constructor(config: HBConfig);
32
- /**
33
- * fetches the meta data for the process
34
- *
35
- * @returns The meta data for the process
36
- *
37
- * @example
38
- * const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
39
- * const meta = await hyperbeam.meta();
40
- * console.log(meta);
41
- */
42
- meta(): Promise<Record<string, JSONValue>>;
43
- /**
44
- * calls the process device /now function, which evaluates the current process state pulling new messages
45
- * to get the latest state
46
- *
47
- * @param path - The path to the hb state
48
- * @param json - Whether to return the result as JSON, defaults to true
49
- * @returns The result of the compute operation
50
- *
51
- * @example
52
- * const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
53
- * const result = await hyperbeam.now({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
54
- * console.log(result);
55
- */
56
- now<T extends JSONValue>({ path, json, }: {
57
- path: string;
58
- json?: boolean;
59
- }): Promise<T>;
60
- /**
61
- * calls the process device /compute function, which uses the currently evaluated state in the node
62
- *
63
- * @param path - The path to the compute resource
64
- * @param json - Whether to return the result as JSON, defaults to true
65
- * @returns The result of the compute operation
66
- *
67
- * @example
68
- * const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
69
- * const result = await hyperbeam.compute({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
70
- * console.log(result);
71
- */
72
- compute<T extends JSONValue>({ path, json, }: {
73
- path: string;
74
- json?: boolean;
75
- }): Promise<T>;
76
- /**
77
- * Checks if the process is HyperBeam compatible and caches the result.
78
- *
79
- * @returns {Promise<boolean>} True if the process is HyperBeam compatible, false otherwise.
80
- */
81
- checkHyperBeamCompatibility({ minSlot, }?: {
82
- minSlot?: number;
83
- }): Promise<boolean>;
84
- fetchHyperbeamPath<T extends JSONValue>({ path, json, }: {
85
- path: string;
86
- json?: boolean;
87
- }): Promise<T>;
88
- }