@gearbox-protocol/sdk 4.2.0-next.3 → 5.0.0-next.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.
Files changed (79) hide show
  1. package/dist/cjs/bots/BotsPlugin.js +2 -2
  2. package/dist/cjs/dev/calcLiquidatableLTs.js +5 -1
  3. package/dist/cjs/dev/index.js +1 -3
  4. package/dist/cjs/dev/ltUtils.js +2 -2
  5. package/dist/cjs/sdk/GearboxSDK.js +2 -5
  6. package/dist/cjs/sdk/accounts/CreditAccountsService.js +10 -5
  7. package/dist/cjs/sdk/base/BaseContract.js +0 -1
  8. package/dist/cjs/sdk/constants/index.js +3 -1
  9. package/dist/cjs/sdk/{utils/version.js → constants/versions.js} +18 -7
  10. package/dist/cjs/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
  11. package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +3 -3
  12. package/dist/cjs/sdk/gauges/GaugeStakingService.js +4 -1
  13. package/dist/cjs/sdk/market/MarketRegister.js +2 -2
  14. package/dist/cjs/sdk/market/MarketSuite.js +1 -5
  15. package/dist/cjs/sdk/market/credit/createCreditConfigurator.js +3 -2
  16. package/dist/cjs/sdk/market/credit/createCreditFacade.js +3 -2
  17. package/dist/cjs/sdk/market/credit/createCreditManager.js +3 -2
  18. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +55 -49
  19. package/dist/cjs/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
  20. package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
  21. package/dist/cjs/sdk/market/oracle/createPriceOracle.js +29 -9
  22. package/dist/cjs/sdk/market/pool/createPool.js +3 -2
  23. package/dist/cjs/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
  24. package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
  25. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
  26. package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +1 -1
  27. package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +5 -5
  28. package/dist/cjs/sdk/router/createRouter.js +3 -2
  29. package/dist/cjs/sdk/utils/index.js +1 -3
  30. package/dist/cjs/zappers/ZappersPlugin.js +2 -2
  31. package/dist/esm/bots/BotsPlugin.js +4 -3
  32. package/dist/esm/dev/calcLiquidatableLTs.js +5 -1
  33. package/dist/esm/dev/index.js +0 -1
  34. package/dist/esm/dev/ltUtils.js +9 -3
  35. package/dist/esm/sdk/GearboxSDK.js +6 -6
  36. package/dist/esm/sdk/accounts/CreditAccountsService.js +12 -6
  37. package/dist/esm/sdk/base/BaseContract.js +0 -1
  38. package/dist/esm/sdk/constants/index.js +1 -0
  39. package/dist/esm/sdk/constants/versions.js +18 -0
  40. package/dist/esm/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
  41. package/dist/esm/sdk/core/address-provider/createAddressProvider.js +1 -1
  42. package/dist/esm/sdk/gauges/GaugeStakingService.js +5 -2
  43. package/dist/esm/sdk/market/MarketRegister.js +7 -3
  44. package/dist/esm/sdk/market/MarketSuite.js +2 -6
  45. package/dist/esm/sdk/market/credit/createCreditConfigurator.js +3 -2
  46. package/dist/esm/sdk/market/credit/createCreditFacade.js +3 -2
  47. package/dist/esm/sdk/market/credit/createCreditManager.js +3 -2
  48. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +60 -50
  49. package/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
  50. package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
  51. package/dist/esm/sdk/market/oracle/createPriceOracle.js +28 -8
  52. package/dist/esm/sdk/market/pool/createPool.js +3 -2
  53. package/dist/esm/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
  54. package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
  55. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +4 -3
  56. package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +2 -2
  57. package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +6 -6
  58. package/dist/esm/sdk/router/createRouter.js +3 -2
  59. package/dist/esm/sdk/utils/index.js +0 -1
  60. package/dist/esm/zappers/ZappersPlugin.js +4 -3
  61. package/dist/types/dev/index.d.ts +0 -1
  62. package/dist/types/sdk/constants/index.d.ts +1 -0
  63. package/dist/types/sdk/constants/versions.d.ts +9 -0
  64. package/dist/types/sdk/core/address-provider/AbstractAddressProviderContract.d.ts +3 -2
  65. package/dist/types/sdk/core/address-provider/types.d.ts +3 -2
  66. package/dist/types/sdk/market/MarketSuite.d.ts +2 -2
  67. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +28 -684
  68. package/dist/types/sdk/market/oracle/PriceOracleV300Contract.d.ts +1 -1
  69. package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +2 -2
  70. package/dist/types/sdk/market/oracle/createPriceOracle.d.ts +14 -3
  71. package/dist/types/sdk/market/oracle/types.d.ts +97 -6
  72. package/dist/types/sdk/plugins/V300StalenessPeriodPlugin.d.ts +3 -2
  73. package/dist/types/sdk/utils/index.d.ts +0 -1
  74. package/package.json +1 -1
  75. package/dist/cjs/dev/PriceFeedStore.js +0 -93
  76. package/dist/esm/dev/PriceFeedStore.js +0 -74
  77. package/dist/esm/sdk/utils/version.js +0 -10
  78. package/dist/types/dev/PriceFeedStore.d.ts +0 -10
  79. package/dist/types/sdk/utils/version.d.ts +0 -2
