@gearbox-protocol/sdk 12.6.7 → 12.7.0

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.
@@ -26,6 +26,7 @@ __export(RevolverTransport_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(RevolverTransport_exports);
28
28
  var import_viem = require("viem");
29
+ var import_chains = require("viem/chains");
29
30
  var import_v4 = require("zod/v4");
30
31
  var import_transports = require("./transports.js");
31
32
  const providerConfigSchema = import_v4.z.object({
@@ -47,11 +48,7 @@ const providerConfigSchema = import_v4.z.object({
47
48
  httpTransportOptions: import_transports.httpTransportOptionsSchema.optional()
48
49
  });
49
50
  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),
51
+ const revolverTransportConfigBaseSchema = import_v4.z.object({
55
52
  /**
56
53
  * How to select the next transport
57
54
  * Defaults to "simple"
@@ -70,6 +67,24 @@ const revolverTransportConfigSchema = import_v4.z.object({
70
67
  */
71
68
  defaultCooldown: import_v4.z.number().optional()
72
69
  });
70
+ const revolverTransportConfigSchema = import_v4.z.union([
71
+ import_v4.z.object({
72
+ /**
73
+ * Pass http provider configs to use
74
+ */
75
+ providers: import_v4.z.array(providerConfigSchema),
76
+ ...revolverTransportConfigBaseSchema.shape
77
+ }),
78
+ import_v4.z.object({
79
+ /**
80
+ * Or pass transports directly
81
+ */
82
+ transports: import_v4.z.array(
83
+ import_v4.z.custom((v) => typeof v === "function")
84
+ ),
85
+ ...revolverTransportConfigBaseSchema.shape
86
+ })
87
+ ]);
73
88
  class NoAvailableTransportsError extends import_viem.BaseError {
74
89
  constructor(cause) {
75
90
  super("no available transports", { cause });
@@ -104,20 +119,31 @@ class RevolverTransport {
104
119
  ...config,
105
120
  shouldRetry: config.shouldRetry ?? defaultShouldRetry
106
121
  };
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,
122
+ let transports;
123
+ if ("providers" in config) {
124
+ transports = config.providers.map(
125
+ ({ url, name, cooldown, httpTransportOptions }) => ({
114
126
  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
- );
127
+ transport: (0, import_viem.http)(url, {
128
+ ...config.defaultHTTPOptions,
129
+ ...httpTransportOptions,
130
+ key: name,
131
+ name,
132
+ onFetchRequest: this.#config.onRequest ? (...args) => this.#config.onRequest?.(name, ...args) : void 0,
133
+ onFetchResponse: this.#config.onResponse ? (...args) => this.#config.onResponse?.(name, ...args) : void 0
134
+ }),
135
+ cooldown: cooldown ?? 0
136
+ })
137
+ );
138
+ } else {
139
+ transports = config.transports.map(
140
+ (t, i) => ({
141
+ name: t({ chain: import_chains.mainnet }).config.name ?? `transport-${i}`,
142
+ transport: t,
143
+ cooldown: 0
144
+ })
145
+ );
146
+ }
121
147
  if (transports.length === 0) {
122
148
  throw new NoAvailableTransportsError();
123
149
  }
@@ -74,6 +74,7 @@ class CreditSuite extends import_base.SDKConstruct {
74
74
  }
75
75
  stateHuman(raw = true) {
76
76
  return {
77
+ isExpired: this.isExpired,
77
78
  creditFacade: this.creditFacade.stateHuman(raw),
78
79
  creditManager: this.creditManager.stateHuman(raw),
79
80
  creditConfigurator: this.creditConfigurator.stateHuman(raw)
@@ -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
  }
@@ -41,6 +41,7 @@ class CreditSuite extends SDKConstruct {
41
41
  }
42
42
  stateHuman(raw = true) {
43
43
  return {
44
+ isExpired: this.isExpired,
44
45
  creditFacade: this.creditFacade.stateHuman(raw),
45
46
  creditManager: this.creditManager.stateHuman(raw),
46
47
  creditConfigurator: this.creditConfigurator.stateHuman(raw)
@@ -39,7 +39,29 @@ 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
+ export declare const revolverTransportConfigSchema: z.ZodUnion<readonly [z.ZodObject<{
43
+ selectionStrategy: z.ZodOptional<z.ZodEnum<{
44
+ simple: "simple";
45
+ ordered: "ordered";
46
+ }>>;
47
+ key: z.ZodOptional<z.ZodString>;
48
+ name: z.ZodOptional<z.ZodString>;
49
+ defaultHTTPOptions: z.ZodOptional<z.ZodObject<{
50
+ batch: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
51
+ batchSize: z.ZodOptional<z.ZodNumber>;
52
+ wait: z.ZodOptional<z.ZodNumber>;
53
+ }, z.core.$strip>]>>;
54
+ fetchOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
55
+ methods: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
56
+ include: z.ZodOptional<z.ZodArray<z.ZodString>>;
57
+ }, z.core.$strip>, z.ZodObject<{
58
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
59
+ }, z.core.$strip>]>>;
60
+ retryCount: z.ZodOptional<z.ZodNumber>;
61
+ retryDelay: z.ZodOptional<z.ZodNumber>;
62
+ timeout: z.ZodOptional<z.ZodNumber>;
63
+ }, z.core.$strip>>;
64
+ defaultCooldown: z.ZodOptional<z.ZodNumber>;
43
65
  providers: z.ZodArray<z.ZodObject<{
44
66
  name: z.ZodString;
45
67
  url: z.ZodURL;
@@ -60,6 +82,7 @@ export declare const revolverTransportConfigSchema: z.ZodObject<{
60
82
  timeout: z.ZodOptional<z.ZodNumber>;
61
83
  }, z.core.$strip>>;
62
84
  }, z.core.$strip>>;
85
+ }, z.core.$strip>, z.ZodObject<{
63
86
  selectionStrategy: z.ZodOptional<z.ZodEnum<{
64
87
  simple: "simple";
65
88
  ordered: "ordered";
@@ -82,7 +105,8 @@ export declare const revolverTransportConfigSchema: z.ZodObject<{
82
105
  timeout: z.ZodOptional<z.ZodNumber>;
83
106
  }, z.core.$strip>>;
84
107
  defaultCooldown: z.ZodOptional<z.ZodNumber>;
85
- }, z.core.$strip>;
108
+ transports: z.ZodArray<z.ZodCustom<Transport, Transport>>;
109
+ }, z.core.$strip>]>;
86
110
  export type RevolverTransportConfig = {
87
111
  logger?: ILogger;
88
112
  /**
@@ -100,6 +100,7 @@ export interface CreditManagerStateHuman extends BaseContractStateHuman {
100
100
  }
101
101
  export type CreditConfiguratorStateHuman = BaseContractStateHuman;
102
102
  export interface CreditSuiteStateHuman {
103
+ isExpired: boolean;
103
104
  creditFacade: CreditFacadeStateHuman;
104
105
  creditManager: CreditManagerStateHuman;
105
106
  creditConfigurator: CreditConfiguratorStateHuman;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.6.7",
3
+ "version": "12.7.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",