@gearbox-protocol/sdk 18.2.0-next.5 → 18.2.0-next.7
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/dist/cjs/permissionless/api/oracles/schemas.js +3 -1
- package/dist/cjs/testnets/TestnetsAPI.js +179 -0
- package/dist/cjs/testnets/errors/TestnetNotFoundError.js +15 -0
- package/dist/cjs/testnets/errors/TestnetRequestFailedError.js +24 -0
- package/dist/cjs/testnets/errors/TestnetStatusError.js +19 -0
- package/dist/cjs/testnets/errors/TestnetValidationError.js +24 -0
- package/dist/cjs/testnets/errors/TestnetWaitTimeoutError.js +30 -0
- package/dist/cjs/testnets/errors/TestnetsError.js +34 -0
- package/dist/cjs/testnets/errors/index.js +13 -0
- package/dist/cjs/testnets/index.js +32 -0
- package/dist/cjs/testnets/package.json +1 -0
- package/dist/cjs/testnets/schemas.js +242 -0
- package/dist/cjs/testnets/types.js +1 -0
- package/dist/esm/permissionless/api/oracles/schemas.js +3 -1
- package/dist/esm/testnets/TestnetsAPI.js +178 -0
- package/dist/esm/testnets/errors/TestnetNotFoundError.js +14 -0
- package/dist/esm/testnets/errors/TestnetRequestFailedError.js +23 -0
- package/dist/esm/testnets/errors/TestnetStatusError.js +18 -0
- package/dist/esm/testnets/errors/TestnetValidationError.js +23 -0
- package/dist/esm/testnets/errors/TestnetWaitTimeoutError.js +29 -0
- package/dist/esm/testnets/errors/TestnetsError.js +33 -0
- package/dist/esm/testnets/errors/index.js +7 -0
- package/dist/esm/testnets/index.js +11 -0
- package/dist/esm/testnets/package.json +1 -0
- package/dist/esm/testnets/schemas.js +228 -0
- package/dist/esm/testnets/types.js +1 -0
- package/dist/types/permissionless/api/oracles/schemas.d.ts +2 -0
- package/dist/types/permissionless/api/oracles/types.d.ts +11 -0
- package/dist/types/testnets/TestnetsAPI.d.ts +108 -0
- package/dist/types/testnets/errors/TestnetNotFoundError.d.ts +12 -0
- package/dist/types/testnets/errors/TestnetRequestFailedError.d.ts +11 -0
- package/dist/types/testnets/errors/TestnetStatusError.d.ts +15 -0
- package/dist/types/testnets/errors/TestnetValidationError.d.ts +16 -0
- package/dist/types/testnets/errors/TestnetWaitTimeoutError.d.ts +21 -0
- package/dist/types/testnets/errors/TestnetsError.d.ts +47 -0
- package/dist/types/testnets/errors/index.d.ts +7 -0
- package/dist/types/testnets/index.d.ts +11 -0
- package/dist/types/testnets/schemas.d.ts +554 -0
- package/dist/types/testnets/types.d.ts +717 -0
- package/package.json +6 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ILogger } from "../onchain/types/logger.js";
|
|
2
|
+
import { CreateTestnetRequest, Testnet, TestnetFiles, TestnetStatus } from "./types.js";
|
|
3
|
+
//#region src/testnets/TestnetsAPI.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options of a {@link TestnetsAPI}.
|
|
6
|
+
**/
|
|
7
|
+
export interface TestnetsAPIOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Base URL of anvil-manager.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue `"https://anvil.gearbox.foundation"`
|
|
12
|
+
**/
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/**
|
|
15
|
+
* API key sent as a bearer token with every request. Without it the private
|
|
16
|
+
* routes (create, kill) answer 401, which surfaces as a
|
|
17
|
+
* {@link TestnetStatusError}.
|
|
18
|
+
**/
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Timeout of one request, in milliseconds.
|
|
22
|
+
*
|
|
23
|
+
* @defaultValue `30_000`
|
|
24
|
+
**/
|
|
25
|
+
timeout?: number;
|
|
26
|
+
logger?: ILogger;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options of {@link TestnetsAPI.waitUntilReady}.
|
|
30
|
+
**/
|
|
31
|
+
export interface WaitUntilReadyOptions {
|
|
32
|
+
/**
|
|
33
|
+
* How long to wait for the testnet to become ready, in milliseconds.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue `600_000` (10 minutes)
|
|
36
|
+
**/
|
|
37
|
+
timeout?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Pause between two status polls, in milliseconds.
|
|
40
|
+
*
|
|
41
|
+
* @defaultValue `5_000`
|
|
42
|
+
**/
|
|
43
|
+
interval?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Client for anvil-manager, which runs the anvil forks Gearbox calls
|
|
47
|
+
* testnets. It manages non-persistent testnets only, addressed by their
|
|
48
|
+
* execution id.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const testnets = new TestnetsAPI({ apiKey: process.env.ANVIL_MANAGER_API_KEY });
|
|
52
|
+
* const { executionId } = await testnets.create({ network: "Mainnet", timeout: "2h" });
|
|
53
|
+
* const status = await testnets.waitUntilReady(executionId);
|
|
54
|
+
* // ... use status.rpcUrl ...
|
|
55
|
+
* await testnets.kill(executionId);
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* Every method throws a {@link TestnetsError} subclass when it fails, except
|
|
59
|
+
* when a response body is not JSON: then it rejects with the error of
|
|
60
|
+
* `response.json()`.
|
|
61
|
+
**/
|
|
62
|
+
export declare class TestnetsAPI {
|
|
63
|
+
#private;
|
|
64
|
+
protected readonly logger?: ILogger;
|
|
65
|
+
constructor(options?: TestnetsAPIOptions);
|
|
66
|
+
/**
|
|
67
|
+
* Base URL every request of this client is sent to.
|
|
68
|
+
**/
|
|
69
|
+
get baseUrl(): string;
|
|
70
|
+
/**
|
|
71
|
+
* Every testnet anvil-manager knows of, persistent ones included.
|
|
72
|
+
**/
|
|
73
|
+
list(): Promise<Testnet[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Status of one testnet.
|
|
76
|
+
*
|
|
77
|
+
* @param id - Execution id of the testnet.
|
|
78
|
+
* @throws {@link TestnetNotFoundError} when there is no such testnet.
|
|
79
|
+
**/
|
|
80
|
+
get(id: string): Promise<TestnetStatus>;
|
|
81
|
+
/**
|
|
82
|
+
* Starts a testnet. It answers as soon as the testnet is created, long
|
|
83
|
+
* before it is {@link TestnetStatus.ready}.
|
|
84
|
+
*
|
|
85
|
+
* @param files - Saved in the testnet's shared dir, where scripts and tasks
|
|
86
|
+
* can read them.
|
|
87
|
+
**/
|
|
88
|
+
create(request: CreateTestnetRequest, files?: TestnetFiles): Promise<TestnetStatus>;
|
|
89
|
+
/**
|
|
90
|
+
* Stops a testnet. Stopping one that is already stopped succeeds.
|
|
91
|
+
*
|
|
92
|
+
* @param id - Execution id of the testnet.
|
|
93
|
+
* @throws {@link TestnetNotFoundError} when there is no such testnet.
|
|
94
|
+
* @throws {@link TestnetStatusError} with status 400 when the testnet is
|
|
95
|
+
* persistent.
|
|
96
|
+
**/
|
|
97
|
+
kill(id: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Polls a testnet's status until it is {@link TestnetStatus.ready}.
|
|
100
|
+
*
|
|
101
|
+
* @param id - Execution id of the testnet.
|
|
102
|
+
* @returns The first status that is ready.
|
|
103
|
+
* @throws {@link TestnetWaitTimeoutError} when the testnet is not ready in
|
|
104
|
+
* time. Any error of a poll is thrown as is, without retrying.
|
|
105
|
+
**/
|
|
106
|
+
waitUntilReady(id: string, options?: WaitUntilReadyOptions): Promise<TestnetStatus>;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TestnetStatusError } from "./TestnetStatusError.js";
|
|
2
|
+
//#region src/testnets/errors/TestnetNotFoundError.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when anvil-manager answered 404: there is no testnet with that
|
|
5
|
+
* execution id.
|
|
6
|
+
**/
|
|
7
|
+
export declare class TestnetNotFoundError extends TestnetStatusError {
|
|
8
|
+
name: string;
|
|
9
|
+
readonly status: 404;
|
|
10
|
+
constructor(url: string, details?: string);
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TestnetsError } from "./TestnetsError.js";
|
|
2
|
+
//#region src/testnets/errors/TestnetRequestFailedError.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when a request to anvil-manager never completed: the network was
|
|
5
|
+
* down, or it took longer than the client's timeout.
|
|
6
|
+
**/
|
|
7
|
+
export declare class TestnetRequestFailedError extends TestnetsError {
|
|
8
|
+
name: string;
|
|
9
|
+
constructor(url: string, cause: unknown);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TestnetsError } from "./TestnetsError.js";
|
|
2
|
+
//#region src/testnets/errors/TestnetStatusError.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when anvil-manager answered with a status outside the 2xx range. What
|
|
5
|
+
* it said about it, when it said anything, is the `details` of the error.
|
|
6
|
+
**/
|
|
7
|
+
export declare class TestnetStatusError extends TestnetsError {
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* Status anvil-manager answered with.
|
|
11
|
+
**/
|
|
12
|
+
readonly status: number;
|
|
13
|
+
constructor(url: string, status: number, details?: string);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TestnetsError } from "./TestnetsError.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
//#region src/testnets/errors/TestnetValidationError.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when anvil-manager answered, but with a payload the testnet schemas
|
|
6
|
+
* do not describe, i.e. the two are of different versions.
|
|
7
|
+
**/
|
|
8
|
+
export declare class TestnetValidationError extends TestnetsError {
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* The zod failure itself, e.g. for `z.treeifyError(error.zodError)`.
|
|
12
|
+
**/
|
|
13
|
+
readonly zodError: z.core.$ZodError;
|
|
14
|
+
constructor(url: string, zodError: z.core.$ZodError);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TestnetsError } from "./TestnetsError.js";
|
|
2
|
+
//#region src/testnets/errors/TestnetWaitTimeoutError.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when a testnet did not become ready before the wait for it ran out.
|
|
5
|
+
**/
|
|
6
|
+
export declare class TestnetWaitTimeoutError extends TestnetsError {
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* Execution id of the testnet that was waited for.
|
|
10
|
+
**/
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/**
|
|
13
|
+
* How long the wait lasted, in milliseconds.
|
|
14
|
+
**/
|
|
15
|
+
readonly timeout: number;
|
|
16
|
+
/**
|
|
17
|
+
* @param url - Status URL that was polled.
|
|
18
|
+
**/
|
|
19
|
+
constructor(url: string, id: string, timeout: number);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BaseError } from "viem";
|
|
2
|
+
//#region src/testnets/errors/TestnetsError.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* What every failure of a testnet API call names, see {@link TestnetsError}.
|
|
5
|
+
**/
|
|
6
|
+
export interface TestnetsErrorParams {
|
|
7
|
+
/**
|
|
8
|
+
* URL that was requested.
|
|
9
|
+
**/
|
|
10
|
+
url: string;
|
|
11
|
+
/**
|
|
12
|
+
* Status anvil-manager answered with, absent when the request never
|
|
13
|
+
* completed.
|
|
14
|
+
**/
|
|
15
|
+
status?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Value that was caught. An `Error` becomes the `cause`, anything else is
|
|
18
|
+
* stringified into the details.
|
|
19
|
+
**/
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
/**
|
|
22
|
+
* What anvil-manager itself said. Used only when there is no {@link cause},
|
|
23
|
+
* whose message viem reports instead.
|
|
24
|
+
**/
|
|
25
|
+
details?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Extra lines reported after the URL and status.
|
|
28
|
+
**/
|
|
29
|
+
metaMessages?: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Thrown by every testnet API call that fails. Its subclasses say how it
|
|
33
|
+
* failed; catch this one to catch all of them.
|
|
34
|
+
**/
|
|
35
|
+
export declare abstract class TestnetsError extends BaseError {
|
|
36
|
+
/**
|
|
37
|
+
* URL that was requested.
|
|
38
|
+
**/
|
|
39
|
+
readonly url: string;
|
|
40
|
+
/**
|
|
41
|
+
* Status anvil-manager answered with, absent when the request never
|
|
42
|
+
* completed.
|
|
43
|
+
**/
|
|
44
|
+
readonly status?: number;
|
|
45
|
+
protected constructor(summary: string, params: TestnetsErrorParams);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TestnetsError, TestnetsErrorParams } from "./TestnetsError.js";
|
|
2
|
+
import { TestnetStatusError } from "./TestnetStatusError.js";
|
|
3
|
+
import { TestnetNotFoundError } from "./TestnetNotFoundError.js";
|
|
4
|
+
import { TestnetRequestFailedError } from "./TestnetRequestFailedError.js";
|
|
5
|
+
import { TestnetValidationError } from "./TestnetValidationError.js";
|
|
6
|
+
import { TestnetWaitTimeoutError } from "./TestnetWaitTimeoutError.js";
|
|
7
|
+
export { TestnetNotFoundError, TestnetRequestFailedError, TestnetStatusError, TestnetValidationError, TestnetWaitTimeoutError, TestnetsError, TestnetsErrorParams };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CreateTestnetRequest, Testnet, TestnetBackendOptions, TestnetBackendState, TestnetBackendStatus, TestnetBlock, TestnetFiles, TestnetOptions, TestnetScript, TestnetScriptBlock, TestnetScriptOptions, TestnetScriptRequest, TestnetStageStatus, TestnetStatus, TestnetTask, TestnetTaskDefinition, TestnetTaskDefinitionRequest, TestnetTaskProgress } from "./types.js";
|
|
2
|
+
import { TestnetsAPI, TestnetsAPIOptions, WaitUntilReadyOptions } from "./TestnetsAPI.js";
|
|
3
|
+
import { TestnetsError, TestnetsErrorParams } from "./errors/TestnetsError.js";
|
|
4
|
+
import { TestnetStatusError } from "./errors/TestnetStatusError.js";
|
|
5
|
+
import { TestnetNotFoundError } from "./errors/TestnetNotFoundError.js";
|
|
6
|
+
import { TestnetRequestFailedError } from "./errors/TestnetRequestFailedError.js";
|
|
7
|
+
import { TestnetValidationError } from "./errors/TestnetValidationError.js";
|
|
8
|
+
import { TestnetWaitTimeoutError } from "./errors/TestnetWaitTimeoutError.js";
|
|
9
|
+
import "./errors/index.js";
|
|
10
|
+
import { testnetBackendOptionsSchema, testnetBackendStateSchema, testnetBackendStatusSchema, testnetBlockSchema, testnetOptionsSchema, testnetSchema, testnetScriptBlockSchema, testnetScriptOptionsSchema, testnetScriptSchema, testnetStageStatusSchema, testnetStatusSchema, testnetTaskDefinitionSchema, testnetTaskProgressSchema, testnetTaskSchema } from "./schemas.js";
|
|
11
|
+
export { CreateTestnetRequest, Testnet, TestnetBackendOptions, TestnetBackendState, TestnetBackendStatus, TestnetBlock, TestnetFiles, TestnetNotFoundError, TestnetOptions, TestnetRequestFailedError, TestnetScript, TestnetScriptBlock, TestnetScriptOptions, TestnetScriptRequest, TestnetStageStatus, TestnetStatus, TestnetStatusError, TestnetTask, TestnetTaskDefinition, TestnetTaskDefinitionRequest, TestnetTaskProgress, TestnetValidationError, TestnetWaitTimeoutError, TestnetsAPI, TestnetsAPIOptions, TestnetsError, TestnetsErrorParams, WaitUntilReadyOptions, testnetBackendOptionsSchema, testnetBackendStateSchema, testnetBackendStatusSchema, testnetBlockSchema, testnetOptionsSchema, testnetSchema, testnetScriptBlockSchema, testnetScriptOptionsSchema, testnetScriptSchema, testnetStageStatusSchema, testnetStatusSchema, testnetTaskDefinitionSchema, testnetTaskProgressSchema, testnetTaskSchema };
|