@gearbox-protocol/sdk 9.1.7 → 9.1.9
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.
|
@@ -91,7 +91,7 @@ class RevolverTransport {
|
|
|
91
91
|
get value() {
|
|
92
92
|
return {
|
|
93
93
|
rotate: (reason) => this.rotate(reason),
|
|
94
|
-
currentTransportName: this.currentTransportName
|
|
94
|
+
currentTransportName: () => this.currentTransportName()
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
request = async (r) => {
|
|
@@ -100,17 +100,19 @@ class RevolverTransport {
|
|
|
100
100
|
}
|
|
101
101
|
do {
|
|
102
102
|
try {
|
|
103
|
-
this.#requests.set(r, this.currentTransportName);
|
|
103
|
+
this.#requests.set(r, this.currentTransportName());
|
|
104
104
|
const resp = await this.#transport({ ...this.overrides }).request(r);
|
|
105
105
|
this.#requests.delete(r);
|
|
106
106
|
return resp;
|
|
107
107
|
} catch (e) {
|
|
108
108
|
if (e instanceof import_viem.RpcError || e instanceof import_viem.HttpRequestError) {
|
|
109
109
|
const reqTransport = this.#requests.get(r);
|
|
110
|
-
if (reqTransport === this.currentTransportName) {
|
|
110
|
+
if (reqTransport === this.currentTransportName()) {
|
|
111
111
|
await this.rotate(e);
|
|
112
112
|
} else {
|
|
113
|
-
this.#logger?.debug(
|
|
113
|
+
this.#logger?.debug(
|
|
114
|
+
`request made with old transport ${reqTransport}, trying again`
|
|
115
|
+
);
|
|
114
116
|
}
|
|
115
117
|
} else {
|
|
116
118
|
this.#requests.delete(r);
|
|
@@ -156,7 +158,7 @@ class RevolverTransport {
|
|
|
156
158
|
},
|
|
157
159
|
"rotating transport"
|
|
158
160
|
);
|
|
159
|
-
const oldTransportName = this.currentTransportName;
|
|
161
|
+
const oldTransportName = this.currentTransportName();
|
|
160
162
|
const now = Date.now();
|
|
161
163
|
this.#transports[this.#index].cooldown = now + (this.#config.cooldown ?? 6e4);
|
|
162
164
|
for (let i = 0; i < this.#transports.length - 1; i++) {
|
|
@@ -173,7 +175,7 @@ class RevolverTransport {
|
|
|
173
175
|
try {
|
|
174
176
|
await this.#config.onRotateSuccess?.(
|
|
175
177
|
oldTransportName,
|
|
176
|
-
this.currentTransportName,
|
|
178
|
+
this.currentTransportName(),
|
|
177
179
|
reason
|
|
178
180
|
);
|
|
179
181
|
} catch {
|
|
@@ -198,7 +200,7 @@ class RevolverTransport {
|
|
|
198
200
|
this.#rotating = false;
|
|
199
201
|
return false;
|
|
200
202
|
}
|
|
201
|
-
|
|
203
|
+
currentTransportName() {
|
|
202
204
|
return this.#transport({}).config.name;
|
|
203
205
|
}
|
|
204
206
|
get #logger() {
|
|
@@ -74,7 +74,7 @@ class RevolverTransport {
|
|
|
74
74
|
get value() {
|
|
75
75
|
return {
|
|
76
76
|
rotate: (reason) => this.rotate(reason),
|
|
77
|
-
currentTransportName: this.currentTransportName
|
|
77
|
+
currentTransportName: () => this.currentTransportName()
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
request = async (r) => {
|
|
@@ -83,17 +83,19 @@ class RevolverTransport {
|
|
|
83
83
|
}
|
|
84
84
|
do {
|
|
85
85
|
try {
|
|
86
|
-
this.#requests.set(r, this.currentTransportName);
|
|
86
|
+
this.#requests.set(r, this.currentTransportName());
|
|
87
87
|
const resp = await this.#transport({ ...this.overrides }).request(r);
|
|
88
88
|
this.#requests.delete(r);
|
|
89
89
|
return resp;
|
|
90
90
|
} catch (e) {
|
|
91
91
|
if (e instanceof RpcError || e instanceof HttpRequestError) {
|
|
92
92
|
const reqTransport = this.#requests.get(r);
|
|
93
|
-
if (reqTransport === this.currentTransportName) {
|
|
93
|
+
if (reqTransport === this.currentTransportName()) {
|
|
94
94
|
await this.rotate(e);
|
|
95
95
|
} else {
|
|
96
|
-
this.#logger?.debug(
|
|
96
|
+
this.#logger?.debug(
|
|
97
|
+
`request made with old transport ${reqTransport}, trying again`
|
|
98
|
+
);
|
|
97
99
|
}
|
|
98
100
|
} else {
|
|
99
101
|
this.#requests.delete(r);
|
|
@@ -139,7 +141,7 @@ class RevolverTransport {
|
|
|
139
141
|
},
|
|
140
142
|
"rotating transport"
|
|
141
143
|
);
|
|
142
|
-
const oldTransportName = this.currentTransportName;
|
|
144
|
+
const oldTransportName = this.currentTransportName();
|
|
143
145
|
const now = Date.now();
|
|
144
146
|
this.#transports[this.#index].cooldown = now + (this.#config.cooldown ?? 6e4);
|
|
145
147
|
for (let i = 0; i < this.#transports.length - 1; i++) {
|
|
@@ -156,7 +158,7 @@ class RevolverTransport {
|
|
|
156
158
|
try {
|
|
157
159
|
await this.#config.onRotateSuccess?.(
|
|
158
160
|
oldTransportName,
|
|
159
|
-
this.currentTransportName,
|
|
161
|
+
this.currentTransportName(),
|
|
160
162
|
reason
|
|
161
163
|
);
|
|
162
164
|
} catch {
|
|
@@ -181,7 +183,7 @@ class RevolverTransport {
|
|
|
181
183
|
this.#rotating = false;
|
|
182
184
|
return false;
|
|
183
185
|
}
|
|
184
|
-
|
|
186
|
+
currentTransportName() {
|
|
185
187
|
return this.#transport({}).config.name;
|
|
186
188
|
}
|
|
187
189
|
get #logger() {
|
|
@@ -50,9 +50,9 @@ export interface RevolverTransportValue {
|
|
|
50
50
|
*/
|
|
51
51
|
rotate: (reason?: BaseError) => Promise<boolean>;
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Returns the name of the current transport
|
|
54
54
|
*/
|
|
55
|
-
currentTransportName: string;
|
|
55
|
+
currentTransportName: () => string;
|
|
56
56
|
}
|
|
57
57
|
export declare class RevolverTransport implements ReturnType<Transport<"revolver", RevolverTransportValue>> {
|
|
58
58
|
#private;
|
|
@@ -76,6 +76,6 @@ export declare class RevolverTransport implements ReturnType<Transport<"revolver
|
|
|
76
76
|
* @returns true if rotation was successful
|
|
77
77
|
*/
|
|
78
78
|
rotate(reason?: BaseError): Promise<boolean>;
|
|
79
|
-
|
|
79
|
+
currentTransportName(): string;
|
|
80
80
|
}
|
|
81
81
|
export {};
|