@ar.io/sdk 1.2.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/bundles/web.bundle.min.js +101 -333
- package/lib/cjs/common/ant.js +1 -351
- package/lib/cjs/common/index.js +0 -4
- package/lib/cjs/common/io.js +3 -3
- package/lib/cjs/types.js +0 -1
- package/lib/cjs/utils/arweave.js +1 -15
- package/lib/cjs/utils/graphql/index.js +0 -1
- package/lib/cjs/utils/graphql/processes.js +2 -2
- package/lib/cjs/utils/index.js +0 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant.js +2 -350
- package/lib/esm/common/index.js +0 -4
- package/lib/esm/common/io.js +4 -4
- package/lib/esm/types.js +0 -1
- package/lib/esm/utils/arweave.js +0 -12
- package/lib/esm/utils/graphql/index.js +0 -1
- package/lib/esm/utils/graphql/processes.js +3 -3
- package/lib/esm/utils/index.js +0 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant.d.ts +1 -274
- package/lib/types/common/index.d.ts +0 -3
- package/lib/types/common.d.ts +1 -138
- package/lib/types/types.d.ts +0 -1
- package/lib/types/utils/arweave.d.ts +0 -5
- package/lib/types/utils/graphql/index.d.ts +0 -1
- package/lib/types/utils/index.d.ts +0 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +5 -10
- package/lib/cjs/arns-service.js +0 -2
- package/lib/cjs/common/ar-io.js +0 -741
- package/lib/cjs/common/contracts/remote-contract.js +0 -55
- package/lib/cjs/common/contracts/warp-contract.js +0 -176
- package/lib/cjs/common/warp.js +0 -25
- package/lib/cjs/utils/graphql/smartweave.js +0 -309
- package/lib/cjs/utils/smartweave.js +0 -58
- package/lib/esm/arns-service.js +0 -1
- package/lib/esm/common/ar-io.js +0 -735
- package/lib/esm/common/contracts/remote-contract.js +0 -51
- package/lib/esm/common/contracts/warp-contract.js +0 -172
- package/lib/esm/common/warp.js +0 -22
- package/lib/esm/utils/graphql/smartweave.js +0 -303
- package/lib/esm/utils/smartweave.js +0 -50
- package/lib/types/arns-service.d.ts +0 -23
- package/lib/types/common/ar-io.d.ts +0 -551
- package/lib/types/common/contracts/remote-contract.d.ts +0 -38
- package/lib/types/common/contracts/warp-contract.d.ts +0 -43
- package/lib/types/common/warp.d.ts +0 -1
- package/lib/types/utils/graphql/smartweave.d.ts +0 -47
- package/lib/types/utils/smartweave.d.ts +0 -41
package/lib/esm/common/ar-io.js
DELETED
|
@@ -1,735 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* This program is free software: you can redistribute it and/or modify
|
|
5
|
-
* it under the terms of the GNU Affero General Public License as published by
|
|
6
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
* (at your option) any later version.
|
|
8
|
-
*
|
|
9
|
-
* This program is distributed in the hope that it will be useful,
|
|
10
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
* GNU Affero General Public License for more details.
|
|
13
|
-
*
|
|
14
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
*/
|
|
17
|
-
import { ARNS_TESTNET_REGISTRY_TX } from '../constants.js';
|
|
18
|
-
import { AR_IO_CONTRACT_FUNCTIONS, DENOMINATIONS, IOToken, } from '../types.js';
|
|
19
|
-
import { isContractConfiguration, isContractTxIdConfiguration, } from '../utils/smartweave.js';
|
|
20
|
-
import { RemoteContract } from './contracts/remote-contract.js';
|
|
21
|
-
import { InvalidContractConfigurationError, WarpContract } from './index.js';
|
|
22
|
-
/**
|
|
23
|
-
* The ArIO class provides an interface to interact with the Arweave Interoperability Contract.
|
|
24
|
-
* @deprecated - This class will be removed in the next major release.
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { ArIO } from '@permaweb/ar-io';
|
|
28
|
-
* const arIO = ArIO.init();
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export class ArIO {
|
|
32
|
-
/**
|
|
33
|
-
* @param config - @type {ContractConfiguration} The configuration object.
|
|
34
|
-
* @returns {WarpContract<ArIOState>} The contract object.
|
|
35
|
-
* @example
|
|
36
|
-
* Using the contract object
|
|
37
|
-
* ```ts
|
|
38
|
-
* ArIO.createContract({ contract: new WarpContract<ArIOState>({ contractTxId: 'myContractTxId' });
|
|
39
|
-
* ```
|
|
40
|
-
* Using the contractTxId
|
|
41
|
-
* ```ts
|
|
42
|
-
* ArIO.createContract({ contractTxId: 'myContractTxId' });
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
static createWriteableContract(config) {
|
|
46
|
-
if (!config || Object.keys(config).length === 0) {
|
|
47
|
-
return new WarpContract({
|
|
48
|
-
contractTxId: ARNS_TESTNET_REGISTRY_TX,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else if (isContractConfiguration(config)) {
|
|
52
|
-
return config.contract instanceof WarpContract
|
|
53
|
-
? config.contract
|
|
54
|
-
: new WarpContract(config.contract.configuration());
|
|
55
|
-
}
|
|
56
|
-
else if (isContractTxIdConfiguration(config)) {
|
|
57
|
-
return new WarpContract({ contractTxId: config.contractTxId });
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
throw new InvalidContractConfigurationError();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
static init(config) {
|
|
64
|
-
if (config && config.signer !== undefined) {
|
|
65
|
-
const { signer, ...rest } = config;
|
|
66
|
-
const contract = this.createWriteableContract(rest);
|
|
67
|
-
return new ArIOWritable({ signer, contract });
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return new ArIOReadable(config);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export class ArIOReadable {
|
|
75
|
-
contract;
|
|
76
|
-
constructor(config) {
|
|
77
|
-
if (!config || config === undefined) {
|
|
78
|
-
this.contract = new RemoteContract({
|
|
79
|
-
contractTxId: ARNS_TESTNET_REGISTRY_TX,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else if (isContractConfiguration(config)) {
|
|
83
|
-
this.contract = config.contract;
|
|
84
|
-
}
|
|
85
|
-
else if (isContractTxIdConfiguration(config)) {
|
|
86
|
-
this.contract = new RemoteContract({
|
|
87
|
-
contractTxId: config.contractTxId,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
throw new InvalidContractConfigurationError();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
96
|
-
* @returns {Promise<ArIOState>} The state of the contract.
|
|
97
|
-
* @example
|
|
98
|
-
* Get the current state
|
|
99
|
-
* ```ts
|
|
100
|
-
* arIO.getState();
|
|
101
|
-
* ```
|
|
102
|
-
* Get the state at a specific block height or sortkey
|
|
103
|
-
* ```ts
|
|
104
|
-
* arIO.getState({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
105
|
-
* arIO.getState({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
async getState(params = {}) {
|
|
109
|
-
const state = await this.contract.getState(params);
|
|
110
|
-
return state;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* @param domain @type {string} The domain name.
|
|
114
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
115
|
-
* @returns {Promise<ArNSNameData | undefined>} The record of the undername domain.
|
|
116
|
-
* @example
|
|
117
|
-
* Get the current record
|
|
118
|
-
* ```ts
|
|
119
|
-
* arIO.getRecord({ domain: "john" });
|
|
120
|
-
* ```
|
|
121
|
-
* Get the record at a specific block height or sortkey
|
|
122
|
-
* ```ts
|
|
123
|
-
* arIO.getRecord({ domain: "john", evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
124
|
-
* arIO.getRecord({ domain: "john", evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
async getArNSRecord({ domain, evaluationOptions, }) {
|
|
128
|
-
const records = await this.getArNSRecords({ evaluationOptions });
|
|
129
|
-
return records[domain];
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
133
|
-
* @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
|
|
134
|
-
* @example
|
|
135
|
-
* Get the current records
|
|
136
|
-
* ```ts
|
|
137
|
-
* ant.getRecords();
|
|
138
|
-
* ```
|
|
139
|
-
* Get the records at a specific block height or sortkey
|
|
140
|
-
* ```ts
|
|
141
|
-
* ant.getRecords({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
142
|
-
* ant.getRecords({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
async getArNSRecords({ evaluationOptions, } = {}) {
|
|
146
|
-
const state = await this.contract.getState({ evaluationOptions });
|
|
147
|
-
return state.records;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
151
|
-
* @returns {Promise<Record<string, ArNSReservedNameData>>} The reserved names.
|
|
152
|
-
* @example
|
|
153
|
-
* Get the current reserved names
|
|
154
|
-
* ```ts
|
|
155
|
-
* arIO.getArNSReservedNames();
|
|
156
|
-
* ```
|
|
157
|
-
* Get the reserved names at a specific block height or sortkey
|
|
158
|
-
* ```ts
|
|
159
|
-
* arIO.getArNSReservedNames({ evaluationOptions: { evalTo: { blockHeight: 1000 } });
|
|
160
|
-
* arIO.getArNSReservedNames({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } });
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
async getArNSReservedNames({ evaluationOptions, } = {}) {
|
|
164
|
-
const state = await this.contract.getState({ evaluationOptions });
|
|
165
|
-
return state.reserved;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* @param domain @type {string} The domain name.
|
|
169
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
170
|
-
* @returns {Promise<ArNSReservedNameData | undefined>} The reserved name data.
|
|
171
|
-
* @example
|
|
172
|
-
* Get the current reserved name
|
|
173
|
-
* ```ts
|
|
174
|
-
* arIO.getArNSReservedName({ domain: "myDomain" });
|
|
175
|
-
* ```
|
|
176
|
-
* Get the reserved name at a specific block height or sortkey
|
|
177
|
-
* ```ts
|
|
178
|
-
* arIO.getArNSReservedName({ domain: "myDomain", evaluationOptions: { evalTo: { blockHeight: 1000 } });
|
|
179
|
-
* arIO.getArNSReservedName({ domain: "myDomain", evaluationOptions: { evalTo: { sortKey: 'mySortKey' } });
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
async getArNSReservedName({ domain, evaluationOptions, }) {
|
|
183
|
-
const reservedNames = await this.getArNSReservedNames({
|
|
184
|
-
evaluationOptions,
|
|
185
|
-
});
|
|
186
|
-
return reservedNames[domain];
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
190
|
-
* @param address @type {string} The address of the account you want the balance of.
|
|
191
|
-
* @returns {Promise<number>} The balance of the provided address
|
|
192
|
-
* @example
|
|
193
|
-
* The current balance of the address.
|
|
194
|
-
* ```ts
|
|
195
|
-
* arIO.getBalance({ address });
|
|
196
|
-
* ```
|
|
197
|
-
* @example
|
|
198
|
-
* Get the balance at a specific block height or sortkey
|
|
199
|
-
* ```ts
|
|
200
|
-
* arIO.getBalance({ address, evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
201
|
-
* arIO.getBalance({ address, evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
async getBalance({ address, evaluationOptions, }) {
|
|
205
|
-
const balances = await this.getBalances({ evaluationOptions });
|
|
206
|
-
return balances[address] || 0;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
210
|
-
* @returns {Promise<Record<string, number>>} The balances of the ArIO Contract
|
|
211
|
-
* @example
|
|
212
|
-
* The current balances of the ANT.
|
|
213
|
-
* ```ts
|
|
214
|
-
* arIO.getBalances();
|
|
215
|
-
* ```
|
|
216
|
-
* @example
|
|
217
|
-
* Get the balances at a specific block height or sortkey
|
|
218
|
-
* ```ts
|
|
219
|
-
* arIO.getBalances({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
220
|
-
* arIO.getBalances({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
async getBalances({ evaluationOptions } = {}) {
|
|
224
|
-
const state = await this.contract.getState({ evaluationOptions });
|
|
225
|
-
return state.balances;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
229
|
-
* @param address @type {string} The address of the gateway you want information about.
|
|
230
|
-
* @returns {Promise<Gateway>} The balance of the provided address
|
|
231
|
-
* @example
|
|
232
|
-
* The current gateway info of the address.
|
|
233
|
-
* ```ts
|
|
234
|
-
* arIO.getGateway({ address });
|
|
235
|
-
* ```
|
|
236
|
-
* @example
|
|
237
|
-
* Get the gateway info of the address at a certain block height or sortkey
|
|
238
|
-
* ```ts
|
|
239
|
-
* arIO.getGateway({ address, evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
240
|
-
* arIO.getGateway({ address, evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
async getGateway({ address, evaluationOptions, }) {
|
|
244
|
-
return this.contract
|
|
245
|
-
.readInteraction({
|
|
246
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.GATEWAY,
|
|
247
|
-
inputs: {
|
|
248
|
-
target: address,
|
|
249
|
-
},
|
|
250
|
-
evaluationOptions,
|
|
251
|
-
})
|
|
252
|
-
.catch(() => {
|
|
253
|
-
return undefined;
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
258
|
-
* @returns {Promise<Record<string, Gateway> >} The registered gateways of the ArIO Network.
|
|
259
|
-
* @example
|
|
260
|
-
* The current gateways.
|
|
261
|
-
* ```ts
|
|
262
|
-
* arIO.getGateways();
|
|
263
|
-
* ```
|
|
264
|
-
* @example
|
|
265
|
-
* Get the gateways at a specific block height or sortkey
|
|
266
|
-
* ```ts
|
|
267
|
-
* arIO.getGateways({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
268
|
-
* arIO.getGateways({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
async getGateways({ evaluationOptions } = {}) {
|
|
272
|
-
return this.contract.readInteraction({
|
|
273
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.GATEWAYS,
|
|
274
|
-
evaluationOptions,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
279
|
-
* @returns {Promise<EpochDistributionData>} The current distribution data of the epoch.
|
|
280
|
-
* @example
|
|
281
|
-
* The current epoch
|
|
282
|
-
* ```ts
|
|
283
|
-
* arIO.getCurrentEpoch();
|
|
284
|
-
* ```
|
|
285
|
-
* @example
|
|
286
|
-
* Get the epoch at a given block height or sortkey
|
|
287
|
-
* ```ts
|
|
288
|
-
* arIO.getCurrentEpoch({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
289
|
-
* arIO.getCurrentEpoch({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
|
-
async getCurrentEpoch({ evaluationOptions, } = {}) {
|
|
293
|
-
return this.contract.readInteraction({
|
|
294
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.EPOCH,
|
|
295
|
-
evaluationOptions,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
300
|
-
* @param blockHeight @type {number} The block height of the epoch you want to get.
|
|
301
|
-
* @returns {Promise<EpochDistributionData>} The current distribution data of the epoch.
|
|
302
|
-
* @example
|
|
303
|
-
* The current epoch
|
|
304
|
-
* ```ts
|
|
305
|
-
* arIO.getEpoch({ blockHeight: 1000 });
|
|
306
|
-
* ```
|
|
307
|
-
* @example
|
|
308
|
-
* Get the epoch at a given block height or sortkey
|
|
309
|
-
* ```ts
|
|
310
|
-
* arIO.getEpoch({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
311
|
-
* arIO.getEpoch({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
async getEpoch({ blockHeight, evaluationOptions, }) {
|
|
315
|
-
return this.contract.readInteraction({
|
|
316
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.EPOCH,
|
|
317
|
-
inputs: {
|
|
318
|
-
height: blockHeight,
|
|
319
|
-
},
|
|
320
|
-
evaluationOptions,
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
325
|
-
* @returns {Promise<WeightedObserver[]>} The current distribution data of the epoch.
|
|
326
|
-
* @example
|
|
327
|
-
* Current prescribed observers
|
|
328
|
-
* ```ts
|
|
329
|
-
* arIO.getPrescribedObservers();
|
|
330
|
-
* ```
|
|
331
|
-
* @example
|
|
332
|
-
* Get the previous prescribed observers at a given block height or sortkey
|
|
333
|
-
* ```ts
|
|
334
|
-
* arIO.getPrescribedObservers({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
335
|
-
* arIO.getPrescribedObservers({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
336
|
-
* ```
|
|
337
|
-
*/
|
|
338
|
-
async getPrescribedObservers({ evaluationOptions, } = {}) {
|
|
339
|
-
return this.contract.readInteraction({
|
|
340
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.PRESCRIBED_OBSERVERS,
|
|
341
|
-
evaluationOptions,
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
346
|
-
* @returns {Promise<Observations>} The current observations data.
|
|
347
|
-
* @example
|
|
348
|
-
* All observations.
|
|
349
|
-
* ```ts
|
|
350
|
-
* arIO.getObservations();
|
|
351
|
-
* ```
|
|
352
|
-
* @example
|
|
353
|
-
* Get observations at a given block height or sortkey
|
|
354
|
-
* ```ts
|
|
355
|
-
* arIO.getObservations({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
356
|
-
* arIO.getObservations({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
357
|
-
* ```
|
|
358
|
-
*/
|
|
359
|
-
async getObservations({ evaluationOptions, } = {}) {
|
|
360
|
-
const { observations } = await this.contract.getState({
|
|
361
|
-
evaluationOptions,
|
|
362
|
-
});
|
|
363
|
-
return observations;
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
367
|
-
* @returns {Promise<EpochDistributionData>} The current distribution data of the epoch.
|
|
368
|
-
* @example
|
|
369
|
-
* Get the current distribution data.
|
|
370
|
-
* ```ts
|
|
371
|
-
* arIO.getDistributions();
|
|
372
|
-
* ```
|
|
373
|
-
* @example
|
|
374
|
-
* Get distributions at a given block height or sortkey
|
|
375
|
-
* ```ts
|
|
376
|
-
* arIO.getDistributions({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
377
|
-
* arIO.getDistributions({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
378
|
-
* ```
|
|
379
|
-
*/
|
|
380
|
-
async getDistributions({ evaluationOptions, } = {}) {
|
|
381
|
-
const { distributions } = await this.contract.getState({
|
|
382
|
-
evaluationOptions,
|
|
383
|
-
});
|
|
384
|
-
return distributions;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Fetches the in-auction domain or the pricing data for how much it would cost to initiate the auction.
|
|
388
|
-
*
|
|
389
|
-
* @param domain @type {string} The domain name in auction
|
|
390
|
-
* @param type @type {RegistrationType} The type of registration, relevant for reading auction prices
|
|
391
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
392
|
-
* @returns {Promise<ArNSAuctionData>} The auction data for the specified name.
|
|
393
|
-
* @example
|
|
394
|
-
* Get the current auction data
|
|
395
|
-
* ```ts
|
|
396
|
-
* arIO.getAuction({ domain: 'myDomain' });
|
|
397
|
-
* ```
|
|
398
|
-
* @example
|
|
399
|
-
* Get the auction data at a given block height or sortkey
|
|
400
|
-
* ```ts
|
|
401
|
-
* arIO.getAuction({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
402
|
-
* arIO.getAuction({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
403
|
-
* ```
|
|
404
|
-
*/
|
|
405
|
-
async getAuction({ domain, type, evaluationOptions, }) {
|
|
406
|
-
return this.contract.readInteraction({
|
|
407
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.AUCTION,
|
|
408
|
-
inputs: {
|
|
409
|
-
name: domain,
|
|
410
|
-
type,
|
|
411
|
-
},
|
|
412
|
-
evaluationOptions,
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Fetches the current auctions.
|
|
417
|
-
*
|
|
418
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
419
|
-
* @returns {Promise<Record<string, ArNSAuctionData>>} The current auctions data.
|
|
420
|
-
* @example
|
|
421
|
-
* Get the current auction data
|
|
422
|
-
* ```ts
|
|
423
|
-
* arIO.getAuctions();
|
|
424
|
-
* ```
|
|
425
|
-
* @example
|
|
426
|
-
* Get the auction data at a given block height or sortkey
|
|
427
|
-
* ```ts
|
|
428
|
-
* arIO.getAuctions({ evaluationOptions: { evalTo: { blockHeight: 1000 } } });
|
|
429
|
-
* arIO.getAuctions({ evaluationOptions: { evalTo: { sortKey: 'mySortKey' } } });
|
|
430
|
-
* ```
|
|
431
|
-
*/
|
|
432
|
-
async getAuctions({ evaluationOptions, } = {}) {
|
|
433
|
-
const { auctions } = await this.contract.getState({
|
|
434
|
-
evaluationOptions,
|
|
435
|
-
});
|
|
436
|
-
return auctions;
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Fetches the price for an interaction
|
|
440
|
-
*
|
|
441
|
-
* @param evaluationOptions @type {EvaluationOptions} The evaluation options.
|
|
442
|
-
* @returns {Promise<number>} The price to perform the interaction - eg the registration cost.
|
|
443
|
-
* @example
|
|
444
|
-
* Get the current auction data
|
|
445
|
-
* ```ts
|
|
446
|
-
* arIO.getPriceForInteraction({
|
|
447
|
-
* interactionName: 'buyRecord',
|
|
448
|
-
* payload: { name: 'ardrive', years: 1, type: 'lease', auction: false},
|
|
449
|
-
* });
|
|
450
|
-
* ```
|
|
451
|
-
* @example
|
|
452
|
-
* Get the auction data at a given block height or sortkey
|
|
453
|
-
* ```ts
|
|
454
|
-
* arIO.getPriceForInteraction({
|
|
455
|
-
* interactionName: 'buyRecord',
|
|
456
|
-
* payload: { name: 'ardrive', years: 1, type: 'lease', auction: false},
|
|
457
|
-
* evaluationOptions: { evalTo: { blockHeight: 1000 } }
|
|
458
|
-
* });
|
|
459
|
-
*
|
|
460
|
-
* arIO.getPriceForInteraction({
|
|
461
|
-
* interactionName: 'buyRecord',
|
|
462
|
-
* payload: { name: 'ardrive', years: 1, type: 'lease', auction: false},
|
|
463
|
-
* evaluationOptions: { evalTo: { sortKey: 'mySortKey' } }
|
|
464
|
-
* });
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
async getPriceForInteraction({ interactionName, payload, evaluationOptions, }) {
|
|
468
|
-
const { price } = await this.contract.readInteraction({
|
|
469
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.PRICE_FOR_INTERACTION,
|
|
470
|
-
inputs: {
|
|
471
|
-
interactionName,
|
|
472
|
-
...payload,
|
|
473
|
-
},
|
|
474
|
-
evaluationOptions,
|
|
475
|
-
});
|
|
476
|
-
return price;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
export class ArIOWritable extends ArIOReadable {
|
|
480
|
-
signer;
|
|
481
|
-
constructor({ signer, ...config }) {
|
|
482
|
-
if (Object.keys(config).length === 0) {
|
|
483
|
-
super({
|
|
484
|
-
contract: new WarpContract({
|
|
485
|
-
contractTxId: ARNS_TESTNET_REGISTRY_TX,
|
|
486
|
-
}),
|
|
487
|
-
});
|
|
488
|
-
this.signer = signer;
|
|
489
|
-
}
|
|
490
|
-
else if (isContractConfiguration(config)) {
|
|
491
|
-
super({ contract: config.contract });
|
|
492
|
-
this.signer = signer;
|
|
493
|
-
}
|
|
494
|
-
else if (isContractTxIdConfiguration(config)) {
|
|
495
|
-
super({
|
|
496
|
-
contract: new WarpContract({
|
|
497
|
-
contractTxId: config.contractTxId,
|
|
498
|
-
}),
|
|
499
|
-
});
|
|
500
|
-
this.signer = signer;
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
throw new InvalidContractConfigurationError();
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* @param target @type {string} The address of the account you want to transfer IO tokens to.
|
|
508
|
-
* @param qty @type {number | mIOToken} The amount of IO or mIO to transfer.
|
|
509
|
-
* @param denomination @type {DENOMINATIONS} The denomination of the amount to transfer (io or mio).
|
|
510
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
511
|
-
* @example
|
|
512
|
-
* mIO transfer
|
|
513
|
-
* ```ts
|
|
514
|
-
* arIO.transfer({
|
|
515
|
-
* target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk",
|
|
516
|
-
* qty: 1 * 10 ** 6,
|
|
517
|
-
* denomination: DENOMINATIONS.MIO
|
|
518
|
-
* });
|
|
519
|
-
*```
|
|
520
|
-
* IO transfer
|
|
521
|
-
* ```ts
|
|
522
|
-
* arIO.transfer({
|
|
523
|
-
target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk",
|
|
524
|
-
qty: new IOToken(100).toMIO(),
|
|
525
|
-
denomination: DENOMINATIONS.IO
|
|
526
|
-
});
|
|
527
|
-
* ```
|
|
528
|
-
*/
|
|
529
|
-
async transfer({ target, qty, denomination = DENOMINATIONS.IO, }, options) {
|
|
530
|
-
let convertedQty = qty;
|
|
531
|
-
// the contract will no longer support denominations
|
|
532
|
-
if (denomination === DENOMINATIONS.IO && typeof qty === 'number') {
|
|
533
|
-
convertedQty = new IOToken(qty).toMIO();
|
|
534
|
-
}
|
|
535
|
-
return this.contract.writeInteraction({
|
|
536
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.TRANSFER,
|
|
537
|
-
inputs: {
|
|
538
|
-
target,
|
|
539
|
-
qty: convertedQty.valueOf(), // convert to number if mIO is provided
|
|
540
|
-
},
|
|
541
|
-
signer: this.signer,
|
|
542
|
-
}, options);
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* @param params @type {JoinNetworkParams} Your gateway configuration.
|
|
546
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
547
|
-
* @example
|
|
548
|
-
* Join the network with the your configuration.
|
|
549
|
-
* ```ts
|
|
550
|
-
* const jointNetworkParams = {
|
|
551
|
-
qty: new IOToken(10000).toMIO(), // initial operator stake
|
|
552
|
-
allowDelegatedStaking: true, // delegated staking settings
|
|
553
|
-
minDelegatedStake: new IOToken(100).toMIO(), // min delegated stake
|
|
554
|
-
delegateRewardShareRatio: 1, // delegate reward share ratio
|
|
555
|
-
autoStake: true, // auto stake operator tokens
|
|
556
|
-
label: 'john smith', // min 1, max 64 characters
|
|
557
|
-
note: 'The example gateway', // max 256 characters
|
|
558
|
-
properties: 'FH1aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2PeY44', // Arweave transaction ID containing additional properties of the Gateway.
|
|
559
|
-
observerWallet: '0VE0wIhDy90WiQoV3U2PeY44FH1aVetOoulPGqgYukj', // wallet address of the observer
|
|
560
|
-
fqdn: 'example.com', // fully qualified domain name
|
|
561
|
-
port: 443, // port number
|
|
562
|
-
protocol: 'https', // protocol
|
|
563
|
-
};
|
|
564
|
-
* arIO.joinNetwork(jointNetworkParams);
|
|
565
|
-
* ```
|
|
566
|
-
*/
|
|
567
|
-
async joinNetwork({ qty, allowDelegatedStaking, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerWallet, }, options) {
|
|
568
|
-
return this.contract.writeInteraction({
|
|
569
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.JOIN_NETWORK,
|
|
570
|
-
inputs: {
|
|
571
|
-
qty: qty.valueOf(), // convert to number if mIO is provided
|
|
572
|
-
allowDelegatedStaking,
|
|
573
|
-
delegateRewardShareRatio,
|
|
574
|
-
fqdn,
|
|
575
|
-
label,
|
|
576
|
-
minDelegatedStake: minDelegatedStake.valueOf(), // convert to number if mIO is provided
|
|
577
|
-
note,
|
|
578
|
-
port,
|
|
579
|
-
properties,
|
|
580
|
-
protocol,
|
|
581
|
-
autoStake,
|
|
582
|
-
observerWallet,
|
|
583
|
-
},
|
|
584
|
-
signer: this.signer,
|
|
585
|
-
}, options);
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* @param params @type {UpdateGatewaySettingsParams} Gateway settings to update
|
|
589
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
590
|
-
* @example
|
|
591
|
-
* Update a setting of the gateway.
|
|
592
|
-
* ```ts
|
|
593
|
-
* arIO.updateGatewaySettings({ autoStake: true, minDelegatedStake: new IOToken(100).toMIO()});
|
|
594
|
-
* ```
|
|
595
|
-
*/
|
|
596
|
-
async updateGatewaySettings({ allowDelegatedStaking, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerWallet, }, options) {
|
|
597
|
-
return this.contract.writeInteraction({
|
|
598
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.UPDATE_GATEWAY_SETTINGS,
|
|
599
|
-
inputs: {
|
|
600
|
-
allowDelegatedStaking,
|
|
601
|
-
delegateRewardShareRatio,
|
|
602
|
-
fqdn,
|
|
603
|
-
label,
|
|
604
|
-
minDelegatedStake: minDelegatedStake?.valueOf(), // convert to number if mIO is provided
|
|
605
|
-
note,
|
|
606
|
-
port,
|
|
607
|
-
properties,
|
|
608
|
-
protocol,
|
|
609
|
-
autoStake,
|
|
610
|
-
observerWallet,
|
|
611
|
-
},
|
|
612
|
-
signer: this.signer,
|
|
613
|
-
}, options);
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* @param target @type {string} The gateway you wish to delegate stake to.
|
|
617
|
-
* @param qty @type {number | mIOToken} The amount of stake to delegate represented in mIO.
|
|
618
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
619
|
-
* @example
|
|
620
|
-
* Delegate stake to a gateway.
|
|
621
|
-
* ```ts
|
|
622
|
-
* arIO.increaseDelegateStake({ target: "FH1aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2PeY44", qty: 1000 });
|
|
623
|
-
* ```
|
|
624
|
-
*/
|
|
625
|
-
async increaseDelegateStake(params, options) {
|
|
626
|
-
return this.contract.writeInteraction({
|
|
627
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.DELEGATE_STAKE,
|
|
628
|
-
inputs: {
|
|
629
|
-
target: params.target,
|
|
630
|
-
qty: params.qty.valueOf(), // convert to number if mIO is provided
|
|
631
|
-
},
|
|
632
|
-
signer: this.signer,
|
|
633
|
-
}, options);
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* @param target @type {string} The gateway you wish to decrease stake at.
|
|
637
|
-
* @param qty @type {number | mIOToken} The amount of stake to decrease represented in mIO.
|
|
638
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
639
|
-
* @example
|
|
640
|
-
* Decrease your delegated staked tokens at a gateway.
|
|
641
|
-
* ```ts
|
|
642
|
-
* arIO.decreaseDelegateStake({ target: "FH1aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2PeY44", qty: new IOToken(1000).toMIO() });
|
|
643
|
-
* ```
|
|
644
|
-
*/
|
|
645
|
-
async decreaseDelegateStake(params, options) {
|
|
646
|
-
return this.contract.writeInteraction({
|
|
647
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.DECREASE_DELEGATE_STAKE,
|
|
648
|
-
inputs: {
|
|
649
|
-
target: params.target,
|
|
650
|
-
qty: params.qty.valueOf(), // convert to number if mIO is provided
|
|
651
|
-
},
|
|
652
|
-
signer: this.signer,
|
|
653
|
-
}, options);
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* @param qty @type {number | mIOToken} The amount of stake to increase by represented in mIO.
|
|
657
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
658
|
-
* @example
|
|
659
|
-
* Increase your staked tokens as an operator
|
|
660
|
-
* ```new IOToken(1000).toMIO()
|
|
661
|
-
* arIO.increaseOperatorStake({ qty: new IOToken(1000).toMIO() });
|
|
662
|
-
* ```
|
|
663
|
-
*/
|
|
664
|
-
async increaseOperatorStake(params, options) {
|
|
665
|
-
return this.contract.writeInteraction({
|
|
666
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.INCREASE_OPERATOR_STAKE,
|
|
667
|
-
inputs: {
|
|
668
|
-
qty: params.qty.valueOf(), // convert to number if mIO is provided
|
|
669
|
-
},
|
|
670
|
-
signer: this.signer,
|
|
671
|
-
}, options);
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* @param qty @type {number} The amount of stake to decrease by.
|
|
675
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
676
|
-
* @example
|
|
677
|
-
* Decrease your staked tokens as an operator
|
|
678
|
-
* ```ts
|
|
679
|
-
* arIO.decreaseOperatorStake({ qty: 1000 });
|
|
680
|
-
* ```
|
|
681
|
-
*/
|
|
682
|
-
async decreaseOperatorStake(params, options) {
|
|
683
|
-
const res = this.contract.writeInteraction({
|
|
684
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.DECREASE_OPERATOR_STAKE,
|
|
685
|
-
inputs: {
|
|
686
|
-
qty: params.qty.valueOf(), // convert to number if mIO is provided
|
|
687
|
-
},
|
|
688
|
-
signer: this.signer,
|
|
689
|
-
}, options);
|
|
690
|
-
return res;
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* @param reportTxId @type {TransactionId} The transaction ID of the report.
|
|
694
|
-
* @param failedGateways @type {WalletAddress[]} The failed gateways you are reporting.
|
|
695
|
-
* @returns {Promise<WriteInteractionResult>} The result of the interaction.
|
|
696
|
-
* @example
|
|
697
|
-
* Save your observations.
|
|
698
|
-
* ```ts
|
|
699
|
-
* arIO.saveObservations({
|
|
700
|
-
* reportTxId: '5f7aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2Pe6ko',
|
|
701
|
-
* failedGateways: ['FH1aVetOoulPGqgYukj0VE0wIhDy90WiQoV3U2PeY44']
|
|
702
|
-
* });
|
|
703
|
-
* ```
|
|
704
|
-
*/
|
|
705
|
-
async saveObservations(params, options) {
|
|
706
|
-
return this.contract.writeInteraction({
|
|
707
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.SAVE_OBSERVATIONS,
|
|
708
|
-
inputs: {
|
|
709
|
-
observerReportTxId: params.reportTxId,
|
|
710
|
-
failedGateways: params.failedGateways,
|
|
711
|
-
},
|
|
712
|
-
signer: this.signer,
|
|
713
|
-
}, options);
|
|
714
|
-
}
|
|
715
|
-
async extendLease(params, options) {
|
|
716
|
-
return this.contract.writeInteraction({
|
|
717
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.EXTEND_RECORD,
|
|
718
|
-
inputs: {
|
|
719
|
-
name: params.domain,
|
|
720
|
-
years: params.years,
|
|
721
|
-
},
|
|
722
|
-
signer: this.signer,
|
|
723
|
-
}, options);
|
|
724
|
-
}
|
|
725
|
-
async increaseUndernameLimit(params, options) {
|
|
726
|
-
return this.contract.writeInteraction({
|
|
727
|
-
functionName: AR_IO_CONTRACT_FUNCTIONS.INCREASE_UNDERNAME_COUNT,
|
|
728
|
-
inputs: {
|
|
729
|
-
name: params.domain,
|
|
730
|
-
qty: params.qty,
|
|
731
|
-
},
|
|
732
|
-
signer: this.signer,
|
|
733
|
-
}, options);
|
|
734
|
-
}
|
|
735
|
-
}
|