@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
@@ -5,11 +5,11 @@ import type { GearboxSDK } from "../GearboxSDK.js";
5
5
  import type { OnDemandPriceUpdate, UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
7
  import type { MultiCall } from "../types/index.js";
8
- import type { AddCollateralProps, ChangeDeptProps, ClaimFarmRewardsProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, GetCreditAccountsOptions, OpenCAProps, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, Rewards, UpdateQuotasProps, WithdrawCollateralProps } from "./types.js";
8
+ import type { AddCollateralProps, ChangeDeptProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, GetCreditAccountsOptions, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, Rewards, UpdateQuotasProps } from "./types.js";
9
9
  export interface CreditAccountServiceOptions {
10
10
  batchSize?: number;
11
11
  }
12
- export declare class CreditAccountsService extends SDKConstruct {
12
+ export declare abstract class AbstractCreditAccountService extends SDKConstruct {
13
13
  #private;
14
14
  constructor(sdk: GearboxSDK, options?: CreditAccountServiceOptions);
15
15
  /**
@@ -94,41 +94,6 @@ export declare class CreditAccountsService extends SDKConstruct {
94
94
  * @returns All necessary data to execute the transaction (call, credit facade)
95
95
  */
96
96
  closeCreditAccount({ operation, assetsToWithdraw, creditAccount: ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
97
- /**
98
- * Fully repays credit account or repays credit account and keeps it open with zero debt
99
- - Repays in the following order: price update -> add collateral to cover the debt ->
100
- -> disable quotas for all tokens -> decrease debt -> disable tokens all tokens -> withdraw all tokens
101
- * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
102
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed on which operation is performed
103
- * @param {Array<Address>} collateralAssets - tokens to repay dept.
104
- In the current implementation, this is the (debt+interest+fess) * buffer,
105
- where buffer refers to amount of tokens which will exceed current debt
106
- in order to cover possible debt increase over tx execution
107
- * @param {Array<Asset>} assetsToWithdraw - tokens to withdraw from credit account.
108
- Typically all non zero ca assets (including unclaimed rewards)
109
- plus underlying token (to withdraw any exceeding underlying token after repay)
110
- * @param {Record<Address, PermitResult>} permits - permits of tokens to withdraw (in any permittable token is present) {@link PermitResult}
111
- * @param {Address} to - Wallet address to withdraw underlying to
112
- * @returns All necessary data to execute the transaction (call, credit facade)
113
- */
114
- repayCreditAccount({ operation, collateralAssets, assetsToWithdraw: wrapped, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
115
- /**
116
- * Fully repays liquidatable account
117
- - Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
118
- withdraw all tokens from credit account
119
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
120
- * @param {Array<Address>} collateralAssets - tokens to repay dept.
121
- In the current implementation, this is the (debt+interest+fess) * buffer,
122
- where buffer refers to amount of tokens which will exceed current debt
123
- in order to cover possible debt increase over tx execution
124
- * @param {Array<Address>} assetsToWithdraw - tokens to withdraw from credit account.
125
- Typically all non zero ca assets (including unclaimed rewards)
126
- plus underlying token (to withdraw any exceeding underlying token after repay)
127
- * @param {Record<Address, PermitResult>} permits - permits of tokens to withdraw (in any permittable token is present) {@link PermitResult}
128
- * @param {Address} to - Wallet address to withdraw underlying to
129
- * @returns All necessary data to execute the transaction (call, credit facade)
130
- */
131
- repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw: wrapped, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<CreditAccountOperationResult>;
132
97
  /**
133
98
  * Updates quota of credit account.
134
99
  - CA quota updated in the following order: price update -> update quotas
@@ -161,18 +126,6 @@ export declare class CreditAccountsService extends SDKConstruct {
161
126
  * @returns All necessary data to execute the transaction (call, credit facade)
162
127
  */
163
128
  changeDebt({ creditAccount, amount, }: ChangeDeptProps): Promise<CreditAccountOperationResult>;
164
- /**
165
- * Withdraws a single collateral from credit account to wallet to and updates quotas;
166
- technically can withdraw several tokens at once
167
- - Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
168
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
169
- * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
170
- * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
171
- * @param {Address} to - Wallet address to withdraw token to
172
- * @param {Array<Asset>} assetsToWithdraw - permits for asset if it is permittable {@link PermitResult}
173
- * @returns All necessary data to execute the transaction (call, credit facade)
174
- */
175
- withdrawCollateral({ creditAccount, assetsToWithdraw: wrapped, to, minQuota, averageQuota, }: WithdrawCollateralProps): Promise<CreditAccountOperationResult>;
176
129
  /**
177
130
  * Executes swap specified by given calls, update quotas of affected tokens
178
131
  - Swap is executed in the following order: price update -> execute swap path -> update quotas
@@ -183,21 +136,6 @@ export declare class CreditAccountsService extends SDKConstruct {
183
136
  * @returns All necessary data to execute the transaction (call, credit facade)
184
137
  */
185
138
  executeSwap({ creditAccount, calls: swapCalls, minQuota, averageQuota, }: ExecuteSwapProps): Promise<CreditAccountOperationResult>;
186
- /**
187
- * Executes swap specified by given calls, update quotas of affected tokens
188
- - Claim rewards is executed in the following order: price update -> execute claim calls ->
189
- -> (optionally: disable reward tokens) -> (optionally: update quotas)
190
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
191
- * @param {Array<Asset>} averageQuota - average quota for desired token;
192
- in this case can be omitted since rewards tokens do not require quotas {@link Asset}
193
- * @param {Array<Asset>} minQuota - minimum quota for desired token;
194
- in this case can be omitted since rewards tokens do not require quotas {@link Asset}
195
- * @param {Array<MultiCall>} calls - array of MultiCall from getRewards {@link MultiCall}
196
- * @param {Array<Asset>} tokensToDisable - tokens to disable after rewards claiming;
197
- sometimes is needed since old credit facade used to enable tokens on claim {@link Asset}
198
- * @returns All necessary data to execute the transaction (call, credit facade)
199
- */
200
- claimFarmRewards({ tokensToDisable, calls: claimCalls, creditAccount: ca, minQuota, averageQuota, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
201
139
  /**
202
140
  * Executes enable/disable tokens specified by given tokens lists and token prices
203
141
  * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
@@ -259,13 +197,20 @@ export declare class CreditAccountsService extends SDKConstruct {
259
197
  getOnDemandPriceUpdates(creditManager: Address, creditAccount: RouterCASlice | undefined, desiredQuotas: Array<Asset> | undefined): Promise<Array<OnDemandPriceUpdate>>;
260
198
  /**
261
199
  * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
262
- * If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled).
263
- * If there is creditAccount update balance > 10n && isEnabled.
264
- * If there is desiredQuotas update quotaBalance > 0.
200
+ * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
201
+ * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
202
+ * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
265
203
  * @param acc
266
204
  * @returns
267
205
  */
268
206
  getPriceUpdatesForFacade(creditManager: Address, creditAccount: RouterCASlice | undefined, desiredQuotas: Array<Asset> | undefined): Promise<Array<MultiCall>>;
207
+ protected prepareDisableQuotas(ca: RouterCASlice): Array<MultiCall>;
208
+ protected prepareUpdateQuotas(creditFacade: Address, { averageQuota, minQuota }: PrepareUpdateQuotasProps): Array<MultiCall>;
209
+ protected prepareDecreaseDebt(ca: RouterCASlice): Array<MultiCall>;
210
+ protected prepareDisableTokens(ca: RouterCASlice): Array<MultiCall>;
211
+ protected prepareDisableToken(creditFacade: Address, token: Address): MultiCall;
212
+ protected prepareWithdrawToken(creditFacade: Address, token: Address, amount: bigint, to: Address): MultiCall;
213
+ protected prepareAddCollateral(creditFacade: Address, assets: Array<Asset>, permits: Record<string, PermitResult>): Array<MultiCall>;
269
214
  /**
270
215
  * Returns addresses of market configurators
271
216
  */
@@ -0,0 +1,25 @@
1
+ import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
2
+ import type { ClaimFarmRewardsProps, CreditAccountOperationResult, ICreditAccountsService, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, SetBotProps, WithdrawCollateralProps } from "./types.js";
3
+ export declare class CreditAccountServiceV300 extends AbstractCreditAccountService implements ICreditAccountsService {
4
+ #private;
5
+ /**
6
+ * Implements {@link ICreditAccountsService.setBot}
7
+ */
8
+ setBot(_: SetBotProps): Promise<CreditAccountOperationResult>;
9
+ /**
10
+ * Implements {@link ICreditAccountsService.withdrawCollateral}
11
+ */
12
+ withdrawCollateral({ creditAccount, assetsToWithdraw: wrapped, to, minQuota, averageQuota, }: WithdrawCollateralProps): Promise<CreditAccountOperationResult>;
13
+ /**
14
+ * Implements {@link ICreditAccountsService.repayCreditAccount}
15
+ */
16
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw: wrapped, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
17
+ /**
18
+ * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
19
+ */
20
+ repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw: wrapped, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<CreditAccountOperationResult>;
21
+ /**
22
+ * Implements {@link ICreditAccountsService.claimFarmRewards}
23
+ */
24
+ claimFarmRewards({ tokensToDisable, calls: claimCalls, creditAccount: ca, minQuota, averageQuota, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
25
+ }
@@ -0,0 +1,24 @@
1
+ import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
2
+ import type { ClaimFarmRewardsProps, CreditAccountOperationResult, ICreditAccountsService, RepayAndLiquidateCreditAccountProps, RepayCreditAccountProps, SetBotProps, WithdrawCollateralProps } from "./types.js";
3
+ export declare class CreditAccountServiceV310 extends AbstractCreditAccountService implements ICreditAccountsService {
4
+ /**
5
+ * Implements {@link ICreditAccountsService.setBot}
6
+ */
7
+ setBot({ botAddress, botBaseType, stopBot, creditAccount: ca, }: SetBotProps): Promise<CreditAccountOperationResult>;
8
+ /**
9
+ * Implements {@link ICreditAccountsService.withdrawCollateral}
10
+ */
11
+ withdrawCollateral({ creditAccount, assetsToWithdraw, to, minQuota, averageQuota, }: WithdrawCollateralProps): Promise<CreditAccountOperationResult>;
12
+ /**
13
+ * Implements {@link ICreditAccountsService.repayCreditAccount}
14
+ */
15
+ repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
16
+ /**
17
+ * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
18
+ */
19
+ repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<CreditAccountOperationResult>;
20
+ /**
21
+ * Implements {@link ICreditAccountsService.claimFarmRewards}
22
+ */
23
+ claimFarmRewards({ calls: legacyCalls, creditAccount: ca, minQuota, averageQuota, }: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
24
+ }
@@ -0,0 +1,2 @@
1
+ import type { BotBaseType } from "./types.js";
2
+ export declare const PERMISSION_BY_TYPE: Record<BotBaseType, bigint>;
@@ -0,0 +1,8 @@
1
+ import type { GearboxSDK } from "../GearboxSDK.js";
2
+ import type { CreditAccountsServiceInstance } from "./types.js";
3
+ /**
4
+ * @sdk
5
+ * @version version of desired credit facade; if no credit facade is considered (you only want to get ca list), either v300 or v310 is fine, because ca compressor has nothing to do with credit facade version
6
+ * @returns
7
+ */
8
+ export declare function createCreditAccountService(sdk: GearboxSDK, version: number): CreditAccountsServiceInstance;
@@ -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";
@@ -1,8 +1,11 @@
1
1
  import type { Address, ContractFunctionArgs } from "viem";
2
2
  import type { iCreditAccountCompressorAbi } from "../../abi/compressors.js";
3
+ import type { BotType } from "../../plugins/bots/types.js";
4
+ import type { SDKConstruct } from "../base/SDKConstruct.js";
3
5
  import type { CreditSuite } from "../market/index.js";
4
6
  import type { Asset, RouterCASlice, RouterCloseResult } from "../router/index.js";
5
7
  import type { MultiCall, RawTx } from "../types/index.js";
8
+ import type { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
6
9
  export type GetCreditAccountsArgs = ContractFunctionArgs<typeof iCreditAccountCompressorAbi, "pure" | "view", "getCreditAccounts">;
7
10
  export interface CreditAccountFilter {
8
11
  owner: Address;
@@ -42,18 +45,47 @@ export interface CloseCreditAccountProps {
42
45
  closePath?: RouterCloseResult;
43
46
  }
44
47
  export interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountProps {
48
+ /**
49
+ * close or zeroDebt
50
+ */
45
51
  operation: CloseOptions;
46
52
  }
47
53
  export interface RepayAndLiquidateCreditAccountProps {
54
+ /**
55
+ * tokens to repay dept.
56
+ In the current implementation, this is the (debt+interest+fess) * buffer,
57
+ where buffer refers to amount of tokens which will exceed current debt
58
+ in order to cover possible debt increase over tx execution
59
+ */
48
60
  collateralAssets: Array<Asset>;
61
+ /**
62
+ * tokens to withdraw from credit account.
63
+ Typically all non zero ca assets (including unclaimed rewards)
64
+ plus underlying token (to withdraw any exceeding underlying token after repay)
65
+ */
49
66
  assetsToWithdraw: Array<Asset>;
67
+ /**
68
+ * minimal credit account data on which operation is performed on which operation is performed
69
+ */
50
70
  creditAccount: RouterCASlice;
71
+ /**
72
+ * Wallet address to withdraw underlying to
73
+ */
51
74
  to: Address;
75
+ /**
76
+ * permits of tokens to withdraw (in any permittable token is present)
77
+ */
52
78
  permits: Record<string, PermitResult>;
53
79
  }
54
80
  export interface PrepareUpdateQuotasProps {
55
- minQuota: Array<Asset>;
81
+ /**
82
+ * average quota for desired token
83
+ */
56
84
  averageQuota: Array<Asset>;
85
+ /**
86
+ * minimum quota for desired token
87
+ */
88
+ minQuota: Array<Asset>;
57
89
  }
58
90
  export interface UpdateQuotasProps extends PrepareUpdateQuotasProps {
59
91
  creditAccount: RouterCASlice;
@@ -65,8 +97,17 @@ export interface AddCollateralProps extends PrepareUpdateQuotasProps {
65
97
  creditAccount: RouterCASlice;
66
98
  }
67
99
  export interface WithdrawCollateralProps extends PrepareUpdateQuotasProps {
100
+ /**
101
+ * list of assets which should be withdrawn
102
+ */
68
103
  assetsToWithdraw: Array<Asset>;
104
+ /**
105
+ * Wallet address to withdraw token to
106
+ */
69
107
  to: Address;
108
+ /**
109
+ * minimal credit account data on which operation is performed
110
+ */
70
111
  creditAccount: RouterCASlice;
71
112
  }
72
113
  export interface ExecuteSwapProps extends PrepareUpdateQuotasProps {
@@ -74,8 +115,19 @@ export interface ExecuteSwapProps extends PrepareUpdateQuotasProps {
74
115
  creditAccount: RouterCASlice;
75
116
  }
76
117
  export interface ClaimFarmRewardsProps extends PrepareUpdateQuotasProps {
118
+ /**
119
+ * Legacy property, v3.1 only enables token when quota is bought and when quota is bought token cannot be disabled.
120
+ * Tokens to disable after rewards claiming;
121
+ sometimes is needed since old credit facade used to enable tokens on claim
122
+ */
77
123
  tokensToDisable: Array<Asset>;
124
+ /**
125
+ * Legacy property - array of MultiCall from getRewards
126
+ */
78
127
  calls: Array<MultiCall>;
128
+ /**
129
+ * minimal credit account data on which operation is performed
130
+ */
79
131
  creditAccount: RouterCASlice;
80
132
  }
81
133
  export interface EnableTokensProps {
@@ -115,3 +167,80 @@ export interface Rewards {
115
167
  calls: Array<MultiCall>;
116
168
  rewards: Array<Asset>;
117
169
  }
170
+ /**
171
+ It was planned that bots related to each other like
172
+ {
173
+ liquidationProtection: LiquidationBotType[]
174
+ someOtherBaseType: someOtherDetailedType[ ... ]
175
+ }
176
+
177
+ BotBaseType = "liquidationProtection" | someOtherBaseType
178
+ BotDetailedType = LiquidationBotType | someOtherDetailedType
179
+ * */
180
+ export type BotBaseType = "LIQUIDATION_PROTECTION";
181
+ export type LiquidationBotType = Exclude<BotType, "PARTIAL_LIQUIDATION_BOT">;
182
+ export interface SetBotProps {
183
+ /**
184
+ * Address of a bot that is being updated
185
+ */
186
+ botAddress: Address;
187
+ /**
188
+ * Bot base type (see comments above)
189
+ */
190
+ botBaseType: BotBaseType;
191
+ /**
192
+ * Either stop or enable bot
193
+ */
194
+ stopBot: boolean;
195
+ /**
196
+ * Minimal credit account data {@link RouterCASlice} on which operation is performed
197
+ */
198
+ creditAccount: RouterCASlice;
199
+ }
200
+ export type CreditAccountsServiceInstance = ICreditAccountsService & AbstractCreditAccountService;
201
+ export interface ICreditAccountsService extends SDKConstruct {
202
+ /**
203
+ * V3.1 method, throws in V3. Connects/disables a bot and updates prices
204
+ * @param props - {@link SetBotProps}
205
+ * @return All necessary data to execute the transaction (call, credit facade)
206
+ */
207
+ setBot: (props: SetBotProps) => Promise<CreditAccountOperationResult>;
208
+ /**
209
+ * Withdraws a single collateral from credit account to wallet to and updates quotas;
210
+ technically can withdraw several tokens at once
211
+ - Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
212
+ * @param props - {@link WithdrawCollateralProps}
213
+ * @return All necessary data to execute the transaction (call, credit facade)
214
+ */
215
+ withdrawCollateral(props: WithdrawCollateralProps): Promise<CreditAccountOperationResult>;
216
+ /**
217
+ * Fully repays credit account or repays credit account and keeps it open with zero debt
218
+ - Repays in the following order: price update -> add collateral to cover the debt ->
219
+ -> disable quotas for all tokens -> decrease debt -> disable tokens all tokens -> withdraw all tokens
220
+ - V3.0 claims rewards for tokens which are specified in legacy SDK
221
+ - V3.1 claims rewards for all tokens IF router is also V3.1
222
+ * @param props - {@link RepayCreditAccountProps}
223
+ * @return All necessary data to execute the transaction (call, credit facade)
224
+ */
225
+ repayCreditAccount(props: RepayCreditAccountProps): Promise<CreditAccountOperationResult>;
226
+ /**
227
+ * Fully repays liquidatable account
228
+ - Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
229
+ withdraw all tokens from credit account
230
+ - V3.0 claims rewards for tokens which are specified in legacy SDK
231
+ - V3.1 claims rewards for all tokens IF router is also V3.1
232
+ * @param props - {@link RepayAndLiquidateCreditAccountProps}
233
+ * @return All necessary data to execute the transaction (call, credit facade)
234
+ */
235
+ repayAndLiquidateCreditAccount(props: RepayAndLiquidateCreditAccountProps): Promise<CreditAccountOperationResult>;
236
+ /**
237
+ * Executes swap specified by given calls, update quotas of affected tokens
238
+ - Claim rewards is executed in the following order: price update -> execute claim calls ->
239
+ -> (optionally: disable reward tokens) -> (optionally: update quotas)
240
+ - V3.0 claims rewards for tokens which are specified in legacy SDK
241
+ - V3.1 claims rewards for all tokens IF router is also V3.1 and falls back to legacy calls if router is not v3.0
242
+ * @param props - {@link ClaimFarmRewardsProps}
243
+ * @return All necessary data to execute the transaction (call, credit facade)
244
+ */
245
+ claimFarmRewards(props: ClaimFarmRewardsProps): Promise<CreditAccountOperationResult>;
246
+ }
@@ -3,7 +3,7 @@ import { iRouterV300Abi } from "../../abi/routerV300.js";
3
3
  import type { GearboxSDK } from "../GearboxSDK.js";
4
4
  import type { Leftovers } from "./AbstractRouterContract.js";
5
5
  import { AbstractRouterContract } from "./AbstractRouterContract.js";
6
- import type { FindAllSwapsProps, FindBestClosePathProps, FindClosePathInput, FindOneTokenPathProps, FindOpenStrategyPathProps, IRouterContract, OpenStrategyResult, RouterCASlice, RouterCloseResult, RouterCMSlice, RouterResult } from "./types.js";
6
+ import type { FindAllSwapsProps, FindBestClosePathProps, FindClaimAllRewardsProps, FindClosePathInput, FindOneTokenPathProps, FindOpenStrategyPathProps, IRouterContract, OpenStrategyResult, RouterCASlice, RouterCloseResult, RouterCMSlice, RouterResult, RouterRewardsResult } from "./types.js";
7
7
  type abi = typeof iRouterV300Abi;
8
8
  export declare class RouterV300Contract extends AbstractRouterContract<abi> implements IRouterContract {
9
9
  #private;
@@ -20,6 +20,10 @@ export declare class RouterV300Contract extends AbstractRouterContract<abi> impl
20
20
  * Implements {@link IRouterContract.findOpenStrategyPath}
21
21
  */
22
22
  findOpenStrategyPath({ creditManager: cm, expectedBalances, leftoverBalances, target, slippage, }: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
23
+ /**
24
+ * Implements {@link IRouterContract.findClaimAllRewards}
25
+ */
26
+ findClaimAllRewards(props: FindClaimAllRewardsProps): Promise<RouterRewardsResult>;
23
27
  /**
24
28
  * Implements {@link IRouterContract.findBestClosePath}
25
29
  */
@@ -2,7 +2,7 @@ import { type Address } from "viem";
2
2
  import type { GearboxSDK } from "../GearboxSDK.js";
3
3
  import type { Leftovers } from "./AbstractRouterContract.js";
4
4
  import { AbstractRouterContract } from "./AbstractRouterContract.js";
5
- import type { FindAllSwapsProps, FindBestClosePathProps, FindClosePathInput, FindOneTokenPathProps, FindOpenStrategyPathProps, IRouterContract, OpenStrategyResult, RouterCASlice, RouterCloseResult, RouterCMSlice, RouterResult } from "./types.js";
5
+ import type { FindAllSwapsProps, FindBestClosePathProps, FindClaimAllRewardsProps, FindClosePathInput, FindOneTokenPathProps, FindOpenStrategyPathProps, IRouterContract, OpenStrategyResult, RouterCASlice, RouterCloseResult, RouterCMSlice, RouterResult, RouterRewardsResult } from "./types.js";
6
6
  declare const abi: readonly [{
7
7
  readonly type: "function";
8
8
  readonly name: "componentAddressByType";
@@ -61,6 +61,54 @@ declare const abi: readonly [{
61
61
  readonly internalType: "bytes32[]";
62
62
  }];
63
63
  readonly stateMutability: "view";
64
+ }, {
65
+ readonly type: "function";
66
+ readonly name: "processClaims";
67
+ readonly inputs: readonly [{
68
+ readonly name: "creditAccount";
69
+ readonly type: "address";
70
+ readonly internalType: "address";
71
+ }, {
72
+ readonly name: "tData";
73
+ readonly type: "tuple[]";
74
+ readonly internalType: "struct TokenData[]";
75
+ readonly components: readonly [{
76
+ readonly name: "token";
77
+ readonly type: "address";
78
+ readonly internalType: "address";
79
+ }, {
80
+ readonly name: "balance";
81
+ readonly type: "uint256";
82
+ readonly internalType: "uint256";
83
+ }, {
84
+ readonly name: "leftoverBalance";
85
+ readonly type: "uint256";
86
+ readonly internalType: "uint256";
87
+ }, {
88
+ readonly name: "numSplits";
89
+ readonly type: "uint256";
90
+ readonly internalType: "uint256";
91
+ }, {
92
+ readonly name: "claimRewards";
93
+ readonly type: "bool";
94
+ readonly internalType: "bool";
95
+ }];
96
+ }];
97
+ readonly outputs: readonly [{
98
+ readonly name: "calls";
99
+ readonly type: "tuple[]";
100
+ readonly internalType: "struct MultiCall[]";
101
+ readonly components: readonly [{
102
+ readonly name: "target";
103
+ readonly type: "address";
104
+ readonly internalType: "address";
105
+ }, {
106
+ readonly name: "callData";
107
+ readonly type: "bytes";
108
+ readonly internalType: "bytes";
109
+ }];
110
+ }];
111
+ readonly stateMutability: "nonpayable";
64
112
  }, {
65
113
  readonly type: "function";
66
114
  readonly name: "routeManyToOne";
@@ -368,6 +416,10 @@ export declare class RouterV310Contract extends AbstractRouterContract<abi> impl
368
416
  * Implements {@link IRouterContract.findOpenStrategyPath}
369
417
  */
370
418
  findOpenStrategyPath(props: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
419
+ /**
420
+ * Implements {@link IRouterContract.findClaimAllRewards}
421
+ */
422
+ findClaimAllRewards(props: FindClaimAllRewardsProps): Promise<RouterRewardsResult>;
371
423
  /**
372
424
  * Implements {@link IRouterContract.findBestClosePath}
373
425
  */
@@ -29,6 +29,12 @@ export interface RouterResult {
29
29
  */
30
30
  calls: Array<MultiCall>;
31
31
  }
32
+ export interface RouterRewardsResult {
33
+ /**
34
+ * List of calls swap/unwrap/etc calls to adapters returned by router
35
+ */
36
+ calls: Array<MultiCall>;
37
+ }
32
38
  /**
33
39
  * Router return list of all balances (including 0 balances) after operation, but it doesn't include original balance
34
40
  * - For example you had 5k sUSDS and 5k DAI as collateral, debt is 20k DAI, router will return 25k sUDS and all other token allowed on CM will be 0n or 1n
@@ -168,6 +174,16 @@ export interface FindOpenStrategyPathProps {
168
174
  */
169
175
  slippage: number | bigint;
170
176
  }
177
+ export interface FindClaimAllRewardsProps {
178
+ /**
179
+ * Minimal credit account data on which operation is performed
180
+ */
181
+ creditAccount: RouterCASlice;
182
+ /**
183
+ * Legacy property - array of MultiCall from getRewards
184
+ */
185
+ calls: Array<MultiCall>;
186
+ }
171
187
  export interface FindBestClosePathProps {
172
188
  /**
173
189
  * Minimal credit account data on which operation is performed
@@ -221,6 +237,12 @@ export interface IRouterContract extends IBaseContract {
221
237
  * @returns result - {@link OpenStrategyResult}
222
238
  */
223
239
  findOpenStrategyPath: (props: FindOpenStrategyPathProps) => Promise<OpenStrategyResult>;
240
+ /**
241
+ * In V3.1 - Constructs calls to claim all rewards for Credit Account. In V3.0 - returns input calls
242
+ * @param props - {@link FindClaimAllRewardsProps}
243
+ * @returns result - {@link RouterRewardsResult}
244
+ */
245
+ findClaimAllRewards: (props: FindClaimAllRewardsProps) => Promise<RouterRewardsResult>;
224
246
  /**
225
247
  * Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
226
248
  * Can be used for closing Credit Account and for liquidations as well.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.3.2",
3
+ "version": "8.4.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",