@gearbox-protocol/sdk 8.3.2 → 8.4.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 (31) hide show
  1. package/dist/cjs/abi/routerV310.js +31 -0
  2. package/dist/cjs/sdk/accounts/{CreditAccountsService.js → AbstractCreditAccountsService.js} +34 -407
  3. package/dist/cjs/sdk/accounts/CreditAccountsServiceV300.js +363 -0
  4. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +200 -0
  5. package/dist/cjs/sdk/accounts/constants.js +33 -0
  6. package/dist/cjs/sdk/accounts/createCreditAccountService.js +39 -0
  7. package/dist/cjs/sdk/accounts/index.js +4 -2
  8. package/dist/cjs/sdk/router/RouterV300Contract.js +8 -0
  9. package/dist/cjs/sdk/router/RouterV310Contract.js +24 -0
  10. package/dist/esm/abi/routerV310.js +31 -0
  11. package/dist/esm/sdk/accounts/{CreditAccountsService.js → AbstractCreditAccountsService.js} +31 -417
  12. package/dist/esm/sdk/accounts/CreditAccountsServiceV300.js +351 -0
  13. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +176 -0
  14. package/dist/esm/sdk/accounts/constants.js +9 -0
  15. package/dist/esm/sdk/accounts/createCreditAccountService.js +15 -0
  16. package/dist/esm/sdk/accounts/index.js +2 -1
  17. package/dist/esm/sdk/router/RouterV300Contract.js +8 -0
  18. package/dist/esm/sdk/router/RouterV310Contract.js +25 -1
  19. package/dist/types/abi/routerV310.d.ts +48 -0
  20. package/dist/types/dev/AccountOpener.d.ts +2 -2
  21. package/dist/types/sdk/accounts/{CreditAccountsService.d.ts → AbstractCreditAccountsService.d.ts} +12 -67
  22. package/dist/types/sdk/accounts/CreditAccountsServiceV300.d.ts +25 -0
  23. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +24 -0
  24. package/dist/types/sdk/accounts/constants.d.ts +2 -0
  25. package/dist/types/sdk/accounts/createCreditAccountService.d.ts +8 -0
  26. package/dist/types/sdk/accounts/index.d.ts +2 -1
  27. package/dist/types/sdk/accounts/types.d.ts +130 -1
  28. package/dist/types/sdk/router/RouterV300Contract.d.ts +5 -1
  29. package/dist/types/sdk/router/RouterV310Contract.d.ts +53 -1
  30. package/dist/types/sdk/router/types.d.ts +22 -0
  31. package/package.json +1 -1