@@ -353,7 +353,7 @@ declare const abi: ({
353
353
  })[];
354
354
  type abi = typeof abi;
355
355
  export declare class PriceOracleV300Contract extends PriceOracleBaseContract<abi> {
356
- constructor(sdk: GearboxSDK, data: PriceOracleData, underlying: Address);
356
+ constructor(sdk: GearboxSDK, data: PriceOracleData);
357
357
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
358
358
  findTokenForPriceFeed(priceFeed: Address): [token: Address | undefined, reserve: boolean];
359
359
  }
@@ -1,4 +1,4 @@
1
- import type { Address, ContractEventName, Log } from "viem";
1
+ import type { ContractEventName, Log } from "viem";
2
2
  import type { PriceOracleData } from "../../base/index.js";
3
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
4
  import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
@@ -339,7 +339,7 @@ declare const abi: readonly [{
339
339
  }];
340
340
  type abi = typeof abi;
341
341
  export declare class PriceOracleV310Contract extends PriceOracleBaseContract<abi> {
342
- constructor(sdk: GearboxSDK, data: PriceOracleData, underlying: Address);
342
+ constructor(sdk: GearboxSDK, data: PriceOracleData);
343
343
  processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
344
344
  }
345
345
  export {};
@@ -1,5 +1,16 @@
1
- import type { Address } from "abitype";
2
1
  import type { PriceOracleData } from "../../base/index.js";
