@gearbox-protocol/sdk 12.6.8 → 12.7.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.
@@ -22,10 +22,12 @@ __export(RevolverTransport_exports, {
22
22
  RevolverTransport: () => RevolverTransport,
23
23
  SelectionStrategy: () => SelectionStrategy,
24
24
  providerConfigSchema: () => providerConfigSchema,
25
+ revolverTransportConfigBaseSchema: () => revolverTransportConfigBaseSchema,
25
26
  revolverTransportConfigSchema: () => revolverTransportConfigSchema
26
27
  });
27
28
  module.exports = __toCommonJS(RevolverTransport_exports);
28
29
  var import_viem = require("viem");
30
+ var import_chains = require("viem/chains");
29
31
  var import_v4 = require("zod/v4");
30
32
  var import_transports = require("./transports.js");
31
33
  const providerConfigSchema = import_v4.z.object({
@@ -47,11 +49,7 @@ const providerConfigSchema = import_v4.z.object({
47
49
  httpTransportOptions: import_transports.httpTransportOptionsSchema.optional()
48
50
  });
49
51
  const SelectionStrategy = import_v4.z.enum(["simple", "ordered"]);
50
- const revolverTransportConfigSchema = import_v4.z.object({
51
- /**
52
- * Providers to use
53
- */
54
- providers: import_v4.z.array(providerConfigSchema),
52
+ const revolverTransportConfigBaseSchema = import_v4.z.object({
55
53
  /**
56
54
  * How to select the next transport
57
55
  * Defaults to "simple"
@@ -70,6 +68,24 @@ const revolverTransportConfigSchema = import_v4.z.object({
70
68
  */
71
69
  defaultCooldown: import_v4.z.number().optional()
72
70
  });
71
+ const revolverTransportConfigSchema = import_v4.z.union([
72
+ import_v4.z.object({
73
+ /**
74
+ * Pass http provider configs to use
75
+ */
76
+ providers: import_v4.z.array(providerConfigSchema),
77
+ ...revolverTransportConfigBaseSchema.shape
78
+ }),
79
+ import_v4.z.object({
80
+ /**
81
+ * Or pass transports directly
82
+ */
83
+ transports: import_v4.z.array(
84
+ import_v4.z.custom((v) => typeof v === "function")
85
+ ),
86
+ ...revolverTransportConfigBaseSchema.shape
87
+ })
88
+ ]);
73
89
  class NoAvailableTransportsError extends import_viem.BaseError {
74
90
  constructor(cause) {
75
91
  super("no available transports", { cause });
@@ -104,20 +120,31 @@ class RevolverTransport {
104
120
  ...config,
105
121
  shouldRetry: config.shouldRetry ?? defaultShouldRetry
106
122
  };
107
- const transports = config.providers.map(
108
- ({ url, name, cooldown, httpTransportOptions }) => ({
109
- name,
110
- transport: (0, import_viem.http)(url, {
111
- ...config.defaultHTTPOptions,
112
- ...httpTransportOptions,
113
- key: name,
123
+ let transports;
124
+ if ("providers" in config) {
125
+ transports = config.providers.map(
126
+ ({ url, name, cooldown, httpTransportOptions }) => ({
114
127
  name,
115
- onFetchRequest: this.#config.onRequest ? (...args) => this.#config.onRequest?.(name, ...args) : void 0,
116
- onFetchResponse: this.#config.onResponse ? (...args) => this.#config.onResponse?.(name, ...args) : void 0
117
- }),
118
- cooldown: cooldown ?? 0
119
- })
120
- );
128
+ transport: (0, import_viem.http)(url, {
129
+ ...config.defaultHTTPOptions,
130
+ ...httpTransportOptions,
131
+ key: name,
132
+ name,
133
+ onFetchRequest: this.#config.onRequest ? (...args) => this.#config.onRequest?.(name, ...args) : void 0,
134
+ onFetchResponse: this.#config.onResponse ? (...args) => this.#config.onResponse?.(name, ...args) : void 0
135
+ }),
136
+ cooldown: cooldown ?? 0
137
+ })
138
+ );
139
+ } else {
140
+ transports = config.transports.map(
141
+ (t, i) => ({
142
+ name: t({ chain: import_chains.mainnet }).config.name ?? `transport-${i}`,
143
+ transport: t,
144
+ cooldown: 0
145
+ })
146
+ );
147
+ }
121
148
  if (transports.length === 0) {
122
149
  throw new NoAvailableTransportsError();
123
150
  }
@@ -330,5 +357,6 @@ class OrderedTransportSelector extends AbstractTransportSelector {
330
357
  RevolverTransport,
331
358
  SelectionStrategy,
332
359
  providerConfigSchema,
360
+ revolverTransportConfigBaseSchema,
333
361
  revolverTransportConfigSchema
334
362
  });
@@ -10,6 +10,7 @@ import {
10
10
  RpcError,
11
11
  withRetry
12
12
  } from "viem";
13
+ import { mainnet } from "viem/chains";
13
14
  import { z } from "zod/v4";
14
15
  import { httpTransportOptionsSchema } from "./transports.js";
15
16
  const providerConfigSchema = z.object({
@@ -31,11 +32,7 @@ const providerConfigSchema = z.object({
31
32
  httpTransportOptions: httpTransportOptionsSchema.optional()
32
33
  });
33
34
  const SelectionStrategy = z.enum(["simple", "ordered"]);
34
- const revolverTransportConfigSchema = z.object({
35
- /**
36
- * Providers to use
37
- */
38
- providers: z.array(providerConfigSchema),
35
+ const revolverTransportConfigBaseSchema = z.object({
39
36
  /**
40
37
  * How to select the next transport
41
38
  * Defaults to "simple"
@@ -54,6 +51,24 @@ const revolverTransportConfigSchema = z.object({
54
51
  */
55
52
  defaultCooldown: z.number().optional()
56
53
  });
54
+ const revolverTransportConfigSchema = z.union([
55
+ z.object({
56
+ /**
57
+ * Pass http provider configs to use
58
+ */
59
+ providers: z.array(providerConfigSchema),
60
+ ...revolverTransportConfigBaseSchema.shape
61
+ }),
62
+ z.object({
63
+ /**
64
+ * Or pass transports directly
65
+ */
66
+ transports: z.array(
67
+ z.custom((v) => typeof v === "function")
68
+ ),
69
+ ...revolverTransportConfigBaseSchema.shape
70
+ })
71
+ ]);
57
72
  class NoAvailableTransportsError extends BaseError {
58
73
  constructor(cause) {
59
74
  super("no available transports", { cause });
@@ -88,20 +103,31 @@ class RevolverTransport {
88
103
  ...config,
89
104
  shouldRetry: config.shouldRetry ?? defaultShouldRetry
90
105
  };
91
- const transports = config.providers.map(
92
- ({ url, name, cooldown, httpTransportOptions }) => ({
93
- name,
94
- transport: http(url, {
95
- ...config.defaultHTTPOptions,
96
- ...httpTransportOptions,
97
- key: name,
106
+ let transports;
107
+ if ("providers" in config) {
108
+ transports = config.providers.map(
109
+ ({ url, name, cooldown, httpTransportOptions }) => ({
98
110
  name,
99
- onFetchRequest: this.#config.onRequest ? (...args) => this.#config.onRequest?.(name, ...args) : void 0,
100
- onFetchResponse: this.#config.onResponse ? (...args) => this.#config.onResponse?.(name, ...args) : void 0
101
- }),
102
- cooldown: cooldown ?? 0
103
- })
104
- );
111
+ transport: http(url, {
112
+ ...config.defaultHTTPOptions,
113
+ ...httpTransportOptions,
114
+ key: name,
115
+ name,
116
+ onFetchRequest: this.#config.onRequest ? (...args) => this.#config.onRequest?.(name, ...args) : void 0,
117
+ onFetchResponse: this.#config.onResponse ? (...args) => this.#config.onResponse?.(name, ...args) : void 0
118
+ }),
119
+ cooldown: cooldown ?? 0
120
+ })
121
+ );
122
+ } else {
123
+ transports = config.transports.map(
124
+ (t, i) => ({
125
+ name: t({ chain: mainnet }).config.name ?? `transport-${i}`,
126
+ transport: t,
127
+ cooldown: 0
128
+ })
129
+ );
130
+ }
105
131
  if (transports.length === 0) {
106
132
  throw new NoAvailableTransportsError();
107
133
  }
@@ -313,5 +339,6 @@ export {
313
339
  RevolverTransport,
314
340
  SelectionStrategy,
315
341
  providerConfigSchema,
342
+ revolverTransportConfigBaseSchema,
316
343
  revolverTransportConfigSchema
317
344
  };
@@ -1,7 +1,7 @@
1
1
  import { BaseError, type EIP1193RequestFn, type Transport, type TransportConfig } from "viem";
2
2
  import type { HttpRpcClientOptions } from "viem/utils";
3
3
  import { z } from "zod/v4";
4
- import { type ILogger } from "../sdk/index.js";
4
+ import type { ILogger } from "../sdk/index.js";
5
5
  export declare const providerConfigSchema: z.ZodObject<{
6
6
  name: z.ZodString;
7
7
  url: z.ZodURL;
@@ -39,7 +39,56 @@ export declare const SelectionStrategy: z.ZodEnum<{
39
39
  * - ordered: will select first available transport that is not in cooldown
40
40
  */
41
41
  export type SelectionStrategy = z.infer<typeof SelectionStrategy>;
42
- export declare const revolverTransportConfigSchema: z.ZodObject<{
42
+ /**
43
+ * Schema without underlying transport configs
44
+ */
45
+ export declare const revolverTransportConfigBaseSchema: z.ZodObject<{
46
+ selectionStrategy: z.ZodOptional<z.ZodEnum<{
47
+ simple: "simple";
48
+ ordered: "ordered";
49
+ }>>;
50
+ key: z.ZodOptional<z.ZodString>;
51
+ name: z.ZodOptional<z.ZodString>;
52
+ defaultHTTPOptions: z.ZodOptional<z.ZodObject<{
53
+ batch: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
54
+ batchSize: z.ZodOptional<z.ZodNumber>;
55
+ wait: z.ZodOptional<z.ZodNumber>;
56
+ }, z.core.$strip>]>>;
57
+ fetchOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
58
+ methods: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
59
+ include: z.ZodOptional<z.ZodArray<z.ZodString>>;
60
+ }, z.core.$strip>, z.ZodObject<{
61
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
62
+ }, z.core.$strip>]>>;
63
+ retryCount: z.ZodOptional<z.ZodNumber>;
64
+ retryDelay: z.ZodOptional<z.ZodNumber>;
65
+ timeout: z.ZodOptional<z.ZodNumber>;
66
+ }, z.core.$strip>>;
67
+ defaultCooldown: z.ZodOptional<z.ZodNumber>;
68
+ }, z.core.$strip>;
69
+ export declare const revolverTransportConfigSchema: z.ZodUnion<readonly [z.ZodObject<{
70
+ selectionStrategy: z.ZodOptional<z.ZodEnum<{
71
+ simple: "simple";
72
+ ordered: "ordered";
73
+ }>>;
74
+ key: z.ZodOptional<z.ZodString>;
75
+ name: z.ZodOptional<z.ZodString>;
76
+ defaultHTTPOptions: z.ZodOptional<z.ZodObject<{
77
+ batch: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
78
+ batchSize: z.ZodOptional<z.ZodNumber>;
79
+ wait: z.ZodOptional<z.ZodNumber>;
80
+ }, z.core.$strip>]>>;
81
+ fetchOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
82
+ methods: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
83
+ include: z.ZodOptional<z.ZodArray<z.ZodString>>;
84
+ }, z.core.$strip>, z.ZodObject<{
85
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
+ }, z.core.$strip>]>>;
87
+ retryCount: z.ZodOptional<z.ZodNumber>;
88
+ retryDelay: z.ZodOptional<z.ZodNumber>;
89
+ timeout: z.ZodOptional<z.ZodNumber>;
90
+ }, z.core.$strip>>;
91
+ defaultCooldown: z.ZodOptional<z.ZodNumber>;
43
92
  providers: z.ZodArray<z.ZodObject<{
44
93
  name: z.ZodString;
45
94
  url: z.ZodURL;
@@ -60,6 +109,7 @@ export declare const revolverTransportConfigSchema: z.ZodObject<{
60
109
  timeout: z.ZodOptional<z.ZodNumber>;
61
110
  }, z.core.$strip>>;
62
111
  }, z.core.$strip>>;
112
+ }, z.core.$strip>, z.ZodObject<{
63
113
  selectionStrategy: z.ZodOptional<z.ZodEnum<{
64
114
  simple: "simple";
65
115
  ordered: "ordered";
@@ -82,7 +132,8 @@ export declare const revolverTransportConfigSchema: z.ZodObject<{
82
132
  timeout: z.ZodOptional<z.ZodNumber>;
83
133
  }, z.core.$strip>>;
84
134
  defaultCooldown: z.ZodOptional<z.ZodNumber>;
85
- }, z.core.$strip>;
135
+ transports: z.ZodArray<z.ZodCustom<Transport, Transport>>;
136
+ }, z.core.$strip>]>;
86
137
  export type RevolverTransportConfig = {
87
138
  logger?: ILogger;
88
139
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.6.8",
3
+ "version": "12.7.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",