@gearbox-protocol/sdk 3.0.0-next.236 → 3.0.0-next.238

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 (114) hide show
  1. package/contracts/index.sol +4 -0
  2. package/lib/apy/index.d.ts +0 -1
  3. package/lib/apy/index.js +0 -1
  4. package/lib/core/creditAccount.d.ts +5 -5
  5. package/lib/core/creditAccount.js +11 -13
  6. package/lib/core/creditManager.d.ts +16 -0
  7. package/lib/core/creditManager.js +154 -0
  8. package/lib/core/pool.d.ts +6 -0
  9. package/lib/core/pool.js +11 -0
  10. package/lib/core/protocols.js +4 -0
  11. package/lib/core/{rewardClaimer.d.ts → rewardClaimer/index.d.ts} +10 -5
  12. package/lib/core/rewardClaimer/index.js +34 -0
  13. package/lib/core/{rewardConvex.d.ts → rewardClaimer/rewardConvex.d.ts} +3 -3
  14. package/lib/core/{rewardConvex.js → rewardClaimer/rewardConvex.js} +7 -8
  15. package/lib/core/{rewardConvex.spec.js → rewardClaimer/rewardConvex.spec.js} +1 -2
  16. package/lib/core/rewardClaimer/stakingRewards.d.ts +34 -0
  17. package/lib/core/rewardClaimer/stakingRewards.js +133 -0
  18. package/lib/core/trade.d.ts +38 -0
  19. package/lib/core/trade.js +110 -0
  20. package/lib/gearboxRewards/api.d.ts +2 -8
  21. package/lib/gearboxRewards/api.js +15 -31
  22. package/lib/index.d.ts +2 -0
  23. package/lib/index.js +2 -0
  24. package/lib/parsers/ERC20Parser.d.ts +8 -0
  25. package/lib/parsers/ERC20Parser.js +36 -0
  26. package/lib/parsers/aaveV2LendingPoolAdapterParser.d.ts +8 -0
  27. package/lib/parsers/aaveV2LendingPoolAdapterParser.js +21 -0
  28. package/lib/parsers/aaveV2WrappedATokenAdapterParser.d.ts +8 -0
  29. package/lib/parsers/aaveV2WrappedATokenAdapterParser.js +21 -0
  30. package/lib/parsers/abstractParser.d.ts +30 -0
  31. package/lib/parsers/abstractParser.js +61 -0
  32. package/lib/parsers/balancerV2VaultParser.d.ts +8 -0
  33. package/lib/parsers/balancerV2VaultParser.js +32 -0
  34. package/lib/parsers/compoundV2CTokenAdapterParser.d.ts +8 -0
  35. package/lib/parsers/compoundV2CTokenAdapterParser.js +21 -0
  36. package/lib/parsers/convexBaseRewardPoolAdapterParser.d.ts +10 -0
  37. package/lib/parsers/convexBaseRewardPoolAdapterParser.js +50 -0
  38. package/lib/parsers/convexBoosterAdapterParser.d.ts +10 -0
  39. package/lib/parsers/convexBoosterAdapterParser.js +44 -0
  40. package/lib/parsers/convextRewardPoolParser.d.ts +8 -0
  41. package/lib/parsers/convextRewardPoolParser.js +21 -0
  42. package/lib/parsers/creditFacadeParser.d.ts +11 -0
  43. package/lib/parsers/creditFacadeParser.js +84 -0
  44. package/lib/parsers/creditManagerParser.d.ts +7 -0
  45. package/lib/parsers/creditManagerParser.js +22 -0
  46. package/lib/parsers/curveAdapterParser.d.ts +13 -0
  47. package/lib/parsers/curveAdapterParser.js +124 -0
  48. package/lib/parsers/erc626AdapterParser.d.ts +8 -0
  49. package/lib/parsers/erc626AdapterParser.js +21 -0
  50. package/lib/parsers/iParser.d.ts +6 -0
  51. package/lib/parsers/iParser.js +2 -0
  52. package/lib/parsers/lidoAdapterParser.d.ts +8 -0
  53. package/lib/parsers/lidoAdapterParser.js +29 -0
  54. package/lib/parsers/lidoSTETHParser.d.ts +8 -0
  55. package/lib/parsers/lidoSTETHParser.js +36 -0
  56. package/lib/parsers/priceOracleParser.d.ts +7 -0
  57. package/lib/parsers/priceOracleParser.js +23 -0
  58. package/lib/parsers/stakingRewardsAdapterParser.d.ts +10 -0
  59. package/lib/parsers/stakingRewardsAdapterParser.js +35 -0
  60. package/lib/parsers/txParser.d.ts +37 -0
  61. package/lib/parsers/txParser.js +174 -0
  62. package/lib/parsers/uniV2AdapterParser.d.ts +8 -0
  63. package/lib/parsers/uniV2AdapterParser.js +51 -0
  64. package/lib/parsers/uniV2AdapterParser.spec.d.ts +1 -0
  65. package/lib/parsers/uniV2AdapterParser.spec.js +59 -0
  66. package/lib/parsers/uniV3AdapterParser.d.ts +10 -0
  67. package/lib/parsers/uniV3AdapterParser.js +101 -0
  68. package/lib/parsers/uniV3AdapterParser.spec.d.ts +1 -0
  69. package/lib/parsers/uniV3AdapterParser.spec.js +96 -0
  70. package/lib/parsers/wstETHAdapterParser.d.ts +8 -0
  71. package/lib/parsers/wstETHAdapterParser.js +50 -0
  72. package/lib/parsers/wstETHAdapterParser.spec.d.ts +1 -0
  73. package/lib/parsers/wstETHAdapterParser.spec.js +37 -0
  74. package/lib/parsers/yearnAdapterParser.spec.d.ts +1 -0
  75. package/lib/parsers/yearnAdapterParser.spec.js +54 -0
  76. package/lib/parsers/yearnV2AdapterParser.d.ts +8 -0
  77. package/lib/parsers/yearnV2AdapterParser.js +57 -0
  78. package/lib/pathfinder/balancerVault.d.ts +33 -0
  79. package/lib/pathfinder/balancerVault.js +59 -0
  80. package/lib/pathfinder/core.d.ts +14 -0
  81. package/lib/pathfinder/core.js +7 -0
  82. package/lib/pathfinder/index.d.ts +3 -0
  83. package/lib/pathfinder/index.js +3 -0
  84. package/lib/pathfinder/pathOptions.d.ts +16 -0
  85. package/lib/pathfinder/pathOptions.js +93 -0
  86. package/lib/pathfinder/pathOptions.spec.d.ts +1 -0
  87. package/lib/pathfinder/pathOptions.spec.js +138 -0
  88. package/lib/pathfinder/pathfinder.d.ts +72 -0
  89. package/lib/pathfinder/pathfinder.js +176 -0
  90. package/lib/pathfinder/pathfinder.spec.d.ts +1 -0
  91. package/lib/pathfinder/pathfinder.spec.js +52 -0
  92. package/lib/pathfinder/utils.d.ts +34 -0
  93. package/lib/pathfinder/utils.js +186 -0
  94. package/lib/payload/creditAccount.d.ts +1 -4
  95. package/lib/payload/pool.d.ts +6 -0
  96. package/lib/redstone/api.d.ts +0 -5
  97. package/lib/redstone/api.js +29 -94
  98. package/lib/types/IERC20ZapperDeposits.d.ts +80 -0
  99. package/lib/types/IERC20ZapperDeposits.js +35 -0
  100. package/lib/types/IStakingRewardsAdapter.d.ts +197 -0
  101. package/lib/types/IStakingRewardsAdapter.js +139 -0
  102. package/lib/types/IZapper.d.ts +38 -0
  103. package/lib/types/IZapper.js +17 -0
  104. package/lib/types/index.d.ts +1 -0
  105. package/lib/types/index.js +1 -0
  106. package/package.json +6 -6
  107. package/lib/core/rewardClaimer.js +0 -10
  108. /package/lib/{apy/auraAPY.d.ts → core/rewardClaimer/aura.d.ts} +0 -0
  109. /package/lib/{apy/auraAPY.js → core/rewardClaimer/aura.js} +0 -0
  110. /package/lib/{apy → core/rewardClaimer}/auraAbi.d.ts +0 -0
  111. /package/lib/{apy → core/rewardClaimer}/auraAbi.js +0 -0
  112. /package/lib/{apy/convexAPY.d.ts → core/rewardClaimer/convex.d.ts} +0 -0
  113. /package/lib/{apy/convexAPY.js → core/rewardClaimer/convex.js} +0 -0
  114. /package/lib/core/{rewardConvex.spec.d.ts → rewardClaimer/rewardConvex.spec.d.ts} +0 -0
