@gearbox-protocol/sdk 9.6.0 → 9.6.2

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,9 +89,8 @@ class GearboxSDK {
89
89
  gasLimit
90
90
  } = options;
91
91
  let { networkType, addressProvider, chainId } = options;
92
- const attachClient = (0, import_viem.createPublicClient)({
93
- transport: (0, import_chain.createTransport)(options)
94
- });
92
+ const transport = (0, import_chain.createTransport)(options);
93
+ const attachClient = (0, import_viem.createPublicClient)({ transport });
95
94
  if (!networkType) {
96
95
  networkType = await (0, import_chain.detectNetwork)(attachClient);
97
96
  }
@@ -104,6 +103,8 @@ class GearboxSDK {
104
103
  const marketConfigurators = mcs ?? import_utils.TypedObjectUtils.keys(import_chain.chains[networkType].defaultMarketConfigurators);
105
104
  const provider = new import_chain.Provider({
106
105
  ...options,
106
+ transport,
107
+ // pass transport to avoid creating a new transport in provider
107
108
  chainId,
108
109
  networkType
109
110
  });
@@ -22,6 +22,7 @@ __export(AbstractLPPriceFeed_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(AbstractLPPriceFeed_exports);
24
24
  var import_viem = require("viem");
25
+ var import_abi = require("../../abi/index.js");
25
26
  var import_versions = require("../../constants/versions.js");
26
27
  var import_AbstractPriceFeed = require("./AbstractPriceFeed.js");
27
28
  const LOWER_BOUND_FACTOR = 99n;
@@ -89,6 +90,13 @@ class AbstractLPPriceFeedContract extends import_AbstractPriceFeed.AbstractPrice
89
90
  );
90
91
  return lowerBound;
91
92
  }
93
+ async currentLowerBound() {
94
+ return await this.sdk.provider.publicClient.readContract({
95
+ abi: import_abi.ilpPriceFeedAbi,
96
+ address: this.address,
97
+ functionName: "lowerBound"
98
+ });
99
+ }
92
100
  static toLowerBound(value) {
93
101
  return value * LOWER_BOUND_FACTOR / 100n;
94
102
  }
@@ -22,7 +22,6 @@ __export(AbstractPriceFeed_exports, {
22
22
  PartialPriceFeedInitError: () => PartialPriceFeedInitError
23
23
  });
24
24
  module.exports = __toCommonJS(AbstractPriceFeed_exports);
25
- var import_abi = require("../../abi/index.js");
26
25
  var import_base = require("../../base/index.js");
27
26
  var import_isUpdatablePriceFeed = require("./isUpdatablePriceFeed.js");
28
27
  var import_PriceFeedRef = require("./PriceFeedRef.js");
@@ -44,6 +43,7 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
44
43
  #decimals;
45
44
  #underlyingPriceFeeds;
46
45
  #skipCheck;
46
+ #answer;
47
47
  #args;
48
48
  hasLowerBoundCap = false;
49
49
  description;
@@ -60,6 +60,7 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
60
60
  this.#decimals = args.decimals;
61
61
  this.#updatable = args.updatable;
62
62
  this.#skipCheck = args.skipCheck;
63
+ this.#answer = args.answer;
63
64
  if (args.underlyingFeeds && args.underlyingStalenessPeriods) {
64
65
  const underlyingStalenessPeriods = args.underlyingStalenessPeriods;
65
66
  this.#underlyingPriceFeeds = args.underlyingFeeds.map(
@@ -94,6 +95,12 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
94
95
  }
95
96
  return this.#underlyingPriceFeeds;
96
97
  }
98
+ get answer() {
99
+ if (this.#answer === void 0) {
100
+ throw new PartialPriceFeedInitError(this.#args);
101
+ }
102
+ return this.#answer;
103
+ }
97
104
  get priceFeedType() {
98
105
  return this.contractType;
99
106
  }
@@ -106,22 +113,6 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
106
113
  pricefeeds: this.underlyingPriceFeeds.map((f) => f.stateHuman(raw))
107
114
  };
108
115
  }
