@gearbox-protocol/sdk 3.0.0-vfour.325 → 3.0.0-vfour.326

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.
@@ -101,13 +101,13 @@ class GearboxSDK {
101
101
  if (!addressProvider) {
102
102
  addressProvider = import_constants.ADDRESS_PROVIDER_V310;
103
103
  }
104
- const marketConfigurators = mcs ?? (0, import_constants.getDefaultMarketConfigurators)(networkType);
104
+ const marketConfigurators = mcs ?? import_utils.TypedObjectUtils.keys(import_chain.chains[networkType].defaultMarketConfigurators);
105
105
  const provider = new import_chain.Provider({
106
106
  ...options,
107
107
  chainId,
108
108
  networkType
109
109
  });
110
- logger?.debug(
110
+ logger?.info(
111
111
  { networkType, chainId, addressProvider, marketConfigurators },
112
112
  "attaching gearbox sdk"
113
113
  );
@@ -161,13 +161,12 @@ class GearboxSDK {
161
161
  if (redstoneGateways?.length) {
162
162
  this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
163
163
  }
164
- this.logger?.info(
164
+ this.logger?.debug(
165
165
  {
166
- addressProvider,
167
- blockNumber: block.number,
166
+ number: block.number,
168
167
  timestamp: block.timestamp
169
168
  },
170
- "attaching"
169
+ "attach block"
171
170
  );
172
171
  this.#addressProvider = await (0, import_core.createAddressProvider)(this, addressProvider);
173
172
  this.logger?.debug(
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var chains_exports = {};
20
20
  __export(chains_exports, {
21
21
  NetworkType: () => NetworkType,
22
- PUBLIC_NETWORKS: () => PUBLIC_NETWORKS,
23
22
  SUPPORTED_NETWORKS: () => SUPPORTED_NETWORKS,
24
23
  chains: () => chains,
25
24
  getChain: () => getChain,
@@ -31,6 +30,7 @@ module.exports = __toCommonJS(chains_exports);
31
30
  var import_viem = require("viem");
32
31
  var import_chains = require("viem/chains");
33
32
  var import_zod = require("zod");
33
+ var import_utils = require("../utils/index.js");
34
34
  const SUPPORTED_NETWORKS = [
35
35
  "Mainnet",
36
36
  "Arbitrum",
@@ -39,10 +39,6 @@ const SUPPORTED_NETWORKS = [
39
39
  "Sonic"
40
40
  ];
41
41
  const NetworkType = import_zod.z.enum(SUPPORTED_NETWORKS);
42
- const PUBLIC_NETWORKS = SUPPORTED_NETWORKS;
43
- function isPublicNetwork(network) {
44
- return PUBLIC_NETWORKS.includes(network);
45
- }
46
42
  function withPublicNode(chain, subdomain) {
47
43
  return (0, import_viem.defineChain)({
48
44
  ...chain,
@@ -56,13 +52,56 @@ function withPublicNode(chain, subdomain) {
56
52
  });
57
53
  }
58
54
  const chains = {
59
- Mainnet: withPublicNode(import_chains.mainnet, "ethereum-rpc"),
60
- Arbitrum: withPublicNode(import_chains.arbitrum, "arbitrum-one-rpc"),
61
- Optimism: withPublicNode(import_chains.optimism, "optimism-rpc"),
62
- Base: withPublicNode(import_chains.base, "base-rpc"),
55
+ Mainnet: withPublicNode(
56
+ {
57
+ ...import_chains.mainnet,
58
+ network: "Mainnet",
59
+ defaultMarketConfigurators: {
60
+ "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
61
+ },
62
+ isPublic: true
63
+ },
64
+ "ethereum-rpc"
65
+ ),
66
+ Arbitrum: withPublicNode(
67
+ {
68
+ ...import_chains.arbitrum,
69
+ network: "Arbitrum",
70
+ defaultMarketConfigurators: {
71
+ "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
72
+ },
73
+ isPublic: true
74
+ },
75
+ "arbitrum-one-rpc"
76
+ ),
77
+ Optimism: withPublicNode(
78
+ {
79
+ ...import_chains.optimism,
80
+ network: "Optimism",
81
+ defaultMarketConfigurators: {
82
+ "0x2a15969CE5320868eb609680751cF8896DD92De5": "Chaos Labs"
83
+ },
84
+ isPublic: true
85
+ },
86
+ "optimism-rpc"
87
+ ),
88
+ Base: withPublicNode(
89
+ {
90
+ ...import_chains.base,
91
+ network: "Base",
92
+ defaultMarketConfigurators: {},
93
+ isPublic: true
94
+ },
95
+ "base-rpc"
96
+ ),
63
97
  Sonic: withPublicNode(
64
98
  (0, import_viem.defineChain)({
65
99
  ...import_chains.sonic,
100
+ network: "Sonic",
101
+ defaultMarketConfigurators: {
102
+ "0x8FFDd1F1433674516f83645a768E8900A2A5D076": "Chaos Labs"
103
+ },
104
+ isPublic: true,
66
105
  blockExplorers: {
67
106
  default: {
68
107
  name: "Sonic Explorer",
@@ -74,13 +113,6 @@ const chains = {
74
113
  "sonic-rpc"
75
114
  )
76
115
  };
77
- const CHAINS_BY_ID = {
78
- [import_chains.mainnet.id]: "Mainnet",
79
- [import_chains.arbitrum.id]: "Arbitrum",
80
- [import_chains.optimism.id]: "Optimism",
81
- [import_chains.base.id]: "Base",
82
- [import_chains.sonic.id]: "Sonic"
83
- };
84
116
  function getChain(chainIdOrNetworkType) {
85
117
  const network = typeof chainIdOrNetworkType === "string" ? chainIdOrNetworkType : getNetworkType(Number(chainIdOrNetworkType));
86
118
  const chain = chains[network];
@@ -90,19 +122,27 @@ function getChain(chainIdOrNetworkType) {
90
122
  return chain;
91
123
  }
92
124
  function getNetworkType(chainId) {
93
- const chainType = CHAINS_BY_ID[chainId];
94
- if (chainType) {
95
- return chainType;
125
+ for (const [network, chain] of import_utils.TypedObjectUtils.entries(chains)) {
126
+ if (chain.id === Number(chainId)) {
127
+ return network;
128
+ }
96
129
  }
97
- throw new Error("Unsupported network");
130
+ throw new Error(`Unsupported network with chainId ${chainId}`);
98
131
  }
99
132
  function isSupportedNetwork(chainId) {
100
- return chainId !== void 0 && !!CHAINS_BY_ID[chainId];
133
+ return Object.values(chains).some((c) => c.id === chainId);
134
+ }
135
+ function isPublicNetwork(networkOrChainId) {
136
+ return Object.values(chains).some((c) => {
137
+ if (typeof networkOrChainId === "string") {
138
+ return c.network === networkOrChainId && c.isPublic;
139
+ }
140
+ return c.id === Number(networkOrChainId) && c.isPublic;
141
+ });
101
142
  }
102
143
  // Annotate the CommonJS export names for ESM import in node:
103
144
  0 && (module.exports = {
104
145
  NetworkType,
105
- PUBLIC_NETWORKS,
106
146
  SUPPORTED_NETWORKS,
107
147
  chains,
108
148
  getChain,
@@ -18,7 +18,6 @@ module.exports = __toCommonJS(constants_exports);
18
18
  __reExport(constants_exports, require("./address-provider.js"), module.exports);
19
19
  __reExport(constants_exports, require("./addresses.js"), module.exports);
20
20
  __reExport(constants_exports, require("./bot-permissions.js"), module.exports);
21
- __reExport(constants_exports, require("./market-configurators.js"), module.exports);
22
21
  __reExport(constants_exports, require("./math.js"), module.exports);
23
22
  __reExport(constants_exports, require("./networks.js"), module.exports);
24
23
  __reExport(constants_exports, require("./periphery.js"), module.exports);
@@ -27,7 +26,6 @@ __reExport(constants_exports, require("./periphery.js"), module.exports);
27
26
  ...require("./address-provider.js"),
28
27
  ...require("./addresses.js"),
29
28
  ...require("./bot-permissions.js"),
30
- ...require("./market-configurators.js"),
31
29
  ...require("./math.js"),
32
30
  ...require("./networks.js"),
33
31
  ...require("./periphery.js")
@@ -40,9 +40,6 @@ function createAdapter(sdk, args) {
40
40
  );
41
41
  }
42
42
  }
43
- sdk.logger?.warn(
44
- `no class found for ${adapterType} v${args.baseParams.version}, falling back to placeholder`
45
- );
46
43
  return new import_PlaceholderAdapterContracts.PlaceholderAdapterContract(sdk, args);
47
44
  }
48
45
  // Annotate the CommonJS export names for ESM import in node:
@@ -119,7 +119,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
119
119
  const redstonePFs = [];
120
120
  const latestUpdate = {
121
121
  redstone: [],
122
- timestamp: Date.now()
122
+ timestamp: Math.floor(Date.now() / 1e3)
123
123
  };
124
124
  for (const pf of updateables) {
125
125
  if ((0, import_RedstonePriceFeed.isRedstone)(pf)) {
@@ -1,12 +1,11 @@
1
1
  import { createPublicClient, parseEventLogs } from "viem";
2
2
  import { TokensMeta } from "./base/index.js";
3
- import { createTransport, Provider } from "./chain/index.js";
3
+ import { chains, createTransport, Provider } from "./chain/index.js";
4
4
  import {
5
5
  ADDRESS_PROVIDER_V310,
6
6
  AP_BOT_LIST,
7
7
  AP_GEAR_STAKING,
8
8
  AP_GEAR_TOKEN,
9
- getDefaultMarketConfigurators,
10
9
  NO_VERSION
11
10
  } from "./constants/index.js";
12
11
  import {
@@ -91,13 +90,13 @@ class GearboxSDK {
91
90
  if (!addressProvider) {
92
91
  addressProvider = ADDRESS_PROVIDER_V310;
93
92
  }
94
- const marketConfigurators = mcs ?? getDefaultMarketConfigurators(networkType);
93
+ const marketConfigurators = mcs ?? TypedObjectUtils.keys(chains[networkType].defaultMarketConfigurators);
95
94
  const provider = new Provider({
96
95
  ...options,
97
96
  chainId,
98
97
  networkType
99
98
  });
100
- logger?.debug(
99
+ logger?.info(
101
100
  { networkType, chainId, addressProvider, marketConfigurators },
102
101
  "attaching gearbox sdk"
103
102
  );
@@ -151,13 +150,12 @@ class GearboxSDK {
151
150
  if (redstoneGateways?.length) {
152
151
  this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
153
152
  }
154
- this.logger?.info(
153
+ this.logger?.debug(
155
154
  {
156
- addressProvider,
157
- blockNumber: block.number,
155
+ number: block.number,
158
156
  timestamp: block.timestamp
159
157
  },
160
- "attaching"
158
+ "attach block"
161
159
  );
162
160
  this.#addressProvider = await createAddressProvider(this, addressProvider);
163
161
  this.logger?.debug(
@@ -1,6 +1,7 @@
1
1
  import { defineChain } from "viem";
2
2
  import { arbitrum, base, mainnet, optimism, sonic } from "viem/chains";
3
3
  import { z } from "zod";
4
+ import { TypedObjectUtils } from "../utils/index.js";
4
5
  const SUPPORTED_NETWORKS = [
5
6
  "Mainnet",
6
7
  "Arbitrum",
@@ -9,10 +10,6 @@ const SUPPORTED_NETWORKS = [
9
10
  "Sonic"
10
11
  ];
11
12
  const NetworkType = z.enum(SUPPORTED_NETWORKS);
12
- const PUBLIC_NETWORKS = SUPPORTED_NETWORKS;
13
- function isPublicNetwork(network) {
14
- return PUBLIC_NETWORKS.includes(network);
15
- }
16
13
  function withPublicNode(chain, subdomain) {
17
14
  return defineChain({
18
15
  ...chain,
@@ -26,13 +23,56 @@ function withPublicNode(chain, subdomain) {
26
23
  });
27
24
  }
28
25
  const chains = {
29
- Mainnet: withPublicNode(mainnet, "ethereum-rpc"),
30
- Arbitrum: withPublicNode(arbitrum, "arbitrum-one-rpc"),
31
- Optimism: withPublicNode(optimism, "optimism-rpc"),
32
- Base: withPublicNode(base, "base-rpc"),
26
+ Mainnet: withPublicNode(
27
+ {
28
+ ...mainnet,
29
+ network: "Mainnet",
30
+ defaultMarketConfigurators: {
31
+ "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
32
+ },
33
+ isPublic: true
34
+ },
35
+ "ethereum-rpc"
36
+ ),
37
+ Arbitrum: withPublicNode(
38
+ {
39
+ ...arbitrum,
40
+ network: "Arbitrum",
41
+ defaultMarketConfigurators: {
42
+ "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
43
+ },
44
+ isPublic: true
45
+ },
46
+ "arbitrum-one-rpc"
47
+ ),
48
+ Optimism: withPublicNode(
49
+ {
50
+ ...optimism,
51
+ network: "Optimism",
52
+ defaultMarketConfigurators: {
53
+ "0x2a15969CE5320868eb609680751cF8896DD92De5": "Chaos Labs"
54
+ },
55
+ isPublic: true
56
+ },
57
+ "optimism-rpc"
58
+ ),
59
+ Base: withPublicNode(
60
+ {
61
+ ...base,
62
+ network: "Base",
63
+ defaultMarketConfigurators: {},
64
+ isPublic: true
65
+ },
66
+ "base-rpc"
67
+ ),
33
68
  Sonic: withPublicNode(
34
69
  defineChain({
35
70
  ...sonic,
71
+ network: "Sonic",
72
+ defaultMarketConfigurators: {
73
+ "0x8FFDd1F1433674516f83645a768E8900A2A5D076": "Chaos Labs"
74
+ },
75
+ isPublic: true,
36
76
  blockExplorers: {
37
77
  default: {
38
78
  name: "Sonic Explorer",
@@ -44,13 +84,6 @@ const chains = {
44
84
  "sonic-rpc"
45
85
  )
46
86
  };
47
- const CHAINS_BY_ID = {
48
- [mainnet.id]: "Mainnet",
49
- [arbitrum.id]: "Arbitrum",
50
- [optimism.id]: "Optimism",
51
- [base.id]: "Base",
52
- [sonic.id]: "Sonic"
53
- };
54
87
  function getChain(chainIdOrNetworkType) {
55
88
  const network = typeof chainIdOrNetworkType === "string" ? chainIdOrNetworkType : getNetworkType(Number(chainIdOrNetworkType));
56
89
  const chain = chains[network];
@@ -60,18 +93,26 @@ function getChain(chainIdOrNetworkType) {
60
93
  return chain;
61
94
  }
62
95
  function getNetworkType(chainId) {
63
- const chainType = CHAINS_BY_ID[chainId];
64
- if (chainType) {
65
- return chainType;
96
+ for (const [network, chain] of TypedObjectUtils.entries(chains)) {
97
+ if (chain.id === Number(chainId)) {
98
+ return network;
99
+ }
66
100
  }
67
- throw new Error("Unsupported network");
101
+ throw new Error(`Unsupported network with chainId ${chainId}`);
68
102
  }
69
103
  function isSupportedNetwork(chainId) {
70
- return chainId !== void 0 && !!CHAINS_BY_ID[chainId];
104
+ return Object.values(chains).some((c) => c.id === chainId);
105
+ }
106
+ function isPublicNetwork(networkOrChainId) {
107
+ return Object.values(chains).some((c) => {
108
+ if (typeof networkOrChainId === "string") {
109
+ return c.network === networkOrChainId && c.isPublic;
110
+ }
111
+ return c.id === Number(networkOrChainId) && c.isPublic;
112
+ });
71
113
  }
72
114
  export {
73
115
  NetworkType,
74
- PUBLIC_NETWORKS,
75
116
  SUPPORTED_NETWORKS,
76
117
  chains,
77
118
  getChain,
@@ -1,7 +1,6 @@
1
1
  export * from "./address-provider.js";
2
2
  export * from "./addresses.js";
3
3
  export * from "./bot-permissions.js";
4
- export * from "./market-configurators.js";
5
4
  export * from "./math.js";
6
5
  export * from "./networks.js";
7
6
  export * from "./periphery.js";
@@ -17,9 +17,6 @@ function createAdapter(sdk, args) {
17
17
  );
18
18
  }
19
19
  }
20
- sdk.logger?.warn(
21
- `no class found for ${adapterType} v${args.baseParams.version}, falling back to placeholder`
22
- );
23
20
  return new PlaceholderAdapterContract(sdk, args);
24
21
  }
25
22
  export {
@@ -98,7 +98,7 @@ class PriceFeedRegister extends SDKConstruct {
98
98
  const redstonePFs = [];
99
99
  const latestUpdate = {
100
100
  redstone: [],
101
- timestamp: Date.now()
101
+ timestamp: Math.floor(Date.now() / 1e3)
102
102
  };
103
103
  for (const pf of updateables) {
104
104
  if (isRedstone(pf)) {
@@ -1,11 +1,15 @@
1
- import { type Chain } from "viem";
1
+ import type { Address, Chain } from "viem";
2
2
  import { z } from "zod";
3
+ export interface GearboxChain extends Chain {
4
+ network: NetworkType;
5
+ defaultMarketConfigurators: Record<Address, string>;
6
+ isPublic: boolean;
7
+ }
3
8
  export declare const SUPPORTED_NETWORKS: readonly ["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic"];
4
9
  export declare const NetworkType: z.ZodEnum<["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic"]>;
5
10
  export type NetworkType = z.infer<typeof NetworkType>;
6
- export declare const PUBLIC_NETWORKS: readonly NetworkType[];
7
- export declare function isPublicNetwork(network: NetworkType): boolean;
8
- export declare const chains: Record<NetworkType, Chain>;
9
- export declare function getChain(chainIdOrNetworkType: number | bigint | NetworkType): Chain;
10
- export declare function getNetworkType(chainId: number): NetworkType;
11
+ export declare const chains: Record<NetworkType, GearboxChain>;
12
+ export declare function getChain(chainIdOrNetworkType: number | bigint | NetworkType): GearboxChain;
13
+ export declare function getNetworkType(chainId: number | bigint): NetworkType;
11
14
  export declare function isSupportedNetwork(chainId: number | undefined): chainId is number;
15
+ export declare function isPublicNetwork(networkOrChainId: NetworkType | number | bigint): boolean;
@@ -1,7 +1,6 @@
1
1
  export * from "./address-provider.js";
2
2
  export * from "./addresses.js";
3
3
  export * from "./bot-permissions.js";
4
- export * from "./market-configurators.js";
5
4
  export * from "./math.js";
6
5
  export * from "./networks.js";
7
6
  export * from "./periphery.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.325",
3
+ "version": "3.0.0-vfour.326",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var market_configurators_exports = {};
20
- __export(market_configurators_exports, {
21
- DEFAULT_MARKET_CONFIGURATORS: () => DEFAULT_MARKET_CONFIGURATORS,
22
- getDefaultMarketConfigurators: () => getDefaultMarketConfigurators
23
- });
24
- module.exports = __toCommonJS(market_configurators_exports);
25
- var import_viem = require("viem");
26
- const DEFAULT_MARKET_CONFIGURATORS = {
27
- Mainnet: {
28
- "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
29
- },
30
- Arbitrum: {
31
- "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
32
- },
33
- Optimism: {
34
- "0x2a15969CE5320868eb609680751cF8896DD92De5": "Chaos Labs"
35
- },
36
- Base: {},
37
- Sonic: { "0x8FFDd1F1433674516f83645a768E8900A2A5D076": "Chaos Labs" }
38
- };
39
- function getDefaultMarketConfigurators(network) {
40
- return Object.keys(DEFAULT_MARKET_CONFIGURATORS[network]).map(
41
- (a) => (0, import_viem.getAddress)(a)
42
- );
43
- }
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {
46
- DEFAULT_MARKET_CONFIGURATORS,
47
- getDefaultMarketConfigurators
48
- });
@@ -1,23 +0,0 @@
1
- import { getAddress } from "viem";
2
- const DEFAULT_MARKET_CONFIGURATORS = {
3
- Mainnet: {
4
- "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
5
- },
6
- Arbitrum: {
7
- "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
8
- },
9
- Optimism: {
10
- "0x2a15969CE5320868eb609680751cF8896DD92De5": "Chaos Labs"
11
- },
12
- Base: {},
13
- Sonic: { "0x8FFDd1F1433674516f83645a768E8900A2A5D076": "Chaos Labs" }
14
- };
15
- function getDefaultMarketConfigurators(network) {
16
- return Object.keys(DEFAULT_MARKET_CONFIGURATORS[network]).map(
17
- (a) => getAddress(a)
18
- );
19
- }
20
- export {
21
- DEFAULT_MARKET_CONFIGURATORS,
22
- getDefaultMarketConfigurators
23
- };
@@ -1,4 +0,0 @@
1
- import type { Address } from "abitype";
2
- import type { NetworkType } from "../chain/index.js";
3
- export declare const DEFAULT_MARKET_CONFIGURATORS: Record<NetworkType, Record<Address, string>>;
4
- export declare function getDefaultMarketConfigurators(network: NetworkType): Address[];