@@ -0,0 +1,351 @@
1
+ import { parseAbi } from "abitype";
2
+ import { encodeFunctionData } from "viem";
3
+ import { NOT_DEPLOYED } from "../constants/addresses.js";
4
+ import { MAX_UINT256 } from "../constants/math.js";
5
+ import {
6
+ auraStakedTokens,
7
+ auraTokens,
8
+ contractsByNetwork,
9
+ convexStakedPhantomTokens,
10
+ convexTokens,
11
+ isAuraStakedToken,
12
+ isConvexStakedPhantomToken,
13
+ isStakingRewardsPhantomToken,
14
+ stakingRewardsTokens,
15
+ tokenDataByNetwork,
16
+ tokenSymbolByAddress
17
+ } from "../sdk-gov-legacy/index.js";
18
+ import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
19
+ class CreditAccountServiceV300 extends AbstractCreditAccountService {
20
+ /**
21
+ * Implements {@link ICreditAccountsService.setBot}
22
+ */
23
+ setBot(_) {
24
+ throw new Error(
25
+ "Not implemented in router v3.0. Try direct call setBotPermissions instead."
26
+ );
27
+ }
28
+ /**
29
+ * Implements {@link ICreditAccountsService.withdrawCollateral}
30
+ */
31
+ async withdrawCollateral({
32
+ creditAccount,
33
+ assetsToWithdraw: wrapped,
34
+ to,
35
+ minQuota,
36
+ averageQuota
37
+ }) {
38
+ const cm = this.sdk.marketRegister.findCreditManager(
39
+ creditAccount.creditManager
40
+ );
41
+ const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
42
+ creditAccount.creditManager,
43
+ creditAccount,
44
+ void 0
45
+ );
46
+ const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
47
+ wrapped,
48
+ false,
49
+ false,
50
+ creditAccount.creditManager
51
+ );
52
+ const calls = [
53
+ ...priceUpdatesCalls,
54
+ ...unwrapCalls,
55
+ ...assetsToWithdraw.map(
56
+ (a) => this.prepareWithdrawToken(
57
+ creditAccount.creditFacade,
58
+ a.token,
59
+ a.balance,
60
+ to
61
+ )
62
+ ),
63
+ ...this.prepareUpdateQuotas(creditAccount.creditFacade, {
64
+ minQuota,
65
+ averageQuota
66
+ })
67
+ ];
68
+ const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
69
+ return { tx, calls, creditFacade: cm.creditFacade };
70
+ }
71
+ /**
72
+ * Implements {@link ICreditAccountsService.repayCreditAccount}
73
+ */
74
+ async repayCreditAccount({
75
+ operation,
76
+ collateralAssets,
77
+ assetsToWithdraw: wrapped,
78
+ creditAccount: ca,
79
+ permits,
80
+ to
81
+ }) {
82
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
83
+ const addCollateral = collateralAssets.filter((a) => a.balance > 0);
84
+ const priceUpdates = await this.getPriceUpdatesForFacade(
85
+ ca.creditManager,
86
+ ca,
87
+ void 0
88
+ );
89
+ const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
90
+ wrapped,
91
+ true,
92
+ true,
93
+ ca.creditManager
94
+ );
95
+ const calls = [
96
+ ...operation === "close" ? [] : priceUpdates,
97
+ ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
98
+ ...this.prepareDisableQuotas(ca),
99
+ ...this.prepareDecreaseDebt(ca),
100
+ ...unwrapCalls,
101
+ ...this.prepareDisableTokens(ca),
102
+ ...assetsToWithdraw.map(
103
+ (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to)
104
+ )
105
+ ];
106
+ const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
107
+ return { tx, calls, creditFacade: cm.creditFacade };
108
+ }
109
+ /**
110
+ * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
111
+ */
112
+ async repayAndLiquidateCreditAccount({
113
+ collateralAssets,
114
+ assetsToWithdraw: wrapped,
115
+ creditAccount: ca,
116
+ permits,
117
+ to
118
+ }) {
119
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
120
+ const priceUpdates = await this.getPriceUpdatesForFacade(
121
+ ca.creditManager,
122
+ ca,
123
+ void 0
124
+ );
125
+ const addCollateral = collateralAssets.filter((a) => a.balance > 0);
126
+ const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
127
+ wrapped,
128
+ true,
129
+ true,
130
+ ca.creditManager
131
+ );
132
+ const calls = [
133
+ ...priceUpdates,
134
+ ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
135
+ ...unwrapCalls,
136
+ ...assetsToWithdraw.map(
137
+ (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to)
138
+ )
139
+ ];
140
+ const tx = cm.creditFacade.liquidateCreditAccount(
141
+ ca.creditAccount,
142
+ to,
143
+ calls
144
+ );
145
+ return { tx, calls, creditFacade: cm.creditFacade };
146
+ }
147
+ /**
148
+ * Implements {@link ICreditAccountsService.claimFarmRewards}
149
+ */
150
+ async claimFarmRewards({
151
+ tokensToDisable,
152
+ calls: claimCalls,
153
+ creditAccount: ca,
154
+ minQuota,
155
+ averageQuota
156
+ }) {
157
+ if (claimCalls.length === 0) throw new Error("No path to execute");
158
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
159
+ const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
160
+ ca.creditManager,
161
+ ca,
162
+ averageQuota
163
+ );
164
+ const calls = [
165
+ ...priceUpdatesCalls,
166
+ ...claimCalls,
167
+ ...tokensToDisable.map(
168
+ (a) => this.prepareDisableToken(ca.creditFacade, a.token)
169
+ ),
170
+ ...this.prepareUpdateQuotas(ca.creditFacade, { minQuota, averageQuota })
171
+ ];
172
+ const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
173
+ return { tx, calls, creditFacade: cm.creditFacade };
174
+ }
175
+ /**
176
+ * unwraps staked tokens and optionally claims associated rewards; Should be remove after transition to 3.1
177
+ * @param acc
178
+ * @returns
179
+ */
180
+ #prepareUnwrapAndWithdrawCallsV3(assets, claim, withdrawAll, creditManager) {
181
+ const network = this.sdk.provider.networkType;
182
+ const suite = this.sdk.marketRegister.findCreditManager(creditManager);
183
+ const cmAdapters = suite.creditManager.adapters.values().reduce((acc, a) => {
184
+ const contractLc = a.targetContract.toLowerCase();
185
+ const adapterLc = a.address.toLowerCase();
186
+ acc[contractLc] = adapterLc;
187
+ return acc;
188
+ }, {});
189
+ const currentContractsData = Object.entries(
190
+ contractsByNetwork[network]
191
+ ).reduce(
192
+ (acc, [symbol, address]) => {
193
+ if (!!address && address !== NOT_DEPLOYED) {
194
+ acc[symbol] = address.toLowerCase();
195
+ }
196
+ return acc;
197
+ },
198
+ {}
199
+ );
200
+ const currentTokenData = Object.entries(tokenDataByNetwork[network]).reduce(
201
+ (acc, [symbol, address]) => {
202
+ if (!!address && address !== NOT_DEPLOYED) {
203
+ acc[symbol] = address.toLowerCase();
204
+ }
205
+ return acc;
206
+ },
207
+ {}
208
+ );
209
+ const { aura, convex, sky } = assets.reduce(
210
+ (acc, a) => {
211
+ const symbol = tokenSymbolByAddress[a.token];
212
+ if (isConvexStakedPhantomToken(symbol)) {
213
+ acc.convex.push(a);
214
+ } else if (isAuraStakedToken(symbol)) {
215
+ acc.aura.push(a);
216
+ } else if (isStakingRewardsPhantomToken(symbol)) {
217
+ acc.sky.push(a);
218
+ }
219
+ return acc;
220
+ },
221
+ { convex: [], aura: [], sky: [] }
222
+ );
223
+ const getWithdrawCall = (pool, a) => {
224
+ return withdrawAll ? this.#withdrawAllAndUnwrap_Convex(pool, claim) : this.#withdrawAndUnwrap_Convex(pool, a.balance, claim);
225
+ };
226
+ const getWithdrawCall_Rewards = (pool, a) => {
227
+ const calls = [
228
+ withdrawAll ? this.#withdrawAll_Rewards(pool) : this.#withdraw_Rewards(pool, a.balance),
229
+ ...claim ? [this.#claim_Rewards(pool)] : []
230
+ ];
231
+ return calls;
232
+ };
233
+ const convexStkCalls = convex.map((a) => {
234
+ const symbol = tokenSymbolByAddress[a.token];
235
+ const { pool } = convexTokens[symbol];
236
+ const poolAddress = currentContractsData[pool];
237
+ if (!poolAddress) {
238
+ throw new Error("Can't withdrawAllAndUnwrap_Convex (convex)");
239
+ }
240
+ const poolAddressLc = poolAddress.toLowerCase();
241
+ return getWithdrawCall(cmAdapters[poolAddressLc], a);
242
+ });
243
+ const auraStkCalls = aura.map((a) => {
244
+ const symbol = tokenSymbolByAddress[a.token];
245
+ const { pool } = auraTokens[symbol];
246
+ const poolAddress = currentContractsData[pool];
247
+ if (!poolAddress) {
248
+ throw new Error("Can't withdrawAllAndUnwrap_Convex (aura)");
249
+ }
250
+ const poolAddressLc = poolAddress.toLowerCase();
251
+ return getWithdrawCall(cmAdapters[poolAddressLc], a);
252
+ });
253
+ const skyStkCalls = sky.flatMap((a) => {
254
+ const symbol = tokenSymbolByAddress[a.token];
255
+ const { pool } = stakingRewardsTokens[symbol];
256
+ const poolAddress = currentContractsData[pool];
257
+ if (!poolAddress) {
258
+ throw new Error("Can't withdrawAllAndUnwrap_Convex (sky)");
259
+ }
260
+ const poolAddressLc = poolAddress.toLowerCase();
261
+ return getWithdrawCall_Rewards(cmAdapters[poolAddressLc], a);
262
+ });
263
+ const unwrapCalls = [...convexStkCalls, ...auraStkCalls, ...skyStkCalls];
264
+ const withdraw = assets.map((a) => {
265
+ const symbol = tokenSymbolByAddress[a.token];
266
+ if (isConvexStakedPhantomToken(symbol)) {
267
+ return {
268
+ ...a,
269
+ token: currentTokenData[convexStakedPhantomTokens[symbol].underlying]
270
+ };
271
+ }
272
+ if (isAuraStakedToken(symbol)) {
273
+ return {
274
+ ...a,
275
+ token: currentTokenData[auraStakedTokens[symbol].underlying]
276
+ };
277
+ }
278
+ if (isStakingRewardsPhantomToken(symbol)) {
279
+ return {
280
+ ...a,
281
+ token: currentTokenData[stakingRewardsTokens[symbol].underlying]
282
+ };
283
+ }
284
+ return a;
285
+ });
286
+ return { unwrapCalls, assetsToWithdraw: withdraw };
287
+ }
288
+ #withdrawAndUnwrap_Convex(address, amount, claim) {
289
+ return {
290
+ target: address,
291
+ callData: encodeFunctionData({
292
+ abi: parseAbi([
293
+ "function withdrawAndUnwrap(uint256, bool claim) returns (uint256 tokensToEnable, uint256 tokensToDisable)"
294
+ ]),
295
+ functionName: "withdrawAndUnwrap",
296
+ args: [amount, claim]
297
+ })
298
+ };
299
+ }
300
+ #withdrawAllAndUnwrap_Convex(address, claim) {
301
+ return {
302
+ target: address,
303
+ callData: encodeFunctionData({
304
+ abi: parseAbi([
305
+ "function withdrawDiffAndUnwrap(uint256 leftoverAmount, bool claim) returns (uint256 tokensToEnable, uint256 tokensToDisable)"
306
+ ]),
307
+ functionName: "withdrawDiffAndUnwrap",
308
+ args: [1n, claim]
309
+ })
310
+ };
311
+ }
312
+ #withdrawAll_Rewards(address) {
313
+ return {
314
+ target: address,
315
+ callData: encodeFunctionData({
316
+ abi: parseAbi([
317
+ "function withdrawDiff(uint256 leftoverAmount) external returns (bool useSafePrices)"
318
+ ]),
319
+ functionName: "withdrawDiff",
320
+ args: [1n]
321
+ })
322
+ };
323
+ }
324
+ #withdraw_Rewards(address, amount) {
325
+ return {
326
+ target: address,
327
+ callData: encodeFunctionData({
328
+ abi: parseAbi([
329
+ "function withdraw(uint256 amount) external returns (bool useSafePrices)"
330
+ ]),
331
+ functionName: "withdraw",
332
+ args: [amount]
333
+ })
334
+ };
335
+ }
336
+ #claim_Rewards(address) {
337
+ return {
338
+ target: address,
339
+ callData: encodeFunctionData({
340
+ abi: parseAbi([
341
+ "function getReward() external returns (bool useSafePrices)"
342
+ ]),
343
+ functionName: "getReward",
344
+ args: []
345
+ })
346
+ };
347
+ }
348
+ }
349
+ export {
350
+ CreditAccountServiceV300
351
+ };
@@ -0,0 +1,176 @@
1
+ import { encodeFunctionData } from "viem";
2
+ import { iCreditFacadeMulticallV310Abi } from "../../abi/v310.js";
3
+ import { MAX_UINT256 } from "../constants/math.js";
4
+ import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
5
+ import { PERMISSION_BY_TYPE } from "./constants.js";
6
+ class CreditAccountServiceV310 extends AbstractCreditAccountService {
7
+ /**
8
+ * Implements {@link ICreditAccountsService.setBot}
9
+ */
10
+ async setBot({
11
+ botAddress,
12
+ botBaseType,
13
+ stopBot,
14
+ creditAccount: ca
15
+ }) {
16
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
17
+ const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
18
+ ca.creditManager,
19
+ ca,
20
+ void 0
21
+ );
22
+ const addBotCall = {
23
+ target: ca.creditFacade,
24
+ callData: encodeFunctionData({
25
+ abi: iCreditFacadeMulticallV310Abi,
26
+ functionName: "setBotPermissions",
27
+ args: [botAddress, stopBot ? 0n : PERMISSION_BY_TYPE[botBaseType]]
28
+ })
29
+ };
30
+ const calls = [...priceUpdatesCalls, addBotCall];
31
+ const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
32
+ return { tx, calls, creditFacade: cm.creditFacade };
33
+ }
34
+ /**
35
+ * Implements {@link ICreditAccountsService.withdrawCollateral}
36
+ */
37
+ async withdrawCollateral({
38
+ creditAccount,
39
+ assetsToWithdraw,
40
+ to,
41
+ minQuota,
42
+ averageQuota
43
+ }) {
44
+ const cm = this.sdk.marketRegister.findCreditManager(
45
+ creditAccount.creditManager
46
+ );
47
+ const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
48
+ creditAccount.creditManager,
49
+ creditAccount,
50
+ void 0
51
+ );
52
+ const calls = [
53
+ ...priceUpdatesCalls,
54
+ ...assetsToWithdraw.map(
55
+ (a) => this.prepareWithdrawToken(
56
+ creditAccount.creditFacade,
57
+ a.token,
58
+ a.balance,
59
+ to
60
+ )
61
+ ),
62
+ ...this.prepareUpdateQuotas(creditAccount.creditFacade, {
63
+ minQuota,
64
+ averageQuota
65
+ })
66
+ ];
67
+ const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
68
+ return { tx, calls, creditFacade: cm.creditFacade };
69
+ }
70
+ /**
71
+ * Implements {@link ICreditAccountsService.repayCreditAccount}
72
+ */
73
+ async repayCreditAccount({
74
+ operation,
75
+ collateralAssets,
76
+ assetsToWithdraw,
77
+ creditAccount: ca,
78
+ permits,
79
+ to
80
+ }) {
81
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
82
+ const addCollateral = collateralAssets.filter((a) => a.balance > 0);
83
+ const router = this.sdk.routerFor(ca);
84
+ const claimPath = await router.findClaimAllRewards({
85
+ calls: [],
86
+ creditAccount: ca
87
+ });
88
+ const priceUpdates = await this.getPriceUpdatesForFacade(
89
+ ca.creditManager,
90
+ ca,
91
+ void 0
92
+ );
93
+ const calls = [
94
+ ...operation === "close" ? [] : priceUpdates,
95
+ ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
96
+ ...this.prepareDisableQuotas(ca),
97
+ ...this.prepareDecreaseDebt(ca),
98
+ ...claimPath.calls,
99
+ ...this.prepareDisableTokens(ca),
100
+ ...assetsToWithdraw.map(
101
+ (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to)
102
+ )
103
+ ];
104
+ const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
105
+ return { tx, calls, creditFacade: cm.creditFacade };
106
+ }
107
+ /**
108
+ * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
109
+ */
110
+ async repayAndLiquidateCreditAccount({
111
+ collateralAssets,
112
+ assetsToWithdraw,
113
+ creditAccount: ca,
114
+ permits,
115
+ to
116
+ }) {
117
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
118
+ const router = this.sdk.routerFor(ca);
119
+ const claimPath = await router.findClaimAllRewards({
120
+ calls: [],
121
+ creditAccount: ca
122
+ });
123
+ const priceUpdates = await this.getPriceUpdatesForFacade(
124
+ ca.creditManager,
125
+ ca,
126
+ void 0
127
+ );
128
+ const addCollateral = collateralAssets.filter((a) => a.balance > 0);
129
+ const calls = [
130
+ ...priceUpdates,
131
+ ...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
132
+ ...claimPath.calls,
133
+ ...assetsToWithdraw.map(
134
+ (t) => this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to)
135
+ )
136
+ ];
137
+ const tx = cm.creditFacade.liquidateCreditAccount(
138
+ ca.creditAccount,
139
+ to,
140
+ calls
141
+ );
142
+ return { tx, calls, creditFacade: cm.creditFacade };
143
+ }
144
+ /**
145
+ * Implements {@link ICreditAccountsService.claimFarmRewards}
146
+ */
147
+ async claimFarmRewards({
148
+ calls: legacyCalls,
149
+ creditAccount: ca,
150
+ minQuota,
151
+ averageQuota
152
+ }) {
153
+ const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
154
+ const router = this.sdk.routerFor(ca);
155
+ const claimPath = await router.findClaimAllRewards({
156
+ calls: legacyCalls,
157
+ creditAccount: ca
158
+ });
159
+ if (claimPath.calls.length === 0) throw new Error("No path to execute");
160
+ const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
161
+ ca.creditManager,
162
+ ca,
163
+ averageQuota
164
+ );
165
+ const calls = [
166
+ ...priceUpdatesCalls,
167
+ ...claimPath.calls,
168
+ ...this.prepareUpdateQuotas(ca.creditFacade, { minQuota, averageQuota })
169
+ ];
170
+ const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
171
+ return { tx, calls, creditFacade: cm.creditFacade };
172
+ }
173
+ }
174
+ export {
175
+ CreditAccountServiceV310
176
+ };
@@ -0,0 +1,9 @@
1
+ import { BotPermissions } from "../constants/bot-permissions.js";
2
+ const PERMISSION_BY_TYPE = {
3
+ LIQUIDATION_PROTECTION: BigInt(
4
+ BotPermissions.ADD_COLLATERAL | BotPermissions.WITHDRAW_COLLATERAL | BotPermissions.DECREASE_DEBT
5
+ )
6
+ };
7
+ export {
8
+ PERMISSION_BY_TYPE
9
+ };
@@ -0,0 +1,15 @@
1
+ import { isV300, isV310 } from "../constants/index.js";
2
+ import { CreditAccountServiceV300 } from "./CreditAccountsServiceV300.js";
3
+ import { CreditAccountServiceV310 } from "./CreditAccountsServiceV310.js";
4
+ function createCreditAccountService(sdk, version) {
5
+ if (isV300(version)) {
6
+ return new CreditAccountServiceV300(sdk);
7
+ }
8
+ if (isV310(version)) {
9
+ return new CreditAccountServiceV310(sdk);
10
+ }
11
+ throw new Error(`Unsupported Credit Account Service version ${version}`);
12
+ }
13
+ export {
14
+ createCreditAccountService
15
+ };
@@ -1,2 +1,3 @@
1
- export * from "./CreditAccountsService.js";
1
+ export * from "./constants.js";
2
+ export * from "./createCreditAccountService.js";
2
3
  export * from "./types.js";