3
2
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
- import type { PriceOracleContract } from "./types.js";
5
- export declare function createPriceOracle(sdk: GearboxSDK, data: PriceOracleData, underlying: Address): PriceOracleContract;
3
+ import type { IPriceOracleContract } from "./types.js";
4
+ /**
5
+ * Used get or create oracle contract instances
6
+ * In 3.0 we can have same oracle for different pools
7
+ * But also due to how compressor works for v3.0, each maketData.priceOracle data will have different tokens (for the same oracle)
8
+ *
9
+ * So this method bridges multiple compressor data pieces and single oracle contract isntance
10
+ *
11
+ * @param sdk
12
+ * @param data
13
+ * @param underlying
14
+ * @returns
15
+ */
16
+ export declare function getOrCreatePriceOracle(sdk: GearboxSDK, data: PriceOracleData): IPriceOracleContract;
@@ -1,9 +1,10 @@
1
- import type { Address, Hex } from "viem";
1
+ import type { Address, ContractFunctionParameters, ContractFunctionReturnType, Hex } from "viem";
2
+ import type { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
2
3
  import type { IBaseContract } from "../../base/index.js";
3
- import type { PriceOracleV310Contract } from "../index.js";
4
- import type { IPriceFeedContract, UpdatePriceFeedsResult } from "../pricefeeds/index.js";
5
- import type { PriceOracleV300Contract } from "./PriceOracleV300Contract.js";
6
- export type PriceOracleContract = PriceOracleV300Contract | PriceOracleV310Contract;
4
+ import type { PriceOracleStateHuman } from "../../types/index.js";
5
+ import type { AddressMap } from "../../utils/index.js";
6
+ import type { IPriceFeedContract, PriceFeedRef, UpdatePriceFeedsResult } from "../pricefeeds/index.js";
7
+ import type PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
7
8
  export interface PriceFeedsForTokensOptions {
8
9
  main?: boolean;
9
10
  reserve?: boolean;
@@ -19,11 +20,101 @@ export interface OnDemandPriceUpdate {
19
20
  data: Hex;
20
21
  }
21
22
  export interface IPriceOracleContract extends IBaseContract {
23
+ mainPriceFeeds: AddressMap<PriceFeedRef>;
24
+ mainPrices: PriceFeedAnswerMap;
25
+ /**
26
+ * Gets main price for given token
27
+ * Throws if token price feed is not found or answer is not successful
28
+ * @param token
29
+ * @returns
30
+ */
31
+ mainPrice: (token: Address) => bigint;
32
+ reservePriceFeeds: AddressMap<PriceFeedRef>;
33
+ reservePrices: PriceFeedAnswerMap;
34
+ /**
35
+ * Gets reserve price for given token
36
+ * Throws if token price feed is not found or answer is not successful
37
+ * @param token
38
+ * @returns
39
+ */
40
+ reservePrice: (token: Address) => bigint;
41
+ /**
42
+ * Loads new prices for this oracle from PriceFeedCompressor
43
+ * Will (re)create price feeds if needed
44
+ */
45
+ updatePrices: () => Promise<void>;
46
+ /**
47
+ * Paired method to updatePrices, helps to update prices on all oracles in one multicall
48
+ */
49
+ syncStateMulticall: () => DelegatedOracleMulticall;
50
+ /**
51
+ * Returns true if oracle's price feed tree contains given price feed
52
+ * This feed is not necessary connected to token, but can be a component of composite feed for some token
53
+ * @param priceFeed
54
+ * @returns
55
+ */
56
+ usesPriceFeed: (priceFeed: Address) => boolean;
57
+ /**
58
+ * Helper method to find "attachment point" of price feed (makes sense for updatable price feeds only) -
59
+ * returns token (in v300 can be ticker) and main/reserve flag
60
+ *
61
+ * @deprecated Should be gone after v310 migration
62
+ *
63
+ * @param priceFeed
64
+ * @returns
65
+ */
66
+ findTokenForPriceFeed: (priceFeed: Address) => [token: Address | undefined, reserve: boolean];
67
+ /**
68
+ * Returns main and reserve price feeds for given tokens
69
+ * @param tokens
70
+ * @param opts Option to include main/reserve feeds only, defaults to both
71
+ * @returns
72
+ */
22
73
  priceFeedsForTokens: (tokens: Address[], opts?: PriceFeedsForTokensOptions) => IPriceFeedContract[];
74
+ /**
75
+ * Generates updates for all updateable price feeds in this oracle (including dependencies)
76
+ * @returns
77
+ */
23
78
  updatePriceFeeds: () => Promise<UpdatePriceFeedsResult>;
79
+ /**
80
+ * Converts previously obtained price updates into CreditFacade multicall entries
81
+ * @param creditFacade
82
+ * @param updates
83
+ * @returns
84
+ */
24
85
  onDemandPriceUpdates: (updates?: UpdatePriceFeedsResult) => OnDemandPriceUpdate[];
25
- convertToUnderlying: (token: Address, amount: bigint, reserve?: boolean) => bigint;
86
+ /**
87
+ * Tries to convert amount of from one token to another, using latest known prices
88
+ * @param from
89
+ * @param to
90
+ * @param amount
91
+ * @param reserve use reserve price feed instead of main
92
+ */
26
93
  convert: (from: Address, to: Address, amount: bigint, reserve?: boolean) => bigint;
94
+ /**
95
+ * Tries to convert amount of token to USD, using latest known prices
96
+ * @param from
97
+ * @param amount
98
+ * @param reserve use reserve price feed instead of main
99
+ */
27
100
  convertToUSD: (from: Address, amount: bigint, reserve?: boolean) => bigint;
101
+ /**
102
+ * Tries to convert amount of USD to token, using latest known prices
103
+ * @param to
104
+ * @param amount
105
+ * @param reserve use reserve price feed instead of main
106
+ */
28
107
  convertFromUSD: (to: Address, amount: bigint, reserve?: boolean) => bigint;
108
+ /**
109
+ * Returns list of addresses that should be watched for events to sync state
110
+ */
111
+ watchAddresses: Set<Address>;
112
+ /**
113
+ * Returns human readable state of the oracle
114
+ */
115
+ stateHuman: (raw?: boolean) => PriceOracleStateHuman;
116
+ }
117
+ export interface DelegatedOracleMulticall {
118
+ call: ContractFunctionParameters<typeof iPriceFeedCompressorAbi, "view", "getPriceOracleState">;
119
+ onResult: (resp: ContractFunctionReturnType<typeof iPriceFeedCompressorAbi, "view", "getPriceOracleState">) => void;
29
120
  }
@@ -13,8 +13,9 @@ export interface V300StalenessPeriodPluginState extends IPluginState {
13
13
  events: StalenessEvent[];
14
14
  }
15
15
  /**
16
- * PriceFeedCompressor returns 0 as staleness period for reserve price feeds
17
- * This is because v3.0 oracle contract cannot return staleness period for reserve price feeds
16
+ * PriceFeedCompressor returns 0 as staleness period for price feeds in v3.0
17
+ * This is because v3.0 oracle contract cannot return staleness period for reserve price feeds.
18
+ * But compressor returns 0 both for main and reserve price feeds.
18
19
  * This plugin is a workaround to load staleness periods using oracle events
19
20
  */
20
21
  export declare class V300StalenessPeriodPlugin extends SDKConstruct implements IGearboxSDKPlugin<V300StalenessPeriodPluginState> {
@@ -10,4 +10,3 @@ export * from "./json.js";
10
10
  export * from "./mappers.js";
11
11
  export * from "./retry.js";
12
12
  export * from "./toAddress.js";
13
- export * from "./version.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "4.2.0-next.3",
3
+ "version": "5.0.0-next.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -1,93 +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 PriceFeedStore_exports = {};
20
- __export(PriceFeedStore_exports, {
21
- PriceFeedStore: () => PriceFeedStore
22
- });
23
- module.exports = __toCommonJS(PriceFeedStore_exports);
24
- var import_compressors = require("../abi/compressors.js");
25
- var import_iPriceFeedStore = require("../abi/iPriceFeedStore.js");
26
- var import_sdk = require("../sdk/index.js");
27
- class PriceFeedStore extends import_sdk.SDKConstruct {
28
- #store;
29
- #compressor;
30
- #logger;
31
- constructor(sdk) {
32
- super(sdk);
33
- this.#store = this.sdk.addressProvider.getAddress("PRICE_FEED_STORE");
34
- [this.#compressor] = this.sdk.addressProvider.getLatestVersion(
35
- import_sdk.AP_PRICE_FEED_COMPRESSOR
36
- );
37
- this.#logger = sdk.logger?.child?.({
38
- module: "PriceFeedStore"
39
- });
40
- }
41
- async load(update = true) {
42
- const pfMap = await this.provider.publicClient.readContract({
43
- address: this.#store,
44
- abi: import_iPriceFeedStore.iPriceFeedStoreAbi,
45
- functionName: "getTokenPriceFeedsMap"
46
- });
47
- const addresses = pfMap.flatMap((f) => f.priceFeeds);
48
- const nodes = await this.#loadFromCompressor(addresses, update);
49
- const result = new import_sdk.AddressMap();
50
- for (const { token, priceFeeds } of pfMap) {
51
- result.upsert(
52
- token,
53
- priceFeeds.map((pf) => nodes.find((n) => n.baseParams.addr === pf)).filter(Boolean)
54
- );
55
- }
56
- return result;
57
- }
58
- async #loadFromCompressor(priceFeeds, update = true) {
59
- let result = await this.provider.publicClient.readContract({
60
- address: this.#compressor,
61
- abi: import_compressors.iPriceFeedCompressorAbi,
62
- functionName: "loadPriceFeedTree",
63
- args: [priceFeeds]
64
- });
65
- if (update) {
66
- const feeds = result.map((f) => this.sdk.priceFeeds.create(f));
67
- const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(feeds);
68
- const [resp] = await (0, import_sdk.simulateWithPriceUpdates)(
69
- this.provider.publicClient,
70
- {
71
- priceUpdates: txs,
72
- contracts: [
73
- {
74
- address: this.#compressor,
75
- abi: import_compressors.iPriceFeedCompressorAbi,
76
- functionName: "loadPriceFeedTree",
77
- args: [priceFeeds]
78
- }
79
- ]
80
- }
81
- );
82
- return resp;
83
- }
84
- this.#logger?.debug(
85
- `loaded ${result.length} price feed nodes from compressor`
86
- );
87
- return [...result];
88
- }
89
- }
90
- // Annotate the CommonJS export names for ESM import in node:
91
- 0 && (module.exports = {
92
- PriceFeedStore
93
- });
@@ -1,74 +0,0 @@
1
- import { iPriceFeedCompressorAbi } from "../abi/compressors.js";
2
- import { iPriceFeedStoreAbi } from "../abi/iPriceFeedStore.js";
3
- import {
4
- AddressMap,
5
- AP_PRICE_FEED_COMPRESSOR,
6
- SDKConstruct,
7
- simulateWithPriceUpdates
8
- } from "../sdk/index.js";
9
- class PriceFeedStore extends SDKConstruct {
10
- #store;
11
- #compressor;
12
- #logger;
13
- constructor(sdk) {
14
- super(sdk);
15
- this.#store = this.sdk.addressProvider.getAddress("PRICE_FEED_STORE");
16
- [this.#compressor] = this.sdk.addressProvider.getLatestVersion(
17
- AP_PRICE_FEED_COMPRESSOR
18
- );
19
- this.#logger = sdk.logger?.child?.({
20
- module: "PriceFeedStore"
21
- });
22
- }
23
- async load(update = true) {
24
- const pfMap = await this.provider.publicClient.readContract({
25
- address: this.#store,
26
- abi: iPriceFeedStoreAbi,
27
- functionName: "getTokenPriceFeedsMap"
28
- });
29
- const addresses = pfMap.flatMap((f) => f.priceFeeds);
30
- const nodes = await this.#loadFromCompressor(addresses, update);
31
- const result = new AddressMap();
32
- for (const { token, priceFeeds } of pfMap) {
33
- result.upsert(
34
- token,
35
- priceFeeds.map((pf) => nodes.find((n) => n.baseParams.addr === pf)).filter(Boolean)
36
- );
37
- }
38
- return result;
39
- }
40
- async #loadFromCompressor(priceFeeds, update = true) {
41
- let result = await this.provider.publicClient.readContract({
42
- address: this.#compressor,
43
- abi: iPriceFeedCompressorAbi,
44
- functionName: "loadPriceFeedTree",
45
- args: [priceFeeds]
46
- });
47
- if (update) {
48
- const feeds = result.map((f) => this.sdk.priceFeeds.create(f));
49
- const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(feeds);
50
- const [resp] = await simulateWithPriceUpdates(
51
- this.provider.publicClient,
52
- {
53
- priceUpdates: txs,
54
- contracts: [
55
- {
56
- address: this.#compressor,
57
- abi: iPriceFeedCompressorAbi,
58
- functionName: "loadPriceFeedTree",
59
- args: [priceFeeds]
60
- }
61
- ]
62
- }
63
- );
64
- return resp;
65
- }
66
- this.#logger?.debug(
67
- `loaded ${result.length} price feed nodes from compressor`
68
- );
69
- return [...result];
70
- }
71
- }
72
- export {
73
- PriceFeedStore
74
- };
@@ -1,10 +0,0 @@
1
- function isV300(version) {
2
- return version >= 300 && version < 310;
3
- }
4
- function isV310(version) {
5
- return version >= 310 && version < 320;
6
- }
7
- export {
8
- isV300,
9
- isV310
10
- };
@@ -1,10 +0,0 @@
1
- import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
2
- import { iPriceFeedStoreAbi } from "../abi/iPriceFeedStore.js";
3
- import type { GearboxSDK, PriceFeedTreeNode, Unarray } from "../sdk/index.js";
4
- import { AddressMap, SDKConstruct } from "../sdk/index.js";
5
- export type ConnectedPriceFeed = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof iPriceFeedStoreAbi, "getTokenPriceFeedsMap">["outputs"]>[0]>;
6
- export declare class PriceFeedStore extends SDKConstruct {
7
- #private;
8
- constructor(sdk: GearboxSDK);
9
- load(update?: boolean): Promise<AddressMap<PriceFeedTreeNode[]>>;
10
- }
@@ -1,2 +0,0 @@
1
- export declare function isV300(version: number): boolean;
2
- export declare function isV310(version: number): boolean;