@gearbox-protocol/sdk 12.9.0-txparser.4 → 12.9.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.
@@ -52,6 +52,9 @@ function getRpcProviderUrl(provider, network, apiKey, protocol = "http") {
52
52
  }
53
53
  }
54
54
  function getAlchemyUrl(network, apiKey, protocol = "http") {
55
+ if (!apiKey) {
56
+ return void 0;
57
+ }
55
58
  const alchemyDomain = ALCHEMY_DOMAINS[network];
56
59
  if (!alchemyDomain) {
57
60
  return void 0;
@@ -95,6 +98,9 @@ const ALCHEMY_DOMAINS = {
95
98
  Somnia: null
96
99
  };
97
100
  function getDrpcUrl(network, apiKey, protocol = "http") {
101
+ if (!apiKey) {
102
+ return void 0;
103
+ }
98
104
  const net = DRPC_NETS[network];
99
105
  return net ? `${protocol}s://lb.drpc.live/${net}/${apiKey}` : void 0;
100
106
  }
@@ -117,6 +123,9 @@ const ANKR_DOMAINS = {
117
123
  Somnia: "somnia_mainnet"
118
124
  };
119
125
  function getAnkrUrl(network, apiKey, protocol = "http") {
126
+ if (!apiKey) {
127
+ return void 0;
128
+ }
120
129
  const net = ANKR_DOMAINS[network];
121
130
  const sep = protocol === "ws" ? "/ws/" : "/";
122
131
  return net ? `${protocol}s://rpc.ankr.com/${net}${sep}${apiKey}` : void 0;
@@ -140,6 +149,9 @@ const THIRDWEB_DOMAINS = {
140
149
  Somnia: import_sdk.chains.Somnia.id.toString()
141
150
  };
142
151
  function getThirdWebUrl(network, apiKey, protocol = "http") {
152
+ if (!apiKey) {
153
+ return void 0;
154
+ }
143
155
  if (protocol === "ws") {
144
156
  return void 0;
145
157
  }
@@ -26,7 +26,7 @@ var import_createAdapter = require("../plugins/adapters/createAdapter.js");
26
26
  var import_sdk = require("../sdk/index.js");
27
27
  function populateContractsRegister(options) {
28
28
  const { client, deployments, tokens, logger, strict } = options;
29
- const register = import_sdk.ChainContractsRegister.for(client, logger);
29
+ const register = new import_sdk.ChainContractsRegister(client, logger);
30
30
  for (const d of deployments) {
31
31
  let contractType;
32
32
  if ("contractType" in d) {
@@ -36,13 +36,13 @@ function populateContractsRegister(options) {
36
36
  }
37
37
  if (contractType === "CREDIT_FACADE" && (0, import_sdk.isV310)(d.version)) {
38
38
  new import_sdk.CreditFacadeV310BaseContract(
39
- { client: register.client, logger },
39
+ { register, logger },
40
40
  { addr: d.address, version: d.version, contractType }
41
41
  );
42
42
  } else if (contractType.startsWith("ADAPTER::")) {
43
43
  (0, import_createAdapter.createAdapter)(
44
44
  {
45
- client: register.client,
45
+ register,
46
46
  logger
47
47
  },
48
48
  {
@@ -51,15 +51,15 @@ class BaseContract extends import_Construct.Construct {
51
51
  version;
52
52
  address;
53
53
  name;
54
- constructor({ client, logger }, args) {
55
- super({ client, logger });
54
+ constructor(options, args) {
55
+ super(options);
56
56
  this.abi = args.abi;
57
57
  this.address = (0, import_viem.getAddress)(args.addr);
58
58
  this.contract = (0, import_viem.getContract)({
59
59
  address: this.address,
60
60
  // add exceptions for better error decoding
61
61
  abi: [...this.abi, ...import_errors.errorAbis],
62
- client
62
+ client: this.client
63
63
  });
64
64
  this.version = Number(args.version || 0);
65
65
  this.contractType = args.contractType ?? "";
@@ -31,9 +31,17 @@ class Construct {
31
31
  * Indicates that contract state needs to be updated
32
32
  */
33
33
  #dirty = false;
34
- constructor({ client, logger }) {
35
- this.client = client;
36
- this.register = import_ChainContractsRegister.ChainContractsRegister.for(client, logger);
34
+ constructor(options) {
35
+ const { logger } = options;
36
+ if ("client" in options) {
37
+ const { client } = options;
38
+ this.client = client;
39
+ this.register = import_ChainContractsRegister.ChainContractsRegister.for(client, logger);
40
+ } else {
41
+ const { register } = options;
42
+ this.register = register;
43
+ this.client = register.client;
44
+ }
37
45
  this.logger = (0, import_utils.childLogger)(
38
46
  this.constructor.name,
39
47
  this.register.logger ?? logger
@@ -22,6 +22,9 @@ function getRpcProviderUrl(provider, network, apiKey, protocol = "http") {
22
22
  }
23
23
  }
24
24
  function getAlchemyUrl(network, apiKey, protocol = "http") {
25
+ if (!apiKey) {
26
+ return void 0;
27
+ }
25
28
  const alchemyDomain = ALCHEMY_DOMAINS[network];
26
29
  if (!alchemyDomain) {
27
30
  return void 0;
@@ -65,6 +68,9 @@ const ALCHEMY_DOMAINS = {
65
68
  Somnia: null
66
69
  };
67
70
  function getDrpcUrl(network, apiKey, protocol = "http") {
71
+ if (!apiKey) {
72
+ return void 0;
73
+ }
68
74
  const net = DRPC_NETS[network];
69
75
  return net ? `${protocol}s://lb.drpc.live/${net}/${apiKey}` : void 0;
70
76
  }
@@ -87,6 +93,9 @@ const ANKR_DOMAINS = {
87
93
  Somnia: "somnia_mainnet"
88
94
  };
89
95
  function getAnkrUrl(network, apiKey, protocol = "http") {
96
+ if (!apiKey) {
97
+ return void 0;
98
+ }
90
99
  const net = ANKR_DOMAINS[network];
91
100
  const sep = protocol === "ws" ? "/ws/" : "/";
92
101
  return net ? `${protocol}s://rpc.ankr.com/${net}${sep}${apiKey}` : void 0;
@@ -110,6 +119,9 @@ const THIRDWEB_DOMAINS = {
110
119
  Somnia: chains.Somnia.id.toString()
111
120
  };
112
121
  function getThirdWebUrl(network, apiKey, protocol = "http") {
122
+ if (!apiKey) {
123
+ return void 0;
124
+ }
113
125
  if (protocol === "ws") {
114
126
  return void 0;
115
127
  }
@@ -11,7 +11,7 @@ import {
11
11
  } from "../sdk/index.js";
12
12
  function populateContractsRegister(options) {
13
13
  const { client, deployments, tokens, logger, strict } = options;
14
- const register = ChainContractsRegister.for(client, logger);
14
+ const register = new ChainContractsRegister(client, logger);
15
15
  for (const d of deployments) {
16
16
  let contractType;
17
17
  if ("contractType" in d) {
@@ -21,13 +21,13 @@ function populateContractsRegister(options) {
21
21
  }
22
22
  if (contractType === "CREDIT_FACADE" && isV310(d.version)) {
23
23
  new CreditFacadeV310BaseContract(
24
- { client: register.client, logger },
24
+ { register, logger },
25
25
  { addr: d.address, version: d.version, contractType }
26
26
  );
27
27
  } else if (contractType.startsWith("ADAPTER::")) {
28
28
  createAdapter(
29
29
  {
30
- client: register.client,
30
+ register,
31
31
  logger
32
32
  },
33
33
  {
@@ -41,15 +41,15 @@ class BaseContract extends Construct {
41
41
  version;
42
42
  address;
43
43
  name;
44
- constructor({ client, logger }, args) {
45
- super({ client, logger });
44
+ constructor(options, args) {
45
+ super(options);
46
46
  this.abi = args.abi;
47
47
  this.address = getAddress(args.addr);
48
48
  this.contract = getContract({
49
49
  address: this.address,
50
50
  // add exceptions for better error decoding
51
51
  abi: [...this.abi, ...errorAbis],
52
- client
52
+ client: this.client
53
53
  });
54
54
  this.version = Number(args.version || 0);
55
55
  this.contractType = args.contractType ?? "";
@@ -8,9 +8,17 @@ class Construct {
8
8
  * Indicates that contract state needs to be updated
9
9
  */
10
10
  #dirty = false;
11
- constructor({ client, logger }) {
12
- this.client = client;
13
- this.register = ChainContractsRegister.for(client, logger);
11
+ constructor(options) {
12
+ const { logger } = options;
13
+ if ("client" in options) {
14
+ const { client } = options;
15
+ this.client = client;
16
+ this.register = ChainContractsRegister.for(client, logger);
17
+ } else {
18
+ const { register } = options;
19
+ this.register = register;
20
+ this.client = register.client;
21
+ }
14
22
  this.logger = childLogger(
15
23
  this.constructor.name,
16
24
  this.register.logger ?? logger
@@ -8,11 +8,11 @@ export declare const rpcProvidersSchema: z.ZodEnum<{
8
8
  ankr: "ankr";
9
9
  }>;
10
10
  export type RpcProvider = z.infer<typeof rpcProvidersSchema>;
11
- export declare function getRpcProviderUrl(provider: RpcProvider, network: NetworkType, apiKey: string, protocol?: "http" | "ws"): string | undefined;
12
- export declare function getAlchemyUrl(network: NetworkType, apiKey: string, protocol?: "http" | "ws"): string | undefined;
13
- export declare function getDrpcUrl(network: NetworkType, apiKey: string, protocol?: "http" | "ws"): string | undefined;
14
- export declare function getAnkrUrl(network: NetworkType, apiKey: string, protocol?: "http" | "ws"): string | undefined;
15
- export declare function getThirdWebUrl(network: NetworkType, apiKey: string, protocol?: "http" | "ws"): string | undefined;
11
+ export declare function getRpcProviderUrl(provider: RpcProvider, network: NetworkType, apiKey?: string, protocol?: "http" | "ws"): string | undefined;
12
+ export declare function getAlchemyUrl(network: NetworkType, apiKey?: string, protocol?: "http" | "ws"): string | undefined;
13
+ export declare function getDrpcUrl(network: NetworkType, apiKey?: string, protocol?: "http" | "ws"): string | undefined;
14
+ export declare function getAnkrUrl(network: NetworkType, apiKey?: string, protocol?: "http" | "ws"): string | undefined;
15
+ export declare function getThirdWebUrl(network: NetworkType, apiKey?: string, protocol?: "http" | "ws"): string | undefined;
16
16
  export declare function getErpcKey(network: NetworkType, projectId?: string, urlBase?: string): string | undefined;
17
17
  /**
18
18
  Non-existent event:
@@ -1,6 +1,6 @@
1
1
  import { type Address, type Chain, type PublicClient, type Transport } from "viem";
2
2
  import { ChainContractsRegister, type ILogger, type TokenMetaData, TokensMeta } from "../sdk/index.js";
3
- export type Deployment = {
3
+ export type DeploymentLike = {
4
4
  address: Address;
5
5
  version: number;
6
6
  } & ({
@@ -11,7 +11,7 @@ export type Deployment = {
11
11
  });
12
12
  export interface PopulateContractsRegisterOptions {
13
13
  client: PublicClient<Transport, Chain>;
14
- deployments: Deployment[];
14
+ deployments: DeploymentLike[];
15
15
  tokens: TokensMeta | Iterable<TokenMetaData>;
16
16
  logger?: ILogger;
17
17
  strict?: boolean;
@@ -28,7 +28,7 @@ export declare class BaseContract<abi extends Abi | readonly unknown[]> extends
28
28
  readonly version: number;
29
29
  readonly address: Address;
30
30
  readonly name: string;
31
- constructor({ client, logger }: ConstructOptions, args: BaseContractArgs<abi>);
31
+ constructor(options: ConstructOptions, args: BaseContractArgs<abi>);
32
32
  stateHuman(_?: boolean): BaseContractStateHuman;
33
33
  /**
34
34
  * Updates (or not) contract's internal state from event
@@ -3,16 +3,19 @@ import type { NetworkType } from "../chain/index.js";
3
3
  import type { ILogger } from "../types/index.js";
4
4
  import { ChainContractsRegister } from "./ChainContractsRegister.js";
5
5
  import type { TokensMeta } from "./TokensMeta.js";
6
- export interface ConstructOptions {
6
+ export type ConstructOptions = {
7
7
  client: PublicClient<Transport, Chain>;
8
8
  logger?: ILogger;
9
- }
9
+ } | {
10
+ register: ChainContractsRegister;
11
+ logger?: ILogger;
12
+ };
10
13
  export declare class Construct {
11
14
  #private;
12
15
  readonly logger?: ILogger;
13
16
  readonly client: PublicClient<Transport, Chain>;
14
17
  readonly register: ChainContractsRegister;
15
- constructor({ client, logger }: ConstructOptions);
18
+ constructor(options: ConstructOptions);
16
19
  get chain(): Chain;
17
20
  get chainId(): number;
18
21
  get networkType(): NetworkType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.9.0-txparser.4",
3
+ "version": "12.9.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",