@@ -156,6 +156,14 @@ class RouterV300Contract extends AbstractRouterContract {
156
156
  calls: [...result.calls]
157
157
  };
158
158
  }
159
+ /**
160
+ * Implements {@link IRouterContract.findClaimAllRewards}
161
+ */
162
+ async findClaimAllRewards(props) {
163
+ return {
164
+ calls: props.calls
165
+ };
166
+ }
159
167
  /**
160
168
  * Implements {@link IRouterContract.findBestClosePath}
161
169
  */
@@ -1,4 +1,4 @@
1
- import { getAddress } from "viem";
1
+ import { encodeFunctionData, getAddress } from "viem";
2
2
  import { iGearboxRouterV310Abi } from "../../abi/routerV310.js";
3
3
  import { BigIntMath } from "../sdk-legacy/index.js";
4
4
  import { AddressMap } from "../utils/AddressMap.js";
@@ -118,6 +118,30 @@ class RouterV310Contract extends AbstractRouterContract {
118
118
  calls: [...result.calls]
119
119
  };
120
120
  }
121
+ /**
122
+ * Implements {@link IRouterContract.findClaimAllRewards}
123
+ */
124
+ async findClaimAllRewards(props) {
125
+ const tData = props.creditAccount.tokens.map((a) => ({
126
+ balance: a.balance,
127
+ claimRewards: true,
128
+ leftoverBalance: a.balance,
129
+ numSplits: 0n,
130
+ token: a.token
131
+ }));
132
+ return {
133
+ calls: [
134
+ {
135
+ target: this.address,
136
+ callData: encodeFunctionData({
137
+ abi: this.abi,
138
+ functionName: "processClaims",
139
+ args: [props.creditAccount.creditAccount, tData]
140
+ })
141
+ }
142
+ ]
143
+ };
144
+ }
121
145
  /**
122
146
  * Implements {@link IRouterContract.findBestClosePath}
123
147
  */
