@gearbox-protocol/sdk 7.11.0-next.3 → 7.11.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.
Files changed (78) hide show
  1. package/dist/cjs/adapters/AdaptersPlugin.js +3 -2
  2. package/dist/cjs/bots/BotsPlugin.js +17 -29
  3. package/dist/cjs/dev/AccountsCounterPlugin.js +10 -19
  4. package/dist/cjs/dev/createTransport.js +2 -1
  5. package/dist/cjs/sdk/GearboxSDK.js +3 -13
  6. package/dist/cjs/sdk/chain/chains.js +21 -10
  7. package/dist/cjs/sdk/constants/address-provider.js +2 -1
  8. package/dist/cjs/sdk/constants/addresses.js +8 -4
  9. package/dist/cjs/sdk/constants/networks.js +5 -2
  10. package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +1 -3
  11. package/dist/cjs/sdk/router/RouterV300Contract.js +2 -1
  12. package/dist/cjs/sdk/sdk-gov-legacy/contracts/contracts.js +74 -37
  13. package/dist/cjs/sdk/sdk-gov-legacy/tokens/token.js +4 -2
  14. package/dist/cjs/sdk/sdk-gov-legacy/tokens/tokenData.js +2 -1
  15. package/dist/cjs/sdk/sdk-legacy/core/endpoint.js +2 -1
  16. package/dist/cjs/sdk/sdk-legacy/gearboxRewards/api.js +159 -94
  17. package/dist/cjs/sdk/sdk-legacy/gearboxRewards/apy.js +1 -1
  18. package/dist/cjs/sdk/sdk-legacy/index.js +2 -0
  19. package/dist/cjs/{pools7DAgo/types.js → sdk/sdk-legacy/pathfinder/core.js} +2 -2
  20. package/dist/cjs/{pools7DAgo → sdk/sdk-legacy/pathfinder}/index.js +4 -6
  21. package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +1 -0
  22. package/dist/cjs/zappers/ZappersPlugin.js +4 -13
  23. package/dist/esm/adapters/AdaptersPlugin.js +3 -2
  24. package/dist/esm/bots/BotsPlugin.js +17 -29
  25. package/dist/esm/dev/AccountsCounterPlugin.js +10 -19
  26. package/dist/esm/dev/createTransport.js +2 -1
  27. package/dist/esm/sdk/GearboxSDK.js +3 -13
  28. package/dist/esm/sdk/chain/chains.js +22 -10
  29. package/dist/esm/sdk/constants/address-provider.js +2 -1
  30. package/dist/esm/sdk/constants/addresses.js +8 -4
  31. package/dist/esm/sdk/constants/networks.js +5 -2
  32. package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +1 -3
  33. package/dist/esm/sdk/router/RouterV300Contract.js +2 -1
  34. package/dist/esm/sdk/sdk-gov-legacy/contracts/contracts.js +74 -37
  35. package/dist/esm/sdk/sdk-gov-legacy/tokens/token.js +4 -2
  36. package/dist/esm/sdk/sdk-gov-legacy/tokens/tokenData.js +2 -1
  37. package/dist/esm/sdk/sdk-legacy/core/endpoint.js +2 -1
  38. package/dist/esm/sdk/sdk-legacy/gearboxRewards/api.js +159 -94
  39. package/dist/esm/sdk/sdk-legacy/gearboxRewards/apy.js +1 -1
  40. package/dist/esm/sdk/sdk-legacy/index.js +1 -0
  41. package/dist/esm/sdk/sdk-legacy/pathfinder/index.js +1 -0
  42. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -0
  43. package/dist/esm/zappers/ZappersPlugin.js +4 -13
  44. package/dist/types/adapters/AdaptersPlugin.d.ts +4 -5
  45. package/dist/types/bots/BotsPlugin.d.ts +3 -5
  46. package/dist/types/bots/types.d.ts +2 -2
  47. package/dist/types/dev/AccountsCounterPlugin.d.ts +2 -4
  48. package/dist/types/sdk/GearboxSDK.d.ts +3 -4
  49. package/dist/types/sdk/chain/chains.d.ts +2 -2
  50. package/dist/types/sdk/plugins/V300StalenessPeriodPlugin.d.ts +2 -3
  51. package/dist/types/sdk/plugins/types.d.ts +15 -33
  52. package/dist/types/sdk/sdk-legacy/gearboxRewards/api.d.ts +27 -16
  53. package/dist/types/sdk/sdk-legacy/gearboxRewards/apy.d.ts +15 -9
  54. package/dist/types/sdk/sdk-legacy/index.d.ts +1 -0
  55. package/dist/types/sdk/sdk-legacy/pathfinder/core.d.ts +14 -0
  56. package/dist/types/sdk/sdk-legacy/pathfinder/index.d.ts +1 -0
  57. package/dist/types/zappers/ZappersPlugin.d.ts +4 -5
  58. package/package.json +1 -1
  59. package/dist/cjs/degenDistributors/DegenDistributorsPlugin.js +0 -110
  60. package/dist/cjs/degenDistributors/index.js +0 -24
  61. package/dist/cjs/degenDistributors/package.json +0 -1
  62. package/dist/cjs/degenDistributors/types.js +0 -16
  63. package/dist/cjs/pools7DAgo/Pools7DAgoPlugin.js +0 -116
  64. package/dist/cjs/pools7DAgo/package.json +0 -1
  65. package/dist/esm/degenDistributors/DegenDistributorsPlugin.js +0 -86
  66. package/dist/esm/degenDistributors/index.js +0 -2
  67. package/dist/esm/degenDistributors/package.json +0 -1
  68. package/dist/esm/pools7DAgo/Pools7DAgoPlugin.js +0 -99
  69. package/dist/esm/pools7DAgo/index.js +0 -2
  70. package/dist/esm/pools7DAgo/package.json +0 -1
  71. package/dist/esm/pools7DAgo/types.js +0 -0
  72. package/dist/types/degenDistributors/DegenDistributorsPlugin.d.ts +0 -22
  73. package/dist/types/degenDistributors/index.d.ts +0 -2
  74. package/dist/types/degenDistributors/types.d.ts +0 -4
  75. package/dist/types/pools7DAgo/Pools7DAgoPlugin.d.ts +0 -22
  76. package/dist/types/pools7DAgo/index.d.ts +0 -2
  77. package/dist/types/pools7DAgo/types.d.ts +0 -9
  78. /package/dist/esm/{degenDistributors/types.js → sdk/sdk-legacy/pathfinder/core.js} +0 -0
