@gearbox-protocol/sdk 16.4.0-next.5 → 16.4.0-next.7
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/onchain/accounts/intents/borrow.js +139 -0
- package/dist/cjs/onchain/accounts/intents/{collateral-money.js → collateral-valuation.js} +7 -7
- package/dist/cjs/onchain/accounts/intents/index.js +82 -1
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +2 -12
- package/dist/cjs/onchain/accounts/intents/maxBorrow.js +89 -0
- package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +14 -14
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +6 -45
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/cjs/onchain/accounts/intents/utils/common.js +19 -0
- package/dist/cjs/onchain/accounts/intents/utils/credit-account-slice.js +21 -0
- package/dist/cjs/onchain/accounts/intents/utils/index.js +2 -0
- package/dist/cjs/onchain/accounts/intents/withdraw-limits.js +8 -8
- package/dist/cjs/onchain/positions/calcHealthFactor.js +3 -3
- package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +2 -1
- package/dist/cjs/sdk/execute/ExecuteApi.js +65 -5
- package/dist/cjs/sdk/prepare/PrepareApi.js +86 -12
- package/dist/esm/onchain/accounts/intents/borrow.js +137 -0
- package/dist/esm/onchain/accounts/intents/{collateral-money.js → collateral-valuation.js} +7 -7
- package/dist/esm/onchain/accounts/intents/index.js +82 -1
- package/dist/esm/onchain/accounts/intents/leverage-band.js +2 -12
- package/dist/esm/onchain/accounts/intents/maxBorrow.js +87 -0
- package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +14 -14
- package/dist/esm/onchain/accounts/intents/open-strategy.js +6 -45
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/esm/onchain/accounts/intents/utils/common.js +19 -1
- package/dist/esm/onchain/accounts/intents/utils/credit-account-slice.js +21 -1
- package/dist/esm/onchain/accounts/intents/utils/index.js +3 -3
- package/dist/esm/onchain/accounts/intents/withdraw-limits.js +8 -8
- package/dist/esm/onchain/positions/calcHealthFactor.js +3 -3
- package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +2 -1
- package/dist/esm/sdk/execute/ExecuteApi.js +65 -5
- package/dist/esm/sdk/prepare/PrepareApi.js +86 -12
- package/dist/types/model/previews.d.ts +11 -2
- package/dist/types/onchain/accounts/index.d.ts +4 -3
- package/dist/types/onchain/accounts/intents/borrow.d.ts +141 -0
- package/dist/types/onchain/accounts/intents/{collateral-money.d.ts → collateral-valuation.d.ts} +8 -8
- package/dist/types/onchain/accounts/intents/index.d.ts +81 -2
- package/dist/types/onchain/accounts/intents/maxBorrow.d.ts +54 -0
- package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -17
- package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +2 -0
- package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/types.d.ts +6 -1
- package/dist/types/onchain/accounts/intents/utils/common.d.ts +15 -1
- package/dist/types/onchain/accounts/intents/utils/credit-account-slice.d.ts +14 -1
- package/dist/types/onchain/accounts/intents/utils/index.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/withdraw-limits.d.ts +1 -1
- package/dist/types/onchain/index.d.ts +4 -3
- package/dist/types/sdk/execute/index.d.ts +2 -2
- package/dist/types/sdk/execute/types.d.ts +48 -6
- package/dist/types/sdk/index.d.ts +5 -4
- package/dist/types/sdk/prepare/PrepareApi.d.ts +15 -3
- package/dist/types/sdk/prepare/index.d.ts +4 -3
- package/dist/types/sdk/prepare/types.d.ts +176 -49
- package/package.json +1 -1
|
@@ -19,17 +19,18 @@ import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
|
19
19
|
import { PeripheryCompressorV310Contract } from "./bots/PeripheryCompressorV310Contract.js";
|
|
20
20
|
import "./bots/index.js";
|
|
21
21
|
import { CreditAccountsServiceV310 } from "./CreditAccountsServiceV310.js";
|
|
22
|
-
import { LeverageBand } from "./intents/leverage-band.js";
|
|
23
22
|
import { CalcDefaultQuotaProps, CalcQuotaUpdateProps, CalcRecommendedQuotaProps, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, roundUpQuota } from "./quota-utils.js";
|
|
24
23
|
import { AccountCalculatorOperation } from "./intents/operations.js";
|
|
25
24
|
import { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteErrors, StartIntent, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent } from "./intents/types.js";
|
|
25
|
+
import { BorrowProps, BorrowState } from "./intents/borrow.js";
|
|
26
|
+
import { LeverageBand } from "./intents/leverage-band.js";
|
|
26
27
|
import { OpenStrategyProps, OpenStrategyState } from "./intents/open-strategy.js";
|
|
27
28
|
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./intents/utils/credit-account-slice.js";
|
|
28
29
|
import { isPhantomToken } from "./intents/utils/pick-token.js";
|
|
29
|
-
import { CreditAccountOperationsService, OpenStrategyPreviewResult } from "./intents/index.js";
|
|
30
|
+
import { BorrowPreviewResult, CreditAccountOperationsService, EmptyAccountPreviewResult, OpenStrategyPreviewResult } from "./intents/index.js";
|
|
30
31
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./liquidations/constants.js";
|
|
31
32
|
import { BuildLiquidationTxProps, BuildLiquidationTxPropsBase, GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidationDetailsPropsBase, GetLiquidationPositionsProps, GetLiquidationPositionsPropsBase, LoadRWALiquidatorsProps, OnchainLiquidationCall, OnchainLiquidationData, OnchainLiquidationOutput, RWALiquidatorInfo } from "./liquidations/types.js";
|
|
32
33
|
import { LiquidationsService } from "./liquidations/LiquidationsService.js";
|
|
33
34
|
import { MultichainLiquidationsService } from "./liquidations/MultichainLiquidationsService.js";
|
|
34
35
|
import "./liquidations/index.js";
|
|
35
|
-
export { AbstractWithdrawalCompressorContract, AccountBotsService, type AccountCalculatorOperation, AccountToCheck, type AddCollateralIntent, type AdjustLeverageIntent, AssembleCaOperationsProps, AssembleClaimDelayedCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, AssembleStartDelayedWithdrawalCallsProps, BotStatusCall, BotsDirectResponse, BuildLiquidationTxProps, BuildLiquidationTxPropsBase, CMSlice, CalcDefaultQuotaProps, CalcQuotaUpdateProps, CalcRecommendedQuotaProps, ClaimFarmRewardsProps, type ClaimRemainder, ClaimableWithdrawal, CloseCreditAccountResult, ConnectedBotsCall, ConnectedBotsPerAccount, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountDataCall, CreditAccountFilter, CreditAccountOperationResult, CreditAccountOperationsService, CreditAccountReadOptions, type CreditAccountSlice, CreditAccountsCall, CreditAccountsQuery, CreditAccountsReadOptions, CreditAccountsServiceV310, CreditAccountsTarget, CreditManagerFilter, CreditManagerOperationResult, CurrentWithdrawals, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, type DelayableIntent, DelayedIntentExtended, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EncodableCreditAccountOperation, type FinishIntentProps, type FinishIntentResult, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResponse, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsArgs, GetCreditAccountsOptions, GetExternalAccountCurrentWithdrawalsProps, GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidationDetailsPropsBase, GetLiquidationPositionsProps, GetLiquidationPositionsPropsBase, GetWithdrawalRequestResultProps, ICreditAccountsService, IRedemptionLoggerContract, IWithdrawalCompressorContract, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, type LeverageBand, LiquidationsService, LoadRWALiquidatorsProps, MulticallWithFailure, MultichainLiquidationsService, OnchainLiquidationCall, OnchainLiquidationData, OnchainLiquidationOutput, OnchainRequestableWithdrawal, OpenCAProps, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, PartiallyLiquidateProps, type PathLossRate, PendingWithdrawal, PeripheryCompressorV310Contract, PreviewDelayedWithdrawalProps, RWALiquidatorInfo, RedemptionLog, RedemptionLoggerV310Contract, type RepayStrategyIntent, RequestableWithdrawal, type ResumableIntent, Rewards, type RouteErrors, SetBotProps, SetBotResult, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, WithdrawableAsset, WithdrawalCompressorLocation, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WithdrawalCompressorVersion, WithdrawalOutput, WithdrawalStatus, WithdrawalsState, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, isPhantomToken, roundUpQuota, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|
|
36
|
+
export { AbstractWithdrawalCompressorContract, AccountBotsService, type AccountCalculatorOperation, AccountToCheck, type AddCollateralIntent, type AdjustLeverageIntent, AssembleCaOperationsProps, AssembleClaimDelayedCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, AssembleStartDelayedWithdrawalCallsProps, BorrowPreviewResult, type BorrowProps, type BorrowState, BotStatusCall, BotsDirectResponse, BuildLiquidationTxProps, BuildLiquidationTxPropsBase, CMSlice, CalcDefaultQuotaProps, CalcQuotaUpdateProps, CalcRecommendedQuotaProps, ClaimFarmRewardsProps, type ClaimRemainder, ClaimableWithdrawal, CloseCreditAccountResult, ConnectedBotsCall, ConnectedBotsPerAccount, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountDataCall, CreditAccountFilter, CreditAccountOperationResult, CreditAccountOperationsService, CreditAccountReadOptions, type CreditAccountSlice, CreditAccountsCall, CreditAccountsQuery, CreditAccountsReadOptions, CreditAccountsServiceV310, CreditAccountsTarget, CreditManagerFilter, CreditManagerOperationResult, CurrentWithdrawals, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, type DelayableIntent, DelayedIntentExtended, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EmptyAccountPreviewResult, EncodableCreditAccountOperation, type FinishIntentProps, type FinishIntentResult, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResponse, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsArgs, GetCreditAccountsOptions, GetExternalAccountCurrentWithdrawalsProps, GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidationDetailsPropsBase, GetLiquidationPositionsProps, GetLiquidationPositionsPropsBase, GetWithdrawalRequestResultProps, ICreditAccountsService, IRedemptionLoggerContract, IWithdrawalCompressorContract, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, type LeverageBand, LiquidationsService, LoadRWALiquidatorsProps, MulticallWithFailure, MultichainLiquidationsService, OnchainLiquidationCall, OnchainLiquidationData, OnchainLiquidationOutput, OnchainRequestableWithdrawal, OpenCAProps, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, PartiallyLiquidateProps, type PathLossRate, PendingWithdrawal, PeripheryCompressorV310Contract, PreviewDelayedWithdrawalProps, RWALiquidatorInfo, RedemptionLog, RedemptionLoggerV310Contract, type RepayStrategyIntent, RequestableWithdrawal, type ResumableIntent, Rewards, type RouteErrors, SetBotProps, SetBotResult, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, WithdrawableAsset, WithdrawalCompressorLocation, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WithdrawalCompressorVersion, WithdrawalOutput, WithdrawalStatus, WithdrawalsState, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, isPhantomToken, roundUpQuota, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { TokenAmount } from "../../../model/primitives.js";
|
|
2
|
+
import "../../../model/index.js";
|
|
3
|
+
import { Asset } from "../../base/types.js";
|
|
4
|
+
import { MultiCall } from "../../types/transactions.js";
|
|
5
|
+
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
6
|
+
import { CreditAccountSlice, OperationState } from "./types.js";
|
|
7
|
+
import "../../index.js";
|
|
8
|
+
import { Address } from "viem";
|
|
9
|
+
//#region src/onchain/accounts/intents/borrow.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Taking a loan against collateral, in one transaction that opens the account.
|
|
12
|
+
*
|
|
13
|
+
* The plainest thing a credit account can do, and the one shape of it the
|
|
14
|
+
* leveraged flows cannot express: the borrowed funds do not stay on the
|
|
15
|
+
* account to be traded, they go to the wallet. What is left behind is the
|
|
16
|
+
* collateral and the debt it backs.
|
|
17
|
+
*/
|
|
18
|
+
interface BorrowProps {
|
|
19
|
+
sdk: OnchainSDK;
|
|
20
|
+
/** Credit manager to open the account in. */
|
|
21
|
+
creditManager: Address;
|
|
22
|
+
/** Token the wallet puts up, in the manager's collateral list. */
|
|
23
|
+
collateralToken: Address;
|
|
24
|
+
/** Amount of {@link collateralToken}, in its own units. */
|
|
25
|
+
collateralAmount: bigint;
|
|
26
|
+
/**
|
|
27
|
+
* Token the loan is paid out in. The market underlying needs no trade;
|
|
28
|
+
* anything else is bought with the borrowed underlying on the way out.
|
|
29
|
+
*
|
|
30
|
+
* On an RWA market the underlying is a compliance wrapper that cannot leave
|
|
31
|
+
* the account, so the payout there is the asset behind it — USDC rather than
|
|
32
|
+
* dcUSDC — and the wrapper itself is refused.
|
|
33
|
+
*/
|
|
34
|
+
borrowToken: Address;
|
|
35
|
+
/** Amount of {@link borrowToken} the wallet asks for, in its own units. */
|
|
36
|
+
borrowAmount: bigint;
|
|
37
|
+
/** Router slippage in PERCENTAGE_FORMAT (100% = 10_000). */
|
|
38
|
+
slippage: number | undefined;
|
|
39
|
+
/** Extra quota headroom in PERCENTAGE_FORMAT. */
|
|
40
|
+
quotaReserve: number | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Existing credit account to draw the loan on, instead of opening one.
|
|
43
|
+
*
|
|
44
|
+
* Must carry no debt and no quotas, as a reused opening must. Borrowing on
|
|
45
|
+
* an account that already owes is what the `ADJUST_LEVERAGE` intent is for.
|
|
46
|
+
**/
|
|
47
|
+
creditAccount?: CreditAccountSlice;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Where a borrow leaves the wallet and the account it opens.
|
|
51
|
+
*
|
|
52
|
+
* A whole {@link OperationState}, holdings included: unlike an opening, a
|
|
53
|
+
* borrow has no second branch of balances to choose between — the collateral
|
|
54
|
+
* is the only thing left on the account and its amount is known exactly.
|
|
55
|
+
* Slippage lands on the payout instead, which is why that one is reported
|
|
56
|
+
* twice.
|
|
57
|
+
*
|
|
58
|
+
* Being that state rather than merely resembling it is what lets a borrow
|
|
59
|
+
* result go straight to `checkSimulation`, which weighs whatever the engine
|
|
60
|
+
* projected: the market, the debt, the quotas and the two factors, all of
|
|
61
|
+
* which a borrow reports where an operation on an existing account does.
|
|
62
|
+
*/
|
|
63
|
+
interface BorrowState extends OperationState {
|
|
64
|
+
/** What the wallet puts up, as it will sit on the account. */
|
|
65
|
+
collateral: TokenAmount;
|
|
66
|
+
/**
|
|
67
|
+
* What the wallet is expected to receive, in the token it asked for. Equal
|
|
68
|
+
* to the debt when that token is the market underlying, and to the debt
|
|
69
|
+
* rescaled where an RWA payout unwraps it one for one; in neither case is
|
|
70
|
+
* anything traded.
|
|
71
|
+
*/
|
|
72
|
+
borrowed: TokenAmount;
|
|
73
|
+
/**
|
|
74
|
+
* The floor under {@link borrowed} once slippage is allowed for — what the
|
|
75
|
+
* transaction is signed against. Equal to `borrowed` when nothing is traded.
|
|
76
|
+
*/
|
|
77
|
+
minBorrowed: TokenAmount;
|
|
78
|
+
/**
|
|
79
|
+
* Router slippage the payout leg was quoted at, in PERCENTAGE_FORMAT
|
|
80
|
+
* (100% = 10_000). The SDK's own default where the caller named none.
|
|
81
|
+
*/
|
|
82
|
+
slippage: number;
|
|
83
|
+
/**
|
|
84
|
+
* Quota to buy for the collateral; feeds `openCA.averageQuota` and
|
|
85
|
+
* `openCA.minQuota` alike, both branches being the same here.
|
|
86
|
+
*
|
|
87
|
+
* Transport for the transaction rather than something to display, like
|
|
88
|
+
* {@link calls} below.
|
|
89
|
+
*/
|
|
90
|
+
quotaIncrease: Asset[];
|
|
91
|
+
/**
|
|
92
|
+
* The leg that turns the borrowed underlying into the payout: a router path
|
|
93
|
+
* where it is bought, the vault redemption where an RWA market unwraps it,
|
|
94
|
+
* empty where the payout is the underlying itself. Feeds `openCA.calls`,
|
|
95
|
+
* which places it before the withdrawal.
|
|
96
|
+
*/
|
|
97
|
+
calls: MultiCall[];
|
|
98
|
+
/**
|
|
99
|
+
* The account this loan was simulated against and must be executed on, when
|
|
100
|
+
* it reuses one; `undefined` for a borrow that opens its own.
|
|
101
|
+
*
|
|
102
|
+
* Carried here rather than asked of the caller again at `buildTx`, so the
|
|
103
|
+
* transaction cannot be built against an account the numbers were not
|
|
104
|
+
* computed for.
|
|
105
|
+
**/
|
|
106
|
+
creditAccount?: Address;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Builds the state a borrow would leave behind.
|
|
110
|
+
*
|
|
111
|
+
* The debt is named rather than derived: a borrow asks for an amount, where an
|
|
112
|
+
* opening asks for a leverage and lets the collateral decide. Everything the
|
|
113
|
+
* loan pays out leaves the account, so the collateral alone backs it — which
|
|
114
|
+
* is what makes the health factor here a straight function of the two amounts.
|
|
115
|
+
*
|
|
116
|
+
* Produces no operation list, as opening never does: the caller hands the
|
|
117
|
+
* numbers and the calls to `sdk.accounts.openCA`, with `withdrawToken` set to
|
|
118
|
+
* the payout.
|
|
119
|
+
*/
|
|
120
|
+
declare function buildBorrowState(props: BorrowProps): Promise<BorrowState>;
|
|
121
|
+
/** Inputs of {@link borrowCollateralQuota}. */
|
|
122
|
+
interface BorrowCollateralQuotaProps {
|
|
123
|
+
sdk: OnchainSDK;
|
|
124
|
+
creditManager: Address;
|
|
125
|
+
/** Collateral the fresh account will hold. */
|
|
126
|
+
assets: Asset[];
|
|
127
|
+
/** Extra quota headroom in PERCENTAGE_FORMAT. */
|
|
128
|
+
quotaReserve: number | undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Quota a borrow buys for its collateral on an account that holds none yet.
|
|
132
|
+
*
|
|
133
|
+
* Shared with `maxBorrow`, because a quota short of the collateral's weighted
|
|
134
|
+
* value is what caps the loan: the two have to read the same number or the
|
|
135
|
+
* ceiling one offers is one the other refuses.
|
|
136
|
+
*
|
|
137
|
+
* @param props - {@link BorrowCollateralQuotaProps}
|
|
138
|
+
**/
|
|
139
|
+
declare function borrowCollateralQuota({ sdk, creditManager, assets, quotaReserve }: BorrowCollateralQuotaProps): Asset[];
|
|
140
|
+
//#endregion
|
|
141
|
+
export { BorrowCollateralQuotaProps, BorrowProps, BorrowState, borrowCollateralQuota, buildBorrowState };
|
package/dist/types/onchain/accounts/intents/{collateral-money.d.ts → collateral-valuation.d.ts}
RENAMED
|
@@ -2,7 +2,7 @@ import { OnchainSDK } from "../../OnchainSDK.js";
|
|
|
2
2
|
import { CreditAccountSlice } from "./types.js";
|
|
3
3
|
import "../../index.js";
|
|
4
4
|
import { Address } from "viem";
|
|
5
|
-
//#region src/onchain/accounts/intents/collateral-
|
|
5
|
+
//#region src/onchain/accounts/intents/collateral-valuation.d.ts
|
|
6
6
|
/** One balance on the account, as the slice carries it. */
|
|
7
7
|
type Holding = CreditAccountSlice["tokens"][number];
|
|
8
8
|
/**
|
|
@@ -17,10 +17,10 @@ type Holding = CreditAccountSlice["tokens"][number];
|
|
|
17
17
|
* exempt and stays on the main feed, as `CreditManagerV3._safeConvertToUSD`
|
|
18
18
|
* does.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
* in, so a threshold never has to be divided back out.
|
|
20
|
+
* Every figure is carried in USD × `PERCENTAGE_FACTOR`, the units the check
|
|
21
|
+
* compares in, so a threshold never has to be divided back out.
|
|
22
22
|
*/
|
|
23
|
-
interface
|
|
23
|
+
interface CollateralValuation {
|
|
24
24
|
/** Market underlying, the one token safe pricing does not touch. */
|
|
25
25
|
underlying: Address;
|
|
26
26
|
/** Whether the holding is weighed at all. */
|
|
@@ -28,7 +28,7 @@ interface CollateralMoney {
|
|
|
28
28
|
/** What the holding backs, in USD × `PERCENTAGE_FACTOR`. */
|
|
29
29
|
weigh(holding: Holding): bigint;
|
|
30
30
|
/** What the holding's quota backs, in the same units; 0 on a closed market. */
|
|
31
|
-
|
|
31
|
+
quotaValue(holding: Holding): bigint;
|
|
32
32
|
/** USD at the main feed; `undefined` when the token has no price at all. */
|
|
33
33
|
mainUsd(token: Address, amount: bigint): bigint | undefined;
|
|
34
34
|
/** USD the check counts the holding at, before its threshold. */
|
|
@@ -36,7 +36,7 @@ interface CollateralMoney {
|
|
|
36
36
|
/** Liquidation threshold in basis points; 0 for a token the manager refuses. */
|
|
37
37
|
lt(token: Address): bigint;
|
|
38
38
|
}
|
|
39
|
-
/** {@inheritDoc
|
|
40
|
-
declare function
|
|
39
|
+
/** {@inheritDoc CollateralValuation} */
|
|
40
|
+
declare function collateralValuation(creditAccount: CreditAccountSlice, sdk: OnchainSDK): CollateralValuation;
|
|
41
41
|
//#endregion
|
|
42
|
-
export {
|
|
42
|
+
export { CollateralValuation, Holding, collateralValuation };
|
|
@@ -2,9 +2,11 @@ import { SDKError } from "../../../model/result.js";
|
|
|
2
2
|
import "../../../model/index.js";
|
|
3
3
|
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
4
4
|
import { IntentValidationError } from "../../validation/raise.js";
|
|
5
|
-
import { LeverageBand, LeverageBandProps } from "./leverage-band.js";
|
|
6
5
|
import { AccountCalculatorOperation } from "./operations.js";
|
|
7
6
|
import { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteErrors, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent } from "./types.js";
|
|
7
|
+
import { BorrowProps, BorrowState } from "./borrow.js";
|
|
8
|
+
import { LeverageBand, LeverageBandProps } from "./leverage-band.js";
|
|
9
|
+
import { MaxBorrowProps } from "./maxBorrow.js";
|
|
8
10
|
import { OpenStrategyProps, OpenStrategyState } from "./open-strategy.js";
|
|
9
11
|
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./utils/credit-account-slice.js";
|
|
10
12
|
import { isPhantomToken } from "./utils/pick-token.js";
|
|
@@ -21,6 +23,22 @@ type OpenStrategyPreviewResult = {
|
|
|
21
23
|
ok: true;
|
|
22
24
|
state: OpenStrategyState;
|
|
23
25
|
} | SDKError<IntentValidationError>;
|
|
26
|
+
/**
|
|
27
|
+
* Borrow preview outcome, shaped like {@link OpenStrategyPreviewResult}: both
|
|
28
|
+
* open an account, so neither has an operation chain to report.
|
|
29
|
+
*/
|
|
30
|
+
type BorrowPreviewResult = {
|
|
31
|
+
ok: true;
|
|
32
|
+
state: BorrowState;
|
|
33
|
+
} | SDKError<IntentValidationError>;
|
|
34
|
+
/**
|
|
35
|
+
* Empty-account preview outcome: the thinnest of the three, since an account
|
|
36
|
+
* that holds nothing has no state to project — only the market's own refusal
|
|
37
|
+
* to open one at all.
|
|
38
|
+
*/
|
|
39
|
+
type EmptyAccountPreviewResult = {
|
|
40
|
+
ok: true;
|
|
41
|
+
} | SDKError<IntentValidationError>;
|
|
24
42
|
/** An intent plus everything previewing it needs. */
|
|
25
43
|
type StartProps = StartIntentProps & {
|
|
26
44
|
intent: StartIntent;
|
|
@@ -119,6 +137,30 @@ declare class CreditAccountOperationsService extends SDKConstruct {
|
|
|
119
137
|
token: Address;
|
|
120
138
|
targetHF?: bigint;
|
|
121
139
|
}): bigint;
|
|
140
|
+
/**
|
|
141
|
+
* Largest loan a given collateral supports at `targetHF`, in the payout
|
|
142
|
+
* token's units — the ceiling a borrow form should offer.
|
|
143
|
+
*
|
|
144
|
+
* Reads no account, like {@link leverageBand}: the borrow opens one. The
|
|
145
|
+
* collateral is valued the way the transaction will be judged, at safe
|
|
146
|
+
* prices and under the quota the borrow buys, and the answer is then held to
|
|
147
|
+
* what the market will lend.
|
|
148
|
+
*
|
|
149
|
+
* A ceiling, not a verdict: the facade's `minDebt` is a floor and is not
|
|
150
|
+
* applied here, so collateral too small for this market still answers with
|
|
151
|
+
* what it carries and {@link borrowIntent} is the one that refuses the loan.
|
|
152
|
+
*
|
|
153
|
+
* The default is {@link MIN_HF_LIMITED}, the threshold a form holds an
|
|
154
|
+
* account to.
|
|
155
|
+
*
|
|
156
|
+
* @param props - The manager, the SDK holding its market, the collateral put
|
|
157
|
+
* up, the token to be paid in, and optionally the health factor to land at
|
|
158
|
+
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
159
|
+
* shape can be funded at any size
|
|
160
|
+
*/
|
|
161
|
+
maxBorrow(props: Omit<MaxBorrowProps, "targetHF"> & {
|
|
162
|
+
targetHF?: bigint;
|
|
163
|
+
}): bigint;
|
|
122
164
|
/**
|
|
123
165
|
* Previews the same operation when its source only redeems through its
|
|
124
166
|
* issuer: a Securitize dsToken, a Mellow share.
|
|
@@ -186,6 +228,21 @@ declare class CreditAccountOperationsService extends SDKConstruct {
|
|
|
186
228
|
* beside it, so both halves of an operation are consumed the same way
|
|
187
229
|
*/
|
|
188
230
|
finishIntent(props: FinishIntentProps): Promise<FinishIntentResult>;
|
|
231
|
+
/**
|
|
232
|
+
* Previews opening an account that holds nothing.
|
|
233
|
+
*
|
|
234
|
+
* Nothing is put up, drawn or routed, so there is no state to build and no
|
|
235
|
+
* guard to run beyond the market's own: a paused or expired facade takes no
|
|
236
|
+
* multicall, and an opening is a multicall like any other. Answers the same
|
|
237
|
+
* envelope its two neighbours do so a caller branches on `ok` throughout.
|
|
238
|
+
*
|
|
239
|
+
* @param props - The SDK holding the market, and the manager to open in
|
|
240
|
+
* @returns `{ ok: true }`, or `{ ok: false, error }` when the market takes
|
|
241
|
+
* no transaction right now
|
|
242
|
+
*/
|
|
243
|
+
openEmptyAccountIntent(props: Pick<StartIntentProps, "sdk"> & {
|
|
244
|
+
creditManager: Address;
|
|
245
|
+
}): Promise<EmptyAccountPreviewResult>;
|
|
189
246
|
/**
|
|
190
247
|
* Previews opening a brand-new leveraged position.
|
|
191
248
|
*
|
|
@@ -199,6 +256,28 @@ declare class CreditAccountOperationsService extends SDKConstruct {
|
|
|
199
256
|
* leverage or the resulting debt is not viable
|
|
200
257
|
*/
|
|
201
258
|
openStrategyIntent(props: OpenStrategyProps): Promise<OpenStrategyPreviewResult>;
|
|
259
|
+
/**
|
|
260
|
+
* Previews taking a loan against collateral, on an account this same
|
|
261
|
+
* transaction opens.
|
|
262
|
+
*
|
|
263
|
+
* Sits beside {@link openStrategyIntent} rather than under
|
|
264
|
+
* {@link startIntent} for the same reason: there is no account yet, and the
|
|
265
|
+
* output feeds `sdk.accounts.openCA`. What sets it apart from an opening is
|
|
266
|
+
* where the loan goes — out to the wallet rather than into a position — so
|
|
267
|
+
* the debt is named outright instead of following from a leverage, and the
|
|
268
|
+
* collateral is the only thing the account is left holding.
|
|
269
|
+
*
|
|
270
|
+
* `creditAccount` draws the loan on one the wallet already holds instead of
|
|
271
|
+
* opening another, as an opening takes one.
|
|
272
|
+
*
|
|
273
|
+
* @param props - Credit manager, the collateral the wallet puts up and the
|
|
274
|
+
* payout it asks for
|
|
275
|
+
* @returns Debt, the payout's two branches and the projection the account
|
|
276
|
+
* lands in, or `{ ok: false, error }` when the loan is not viable — a debt
|
|
277
|
+
* outside the facade's limits, collateral that cannot carry it, a payout the
|
|
278
|
+
* router has no path to
|
|
279
|
+
*/
|
|
280
|
+
borrowIntent(props: BorrowProps): Promise<BorrowPreviewResult>;
|
|
202
281
|
}
|
|
203
282
|
//#endregion
|
|
204
|
-
export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, type ClaimRemainder, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, type FinishIntentProps, type FinishIntentResult, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, type PathLossRate, type RepayStrategyIntent, type ResumableIntent, type RouteErrors, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
|
|
283
|
+
export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, BorrowPreviewResult, type BorrowProps, type BorrowState, type ClaimRemainder, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EmptyAccountPreviewResult, type FinishIntentProps, type FinishIntentResult, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, type PathLossRate, type RepayStrategyIntent, type ResumableIntent, type RouteErrors, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
2
|
+
import "../../index.js";
|
|
3
|
+
import { Address } from "viem";
|
|
4
|
+
//#region src/onchain/accounts/intents/maxBorrow.d.ts
|
|
5
|
+
interface MaxBorrowProps {
|
|
6
|
+
sdk: OnchainSDK;
|
|
7
|
+
/** Credit manager the loan would be taken in. */
|
|
8
|
+
creditManager: Address;
|
|
9
|
+
/** Token the wallet puts up, in the manager's collateral list. */
|
|
10
|
+
collateralToken: Address;
|
|
11
|
+
/** Amount of {@link collateralToken}, in its own units. */
|
|
12
|
+
collateralAmount: bigint;
|
|
13
|
+
/** Token the loan is paid out in; the answer is in its units. */
|
|
14
|
+
borrowToken: Address;
|
|
15
|
+
/** Health factor the loan has to leave the account at, in basis points. */
|
|
16
|
+
targetHF: bigint;
|
|
17
|
+
/** Extra quota headroom in PERCENTAGE_FORMAT, as the borrow itself takes. */
|
|
18
|
+
quotaReserve: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Largest loan this collateral supports at `targetHF` — the ceiling a borrow
|
|
22
|
+
* form should offer, in the payout token's units.
|
|
23
|
+
*
|
|
24
|
+
* The inverse of a borrow rather than a search for one: the loan leaves the
|
|
25
|
+
* account entirely, so the collateral is the whole of what backs the debt, and
|
|
26
|
+
* the health factor is one division away from the amount. Solving it the other
|
|
27
|
+
* way round costs a division too, and no iteration.
|
|
28
|
+
*
|
|
29
|
+
* Collateral is valued the way the transaction will be judged — at safe
|
|
30
|
+
* prices, under its liquidation threshold, capped by the quota the borrow
|
|
31
|
+
* buys for it, all of which is {@link collateralValuation}'s business. The ceiling
|
|
32
|
+
* is then held to what the market will actually lend: the pool's free
|
|
33
|
+
* liquidity, the manager's own allowance and the facade's `maxDebt`, whichever
|
|
34
|
+
* binds first.
|
|
35
|
+
*
|
|
36
|
+
* The facade's `minDebt` is deliberately not applied. It is a floor, and a
|
|
37
|
+
* ceiling answered as `0n` because the collateral is too small for this market
|
|
38
|
+
* would tell a form nothing about what it is holding — the number a user needs
|
|
39
|
+
* to see is the one they are short of. Collateral that carries something
|
|
40
|
+
* therefore answers with it, whether or not the market would lend that little;
|
|
41
|
+
* a loan under the floor is refused by `borrow` itself, with `debtOutOfRange`
|
|
42
|
+
* naming both ends.
|
|
43
|
+
*
|
|
44
|
+
* Nothing is fetched or simulated — the account does not exist yet and every
|
|
45
|
+
* input is loaded market state, so a form can call this on each keystroke.
|
|
46
|
+
*
|
|
47
|
+
* @param props - {@link MaxBorrowProps}
|
|
48
|
+
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
49
|
+
* shape exists at any size — a collateral that backs nothing at safe prices, a
|
|
50
|
+
* market with nothing left to lend, and a manager the SDK does not hold yet
|
|
51
|
+
**/
|
|
52
|
+
declare function maxBorrow(props: MaxBorrowProps): bigint;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { MaxBorrowProps, maxBorrow };
|
|
@@ -16,9 +16,9 @@ interface MaxWithdrawCollateralProps {
|
|
|
16
16
|
* factor stays at or above `targetHF`.
|
|
17
17
|
*
|
|
18
18
|
* This is the collateral check solved for one balance, and it counts what that
|
|
19
|
-
* check counts — see {@link
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* check counts — see {@link collateralValuation} for it, safe prices included.
|
|
20
|
+
* The debt is valued at the main feed, as the check does. Zero debt frees the
|
|
21
|
+
* whole balance.
|
|
22
22
|
*
|
|
23
23
|
* Rounding always favours the account, so the answer clears the check rather
|
|
24
24
|
* than landing a wei short of it.
|
|
@@ -8,15 +8,8 @@ import { CreditAccountSlice, SimulationPrices } from "./types.js";
|
|
|
8
8
|
import "../../index.js";
|
|
9
9
|
import { Address } from "viem";
|
|
10
10
|
//#region src/onchain/accounts/intents/open-strategy.d.ts
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* The union says which of the two openings this is: {@link OpenStrategyEmpty}
|
|
15
|
-
* takes only the market, because an account holding nothing has nothing to
|
|
16
|
-
* route, no leverage to reach and no target to reach it in.
|
|
17
|
-
*/
|
|
18
|
-
type OpenStrategyProps = OpenStrategyFunded | OpenStrategyEmpty;
|
|
19
|
-
interface OpenStrategyFunded {
|
|
11
|
+
/** Opening an account and putting a position on it in one transaction. */
|
|
12
|
+
interface OpenStrategyProps {
|
|
20
13
|
sdk: OnchainSDK;
|
|
21
14
|
/** Credit manager to open the account in. */
|
|
22
15
|
creditManager: Address;
|
|
@@ -39,13 +32,6 @@ interface OpenStrategyFunded {
|
|
|
39
32
|
* is what the `DEPOSIT` intent is for.
|
|
40
33
|
**/
|
|
41
34
|
creditAccount?: CreditAccountSlice;
|
|
42
|
-
empty?: false;
|
|
43
|
-
}
|
|
44
|
-
/** Opening an account that holds nothing, for a position to land on later. */
|
|
45
|
-
interface OpenStrategyEmpty {
|
|
46
|
-
sdk: OnchainSDK;
|
|
47
|
-
creditManager: Address;
|
|
48
|
-
empty: true;
|
|
49
35
|
}
|
|
50
36
|
/**
|
|
51
37
|
* Projected result of opening a brand-new leveraged position.
|
|
@@ -95,4 +81,4 @@ interface OpenStrategyState extends Omit<AccountProjection, "assets" | "quotas">
|
|
|
95
81
|
*/
|
|
96
82
|
declare function buildOpenStrategyState(props: OpenStrategyProps): Promise<OpenStrategyState>;
|
|
97
83
|
//#endregion
|
|
98
|
-
export {
|
|
84
|
+
export { OpenStrategyProps, OpenStrategyState, buildOpenStrategyState };
|
|
@@ -90,6 +90,8 @@ interface BuildMockSdkArgs {
|
|
|
90
90
|
baseInterestRate?: bigint;
|
|
91
91
|
/** Credit manager interest fee in Bps; feeds position metrics. */
|
|
92
92
|
feeInterest?: number;
|
|
93
|
+
/** Quoted tokens the facade enables at once; feeds `checkQuotaCount`. */
|
|
94
|
+
maxEnabledTokens?: number;
|
|
93
95
|
creditManager: Address;
|
|
94
96
|
creditFacade: Address;
|
|
95
97
|
/** Market underlying token (`market.pool.underlying`). */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Asset } from "../../../base/types.js";
|
|
2
2
|
import { OnchainSDK } from "../../../OnchainSDK.js";
|
|
3
|
-
import {
|
|
3
|
+
import { OpenStrategyProps } from "../open-strategy.js";
|
|
4
4
|
import "../../../index.js";
|
|
5
5
|
import { MarketSdkExtras } from "../testing/market.js";
|
|
6
6
|
import { Address } from "viem";
|
|
@@ -51,6 +51,6 @@ declare const case_underlying_1x: OpenStrategyCase;
|
|
|
51
51
|
*/
|
|
52
52
|
declare const case_mixed_with_leftover: OpenStrategyCase;
|
|
53
53
|
declare function buildOpenStrategySdk(extras?: MarketSdkExtras): OnchainSDK;
|
|
54
|
-
declare function buildOpenStrategyProps(c: OpenStrategyCase, sdk: OnchainSDK):
|
|
54
|
+
declare function buildOpenStrategyProps(c: OpenStrategyCase, sdk: OnchainSDK): OpenStrategyProps;
|
|
55
55
|
//#endregion
|
|
56
56
|
export { COLLATERAL_ANY, HALF_UND, KEEP_ANY, LEVERAGE_1X, LEVERAGE_2X, LEVERAGE_3X, LT, MARGIN_UND, OpenStrategyCase, buildOpenStrategyProps, buildOpenStrategySdk, case_mixed_with_leftover, case_underlying_1x, case_underlying_3x, quotaFor };
|
|
@@ -68,7 +68,12 @@ interface OperationState extends AccountProjection, SimulationPrices {
|
|
|
68
68
|
* underlying of everything its routed legs and redemption request return,
|
|
69
69
|
* the expected claim included, against the value of what they spend.
|
|
70
70
|
* In `PERCENTAGE_FACTOR_1KK` (1_000_000 = 100%), negative for a loss.
|
|
71
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* `undefined` where nothing was traded, where a leg cannot be priced, and on
|
|
73
|
+
* a {@link BorrowState}, which does not measure it: the rate compares an
|
|
74
|
+
* account against itself before and after, and a borrow's payout goes to the
|
|
75
|
+
* wallet rather than staying to be compared. What its route cost is on that
|
|
76
|
+
* state as `borrowed` against `totalDebt`.
|
|
72
77
|
*/
|
|
73
78
|
executionCost: bigint | undefined;
|
|
74
79
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Asset } from "../../../base/types.js";
|
|
2
2
|
import { RouterCASlice } from "../../../router/types.js";
|
|
3
|
+
import { MarketSuite } from "../../../market/MarketSuite.js";
|
|
4
|
+
import { CreditSuite } from "../../../market/credit/CreditSuite.js";
|
|
3
5
|
import { OnchainSDK } from "../../../OnchainSDK.js";
|
|
4
6
|
import { CreditAccountSlice } from "../types.js";
|
|
5
7
|
import "../../../index.js";
|
|
@@ -7,6 +9,18 @@ import { Address } from "viem";
|
|
|
7
9
|
//#region src/onchain/accounts/intents/utils/common.d.ts
|
|
8
10
|
/** Case-insensitive address equality. */
|
|
9
11
|
declare const eq: (a: Address, b: Address) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The suite and market behind a credit manager, or nothing where the register
|
|
14
|
+
* has no entry for it.
|
|
15
|
+
*
|
|
16
|
+
* For the reads a form calls on every keystroke, including before the SDK has
|
|
17
|
+
* finished attaching: a question the register cannot answer yet is not an
|
|
18
|
+
* error. Everything that prepares a transaction wants the throw instead.
|
|
19
|
+
*/
|
|
20
|
+
declare function resolveCreditManager(sdk: OnchainSDK, creditManager: Address): {
|
|
21
|
+
suite: CreditSuite;
|
|
22
|
+
market: MarketSuite;
|
|
23
|
+
} | undefined;
|
|
10
24
|
declare function toTargetDecimals(fromAmount: bigint, fromToken: Address, toToken: Address, sdk: OnchainSDK): bigint;
|
|
11
25
|
/**
|
|
12
26
|
* Router CA slice from the account slice. RouterV310 reads `ca.tokens` for
|
|
@@ -16,4 +30,4 @@ declare function toTargetDecimals(fromAmount: bigint, fromToken: Address, toToke
|
|
|
16
30
|
*/
|
|
17
31
|
declare function toRouterCaSlice(creditAccount: CreditAccountSlice, expectedBalances?: Asset[]): RouterCASlice;
|
|
18
32
|
//#endregion
|
|
19
|
-
export { eq, toRouterCaSlice, toTargetDecimals };
|
|
33
|
+
export { eq, resolveCreditManager, toRouterCaSlice, toTargetDecimals };
|
|
@@ -15,6 +15,19 @@ import { Address } from "viem";
|
|
|
15
15
|
* behave consistently everywhere downstream.
|
|
16
16
|
*/
|
|
17
17
|
declare function toCreditAccountSlice(ca: CreditAccountDataPayload): CreditAccountSlice;
|
|
18
|
+
/**
|
|
19
|
+
* The slice a flow that has no account yet quotes against.
|
|
20
|
+
*
|
|
21
|
+
* Nothing of it exists on chain until the transaction lands, and nothing has
|
|
22
|
+
* to: the pathfinder is asked about the credit manager, and every balance the
|
|
23
|
+
* flow reasons about is one the transaction itself puts there. The zero
|
|
24
|
+
* address stands in for the account so the shape is complete.
|
|
25
|
+
*/
|
|
26
|
+
declare function unopenedAccountSlice(args: {
|
|
27
|
+
creditManager: Address;
|
|
28
|
+
creditFacade: Address;
|
|
29
|
+
underlying: Address;
|
|
30
|
+
}): CreditAccountSlice;
|
|
18
31
|
/**
|
|
19
32
|
* Reads an account by address and narrows it to {@link CreditAccountSlice}.
|
|
20
33
|
*
|
|
@@ -26,4 +39,4 @@ declare function toCreditAccountSlice(ca: CreditAccountDataPayload): CreditAccou
|
|
|
26
39
|
*/
|
|
27
40
|
declare function fetchCreditAccountSlice(sdk: OnchainSDK, creditAccount: Address): Promise<CreditAccountSlice>;
|
|
28
41
|
//#endregion
|
|
29
|
-
export { fetchCreditAccountSlice, toCreditAccountSlice };
|
|
42
|
+
export { fetchCreditAccountSlice, toCreditAccountSlice, unopenedAccountSlice };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./credit-account-slice.js";
|
|
1
|
+
import { fetchCreditAccountSlice, toCreditAccountSlice, unopenedAccountSlice } from "./credit-account-slice.js";
|
|
2
2
|
import { CandidateToken, isPhantomToken, isRedemptionPhantomToken, pickFattestNonPhantomToken, rankAccountTokens } from "./pick-token.js";
|
|
3
3
|
import { LegProbe, collectPriceImpact, lossRate, startProbe } from "./price-impact.js";
|
|
4
4
|
import { OpenStrategyLeg, RouterPaths, SwapLeg, createOraclePaths, createRouterPaths } from "./router-path.js";
|
|
5
5
|
import { adjustStateToSnapshot } from "./adjust-state-to-snapshot.js";
|
|
6
6
|
import { assembleOperationCalls } from "./assemble-operation-calls.js";
|
|
7
7
|
import { calcBorrowedAmountPlusInterestAndFees } from "./borrowed-amount-plus-interest-and-fees.js";
|
|
8
|
-
import { eq, toRouterCaSlice, toTargetDecimals } from "./common.js";
|
|
8
|
+
import { eq, resolveCreditManager, toRouterCaSlice, toTargetDecimals } from "./common.js";
|
|
9
9
|
import { LedgerSnapshot, OperationLedger } from "./ledger.js";
|
|
10
10
|
import { clearedQuotas, getQuotasForUpdate, quotasAfterUpdate } from "./quotas-for-update.js";
|
|
11
|
-
export { CandidateToken, LedgerSnapshot, LegProbe, OpenStrategyLeg, OperationLedger, RouterPaths, SwapLeg, adjustStateToSnapshot, assembleOperationCalls, calcBorrowedAmountPlusInterestAndFees, clearedQuotas, collectPriceImpact, createOraclePaths, createRouterPaths, eq, fetchCreditAccountSlice, getQuotasForUpdate, isPhantomToken, isRedemptionPhantomToken, lossRate, pickFattestNonPhantomToken, quotasAfterUpdate, rankAccountTokens, startProbe, toCreditAccountSlice, toRouterCaSlice, toTargetDecimals };
|
|
11
|
+
export { CandidateToken, LedgerSnapshot, LegProbe, OpenStrategyLeg, OperationLedger, RouterPaths, SwapLeg, adjustStateToSnapshot, assembleOperationCalls, calcBorrowedAmountPlusInterestAndFees, clearedQuotas, collectPriceImpact, createOraclePaths, createRouterPaths, eq, fetchCreditAccountSlice, getQuotasForUpdate, isPhantomToken, isRedemptionPhantomToken, lossRate, pickFattestNonPhantomToken, quotasAfterUpdate, rankAccountTokens, resolveCreditManager, startProbe, toCreditAccountSlice, toRouterCaSlice, toTargetDecimals, unopenedAccountSlice };
|
|
@@ -47,7 +47,7 @@ interface MaxSafeWithdrawalProps {
|
|
|
47
47
|
* in underlying units.
|
|
48
48
|
*
|
|
49
49
|
* A withdrawal hands funds over, so the facade weighs the account it leaves
|
|
50
|
-
* behind at safe prices rather than main ones — see {@link
|
|
50
|
+
* behind at safe prices rather than main ones — see {@link collateralValuation}.
|
|
51
51
|
* That is a second limit on top of the facade's `debtLimits`, and the two are
|
|
52
52
|
* independent: a caller wanting the amount a form may actually offer takes the
|
|
53
53
|
* lesser of this and `maxProportionalWithdrawal`.
|