@@ -56,6 +56,54 @@ export declare const iGearboxRouterV310Abi: readonly [{
56
56
  readonly internalType: "bytes32[]";
57
57
  }];
58
58
  readonly stateMutability: "view";
59
+ }, {
60
+ readonly type: "function";
61
+ readonly name: "processClaims";
62
+ readonly inputs: readonly [{
63
+ readonly name: "creditAccount";
64
+ readonly type: "address";
65
+ readonly internalType: "address";
66
+ }, {
67
+ readonly name: "tData";
68
+ readonly type: "tuple[]";
69
+ readonly internalType: "struct TokenData[]";
70
+ readonly components: readonly [{
71
+ readonly name: "token";
72
+ readonly type: "address";
73
+ readonly internalType: "address";
74
+ }, {
75
+ readonly name: "balance";
76
+ readonly type: "uint256";
77
+ readonly internalType: "uint256";
78
+ }, {
79
+ readonly name: "leftoverBalance";
80
+ readonly type: "uint256";
81
+ readonly internalType: "uint256";
82
+ }, {
83
+ readonly name: "numSplits";
84
+ readonly type: "uint256";
85
+ readonly internalType: "uint256";
86
+ }, {
87
+ readonly name: "claimRewards";
88
+ readonly type: "bool";
89
+ readonly internalType: "bool";
90
+ }];
91
+ }];
92
+ readonly outputs: readonly [{
93
+ readonly name: "calls";
94
+ readonly type: "tuple[]";
95
+ readonly internalType: "struct MultiCall[]";
96
+ readonly components: readonly [{
97
+ readonly name: "target";
98
+ readonly type: "address";
99
+ readonly internalType: "address";
100
+ }, {
101
+ readonly name: "callData";
102
+ readonly type: "bytes";
103
+ readonly internalType: "bytes";
104
+ }];
105
+ }];
106
+ readonly stateMutability: "nonpayable";
59
107
  }, {
60
108
  readonly type: "function";
61
109
  readonly name: "routeManyToOne";
@@ -1,6 +1,6 @@
1
1
  import type { Address, Hash, PrivateKeyAccount } from "viem";
2
2
  import { BaseError } from "viem";
3
- import type { CreditAccountData, CreditAccountsService, RawTx } from "../sdk/index.js";
3
+ import type { CreditAccountData, CreditAccountsServiceInstance, RawTx } from "../sdk/index.js";
4
4
  import { SDKConstruct } from "../sdk/index.js";
5
5
  export declare class OpenTxRevertedError extends BaseError {
6
6
  readonly txHash: Hash;
@@ -37,7 +37,7 @@ export interface OpenAccountResult {
37
37
  }
38
38
  export declare class AccountOpener extends SDKConstruct {
39
39
  #private;
40
- constructor(service: CreditAccountsService, options?: AccountOpenerOptions);
40
+ constructor(service: CreditAccountsServiceInstance, options?: AccountOpenerOptions);
41
41
  get borrower(): Address;
42
42
  /**
43
43
  * Tries to open account with underlying only in each CM