@@ -8,48 +8,10 @@ import { GearboxBackendApi } from "../core/endpoint.js";
8
8
  import { BigIntMath } from "../utils/math.js";
9
9
  import { MerkleXYZApi } from "./merklAPI.js";
10
10
  class GearboxRewardsApi {
11
- static async getLmRewardsV2({
12
- provider,
13
- account,
14
- currentTokenData,
15
- network,
16
- airdropDistributorAddress,
17
- reportError
18
- }) {
19
- if (!airdropDistributorAddress) return [];
20
- const [claimedRespUnsafe, merkleDataRespUnsafe] = await Promise.allSettled([
21
- this.getClaimed({ airdropDistributorAddress, provider, account }),
22
- this.getMerkle(provider, airdropDistributorAddress, network, account)
23
- ]);
24
- const claimedResp = this.extractFulfilled(claimedRespUnsafe, reportError, "getLmRewardsV2") || 0n;
25
- const merkleDataResp = this.extractFulfilled(
26
- merkleDataRespUnsafe,
27
- reportError,
28
- "getLmRewardsV2"
29
- );
30
- const amountOnContract = this.getAmountOnContract({
31
- account,
32
- merkleData: merkleDataResp
33
- });
34
- const diff = amountOnContract - claimedResp;
35
- const availableToClaimV2 = BigIntMath.max(0n, diff);
36
- const rewards = [
37
- {
38
- amount: availableToClaimV2,
39
- type: "merkleV2",
40
- rewardToken: currentTokenData.GEAR,
41
- rewardTokenDecimals: 18,
42
- rewardTokenSymbol: "GEAR"
43
- }
44
- ];
45
- return rewards;
46
- }
47
- static async getLmRewardsV3({
11
+ static async getLmRewardsInfo({
48
12
  pools,
49
- tokensList,
50
13
  provider,
51
- account,
52
- reportError
14
+ tokensList
53
15
  }) {
54
16
  const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
55
17
  p.stakedDieselToken.forEach((t) => {
@@ -60,85 +22,155 @@ class GearboxRewardsApi {
60
22
  });
61
23
  return acc;
62
24
  }, {});
63
- const stakedDieselTokens = TypedObjectUtils.keys(poolByStakedDiesel);
64
- const farmInfoCalls = stakedDieselTokens.map((address) => ({
25
+ const poolByDiesel = Object.values(pools).reduce(
26
+ (acc, p) => {
27
+ acc[p.dieselToken] = p.address;
28
+ return acc;
29
+ },
30
+ {}
31
+ );
32
+ const poolByItsToken = { ...poolByStakedDiesel, ...poolByDiesel };
33
+ const poolStakedTokens = TypedObjectUtils.keys(poolByStakedDiesel);
34
+ const allPoolTokens = TypedObjectUtils.keys(poolByItsToken);
35
+ const farmInfoCalls = poolStakedTokens.map((address) => ({
65
36
  address,
66
37
  abi: iFarmingPoolAbi,
67
38
  functionName: "farmInfo",
68
39
  args: []
69
40
  }));
70
- const rewardTokenCalls = stakedDieselTokens.map((address) => ({
41
+ const farmSupplyCalls = allPoolTokens.map((address) => ({
71
42
  address,
72
- abi: POOL_REWARDS_ABI,
73
- functionName: "rewardsToken",
43
+ abi: iFarmingPoolAbi,
44
+ functionName: "totalSupply",
74
45
  args: []
75
46
  }));
76
- const farmedCalls = stakedDieselTokens.map((address) => ({
47
+ const rewardTokenCalls = poolStakedTokens.map((address) => ({
77
48
  address,
78
- abi: iFarmingPoolAbi,
79
- functionName: "farmed",
80
- args: [account]
49
+ abi: POOL_REWARDS_ABI,
50
+ functionName: "rewardsToken",
51
+ args: []
81
52
  }));
82
- const [response] = await Promise.allSettled([
83
- provider.multicall({
84
- allowFailure: false,
85
- contracts: [...farmInfoCalls, ...rewardTokenCalls, ...farmedCalls]
86
- })
87
- ]);
88
- const safeResponse = this.extractFulfilled(response, reportError, "v3Rewards") || [];
53
+ const mc = await provider.multicall({
54
+ allowFailure: false,
55
+ contracts: [...farmInfoCalls, ...farmSupplyCalls, ...rewardTokenCalls]
56
+ });
57
+ const mcResponse = mc;
58
+ const [...restMCResponse] = mcResponse;
89
59
  const farmInfoCallsEnd = farmInfoCalls.length;
90
- const farmInfo = safeResponse.slice(
60
+ const farmInfo = restMCResponse.slice(
91
61
  0,
92
62
  farmInfoCallsEnd
93
63
  );
94
- const rewardTokenCallsEnd = farmInfoCallsEnd + rewardTokenCalls.length;
95
- const rewardTokens = safeResponse.slice(
64
+ const farmSupplyCallsEnd = farmInfoCallsEnd + farmSupplyCalls.length;
65
+ const farmSupply = restMCResponse.slice(
96
66
  farmInfoCallsEnd,
97
- rewardTokenCallsEnd
67
+ farmSupplyCallsEnd
98
68
  );
99
- const farmedCallsEnd = rewardTokenCallsEnd + farmedCalls.length;
100
- const farmedList = safeResponse.slice(
101
- rewardTokenCallsEnd,
102
- farmedCallsEnd
69
+ const rewardTokenCallsEnd = farmSupplyCallsEnd + rewardTokenCalls.length;
70
+ const rewardTokens = restMCResponse.slice(
71
+ farmSupplyCallsEnd,
72
+ rewardTokenCallsEnd
103
73
  );
104
- const gearboxLmRewards = stakedDieselTokens.map(
105
- (address, i) => {
106
- const pool = poolByStakedDiesel[address];
107
- const info = farmInfo[i];
108
- const rewardToken = rewardTokens[i]?.toLowerCase();
109
- const farmed = farmedList[i];
110
- if (!pool || !info || !rewardToken) return void 0;
111
- return {
112
- pool,
113
- poolToken: address,
114
- rewardToken,
115
- rewardTokenDecimals: tokensList[rewardToken]?.decimals || 18,
116
- rewardTokenSymbol: tokensList[rewardToken]?.symbol || "unknown",
117
- amount: farmed ?? 0n,
118
- type: "stakedV3"
119
- };
120
- }
74
+ const infoByPool = poolStakedTokens.reduce(
75
+ (acc, p, index) => {
76
+ const info = farmInfo[index];
77
+ if (info) acc[p] = info;
78
+ return acc;
79
+ },
80
+ {}
121
81
  );
122
- const { zero, nonZero } = gearboxLmRewards.reduce(
123
- (acc, r) => {
124
- if (r && r.amount > 0n) {
125
- acc.nonZero.push(r);
126
- } else if (r) {
127
- acc.zero.push(r);
82
+ const rewardTokenPool = poolStakedTokens.reduce(
83
+ (acc, p, index) => {
84
+ const token = rewardTokens[index];
85
+ if (token) {
86
+ acc[p] = token.toLowerCase();
128
87
  }
129
88
  return acc;
130
89
  },
131
- { nonZero: [], zero: [] }
90
+ {}
91
+ );
92
+ const stakedTokenRewards = allPoolTokens.reduce(
93
+ (acc, pool) => {
94
+ const info = infoByPool[pool];
95
+ const token = rewardTokenPool[pool];
96
+ const tokenData = tokensList[token];
97
+ const baseReward = info && tokenData ? {
98
+ pool: poolByItsToken[pool],
99
+ duration: BigInt(info.duration),
100
+ finished: BigInt(info.finished),
101
+ reward: info.reward,
102
+ balance: info.balance,
103
+ symbol: tokenData.symbol
104
+ } : void 0;
105
+ if (baseReward) acc.base[pool] = baseReward;
106
+ acc.all[pool] = [...baseReward ? [baseReward] : []];
107
+ return acc;
108
+ },
109
+ { base: {}, all: {} }
132
110
  );
133
- return [...nonZero, zero];
111
+ const rewardPoolsSupply = allPoolTokens.reduce(
112
+ (acc, address, i) => {
113
+ acc[address] = farmSupply[i] || 0n;
114
+ return acc;
115
+ },
116
+ {}
117
+ );
118
+ return {
119
+ rewardPoolsInfo: stakedTokenRewards.all,
120
+ baseRewardPoolsInfo: stakedTokenRewards.base,
121
+ rewardPoolsSupply
122
+ };
134
123
  }
135
- static async getLmRewardsMerkle({
124
+ static async getLmRewardsV2({
125
+ provider,
126
+ account,
127
+ currentTokenData,
128
+ network,
129
+ airdropDistributorAddress
130
+ }) {
131
+ if (!airdropDistributorAddress) return { rewards: [] };
132
+ const [claimedResp, merkleDataResp] = await Promise.all([
133
+ this.getClaimed({ airdropDistributorAddress, provider, account }),
134
+ this.getMerkle(provider, airdropDistributorAddress, network, account)
135
+ ]);
136
+ const amountOnContract = this.getAmountOnContract({
137
+ account,
138
+ merkleData: merkleDataResp
139
+ });
140
+ const diff = amountOnContract - claimedResp;
141
+ const availableToClaimV2 = BigIntMath.max(0n, diff);
142
+ const rewards = [
143
+ {
144
+ amount: availableToClaimV2,
145
+ type: "merkleV2",
146
+ rewardToken: currentTokenData.GEAR,
147
+ rewardTokenDecimals: 18,
148
+ rewardTokenSymbol: "GEAR"
149
+ }
150
+ ];
151
+ return { rewards };
152
+ }
153
+ static async getLmRewardsV3({
136
154
  pools,
155
+ baseRewardPoolsInfo,
156
+ currentTokenData,
157
+ tokensList,
158
+ provider,
137
159
  account,
138
160
  network,
139
161
  reportError
140
162
  }) {
141
- const [merkleXYZLMResponse] = await Promise.allSettled([
163
+ const poolTokens = Object.keys(baseRewardPoolsInfo);
164
+ const [gearboxLmResponse, merkleXYZLMResponse] = await Promise.allSettled([
165
+ provider.multicall({
166
+ allowFailure: false,
167
+ contracts: poolTokens.map((address) => ({
168
+ address,
169
+ abi: iFarmingPoolAbi,
170
+ functionName: "farmed",
171
+ args: [account]
172
+ }))
173
+ }),
142
174
  axios.get(
143
175
  MerkleXYZApi.getUserRewardsUrl({
144
176
  params: {
@@ -148,10 +180,15 @@ class GearboxRewardsApi {
148
180
  })
149
181
  )
150
182
  ]);
183
+ const gearboxLm = this.extractFulfilled(
184
+ gearboxLmResponse,
185
+ reportError,
186
+ "v3Rewards"
187
+ ) || [];
151
188
  const merkleXYZLm = this.extractFulfilled(
152
189
  merkleXYZLMResponse,
153
190
  reportError,
154
- "merkleXYZLm"
191
+ "merkleRewards"
155
192
  )?.data;
156
193
  const poolByItsToken = Object.values(pools).reduce((acc, p) => {
157
194
  p.stakedDieselToken.forEach((t) => {
@@ -189,7 +226,34 @@ class GearboxRewardsApi {
189
226
  });
190
227
  return acc;
191
228
  }, {});
192
- return Object.values(extraRewards);
229
+ const gearboxLmRewards = poolTokens.map((address, i) => {
230
+ const info = baseRewardPoolsInfo[address];
231
+ const rewardToken = currentTokenData[info.symbol];
232
+ return {
233
+ pool: info.pool,
234
+ poolToken: address,
235
+ rewardToken,
236
+ rewardTokenDecimals: tokensList[rewardToken]?.decimals || 18,
237
+ rewardTokenSymbol: info.symbol,
238
+ amount: gearboxLm[i] || 0n,
239
+ type: "stakedV3"
240
+ };
241
+ });
242
+ const { zero, nonZero } = gearboxLmRewards.reduce(
243
+ (acc, r) => {
244
+ const amount = r.amount || 0n;
245
+ if (amount > 0n) {
246
+ acc.nonZero.push(r);
247
+ } else {
248
+ acc.zero.push(r);
249
+ }
250
+ return acc;
251
+ },
252
+ { nonZero: [], zero: [] }
253
+ );
254
+ return {
255
+ rewards: [...nonZero, ...Object.values(extraRewards), zero]
256
+ };
193
257
  }
194
258
  static extractFulfilled(r, reportError, description) {
195
259
  if (r.status === "fulfilled") {
@@ -294,7 +358,8 @@ class GearboxRewardsApi {
294
358
  account,
295
359
  merkleData
296
360
  }) {
297
- const { amount } = merkleData?.claims?.[getAddress(account)] || {};
361
+ const { claims = {} } = merkleData || {};
362
+ const { amount } = claims[getAddress(account)] || {};
298
363
  return BigInt(amount || 0);
299
364
  }
300
365
  }
@@ -20,7 +20,7 @@ class GearboxRewardsApy {
20
20
  if (!isV3 || !stakedDieselToken) return [];
21
21
  const info = rewardPoolsInfo[stakedDieselToken];
22
22
  if (!info) return [];
23
- const extra = (Array.isArray(info) ? info : [info]).map(
23
+ const extra = info.map(
24
24
  (inf) => this.getPoolSingleExtraLmAPY_V3({
25
25
  ...restProps,
26
26
  stakedDieselToken,
@@ -9,6 +9,7 @@ export * from "./core/pool.js";
9
9
  export * from "./core/strategy.js";
10
10
  export * from "./core/transactions.js";
11
11
  export * from "./gearboxRewards/index.js";
12
+ export * from "./pathfinder/index.js";
12
13
  export * from "./payload/creditAccount.js";
13
14
  export * from "./payload/creditManager.js";
14
15
  export * from "./payload/creditSession.js";
@@ -0,0 +1 @@
1
+ export * from "./core.js";
@@ -79,6 +79,7 @@ async function simulateWithPriceUpdates(client, parameters) {
79
79
  if (mustThrow) {
80
80
  throw err;
81
81
  }
82
+ console.warn(err);
82
83
  }
83
84
  const restResults = multicallResults.slice(priceUpdates.length + 2).map((r) => r.result);
84
85
  return restResults;
@@ -8,16 +8,10 @@ import {
8
8
  class ZappersPlugin extends SDKConstruct {
9
9
  #zappers;
10
10
  version = 1;
11
- // public async attach(): Promise<void> {
12
- // await this.load(true);
13
- // }
14
- async syncState() {
15
- await this.load();
11
+ async attach() {
12
+ await this.loadZappers();
16
13
  }
17
- async load(force) {
18
- if (!force && this.loaded) {
19
- return this.state;
20
- }
14
+ async loadZappers() {
21
15
  this.#zappers = new AddressMap(void 0, "zappers");
22
16
  const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
23
17
  AP_PERIPHERY_COMPRESSOR,
@@ -54,7 +48,6 @@ class ZappersPlugin extends SDKConstruct {
54
48
  }
55
49
  }
56
50
  this.#loadZapperTokens();
57
- return this.state;
58
51
  }
59
52
  get zappers() {
60
53
  if (!this.#zappers) {
@@ -62,9 +55,6 @@ class ZappersPlugin extends SDKConstruct {
62
55
  }
63
56
  return this.#zappers;
64
57
  }
65
- get loaded() {
66
- return !!this.#zappers;
67
- }
68
58
  stateHuman(_) {
69
59
  return this.zappers.values().flatMap(
70
60
  (l) => l.flatMap((z) => ({
@@ -78,6 +68,7 @@ class ZappersPlugin extends SDKConstruct {
78
68
  }
79
69
  get state() {
80
70
  return {
71
+ version: this.version,
81
72
  zappers: this.zappers.asRecord()
82
73
  };
83
74
  }
@@ -1,11 +1,10 @@
1
- import type { BaseState, IBaseContract, IGearboxSDKPlugin } from "../sdk/index.js";
1
+ import type { BaseState, IBaseContract, IGearboxSDKPlugin, IPluginState } from "../sdk/index.js";
2
2
  import { SDKConstruct } from "../sdk/index.js";
3
- export declare class AdaptersPlugin extends SDKConstruct implements IGearboxSDKPlugin<{}> {
3
+ export declare class AdaptersPlugin extends SDKConstruct implements IGearboxSDKPlugin<IPluginState> {
4
4
  readonly name = "Adapters";
5
5
  readonly version = 1;
6
- readonly loaded = true;
7
6
  createContract(data: BaseState): IBaseContract | undefined;
8
7
  stateHuman(_?: boolean): {};
9
- get state(): {};
10
- hydrate(_: {}): void;
8
+ get state(): IPluginState;
9
+ hydrate(_: IPluginState): void;
11
10
  }
@@ -1,6 +1,6 @@
1
1
  import type { Address } from "viem";
2
2
  import type { GearboxSDK, IGearboxSDKPlugin } from "../sdk/index.js";
3
- import { AddressMap, SDKConstruct } from "../sdk/index.js";
3
+ import { SDKConstruct } from "../sdk/index.js";
4
4
  import { PartialLiquidationBotV300Contract } from "./PartialLiquidationBotV300Contract.js";
5
5
  import { PartialLiquidationBotV310Contract } from "./PartialLiquidationBotV310Contract.js";
6
6
  import { type BotsPluginState, type BotsPluginStateHuman, type BotState } from "./types.js";
@@ -13,13 +13,11 @@ export declare class BotsPlugin extends SDKConstruct implements IGearboxSDKPlugi
13
13
  #private;
14
14
  readonly version = 1;
15
15
  constructor(sdk: GearboxSDK);
16
+ attach(): Promise<void>;
16
17
  syncState(): Promise<void>;
17
- get loaded(): boolean;
18
- load(force?: boolean): Promise<BotsPluginState>;
19
- stateHuman(raw?: boolean): BotsPluginStateHuman;
20
- get botsByMarket(): AddressMap<PartialLiquidationBotContract[]>;
21
18
  botsByMarketConfigurator(mc: Address): PartialLiquidationBotContract[];
22
19
  get allBots(): PartialLiquidationBotContract[];
20
+ stateHuman(raw?: boolean): BotsPluginStateHuman;
23
21
  get state(): BotsPluginState;
24
22
  hydrate(state: BotsPluginState): void;
25
23
  }
@@ -1,7 +1,7 @@
1
1
  import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
2
2
  import type { Address } from "viem";
3
3
  import type { iPeripheryCompressorAbi } from "../abi/compressors.js";
4
- import type { BaseContractStateHuman, Unarray } from "../sdk/index.js";
4
+ import type { BaseContractStateHuman, IPluginState, Unarray } from "../sdk/index.js";
5
5
  export type BotState = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof iPeripheryCompressorAbi, "getBots">["outputs"]>>;
6
6
  export interface BotParameters {
7
7
  treasury: Address;
@@ -31,7 +31,7 @@ export interface BotsPluginStateHuman {
31
31
  */
32
32
  bots: Record<string, BotStateHuman[]>;
33
33
  }
34
- export interface BotsPluginState {
34
+ export interface BotsPluginState extends IPluginState {
35
35
  /**
36
36
  * Mapping market configurator address to bot states
37
37
  */
@@ -1,7 +1,7 @@
1
1
  import type { Address } from "viem";
2
- import type { IGearboxSDKPlugin } from "../sdk/index.js";
2
+ import type { IGearboxSDKPlugin, IPluginState } from "../sdk/index.js";
3
3
  import { AddressMap, SDKConstruct } from "../sdk/index.js";
4
- export interface AccountsCounterPluginState {
4
+ export interface AccountsCounterPluginState extends IPluginState {
5
5
  /**
6
6
  * Mapping of credit manager addresses to the number of accounts
7
7
  */
@@ -13,9 +13,7 @@ export declare class AccountsCounterPlugin extends SDKConstruct implements IGear
13
13
  attach(): Promise<void>;
14
14
  syncState(): Promise<void>;
15
15
  get accounts(): AddressMap<bigint>;
16
- get loaded(): boolean;
17
16
  forCreditManager(addr: Address): bigint;
18
- load(force?: boolean): Promise<AccountsCounterPluginState>;
19
17
  get state(): AccountsCounterPluginState;
20
18
  hydrate(state: AccountsCounterPluginState): void;
21
19
  }
@@ -60,7 +60,6 @@ export interface SyncStateOptions {
60
60
  }
61
61
  export type SDKHooks = {
62
62
  syncState: [SyncStateOptions];
63
- rehydrate: [SyncStateOptions];
64
63
  };
65
64
  export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
66
65
  #private;
@@ -84,8 +83,8 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
84
83
  * Token metadata such as symbol and decimals
85
84
  */
86
85
  readonly tokensMeta: TokensMeta;
87
- addHook: <K extends keyof SDKHooks>(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
88
- removeHook: <K extends keyof SDKHooks>(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
86
+ addHook: <K extends "syncState">(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
87
+ removeHook: <K extends "syncState">(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
89
88
  static attach<const Plugins extends PluginsMap>(options: SDKOptions<Plugins> & Partial<NetworkOptions> & ConnectionOptions & TransportOptions): Promise<GearboxSDK<Plugins>>;
90
89
  static hydrate<const Plugins extends PluginsMap>(options: HydrateOptions<Plugins> & ConnectionOptions & TransportOptions, state: GearboxState<Plugins>): GearboxSDK<Plugins>;
91
90
  private constructor();
@@ -97,7 +96,7 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
97
96
  /**
98
97
  * Rehydrate existing SDK from new state without re-creating instance
99
98
  */
100
- rehydrate(state: GearboxState<Plugins>): Promise<void>;
99
+ rehydrate(state: GearboxState<Plugins>): void;
101
100
  /**
102
101
  * Converts contract call into some human-friendly string
103
102
  * This method is safe and should not throw
@@ -23,8 +23,8 @@ export interface GearboxChain extends Chain {
23
23
  */
24
24
  alchemyDomain?: string;
25
25
  }
26
- export declare const SUPPORTED_NETWORKS: readonly ["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain"];
27
- export declare const NetworkType: z.ZodEnum<["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain"]>;
26
+ export declare const SUPPORTED_NETWORKS: readonly ["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain", "Etherlink"];
27
+ export declare const NetworkType: z.ZodEnum<["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain", "Etherlink"]>;
28
28
  export type NetworkType = z.infer<typeof NetworkType>;
29
29
  export declare const chains: Record<NetworkType, GearboxChain>;
30
30
  export declare function getChain(chainIdOrNetworkType: number | bigint | NetworkType): GearboxChain;
@@ -1,7 +1,7 @@
1
1
  import type { Address } from "viem";
2
2
  import { SDKConstruct } from "../base/index.js";
3
3
  import type { GearboxSDK } from "../GearboxSDK.js";
4
- import type { IGearboxSDKPlugin } from "./types.js";
4
+ import type { IGearboxSDKPlugin, IPluginState } from "./types.js";
5
5
  export interface StalenessEvent {
6
6
  oracle: Address;
7
7
  priceFeed: Address;
@@ -9,7 +9,7 @@ export interface StalenessEvent {
9
9
  stalenessPeriod: number;
10
10
  reserve: boolean;
11
11
  }
12
- export interface V300StalenessPeriodPluginState {
12
+ export interface V300StalenessPeriodPluginState extends IPluginState {
13
13
  events: StalenessEvent[];
14
14
  }
15
15
  /**
@@ -22,7 +22,6 @@ export declare class V300StalenessPeriodPlugin extends SDKConstruct implements I
22
22
  #private;
23
23
  readonly version = 1;
24
24
  constructor(sdk: GearboxSDK);
25
- get loaded(): boolean;
26
25
  attach(): Promise<void>;
27
26
  syncState(): Promise<void>;
28
27
  get state(): V300StalenessPeriodPluginState;
@@ -1,47 +1,20 @@
1
1
  import type { BaseState, IBaseContract } from "../base/index.js";
2
2
  import type { GearboxSDK } from "../GearboxSDK.js";
3
- export type IPluginState<State extends Record<keyof State, unknown> = {}> = {
3
+ export interface IPluginState {
4
4
  version: number;
5
- } & ({
6
- loaded: false;
7
- } | ({
8
- loaded: true;
9
- } & State));
10
- export type IGearboxSDKPluginConstructor<TState extends Record<keyof TState, unknown>, TPlugin extends IGearboxSDKPlugin<TState>> = new (sdk: GearboxSDK<any>) => TPlugin;
11
- export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown> = {}> {
5
+ }
6
+ export type IGearboxSDKPluginConstructor<TState extends IPluginState | undefined, TPlugin extends IGearboxSDKPlugin<TState>> = new (sdk: GearboxSDK<any>) => TPlugin;
7
+ export interface IGearboxSDKPlugin<TState extends IPluginState | undefined> {
12
8
  /**
13
9
  * Plugin version, used to check if the plugin state is compatible with the plugin during hydration
14
10
  */
15
11
  version: number;
16
- /**
17
- * Indicates that plugins state is ready to use
18
- * It does not matter how this state was obtained, be it via attach, hydrate or on-demand load
19
- */
20
- loaded: boolean;
21
- /**
22
- * Plugin state, can be hydarted/dehydrated
23
- */
24
- state: TState;
25
- /**
26
- * Loads state on demand
27
- * If it's already loaded, does nothing and returns the same state, unless force is set to true
28
- * @param force
29
- * @returns
30
- */
31
- load?: (force?: boolean) => Promise<TState>;
32
12
  /**
33
13
  * Called after SDK is attached
34
- * Plugins are not required to implement this. For example plugin can be stateless, or load state on demand only
35
14
  * @param sdk
36
15
  * @returns
37
16
  */
38
17
  attach?: () => Promise<void>;
39
- /**
40
- * Loads plugin state from dehydrated state
41
- * @param state
42
- * @returns
43
- */
44
- hydrate?: (state: TState) => void;
45
18
  /**
46
19
  * Called after SDK state is already synced, meaning that block number and timestamp are accessible from SDK
47
20
  *
@@ -51,7 +24,6 @@ export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown>
51
24
  syncState?: () => Promise<void>;
52
25
  /**
53
26
  * Can be called by SDK to create some auxiliary contracts, such as zappers and adapters
54
- * Otherwise they are created as BaseContract instances by sdk
55
27
  * @param params
56
28
  * @returns
57
29
  */
@@ -62,11 +34,21 @@ export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown>
62
34
  * @returns
63
35
  */
64
36
  stateHuman?: (raw?: boolean) => unknown;
37
+ /**
38
+ * Plugin state, can be hydarted/dehydrated
39
+ */
40
+ state: TState;
41
+ /**
42
+ * Loads plugin state from dehydrated state
43
+ * @param state
44
+ * @returns
45
+ */
46
+ hydrate?: (state: TState) => void;
65
47
  }
66
48
  /**
67
49
  * Helper type that extracts the state type from a plugin instance
68
50
  */
69
- export type PluginState<T> = T extends IGearboxSDKPlugin<infer TState> ? IPluginState<TState> : never;
51
+ export type PluginState<T> = T extends IGearboxSDKPlugin<infer TState> ? TState : never;
70
52
  /**
71
53
  * Mapping between plugin name and plugin instance
72
54
  */