109
- async currentLowerBound() {
110
- return await this.sdk.provider.publicClient.readContract({
111
- abi: import_abi.ilpPriceFeedAbi,
112
- address: this.address,
113
- functionName: "lowerBound"
114
- });
115
- }
116
- async answer(overrides) {
117
- const lastRoundData = await this.sdk.provider.publicClient.readContract({
118
- abi: import_abi.ilpPriceFeedAbi,
119
- address: this.address,
120
- functionName: "latestRoundData",
121
- ...overrides
122
- });
123
- return lastRoundData[1];
124
- }
125
116
  updatableDependencies() {
126
117
  const underlying = this.underlyingPriceFeeds.flatMap(
127
118
  (f) => f.priceFeed.updatableDependencies()
@@ -87,9 +87,8 @@ class GearboxSDK {
87
87
  gasLimit
88
88
  } = options;
89
89
  let { networkType, addressProvider, chainId } = options;
90
- const attachClient = createPublicClient({
91
- transport: createTransport(options)
92
- });
90
+ const transport = createTransport(options);
91
+ const attachClient = createPublicClient({ transport });
93
92
  if (!networkType) {
94
93
  networkType = await detectNetwork(attachClient);
95
94
  }
@@ -102,6 +101,8 @@ class GearboxSDK {
102
101
  const marketConfigurators = mcs ?? TypedObjectUtils.keys(chains[networkType].defaultMarketConfigurators);
103
102
  const provider = new Provider({
104
103
  ...options,
104
+ transport,
105
+ // pass transport to avoid creating a new transport in provider
105
106
  chainId,
106
107
  networkType
107
108
  });
@@ -1,4 +1,5 @@
1
1
  import { decodeAbiParameters, hexToBytes } from "viem";
2
+ import { ilpPriceFeedAbi } from "../../abi/index.js";
2
3
  import { isV310 } from "../../constants/versions.js";
3
4
  import {
4
5
  AbstractPriceFeedContract
@@ -68,6 +69,13 @@ class AbstractLPPriceFeedContract extends AbstractPriceFeedContract {
68
69
  );
69
70
  return lowerBound;
70
71
  }
72
+ async currentLowerBound() {
73
+ return await this.sdk.provider.publicClient.readContract({
74
+ abi: ilpPriceFeedAbi,
75
+ address: this.address,
76
+ functionName: "lowerBound"
77
+ });
78
+ }
71
79
  static toLowerBound(value) {
72
80
  return value * LOWER_BOUND_FACTOR / 100n;
73
81
  }
@@ -1,4 +1,3 @@
1
- import { ilpPriceFeedAbi } from "../../abi/index.js";
2
1
  import { BaseContract } from "../../base/index.js";
3
2
  import { isUpdatablePriceFeed } from "./isUpdatablePriceFeed.js";
4
3
  import { PriceFeedRef } from "./PriceFeedRef.js";
@@ -20,6 +19,7 @@ class AbstractPriceFeedContract extends BaseContract {
20
19
  #decimals;
21
20
  #underlyingPriceFeeds;
22
21
  #skipCheck;
22
+ #answer;
23
23
  #args;
24
24
  hasLowerBoundCap = false;
25
25
  description;
@@ -36,6 +36,7 @@ class AbstractPriceFeedContract extends BaseContract {
36
36
  this.#decimals = args.decimals;
37
37
  this.#updatable = args.updatable;
38
38
  this.#skipCheck = args.skipCheck;
39
+ this.#answer = args.answer;
39
40
  if (args.underlyingFeeds && args.underlyingStalenessPeriods) {
40
41
  const underlyingStalenessPeriods = args.underlyingStalenessPeriods;
41
42
  this.#underlyingPriceFeeds = args.underlyingFeeds.map(
@@ -70,6 +71,12 @@ class AbstractPriceFeedContract extends BaseContract {
70
71
  }
71
72
  return this.#underlyingPriceFeeds;
72
73
  }
74
+ get answer() {
75
+ if (this.#answer === void 0) {
76
+ throw new PartialPriceFeedInitError(this.#args);
77
+ }
78
+ return this.#answer;
79
+ }
73
80
  get priceFeedType() {
74
81
  return this.contractType;
75
82
  }
@@ -82,22 +89,6 @@ class AbstractPriceFeedContract extends BaseContract {
82
89
  pricefeeds: this.underlyingPriceFeeds.map((f) => f.stateHuman(raw))
83
90
  };
84
91
  }
85
- async currentLowerBound() {
86
- return await this.sdk.provider.publicClient.readContract({
87
- abi: ilpPriceFeedAbi,
88
- address: this.address,
89
- functionName: "lowerBound"
90
- });
91
- }
92
- async answer(overrides) {
93
- const lastRoundData = await this.sdk.provider.publicClient.readContract({
94
- abi: ilpPriceFeedAbi,
95
- address: this.address,
96
- functionName: "latestRoundData",
97
- ...overrides
98
- });
99
- return lastRoundData[1];
100
- }
101
92
  updatableDependencies() {
102
93
  const underlying = this.underlyingPriceFeeds.flatMap(
103
94
  (f) => f.priceFeed.updatableDependencies()
@@ -20,7 +20,13 @@ export interface OnDemandPriceUpdates<T = unknown> {
20
20
  multicall: MultiCall[];
21
21
  }
22
22
  export interface IPriceOracleContract extends IBaseContract {
23
+ /**
24
+ * Mapping Token => [PriceFeed Address, stalenessPeriod]
25
+ */
23
26
  mainPriceFeeds: AddressMap<PriceFeedRef>;
27
+ /**
28
+ * Mapping Token => Price in USD
29
+ */
24
30
  mainPrices: PriceFeedAnswerMap;
25
31
  /**
26
32
  * Gets main price for given token
@@ -29,7 +35,13 @@ export interface IPriceOracleContract extends IBaseContract {
29
35
  * @returns
30
36
  */
31
37
  mainPrice: (token: Address) => bigint;
38
+ /**
39
+ * Mapping Token => [PriceFeed Address, stalenessPeriod]
40
+ */
32
41
  reservePriceFeeds: AddressMap<PriceFeedRef>;
42
+ /**
43
+ * Mapping Token => Price in USD
44
+ */
33
45
  reservePrices: PriceFeedAnswerMap;
34
46
  /**
35
47
  * Gets reserve price for given token
@@ -2,7 +2,8 @@ import type { Abi, Address, UnionOmit } from "viem";
2
2
  import type { GearboxSDK } from "../../GearboxSDK.js";
3
3
  import type { LPPriceFeedStateHuman } from "../../types/state-human.js";
4
4
  import { AbstractPriceFeedContract, type PriceFeedConstructorArgs } from "./AbstractPriceFeed.js";
5
- export declare abstract class AbstractLPPriceFeedContract<const abi extends Abi | readonly unknown[]> extends AbstractPriceFeedContract<abi> {
5
+ import type { ILPPriceFeedContract } from "./types.js";
6
+ export declare abstract class AbstractLPPriceFeedContract<const abi extends Abi | readonly unknown[]> extends AbstractPriceFeedContract<abi> implements ILPPriceFeedContract {
6
7
  readonly lpContract: Address;
7
8
  readonly lpToken: Address;
8
9
  readonly lowerBound: bigint;
@@ -13,6 +14,7 @@ export declare abstract class AbstractLPPriceFeedContract<const abi extends Abi
13
14
  constructor(sdk: GearboxSDK, args: PriceFeedConstructorArgs<abi>);
14
15
  abstract getValue(): Promise<bigint>;
15
16
  getLowerBound(): Promise<bigint>;
17
+ currentLowerBound(): Promise<bigint>;
16
18
  static toLowerBound(value: bigint): bigint;
17
19
  stateHuman(raw?: boolean): UnionOmit<LPPriceFeedStateHuman, "stalenessPeriod">;
18
20
  }
@@ -1,5 +1,5 @@
1
1
  import type { Abi, RequiredBy, UnionOmit } from "viem";
2
- import type { PriceFeedTreeNode } from "../../base/index.js";
2
+ import type { PriceFeedAnswer, PriceFeedTreeNode } from "../../base/index.js";
3
3
  import { BaseContract } from "../../base/index.js";
4
4
  import type { GearboxSDK } from "../../GearboxSDK.js";
5
5
  import type { PriceFeedStateHuman } from "../../types/index.js";
@@ -24,11 +24,8 @@ export declare abstract class AbstractPriceFeedContract<const abi extends Abi |
24
24
  get updatable(): boolean;
25
25
  get skipCheck(): boolean;
26
26
  get underlyingPriceFeeds(): readonly PriceFeedRef[];
27
+ get answer(): PriceFeedAnswer;
27
28
  get priceFeedType(): PriceFeedContractType;
28
29
  stateHuman(raw?: boolean): UnionOmit<PriceFeedStateHuman, "stalenessPeriod">;
29
- currentLowerBound(): Promise<bigint>;
30
- answer(overrides?: {
31
- blockNumber?: bigint;
32
- }): Promise<bigint>;
33
30
  updatableDependencies(): IUpdatablePriceFeedContract[];
34
31
  }
@@ -3,6 +3,9 @@ import { SDKConstruct } from "../../base/index.js";
3
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
4
  import type { PriceFeedStateHuman } from "../../types/index.js";
5
5
  import type { IPriceFeedContract } from "./types.js";
6
+ /**
7
+ * PriceFeedRef is a connector between price feed and oracle, e.g. oracle's entry for price feed + staleness period
8
+ */
6
9
  export declare class PriceFeedRef extends SDKConstruct {
7
10
  #private;
8
11
  readonly address: Address;
@@ -1,5 +1,5 @@
1
1
  import type { Address, Hex, UnionOmit } from "viem";
2
- import type { IBaseContract } from "../../base/index.js";
2
+ import type { IBaseContract, PriceFeedAnswer } from "../../base/index.js";
3
3
  import type { IPriceUpdateTx, PriceFeedStateHuman, RawTx } from "../../types/index.js";
4
4
  import type { PriceFeedRef } from "./PriceFeedRef.js";
5
5
  export type PriceFeedUsageType = "Main" | "Reserve";
@@ -18,10 +18,12 @@ export interface IPriceFeedContract extends IBaseContract {
18
18
  * This flag idicates that all the price feed data (decimals, skip check, dependencies...) has been loaded from compressor
19
19
  */
20
20
  readonly loaded: boolean;
21
+ /**
22
+ * Latest answer for this price feed
23
+ */
24
+ readonly answer: PriceFeedAnswer;
25
+ readonly skipCheck: boolean;
21
26
  readonly underlyingPriceFeeds: readonly PriceFeedRef[];
22
- answer: (overrides?: {
23
- blockNumber?: bigint;
24
- }) => Promise<bigint>;
25
27
  stateHuman: (raw?: boolean) => UnionOmit<PriceFeedStateHuman, "stalenessPeriod">;
26
28
  /**
27
29
  * Returns all updatable depenedencies (uderlying price feeds) of this price feed, including price feed itself, if it's updatable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "9.6.0",
3
+ "version": "9.6.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",