@gearbox-protocol/sdk 12.3.2 → 12.3.4

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.
@@ -22,6 +22,7 @@ __export(DegenDistributorsPlugin_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(DegenDistributorsPlugin_exports);
24
24
  var import_sdk = require("../../sdk/index.js");
25
+ var import_MarketConfiguratorContract = require("../../sdk/market/MarketConfiguratorContract.js");
25
26
  const MAP_LABEL = "degenDistributors";
26
27
  class DegenDistributorsPlugin extends import_sdk.BasePlugin {
27
28
  #distributors;
@@ -39,12 +40,15 @@ class DegenDistributorsPlugin extends import_sdk.BasePlugin {
39
40
  this.sdk.logger?.debug(
40
41
  `loading degen distributors for ${this.sdk.networkType}`
41
42
  );
42
- const distributors = await Promise.allSettled(
43
- configurators.map((cfg) => cfg.getPeripheryContract("DEGEN_DISTRIBUTOR"))
43
+ const distributors = await import_MarketConfiguratorContract.MarketConfiguratorContract.getPeripheryContractBatch(
44
+ Object.values(configurators),
45
+ this.sdk.client,
46
+ "DEGEN_DISTRIBUTOR"
44
47
  );
45
48
  const distributorByConfigurator = configurators.reduce((acc, cfg, index) => {
46
49
  const cfgLC = cfg.address.toLowerCase();
47
- acc[cfgLC] = distributors[index];
50
+ const distributor = distributors[index];
51
+ acc[cfgLC] = distributor;
48
52
  return acc;
49
53
  }, {});
50
54
  this.#distributors = new import_sdk.AddressMap(void 0, MAP_LABEL);
@@ -53,11 +57,13 @@ class DegenDistributorsPlugin extends import_sdk.BasePlugin {
53
57
  const cfg = m.configurator.address;
54
58
  const cfgLC = cfg.toLowerCase();
55
59
  const r = distributorByConfigurator?.[cfgLC];
56
- if (r.status === "fulfilled") {
57
- this.#distributors?.upsert(pool, r.value);
60
+ if (r.status === "success" && r.result.length > 0) {
61
+ this.#distributors?.upsert(pool, r.result[0]);
58
62
  } else {
59
- this.sdk.logger?.error(
60
- `failed to load degen distributor for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.reason}`
63
+ this.sdk.logger?.warn(
64
+ `failed to load degen distributor for market configurator ${this.labelAddress(
65
+ cfg
66
+ )} and pool ${this.labelAddress(pool)}: ${r.error}`
61
67
  );
62
68
  }
63
69
  });
@@ -47,6 +47,20 @@ class MarketConfiguratorContract extends import_base.BaseContract {
47
47
  `Market configurator ${this.#curatorName}`
48
48
  );
49
49
  }
50
+ static async getPeripheryContractBatch(configurators, client, contract) {
51
+ const resp = await client.multicall({
52
+ allowFailure: true,
53
+ contracts: configurators.map(
54
+ (cfg) => ({
55
+ address: cfg.address,
56
+ abi: cfg.abi,
57
+ functionName: "getPeripheryContracts",
58
+ args: [(0, import_viem.stringToHex)(contract, { size: 32 })]
59
+ })
60
+ )
61
+ });
62
+ return resp;
63
+ }
50
64
  async getPeripheryContract(contract) {
51
65
  const resp = await this.client.readContract({
52
66
  address: this.address,
@@ -1,4 +1,5 @@
1
1
  import { AddressMap, BasePlugin } from "../../sdk/index.js";
2
+ import { MarketConfiguratorContract } from "../../sdk/market/MarketConfiguratorContract.js";
2
3
  const MAP_LABEL = "degenDistributors";
3
4
  class DegenDistributorsPlugin extends BasePlugin {
4
5
  #distributors;
@@ -16,12 +17,15 @@ class DegenDistributorsPlugin extends BasePlugin {
16
17
  this.sdk.logger?.debug(
17
18
  `loading degen distributors for ${this.sdk.networkType}`
18
19
  );
19
- const distributors = await Promise.allSettled(
20
- configurators.map((cfg) => cfg.getPeripheryContract("DEGEN_DISTRIBUTOR"))
20
+ const distributors = await MarketConfiguratorContract.getPeripheryContractBatch(
21
+ Object.values(configurators),
22
+ this.sdk.client,
23
+ "DEGEN_DISTRIBUTOR"
21
24
  );
22
25
  const distributorByConfigurator = configurators.reduce((acc, cfg, index) => {
23
26
  const cfgLC = cfg.address.toLowerCase();
24
- acc[cfgLC] = distributors[index];
27
+ const distributor = distributors[index];
28
+ acc[cfgLC] = distributor;
25
29
  return acc;
26
30
  }, {});
27
31
  this.#distributors = new AddressMap(void 0, MAP_LABEL);
@@ -30,11 +34,13 @@ class DegenDistributorsPlugin extends BasePlugin {
30
34
  const cfg = m.configurator.address;
31
35
  const cfgLC = cfg.toLowerCase();
32
36
  const r = distributorByConfigurator?.[cfgLC];
33
- if (r.status === "fulfilled") {
34
- this.#distributors?.upsert(pool, r.value);
37
+ if (r.status === "success" && r.result.length > 0) {
38
+ this.#distributors?.upsert(pool, r.result[0]);
35
39
  } else {
36
- this.sdk.logger?.error(
37
- `failed to load degen distributor for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.reason}`
40
+ this.sdk.logger?.warn(
41
+ `failed to load degen distributor for market configurator ${this.labelAddress(
42
+ cfg
43
+ )} and pool ${this.labelAddress(pool)}: ${r.error}`
38
44
  );
39
45
  }
40
46
  });
@@ -26,6 +26,20 @@ class MarketConfiguratorContract extends BaseContract {
26
26
  `Market configurator ${this.#curatorName}`
27
27
  );
28
28
  }
29
+ static async getPeripheryContractBatch(configurators, client, contract) {
30
+ const resp = await client.multicall({
31
+ allowFailure: true,
32
+ contracts: configurators.map(
33
+ (cfg) => ({
34
+ address: cfg.address,
35
+ abi: cfg.abi,
36
+ functionName: "getPeripheryContracts",
37
+ args: [stringToHex(contract, { size: 32 })]
38
+ })
39
+ )
40
+ });
41
+ return resp;
42
+ }
29
43
  async getPeripheryContract(contract) {
30
44
  const resp = await this.client.readContract({
31
45
  address: this.address,
@@ -1531,6 +1531,15 @@ export declare class MarketConfiguratorContract extends BaseContract<abi> {
1531
1531
  #private;
1532
1532
  constructor(options: ConstructOptions, address: Address);
1533
1533
  loadCuratorName(): Promise<void>;
1534
+ static getPeripheryContractBatch(configurators: MarketConfiguratorContract[], client: MarketConfiguratorContract["client"], contract: PeripheryContract): Promise<({
1535
+ error: Error;
1536
+ result?: undefined;
1537
+ status: "failure";
1538
+ } | {
1539
+ error?: undefined;
1540
+ result: readonly `0x${string}`[];
1541
+ status: "success";
1542
+ })[]>;
1534
1543
  getPeripheryContract(contract: PeripheryContract): Promise<Address>;
1535
1544
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
1536
1545
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.3.2",
3
+ "version": "12.3.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",