@gearbox-protocol/sdk 16.0.0-next.42 → 16.0.0-next.44
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/model/index.js +4 -0
- package/dist/cjs/model/result.js +27 -0
- package/dist/cjs/onchain/accounts/index.js +0 -2
- package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +13 -7
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -19
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +1 -2
- package/dist/cjs/onchain/index.js +0 -5
- package/dist/cjs/onchain/market/index.js +0 -2
- package/dist/cjs/onchain/market/zapper/ZapperContract.js +15 -8
- package/dist/cjs/onchain/market/zapper/errors.js +0 -17
- package/dist/cjs/onchain/market/zapper/index.js +1 -2
- package/dist/cjs/onchain/validation/checks.js +1 -1
- package/dist/cjs/onchain/validation/index.js +0 -1
- package/dist/cjs/preview/index.js +2 -8
- package/dist/cjs/preview/parse/errors.js +0 -32
- package/dist/cjs/preview/parse/index.js +1 -5
- package/dist/cjs/preview/parse/parseOperationCalldata.js +28 -17
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +17 -11
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +5 -2
- package/dist/cjs/preview/preview/detectDelayedClaim.js +9 -7
- package/dist/cjs/preview/preview/detectDelayedOperation.js +11 -4
- package/dist/cjs/preview/preview/errors.js +0 -16
- package/dist/cjs/preview/preview/index.js +1 -2
- package/dist/cjs/preview/preview/previewOperation.js +30 -11
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/cjs/preview/simulate/errors.js +15 -24
- package/dist/cjs/preview/simulate/index.js +1 -1
- package/dist/cjs/preview/simulate/simulateOperation.js +6 -4
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +6 -3
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -1
- package/dist/cjs/sdk/index.js +1 -1
- package/dist/cjs/sdk/prepare/PrepareApi.js +198 -278
- package/dist/cjs/sdk/prepare/errors.js +5 -2
- package/dist/cjs/sdk/prepare/index.js +1 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/index.js +2 -1
- package/dist/esm/model/result.js +24 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +14 -8
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +1 -19
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +2 -2
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +2 -4
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/index.js +1 -2
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +16 -9
- package/dist/esm/onchain/market/zapper/errors.js +1 -17
- package/dist/esm/onchain/market/zapper/index.js +2 -2
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/checks.js +1 -1
- package/dist/esm/onchain/validation/index.js +2 -2
- package/dist/esm/preview/index.js +3 -5
- package/dist/esm/preview/parse/errors.js +1 -30
- package/dist/esm/preview/parse/index.js +2 -3
- package/dist/esm/preview/parse/parseOperationCalldata.js +28 -17
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +17 -11
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +5 -2
- package/dist/esm/preview/preview/detectDelayedClaim.js +9 -7
- package/dist/esm/preview/preview/detectDelayedOperation.js +11 -4
- package/dist/esm/preview/preview/errors.js +1 -16
- package/dist/esm/preview/preview/index.js +2 -2
- package/dist/esm/preview/preview/previewOperation.js +30 -11
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/esm/preview/simulate/errors.js +16 -24
- package/dist/esm/preview/simulate/index.js +2 -2
- package/dist/esm/preview/simulate/simulateOperation.js +6 -4
- package/dist/esm/preview/simulate/simulatePoolOperation.js +7 -4
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -1
- package/dist/esm/sdk/index.js +2 -2
- package/dist/esm/sdk/prepare/PrepareApi.js +199 -279
- package/dist/esm/sdk/prepare/errors.js +5 -2
- package/dist/esm/sdk/prepare/index.js +2 -2
- package/dist/types/model/errors.d.ts +4 -32
- package/dist/types/model/index.d.ts +3 -2
- package/dist/types/model/result.d.ts +48 -0
- package/dist/types/onchain/accounts/index.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +6 -4
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +9 -5
- package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +6 -4
- package/dist/types/onchain/index.d.ts +4 -4
- package/dist/types/onchain/market/index.d.ts +1 -1
- package/dist/types/onchain/market/zapper/ZapperContract.d.ts +7 -3
- package/dist/types/onchain/market/zapper/errors.d.ts +11 -6
- package/dist/types/onchain/market/zapper/index.d.ts +1 -1
- package/dist/types/onchain/market/zapper/types.d.ts +4 -1
- package/dist/types/onchain/validation/checks.d.ts +1 -1
- package/dist/types/onchain/validation/index.d.ts +2 -2
- package/dist/types/preview/index.d.ts +5 -3
- package/dist/types/preview/parse/errors.d.ts +19 -12
- package/dist/types/preview/parse/index.d.ts +1 -1
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +5 -1
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +5 -2
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +6 -1
- package/dist/types/preview/preview/detectDelayedClaim.d.ts +7 -6
- package/dist/types/preview/preview/detectDelayedOperation.d.ts +3 -1
- package/dist/types/preview/preview/errors.d.ts +8 -5
- package/dist/types/preview/preview/index.d.ts +2 -2
- package/dist/types/preview/preview/previewOperation.d.ts +21 -2
- package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +3 -1
- package/dist/types/preview/simulate/errors.d.ts +12 -8
- package/dist/types/preview/simulate/index.d.ts +2 -2
- package/dist/types/preview/simulate/simulateOperation.d.ts +4 -1
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +4 -1
- package/dist/types/sdk/execute/types.d.ts +6 -11
- package/dist/types/sdk/index.d.ts +3 -3
- package/dist/types/sdk/prepare/PrepareApi.d.ts +29 -26
- package/dist/types/sdk/prepare/errors.d.ts +57 -20
- package/dist/types/sdk/prepare/index.d.ts +3 -3
- package/dist/types/sdk/prepare/types.d.ts +73 -74
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +4 -1
- package/dist/types/sdk/preview/types.d.ts +7 -3
- package/dist/types/sdk/types.d.ts +1 -3
- package/package.json +11 -2
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
import { PoolV310Contract } from "../../onchain/market/pool/PoolV310Contract.js";
|
|
2
4
|
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
3
5
|
import "../../onchain/index.js";
|
|
4
6
|
import { PoolOperation } from "./types-pools.js";
|
|
5
7
|
import "./types.js";
|
|
8
|
+
import { UnsupportedPoolFunctionError } from "./errors.js";
|
|
6
9
|
import { Hex } from "viem";
|
|
7
10
|
//#region src/preview/parse/parsePoolOperationCalldata.d.ts
|
|
8
11
|
/**
|
|
@@ -11,8 +14,8 @@ import { Hex } from "viem";
|
|
|
11
14
|
* @param sdk - The SDK instance.
|
|
12
15
|
* @param pool - The pool contract.
|
|
13
16
|
* @param calldata - The calldata to parse.
|
|
14
|
-
* @returns The parsed operation.
|
|
17
|
+
* @returns The parsed operation behind `ok`, or the refusal.
|
|
15
18
|
*/
|
|
16
|
-
declare function parsePoolOperationCalldata(sdk: OnchainSDK, pool: PoolV310Contract, calldata: Hex): PoolOperation
|
|
19
|
+
declare function parsePoolOperationCalldata(sdk: OnchainSDK, pool: PoolV310Contract, calldata: Hex): SDKReturn<PoolOperation, UnsupportedPoolFunctionError>;
|
|
17
20
|
//#endregion
|
|
18
21
|
export { parsePoolOperationCalldata };
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { UnsupportedZapperFunctionError } from "../../onchain/market/zapper/errors.js";
|
|
1
4
|
import { PluginsMap } from "../../onchain/plugins/types.js";
|
|
2
5
|
import "../../onchain/index.js";
|
|
6
|
+
import { UnsupportedPoolFunctionError, UnsupportedTargetError } from "../parse/errors.js";
|
|
3
7
|
import { PreviewOperationInput, PreviewOperationOptions } from "../types.js";
|
|
8
|
+
import "../parse/index.js";
|
|
4
9
|
import { PrerequisiteResult } from "./types.js";
|
|
5
10
|
//#region src/preview/prerequisites/checkPrerequisites.d.ts
|
|
6
11
|
/**
|
|
@@ -18,6 +23,6 @@ import { PrerequisiteResult } from "./types.js";
|
|
|
18
23
|
* (e.g. pool is paused) is intentionally out of scope, since the user cannot
|
|
19
24
|
* resolve it.
|
|
20
25
|
*/
|
|
21
|
-
declare function checkPrerequisites<P extends PluginsMap>(input: PreviewOperationInput<P>, options?: PreviewOperationOptions): Promise<PrerequisiteResult[]
|
|
26
|
+
declare function checkPrerequisites<P extends PluginsMap>(input: PreviewOperationInput<P>, options?: PreviewOperationOptions): Promise<SDKReturn<PrerequisiteResult[], UnsupportedTargetError | UnsupportedPoolFunctionError | UnsupportedZapperFunctionError>>;
|
|
22
27
|
//#endregion
|
|
23
28
|
export { checkPrerequisites };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DelayedIntent } from "../../model/delayed-intents.js";
|
|
2
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
3
|
import "../../model/index.js";
|
|
4
|
+
import { InvalidDelayedIntentError } from "../../onchain/accounts/withdrawal-compressor/errors.js";
|
|
3
5
|
import { PluginsMap } from "../../onchain/plugins/types.js";
|
|
4
6
|
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
5
7
|
import "../../onchain/index.js";
|
|
@@ -41,12 +43,11 @@ declare function detectDelayedClaim<P extends PluginsMap>(sdk: OnchainSDK<P>, mu
|
|
|
41
43
|
* @param sdk - Attached SDK.
|
|
42
44
|
* @param multicall - Parsed inner operations of the multicall.
|
|
43
45
|
* @param blockNumber - Optional block number to read the log at.
|
|
44
|
-
* @returns The decoded intent
|
|
45
|
-
* nothing, the redemption logger is not deployed, or the log carries
|
|
46
|
-
* intent
|
|
47
|
-
*
|
|
48
|
-
* but cannot be decoded as a `DelayedIntent`.
|
|
46
|
+
* @returns The decoded intent behind `ok` (`undefined` when the multicall
|
|
47
|
+
* claims nothing, the redemption logger is not deployed, or the log carries
|
|
48
|
+
* no intent), or the `invalidDelayedIntent` refusal when the logged
|
|
49
|
+
* `extraData` is non-empty but cannot be decoded as a `DelayedIntent`.
|
|
49
50
|
*/
|
|
50
|
-
declare function resolveDelayedClaimIntent<P extends PluginsMap>(sdk: OnchainSDK<P>, multicall: InnerOperation[], blockNumber?: bigint): Promise<DelayedIntent | undefined
|
|
51
|
+
declare function resolveDelayedClaimIntent<P extends PluginsMap>(sdk: OnchainSDK<P>, multicall: InnerOperation[], blockNumber?: bigint): Promise<SDKReturn<DelayedIntent | undefined, InvalidDelayedIntentError>>;
|
|
51
52
|
//#endregion
|
|
52
53
|
export { DetectedDelayedClaim, detectDelayedClaim, resolveDelayedClaimIntent };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DelayedIntent } from "../../model/delayed-intents.js";
|
|
2
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
3
|
import "../../model/index.js";
|
|
4
|
+
import { InvalidDelayedIntentError } from "../../onchain/accounts/withdrawal-compressor/errors.js";
|
|
3
5
|
import { DelayedWithdrawalRequest } from "../../onchain/market/adapters/types.js";
|
|
4
6
|
import { PluginsMap } from "../../onchain/plugins/types.js";
|
|
5
7
|
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
@@ -32,6 +34,6 @@ interface DetectedDelayedOperation {
|
|
|
32
34
|
* @throws InvalidDelayedIntentError when a request carries non-empty
|
|
33
35
|
* `extraData` that cannot be decoded as a `DelayedIntent`.
|
|
34
36
|
*/
|
|
35
|
-
declare function detectDelayedOperation<P extends PluginsMap>(sdk: OnchainSDK<P>, multicall: InnerOperation[]): DetectedDelayedOperation | undefined
|
|
37
|
+
declare function detectDelayedOperation<P extends PluginsMap>(sdk: OnchainSDK<P>, multicall: InnerOperation[]): SDKReturn<DetectedDelayedOperation | undefined, InvalidDelayedIntentError>;
|
|
36
38
|
//#endregion
|
|
37
39
|
export { DetectedDelayedOperation, detectDelayedOperation };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { IGearboxError } from "../../model/errors.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
//#region src/preview/preview/errors.d.ts
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
+
* Refusal answered by `previewOperation` for parsed operations it cannot
|
|
6
|
+
* preview yet. A plain returned object per the SDK's refusal vocabulary —
|
|
7
|
+
* not a thrown `Error`.
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
interface UnsupportedOperationError extends IGearboxError {
|
|
10
|
+
code: "unsupportedOperation";
|
|
7
11
|
/** The parsed operation kind (the `operation` discriminant). */
|
|
8
|
-
|
|
9
|
-
constructor(operation: string);
|
|
12
|
+
operation: string;
|
|
10
13
|
}
|
|
11
14
|
//#endregion
|
|
12
15
|
export { UnsupportedOperationError };
|
|
@@ -7,7 +7,7 @@ import { UnsupportedOperationError } from "./errors.js";
|
|
|
7
7
|
import { estimateClaimableAt } from "./estimateClaimableAt.js";
|
|
8
8
|
import { previewAdjustStrategyPosition } from "./previewAdjustStrategyPosition.js";
|
|
9
9
|
import { CloseOrRepayOperation, previewExitOrRepayStrategyPosition } from "./previewExitOrRepayStrategyPosition.js";
|
|
10
|
-
import { previewOperation } from "./previewOperation.js";
|
|
10
|
+
import { PreviewOperationError, previewOperation } from "./previewOperation.js";
|
|
11
11
|
import { ReplayState, makeReplayState, replayInnerOperations } from "./replayInnerOperations.js";
|
|
12
12
|
import { ReplayMulticallResult, ReplayableOperation, replayMulticall } from "./replayMulticall.js";
|
|
13
|
-
export { CloseOrRepayOperation, CreditAccountState, CreditAccountStateProps, DetectedDelayedClaim, DetectedDelayedOperation, ReplayMulticallResult, ReplayState, ReplayableOperation, UnsupportedOperationError, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, makeReplayState, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
13
|
+
export { CloseOrRepayOperation, CreditAccountState, CreditAccountStateProps, DetectedDelayedClaim, DetectedDelayedOperation, PreviewOperationError, ReplayMulticallResult, ReplayState, ReplayableOperation, UnsupportedOperationError, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, makeReplayState, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
import { OperationPreview } from "../../model/previews.js";
|
|
2
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
3
|
import "../../model/index.js";
|
|
4
|
+
import { InvalidDelayedIntentError } from "../../onchain/accounts/withdrawal-compressor/errors.js";
|
|
5
|
+
import { UnsupportedZapperFunctionError } from "../../onchain/market/zapper/errors.js";
|
|
3
6
|
import { PluginsMap } from "../../onchain/plugins/types.js";
|
|
4
7
|
import "../../onchain/index.js";
|
|
8
|
+
import { UnsupportedPoolFunctionError, UnsupportedTargetError } from "../parse/errors.js";
|
|
5
9
|
import { PreviewOperationInput, PreviewOperationOptions } from "../types.js";
|
|
10
|
+
import "../parse/index.js";
|
|
11
|
+
import { UnsupportedOperationError } from "./errors.js";
|
|
12
|
+
import { PreviewSimulationError } from "../simulate/errors.js";
|
|
6
13
|
//#region src/preview/preview/previewOperation.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Everything {@link previewOperation} can refuse with: the refusal errors
|
|
16
|
+
* its pipeline raises, discriminated by `code`. Each is a plain object —
|
|
17
|
+
* never a thrown `Error` — per the SDK's refusal vocabulary.
|
|
18
|
+
*/
|
|
19
|
+
type PreviewOperationError = UnsupportedTargetError | UnsupportedPoolFunctionError | UnsupportedZapperFunctionError | UnsupportedOperationError | InvalidDelayedIntentError | PreviewSimulationError;
|
|
7
20
|
/**
|
|
8
21
|
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
9
22
|
* assembles an operation-specific, human-displayable preview.
|
|
23
|
+
*
|
|
24
|
+
* Answers an {@link SDKReturn} envelope: the preview behind `ok: true`, or —
|
|
25
|
+
* when the transaction is one the previewer refuses to read — a
|
|
26
|
+
* {@link PreviewOperationError} behind `ok: false`. A thrown exception
|
|
27
|
+
* still means the SDK could not do its job (a read failed, the targeted
|
|
28
|
+
* credit account could not be resolved), not a refusal of the transaction.
|
|
10
29
|
*/
|
|
11
|
-
declare function previewOperation<P extends PluginsMap = PluginsMap>(input: PreviewOperationInput<P>, options?: PreviewOperationOptions): Promise<OperationPreview
|
|
30
|
+
declare function previewOperation<P extends PluginsMap = PluginsMap>(input: PreviewOperationInput<P>, options?: PreviewOperationOptions): Promise<SDKReturn<OperationPreview, PreviewOperationError>>;
|
|
12
31
|
//#endregion
|
|
13
|
-
export { previewOperation };
|
|
32
|
+
export { PreviewOperationError, previewOperation };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { PoolPositionOperationPreview } from "../../model/previews.js";
|
|
2
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
3
|
import "../../model/index.js";
|
|
3
4
|
import { PluginsMap } from "../../onchain/plugins/types.js";
|
|
4
5
|
import "../../onchain/index.js";
|
|
5
6
|
import { PoolOperation } from "../parse/types-pools.js";
|
|
6
7
|
import { PreviewOperationInput, PreviewOperationOptions } from "../types.js";
|
|
7
8
|
import "../parse/index.js";
|
|
9
|
+
import { PreviewSimulationError } from "../simulate/errors.js";
|
|
8
10
|
//#region src/preview/preview/previewPoolPositionOperation.d.ts
|
|
9
|
-
declare function previewPoolPositionOperation<P extends PluginsMap>(input: PreviewOperationInput<P>, operation: PoolOperation, options?: PreviewOperationOptions): Promise<PoolPositionOperationPreview
|
|
11
|
+
declare function previewPoolPositionOperation<P extends PluginsMap>(input: PreviewOperationInput<P>, operation: PoolOperation, options?: PreviewOperationOptions): Promise<SDKReturn<PoolPositionOperationPreview, PreviewSimulationError>>;
|
|
10
12
|
//#endregion
|
|
11
13
|
export { previewPoolPositionOperation };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IGearboxError } from "../../model/errors.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { Hex } from "viem";
|
|
2
4
|
//#region src/preview/simulate/errors.d.ts
|
|
3
5
|
/** Which simulation flow produced a failure. */
|
|
4
6
|
type SimulationFlowSource = "multicall" | "unknown";
|
|
@@ -8,14 +10,16 @@ interface SimulationFlowFailure {
|
|
|
8
10
|
detail: SimulationError;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
* decoded revert reason (see {@link failures}).
|
|
13
|
+
* Refusal answered when the pool simulation fails. It wraps each flow's
|
|
14
|
+
* decoded revert reason (see {@link failures}). A plain returned object per
|
|
15
|
+
* the SDK's refusal vocabulary — not a thrown `Error`.
|
|
13
16
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** Per-flow decoded failures behind this
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
interface PreviewSimulationError extends IGearboxError {
|
|
18
|
+
code: "previewSimulationFailed";
|
|
19
|
+
/** Per-flow decoded failures behind this refusal. */
|
|
20
|
+
failures: SimulationFlowFailure[];
|
|
21
|
+
/** First flow failure that was itself an `Error`, kept for debugging. */
|
|
22
|
+
cause?: Error;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Normalises an unknown rejection reason into a {@link PreviewSimulationError}.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PreviewSimulationError, SimulationError, SimulationFlowFailure, SimulationFlowSource } from "./errors.js";
|
|
1
|
+
import { PreviewSimulationError, SimulationError, SimulationFlowFailure, SimulationFlowSource, asPreviewSimulationError } from "./errors.js";
|
|
2
2
|
import { PoolOperationSimulationResult, SimulationInput } from "./types.js";
|
|
3
3
|
import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
4
4
|
import { simulateOperation } from "./simulateOperation.js";
|
|
5
5
|
import { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
6
6
|
import { simulateRWAOperation } from "./simulateRWAOperation.js";
|
|
7
|
-
export { type PoolOperationSimulationResult, PreviewSimulationError, type SimulationError, type SimulationFlowFailure, type SimulationFlowSource, type SimulationInput, simulateFacadeOperation, simulateOperation, simulatePoolOperation, simulateRWAOperation };
|
|
7
|
+
export { type PoolOperationSimulationResult, type PreviewSimulationError, type SimulationError, type SimulationFlowFailure, type SimulationFlowSource, type SimulationInput, asPreviewSimulationError, simulateFacadeOperation, simulateOperation, simulatePoolOperation, simulateRWAOperation };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
import { PreviewOperationOptions } from "../types.js";
|
|
4
|
+
import { PreviewSimulationError } from "./errors.js";
|
|
2
5
|
import { PoolOperationSimulationResult, SimulationInput } from "./types.js";
|
|
3
6
|
//#region src/preview/simulate/simulateOperation.d.ts
|
|
4
7
|
/**
|
|
5
8
|
* Simulates a parsed pool or credit account operation
|
|
6
9
|
*/
|
|
7
|
-
declare function simulateOperation(input: SimulationInput, options?: PreviewOperationOptions): Promise<PoolOperationSimulationResult
|
|
10
|
+
declare function simulateOperation(input: SimulationInput, options?: PreviewOperationOptions): Promise<SDKReturn<PoolOperationSimulationResult, PreviewSimulationError>>;
|
|
8
11
|
//#endregion
|
|
9
12
|
export { simulateOperation };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { SDKReturn } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
import { PoolOperation } from "../parse/types-pools.js";
|
|
2
4
|
import { PreviewOperationOptions } from "../types.js";
|
|
3
5
|
import "../parse/index.js";
|
|
6
|
+
import { PreviewSimulationError } from "./errors.js";
|
|
4
7
|
import { PoolOperationSimulationResult, SimulationInput } from "./types.js";
|
|
5
8
|
//#region src/preview/simulate/simulatePoolOperation.d.ts
|
|
6
9
|
/**
|
|
@@ -17,6 +20,6 @@ import { PoolOperationSimulationResult, SimulationInput } from "./types.js";
|
|
|
17
20
|
* It does not execute the calldata, so it ignores balance/allowance
|
|
18
21
|
* prerequisites (preview reads succeed regardless).
|
|
19
22
|
*/
|
|
20
|
-
declare function simulatePoolOperation(input: SimulationInput<PoolOperation>, options?: PreviewOperationOptions): Promise<PoolOperationSimulationResult
|
|
23
|
+
declare function simulatePoolOperation(input: SimulationInput<PoolOperation>, options?: PreviewOperationOptions): Promise<SDKReturn<PoolOperationSimulationResult, PreviewSimulationError>>;
|
|
21
24
|
//#endregion
|
|
22
25
|
export { simulatePoolOperation };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ChainId } from "../../model/primitives.js";
|
|
2
|
+
import { SDKResult } from "../../model/result.js";
|
|
2
3
|
import "../../model/index.js";
|
|
3
4
|
import { Asset } from "../../onchain/base/types.js";
|
|
4
5
|
import { SecuritizeRegisterMessage } from "../../onchain/market/rwa/securitize/types.js";
|
|
5
6
|
import { RawTx } from "../../onchain/types/transactions.js";
|
|
6
7
|
import "../../onchain/index.js";
|
|
7
|
-
import {
|
|
8
|
+
import { LpResult, OpenStrategyResult, StrategyResult } from "../prepare/types.js";
|
|
8
9
|
import "../prepare/index.js";
|
|
9
10
|
import { Address } from "viem";
|
|
10
11
|
//#region src/sdk/execute/types.d.ts
|
|
@@ -21,9 +22,7 @@ interface PoolPrepareRequest {
|
|
|
21
22
|
pool: Address;
|
|
22
23
|
wallet: Address;
|
|
23
24
|
op: "deposit" | "withdraw" | "redeem";
|
|
24
|
-
sim:
|
|
25
|
-
success: true;
|
|
26
|
-
}>;
|
|
25
|
+
sim: SDKResult<LpResult>;
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
29
28
|
* Opening a new position, from a viable
|
|
@@ -36,9 +35,7 @@ interface OpenPrepareRequest {
|
|
|
36
35
|
chainId: ChainId;
|
|
37
36
|
creditManager: Address;
|
|
38
37
|
wallet: Address;
|
|
39
|
-
sim:
|
|
40
|
-
success: true;
|
|
41
|
-
}>;
|
|
38
|
+
sim: SDKResult<OpenStrategyResult>;
|
|
42
39
|
/** What leaves the wallet, token by token. */
|
|
43
40
|
collateral: Asset[];
|
|
44
41
|
/** Native value to attach when paying a wrapped-native market in the coin. */
|
|
@@ -56,16 +53,14 @@ interface OpenPrepareRequest {
|
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
55
|
* Any of the five operations on an existing account, from a viable
|
|
59
|
-
* {@link
|
|
56
|
+
* {@link StrategyResult}: the facade multicall is the result's `calls`.
|
|
60
57
|
**/
|
|
61
58
|
interface AccountPrepareRequest {
|
|
62
59
|
kind: "account";
|
|
63
60
|
chainId: ChainId;
|
|
64
61
|
creditAccount: Address;
|
|
65
62
|
wallet: Address;
|
|
66
|
-
sim:
|
|
67
|
-
success: true;
|
|
68
|
-
}>;
|
|
63
|
+
sim: SDKResult<StrategyResult>;
|
|
69
64
|
}
|
|
70
65
|
/**
|
|
71
66
|
* What {@link IOpportunitiesExecute.buildTx} turns into a transaction: a
|
|
@@ -2,8 +2,8 @@ import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErr
|
|
|
2
2
|
import { LeverageBand } from "../onchain/accounts/intents/leverage-band.js";
|
|
3
3
|
import { OperationState, PathLossRate } from "../onchain/accounts/intents/types.js";
|
|
4
4
|
import { ILiquidations, ILiquidationsByMode } from "./liquidations/types.js";
|
|
5
|
-
import { CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError,
|
|
6
|
-
import { AddCollateralParams, AdjustLeverageParams,
|
|
5
|
+
import { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./prepare/errors.js";
|
|
6
|
+
import { AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
7
7
|
import { ChainOf, PrepareApi } from "./prepare/PrepareApi.js";
|
|
8
8
|
import "./prepare/index.js";
|
|
9
9
|
import { AccountPrepareRequest, IOpportunitiesExecute, OpenPrepareRequest, PoolPrepareRequest, PrepareRequest } from "./execute/types.js";
|
|
@@ -35,4 +35,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
|
|
|
35
35
|
import { assertSameChains } from "./errors/assertSameChains.js";
|
|
36
36
|
import { everyChainFailed } from "./errors/everyChainFailed.js";
|
|
37
37
|
import "./errors/index.js";
|
|
38
|
-
export { AbstractNamespace, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError,
|
|
38
|
+
export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, BorrowLimitBinding, ChainOf, ChainRef, CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DebtOutOfRangeError, DelayedStrategyResult, DepositStrategyParams, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, ForbiddenTokenError, GearboxSDK, GearboxSDKOptions, IGearboxSDK, ILiquidations, ILiquidationsByMode, INotices, INoticesByMode, IOpportunities, IOpportunitiesBase, IOpportunitiesByMode, IOpportunitiesExecute, IOpportunitiesOffchainBranch, IOpportunitiesOffchainOnly, IOpportunitiesOnchainBranch, IOpportunitiesOnchainOnly, IOpportunitiesPrepare, IOpportunityMergers, IPositionMergers, IPositions, IPositionsBase, IPositionsByMode, IPositionsOffchainBranch, IPositionsOffchainOnly, IPositionsOnchainBranch, IPositionsOnchainOnly, IPreview, IPreviewByMode, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, IntentPreviewError, type LeverageBand, LeverageOutOfRangeError, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpResult, MalformedTransactionError, MarketExpiredError, MarketPausedError, type MergeListResult, MergedQuery, MissingSourceError, Mode, MultipleDelayedWithdrawalsError, NamespaceOptions, NoDelayedRouteError, NoRecordedIntentError, NoSourceServedError, NoStrategyTargetCollateralError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenFlowError, OpenPrepareRequest, OpenStrategyParams, OpenStrategyResult, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PoolSunsetError, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewNamespace, PreviewRefusal, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, RepayStrategyParams, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyResult, StrategyRoutesResult, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawCollateralParams, WithdrawStrategyParams, WithdrawalInProgressError, assertSameChains, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Bps, ChainId } from "../../model/primitives.js";
|
|
2
2
|
import { PositionCollateral, StrategyPosition } from "../../model/positions.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SDKReturn } from "../../model/result.js";
|
|
4
4
|
import "../../model/index.js";
|
|
5
5
|
import { Asset } from "../../onchain/base/types.js";
|
|
6
6
|
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
7
7
|
import { MultichainSDK } from "../../onchain/MultichainSDK.js";
|
|
8
|
-
import {
|
|
8
|
+
import { MultichainConstruct } from "../../onchain/base/MultichainConstruct.js";
|
|
9
9
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
10
10
|
import "../../onchain/index.js";
|
|
11
|
-
import {
|
|
11
|
+
import { AccountFlowError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError } from "./errors.js";
|
|
12
|
+
import { AddCollateralParams, AdjustLeverageParams, DepositStrategyParams, FinalizeParams, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
12
13
|
import { EnsureFreshChains } from "../types.js";
|
|
13
14
|
import { Address } from "viem";
|
|
14
15
|
//#region src/sdk/prepare/PrepareApi.d.ts
|
|
@@ -28,72 +29,74 @@ type ChainOf = (chainId: ChainId) => OnchainSDK;
|
|
|
28
29
|
* protocol knowledge stays in `CreditAccountOperationsService` and
|
|
29
30
|
* `PoolService`.
|
|
30
31
|
*
|
|
31
|
-
* A prepared operation names one chain
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* A prepared operation names one chain and reads it directly: there is no
|
|
33
|
+
* second source to fall back to, so a chain the SDK does not cover, or one
|
|
34
|
+
* that fails the read, is a failure of the whole request rather than a thinner
|
|
35
|
+
* answer.
|
|
35
36
|
*
|
|
36
|
-
* No method here throws. Every way a preparation can
|
|
37
|
-
* refusals, the
|
|
38
|
-
* engine raises — comes back
|
|
39
|
-
*
|
|
37
|
+
* No refusable async method here throws. Every way such a preparation can
|
|
38
|
+
* fail — the market's own refusals, the ones the namespace decides itself, and
|
|
39
|
+
* anything the chain or the engine raises — comes back in the failure half of
|
|
40
|
+
* its `SDKReturn`, under the codes that method's signature names. A caller
|
|
41
|
+
* writes one branch, not a branch and a `try`. The synchronous LP methods and
|
|
42
|
+
* the bare `max*` reads throw on bugs and lifecycle errors instead, see
|
|
43
|
+
* {@link IOpportunitiesPrepare}.
|
|
40
44
|
**/
|
|
41
45
|
declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPrepare {
|
|
42
46
|
#private;
|
|
43
47
|
constructor(sdk: MultichainSDK, ensureFresh?: EnsureFreshChains);
|
|
44
|
-
protected queryChain<T>(props: ChainQueryOneProps<T>): Promise<DataResponse<T>>;
|
|
45
48
|
/**
|
|
46
49
|
* {@inheritDoc IOpportunitiesPrepare.finalize}
|
|
47
50
|
**/
|
|
48
|
-
finalize(position: PositionInput, params: FinalizeParams): Promise<
|
|
51
|
+
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<StrategyResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
|
|
49
52
|
/**
|
|
50
53
|
* {@inheritDoc IOpportunitiesPrepare.deposit}
|
|
51
54
|
**/
|
|
52
|
-
deposit(pool: PoolInput, params: LpParams):
|
|
55
|
+
deposit(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
53
56
|
/**
|
|
54
57
|
* {@inheritDoc IOpportunitiesPrepare.withdraw}
|
|
55
58
|
**/
|
|
56
|
-
withdraw(pool: PoolInput, params: LpParams):
|
|
59
|
+
withdraw(pool: PoolInput, params: LpParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
57
60
|
/**
|
|
58
61
|
* {@inheritDoc IOpportunitiesPrepare.redeem}
|
|
59
62
|
**/
|
|
60
|
-
redeem(pool: PoolInput, params: LpRedeemParams):
|
|
63
|
+
redeem(pool: PoolInput, params: LpRedeemParams): SDKReturn<LpResult, UnsupportedTokenPairError>;
|
|
61
64
|
/**
|
|
62
65
|
* {@inheritDoc IOpportunitiesPrepare.openNewStrategy}
|
|
63
66
|
**/
|
|
64
|
-
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<
|
|
67
|
+
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError>>;
|
|
65
68
|
/**
|
|
66
69
|
* {@inheritDoc IOpportunitiesPrepare.depositStrategy}
|
|
67
70
|
**/
|
|
68
|
-
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<
|
|
71
|
+
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | InsufficientPoolLiquidityError>>;
|
|
69
72
|
/**
|
|
70
73
|
* {@inheritDoc IOpportunitiesPrepare.withdrawStrategy}
|
|
71
74
|
**/
|
|
72
|
-
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<
|
|
75
|
+
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteRefusals>>;
|
|
73
76
|
/**
|
|
74
77
|
* {@inheritDoc IOpportunitiesPrepare.maxWithdraw}
|
|
75
78
|
**/
|
|
76
|
-
maxWithdraw(position: PositionInput): Promise<
|
|
79
|
+
maxWithdraw(position: PositionInput): Promise<bigint>;
|
|
77
80
|
/**
|
|
78
81
|
* {@inheritDoc IOpportunitiesPrepare.repayStrategy}
|
|
79
82
|
**/
|
|
80
|
-
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<
|
|
83
|
+
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<SDKReturn<StrategyResult, AccountFlowError | DebtOutOfRangeError | UnsupportedCollateralTokenError>>;
|
|
81
84
|
/**
|
|
82
85
|
* {@inheritDoc IOpportunitiesPrepare.maxRepay}
|
|
83
86
|
**/
|
|
84
|
-
maxRepay(position: PositionInput): Promise<
|
|
87
|
+
maxRepay(position: PositionInput): Promise<bigint>;
|
|
85
88
|
/**
|
|
86
89
|
* {@inheritDoc IOpportunitiesPrepare.adjustLeverage}
|
|
87
90
|
**/
|
|
88
|
-
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<
|
|
91
|
+
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError | InsufficientPoolLiquidityError | LeverageOutOfRangeError) & WithRouteRefusals>>;
|
|
89
92
|
/**
|
|
90
93
|
* {@inheritDoc IOpportunitiesPrepare.addCollateral}
|
|
91
94
|
**/
|
|
92
|
-
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<
|
|
95
|
+
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
93
96
|
/**
|
|
94
97
|
* {@inheritDoc IOpportunitiesPrepare.withdrawCollateral}
|
|
95
98
|
**/
|
|
96
|
-
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<
|
|
99
|
+
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError>>;
|
|
97
100
|
/**
|
|
98
101
|
* {@inheritDoc IOpportunitiesPrepare.leverageBand}
|
|
99
102
|
**/
|
|
@@ -105,7 +108,7 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
|
|
|
105
108
|
/**
|
|
106
109
|
* {@inheritDoc IOpportunitiesPrepare.maxWithdrawCollateral}
|
|
107
110
|
**/
|
|
108
|
-
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<
|
|
111
|
+
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<bigint>;
|
|
109
112
|
}
|
|
110
113
|
//#endregion
|
|
111
114
|
export { ChainOf, PrepareApi };
|
|
@@ -18,13 +18,20 @@ import { Address } from "viem";
|
|
|
18
18
|
* `prepare` and `preview` refusing in one vocabulary; what differs is where the
|
|
19
19
|
* numbers sit. The engine keeps them one level down, in `detail`, because it
|
|
20
20
|
* distributes them over `reason`; here they are stated outright, so it is
|
|
21
|
-
* `error.maxDebt` rather than `error.detail.maxDebt`.
|
|
22
|
-
* namespace's own, raised before or around the engine.
|
|
21
|
+
* `error.maxDebt` rather than `error.detail.maxDebt`.
|
|
23
22
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* There is deliberately no union of all of them: each `prepare` method names
|
|
24
|
+
* exactly the codes its own flow can raise, see the signatures in
|
|
25
|
+
* {@link IOpportunitiesPrepare}. What is shared is the plumbing every flow
|
|
26
|
+
* goes through, and that is the two base unions below.
|
|
26
27
|
**/
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* What ANY operation on an existing account can refuse with: the engine's
|
|
30
|
+
* shared guards, the missing account, and a wrapped crash.
|
|
31
|
+
**/
|
|
32
|
+
type AccountFlowError = MarketPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientSourceBalanceError | CreditAccountNotFoundError | UnexpectedFailureError;
|
|
33
|
+
/** Same guards for the account-less open flow. */
|
|
34
|
+
type OpenFlowError = MarketPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientSourceBalanceError | UnexpectedFailureError;
|
|
28
35
|
/** The debt the request implies falls outside the facade's band. */
|
|
29
36
|
interface DebtOutOfRangeError extends IGearboxError {
|
|
30
37
|
code: "debtOutOfRange";
|
|
@@ -101,15 +108,15 @@ interface WithdrawalInProgressError extends IGearboxError {
|
|
|
101
108
|
interface NoRecordedIntentError extends IGearboxError {
|
|
102
109
|
code: "noRecordedIntent";
|
|
103
110
|
}
|
|
104
|
-
/** The facade
|
|
111
|
+
/** The facade is paused: nothing can be done at all. */
|
|
105
112
|
interface MarketPausedError extends IGearboxError {
|
|
106
113
|
code: "marketPaused";
|
|
107
114
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
115
|
+
* The paused credit manager. Always present from `prepare`: the engine's
|
|
116
|
+
* shared guards check the manager, and the pool-paused variant is raised
|
|
117
|
+
* only by the preview-side `checkOperation` — it never reaches this union.
|
|
110
118
|
**/
|
|
111
|
-
creditManager
|
|
112
|
-
pool?: Address;
|
|
119
|
+
creditManager: Address;
|
|
113
120
|
}
|
|
114
121
|
/** The facade is past its expiration date and takes no more multicalls. */
|
|
115
122
|
interface MarketExpiredError extends IGearboxError {
|
|
@@ -228,11 +235,10 @@ interface CreditAccountNotFoundError extends IGearboxError {
|
|
|
228
235
|
* connected to, a market or token address it knows nothing about, a contract
|
|
229
236
|
* that reverted where nothing should, a bug of ours.
|
|
230
237
|
*
|
|
231
|
-
* The one code that is not a
|
|
238
|
+
* The one code that is not a refusal of the request — everything above says
|
|
232
239
|
* "this cannot be done", this one says "we do not know". It exists so that a
|
|
233
|
-
* `prepare` method always answers: the failure that used to escape
|
|
234
|
-
* exception arrives here instead, whole, under `cause`.
|
|
235
|
-
* chain as failed alongside it.
|
|
240
|
+
* refusable `prepare` method always answers: the failure that used to escape
|
|
241
|
+
* as an exception arrives here instead, whole, under `cause`.
|
|
236
242
|
**/
|
|
237
243
|
interface UnexpectedFailureError extends IGearboxError {
|
|
238
244
|
code: "unexpectedFailure";
|
|
@@ -240,17 +246,45 @@ interface UnexpectedFailureError extends IGearboxError {
|
|
|
240
246
|
cause: Error;
|
|
241
247
|
}
|
|
242
248
|
/**
|
|
243
|
-
*
|
|
244
|
-
* {@link
|
|
249
|
+
* What every refusal of a two-route request carries on top of its own code,
|
|
250
|
+
* see {@link StrategyRoutesResult}.
|
|
245
251
|
*
|
|
246
252
|
* `refused` says why each route is missing, which is the answer a form needs
|
|
247
253
|
* even when neither exists: the error itself is the instant route's refusal —
|
|
248
254
|
* the one a caller can usually act on — or the delayed route's when the instant
|
|
249
255
|
* one did not get far enough to have a reason of its own.
|
|
250
256
|
**/
|
|
251
|
-
|
|
257
|
+
interface WithRouteRefusals {
|
|
252
258
|
refused: RouteRefusals;
|
|
253
|
-
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The error each engine reason maps to — the range of {@link toRefusalError},
|
|
262
|
+
* spelled reason by reason so a narrow issue arrives as a narrow error.
|
|
263
|
+
*
|
|
264
|
+
* A lookup table, not a vocabulary: nothing answers with `RefusalErrors[R]`
|
|
265
|
+
* as a union. The unions callers see are the ones each method's signature
|
|
266
|
+
* spells out.
|
|
267
|
+
**/
|
|
268
|
+
interface RefusalErrors {
|
|
269
|
+
debtOutOfRange: DebtOutOfRangeError;
|
|
270
|
+
leverageOutOfRange: LeverageOutOfRangeError;
|
|
271
|
+
insufficientSourceBalance: InsufficientSourceBalanceError;
|
|
272
|
+
unsupportedCollateralToken: UnsupportedCollateralTokenError;
|
|
273
|
+
unsupportedTokenPair: UnsupportedTokenPairError;
|
|
274
|
+
noDelayedRoute: NoDelayedRouteError;
|
|
275
|
+
multipleDelayedWithdrawals: MultipleDelayedWithdrawalsError;
|
|
276
|
+
withdrawalInProgress: WithdrawalInProgressError;
|
|
277
|
+
noRecordedIntent: NoRecordedIntentError;
|
|
278
|
+
marketPaused: MarketPausedError;
|
|
279
|
+
marketExpired: MarketExpiredError;
|
|
280
|
+
insufficientPoolLiquidity: InsufficientPoolLiquidityError;
|
|
281
|
+
quotaLimitReached: QuotaLimitReachedError;
|
|
282
|
+
forbiddenToken: ForbiddenTokenError;
|
|
283
|
+
insufficientCollateral: InsufficientCollateralError;
|
|
284
|
+
poolSunset: PoolSunsetError;
|
|
285
|
+
quotaCountExceeded: QuotaCountExceededError;
|
|
286
|
+
malformedTransaction: MalformedTransactionError;
|
|
287
|
+
}
|
|
254
288
|
/**
|
|
255
289
|
* The engine's refusal, as the error the namespace answers with.
|
|
256
290
|
*
|
|
@@ -259,8 +293,11 @@ type RoutesPrepareError = PrepareError & {
|
|
|
259
293
|
* {@link MESSAGES}. A malformed transaction is spelled out rather than spread,
|
|
260
294
|
* because its detail names a `code` and a `message` of its own and they are not
|
|
261
295
|
* the envelope's.
|
|
296
|
+
*
|
|
297
|
+
* Generic over the issue it is handed, so a call site that already knows the
|
|
298
|
+
* reason gets that reason's error back rather than a union to narrow again.
|
|
262
299
|
**/
|
|
263
|
-
declare function
|
|
300
|
+
declare function toRefusalError<I extends PreviewIssue>(issue: I): RefusalErrors[I["reason"]];
|
|
264
301
|
/**
|
|
265
302
|
* {@inheritDoc NoStrategyTargetCollateralError}
|
|
266
303
|
**/
|
|
@@ -277,4 +314,4 @@ declare function creditAccountNotFound(creditAccount: Address): CreditAccountNot
|
|
|
277
314
|
**/
|
|
278
315
|
declare function unexpectedFailure(thrown: unknown): UnexpectedFailureError;
|
|
279
316
|
//#endregion
|
|
280
|
-
export { CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError,
|
|
317
|
+
export { AccountFlowError, CreditAccountNotFoundError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientCollateralError, InsufficientPoolLiquidityError, InsufficientSourceBalanceError, LeverageOutOfRangeError, MalformedTransactionError, MarketExpiredError, MarketPausedError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, OpenFlowError, PoolSunsetError, QuotaCountExceededError, QuotaLimitReachedError, RefusalErrors, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithRouteRefusals, WithdrawalInProgressError, creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure };
|