@@ -72,6 +72,10 @@ import {ICurveV1_3AssetsAdapter} from
72
72
  import {ICurveV1_4AssetsAdapter} from
73
73
  "@gearbox-protocol/integrations-v3/contracts/interfaces/curve/ICurveV1_4AssetsAdapter.sol";
74
74
 
75
+ import {IStakingRewardsAdapter} from
76
+ "@gearbox-protocol/integrations-v3/contracts/interfaces/sky/IStakingRewardsAdapter.sol";
77
+
78
+
75
79
 
76
80
  import {IMulticall3} from "@gearbox-protocol/router-v3/lib/forge-std/src/interfaces/IMulticall3.sol";
77
81
  import {IRouterV3} from "@gearbox-protocol/router-v3/contracts/interfaces/IRouterV3.sol";
@@ -9,7 +9,6 @@ export type TokensWithApyRecord = PartialRecord<TokensWithAPY, number>;
9
9
  export declare const isTokenWithAPY: (t: unknown) => t is TokensWithAPY;
10
10
  export type AllLPTokens = LPTokens | ExtraFarmTokens;
11
11
  export declare const isFarmToken: (t: unknown) => t is AllLPTokens;
12
- export * from "./convexAPY";
13
12
  export * from "./curveAPY";
14
13
  export * from "./defiLamaAPY";
