@gearbox-protocol/sdk 3.0.0-vfour.86 → 3.0.0-vfour.88
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.
- package/dist/cjs/sdk/index.cjs +120 -67
- package/dist/cjs/sdk/index.d.ts +62 -22
- package/dist/esm/sdk/index.d.mts +62 -22
- package/dist/esm/sdk/index.mjs +120 -67
- package/package.json +1 -1
package/dist/cjs/sdk/index.cjs
CHANGED
|
@@ -22418,11 +22418,11 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
22418
22418
|
*/
|
|
22419
22419
|
async fullyLiquidate(account, to, slippage = 50n) {
|
|
22420
22420
|
const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
|
|
22421
|
-
const routerCloseResult = await this.sdk.router.findBestClosePath(
|
|
22422
|
-
account,
|
|
22423
|
-
cm.creditManager,
|
|
22421
|
+
const routerCloseResult = await this.sdk.router.findBestClosePath({
|
|
22422
|
+
creditAccount: account,
|
|
22423
|
+
creditManager: cm.creditManager,
|
|
22424
22424
|
slippage
|
|
22425
|
-
);
|
|
22425
|
+
});
|
|
22426
22426
|
const priceUpdates = await this.getPriceUpdatesForFacade(account);
|
|
22427
22427
|
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
22428
22428
|
account.creditAccount,
|
|
@@ -22434,39 +22434,104 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
22434
22434
|
/**
|
|
22435
22435
|
* Closes credit account or sets debt to zero (but keep account)
|
|
22436
22436
|
* @param operation
|
|
22437
|
-
* @param
|
|
22437
|
+
* @param creditAccount
|
|
22438
22438
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
22439
22439
|
* @param to Address to withdraw underlying to
|
|
22440
22440
|
* @param slippage
|
|
22441
|
+
* @param closePath
|
|
22441
22442
|
* @returns
|
|
22442
22443
|
*/
|
|
22443
|
-
async closeCreditAccount(
|
|
22444
|
-
|
|
22445
|
-
|
|
22446
|
-
|
|
22447
|
-
|
|
22448
|
-
|
|
22449
|
-
|
|
22444
|
+
async closeCreditAccount({
|
|
22445
|
+
operation,
|
|
22446
|
+
assetsToWithdraw,
|
|
22447
|
+
creditAccount: ca,
|
|
22448
|
+
to,
|
|
22449
|
+
slippage = 50n,
|
|
22450
|
+
closePath
|
|
22451
|
+
}) {
|
|
22452
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
22453
|
+
const routerCloseResult = closePath || await this.sdk.router.findBestClosePath({
|
|
22454
|
+
creditAccount: ca,
|
|
22455
|
+
creditManager: cm.creditManager,
|
|
22456
|
+
slippage
|
|
22450
22457
|
});
|
|
22451
|
-
const
|
|
22458
|
+
const calls = [
|
|
22459
|
+
...routerCloseResult.calls,
|
|
22460
|
+
...this.#prepareDisableQuotas(ca),
|
|
22461
|
+
...this.#prepareDecreaseDebt(ca),
|
|
22462
|
+
...this.#prepareDisableTokens(ca),
|
|
22463
|
+
...assetsToWithdraw.map(
|
|
22464
|
+
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22465
|
+
)
|
|
22466
|
+
];
|
|
22467
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
22452
22468
|
return { tx, calls, routerCloseResult };
|
|
22453
22469
|
}
|
|
22454
22470
|
/**
|
|
22455
22471
|
* Repays credit account or sets debt to zero (but keep account)
|
|
22456
22472
|
* @param operation
|
|
22457
|
-
* @param
|
|
22473
|
+
* @param creditAccount
|
|
22458
22474
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
22459
22475
|
* @param collateralAssets Tokens to pay for
|
|
22460
22476
|
* @param to Address to withdraw underlying to
|
|
22461
22477
|
* @param slippage
|
|
22478
|
+
* @param permits
|
|
22462
22479
|
* @returns
|
|
22463
22480
|
*/
|
|
22464
|
-
async repayCreditAccount(
|
|
22465
|
-
|
|
22466
|
-
|
|
22481
|
+
async repayCreditAccount({
|
|
22482
|
+
operation,
|
|
22483
|
+
collateralAssets,
|
|
22484
|
+
assetsToWithdraw,
|
|
22485
|
+
creditAccount: ca,
|
|
22486
|
+
permits,
|
|
22487
|
+
to
|
|
22488
|
+
}) {
|
|
22489
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
22490
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
22491
|
+
const calls = [
|
|
22492
|
+
...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
|
|
22493
|
+
...this.#prepareDisableQuotas(ca),
|
|
22494
|
+
...this.#prepareDecreaseDebt(ca),
|
|
22495
|
+
...this.#prepareDisableTokens(ca),
|
|
22496
|
+
// TODO: probably needs a way to handle reward tokens
|
|
22497
|
+
...assetsToWithdraw.map(
|
|
22498
|
+
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22499
|
+
)
|
|
22500
|
+
];
|
|
22501
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
22502
|
+
return { tx, calls };
|
|
22503
|
+
}
|
|
22504
|
+
/**
|
|
22505
|
+
* Repays liquidatable credit account
|
|
22506
|
+
* @param creditAccount
|
|
22507
|
+
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
22508
|
+
* @param collateralAssets Tokens to pay for
|
|
22509
|
+
* @param to Address to withdraw underlying to
|
|
22510
|
+
* @param slippage
|
|
22511
|
+
* @returns
|
|
22512
|
+
*/
|
|
22513
|
+
async repayAndLiquidateCreditAccount({
|
|
22514
|
+
collateralAssets,
|
|
22515
|
+
assetsToWithdraw,
|
|
22516
|
+
creditAccount: ca,
|
|
22517
|
+
permits,
|
|
22518
|
+
to
|
|
22519
|
+
}) {
|
|
22520
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
22521
|
+
const priceUpdates = await this.getPriceUpdatesForFacade(ca);
|
|
22522
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
22523
|
+
const calls = [
|
|
22524
|
+
...priceUpdates,
|
|
22525
|
+
...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
|
|
22526
|
+
...assetsToWithdraw.map(
|
|
22527
|
+
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22528
|
+
)
|
|
22529
|
+
];
|
|
22530
|
+
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
22531
|
+
ca.creditAccount,
|
|
22532
|
+
to,
|
|
22533
|
+
calls
|
|
22467
22534
|
);
|
|
22468
|
-
const { calls } = await this.#prepareRepayCreditAccount(props);
|
|
22469
|
-
const tx = props.operation === "close" ? cm.creditFacade.closeCreditAccount(props.ca.creditAccount, calls) : cm.creditFacade.multicall(props.ca.creditAccount, calls);
|
|
22470
22535
|
return { tx, calls };
|
|
22471
22536
|
}
|
|
22472
22537
|
/**
|
|
@@ -22557,45 +22622,6 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
22557
22622
|
const updates = await this.getOnDemandPriceUpdates(acc);
|
|
22558
22623
|
return cm.creditFacade.encodeOnDemandPriceUpdates(updates);
|
|
22559
22624
|
}
|
|
22560
|
-
async #prepareCloseCreditAccount({
|
|
22561
|
-
ca,
|
|
22562
|
-
cm,
|
|
22563
|
-
assetsToWithdraw,
|
|
22564
|
-
to,
|
|
22565
|
-
slippage = 50n,
|
|
22566
|
-
closePath
|
|
22567
|
-
}) {
|
|
22568
|
-
const routerCloseResult = closePath || await this.sdk.router.findBestClosePath(ca, cm.creditManager, slippage);
|
|
22569
|
-
const calls = [
|
|
22570
|
-
...routerCloseResult.calls,
|
|
22571
|
-
...this.#prepareDisableQuotas(ca),
|
|
22572
|
-
...this.#prepareDecreaseDebt(ca),
|
|
22573
|
-
...this.#prepareDisableTokens(ca),
|
|
22574
|
-
...assetsToWithdraw.map(
|
|
22575
|
-
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22576
|
-
)
|
|
22577
|
-
];
|
|
22578
|
-
return { calls, routerCloseResult };
|
|
22579
|
-
}
|
|
22580
|
-
async #prepareRepayCreditAccount({
|
|
22581
|
-
ca,
|
|
22582
|
-
assetsToWithdraw,
|
|
22583
|
-
to,
|
|
22584
|
-
collateralAssets,
|
|
22585
|
-
permits
|
|
22586
|
-
}) {
|
|
22587
|
-
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
22588
|
-
const calls = [
|
|
22589
|
-
...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
|
|
22590
|
-
...this.#prepareDisableQuotas(ca),
|
|
22591
|
-
...this.#prepareDecreaseDebt(ca),
|
|
22592
|
-
...this.#prepareDisableTokens(ca),
|
|
22593
|
-
...assetsToWithdraw.map(
|
|
22594
|
-
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22595
|
-
)
|
|
22596
|
-
];
|
|
22597
|
-
return { calls };
|
|
22598
|
-
}
|
|
22599
22625
|
#prepareDisableQuotas(ca) {
|
|
22600
22626
|
const calls = [];
|
|
22601
22627
|
for (const { token, quota } of ca.tokens) {
|
|
@@ -23001,7 +23027,16 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23001
23027
|
* @param slippage
|
|
23002
23028
|
* @returns
|
|
23003
23029
|
*/
|
|
23004
|
-
async findAllSwaps(
|
|
23030
|
+
async findAllSwaps({
|
|
23031
|
+
creditAccount: ca,
|
|
23032
|
+
creditManager: cm,
|
|
23033
|
+
swapOperation,
|
|
23034
|
+
tokenIn,
|
|
23035
|
+
tokenOut,
|
|
23036
|
+
amount,
|
|
23037
|
+
leftoverAmount,
|
|
23038
|
+
slippage
|
|
23039
|
+
}) {
|
|
23005
23040
|
const connectors = this.getAvailableConnectors(cm.collateralTokens);
|
|
23006
23041
|
const swapTask = {
|
|
23007
23042
|
swapOperation: SWAP_OPERATIONS[swapOperation],
|
|
@@ -23031,15 +23066,22 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23031
23066
|
}
|
|
23032
23067
|
/**
|
|
23033
23068
|
* Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
|
|
23034
|
-
* @param
|
|
23035
|
-
* @param
|
|
23069
|
+
* @param creditAccount
|
|
23070
|
+
* @param creditManager
|
|
23036
23071
|
* @param tokenIn
|
|
23037
23072
|
* @param tokenOut
|
|
23038
23073
|
* @param amount
|
|
23039
23074
|
* @param slippage
|
|
23040
23075
|
* @returns
|
|
23041
23076
|
*/
|
|
23042
|
-
async findOneTokenPath(
|
|
23077
|
+
async findOneTokenPath({
|
|
23078
|
+
creditAccount: ca,
|
|
23079
|
+
creditManager: cm,
|
|
23080
|
+
tokenIn,
|
|
23081
|
+
tokenOut,
|
|
23082
|
+
amount,
|
|
23083
|
+
slippage
|
|
23084
|
+
}) {
|
|
23043
23085
|
const connectors = this.getAvailableConnectors(cm.collateralTokens);
|
|
23044
23086
|
const { result } = await this.contract.simulate.findOneTokenPath(
|
|
23045
23087
|
[
|
|
@@ -23062,7 +23104,7 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23062
23104
|
}
|
|
23063
23105
|
/**
|
|
23064
23106
|
* @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
|
|
23065
|
-
* @param
|
|
23107
|
+
* @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
|
|
23066
23108
|
* @param expectedBalances Expected balances which would be on account accounting also debt. For example,
|
|
23067
23109
|
* if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
|
|
23068
23110
|
* from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
|
|
@@ -23071,7 +23113,13 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23071
23113
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
23072
23114
|
* @returns PathFinderOpenStrategyResult which
|
|
23073
23115
|
*/
|
|
23074
|
-
async findOpenStrategyPath(
|
|
23116
|
+
async findOpenStrategyPath({
|
|
23117
|
+
creditManager: cm,
|
|
23118
|
+
expectedBalances,
|
|
23119
|
+
leftoverBalances,
|
|
23120
|
+
target,
|
|
23121
|
+
slippage
|
|
23122
|
+
}) {
|
|
23075
23123
|
const [expectedMap, leftoverMap] = [
|
|
23076
23124
|
balancesMap(expectedBalances),
|
|
23077
23125
|
balancesMap(leftoverBalances)
|
|
@@ -23113,14 +23161,19 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23113
23161
|
/**
|
|
23114
23162
|
* @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
|
|
23115
23163
|
* Can bu used for closing Credit Account and for liquidations as well.
|
|
23116
|
-
* @param
|
|
23117
|
-
* @param
|
|
23164
|
+
* @param creditAccount CreditAccountStruct object used for close path computation
|
|
23165
|
+
* @param creditManager CreditManagerSlice for corresponding credit manager
|
|
23118
23166
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
23119
23167
|
* @return The best option in PathFinderCloseResult format, which
|
|
23120
23168
|
* - underlyingBalance - total balance of underlying token
|
|
23121
23169
|
* - calls - list of calls which should be done to swap & unwrap everything to underlying token
|
|
23122
23170
|
*/
|
|
23123
|
-
async findBestClosePath(
|
|
23171
|
+
async findBestClosePath({
|
|
23172
|
+
creditAccount: ca,
|
|
23173
|
+
creditManager: cm,
|
|
23174
|
+
slippage,
|
|
23175
|
+
balances
|
|
23176
|
+
}) {
|
|
23124
23177
|
const { pathOptions, expected, leftover, connectors } = this.getFindClosePathInput(
|
|
23125
23178
|
ca,
|
|
23126
23179
|
cm,
|
package/dist/cjs/sdk/index.d.ts
CHANGED
|
@@ -24891,7 +24891,7 @@ interface PathOption {
|
|
|
24891
24891
|
}
|
|
24892
24892
|
type PathOptionSerie = PathOption[];
|
|
24893
24893
|
interface SwapTask {
|
|
24894
|
-
swapOperation:
|
|
24894
|
+
swapOperation: number;
|
|
24895
24895
|
creditAccount: Address;
|
|
24896
24896
|
tokenIn: Address;
|
|
24897
24897
|
tokenOut: Address;
|
|
@@ -24921,6 +24921,37 @@ interface Asset {
|
|
|
24921
24921
|
}
|
|
24922
24922
|
|
|
24923
24923
|
type abi = typeof routerV3Abi;
|
|
24924
|
+
interface FindAllSwapsProps {
|
|
24925
|
+
creditAccount: CreditAccountDataSlice;
|
|
24926
|
+
creditManager: CreditManagerSlice;
|
|
24927
|
+
swapOperation: SwapOperation;
|
|
24928
|
+
tokenIn: Address;
|
|
24929
|
+
tokenOut: Address;
|
|
24930
|
+
amount: bigint;
|
|
24931
|
+
leftoverAmount: bigint;
|
|
24932
|
+
slippage: number | bigint;
|
|
24933
|
+
}
|
|
24934
|
+
interface FindOneTokenPathProps {
|
|
24935
|
+
creditAccount: CreditAccountDataSlice;
|
|
24936
|
+
creditManager: CreditManagerSlice;
|
|
24937
|
+
tokenIn: Address;
|
|
24938
|
+
tokenOut: Address;
|
|
24939
|
+
amount: bigint;
|
|
24940
|
+
slippage: number | bigint;
|
|
24941
|
+
}
|
|
24942
|
+
interface FindOpenStrategyPathProps {
|
|
24943
|
+
creditManager: CreditManagerSlice;
|
|
24944
|
+
expectedBalances: Asset[];
|
|
24945
|
+
leftoverBalances: Asset[];
|
|
24946
|
+
target: Address;
|
|
24947
|
+
slippage: number | bigint;
|
|
24948
|
+
}
|
|
24949
|
+
interface FindBestClosePathProps {
|
|
24950
|
+
creditAccount: CreditAccountDataSlice;
|
|
24951
|
+
creditManager: CreditManagerSlice;
|
|
24952
|
+
slippage: bigint | number;
|
|
24953
|
+
balances?: ClosePathBalances;
|
|
24954
|
+
}
|
|
24924
24955
|
interface FindClosePathInput {
|
|
24925
24956
|
pathOptions: PathOptionSerie[];
|
|
24926
24957
|
expected: Asset[];
|
|
@@ -24964,21 +24995,21 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
|
|
|
24964
24995
|
* @param slippage
|
|
24965
24996
|
* @returns
|
|
24966
24997
|
*/
|
|
24967
|
-
findAllSwaps(
|
|
24998
|
+
findAllSwaps({ creditAccount: ca, creditManager: cm, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage, }: FindAllSwapsProps): Promise<RouterResult[]>;
|
|
24968
24999
|
/**
|
|
24969
25000
|
* Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
|
|
24970
|
-
* @param
|
|
24971
|
-
* @param
|
|
25001
|
+
* @param creditAccount
|
|
25002
|
+
* @param creditManager
|
|
24972
25003
|
* @param tokenIn
|
|
24973
25004
|
* @param tokenOut
|
|
24974
25005
|
* @param amount
|
|
24975
25006
|
* @param slippage
|
|
24976
25007
|
* @returns
|
|
24977
25008
|
*/
|
|
24978
|
-
findOneTokenPath(
|
|
25009
|
+
findOneTokenPath({ creditAccount: ca, creditManager: cm, tokenIn, tokenOut, amount, slippage, }: FindOneTokenPathProps): Promise<RouterResult>;
|
|
24979
25010
|
/**
|
|
24980
25011
|
* @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
|
|
24981
|
-
* @param
|
|
25012
|
+
* @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
|
|
24982
25013
|
* @param expectedBalances Expected balances which would be on account accounting also debt. For example,
|
|
24983
25014
|
* if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
|
|
24984
25015
|
* from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
|
|
@@ -24987,18 +25018,18 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
|
|
|
24987
25018
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
24988
25019
|
* @returns PathFinderOpenStrategyResult which
|
|
24989
25020
|
*/
|
|
24990
|
-
findOpenStrategyPath(
|
|
25021
|
+
findOpenStrategyPath({ creditManager: cm, expectedBalances, leftoverBalances, target, slippage, }: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
|
|
24991
25022
|
/**
|
|
24992
25023
|
* @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
|
|
24993
25024
|
* Can bu used for closing Credit Account and for liquidations as well.
|
|
24994
|
-
* @param
|
|
24995
|
-
* @param
|
|
25025
|
+
* @param creditAccount CreditAccountStruct object used for close path computation
|
|
25026
|
+
* @param creditManager CreditManagerSlice for corresponding credit manager
|
|
24996
25027
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
24997
25028
|
* @return The best option in PathFinderCloseResult format, which
|
|
24998
25029
|
* - underlyingBalance - total balance of underlying token
|
|
24999
25030
|
* - calls - list of calls which should be done to swap & unwrap everything to underlying token
|
|
25000
25031
|
*/
|
|
25001
|
-
findBestClosePath(
|
|
25032
|
+
findBestClosePath({ creditAccount: ca, creditManager: cm, slippage, balances, }: FindBestClosePathProps): Promise<RouterCloseResult>;
|
|
25002
25033
|
/**
|
|
25003
25034
|
* Finds input to be used with findBestClosePath
|
|
25004
25035
|
* @param ca
|
|
@@ -25192,24 +25223,21 @@ interface RepayCreditAccountResult {
|
|
|
25192
25223
|
calls: Array<MultiCall>;
|
|
25193
25224
|
}
|
|
25194
25225
|
type CloseOptions = "close" | "zeroDebt";
|
|
25195
|
-
interface CloseCreditAccountProps
|
|
25226
|
+
interface CloseCreditAccountProps {
|
|
25196
25227
|
operation: CloseOptions;
|
|
25197
|
-
|
|
25198
|
-
interface PrepareCloseCreditAccountProps {
|
|
25199
|
-
cm: CreditFactory;
|
|
25200
|
-
ca: CreditAccountDataSlice;
|
|
25228
|
+
creditAccount: CreditAccountDataSlice;
|
|
25201
25229
|
assetsToWithdraw: Address[];
|
|
25202
25230
|
to: Address;
|
|
25203
25231
|
slippage?: bigint;
|
|
25204
25232
|
closePath?: RouterCloseResult;
|
|
25205
25233
|
}
|
|
25206
|
-
interface RepayCreditAccountProps extends
|
|
25234
|
+
interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountProps {
|
|
25207
25235
|
operation: CloseOptions;
|
|
25208
25236
|
}
|
|
25209
|
-
interface
|
|
25237
|
+
interface RepayAndLiquidateCreditAccountProps {
|
|
25210
25238
|
collateralAssets: Asset[];
|
|
25211
25239
|
assetsToWithdraw: Address[];
|
|
25212
|
-
|
|
25240
|
+
creditAccount: CreditAccountDataSlice;
|
|
25213
25241
|
to: Address;
|
|
25214
25242
|
permits: Record<string, PermitResult>;
|
|
25215
25243
|
}
|
|
@@ -25258,24 +25286,36 @@ declare class CreditAccountsService extends SDKConstruct {
|
|
|
25258
25286
|
/**
|
|
25259
25287
|
* Closes credit account or sets debt to zero (but keep account)
|
|
25260
25288
|
* @param operation
|
|
25261
|
-
* @param
|
|
25289
|
+
* @param creditAccount
|
|
25262
25290
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
25263
25291
|
* @param to Address to withdraw underlying to
|
|
25264
25292
|
* @param slippage
|
|
25293
|
+
* @param closePath
|
|
25265
25294
|
* @returns
|
|
25266
25295
|
*/
|
|
25267
|
-
closeCreditAccount(
|
|
25296
|
+
closeCreditAccount({ operation, assetsToWithdraw, creditAccount: ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
|
|
25268
25297
|
/**
|
|
25269
25298
|
* Repays credit account or sets debt to zero (but keep account)
|
|
25270
25299
|
* @param operation
|
|
25271
|
-
* @param
|
|
25300
|
+
* @param creditAccount
|
|
25301
|
+
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
25302
|
+
* @param collateralAssets Tokens to pay for
|
|
25303
|
+
* @param to Address to withdraw underlying to
|
|
25304
|
+
* @param slippage
|
|
25305
|
+
* @param permits
|
|
25306
|
+
* @returns
|
|
25307
|
+
*/
|
|
25308
|
+
repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
|
|
25309
|
+
/**
|
|
25310
|
+
* Repays liquidatable credit account
|
|
25311
|
+
* @param creditAccount
|
|
25272
25312
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
25273
25313
|
* @param collateralAssets Tokens to pay for
|
|
25274
25314
|
* @param to Address to withdraw underlying to
|
|
25275
25315
|
* @param slippage
|
|
25276
25316
|
* @returns
|
|
25277
25317
|
*/
|
|
25278
|
-
|
|
25318
|
+
repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<RepayCreditAccountResult>;
|
|
25279
25319
|
/**
|
|
25280
25320
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
25281
25321
|
* @param accounts
|
package/dist/esm/sdk/index.d.mts
CHANGED
|
@@ -24891,7 +24891,7 @@ interface PathOption {
|
|
|
24891
24891
|
}
|
|
24892
24892
|
type PathOptionSerie = PathOption[];
|
|
24893
24893
|
interface SwapTask {
|
|
24894
|
-
swapOperation:
|
|
24894
|
+
swapOperation: number;
|
|
24895
24895
|
creditAccount: Address;
|
|
24896
24896
|
tokenIn: Address;
|
|
24897
24897
|
tokenOut: Address;
|
|
@@ -24921,6 +24921,37 @@ interface Asset {
|
|
|
24921
24921
|
}
|
|
24922
24922
|
|
|
24923
24923
|
type abi = typeof routerV3Abi;
|
|
24924
|
+
interface FindAllSwapsProps {
|
|
24925
|
+
creditAccount: CreditAccountDataSlice;
|
|
24926
|
+
creditManager: CreditManagerSlice;
|
|
24927
|
+
swapOperation: SwapOperation;
|
|
24928
|
+
tokenIn: Address;
|
|
24929
|
+
tokenOut: Address;
|
|
24930
|
+
amount: bigint;
|
|
24931
|
+
leftoverAmount: bigint;
|
|
24932
|
+
slippage: number | bigint;
|
|
24933
|
+
}
|
|
24934
|
+
interface FindOneTokenPathProps {
|
|
24935
|
+
creditAccount: CreditAccountDataSlice;
|
|
24936
|
+
creditManager: CreditManagerSlice;
|
|
24937
|
+
tokenIn: Address;
|
|
24938
|
+
tokenOut: Address;
|
|
24939
|
+
amount: bigint;
|
|
24940
|
+
slippage: number | bigint;
|
|
24941
|
+
}
|
|
24942
|
+
interface FindOpenStrategyPathProps {
|
|
24943
|
+
creditManager: CreditManagerSlice;
|
|
24944
|
+
expectedBalances: Asset[];
|
|
24945
|
+
leftoverBalances: Asset[];
|
|
24946
|
+
target: Address;
|
|
24947
|
+
slippage: number | bigint;
|
|
24948
|
+
}
|
|
24949
|
+
interface FindBestClosePathProps {
|
|
24950
|
+
creditAccount: CreditAccountDataSlice;
|
|
24951
|
+
creditManager: CreditManagerSlice;
|
|
24952
|
+
slippage: bigint | number;
|
|
24953
|
+
balances?: ClosePathBalances;
|
|
24954
|
+
}
|
|
24924
24955
|
interface FindClosePathInput {
|
|
24925
24956
|
pathOptions: PathOptionSerie[];
|
|
24926
24957
|
expected: Asset[];
|
|
@@ -24964,21 +24995,21 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
|
|
|
24964
24995
|
* @param slippage
|
|
24965
24996
|
* @returns
|
|
24966
24997
|
*/
|
|
24967
|
-
findAllSwaps(
|
|
24998
|
+
findAllSwaps({ creditAccount: ca, creditManager: cm, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage, }: FindAllSwapsProps): Promise<RouterResult[]>;
|
|
24968
24999
|
/**
|
|
24969
25000
|
* Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
|
|
24970
|
-
* @param
|
|
24971
|
-
* @param
|
|
25001
|
+
* @param creditAccount
|
|
25002
|
+
* @param creditManager
|
|
24972
25003
|
* @param tokenIn
|
|
24973
25004
|
* @param tokenOut
|
|
24974
25005
|
* @param amount
|
|
24975
25006
|
* @param slippage
|
|
24976
25007
|
* @returns
|
|
24977
25008
|
*/
|
|
24978
|
-
findOneTokenPath(
|
|
25009
|
+
findOneTokenPath({ creditAccount: ca, creditManager: cm, tokenIn, tokenOut, amount, slippage, }: FindOneTokenPathProps): Promise<RouterResult>;
|
|
24979
25010
|
/**
|
|
24980
25011
|
* @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
|
|
24981
|
-
* @param
|
|
25012
|
+
* @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
|
|
24982
25013
|
* @param expectedBalances Expected balances which would be on account accounting also debt. For example,
|
|
24983
25014
|
* if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
|
|
24984
25015
|
* from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
|
|
@@ -24987,18 +25018,18 @@ declare class RouterV3Contract extends BaseContract<abi> implements IHooks<Route
|
|
|
24987
25018
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
24988
25019
|
* @returns PathFinderOpenStrategyResult which
|
|
24989
25020
|
*/
|
|
24990
|
-
findOpenStrategyPath(
|
|
25021
|
+
findOpenStrategyPath({ creditManager: cm, expectedBalances, leftoverBalances, target, slippage, }: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
|
|
24991
25022
|
/**
|
|
24992
25023
|
* @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
|
|
24993
25024
|
* Can bu used for closing Credit Account and for liquidations as well.
|
|
24994
|
-
* @param
|
|
24995
|
-
* @param
|
|
25025
|
+
* @param creditAccount CreditAccountStruct object used for close path computation
|
|
25026
|
+
* @param creditManager CreditManagerSlice for corresponding credit manager
|
|
24996
25027
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
24997
25028
|
* @return The best option in PathFinderCloseResult format, which
|
|
24998
25029
|
* - underlyingBalance - total balance of underlying token
|
|
24999
25030
|
* - calls - list of calls which should be done to swap & unwrap everything to underlying token
|
|
25000
25031
|
*/
|
|
25001
|
-
findBestClosePath(
|
|
25032
|
+
findBestClosePath({ creditAccount: ca, creditManager: cm, slippage, balances, }: FindBestClosePathProps): Promise<RouterCloseResult>;
|
|
25002
25033
|
/**
|
|
25003
25034
|
* Finds input to be used with findBestClosePath
|
|
25004
25035
|
* @param ca
|
|
@@ -25192,24 +25223,21 @@ interface RepayCreditAccountResult {
|
|
|
25192
25223
|
calls: Array<MultiCall>;
|
|
25193
25224
|
}
|
|
25194
25225
|
type CloseOptions = "close" | "zeroDebt";
|
|
25195
|
-
interface CloseCreditAccountProps
|
|
25226
|
+
interface CloseCreditAccountProps {
|
|
25196
25227
|
operation: CloseOptions;
|
|
25197
|
-
|
|
25198
|
-
interface PrepareCloseCreditAccountProps {
|
|
25199
|
-
cm: CreditFactory;
|
|
25200
|
-
ca: CreditAccountDataSlice;
|
|
25228
|
+
creditAccount: CreditAccountDataSlice;
|
|
25201
25229
|
assetsToWithdraw: Address[];
|
|
25202
25230
|
to: Address;
|
|
25203
25231
|
slippage?: bigint;
|
|
25204
25232
|
closePath?: RouterCloseResult;
|
|
25205
25233
|
}
|
|
25206
|
-
interface RepayCreditAccountProps extends
|
|
25234
|
+
interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountProps {
|
|
25207
25235
|
operation: CloseOptions;
|
|
25208
25236
|
}
|
|
25209
|
-
interface
|
|
25237
|
+
interface RepayAndLiquidateCreditAccountProps {
|
|
25210
25238
|
collateralAssets: Asset[];
|
|
25211
25239
|
assetsToWithdraw: Address[];
|
|
25212
|
-
|
|
25240
|
+
creditAccount: CreditAccountDataSlice;
|
|
25213
25241
|
to: Address;
|
|
25214
25242
|
permits: Record<string, PermitResult>;
|
|
25215
25243
|
}
|
|
@@ -25258,24 +25286,36 @@ declare class CreditAccountsService extends SDKConstruct {
|
|
|
25258
25286
|
/**
|
|
25259
25287
|
* Closes credit account or sets debt to zero (but keep account)
|
|
25260
25288
|
* @param operation
|
|
25261
|
-
* @param
|
|
25289
|
+
* @param creditAccount
|
|
25262
25290
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
25263
25291
|
* @param to Address to withdraw underlying to
|
|
25264
25292
|
* @param slippage
|
|
25293
|
+
* @param closePath
|
|
25265
25294
|
* @returns
|
|
25266
25295
|
*/
|
|
25267
|
-
closeCreditAccount(
|
|
25296
|
+
closeCreditAccount({ operation, assetsToWithdraw, creditAccount: ca, to, slippage, closePath, }: CloseCreditAccountProps): Promise<CloseCreditAccountResult>;
|
|
25268
25297
|
/**
|
|
25269
25298
|
* Repays credit account or sets debt to zero (but keep account)
|
|
25270
25299
|
* @param operation
|
|
25271
|
-
* @param
|
|
25300
|
+
* @param creditAccount
|
|
25301
|
+
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
25302
|
+
* @param collateralAssets Tokens to pay for
|
|
25303
|
+
* @param to Address to withdraw underlying to
|
|
25304
|
+
* @param slippage
|
|
25305
|
+
* @param permits
|
|
25306
|
+
* @returns
|
|
25307
|
+
*/
|
|
25308
|
+
repayCreditAccount({ operation, collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayCreditAccountProps): Promise<RepayCreditAccountResult>;
|
|
25309
|
+
/**
|
|
25310
|
+
* Repays liquidatable credit account
|
|
25311
|
+
* @param creditAccount
|
|
25272
25312
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
25273
25313
|
* @param collateralAssets Tokens to pay for
|
|
25274
25314
|
* @param to Address to withdraw underlying to
|
|
25275
25315
|
* @param slippage
|
|
25276
25316
|
* @returns
|
|
25277
25317
|
*/
|
|
25278
|
-
|
|
25318
|
+
repayAndLiquidateCreditAccount({ collateralAssets, assetsToWithdraw, creditAccount: ca, permits, to, }: RepayAndLiquidateCreditAccountProps): Promise<RepayCreditAccountResult>;
|
|
25279
25319
|
/**
|
|
25280
25320
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
25281
25321
|
* @param accounts
|
package/dist/esm/sdk/index.mjs
CHANGED
|
@@ -22416,11 +22416,11 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
22416
22416
|
*/
|
|
22417
22417
|
async fullyLiquidate(account, to, slippage = 50n) {
|
|
22418
22418
|
const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
|
|
22419
|
-
const routerCloseResult = await this.sdk.router.findBestClosePath(
|
|
22420
|
-
account,
|
|
22421
|
-
cm.creditManager,
|
|
22419
|
+
const routerCloseResult = await this.sdk.router.findBestClosePath({
|
|
22420
|
+
creditAccount: account,
|
|
22421
|
+
creditManager: cm.creditManager,
|
|
22422
22422
|
slippage
|
|
22423
|
-
);
|
|
22423
|
+
});
|
|
22424
22424
|
const priceUpdates = await this.getPriceUpdatesForFacade(account);
|
|
22425
22425
|
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
22426
22426
|
account.creditAccount,
|
|
@@ -22432,39 +22432,104 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
22432
22432
|
/**
|
|
22433
22433
|
* Closes credit account or sets debt to zero (but keep account)
|
|
22434
22434
|
* @param operation
|
|
22435
|
-
* @param
|
|
22435
|
+
* @param creditAccount
|
|
22436
22436
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
22437
22437
|
* @param to Address to withdraw underlying to
|
|
22438
22438
|
* @param slippage
|
|
22439
|
+
* @param closePath
|
|
22439
22440
|
* @returns
|
|
22440
22441
|
*/
|
|
22441
|
-
async closeCreditAccount(
|
|
22442
|
-
|
|
22443
|
-
|
|
22444
|
-
|
|
22445
|
-
|
|
22446
|
-
|
|
22447
|
-
|
|
22442
|
+
async closeCreditAccount({
|
|
22443
|
+
operation,
|
|
22444
|
+
assetsToWithdraw,
|
|
22445
|
+
creditAccount: ca,
|
|
22446
|
+
to,
|
|
22447
|
+
slippage = 50n,
|
|
22448
|
+
closePath
|
|
22449
|
+
}) {
|
|
22450
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
22451
|
+
const routerCloseResult = closePath || await this.sdk.router.findBestClosePath({
|
|
22452
|
+
creditAccount: ca,
|
|
22453
|
+
creditManager: cm.creditManager,
|
|
22454
|
+
slippage
|
|
22448
22455
|
});
|
|
22449
|
-
const
|
|
22456
|
+
const calls = [
|
|
22457
|
+
...routerCloseResult.calls,
|
|
22458
|
+
...this.#prepareDisableQuotas(ca),
|
|
22459
|
+
...this.#prepareDecreaseDebt(ca),
|
|
22460
|
+
...this.#prepareDisableTokens(ca),
|
|
22461
|
+
...assetsToWithdraw.map(
|
|
22462
|
+
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22463
|
+
)
|
|
22464
|
+
];
|
|
22465
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
22450
22466
|
return { tx, calls, routerCloseResult };
|
|
22451
22467
|
}
|
|
22452
22468
|
/**
|
|
22453
22469
|
* Repays credit account or sets debt to zero (but keep account)
|
|
22454
22470
|
* @param operation
|
|
22455
|
-
* @param
|
|
22471
|
+
* @param creditAccount
|
|
22456
22472
|
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
22457
22473
|
* @param collateralAssets Tokens to pay for
|
|
22458
22474
|
* @param to Address to withdraw underlying to
|
|
22459
22475
|
* @param slippage
|
|
22476
|
+
* @param permits
|
|
22460
22477
|
* @returns
|
|
22461
22478
|
*/
|
|
22462
|
-
async repayCreditAccount(
|
|
22463
|
-
|
|
22464
|
-
|
|
22479
|
+
async repayCreditAccount({
|
|
22480
|
+
operation,
|
|
22481
|
+
collateralAssets,
|
|
22482
|
+
assetsToWithdraw,
|
|
22483
|
+
creditAccount: ca,
|
|
22484
|
+
permits,
|
|
22485
|
+
to
|
|
22486
|
+
}) {
|
|
22487
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
22488
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
22489
|
+
const calls = [
|
|
22490
|
+
...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
|
|
22491
|
+
...this.#prepareDisableQuotas(ca),
|
|
22492
|
+
...this.#prepareDecreaseDebt(ca),
|
|
22493
|
+
...this.#prepareDisableTokens(ca),
|
|
22494
|
+
// TODO: probably needs a way to handle reward tokens
|
|
22495
|
+
...assetsToWithdraw.map(
|
|
22496
|
+
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22497
|
+
)
|
|
22498
|
+
];
|
|
22499
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
22500
|
+
return { tx, calls };
|
|
22501
|
+
}
|
|
22502
|
+
/**
|
|
22503
|
+
* Repays liquidatable credit account
|
|
22504
|
+
* @param creditAccount
|
|
22505
|
+
* @param assetsToWithdraw Tokens to withdraw from credit account
|
|
22506
|
+
* @param collateralAssets Tokens to pay for
|
|
22507
|
+
* @param to Address to withdraw underlying to
|
|
22508
|
+
* @param slippage
|
|
22509
|
+
* @returns
|
|
22510
|
+
*/
|
|
22511
|
+
async repayAndLiquidateCreditAccount({
|
|
22512
|
+
collateralAssets,
|
|
22513
|
+
assetsToWithdraw,
|
|
22514
|
+
creditAccount: ca,
|
|
22515
|
+
permits,
|
|
22516
|
+
to
|
|
22517
|
+
}) {
|
|
22518
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
22519
|
+
const priceUpdates = await this.getPriceUpdatesForFacade(ca);
|
|
22520
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
22521
|
+
const calls = [
|
|
22522
|
+
...priceUpdates,
|
|
22523
|
+
...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
|
|
22524
|
+
...assetsToWithdraw.map(
|
|
22525
|
+
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22526
|
+
)
|
|
22527
|
+
];
|
|
22528
|
+
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
22529
|
+
ca.creditAccount,
|
|
22530
|
+
to,
|
|
22531
|
+
calls
|
|
22465
22532
|
);
|
|
22466
|
-
const { calls } = await this.#prepareRepayCreditAccount(props);
|
|
22467
|
-
const tx = props.operation === "close" ? cm.creditFacade.closeCreditAccount(props.ca.creditAccount, calls) : cm.creditFacade.multicall(props.ca.creditAccount, calls);
|
|
22468
22533
|
return { tx, calls };
|
|
22469
22534
|
}
|
|
22470
22535
|
/**
|
|
@@ -22555,45 +22620,6 @@ var CreditAccountsService = class extends SDKConstruct {
|
|
|
22555
22620
|
const updates = await this.getOnDemandPriceUpdates(acc);
|
|
22556
22621
|
return cm.creditFacade.encodeOnDemandPriceUpdates(updates);
|
|
22557
22622
|
}
|
|
22558
|
-
async #prepareCloseCreditAccount({
|
|
22559
|
-
ca,
|
|
22560
|
-
cm,
|
|
22561
|
-
assetsToWithdraw,
|
|
22562
|
-
to,
|
|
22563
|
-
slippage = 50n,
|
|
22564
|
-
closePath
|
|
22565
|
-
}) {
|
|
22566
|
-
const routerCloseResult = closePath || await this.sdk.router.findBestClosePath(ca, cm.creditManager, slippage);
|
|
22567
|
-
const calls = [
|
|
22568
|
-
...routerCloseResult.calls,
|
|
22569
|
-
...this.#prepareDisableQuotas(ca),
|
|
22570
|
-
...this.#prepareDecreaseDebt(ca),
|
|
22571
|
-
...this.#prepareDisableTokens(ca),
|
|
22572
|
-
...assetsToWithdraw.map(
|
|
22573
|
-
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22574
|
-
)
|
|
22575
|
-
];
|
|
22576
|
-
return { calls, routerCloseResult };
|
|
22577
|
-
}
|
|
22578
|
-
async #prepareRepayCreditAccount({
|
|
22579
|
-
ca,
|
|
22580
|
-
assetsToWithdraw,
|
|
22581
|
-
to,
|
|
22582
|
-
collateralAssets,
|
|
22583
|
-
permits
|
|
22584
|
-
}) {
|
|
22585
|
-
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
22586
|
-
const calls = [
|
|
22587
|
-
...this.#prepareAddCollateralCalls(addCollateral, ca, permits),
|
|
22588
|
-
...this.#prepareDisableQuotas(ca),
|
|
22589
|
-
...this.#prepareDecreaseDebt(ca),
|
|
22590
|
-
...this.#prepareDisableTokens(ca),
|
|
22591
|
-
...assetsToWithdraw.map(
|
|
22592
|
-
(t) => this.#prepareWithdrawToken(ca, t, MAX_UINT256, to)
|
|
22593
|
-
)
|
|
22594
|
-
];
|
|
22595
|
-
return { calls };
|
|
22596
|
-
}
|
|
22597
22623
|
#prepareDisableQuotas(ca) {
|
|
22598
22624
|
const calls = [];
|
|
22599
22625
|
for (const { token, quota } of ca.tokens) {
|
|
@@ -22999,7 +23025,16 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
22999
23025
|
* @param slippage
|
|
23000
23026
|
* @returns
|
|
23001
23027
|
*/
|
|
23002
|
-
async findAllSwaps(
|
|
23028
|
+
async findAllSwaps({
|
|
23029
|
+
creditAccount: ca,
|
|
23030
|
+
creditManager: cm,
|
|
23031
|
+
swapOperation,
|
|
23032
|
+
tokenIn,
|
|
23033
|
+
tokenOut,
|
|
23034
|
+
amount,
|
|
23035
|
+
leftoverAmount,
|
|
23036
|
+
slippage
|
|
23037
|
+
}) {
|
|
23003
23038
|
const connectors = this.getAvailableConnectors(cm.collateralTokens);
|
|
23004
23039
|
const swapTask = {
|
|
23005
23040
|
swapOperation: SWAP_OPERATIONS[swapOperation],
|
|
@@ -23029,15 +23064,22 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23029
23064
|
}
|
|
23030
23065
|
/**
|
|
23031
23066
|
* Finds best path to swap all Normal tokens and tokens "on the way" to target one and vice versa
|
|
23032
|
-
* @param
|
|
23033
|
-
* @param
|
|
23067
|
+
* @param creditAccount
|
|
23068
|
+
* @param creditManager
|
|
23034
23069
|
* @param tokenIn
|
|
23035
23070
|
* @param tokenOut
|
|
23036
23071
|
* @param amount
|
|
23037
23072
|
* @param slippage
|
|
23038
23073
|
* @returns
|
|
23039
23074
|
*/
|
|
23040
|
-
async findOneTokenPath(
|
|
23075
|
+
async findOneTokenPath({
|
|
23076
|
+
creditAccount: ca,
|
|
23077
|
+
creditManager: cm,
|
|
23078
|
+
tokenIn,
|
|
23079
|
+
tokenOut,
|
|
23080
|
+
amount,
|
|
23081
|
+
slippage
|
|
23082
|
+
}) {
|
|
23041
23083
|
const connectors = this.getAvailableConnectors(cm.collateralTokens);
|
|
23042
23084
|
const { result } = await this.contract.simulate.findOneTokenPath(
|
|
23043
23085
|
[
|
|
@@ -23060,7 +23102,7 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23060
23102
|
}
|
|
23061
23103
|
/**
|
|
23062
23104
|
* @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
|
|
23063
|
-
* @param
|
|
23105
|
+
* @param creditManager CreditManagerData which represents credit manager you want to use to open Credit Account
|
|
23064
23106
|
* @param expectedBalances Expected balances which would be on account accounting also debt. For example,
|
|
23065
23107
|
* if you open an USDC Credit Account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
|
|
23066
23108
|
* from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
|
|
@@ -23069,7 +23111,13 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23069
23111
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
23070
23112
|
* @returns PathFinderOpenStrategyResult which
|
|
23071
23113
|
*/
|
|
23072
|
-
async findOpenStrategyPath(
|
|
23114
|
+
async findOpenStrategyPath({
|
|
23115
|
+
creditManager: cm,
|
|
23116
|
+
expectedBalances,
|
|
23117
|
+
leftoverBalances,
|
|
23118
|
+
target,
|
|
23119
|
+
slippage
|
|
23120
|
+
}) {
|
|
23073
23121
|
const [expectedMap, leftoverMap] = [
|
|
23074
23122
|
balancesMap(expectedBalances),
|
|
23075
23123
|
balancesMap(leftoverBalances)
|
|
@@ -23111,14 +23159,19 @@ var RouterV3Contract = class extends BaseContract {
|
|
|
23111
23159
|
/**
|
|
23112
23160
|
* @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
|
|
23113
23161
|
* Can bu used for closing Credit Account and for liquidations as well.
|
|
23114
|
-
* @param
|
|
23115
|
-
* @param
|
|
23162
|
+
* @param creditAccount CreditAccountStruct object used for close path computation
|
|
23163
|
+
* @param creditManager CreditManagerSlice for corresponding credit manager
|
|
23116
23164
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
23117
23165
|
* @return The best option in PathFinderCloseResult format, which
|
|
23118
23166
|
* - underlyingBalance - total balance of underlying token
|
|
23119
23167
|
* - calls - list of calls which should be done to swap & unwrap everything to underlying token
|
|
23120
23168
|
*/
|
|
23121
|
-
async findBestClosePath(
|
|
23169
|
+
async findBestClosePath({
|
|
23170
|
+
creditAccount: ca,
|
|
23171
|
+
creditManager: cm,
|
|
23172
|
+
slippage,
|
|
23173
|
+
balances
|
|
23174
|
+
}) {
|
|
23122
23175
|
const { pathOptions, expected, leftover, connectors } = this.getFindClosePathInput(
|
|
23123
23176
|
ca,
|
|
23124
23177
|
cm,
|