@gearbox-protocol/sdk 3.0.0-vfour.282 → 3.0.0-vfour.283

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.
@@ -190,7 +190,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
190
190
  }
191
191
  /**
192
192
  * Method to get all connected bots for credit account
193
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts to check connected bots on
193
+ * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
194
+ and their credit managers to check connected bots on
194
195
  * @returns call result of getConnectedBots for each credit account
195
196
  */
196
197
  async getConnectedBots(accountsToCheck) {
@@ -239,16 +240,16 @@ class CreditAccountsService extends import_base.SDKConstruct {
239
240
  }
240
241
  /**
241
242
  * Closes credit account or closes credit account and keeps it open with zero debt.
242
- Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
243
+ - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
243
244
  -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens tokens -> withdraw underlying tokenz
244
245
  * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
245
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
246
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
246
247
  * @param {Array<Address>} assetsToWithdraw - tokens to withdraw from credit account.
247
248
  For credit account closing this is the underlying token, because during the closure,
248
249
  all tokens on account are swapped into the underlying,
249
250
  and only the underlying token will remain on the credit account
250
251
  * @param {Address} to - Wallet address to withdraw underlying to
251
- * @param {number} slippage - SLIPPAGE_DECIMALS = 100n
252
+ * @param {number} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
252
253
  * @default 50n
253
254
  * @param {RouterCloseResult | undefined} closePath - result of findBestClosePath method from router; if omited, calls marketRegister.findCreditManager {@link RouterCloseResult}
254
255
  * @returns All necessary data to execute the transaction (call, credit facade)
@@ -287,10 +288,10 @@ class CreditAccountsService extends import_base.SDKConstruct {
287
288
  }
288
289
  /**
289
290
  * Fully repays credit account or repays credit account and keeps it open with zero debt
290
- Repays in the following order: price update -> add collateral to cover the debt ->
291
+ - Repays in the following order: price update -> add collateral to cover the debt ->
291
292
  -> disable quotas for all tokens -> decrease debt -> disable tokens all tokens -> withdraw all tokens
292
293
  * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
293
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
294
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed on which operation is performed
294
295
  * @param {Array<Address>} collateralAssets - tokens to repay dept.
295
296
  In the current implementation, this is the (debt+interest+fess) * buffer,
296
297
  where buffer refers to amount of tokens which will exceed current debt
@@ -340,9 +341,9 @@ class CreditAccountsService extends import_base.SDKConstruct {
340
341
  }
341
342
  /**
342
343
  * Fully repays liquidatable account
343
- Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
344
+ - Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
344
345
  withdraw all tokens from credit account
345
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
346
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
346
347
  * @param {Array<Address>} collateralAssets - tokens to repay dept.
347
348
  In the current implementation, this is the (debt+interest+fess) * buffer,
348
349
  where buffer refers to amount of tokens which will exceed current debt
@@ -391,8 +392,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
391
392
  }
392
393
  /**
393
394
  * Updates quota of credit account.
394
- CA quota updated in the following order: price update -> update quotas
395
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
395
+ - CA quota updated in the following order: price update -> update quotas
396
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
396
397
  * @param {Array<Asset>} averageQuota - average quota for desired tokens {@link Asset}
397
398
  * @param {Array<Asset>} minQuota - minimum quota for desired tokens {@link Asset}
398
399
  * @returns All necessary data to execute the transaction (call, credit facade)
@@ -428,8 +429,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
428
429
  }
429
430
  /**
430
431
  * Adds a single collateral to credit account and updates quotas
431
- Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
432
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
432
+ - Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
433
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
433
434
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
434
435
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
435
436
  * @param {Asset} asset - asset to add as collateral {@link Asset}
@@ -471,8 +472,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
471
472
  }
472
473
  /**
473
474
  * Increases or decreases debt of credit account; debt decrease uses token ON CREDIT ACCOUNT
474
- Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
475
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
475
+ - Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
476
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
476
477
  * @param {bigint} amount - amount to change debt by;
477
478
  0 - prohibited value;
478
479
  negative value for debt decrease;
@@ -511,8 +512,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
511
512
  /**
512
513
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
513
514
  technically can withdraw several tokens at once
514
- Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
515
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
515
+ - Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
516
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
516
517
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
517
518
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
518
519
  * @param {Address} to - Wallet address to withdraw token to
@@ -561,8 +562,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
561
562
  }
562
563
  /**
563
564
  * Executes swap specified by given calls, update quotas of affected tokens
564
- Swap is executed in the following order: price update -> execute swap path -> update quotas
565
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
565
+ - Swap is executed in the following order: price update -> execute swap path -> update quotas
566
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
566
567
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
567
568
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
568
569
  * @param {Array<MultiCall>} calls - array of MultiCall from router methods getSingleSwap or getAllSwaps {@link MultiCall}
@@ -596,9 +597,9 @@ class CreditAccountsService extends import_base.SDKConstruct {
596
597
  }
597
598
  /**
598
599
  * Executes swap specified by given calls, update quotas of affected tokens
599
- Claim rewards is executed in the following order: price update -> execute claim calls ->
600
+ - Claim rewards is executed in the following order: price update -> execute claim calls ->
600
601
  -> (optionally: disable reward tokens) -> (optionally: update quotas)
601
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
602
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
602
603
  * @param {Array<Asset>} averageQuota - average quota for desired token;
603
604
  in this case can be omitted since rewards tokens do not require quotas {@link Asset}
604
605
  * @param {Array<Asset>} minQuota - minimum quota for desired token;
@@ -635,13 +636,13 @@ class CreditAccountsService extends import_base.SDKConstruct {
635
636
  }
636
637
  /**
637
638
  * Executes swap specified by given calls, update quotas of affected tokens
638
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
639
+ - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
639
640
  -> update quotas -> (optionally: execute swap path for trading/strategy) ->
640
641
  -> (optionally: withdraw debt for lending)
641
- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
642
- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
643
- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
644
- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
642
+ - Basic open credit account: price update -> increase debt -> add collateral -> update quotas
643
+ - Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
644
+ - Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
645
+ - In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
645
646
  * @param {bigint} ethAmount - native token amount to attach to tx
646
647
  * @param {Address} creditManager - address of credit manager to open credit account on
647
648
  * @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
@@ -56,16 +56,17 @@ class RouterV300Contract extends import_AbstractRouterContract.AbstractRouterCon
56
56
  this.#connectors = (0, import_sdk_gov_legacy.getConnectors)(sdk.provider.networkType);
57
57
  }
58
58
  /**
59
- * Finds all available swaps for NORMAL tokens
60
- * @param ca
61
- * @param cm
62
- * @param swapOperation
63
- * @param tokenIn
64
- * @param tokenOut
65
- * @param amount
66
- * @param leftoverAmount
67
- * @param slippage
68
- * @returns
59
+ * Finds all available swaps for given tokens; technically should be avoided to use, since doesn't have any advantage over findOneTokenPath.
60
+ * Deduplicates results by minAmount + strigified call path and returns only unique ones.
61
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
62
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
63
+ * @param {SwapOperation} swapOperation - {@link SwapOperation} = "EXACT_INPUT" | "EXACT_INPUT_ALL" | "EXACT_OUTPUT"; however router stopped to support EXACT_OUTPUT
64
+ * @param {Address} tokenIn - address of input token
65
+ * @param {Address} tokenOut - address of output token
66
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
67
+ * @param {bigint} amount - amount of token in to swap
68
+ * @param {bigint} leftoverAmount - amount that should be left on account after swap; technically equals to 0 in the most of the cases
69
+ * @returns Array of {@link RouterResult}
69
70
  */
70
71
  async findAllSwaps({
71
72
  creditAccount: ca,
@@ -105,14 +106,16 @@ class RouterV300Contract extends import_AbstractRouterContract.AbstractRouterCon
105
106
  return Object.values(unique);
106
107
  }
107
108
  /**
108
- * Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
109
- * @param creditAccount
110
- * @param creditManager
111
- * @param tokenIn
112
- * @param tokenOut
113
- * @param amount
114
- * @param slippage
115
- * @returns
109
+ * Find the best path to swap token A to token B.
110
+ * - Connectors - list of tokens which can be used as a token to align path through, for ex. when swapping sUSDe it is good to check swaps through USDe.
111
+ * - #overridePTRedeem - if token is PT token and PT token is already redeemable, we need to claim it manually, since old router can't do it. This can work in old app only because you cannot swap pt_sUSDe into sUSde before maturity and when it is matured, override takes place.
112
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
113
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
114
+ * @param {Address} tokenIn - address of input token
115
+ * @param {Address} tokenOut - address of output token
116
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
117
+ * @param {bigint} amount - amount of token in to swap
118
+ * @returns minAmount, avgAmount found and array of calls to execute swap
116
119
  */
117
120
  async findOneTokenPath(props) {
118
121
  const {
@@ -147,15 +150,22 @@ class RouterV300Contract extends import_AbstractRouterContract.AbstractRouterCon
147
150
  };
148
151
  }
149
152
  /**
150
- * @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
151
- * @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
152
- * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
153
- * if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
154
- * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
155
- * @param leftoverBalances Balances to keep on account after opening
156
- * @param target Address of symbol of desired token
157
- * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
158
- * @returns PathFinderOpenStrategyResult which
153
+ * @dev Finds the best path for opening Credit Account; converts all expectedBalances besides leftoverBalances into target token
154
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
155
+ * @param {Array<Asset>} expectedBalances - Collateral assets + debt asset, nominated in ther respective tokens.
156
+ * For example, if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_000 DAI as collateral
157
+ * from your own funds, expectedBalances should be: [{amount: 10*10**wethDecimals}, {amount: 10000*10**daiDecimals}, {amount: 10000*10**usdcDecimals}]
158
+ * @param leftoverBalances - balances to keep on account after opening.
159
+ * For example if don't want to swap WETH in the example above, leftoverBalances should be: [{amount: 10*10**wethDecimals}]
160
+ * @param target - Address of desired token to swap into
161
+ * @param slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
162
+ * @returns Router return list of all balances (including 0 balances) after operation, but it doesn't include original balance
163
+ * - 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
164
+ * Since FE is interested in FULL balances structure, we override target balance in the following way:
165
+ * min = record[sUSDS] = 5k from collateral + 25k of minAmount; avg = record[sUSDS] = 5k from collateral + 25.5k of avgAmount
166
+ * - minAmount
167
+ * - avgAmount
168
+ * - array of calls to execute swap
159
169
  */
160
170
  async findOpenStrategyPath({
161
171
  creditManager: cm,
@@ -205,12 +215,24 @@ class RouterV300Contract extends import_AbstractRouterContract.AbstractRouterCon
205
215
  /**
206
216
  * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
207
217
  * Can bu used for closing Credit Account and for liquidations as well.
208
- * @param creditAccount CreditAccountStruct object used for close path computation
209
- * @param creditManager CreditManagerSlice for corresponding credit manager
210
- * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
218
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
219
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
220
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
221
+ * @param {ClosePathBalances | undefined} balances - Balances {@link ClosePathBalances} to close account with, if not provided, all assets will be swapped according to inner logic.
222
+ * Consists of:
223
+ * @param {Array<Asset>} expectedBalances - list of all credit account balances nominated in their respective tokens.
224
+ * For example: [{amount: 10x10^wethDecimals}, {amount: 10000x10^daiDecimals}]
225
+ * @param {Array<Asset>} leftoverBalances - list of all credit account balances that shouldn't be swapped nominated in their respective tokens.
226
+ * Used for credit account repaying; in this mode leftover assets list should include all assets besides underlying token.
227
+ * For example considering account above is on DAI CM: [{amount: 10x10^wethDecimals}]
211
228
  * @return The best option in PathFinderCloseResult format, which
212
- * - underlyingBalance - total balance of underlying token
213
- * - calls - list of calls which should be done to swap & unwrap everything to underlying token
229
+ * - underlyingBalance - since this method swaps only tokens different from underlying,
230
+ * we are more interested in TOTAL balance of underlying token after all swaps are done
231
+ * for this reason we sum up underlying token that was on account before swap
232
+ * with underlying token amount found during swap and call it underlyingBalance
233
+ * - calls - list of calls which should be done to swap & unwrap everything to underlying token
234
+ * - amount
235
+ * - minAmount
214
236
  */
215
237
  async findBestClosePath({
216
238
  creditAccount: ca,
@@ -298,12 +320,18 @@ class RouterV300Contract extends import_AbstractRouterContract.AbstractRouterCon
298
320
  pathOptions
299
321
  };
300
322
  }
323
+ /**
324
+ * Connectors - list of tokens which can be used as a token to align path through, for ex. when swapping sUSDe it is good to check swaps through USDe.
325
+ */
301
326
  getAvailableConnectors(collateralTokens) {
302
327
  return collateralTokens.filter(
303
328
  (t) => this.#connectors.includes(t.toLowerCase())
304
329
  );
305
330
  }
306
- // TODO: remove me when new router will be added
331
+ /**
332
+ * if token is PT token and PT token is already redeemable, we need to claim it manually, since old router can't do it.
333
+ This can work in old app only because you cannot swap pt_sUSDe into sUSde before maturity and when it is matured, override takes place.
334
+ */
307
335
  async #overridePTRedeem({
308
336
  creditAccount,
309
337
  creditManager,
@@ -196,7 +196,8 @@ class CreditAccountsService extends SDKConstruct {
196
196
  }
197
197
  /**
198
198
  * Method to get all connected bots for credit account
199
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts to check connected bots on
199
+ * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
200
+ and their credit managers to check connected bots on
200
201
  * @returns call result of getConnectedBots for each credit account
201
202
  */
202
203
  async getConnectedBots(accountsToCheck) {
@@ -245,16 +246,16 @@ class CreditAccountsService extends SDKConstruct {
245
246
  }
246
247
  /**
247
248
  * Closes credit account or closes credit account and keeps it open with zero debt.
248
- Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
249
+ - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
249
250
  -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens tokens -> withdraw underlying tokenz
250
251
  * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
251
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
252
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
252
253
  * @param {Array<Address>} assetsToWithdraw - tokens to withdraw from credit account.
253
254
  For credit account closing this is the underlying token, because during the closure,
254
255
  all tokens on account are swapped into the underlying,
255
256
  and only the underlying token will remain on the credit account
256
257
  * @param {Address} to - Wallet address to withdraw underlying to
257
- * @param {number} slippage - SLIPPAGE_DECIMALS = 100n
258
+ * @param {number} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
258
259
  * @default 50n
259
260
  * @param {RouterCloseResult | undefined} closePath - result of findBestClosePath method from router; if omited, calls marketRegister.findCreditManager {@link RouterCloseResult}
260
261
  * @returns All necessary data to execute the transaction (call, credit facade)
@@ -293,10 +294,10 @@ class CreditAccountsService extends SDKConstruct {
293
294
  }
294
295
  /**
295
296
  * Fully repays credit account or repays credit account and keeps it open with zero debt
296
- Repays in the following order: price update -> add collateral to cover the debt ->
297
+ - Repays in the following order: price update -> add collateral to cover the debt ->
297
298
  -> disable quotas for all tokens -> decrease debt -> disable tokens all tokens -> withdraw all tokens
298
299
  * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
299
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
300
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed on which operation is performed
300
301
  * @param {Array<Address>} collateralAssets - tokens to repay dept.
301
302
  In the current implementation, this is the (debt+interest+fess) * buffer,
302
303
  where buffer refers to amount of tokens which will exceed current debt
@@ -346,9 +347,9 @@ class CreditAccountsService extends SDKConstruct {
346
347
  }
347
348
  /**
348
349
  * Fully repays liquidatable account
349
- Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
350
+ - Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
350
351
  withdraw all tokens from credit account
351
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
352
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
352
353
  * @param {Array<Address>} collateralAssets - tokens to repay dept.
353
354
  In the current implementation, this is the (debt+interest+fess) * buffer,
354
355
  where buffer refers to amount of tokens which will exceed current debt
@@ -397,8 +398,8 @@ class CreditAccountsService extends SDKConstruct {
397
398
  }
398
399
  /**
399
400
  * Updates quota of credit account.
400
- CA quota updated in the following order: price update -> update quotas
401
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
401
+ - CA quota updated in the following order: price update -> update quotas
402
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
402
403
  * @param {Array<Asset>} averageQuota - average quota for desired tokens {@link Asset}
403
404
  * @param {Array<Asset>} minQuota - minimum quota for desired tokens {@link Asset}
404
405
  * @returns All necessary data to execute the transaction (call, credit facade)
@@ -434,8 +435,8 @@ class CreditAccountsService extends SDKConstruct {
434
435
  }
435
436
  /**
436
437
  * Adds a single collateral to credit account and updates quotas
437
- Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
438
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
438
+ - Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
439
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
439
440
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
440
441
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
441
442
  * @param {Asset} asset - asset to add as collateral {@link Asset}
@@ -477,8 +478,8 @@ class CreditAccountsService extends SDKConstruct {
477
478
  }
478
479
  /**
479
480
  * Increases or decreases debt of credit account; debt decrease uses token ON CREDIT ACCOUNT
480
- Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
481
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
481
+ - Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
482
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
482
483
  * @param {bigint} amount - amount to change debt by;
483
484
  0 - prohibited value;
484
485
  negative value for debt decrease;
@@ -517,8 +518,8 @@ class CreditAccountsService extends SDKConstruct {
517
518
  /**
518
519
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
519
520
  technically can withdraw several tokens at once
520
- Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
521
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
521
+ - Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
522
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
522
523
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
523
524
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
524
525
  * @param {Address} to - Wallet address to withdraw token to
@@ -567,8 +568,8 @@ class CreditAccountsService extends SDKConstruct {
567
568
  }
568
569
  /**
569
570
  * Executes swap specified by given calls, update quotas of affected tokens
570
- Swap is executed in the following order: price update -> execute swap path -> update quotas
571
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
571
+ - Swap is executed in the following order: price update -> execute swap path -> update quotas
572
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
572
573
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
573
574
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
574
575
  * @param {Array<MultiCall>} calls - array of MultiCall from router methods getSingleSwap or getAllSwaps {@link MultiCall}
@@ -602,9 +603,9 @@ class CreditAccountsService extends SDKConstruct {
602
603
  }
603
604
  /**
604
605
  * Executes swap specified by given calls, update quotas of affected tokens
605
- Claim rewards is executed in the following order: price update -> execute claim calls ->
606
+ - Claim rewards is executed in the following order: price update -> execute claim calls ->
606
607
  -> (optionally: disable reward tokens) -> (optionally: update quotas)
607
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
608
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
608
609
  * @param {Array<Asset>} averageQuota - average quota for desired token;
609
610
  in this case can be omitted since rewards tokens do not require quotas {@link Asset}
610
611
  * @param {Array<Asset>} minQuota - minimum quota for desired token;
@@ -641,13 +642,13 @@ class CreditAccountsService extends SDKConstruct {
641
642
  }
642
643
  /**
643
644
  * Executes swap specified by given calls, update quotas of affected tokens
644
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
645
+ - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
645
646
  -> update quotas -> (optionally: execute swap path for trading/strategy) ->
646
647
  -> (optionally: withdraw debt for lending)
647
- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
648
- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
649
- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
650
- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
648
+ - Basic open credit account: price update -> increase debt -> add collateral -> update quotas
649
+ - Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
650
+ - Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
651
+ - In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
651
652
  * @param {bigint} ethAmount - native token amount to attach to tx
652
653
  * @param {Address} creditManager - address of credit manager to open credit account on
653
654
  * @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
@@ -33,16 +33,17 @@ class RouterV300Contract extends AbstractRouterContract {
33
33
  this.#connectors = getConnectors(sdk.provider.networkType);
34
34
  }
35
35
  /**
36
- * Finds all available swaps for NORMAL tokens
37
- * @param ca
38
- * @param cm
39
- * @param swapOperation
40
- * @param tokenIn
41
- * @param tokenOut
42
- * @param amount
43
- * @param leftoverAmount
44
- * @param slippage
45
- * @returns
36
+ * Finds all available swaps for given tokens; technically should be avoided to use, since doesn't have any advantage over findOneTokenPath.
37
+ * Deduplicates results by minAmount + strigified call path and returns only unique ones.
38
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
39
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
40
+ * @param {SwapOperation} swapOperation - {@link SwapOperation} = "EXACT_INPUT" | "EXACT_INPUT_ALL" | "EXACT_OUTPUT"; however router stopped to support EXACT_OUTPUT
41
+ * @param {Address} tokenIn - address of input token
42
+ * @param {Address} tokenOut - address of output token
43
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
44
+ * @param {bigint} amount - amount of token in to swap
45
+ * @param {bigint} leftoverAmount - amount that should be left on account after swap; technically equals to 0 in the most of the cases
46
+ * @returns Array of {@link RouterResult}
46
47
  */
47
48
  async findAllSwaps({
48
49
  creditAccount: ca,
@@ -82,14 +83,16 @@ class RouterV300Contract extends AbstractRouterContract {
82
83
  return Object.values(unique);
83
84
  }
84
85
  /**
85
- * Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
86
- * @param creditAccount
87
- * @param creditManager
88
- * @param tokenIn
89
- * @param tokenOut
90
- * @param amount
91
- * @param slippage
92
- * @returns
86
+ * Find the best path to swap token A to token B.
87
+ * - Connectors - list of tokens which can be used as a token to align path through, for ex. when swapping sUSDe it is good to check swaps through USDe.
88
+ * - #overridePTRedeem - if token is PT token and PT token is already redeemable, we need to claim it manually, since old router can't do it. This can work in old app only because you cannot swap pt_sUSDe into sUSde before maturity and when it is matured, override takes place.
89
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
90
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
91
+ * @param {Address} tokenIn - address of input token
92
+ * @param {Address} tokenOut - address of output token
93
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
94
+ * @param {bigint} amount - amount of token in to swap
95
+ * @returns minAmount, avgAmount found and array of calls to execute swap
93
96
  */
94
97
  async findOneTokenPath(props) {
95
98
  const {
@@ -124,15 +127,22 @@ class RouterV300Contract extends AbstractRouterContract {
124
127
  };
125
128
  }
126
129
  /**
127
- * @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
128
- * @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
129
- * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
130
- * if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
131
- * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
132
- * @param leftoverBalances Balances to keep on account after opening
133
- * @param target Address of symbol of desired token
134
- * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
135
- * @returns PathFinderOpenStrategyResult which
130
+ * @dev Finds the best path for opening Credit Account; converts all expectedBalances besides leftoverBalances into target token
131
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
132
+ * @param {Array<Asset>} expectedBalances - Collateral assets + debt asset, nominated in ther respective tokens.
133
+ * For example, if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_000 DAI as collateral
134
+ * from your own funds, expectedBalances should be: [{amount: 10*10**wethDecimals}, {amount: 10000*10**daiDecimals}, {amount: 10000*10**usdcDecimals}]
135
+ * @param leftoverBalances - balances to keep on account after opening.
136
+ * For example if don't want to swap WETH in the example above, leftoverBalances should be: [{amount: 10*10**wethDecimals}]
137
+ * @param target - Address of desired token to swap into
138
+ * @param slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
139
+ * @returns Router return list of all balances (including 0 balances) after operation, but it doesn't include original balance
140
+ * - 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
141
+ * Since FE is interested in FULL balances structure, we override target balance in the following way:
142
+ * min = record[sUSDS] = 5k from collateral + 25k of minAmount; avg = record[sUSDS] = 5k from collateral + 25.5k of avgAmount
143
+ * - minAmount
144
+ * - avgAmount
145
+ * - array of calls to execute swap
136
146
  */
137
147
  async findOpenStrategyPath({
138
148
  creditManager: cm,
@@ -182,12 +192,24 @@ class RouterV300Contract extends AbstractRouterContract {
182
192
  /**
183
193
  * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
184
194
  * Can bu used for closing Credit Account and for liquidations as well.
185
- * @param creditAccount CreditAccountStruct object used for close path computation
186
- * @param creditManager CreditManagerSlice for corresponding credit manager
187
- * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
195
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
196
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
197
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
198
+ * @param {ClosePathBalances | undefined} balances - Balances {@link ClosePathBalances} to close account with, if not provided, all assets will be swapped according to inner logic.
199
+ * Consists of:
200
+ * @param {Array<Asset>} expectedBalances - list of all credit account balances nominated in their respective tokens.
201
+ * For example: [{amount: 10x10^wethDecimals}, {amount: 10000x10^daiDecimals}]
202
+ * @param {Array<Asset>} leftoverBalances - list of all credit account balances that shouldn't be swapped nominated in their respective tokens.
203
+ * Used for credit account repaying; in this mode leftover assets list should include all assets besides underlying token.
204
+ * For example considering account above is on DAI CM: [{amount: 10x10^wethDecimals}]
188
205
  * @return The best option in PathFinderCloseResult format, which
189
- * - underlyingBalance - total balance of underlying token
190
- * - calls - list of calls which should be done to swap & unwrap everything to underlying token
206
+ * - underlyingBalance - since this method swaps only tokens different from underlying,
207
+ * we are more interested in TOTAL balance of underlying token after all swaps are done
208
+ * for this reason we sum up underlying token that was on account before swap
209
+ * with underlying token amount found during swap and call it underlyingBalance
210
+ * - calls - list of calls which should be done to swap & unwrap everything to underlying token
211
+ * - amount
212
+ * - minAmount
191
213
  */
192
214
  async findBestClosePath({
193
215
  creditAccount: ca,
@@ -275,12 +297,18 @@ class RouterV300Contract extends AbstractRouterContract {
275
297
  pathOptions
276
298
  };
277
299
  }
300
+ /**
301
+ * Connectors - list of tokens which can be used as a token to align path through, for ex. when swapping sUSDe it is good to check swaps through USDe.
302
+ */
278
303
  getAvailableConnectors(collateralTokens) {
279
304
  return collateralTokens.filter(
280
305
  (t) => this.#connectors.includes(t.toLowerCase())
281
306
  );
282
307
  }
283
- // TODO: remove me when new router will be added
308
+ /**
309
+ * if token is PT token and PT token is already redeemable, we need to claim it manually, since old router can't do it.
310
+ This can work in old app only because you cannot swap pt_sUSDe into sUSde before maturity and when it is matured, override takes place.
311
+ */
284
312
  async #overridePTRedeem({
285
313
  creditAccount,
286
314
  creditManager,
@@ -136,7 +136,8 @@ export declare class CreditAccountsService extends SDKConstruct {
136
136
  getRewards(creditAccount: Address): Promise<Array<Rewards>>;
137
137
  /**
138
138
  * Method to get all connected bots for credit account
139
- * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts to check connected bots on
139
+ * @param {Array<{ creditAccount: Address; creditManager: Address }>} accountsToCheck - list of credit accounts
140
+ and their credit managers to check connected bots on
140
141
  * @returns call result of getConnectedBots for each credit account
141
142
  */
142
143
  getConnectedBots(accountsToCheck: Array<{
@@ -172,16 +173,16 @@ export declare class CreditAccountsService extends SDKConstruct {
172
173
  fullyLiquidate(account: RouterCASlice, to: Address, slippage?: bigint): Promise<CloseCreditAccountResult>;
173
174
  /**
174
175
  * Closes credit account or closes credit account and keeps it open with zero debt.
175
- Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
176
+ - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
176
177
  -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens tokens -> withdraw underlying tokenz
177
178
  * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
178
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
179
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
179
180
  * @param {Array<Address>} assetsToWithdraw - tokens to withdraw from credit account.
180
181
  For credit account closing this is the underlying token, because during the closure,
181
182
  all tokens on account are swapped into the underlying,
182
183
  and only the underlying token will remain on the credit account
183
184
  * @param {Address} to - Wallet address to withdraw underlying to
184
- * @param {number} slippage - SLIPPAGE_DECIMALS = 100n
185
+ * @param {number} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
185
186
  * @default 50n
186
187
  * @param {RouterCloseResult | undefined} closePath - result of findBestClosePath method from router; if omited, calls marketRegister.findCreditManager {@link RouterCloseResult}
187
188
  * @returns All necessary data to execute the transaction (call, credit facade)
@@ -189,10 +190,10 @@ export declare class CreditAccountsService extends SDKConstruct {
189
190
  closeCreditAccount({ operation, assetsToWithdraw, creditAccount: ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
190
191
  /**
191
192
  * Fully repays credit account or repays credit account and keeps it open with zero debt
192
- Repays in the following order: price update -> add collateral to cover the debt ->
193
+ - Repays in the following order: price update -> add collateral to cover the debt ->
193
194
  -> disable quotas for all tokens -> decrease debt -> disable tokens all tokens -> withdraw all tokens
194
195
  * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
195
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
196
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed on which operation is performed
196
197
  * @param {Array<Address>} collateralAssets - tokens to repay dept.
197
198
  In the current implementation, this is the (debt+interest+fess) * buffer,
198
199
  where buffer refers to amount of tokens which will exceed current debt
@@ -207,9 +208,9 @@ export declare class CreditAccountsService extends SDKConstruct {
207
208
  repayCreditAccount({ operation, collateralAssets, assetsToWithdraw: wrapped, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<CommonResult>;
208
209
  /**
209
210
  * Fully repays liquidatable account
210
- Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
211
+ - Repay and liquidate is executed in the following order: price update -> add collateral to cover the debt ->
211
212
  withdraw all tokens from credit account
212
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
213
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
213
214
  * @param {Array<Address>} collateralAssets - tokens to repay dept.
214
215
  In the current implementation, this is the (debt+interest+fess) * buffer,
215
216
  where buffer refers to amount of tokens which will exceed current debt
@@ -224,8 +225,8 @@ export declare class CreditAccountsService extends SDKConstruct {
224
225
  repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw: wrapped, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<CommonResult>;
225
226
  /**
226
227
  * Updates quota of credit account.
227
- CA quota updated in the following order: price update -> update quotas
228
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
228
+ - CA quota updated in the following order: price update -> update quotas
229
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
229
230
  * @param {Array<Asset>} averageQuota - average quota for desired tokens {@link Asset}
230
231
  * @param {Array<Asset>} minQuota - minimum quota for desired tokens {@link Asset}
231
232
  * @returns All necessary data to execute the transaction (call, credit facade)
@@ -233,8 +234,8 @@ export declare class CreditAccountsService extends SDKConstruct {
233
234
  updateQuotas({ minQuota, averageQuota, creditAccount, }: UpdateQuotasProps): Promise<CommonResult>;
234
235
  /**
235
236
  * Adds a single collateral to credit account and updates quotas
236
- Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
237
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
237
+ - Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
238
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
238
239
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
239
240
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
240
241
  * @param {Asset} asset - asset to add as collateral {@link Asset}
@@ -245,8 +246,8 @@ export declare class CreditAccountsService extends SDKConstruct {
245
246
  addCollateral({ creditAccount, asset, permit, ethAmount, minQuota, averageQuota, }: AddCollateralProps): Promise<CommonResult>;
246
247
  /**
247
248
  * Increases or decreases debt of credit account; debt decrease uses token ON CREDIT ACCOUNT
248
- Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
249
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
249
+ - Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
250
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
250
251
  * @param {bigint} amount - amount to change debt by;
251
252
  0 - prohibited value;
252
253
  negative value for debt decrease;
@@ -257,8 +258,8 @@ export declare class CreditAccountsService extends SDKConstruct {
257
258
  /**
258
259
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
259
260
  technically can withdraw several tokens at once
260
- Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
261
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
261
+ - Collateral is withdrawn in the following order: price update -> withdraw token -> update quotas for affected tokens
262
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
262
263
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
263
264
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
264
265
  * @param {Address} to - Wallet address to withdraw token to
@@ -268,8 +269,8 @@ export declare class CreditAccountsService extends SDKConstruct {
268
269
  withdrawCollateral({ creditAccount, assetsToWithdraw: wrapped, to, minQuota, averageQuota, }: WithdrawCollateralProps): Promise<CommonResult>;
269
270
  /**
270
271
  * Executes swap specified by given calls, update quotas of affected tokens
271
- Swap is executed in the following order: price update -> execute swap path -> update quotas
272
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
272
+ - Swap is executed in the following order: price update -> execute swap path -> update quotas
273
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
273
274
  * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
274
275
  * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
275
276
  * @param {Array<MultiCall>} calls - array of MultiCall from router methods getSingleSwap or getAllSwaps {@link MultiCall}
@@ -278,9 +279,9 @@ export declare class CreditAccountsService extends SDKConstruct {
278
279
  executeSwap({ creditAccount, calls: swapCalls, minQuota, averageQuota, }: ExecuteSwapProps): Promise<CommonResult>;
279
280
  /**
280
281
  * Executes swap specified by given calls, update quotas of affected tokens
281
- Claim rewards is executed in the following order: price update -> execute claim calls ->
282
+ - Claim rewards is executed in the following order: price update -> execute claim calls ->
282
283
  -> (optionally: disable reward tokens) -> (optionally: update quotas)
283
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice}
284
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
284
285
  * @param {Array<Asset>} averageQuota - average quota for desired token;
285
286
  in this case can be omitted since rewards tokens do not require quotas {@link Asset}
286
287
  * @param {Array<Asset>} minQuota - minimum quota for desired token;
@@ -293,13 +294,13 @@ export declare class CreditAccountsService extends SDKConstruct {
293
294
  claimFarmRewards({ tokensToDisable, calls: claimCalls, creditAccount: ca, minQuota, averageQuota, }: ClaimFarmRewardsProps): Promise<CommonResult>;
294
295
  /**
295
296
  * Executes swap specified by given calls, update quotas of affected tokens
296
- Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
297
+ - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
297
298
  -> update quotas -> (optionally: execute swap path for trading/strategy) ->
298
299
  -> (optionally: withdraw debt for lending)
299
- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
300
- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
301
- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
302
- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
300
+ - Basic open credit account: price update -> increase debt -> add collateral -> update quotas
301
+ - Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
302
+ - Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
303
+ - In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
303
304
  * @param {bigint} ethAmount - native token amount to attach to tx
304
305
  * @param {Address} creditManager - address of credit manager to open credit account on
305
306
  * @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
@@ -9,50 +9,72 @@ export declare class RouterV300Contract extends AbstractRouterContract<abi> impl
9
9
  #private;
10
10
  constructor(sdk: GearboxSDK, address: Address);
11
11
  /**
12
- * Finds all available swaps for NORMAL tokens
13
- * @param ca
14
- * @param cm
15
- * @param swapOperation
16
- * @param tokenIn
17
- * @param tokenOut
18
- * @param amount
19
- * @param leftoverAmount
20
- * @param slippage
21
- * @returns
12
+ * Finds all available swaps for given tokens; technically should be avoided to use, since doesn't have any advantage over findOneTokenPath.
13
+ * Deduplicates results by minAmount + strigified call path and returns only unique ones.
14
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
15
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
16
+ * @param {SwapOperation} swapOperation - {@link SwapOperation} = "EXACT_INPUT" | "EXACT_INPUT_ALL" | "EXACT_OUTPUT"; however router stopped to support EXACT_OUTPUT
17
+ * @param {Address} tokenIn - address of input token
18
+ * @param {Address} tokenOut - address of output token
19
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
20
+ * @param {bigint} amount - amount of token in to swap
21
+ * @param {bigint} leftoverAmount - amount that should be left on account after swap; technically equals to 0 in the most of the cases
22
+ * @returns Array of {@link RouterResult}
22
23
  */
23
24
  findAllSwaps({ creditAccount: ca, creditManager: cm, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage, }: FindAllSwapsProps): Promise<Array<RouterResult>>;
24
25
  /**
25
- * Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
26
- * @param creditAccount
27
- * @param creditManager
28
- * @param tokenIn
29
- * @param tokenOut
30
- * @param amount
31
- * @param slippage
32
- * @returns
26
+ * Find the best path to swap token A to token B.
27
+ * - Connectors - list of tokens which can be used as a token to align path through, for ex. when swapping sUSDe it is good to check swaps through USDe.
28
+ * - #overridePTRedeem - if token is PT token and PT token is already redeemable, we need to claim it manually, since old router can't do it. This can work in old app only because you cannot swap pt_sUSDe into sUSde before maturity and when it is matured, override takes place.
29
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
30
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
31
+ * @param {Address} tokenIn - address of input token
32
+ * @param {Address} tokenOut - address of output token
33
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
34
+ * @param {bigint} amount - amount of token in to swap
35
+ * @returns minAmount, avgAmount found and array of calls to execute swap
33
36
  */
34
37
  findOneTokenPath(props: FindOneTokenPathProps): Promise<RouterResult>;
35
38
  /**
36
- * @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
37
- * @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
38
- * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
39
- * if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
40
- * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
41
- * @param leftoverBalances Balances to keep on account after opening
42
- * @param target Address of symbol of desired token
43
- * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
44
- * @returns PathFinderOpenStrategyResult which
39
+ * @dev Finds the best path for opening Credit Account; converts all expectedBalances besides leftoverBalances into target token
40
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
41
+ * @param {Array<Asset>} expectedBalances - Collateral assets + debt asset, nominated in ther respective tokens.
42
+ * For example, if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_000 DAI as collateral
43
+ * from your own funds, expectedBalances should be: [{amount: 10*10**wethDecimals}, {amount: 10000*10**daiDecimals}, {amount: 10000*10**usdcDecimals}]
44
+ * @param leftoverBalances - balances to keep on account after opening.
45
+ * For example if don't want to swap WETH in the example above, leftoverBalances should be: [{amount: 10*10**wethDecimals}]
46
+ * @param target - Address of desired token to swap into
47
+ * @param slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
48
+ * @returns Router return list of all balances (including 0 balances) after operation, but it doesn't include original balance
49
+ * - 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
50
+ * Since FE is interested in FULL balances structure, we override target balance in the following way:
51
+ * min = record[sUSDS] = 5k from collateral + 25k of minAmount; avg = record[sUSDS] = 5k from collateral + 25.5k of avgAmount
52
+ * - minAmount
53
+ * - avgAmount
54
+ * - array of calls to execute swap
45
55
  */
46
56
  findOpenStrategyPath({ creditManager: cm, expectedBalances, leftoverBalances, target, slippage, }: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
47
57
  /**
48
58
  * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
49
59
  * Can bu used for closing Credit Account and for liquidations as well.
50
- * @param creditAccount CreditAccountStruct object used for close path computation
51
- * @param creditManager CreditManagerSlice for corresponding credit manager
52
- * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
60
+ * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
61
+ * @param {RouterCMSlice} creditManager - minimal credit manager data {@link RouterCMSlice} on which operation is performed
62
+ * @param {number | bigint} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
63
+ * @param {ClosePathBalances | undefined} balances - Balances {@link ClosePathBalances} to close account with, if not provided, all assets will be swapped according to inner logic.
64
+ * Consists of:
65
+ * @param {Array<Asset>} expectedBalances - list of all credit account balances nominated in their respective tokens.
66
+ * For example: [{amount: 10x10^wethDecimals}, {amount: 10000x10^daiDecimals}]
67
+ * @param {Array<Asset>} leftoverBalances - list of all credit account balances that shouldn't be swapped nominated in their respective tokens.
68
+ * Used for credit account repaying; in this mode leftover assets list should include all assets besides underlying token.
69
+ * For example considering account above is on DAI CM: [{amount: 10x10^wethDecimals}]
53
70
  * @return The best option in PathFinderCloseResult format, which
54
- * - underlyingBalance - total balance of underlying token
55
- * - calls - list of calls which should be done to swap & unwrap everything to underlying token
71
+ * - underlyingBalance - since this method swaps only tokens different from underlying,
72
+ * we are more interested in TOTAL balance of underlying token after all swaps are done
73
+ * for this reason we sum up underlying token that was on account before swap
74
+ * with underlying token amount found during swap and call it underlyingBalance
75
+ * - calls - list of calls which should be done to swap & unwrap everything to underlying token
76
+ * - amount
77
+ * - minAmount
56
78
  */
57
79
  findBestClosePath({ creditAccount: ca, creditManager: cm, slippage, balances, }: FindBestClosePathProps): Promise<RouterCloseResult>;
58
80
  /**
@@ -63,6 +85,9 @@ export declare class RouterV300Contract extends AbstractRouterContract<abi> impl
63
85
  * @returns
64
86
  */
65
87
  getFindClosePathInput(ca: RouterCASlice, cm: RouterCMSlice, balances?: Leftovers): FindClosePathInput;
88
+ /**
89
+ * Connectors - list of tokens which can be used as a token to align path through, for ex. when swapping sUSDe it is good to check swaps through USDe.
90
+ */
66
91
  getAvailableConnectors(collateralTokens: Array<Address>): Array<Address>;
67
92
  }
68
93
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.282",
3
+ "version": "3.0.0-vfour.283",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",