@gearbox-protocol/sdk 9.15.4 → 9.16.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.
|
@@ -89,8 +89,7 @@ class GearboxSDK {
|
|
|
89
89
|
gasLimit
|
|
90
90
|
} = options;
|
|
91
91
|
let { networkType, addressProvider, chainId } = options;
|
|
92
|
-
const transport = (0, import_chain.
|
|
93
|
-
const attachClient = (0, import_viem.createPublicClient)({ transport });
|
|
92
|
+
const [transport, attachClient] = (0, import_chain.createTransportClient)(options);
|
|
94
93
|
if (!networkType) {
|
|
95
94
|
networkType = await (0, import_chain.detectNetwork)(attachClient);
|
|
96
95
|
}
|
|
@@ -19,19 +19,30 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var Provider_exports = {};
|
|
20
20
|
__export(Provider_exports, {
|
|
21
21
|
Provider: () => Provider,
|
|
22
|
-
|
|
22
|
+
createTransportClient: () => createTransportClient
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(Provider_exports);
|
|
25
25
|
var import_viem = require("viem");
|
|
26
26
|
var import_AddressLabeller = require("../base/AddressLabeller.js");
|
|
27
27
|
var import_chains = require("./chains.js");
|
|
28
|
-
function
|
|
28
|
+
function createTransportClient(opts, chain) {
|
|
29
29
|
const { timeout = 12e4, retryCount } = opts;
|
|
30
|
+
let transport;
|
|
31
|
+
if ("client" in opts) {
|
|
32
|
+
transport = () => ({
|
|
33
|
+
config: opts.client.transport.config,
|
|
34
|
+
request: opts.client.transport.request,
|
|
35
|
+
value: opts.client.transport.value
|
|
36
|
+
});
|
|
37
|
+
return [transport, opts.client];
|
|
38
|
+
}
|
|
30
39
|
if ("transport" in opts) {
|
|
31
|
-
|
|
40
|
+
transport = opts.transport;
|
|
41
|
+
} else {
|
|
42
|
+
const rpcs = opts.rpcURLs.map((url) => (0, import_viem.http)(url, { timeout, retryCount }));
|
|
43
|
+
transport = rpcs.length > 1 ? (0, import_viem.fallback)(rpcs) : rpcs[0];
|
|
32
44
|
}
|
|
33
|
-
|
|
34
|
-
return rpcs.length > 1 ? (0, import_viem.fallback)(rpcs) : rpcs[0];
|
|
45
|
+
return [transport, (0, import_viem.createPublicClient)({ transport, chain })];
|
|
35
46
|
}
|
|
36
47
|
class Provider {
|
|
37
48
|
chainId;
|
|
@@ -48,11 +59,10 @@ class Provider {
|
|
|
48
59
|
...import_chains.chains[networkType],
|
|
49
60
|
id: chainId
|
|
50
61
|
});
|
|
51
|
-
this.#transport =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
62
|
+
[this.#transport, this.#publicClient] = createTransportClient(
|
|
63
|
+
opts,
|
|
64
|
+
this.chain
|
|
65
|
+
);
|
|
56
66
|
this.addressLabels = new import_AddressLabeller.AddressLabeller();
|
|
57
67
|
}
|
|
58
68
|
get transport() {
|
|
@@ -72,5 +82,5 @@ class Provider {
|
|
|
72
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
73
83
|
0 && (module.exports = {
|
|
74
84
|
Provider,
|
|
75
|
-
|
|
85
|
+
createTransportClient
|
|
76
86
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseEventLogs } from "viem";
|
|
2
2
|
import { TokensMeta } from "./base/index.js";
|
|
3
3
|
import {
|
|
4
4
|
chains,
|
|
5
|
-
|
|
5
|
+
createTransportClient,
|
|
6
6
|
detectNetwork,
|
|
7
7
|
Provider
|
|
8
8
|
} from "./chain/index.js";
|
|
@@ -87,8 +87,7 @@ class GearboxSDK {
|
|
|
87
87
|
gasLimit
|
|
88
88
|
} = options;
|
|
89
89
|
let { networkType, addressProvider, chainId } = options;
|
|
90
|
-
const transport =
|
|
91
|
-
const attachClient = createPublicClient({ transport });
|
|
90
|
+
const [transport, attachClient] = createTransportClient(options);
|
|
92
91
|
if (!networkType) {
|
|
93
92
|
networkType = await detectNetwork(attachClient);
|
|
94
93
|
}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { createPublicClient, defineChain, fallback, http } from "viem";
|
|
2
2
|
import { AddressLabeller } from "../base/AddressLabeller.js";
|
|
3
3
|
import { chains } from "./chains.js";
|
|
4
|
-
function
|
|
4
|
+
function createTransportClient(opts, chain) {
|
|
5
5
|
const { timeout = 12e4, retryCount } = opts;
|
|
6
|
+
let transport;
|
|
7
|
+
if ("client" in opts) {
|
|
8
|
+
transport = () => ({
|
|
9
|
+
config: opts.client.transport.config,
|
|
10
|
+
request: opts.client.transport.request,
|
|
11
|
+
value: opts.client.transport.value
|
|
12
|
+
});
|
|
13
|
+
return [transport, opts.client];
|
|
14
|
+
}
|
|
6
15
|
if ("transport" in opts) {
|
|
7
|
-
|
|
16
|
+
transport = opts.transport;
|
|
17
|
+
} else {
|
|
18
|
+
const rpcs = opts.rpcURLs.map((url) => http(url, { timeout, retryCount }));
|
|
19
|
+
transport = rpcs.length > 1 ? fallback(rpcs) : rpcs[0];
|
|
8
20
|
}
|
|
9
|
-
|
|
10
|
-
return rpcs.length > 1 ? fallback(rpcs) : rpcs[0];
|
|
21
|
+
return [transport, createPublicClient({ transport, chain })];
|
|
11
22
|
}
|
|
12
23
|
class Provider {
|
|
13
24
|
chainId;
|
|
@@ -24,11 +35,10 @@ class Provider {
|
|
|
24
35
|
...chains[networkType],
|
|
25
36
|
id: chainId
|
|
26
37
|
});
|
|
27
|
-
this.#transport =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
38
|
+
[this.#transport, this.#publicClient] = createTransportClient(
|
|
39
|
+
opts,
|
|
40
|
+
this.chain
|
|
41
|
+
);
|
|
32
42
|
this.addressLabels = new AddressLabeller();
|
|
33
43
|
}
|
|
34
44
|
get transport() {
|
|
@@ -47,5 +57,5 @@ class Provider {
|
|
|
47
57
|
}
|
|
48
58
|
export {
|
|
49
59
|
Provider,
|
|
50
|
-
|
|
60
|
+
createTransportClient
|
|
51
61
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PublicClient, Transport } from "viem";
|
|
1
|
+
import type { Chain, PublicClient, Transport } from "viem";
|
|
2
2
|
import type { IAddressLabeller } from "../base/IAddressLabeller.js";
|
|
3
3
|
import type { GearboxChain, NetworkType } from "./chains.js";
|
|
4
4
|
export interface NetworkOptions {
|
|
@@ -18,9 +18,14 @@ export type TransportOptions = {
|
|
|
18
18
|
rpcURLs: string[];
|
|
19
19
|
} | {
|
|
20
20
|
/**
|
|
21
|
-
* Alternatively, can pass
|
|
21
|
+
* Alternatively, can pass viem transport
|
|
22
22
|
*/
|
|
23
23
|
transport: Transport;
|
|
24
|
+
} | {
|
|
25
|
+
/**
|
|
26
|
+
* Alternatively, can pass entire viem client
|
|
27
|
+
*/
|
|
28
|
+
client: PublicClient;
|
|
24
29
|
};
|
|
25
30
|
export interface ConnectionOptions {
|
|
26
31
|
/**
|
|
@@ -32,7 +37,7 @@ export interface ConnectionOptions {
|
|
|
32
37
|
*/
|
|
33
38
|
retryCount?: number;
|
|
34
39
|
}
|
|
35
|
-
export declare function
|
|
40
|
+
export declare function createTransportClient(opts: TransportOptions & ConnectionOptions, chain?: Chain): [Transport, PublicClient];
|
|
36
41
|
export declare class Provider {
|
|
37
42
|
#private;
|
|
38
43
|
readonly chainId: number;
|