@gearbox-protocol/sdk 3.0.0-vfour.344 → 3.0.0-vfour.346

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.
@@ -111,7 +111,7 @@ class AdaptersPlugin extends import_sdk.SDKConstruct {
111
111
  }
112
112
  }
113
113
  }
114
- stateHuman(raw) {
114
+ stateHuman(_) {
115
115
  return {};
116
116
  }
117
117
  }
@@ -216,21 +216,21 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
216
216
  * Implements {@link IRouterContract.findAllSwaps}
217
217
  * @deprecated v3.0 legacy method
218
218
  */
219
- findAllSwaps(props) {
219
+ findAllSwaps(_) {
220
220
  throw ERR_NOT_IMPLEMENTED;
221
221
  }
222
222
  /**
223
223
  * Implements {@link IRouterContract.getAvailableConnectors}
224
224
  * @deprecated v3.0 legacy method
225
225
  */
226
- getAvailableConnectors(collateralTokens) {
226
+ getAvailableConnectors(_) {
227
227
  throw ERR_NOT_IMPLEMENTED;
228
228
  }
229
229
  /**
230
230
  * Implements {@link IRouterContract.getFindClosePathInput}
231
231
  * @deprecated v3.0 legacy method
232
232
  */
233
- getFindClosePathInput(ca, cm, balances) {
233
+ getFindClosePathInput(_, __, ___) {
234
234
  throw ERR_NOT_IMPLEMENTED;
235
235
  }
236
236
  }
@@ -212,6 +212,10 @@ class CreditAccountData_Legacy {
212
212
  const max = underlyingPrice > 0 ? assetsLTMoney * 10n ** BigInt(underlyingDecimals) / underlyingPrice / targetHF / 10n ** BigInt(import_constants.WAD_DECIMALS_POW - import_constants.PRICE_DECIMALS_POW) : 0n;
213
213
  return max;
214
214
  }
215
+ // [
216
+ // Sum(amount_i * price_i * apy_i - quota_i * quotaPrice * quotaRate_i * (1 + feeInterest)) -
217
+ // debt * debtPrice * baseRateWithFee
218
+ // ] / (totalValue - debt) * debtPrice
215
219
  static calcOverallAPY({
216
220
  caAssets,
217
221
  lpAPY,
@@ -250,16 +254,18 @@ class CreditAccountData_Legacy {
250
254
  },
251
255
  0n
252
256
  );
253
- const assetAPYAmountInUnderlying = import_price.PriceUtils.convertByPrice(
254
- assetAPYMoney,
255
- {
256
- price: underlyingPrice || import_constants.PRICE_DECIMALS,
257
- decimals: underlyingTokenDecimals
258
- }
257
+ const debtMoney = import_price.PriceUtils.calcTotalPrice(
258
+ underlyingPrice || 0n,
259
+ debt,
260
+ underlyingTokenDecimals
261
+ );
262
+ const debtAPYMoney = debtMoney * BigInt(baseRateWithFee);
263
+ const yourAssetsMoney = import_price.PriceUtils.calcTotalPrice(
264
+ underlyingPrice || import_constants.PRICE_DECIMALS,
265
+ totalValue - debt,
266
+ underlyingTokenDecimals
259
267
  );
260
- const debtAPY = debt * BigInt(baseRateWithFee);
261
- const yourAssets = totalValue - debt;
262
- const apyInPercent = (assetAPYAmountInUnderlying - debtAPY) / yourAssets;
268
+ const apyInPercent = (assetAPYMoney - debtAPYMoney) / yourAssetsMoney;
263
269
  return apyInPercent;
264
270
  }
265
271
  hash() {
@@ -26,7 +26,6 @@ var import_constants = require("../../constants/index.js");
26
26
  var import_utils = require("../../utils/index.js");
27
27
  class CreditManagerData_Legacy {
28
28
  address;
29
- type;
30
29
  underlyingToken;
31
30
  pool;
32
31
  creditFacade;
@@ -43,7 +42,6 @@ class CreditManagerData_Legacy {
43
42
  isBorrowingForbidden;
44
43
  maxEnabledTokensLength;
45
44
  name;
46
- tier;
47
45
  marketConfigurator;
48
46
  baseBorrowRate;
49
47
  minDebt;
@@ -59,6 +57,7 @@ class CreditManagerData_Legacy {
59
57
  collateralTokens = [];
60
58
  supportedTokens = {};
61
59
  usableTokens = {};
60
+ forbiddenTokens = {};
62
61
  adapters = {};
63
62
  contractsByAdapter = {};
64
63
  liquidationThresholds;
@@ -66,10 +65,8 @@ class CreditManagerData_Legacy {
66
65
  constructor(payload) {
67
66
  this.address = payload.addr.toLowerCase();
68
67
  this.underlyingToken = payload.underlying.toLowerCase();
69
- this.type = CreditManagerData_Legacy.getType(payload.name || "");
70
68
  this.name = payload.name;
71
69
  this.pool = payload.pool.toLowerCase();
72
- this.tier = CreditManagerData_Legacy.getTier(payload.name);
73
70
  this.creditFacade = payload.creditFacade.toLowerCase();
74
71
  this.creditConfigurator = payload.creditConfigurator.toLowerCase();
75
72
  this.degenNFT = payload.degenNFT.toLowerCase();
@@ -126,12 +123,15 @@ class CreditManagerData_Legacy {
126
123
  },
127
124
  {}
128
125
  );
129
- payload.collateralTokens.forEach((t) => {
126
+ payload.collateralTokens.forEach((t, index) => {
130
127
  const tLc = t.toLowerCase();
128
+ const mask = BigInt(1 << index);
129
+ const isForbidden = (mask & payload.forbiddenTokenMask) !== 0n;
131
130
  const zeroLt = this.liquidationThresholds[tLc] === 0n;
132
131
  const quotaNotActive = this.quotas[tLc]?.isActive === false;
133
- const allowed = !zeroLt && !quotaNotActive;
132
+ const allowed = !zeroLt && !quotaNotActive && !isForbidden;
134
133
  if (allowed) this.usableTokens[tLc] = true;
134
+ if (isForbidden) this.forbiddenTokens[tLc] = true;
135
135
  this.collateralTokens.push(tLc);
136
136
  this.supportedTokens[tLc] = true;
137
137
  });
@@ -139,22 +139,8 @@ class CreditManagerData_Legacy {
139
139
  isQuoted(token) {
140
140
  return !!this.quotas[token];
141
141
  }
142
- static getTier(name) {
143
- const DEFAULT_TIER = 99;
144
- const l = name.split(" ") || [];
145
- const index = l.findIndex((w) => w.toLowerCase() === "tier");
146
- if (index < 0) return DEFAULT_TIER;
147
- const number = l[index + 1];
148
- const n = Number(number || DEFAULT_TIER);
149
- return Number.isNaN(n) ? DEFAULT_TIER : n;
150
- }
151
- static getType(name) {
152
- const [identity = ""] = name.split(" ") || [];
153
- const lc = identity.toLowerCase();
154
- if (lc === "farm") return "farm";
155
- if (lc === "trade") return "trade";
156
- if (lc === "restaking") return "restaking";
157
- return "universal";
142
+ isForbidden(token) {
143
+ return !!this.forbiddenTokens[token];
158
144
  }
159
145
  }
160
146
  class ChartsCreditManagerData {
@@ -165,7 +151,6 @@ class ChartsCreditManagerData {
165
151
  pool;
166
152
  version;
167
153
  name;
168
- tier;
169
154
  borrowRate;
170
155
  borrowRateOld;
171
156
  borrowRateChange;
@@ -210,7 +195,6 @@ class ChartsCreditManagerData {
210
195
  this.pool = (payload.poolAddress || "").toLowerCase();
211
196
  this.version = payload.version || 2;
212
197
  this.name = payload.name || "";
213
- this.tier = CreditManagerData_Legacy.getTier(payload.name || "");
214
198
  this.borrowRate = Number(
215
199
  (0, import_utils.toBigInt)(payload.borrowRate || 0) * ((0, import_utils.toBigInt)(payload.feeInterest || 0) + import_constants.PERCENTAGE_FACTOR) * import_constants.PERCENTAGE_DECIMALS / import_constants.RAY
216
200
  );
@@ -28,6 +28,10 @@ class PositionUtils {
28
28
  const maxLeverage = import_constants.PERCENTAGE_FACTOR * import_constants.LEVERAGE_DECIMALS / (import_constants.PERCENTAGE_FACTOR - maxThreshold);
29
29
  return Number(maxLeverage - import_constants.LEVERAGE_DECIMALS);
30
30
  }
31
+ // [apy - quotaRate * (1 + feeInterest)] +
32
+ // [
33
+ // apy - baseRateWithFee - quotaRate * (1 + feeInterest)
34
+ // ] * (leverage - 1)
31
35
  static maxAPY({
32
36
  apy,
33
37
  leverage,
@@ -76,7 +76,7 @@ class ZappersPlugin extends import_sdk.SDKConstruct {
76
76
  }
77
77
  return this.#zappers;
78
78
  }
79
- stateHuman(raw) {
79
+ stateHuman(_) {
80
80
  return this.zappers.values().flatMap(
81
81
  (l) => l.flatMap((z) => ({
82
82
  address: z.baseParams.addr,
@@ -88,7 +88,7 @@ class AdaptersPlugin extends SDKConstruct {
88
88
  }
89
89
  }
90
90
  }
91
- stateHuman(raw) {
91
+ stateHuman(_) {
92
92
  return {};
93
93
  }
94
94
  }
@@ -193,21 +193,21 @@ class RouterV310Contract extends AbstractRouterContract {
193
193
  * Implements {@link IRouterContract.findAllSwaps}
194
194
  * @deprecated v3.0 legacy method
195
195
  */
196
- findAllSwaps(props) {
196
+ findAllSwaps(_) {
197
197
  throw ERR_NOT_IMPLEMENTED;
198
198
  }
199
199
  /**
200
200
  * Implements {@link IRouterContract.getAvailableConnectors}
201
201
  * @deprecated v3.0 legacy method
202
202
  */
203
- getAvailableConnectors(collateralTokens) {
203
+ getAvailableConnectors(_) {
204
204
  throw ERR_NOT_IMPLEMENTED;
205
205
  }
206
206
  /**
207
207
  * Implements {@link IRouterContract.getFindClosePathInput}
208
208
  * @deprecated v3.0 legacy method
209
209
  */
210
- getFindClosePathInput(ca, cm, balances) {
210
+ getFindClosePathInput(_, __, ___) {
211
211
  throw ERR_NOT_IMPLEMENTED;
212
212
  }
213
213
  }
@@ -198,6 +198,10 @@ class CreditAccountData_Legacy {
198
198
  const max = underlyingPrice > 0 ? assetsLTMoney * 10n ** BigInt(underlyingDecimals) / underlyingPrice / targetHF / 10n ** BigInt(WAD_DECIMALS_POW - PRICE_DECIMALS_POW) : 0n;
199
199
  return max;
200
200
  }
201
+ // [
202
+ // Sum(amount_i * price_i * apy_i - quota_i * quotaPrice * quotaRate_i * (1 + feeInterest)) -
203
+ // debt * debtPrice * baseRateWithFee
204
+ // ] / (totalValue - debt) * debtPrice
201
205
  static calcOverallAPY({
202
206
  caAssets,
203
207
  lpAPY,
@@ -236,16 +240,18 @@ class CreditAccountData_Legacy {
236
240
  },
237
241
  0n
238
242
  );
239
- const assetAPYAmountInUnderlying = PriceUtils.convertByPrice(
240
- assetAPYMoney,
241
- {
242
- price: underlyingPrice || PRICE_DECIMALS,
243
- decimals: underlyingTokenDecimals
244
- }
243
+ const debtMoney = PriceUtils.calcTotalPrice(
244
+ underlyingPrice || 0n,
245
+ debt,
246
+ underlyingTokenDecimals
247
+ );
248
+ const debtAPYMoney = debtMoney * BigInt(baseRateWithFee);
249
+ const yourAssetsMoney = PriceUtils.calcTotalPrice(
250
+ underlyingPrice || PRICE_DECIMALS,
251
+ totalValue - debt,
252
+ underlyingTokenDecimals
245
253
  );
246
- const debtAPY = debt * BigInt(baseRateWithFee);
247
- const yourAssets = totalValue - debt;
248
- const apyInPercent = (assetAPYAmountInUnderlying - debtAPY) / yourAssets;
254
+ const apyInPercent = (assetAPYMoney - debtAPYMoney) / yourAssetsMoney;
249
255
  return apyInPercent;
250
256
  }
251
257
  hash() {
@@ -6,7 +6,6 @@ import {
6
6
  import { toBigInt } from "../../utils/index.js";
7
7
  class CreditManagerData_Legacy {
8
8
  address;
9
- type;
10
9
  underlyingToken;
11
10
  pool;
12
11
  creditFacade;
@@ -23,7 +22,6 @@ class CreditManagerData_Legacy {
23
22
  isBorrowingForbidden;
24
23
  maxEnabledTokensLength;
25
24
  name;
26
- tier;
27
25
  marketConfigurator;
28
26
  baseBorrowRate;
29
27
  minDebt;
@@ -39,6 +37,7 @@ class CreditManagerData_Legacy {
39
37
  collateralTokens = [];
40
38
  supportedTokens = {};
41
39
  usableTokens = {};
40
+ forbiddenTokens = {};
42
41
  adapters = {};
43
42
  contractsByAdapter = {};
44
43
  liquidationThresholds;
@@ -46,10 +45,8 @@ class CreditManagerData_Legacy {
46
45
  constructor(payload) {
47
46
  this.address = payload.addr.toLowerCase();
48
47
  this.underlyingToken = payload.underlying.toLowerCase();
49
- this.type = CreditManagerData_Legacy.getType(payload.name || "");
50
48
  this.name = payload.name;
51
49
  this.pool = payload.pool.toLowerCase();
52
- this.tier = CreditManagerData_Legacy.getTier(payload.name);
53
50
  this.creditFacade = payload.creditFacade.toLowerCase();
54
51
  this.creditConfigurator = payload.creditConfigurator.toLowerCase();
55
52
  this.degenNFT = payload.degenNFT.toLowerCase();
@@ -106,12 +103,15 @@ class CreditManagerData_Legacy {
106
103
  },
107
104
  {}
108
105
  );
109
- payload.collateralTokens.forEach((t) => {
106
+ payload.collateralTokens.forEach((t, index) => {
110
107
  const tLc = t.toLowerCase();
108
+ const mask = BigInt(1 << index);
109
+ const isForbidden = (mask & payload.forbiddenTokenMask) !== 0n;
111
110
  const zeroLt = this.liquidationThresholds[tLc] === 0n;
112
111
  const quotaNotActive = this.quotas[tLc]?.isActive === false;
113
- const allowed = !zeroLt && !quotaNotActive;
112
+ const allowed = !zeroLt && !quotaNotActive && !isForbidden;
114
113
  if (allowed) this.usableTokens[tLc] = true;
114
+ if (isForbidden) this.forbiddenTokens[tLc] = true;
115
115
  this.collateralTokens.push(tLc);
116
116
  this.supportedTokens[tLc] = true;
117
117
  });
@@ -119,22 +119,8 @@ class CreditManagerData_Legacy {
119
119
  isQuoted(token) {
120
120
  return !!this.quotas[token];
121
121
  }
122
- static getTier(name) {
123
- const DEFAULT_TIER = 99;
124
- const l = name.split(" ") || [];
125
- const index = l.findIndex((w) => w.toLowerCase() === "tier");
126
- if (index < 0) return DEFAULT_TIER;
127
- const number = l[index + 1];
128
- const n = Number(number || DEFAULT_TIER);
129
- return Number.isNaN(n) ? DEFAULT_TIER : n;
130
- }
131
- static getType(name) {
132
- const [identity = ""] = name.split(" ") || [];
133
- const lc = identity.toLowerCase();
134
- if (lc === "farm") return "farm";
135
- if (lc === "trade") return "trade";
136
- if (lc === "restaking") return "restaking";
137
- return "universal";
122
+ isForbidden(token) {
123
+ return !!this.forbiddenTokens[token];
138
124
  }
139
125
  }
140
126
  class ChartsCreditManagerData {
@@ -145,7 +131,6 @@ class ChartsCreditManagerData {
145
131
  pool;
146
132
  version;
147
133
  name;
148
- tier;
149
134
  borrowRate;
150
135
  borrowRateOld;
151
136
  borrowRateChange;
@@ -190,7 +175,6 @@ class ChartsCreditManagerData {
190
175
  this.pool = (payload.poolAddress || "").toLowerCase();
191
176
  this.version = payload.version || 2;
192
177
  this.name = payload.name || "";
193
- this.tier = CreditManagerData_Legacy.getTier(payload.name || "");
194
178
  this.borrowRate = Number(
195
179
  toBigInt(payload.borrowRate || 0) * (toBigInt(payload.feeInterest || 0) + PERCENTAGE_FACTOR) * PERCENTAGE_DECIMALS / RAY
196
180
  );
@@ -5,6 +5,10 @@ class PositionUtils {
5
5
  const maxLeverage = PERCENTAGE_FACTOR * LEVERAGE_DECIMALS / (PERCENTAGE_FACTOR - maxThreshold);
6
6
  return Number(maxLeverage - LEVERAGE_DECIMALS);
7
7
  }
8
+ // [apy - quotaRate * (1 + feeInterest)] +
9
+ // [
10
+ // apy - baseRateWithFee - quotaRate * (1 + feeInterest)
11
+ // ] * (leverage - 1)
8
12
  static maxAPY({
9
13
  apy,
10
14
  leverage,
@@ -56,7 +56,7 @@ class ZappersPlugin extends SDKConstruct {
56
56
  }
57
57
  return this.#zappers;
58
58
  }
59
- stateHuman(raw) {
59
+ stateHuman(_) {
60
60
  return this.zappers.values().flatMap(
61
61
  (l) => l.flatMap((z) => ({
62
62
  address: z.baseParams.addr,
@@ -3,5 +3,5 @@ import { SDKConstruct } from "../sdk/index.js";
3
3
  export declare class AdaptersPlugin extends SDKConstruct implements IGearboxSDKPlugin {
4
4
  readonly name = "Adapters";
5
5
  createContract(data: BaseState): IBaseContract | undefined;
6
- stateHuman(raw?: boolean): {};
6
+ stateHuman(_?: boolean): {};
7
7
  }
@@ -368,16 +368,16 @@ export declare class RouterV310Contract extends AbstractRouterContract<abi> impl
368
368
  * Implements {@link IRouterContract.findAllSwaps}
369
369
  * @deprecated v3.0 legacy method
370
370
  */
371
- findAllSwaps(props: FindAllSwapsProps): Promise<RouterResult[]>;
371
+ findAllSwaps(_: FindAllSwapsProps): Promise<RouterResult[]>;
372
372
  /**
373
373
  * Implements {@link IRouterContract.getAvailableConnectors}
374
374
  * @deprecated v3.0 legacy method
375
375
  */
376
- getAvailableConnectors(collateralTokens: Address[]): Address[];
376
+ getAvailableConnectors(_: Address[]): Address[];
377
377
  /**
378
378
  * Implements {@link IRouterContract.getFindClosePathInput}
379
379
  * @deprecated v3.0 legacy method
380
380
  */
381
- getFindClosePathInput(ca: RouterCASlice, cm: RouterCMSlice, balances?: Leftovers): FindClosePathInput;
381
+ getFindClosePathInput(_: RouterCASlice, __: RouterCMSlice, ___?: Leftovers): FindClosePathInput;
382
382
  }
383
383
  export {};
@@ -1,9 +1,7 @@
1
1
  import type { Address } from "viem";
2
2
  import type { ChartsCreditManagerPayload, CreditManagerDataPayload, QuotaInfo } from "../payload/creditManager.js";
3
- export type CreditManagerType = "universal" | "trade" | "farm" | "restaking";
4
3
  export declare class CreditManagerData_Legacy {
5
4
  readonly address: Address;
6
- readonly type: CreditManagerType;
7
5
  readonly underlyingToken: Address;
8
6
  readonly pool: Address;
9
7
  readonly creditFacade: Address;
@@ -16,7 +14,6 @@ export declare class CreditManagerData_Legacy {
16
14
  readonly isBorrowingForbidden: boolean;
17
15
  readonly maxEnabledTokensLength: number;
18
16
  readonly name: string;
19
- readonly tier: number;
20
17
  readonly marketConfigurator: Address;
21
18
  readonly baseBorrowRate: number;
22
19
  readonly minDebt: bigint;
@@ -32,14 +29,14 @@ export declare class CreditManagerData_Legacy {
32
29
  readonly collateralTokens: Array<Address>;
33
30
  readonly supportedTokens: Record<Address, true>;
34
31
  readonly usableTokens: Record<Address, true>;
32
+ readonly forbiddenTokens: Record<Address, true>;
35
33
  readonly adapters: Record<Address, CreditManagerDataPayload["adapters"][1]>;
36
34
  readonly contractsByAdapter: Record<Address, Address>;
37
35
  readonly liquidationThresholds: Record<Address, bigint>;
38
36
  readonly quotas: Record<Address, QuotaInfo>;
39
37
  constructor(payload: CreditManagerDataPayload);
40
38
  isQuoted(token: Address): boolean;
41
- static getTier(name: string): number;
42
- static getType(name: string): CreditManagerType;
39
+ isForbidden(token: Address): boolean;
43
40
  }
44
41
  export declare class ChartsCreditManagerData {
45
42
  readonly address: Address;
@@ -49,7 +46,6 @@ export declare class ChartsCreditManagerData {
49
46
  readonly pool: Address;
50
47
  readonly version: number;
51
48
  readonly name: string;
52
- readonly tier: number;
53
49
  readonly borrowRate: number;
54
50
  readonly borrowRateOld: number;
55
51
  readonly borrowRateChange: number;
@@ -6,5 +6,5 @@ export declare class ZappersPlugin extends SDKConstruct implements IGearboxSDKPl
6
6
  attach(): Promise<void>;
7
7
  loadZappers(): Promise<void>;
8
8
  get zappers(): AddressMap<ZapperDataFull[]>;
9
- stateHuman(raw?: boolean): ZapperStateHuman[];
9
+ stateHuman(_?: boolean): ZapperStateHuman[];
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.344",
3
+ "version": "3.0.0-vfour.346",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",