15
14
  export * from "./lidoAPY";
package/lib/apy/index.js CHANGED
@@ -83,7 +83,6 @@ const isFarmToken = (t) => {
83
83
  return (0, sdk_gov_1.isLPToken)(t) || (0, exports.isExtraFarmToken)(t);
84
84
  };
85
85
  exports.isFarmToken = isFarmToken;
86
- __exportStar(require("./convexAPY"), exports);
87
86
  __exportStar(require("./curveAPY"), exports);
88
87
  __exportStar(require("./defiLamaAPY"), exports);
89
88
  __exportStar(require("./lidoAPY"), exports);
@@ -90,14 +90,15 @@ export interface TimeToLiquidationProps {
90
90
  }
91
91
  export declare class CreditAccountData {
92
92
  readonly isSuccessful: boolean;
93
- readonly creditAccount: Address;
93
+ readonly priceFeedsNeeded: Address[];
94
+ readonly addr: Address;
94
95
  readonly borrower: Address;
95
96
  readonly creditManager: Address;
96
97
  readonly creditFacade: Address;
97
- readonly underlying: Address;
98
+ readonly underlyingToken: Address;
98
99
  readonly expirationDate: number;
99
100
  readonly version: number;
100
- readonly enabledTokensMask: bigint;
101
+ readonly enabledTokenMask: bigint;
101
102
  readonly healthFactor: number;
102
103
  isDeleting: boolean;
103
104
  readonly baseBorrowRateWithoutFee: number;
@@ -106,14 +107,13 @@ export declare class CreditAccountData {
106
107
  readonly accruedFees: bigint;
107
108
  readonly totalDebtUSD: bigint;
108
109
  readonly borrowedAmountPlusInterestAndFees: bigint;
109
- readonly debt: bigint;
110
110
  readonly totalValue: bigint;
111
111
  readonly totalValueUSD: bigint;
112
112
  readonly twvUSD: bigint;
113
113
  readonly activeBots: Record<Address, true>;
114
114
  readonly balances: Record<Address, bigint>;
115
115
  readonly collateralTokens: Array<Address>;
116
- readonly tokens: Record<Address, CaTokenBalance>;
116
+ readonly allBalances: Record<Address, CaTokenBalance>;
117
117
  readonly forbiddenTokens: Record<Address, true>;
118
118
  readonly quotedTokens: Record<Address, true>;
119
119
  constructor(payload: CreditAccountDataPayload);
@@ -10,14 +10,15 @@ exports.MAX_UINT256 = 1157920892373161954235709850086879078532699846656405640394
10
10
  const MAX_UINT16 = 65535;
11
11
  class CreditAccountData {
12
12
  isSuccessful;
13
- creditAccount;
13
+ priceFeedsNeeded;
14
+ addr;
14
15
  borrower;
15
16
  creditManager;
16
17
  creditFacade;
17
- underlying;
18
+ underlyingToken;
18
19
  expirationDate;
19
20
  version;
20
- enabledTokensMask;
21
+ enabledTokenMask;
21
22
  healthFactor;
22
23
  isDeleting;
23
24
  baseBorrowRateWithoutFee;
@@ -26,32 +27,31 @@ class CreditAccountData {
26
27
  accruedFees;
27
28
  totalDebtUSD;
28
29
  borrowedAmountPlusInterestAndFees;
29
- debt;
30
30
  totalValue;
31
31
  totalValueUSD;
32
32
  twvUSD;
33
33
  activeBots;
34
34
  balances = {};
35
35
  collateralTokens = [];
36
- tokens = {};
36
+ allBalances = {};
37
37
  forbiddenTokens = {};
38
38
  quotedTokens = {};
39
39
  constructor(payload) {
40
40
  this.isSuccessful = payload.isSuccessful;
41
- this.creditAccount = payload.addr.toLowerCase();
41
+ this.priceFeedsNeeded = payload.priceFeedsNeeded.map(t => t);
42
+ this.addr = payload.addr.toLowerCase();
42
43
  this.borrower = payload.borrower.toLowerCase();
43
44
  this.creditManager = payload.creditManager.toLowerCase();
44
45
  this.creditFacade = payload.creditFacade.toLowerCase();
45
- this.underlying = payload.underlying.toLowerCase();
46
+ this.underlyingToken = payload.underlying.toLowerCase();
46
47
  this.expirationDate = Number(payload.expirationDate);
47
48
  this.version = Number(payload.cfVersion);
48
49
  this.healthFactor = Number(payload.healthFactor || 0n);
49
- this.enabledTokensMask = payload.enabledTokensMask;
50
+ this.enabledTokenMask = payload.enabledTokensMask;
50
51
  this.isDeleting = false;
51
52
  this.borrowedAmount = payload.debt;
52
53
  this.accruedInterest = payload.accruedInterest || 0n;
53
54
  this.accruedFees = payload.accruedFees || 0n;
54
- this.debt = this.borrowedAmount;
55
55
  this.borrowedAmountPlusInterestAndFees =
56
56
  this.borrowedAmount + this.accruedInterest + this.accruedFees;
57
57
  this.totalDebtUSD = payload.totalDebtUSD;
@@ -67,7 +67,6 @@ class CreditAccountData {
67
67
  payload.balances.forEach(b => {
68
68
  const token = b.token.toLowerCase();
69
69
  const balance = {
70
- success: b.success,
71
70
  token,
72
71
  balance: b.balance,
73
72
  isForbidden: b.isForbidden,
@@ -75,7 +74,6 @@ class CreditAccountData {
75
74
  isQuoted: b.isQuoted,
76
75
  quota: b.quota,
77
76
  quotaRate: BigInt(b.quotaRate) * sdk_gov_1.PERCENTAGE_DECIMALS,
78
- mask: b.mask,
79
77
  };
80
78
  if (!b.isForbidden) {
81
79
  this.balances[token] = balance.balance;
@@ -87,7 +85,7 @@ class CreditAccountData {
87
85
  if (b.isQuoted) {
88
86
  this.quotedTokens[token] = true;
89
87
  }
90
- this.tokens[token] = balance;
88
+ this.allBalances[token] = balance;
91
89
  });
92
90
  }
93
91
  setDeleteInProgress(d) {
@@ -148,7 +146,7 @@ class CreditAccountData {
148
146
  return !!this.quotedTokens[token];
149
147
  }
150
148
  isTokenEnabled(token) {
151
- return this.tokens[token].isEnabled;
149
+ return this.allBalances[token].isEnabled;
152
150
  }
153
151
  static calcMaxDebtIncrease(healthFactor, debt, underlyingLT, minHf = Number(sdk_gov_1.PERCENTAGE_FACTOR)) {
154
152
  // HF = (TWV + d*lt) / (D + d) => d = (HF*D - TWV) / (l - HF)
@@ -1,4 +1,5 @@
1
1
  import { Address } from "viem";
2
+ import { MultiCall } from "../pathfinder/core";
2
3
  import { ChartsCreditManagerPayload, CreditManagerDataPayload, QuotaInfo } from "../payload/creditManager";
3
4
  import { LinearModel } from "../payload/pool";
4
5
  export type CreditManagerType = "universal" | "trade" | "farm" | "restaking";
@@ -38,7 +39,22 @@ export declare class CreditManagerData {
38
39
  readonly quotas: Record<Address, QuotaInfo>;
39
40
  readonly interestModel: LinearModel;
40
41
  constructor(payload: CreditManagerDataPayload);
42
+ get id(): Address;
41
43
  isQuoted(token: Address): boolean;
44
+ encodeAddCollateralV3(tokenAddress: Address, amount: bigint): MultiCall;
45
+ encodeAddCollateralWithPermitV3(tokenAddress: Address, amount: bigint, deadline: bigint, v: number, r: Address, s: Address): MultiCall;
46
+ encodeIncreaseDebtV3(amount: bigint): MultiCall;
47
+ encodeDecreaseDebtV3(amount: bigint): MultiCall;
48
+ encodeEnableTokenV3(token: Address): MultiCall;
49
+ encodeDisableTokenV3(token: Address): MultiCall;
50
+ encodeUpdateQuotaV3(token: Address, quotaChange: bigint, minQuota: bigint): MultiCall;
51
+ encodeWithdrawCollateralV3(token: Address, amount: bigint, to: Address): MultiCall;
52
+ static withdrawAndUnwrap_Convex(address: Address, amount: bigint, claim: boolean): MultiCall;
53
+ static withdrawAllAndUnwrap_Convex(address: Address, claim: boolean): MultiCall;
54
+ static withdrawAll_Rewards(address: Address): MultiCall;
55
+ static withdraw_Rewards(address: Address, amount: bigint): MultiCall;
56
+ static claim_Rewards(address: Address): MultiCall;
57
+ encodeOnDemandPriceUpdateV3(token: Address, reserve: boolean, data: Address): MultiCall;
42
58
  static getTier(name: string): number;
43
59
  static getType(name: string): CreditManagerType;
44
60
  }
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChartsCreditManagerData = exports.CreditManagerData = void 0;
4
4
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
+ const viem_1 = require("viem");
6
+ const txParser_1 = require("../parsers/txParser");
7
+ const types_1 = require("../types");
5
8
  class CreditManagerData {
6
9
  address;
7
10
  type;
@@ -113,10 +116,161 @@ class CreditManagerData {
113
116
  this.collateralTokens.push(tLc);
114
117
  this.supportedTokens[tLc] = true;
115
118
  });
119
+ txParser_1.TxParser.addCreditManager(this.address, this.version);
120
+ if (!!this.creditFacade && this.creditFacade !== sdk_gov_1.ADDRESS_0X0) {
121
+ txParser_1.TxParser.addCreditFacade(this.creditFacade, sdk_gov_1.tokenSymbolByAddress[this.underlyingToken], this.version);
122
+ txParser_1.TxParser.addAdapters(payload.adapters.map(a => ({
123
+ adapter: a.adapter,
124
+ contract: a.targetContract,
125
+ })));
126
+ }
127
+ }
128
+ get id() {
129
+ return this.address;
116
130
  }
117
131
  isQuoted(token) {
118
132
  return !!this.quotas[token];
119
133
  }
134
+ encodeAddCollateralV3(tokenAddress, amount) {
135
+ return {
136
+ target: this.creditFacade,
137
+ callData: (0, viem_1.encodeFunctionData)({
138
+ abi: types_1.iCreditFacadeV3MulticallAbi,
139
+ functionName: "addCollateral",
140
+ args: [tokenAddress, amount],
141
+ }),
142
+ };
143
+ }
144
+ encodeAddCollateralWithPermitV3(tokenAddress, amount, deadline, v, r, s) {
145
+ return {
146
+ target: this.creditFacade,
147
+ callData: (0, viem_1.encodeFunctionData)({
148
+ abi: types_1.iCreditFacadeV3MulticallAbi,
149
+ functionName: "addCollateralWithPermit",
150
+ args: [tokenAddress, amount, deadline, v, r, s],
151
+ }),
152
+ };
153
+ }
154
+ encodeIncreaseDebtV3(amount) {
155
+ return {
156
+ target: this.creditFacade,
157
+ callData: (0, viem_1.encodeFunctionData)({
158
+ abi: types_1.iCreditFacadeV3MulticallAbi,
159
+ functionName: "increaseDebt",
160
+ args: [amount],
161
+ }),
162
+ };
163
+ }
164
+ encodeDecreaseDebtV3(amount) {
165
+ return {
166
+ target: this.creditFacade,
167
+ callData: (0, viem_1.encodeFunctionData)({
168
+ abi: types_1.iCreditFacadeV3MulticallAbi,
169
+ functionName: "decreaseDebt",
170
+ args: [amount],
171
+ }),
172
+ };
173
+ }
174
+ encodeEnableTokenV3(token) {
175
+ return {
176
+ target: this.creditFacade,
177
+ callData: (0, viem_1.encodeFunctionData)({
178
+ abi: types_1.iCreditFacadeV3MulticallAbi,
179
+ functionName: "enableToken",
180
+ args: [token],
181
+ }),
182
+ };
183
+ }
184
+ encodeDisableTokenV3(token) {
185
+ return {
186
+ target: this.creditFacade,
187
+ callData: (0, viem_1.encodeFunctionData)({
188
+ abi: types_1.iCreditFacadeV3MulticallAbi,
189
+ functionName: "disableToken",
190
+ args: [token],
191
+ }),
192
+ };
193
+ }
194
+ encodeUpdateQuotaV3(token, quotaChange, minQuota) {
195
+ return {
196
+ target: this.creditFacade,
197
+ callData: (0, viem_1.encodeFunctionData)({
198
+ abi: types_1.iCreditFacadeV3MulticallAbi,
199
+ functionName: "updateQuota",
200
+ args: [token, quotaChange, minQuota],
201
+ }),
202
+ };
203
+ }
204
+ encodeWithdrawCollateralV3(token, amount, to) {
205
+ return {
206
+ target: this.creditFacade,
207
+ callData: (0, viem_1.encodeFunctionData)({
208
+ abi: types_1.iCreditFacadeV3MulticallAbi,
209
+ functionName: "withdrawCollateral",
210
+ args: [token, amount, to],
211
+ }),
212
+ };
213
+ }
214
+ static withdrawAndUnwrap_Convex(address, amount, claim) {
215
+ return {
216
+ target: address,
217
+ callData: (0, viem_1.encodeFunctionData)({
218
+ abi: types_1.iConvexV1BaseRewardPoolAdapterAbi,
219
+ functionName: "withdrawAndUnwrap",
220
+ args: [amount, claim],
221
+ }),
222
+ };
223
+ }
224
+ static withdrawAllAndUnwrap_Convex(address, claim) {
225
+ return {
226
+ target: address,
227
+ callData: (0, viem_1.encodeFunctionData)({
228
+ abi: types_1.iConvexV1BaseRewardPoolAdapterAbi,
229
+ functionName: "withdrawDiffAndUnwrap",
230
+ args: [1n, claim],
231
+ }),
232
+ };
233
+ }
234
+ static withdrawAll_Rewards(address) {
235
+ return {
236
+ target: address,
237
+ callData: (0, viem_1.encodeFunctionData)({
238
+ abi: types_1.iStakingRewardsAdapterAbi,
239
+ functionName: "withdrawDiff",
240
+ args: [1n],
241
+ }),
242
+ };
243
+ }
244
+ static withdraw_Rewards(address, amount) {
245
+ return {
246
+ target: address,
247
+ callData: (0, viem_1.encodeFunctionData)({
248
+ abi: types_1.iStakingRewardsAdapterAbi,
249
+ functionName: "withdraw",
250
+ args: [amount],
251
+ }),
252
+ };
253
+ }
254
+ static claim_Rewards(address) {
255
+ return {
256
+ target: address,
257
+ callData: (0, viem_1.encodeFunctionData)({
258
+ abi: types_1.iStakingRewardsAdapterAbi,
259
+ functionName: "getReward",
260
+ args: [],
261
+ }),
262
+ };
263
+ }
264
+ encodeOnDemandPriceUpdateV3(token, reserve, data) {
265
+ return {
266
+ target: this.creditFacade,
267
+ callData: (0, viem_1.encodeFunctionData)({
268
+ abi: types_1.iCreditFacadeV3MulticallAbi,
269
+ functionName: "onDemandPriceUpdate",
270
+ args: [token, reserve, data],
271
+ }),
272
+ };
273
+ }
120
274
  static getTier(name) {
121
275
  const DEFAULT_TIER = 99;
122
276
  const l = name.split(" ") || [];
@@ -21,6 +21,12 @@ export declare class PoolData {
21
21
  readonly utilization: number;
22
22
  readonly totalBorrowed: bigint;
23
23
  readonly totalDebtLimit: bigint;
24
+ readonly creditManagerDebtParams: Record<Address, {
25
+ creditManager: Address;
26
+ borrowed: bigint;
27
+ limit: bigint;
28
+ availableToBorrow: bigint;
29
+ }>;
24
30
  readonly quotas: Record<Address, {
25
31
  token: Address;
26
32
  rate: bigint;
package/lib/core/pool.js CHANGED
@@ -26,6 +26,7 @@ class PoolData {
26
26
  utilization;
27
27
  totalBorrowed;
28
28
  totalDebtLimit;
29
+ creditManagerDebtParams;
29
30
  quotas;
30
31
  zappers;
31
32
  totalAssets;
@@ -61,6 +62,16 @@ class PoolData {
61
62
  this.utilization = PoolData.calculateUtilization(expected, available);
62
63
  this.totalBorrowed = payload.totalBorrowed;
63
64
  this.totalDebtLimit = payload.totalDebtLimit;
65
+ this.creditManagerDebtParams = payload.creditManagerDebtParams.reduce((acc, p) => {
66
+ const creditManager = p.creditManager.toLowerCase();
67
+ acc[creditManager] = {
68
+ creditManager,
69
+ borrowed: p.borrowed,
70
+ limit: p.limit,
71
+ availableToBorrow: p.availableToBorrow,
72
+ };
73
+ return acc;
74
+ }, {});
64
75
  this.quotas = payload.quotas.reduce((acc, q) => {
65
76
  const token = q.token.toLowerCase();
66
77
  acc[token] = {
@@ -130,6 +130,10 @@ const PROTOCOL_DATA = {
130
130
  name: "Lombard",
131
131
  icon: "/protocols/lombard.svg",
132
132
  },
133
+ Sky: {
134
+ name: "Sky",
135
+ icon: "/protocols/sky.svg",
136
+ },
133
137
  };
134
138
  const isExtendedProtocol = (t) => typeof t === "string" && !!PROTOCOL_DATA[t];
135
139
  exports.isExtendedProtocol = isExtendedProtocol;
@@ -1,12 +1,11 @@
1
1
  import { NetworkType, PartialRecord, Protocols, SupportedContract, SupportedToken } from "@gearbox-protocol/sdk-gov";
2
2
  import { Address, PublicClient } from "viem";
3
- import { MultiCall } from "../pathfinder/core";
4
- import { CreditAccountData } from "./creditAccount";
5
- import { CreditManagerData } from "./creditManager";
3
+ import { MultiCall } from "../../pathfinder/core";
4
+ import { CreditAccountData } from "../creditAccount";
5
+ import { CreditManagerData } from "../creditManager";
6
6
  export interface Rewards {
7
7
  contract: SupportedContract;
8
- totalSupply: bigint;
9
- protocol: Protocols.Aura | Protocols.Convex;
8
+ protocol: Protocols.Aura | Protocols.Convex | Protocols.Sky;
10
9
  rewards: PartialRecord<SupportedToken, bigint>;
11
10
  calls: Array<MultiCall>;
12
11
  }
@@ -17,4 +16,10 @@ export interface AdapterWithType {
17
16
  }
18
17
  export declare class RewardClaimer {
19
18
  static findRewards(ca: CreditAccountData, cm: CreditManagerData, network: NetworkType, provider: PublicClient): Promise<Array<Rewards>>;
19
+ static findRewardTokens(cm: CreditManagerData, provider: PublicClient): Promise<{
20
+ staking: {
21
+ adapters: AdapterWithType[];
22
+ tokens: (`0x${string}` | undefined)[];
23
+ };
24
+ }>;
20
25
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RewardClaimer = void 0;
4
+ const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
+ const rewardConvex_1 = require("./rewardConvex");
6
+ const stakingRewards_1 = require("./stakingRewards");
7
+ class RewardClaimer {
8
+ static async findRewards(ca, cm, network, provider) {
9
+ const tokens = await RewardClaimer.findRewardTokens(cm, provider);
10
+ const [convex, staking] = await Promise.all([
11
+ rewardConvex_1.RewardConvex.findRewards(ca, cm, network, provider),
12
+ stakingRewards_1.StakingRewards.findRewards(ca, provider, tokens.staking.adapters, tokens.staking.tokens),
13
+ ]);
14
+ return [...convex, ...staking];
15
+ }
16
+ static async findRewardTokens(cm, provider) {
17
+ const { calls: stakingCalls, adapters: stakingAdapters } = stakingRewards_1.StakingRewards.getRewardTokenCalls(cm);
18
+ const stakingTotal = stakingCalls.flat(1);
19
+ const response = await provider.multicall({
20
+ allowFailure: true,
21
+ multicallAddress: sdk_gov_1.MULTICALL_ADDRESS,
22
+ contracts: [...stakingTotal],
23
+ });
24
+ const stakingEnd = stakingTotal.length;
25
+ const stakingRewardTokensResponse = response.slice(0, stakingEnd);
26
+ return {
27
+ staking: {
28
+ adapters: stakingAdapters,
29
+ tokens: stakingRewardTokensResponse.map(r => r?.result),
30
+ },
31
+ };
32
+ }
33
+ }
34
+ exports.RewardClaimer = RewardClaimer;
@@ -1,8 +1,8 @@
1
1
  import { NetworkType, Protocols, SupportedToken } from "@gearbox-protocol/sdk-gov";
2
2
  import { Abi, Address, PublicClient } from "viem";
3
- import { CreditAccountData } from "./creditAccount";
4
- import { CreditManagerData } from "./creditManager";
5
- import { AdapterWithType, Rewards } from "./rewardClaimer";
3
+ import { CreditAccountData } from "../creditAccount";
4
+ import { CreditManagerData } from "../creditManager";
5
+ import { AdapterWithType, Rewards } from "../rewardClaimer";
6
6
  type DistributionList = Array<Array<RewardDistribution>>;
7
7
  type CallsList = Array<Array<{
8
8
  address: Address;
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RewardConvex = void 0;
4
4
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
5
  const viem_1 = require("viem");
6
- const apy_1 = require("../apy");
7
- const auraAbi_1 = require("../apy/auraAbi");
8
- const auraAPY_1 = require("../apy/auraAPY");
9
- const types_1 = require("../types");
6
+ const types_1 = require("../../types");
7
+ const aura_1 = require("./aura");
8
+ const auraAbi_1 = require("./auraAbi");
9
+ const convex_1 = require("./convex");
10
10
  // convex[totalSupply, ...tokens] aura[totalSupply, multiplier, ...tokens]
11
11
  class RewardConvex {
12
12
  static async findRewards(ca, cm, network, provider) {
13
- const prepared = RewardConvex.prepareMultiCalls(ca.creditAccount, cm, network);
13
+ const prepared = RewardConvex.prepareMultiCalls(ca.addr, cm, network);
14
14
  if (!prepared)
15
15
  return [];
16
16
  const { auraCalls, auraDistribution, convexCalls, convexDistribution } = prepared;
@@ -198,7 +198,6 @@ class RewardConvex {
198
198
  // create base
199
199
  const base = {
200
200
  contract: baseDistribution.contract,
201
- totalSupply: totalSupply,
202
201
  protocol: baseDistribution.protocol,
203
202
  rewards: {
204
203
  [baseDistribution.token]: baseReward,
@@ -212,8 +211,8 @@ class RewardConvex {
212
211
  };
213
212
  // add boosted
214
213
  const boostedReward = baseDistribution.protocol === sdk_gov_1.Protocols.Aura
215
- ? (0, auraAPY_1.getAURAMintAmount)(baseReward, totalSupply, multiplier)
216
- : (0, apy_1.getCVXMintAmount)(baseReward, totalSupply);
214
+ ? (0, aura_1.getAURAMintAmount)(baseReward, totalSupply, multiplier)
215
+ : (0, convex_1.getCVXMintAmount)(baseReward, totalSupply);
217
216
  base.rewards = {
218
217
  ...base.rewards,
219
218
  [boostedRewardToken]: boostedReward,
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
4
4
  const chai_1 = require("chai");
5
5
  const viem_1 = require("viem");
6
- const types_1 = require("../types");
6
+ const types_1 = require("../../types");
7
7
  const rewardConvex_1 = require("./rewardConvex");
8
8
  const ADAPTER_CONVEX_3CRV_POOL = sdk_gov_1.DUMB_ADDRESS;
9
9
  const ADAPTER_CURVE_FRAX_POOL = sdk_gov_1.DUMB_ADDRESS2;
@@ -94,7 +94,6 @@ describe("RewardConvex test", () => {
94
94
  const expected = [
95
95
  {
96
96
  protocol: sdk_gov_1.Protocols.Convex,
97
- totalSupply: 0n,
98
97
  contract: "CONVEX_3CRV_POOL",
99
98
  rewards: {
100
99
  CRV: 1000n,
@@ -0,0 +1,34 @@
1
+ import { SupportedToken } from "@gearbox-protocol/sdk-gov";
2
+ import { Abi, Address, PublicClient } from "viem";
3
+ import { CreditAccountData } from "../creditAccount";
4
+ import { CreditManagerData } from "../creditManager";
5
+ import { AdapterWithType, Rewards } from "../rewardClaimer";
6
+ type DistributionList = Array<Array<RewardDistribution>>;
7
+ type CallsList = Array<Array<{
8
+ address: Address;
9
+ abi: Abi;
10
+ functionName: string;
11
+ args: unknown[];
12
+ }>>;
13
+ export interface RewardDistribution {
14
+ contract: Rewards["contract"];
15
+ protocol: Rewards["protocol"];
16
+ token: SupportedToken;
17
+ adapter: Address;
18
+ contractAddress: Address;
19
+ }
20
+ export declare class StakingRewards {
21
+ static findRewards(ca: CreditAccountData, provider: PublicClient, adapters: Array<AdapterWithType>, rewardTokens: Array<Address | undefined>): Promise<Array<Rewards>>;
22
+ static getRewardTokenCalls(cm: CreditManagerData): {
23
+ calls: CallsList;
24
+ adapters: AdapterWithType[];
25
+ };
26
+ private static findAdapters;
27
+ static prepareMultiCalls(creditAccount: Address, adapters: Array<AdapterWithType>, rewardTokens: Array<Address | undefined>): {
28
+ distribution: DistributionList;
29
+ calls: CallsList;
30
+ } | undefined;
31
+ private static parseResults;
32
+ private static getRewardObject;
33
+ }
34
+ export {};