@ar.io/sdk 3.21.1-alpha.1 → 3.22.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.
- package/bundles/web.bundle.min.js +69 -69
- package/lib/cjs/cli/cli.js +1 -5
- package/lib/cjs/cli/options.js +6 -0
- package/lib/cjs/cli/utils.js +42 -1
- package/lib/cjs/common/hyperbeam/hb.js +173 -0
- package/lib/cjs/common/io.js +43 -3
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +1 -5
- package/lib/esm/cli/options.js +6 -0
- package/lib/esm/cli/utils.js +41 -1
- package/lib/esm/common/hyperbeam/hb.js +169 -0
- package/lib/esm/common/io.js +43 -3
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/options.d.ts +4 -0
- package/lib/types/cli/utils.d.ts +2 -1
- package/lib/types/common/hyperbeam/hb.d.ts +88 -0
- package/lib/types/common/io.d.ts +4 -2
- package/lib/types/types/common.d.ts +3 -0
- package/lib/types/types/io.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/esm/common/io.js
CHANGED
|
@@ -24,6 +24,7 @@ import { defaultArweave } from './arweave.js';
|
|
|
24
24
|
import { AOProcess } from './contracts/ao-process.js';
|
|
25
25
|
import { InvalidContractConfigurationError } from './error.js';
|
|
26
26
|
import { createFaucet } from './faucet.js';
|
|
27
|
+
import { HB } from './hyperbeam/hb.js';
|
|
27
28
|
import { Logger } from './logger.js';
|
|
28
29
|
import { TurboArNSPaymentFactory, TurboArNSPaymentProviderAuthenticated, isTurboArNSSigner, } from './turbo.js';
|
|
29
30
|
export class ARIO {
|
|
@@ -100,9 +101,9 @@ export class ARIOReadable {
|
|
|
100
101
|
hyperbeamUrl;
|
|
101
102
|
paymentProvider; // TODO: this could be an array/map of payment providers
|
|
102
103
|
logger = Logger.default;
|
|
104
|
+
hb;
|
|
103
105
|
constructor(config) {
|
|
104
106
|
this.arweave = config?.arweave ?? defaultArweave;
|
|
105
|
-
this.hyperbeamUrl = config?.hyperbeamUrl;
|
|
106
107
|
if (config === undefined || Object.keys(config).length === 0) {
|
|
107
108
|
this.process = new AOProcess({
|
|
108
109
|
processId: ARIO_MAINNET_PROCESS_ID,
|
|
@@ -119,6 +120,19 @@ export class ARIOReadable {
|
|
|
119
120
|
else {
|
|
120
121
|
throw new InvalidContractConfigurationError();
|
|
121
122
|
}
|
|
123
|
+
// only use hyperbeam if the client has provided a hyperbeamUrl
|
|
124
|
+
// this will avoid overwhelming the HyperBeam node with requests
|
|
125
|
+
// as we shift using HyperBEAM for all ANT operations
|
|
126
|
+
if (config?.hyperbeamUrl !== undefined) {
|
|
127
|
+
this.hyperbeamUrl = config.hyperbeamUrl;
|
|
128
|
+
this.hb = new HB({
|
|
129
|
+
url: this.hyperbeamUrl,
|
|
130
|
+
processId: this.process.processId,
|
|
131
|
+
});
|
|
132
|
+
this.logger.debug(`Using HyperBEAM node for process ${this.process.processId}`, {
|
|
133
|
+
hyperbeamUrl: this.hyperbeamUrl,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
122
136
|
this.paymentProvider = TurboArNSPaymentFactory.init({
|
|
123
137
|
paymentUrl: config?.paymentUrl,
|
|
124
138
|
});
|
|
@@ -218,6 +232,24 @@ export class ARIOReadable {
|
|
|
218
232
|
});
|
|
219
233
|
}
|
|
220
234
|
async getBalance({ address }) {
|
|
235
|
+
if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
|
|
236
|
+
this.logger.debug('Getting balance from HyperBEAM', { address });
|
|
237
|
+
const res = await this.hb
|
|
238
|
+
.compute({
|
|
239
|
+
path: `balances/${address}`,
|
|
240
|
+
})
|
|
241
|
+
.then((res) => Number(res))
|
|
242
|
+
.catch((error) => {
|
|
243
|
+
this.logger.error('Failed to get balance from HyperBEAM', {
|
|
244
|
+
cause: error,
|
|
245
|
+
});
|
|
246
|
+
return null;
|
|
247
|
+
});
|
|
248
|
+
if (res !== null)
|
|
249
|
+
return res;
|
|
250
|
+
// else fall through to CU read
|
|
251
|
+
this.logger.info('Failed to get balance from HyperBEAM, failing over to to CU read', { address });
|
|
252
|
+
}
|
|
221
253
|
return this.process.read({
|
|
222
254
|
tags: [
|
|
223
255
|
{ name: 'Action', value: 'Balance' },
|
|
@@ -816,7 +848,7 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
816
848
|
signer: this.signer,
|
|
817
849
|
});
|
|
818
850
|
}
|
|
819
|
-
async joinNetwork({ operatorStake, allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }, options) {
|
|
851
|
+
async joinNetwork({ operatorStake, allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, services, }, options) {
|
|
820
852
|
const { tags = [] } = options || {};
|
|
821
853
|
const allTags = [
|
|
822
854
|
...tags,
|
|
@@ -873,6 +905,10 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
873
905
|
name: 'Observer-Address',
|
|
874
906
|
value: observerAddress,
|
|
875
907
|
},
|
|
908
|
+
{
|
|
909
|
+
name: 'Services',
|
|
910
|
+
value: services ? JSON.stringify(services) : undefined,
|
|
911
|
+
},
|
|
876
912
|
];
|
|
877
913
|
return this.process.send({
|
|
878
914
|
signer: this.signer,
|
|
@@ -886,7 +922,7 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
886
922
|
tags: [...tags, { name: 'Action', value: 'Leave-Network' }],
|
|
887
923
|
});
|
|
888
924
|
}
|
|
889
|
-
async updateGatewaySettings({ allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }, options) {
|
|
925
|
+
async updateGatewaySettings({ allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, services, }, options) {
|
|
890
926
|
const { tags = [] } = options || {};
|
|
891
927
|
const allTags = [
|
|
892
928
|
...tags,
|
|
@@ -915,6 +951,10 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
915
951
|
value: minDelegatedStake?.valueOf().toString(),
|
|
916
952
|
},
|
|
917
953
|
{ name: 'Auto-Stake', value: autoStake?.toString() },
|
|
954
|
+
{
|
|
955
|
+
name: 'Services',
|
|
956
|
+
value: services ? JSON.stringify(services) : undefined,
|
|
957
|
+
},
|
|
918
958
|
];
|
|
919
959
|
return this.process.send({
|
|
920
960
|
signer: this.signer,
|
package/lib/esm/version.js
CHANGED
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -46,7 +46,8 @@ export declare function paginationParamsFromOptions<O extends PaginationCLIOptio
|
|
|
46
46
|
export declare function epochInputFromOptions(options: EpochCLIOptions): EpochInput;
|
|
47
47
|
export declare function requiredInitiatorFromOptions(options: InitiatorCLIOptions): string;
|
|
48
48
|
export declare function customTagsFromOptions<O extends WriteActionCLIOptions>(options: O): WriteOptions;
|
|
49
|
-
export declare function
|
|
49
|
+
export declare function servicesFromOptions(services?: string): any;
|
|
50
|
+
export declare function gatewaySettingsFromOptions(options: UpdateGatewaySettingsCLIOptions): AoUpdateGatewaySettingsParams;
|
|
50
51
|
export declare function requiredTargetAndQuantityFromOptions(options: TransferCLIOptions): {
|
|
51
52
|
target: string;
|
|
52
53
|
arioQuantity: ARIOToken;
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
}
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Arweave from 'arweave';
|
|
2
2
|
import { ARIOWithFaucet, AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSNameDataWithName, AoArNSPurchaseParams, AoArNSReservedNameData, AoArNSReservedNameDataWithName, AoBalanceWithAddress, AoBuyRecordParams, AoCreatePrimaryNameRequest, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionData, AoEpochDistributionTotalsData, AoEpochObservationData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGatewayWithAddress, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoJoinNetworkParams, AoMessageResult, AoPaginatedAddressParams, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoRegistrationFees, AoReturnedName, AoRevokeVaultParams, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, AoWeightedObserver, ArNSNameResolutionData, ArNSNameResolver, BuyArNSNameProgressEvents, CostDetailsResult, DemandFactorSettings, EpochInput, OptionalArweave, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, SetPrimaryNameProgressEvents, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
|
|
3
3
|
import { AOProcess } from './contracts/ao-process.js';
|
|
4
|
+
import { HB } from './hyperbeam/hb.js';
|
|
4
5
|
import { Logger } from './logger.js';
|
|
5
6
|
import { TurboArNSPaymentProviderAuthenticated, TurboArNSPaymentProviderUnauthenticated } from './turbo.js';
|
|
6
7
|
type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration & {
|
|
@@ -31,6 +32,7 @@ export declare class ARIOReadable implements AoARIORead, ArNSNameResolver {
|
|
|
31
32
|
protected hyperbeamUrl: string | undefined;
|
|
32
33
|
protected paymentProvider: TurboArNSPaymentProviderUnauthenticated;
|
|
33
34
|
protected logger: Logger;
|
|
35
|
+
protected hb: HB | undefined;
|
|
34
36
|
constructor(config?: ARIOConfigNoSigner);
|
|
35
37
|
getInfo(): Promise<{
|
|
36
38
|
Name: string;
|
|
@@ -172,9 +174,9 @@ export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
|
|
|
172
174
|
createVault({ lockLengthMs, quantity }: AoCreateVaultParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
173
175
|
extendVault({ vaultId, extendLengthMs }: AoExtendVaultParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
174
176
|
increaseVault({ vaultId, quantity }: AoIncreaseVaultParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
175
|
-
joinNetwork({ operatorStake, allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }: AoJoinNetworkParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
177
|
+
joinNetwork({ operatorStake, allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, services, }: AoJoinNetworkParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
176
178
|
leaveNetwork(options?: WriteOptions): Promise<AoMessageResult>;
|
|
177
|
-
updateGatewaySettings({ allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }: AoUpdateGatewaySettingsParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
179
|
+
updateGatewaySettings({ allowDelegatedStaking, allowedDelegates, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, services, }: AoUpdateGatewaySettingsParams, options?: WriteOptions): Promise<AoMessageResult>;
|
|
178
180
|
delegateStake(params: {
|
|
179
181
|
target: string;
|
|
180
182
|
stakeQty: number | mARIOToken;
|
package/lib/types/types/io.d.ts
CHANGED
|
@@ -278,6 +278,7 @@ export type AoAllGatewayVaults = AoGatewayVault & {
|
|
|
278
278
|
};
|
|
279
279
|
export type AoJoinNetworkParams = Pick<AoGateway, 'operatorStake'> & Partial<AoGatewaySettings> & {
|
|
280
280
|
observerAddress?: WalletAddress;
|
|
281
|
+
services?: AoGatewayServices;
|
|
281
282
|
};
|
|
282
283
|
export type AoUpdateGatewaySettingsParams = AtLeastOne<Omit<AoJoinNetworkParams, 'operatorStake'>>;
|
|
283
284
|
export type AoArNSNameParams = {
|
package/lib/types/version.d.ts
CHANGED