@gearbox-protocol/sdk 16.0.0-next.41 → 16.0.0-next.43
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/errors.js +1 -0
- package/dist/cjs/model/index.js +5 -0
- package/dist/cjs/model/result.js +27 -0
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +1 -1
- package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +14 -14
- package/dist/cjs/onchain/index.js +0 -1
- package/dist/cjs/onchain/market/zapper/errors.js +13 -12
- package/dist/cjs/onchain/validation/index.js +0 -1
- package/dist/cjs/preview/index.js +4 -1
- package/dist/cjs/preview/parse/errors.js +25 -22
- package/dist/cjs/preview/preview/errors.js +12 -11
- package/dist/cjs/preview/preview/previewOperation.js +41 -10
- package/dist/cjs/preview/simulate/errors.js +18 -17
- package/dist/cjs/sdk/execute/ExecuteApi.js +3 -3
- package/dist/cjs/sdk/index.js +5 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +254 -101
- package/dist/cjs/sdk/prepare/errors.js +93 -0
- package/dist/cjs/sdk/prepare/index.js +5 -0
- package/dist/esm/model/errors.js +1 -0
- package/dist/esm/model/index.js +3 -1
- package/dist/esm/model/result.js +24 -0
- package/dist/esm/onchain/accounts/intents/open-strategy.js +1 -1
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +14 -14
- package/dist/esm/onchain/index.js +2 -2
- package/dist/esm/onchain/market/zapper/errors.js +13 -12
- package/dist/esm/onchain/validation/index.js +2 -2
- package/dist/esm/preview/index.js +4 -2
- package/dist/esm/preview/parse/errors.js +25 -22
- package/dist/esm/preview/preview/errors.js +12 -11
- package/dist/esm/preview/preview/previewOperation.js +41 -10
- package/dist/esm/preview/simulate/errors.js +18 -17
- package/dist/esm/sdk/execute/ExecuteApi.js +3 -3
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/prepare/PrepareApi.js +255 -102
- package/dist/esm/sdk/prepare/errors.js +89 -0
- package/dist/esm/sdk/prepare/index.js +2 -1
- package/dist/types/model/errors.d.ts +46 -0
- package/dist/types/model/index.d.ts +3 -1
- package/dist/types/model/result.d.ts +48 -0
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/types.d.ts +13 -14
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +18 -5
- package/dist/types/onchain/index.d.ts +2 -2
- package/dist/types/onchain/market/zapper/errors.d.ts +20 -6
- 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 +36 -11
- package/dist/types/preview/preview/errors.d.ts +17 -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/simulate/errors.d.ts +21 -8
- package/dist/types/sdk/execute/types.d.ts +9 -14
- package/dist/types/sdk/index.d.ts +3 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +30 -22
- package/dist/types/sdk/prepare/errors.d.ts +317 -0
- package/dist/types/sdk/prepare/index.d.ts +3 -2
- package/dist/types/sdk/prepare/types.d.ts +88 -62
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +4 -1
- package/dist/types/sdk/preview/types.d.ts +7 -3
- package/package.json +11 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const require_model_charts_schema = require("./charts.schema.js");
|
|
|
6
6
|
require("./curators.js");
|
|
7
7
|
const require_model_curators_schema = require("./curators.schema.js");
|
|
8
8
|
require("./delayed-intents.js");
|
|
9
|
+
require("./errors.js");
|
|
9
10
|
const require_model_filters = require("./filters.js");
|
|
10
11
|
const require_model_filters_schema = require("./filters.schema.js");
|
|
11
12
|
const require_model_liquidations = require("./liquidations.js");
|
|
@@ -20,6 +21,7 @@ const require_model_previews = require("./previews.js");
|
|
|
20
21
|
require("./primitives.js");
|
|
21
22
|
require("./response.js");
|
|
22
23
|
const require_model_response_schema = require("./response.schema.js");
|
|
24
|
+
const require_model_result = require("./result.js");
|
|
23
25
|
require("./withdrawals.js");
|
|
24
26
|
const require_model_withdrawals_schema = require("./withdrawals.schema.js");
|
|
25
27
|
exports.CHART_METRIC_UNITS = require_model_charts.CHART_METRIC_UNITS;
|
|
@@ -70,6 +72,7 @@ exports.filterAllSchema = require_model_filters_schema.filterAllSchema;
|
|
|
70
72
|
exports.filterable = require_model_filters_schema.filterable;
|
|
71
73
|
exports.instantReceivedAssetSchema = require_model_liquidations_schema.instantReceivedAssetSchema;
|
|
72
74
|
exports.isFilterSet = require_model_filters.isFilterSet;
|
|
75
|
+
exports.isSDKError = require_model_result.isSDKError;
|
|
73
76
|
exports.leverageSchema = require_model_primitives_schema.leverageSchema;
|
|
74
77
|
exports.liquidatableAccountFilterSchema = require_model_liquidations_schema.liquidatableAccountFilterSchema;
|
|
75
78
|
exports.liquidatableAccountSchema = require_model_liquidations_schema.liquidatableAccountSchema;
|
|
@@ -132,6 +135,8 @@ exports.responseMetadataSchema = require_model_response_schema.responseMetadataS
|
|
|
132
135
|
exports.responseSchema = require_model_response_schema.responseSchema;
|
|
133
136
|
exports.rewardsPnLSchema = require_model_positions_schema.rewardsPnLSchema;
|
|
134
137
|
exports.rewardsSchema = require_model_opportunities_schema.rewardsSchema;
|
|
138
|
+
exports.sdkErr = require_model_result.sdkErr;
|
|
139
|
+
exports.sdkOk = require_model_result.sdkOk;
|
|
135
140
|
exports.strategyOpportunityChartMetricSchema = require_model_charts_schema.strategyOpportunityChartMetricSchema;
|
|
136
141
|
exports.strategyOpportunityDetailSchema = require_model_opportunities_schema.strategyOpportunityDetailSchema;
|
|
137
142
|
exports.strategyOpportunityId = require_model_opportunities.strategyOpportunityId;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/model/result.ts
|
|
3
|
+
/** The success half, built. */
|
|
4
|
+
function sdkOk(data) {
|
|
5
|
+
return {
|
|
6
|
+
ok: true,
|
|
7
|
+
data
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** The failure half, built. */
|
|
11
|
+
function sdkErr(error) {
|
|
12
|
+
return {
|
|
13
|
+
ok: false,
|
|
14
|
+
error
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Narrows a {@link SDKReturn} to its failure half. Trivial over `ok`, but it
|
|
19
|
+
* names the intent at call sites that would otherwise read `!r.ok`.
|
|
20
|
+
**/
|
|
21
|
+
function isSDKError(answer) {
|
|
22
|
+
return !answer.ok;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.isSDKError = isSDKError;
|
|
26
|
+
exports.sdkErr = sdkErr;
|
|
27
|
+
exports.sdkOk = sdkOk;
|
|
@@ -11,7 +11,7 @@ require("./utils/index.js");
|
|
|
11
11
|
const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
12
12
|
/**
|
|
13
13
|
* Builds the state opening a leveraged position out of wallet collateral would
|
|
14
|
-
*
|
|
14
|
+
* reach.
|
|
15
15
|
*
|
|
16
16
|
* Debt follows from the target leverage against the supplied margin
|
|
17
17
|
* (`debt = margin * (L - 1)`, `totalValue = margin * L`); the collateral and the
|
|
@@ -54,7 +54,7 @@ async function projectTail(args) {
|
|
|
54
54
|
const { request, delayed, creditAccount, sdk, quotaReserve } = args;
|
|
55
55
|
const { claim } = delayed;
|
|
56
56
|
const queued = request.outputs.find((o) => o.isDelayed);
|
|
57
|
-
if (!queued || !claim) throw new
|
|
57
|
+
if (!queued || !claim) throw new require_onchain_validation_refusal.IntentPreviewError("noRecordedIntent", void 0, "projectTail: the request queued nothing to claim");
|
|
58
58
|
const next = sliceAfter(creditAccount, delayed.afterRequest);
|
|
59
59
|
const steps = planTail({
|
|
60
60
|
intent: delayed.record,
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/onchain/accounts/withdrawal-compressor/errors.ts
|
|
3
|
+
function invalidDelayedIntent(extraData, cause) {
|
|
4
|
+
const verdict = {
|
|
5
|
+
code: "invalidDelayedIntent",
|
|
6
|
+
message: `cannot decode delayed intent from extraData ${extraData}`,
|
|
7
|
+
extraData
|
|
8
|
+
};
|
|
9
|
+
if (cause !== void 0) verdict.cause = cause instanceof Error ? cause : new Error(String(cause));
|
|
10
|
+
return verdict;
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(invalidDelayedIntent, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "invalidDelayedIntent" });
|
|
3
13
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* here means a malformed/foreign transaction that must not be previewed as
|
|
8
|
-
* if it were fine.
|
|
14
|
+
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
15
|
+
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
16
|
+
* the answer is never an `Error`.
|
|
9
17
|
*/
|
|
10
|
-
|
|
11
|
-
/** Raw `extraData` that failed to decode. */
|
|
12
|
-
extraData;
|
|
13
|
-
constructor(extraData, cause) {
|
|
14
|
-
super(`cannot decode delayed intent from extraData ${extraData}`, { cause });
|
|
15
|
-
this.name = "InvalidDelayedIntentError";
|
|
16
|
-
this.extraData = extraData;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
18
|
+
const InvalidDelayedIntentError = invalidDelayedIntent;
|
|
19
19
|
//#endregion
|
|
20
20
|
exports.InvalidDelayedIntentError = InvalidDelayedIntentError;
|
|
@@ -346,7 +346,6 @@ exports.IERC20ZapperContract = require_onchain_market_zapper_IERC20ZapperContrac
|
|
|
346
346
|
exports.IETHZapperContract = require_onchain_market_zapper_IETHZapperContract.IETHZapperContract;
|
|
347
347
|
exports.InfinifiGatewayAdapterContract = require_onchain_market_adapters_contracts_InfinifiGatewayAdapterContract.InfinifiGatewayAdapterContract;
|
|
348
348
|
exports.InfinifiUnwindingGatewayAdapterContract = require_onchain_market_adapters_contracts_InfinifiUnwindingGatewayAdapterContract.InfinifiUnwindingGatewayAdapterContract;
|
|
349
|
-
exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
|
|
350
349
|
exports.InvalidDelayedIntentError = require_onchain_accounts_withdrawal_compressor_errors.InvalidDelayedIntentError;
|
|
351
350
|
exports.KelpLRTDepositPoolAdapterContract = require_onchain_market_adapters_contracts_KelpLRTDepositPoolAdapterContract.KelpLRTDepositPoolAdapterContract;
|
|
352
351
|
exports.KelpLRTWithdrawalManagerAdapterContract = require_onchain_market_adapters_contracts_KelpLRTWithdrawalManagerAdapterContract.KelpLRTWithdrawalManagerAdapterContract;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/onchain/market/zapper/errors.ts
|
|
3
|
+
function unsupportedZapperFunction(zapper, functionName) {
|
|
4
|
+
return {
|
|
5
|
+
code: "unsupportedZapperFunction",
|
|
6
|
+
message: `unsupported zapper function "${functionName}" on ${zapper}`,
|
|
7
|
+
zapper,
|
|
8
|
+
functionName
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(unsupportedZapperFunction, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedZapperFunction" });
|
|
3
12
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
13
|
+
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
14
|
+
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
15
|
+
* the answer is never an `Error`.
|
|
6
16
|
*/
|
|
7
|
-
|
|
8
|
-
zapper;
|
|
9
|
-
functionName;
|
|
10
|
-
constructor(zapper, functionName) {
|
|
11
|
-
super(`unsupported zapper function "${functionName}" on ${zapper}`);
|
|
12
|
-
this.name = "UnsupportedZapperFunctionError";
|
|
13
|
-
this.zapper = zapper;
|
|
14
|
-
this.functionName = functionName;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
+
const UnsupportedZapperFunctionError = unsupportedZapperFunction;
|
|
17
18
|
//#endregion
|
|
18
19
|
exports.UnsupportedZapperFunctionError = UnsupportedZapperFunctionError;
|
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_onchain_validation_checks = require("./checks.js");
|
|
3
3
|
const require_onchain_validation_refusal = require("./refusal.js");
|
|
4
4
|
const require_onchain_validation_token = require("./token.js");
|
|
5
|
-
exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
|
|
6
5
|
exports.MIN_HEALTH_FACTOR_FACADE = require_onchain_validation_checks.MIN_HEALTH_FACTOR_FACADE;
|
|
7
6
|
exports.MIN_HEALTH_FACTOR_FORM = require_onchain_validation_checks.MIN_HEALTH_FACTOR_FORM;
|
|
8
7
|
exports.MIN_HF_LIMITED = require_onchain_validation_checks.MIN_HF_LIMITED;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_market_zapper_errors = require("../onchain/market/zapper/errors.js");
|
|
3
3
|
const require_onchain_validation_refusal = require("../onchain/validation/refusal.js");
|
|
4
|
+
const require_onchain_accounts_withdrawal_compressor_errors = require("../onchain/accounts/withdrawal-compressor/errors.js");
|
|
4
5
|
const require_preview_trace_errors = require("./trace/errors.js");
|
|
5
6
|
const require_preview_trace_extractAdapterCallTraces = require("./trace/extractAdapterCallTraces.js");
|
|
6
7
|
const require_preview_trace_extractTransfers = require("./trace/extractTransfers.js");
|
|
@@ -31,6 +32,7 @@ const require_preview_preview_replayInnerOperations = require("./preview/replayI
|
|
|
31
32
|
const require_preview_preview_replayMulticall = require("./preview/replayMulticall.js");
|
|
32
33
|
const require_preview_preview_previewAdjustStrategyPosition = require("./preview/previewAdjustStrategyPosition.js");
|
|
33
34
|
const require_preview_preview_previewExitOrRepayStrategyPosition = require("./preview/previewExitOrRepayStrategyPosition.js");
|
|
35
|
+
const require_preview_simulate_errors = require("./simulate/errors.js");
|
|
34
36
|
const require_preview_preview_previewOperation = require("./preview/previewOperation.js");
|
|
35
37
|
require("./preview/index.js");
|
|
36
38
|
require("./types.js");
|
|
@@ -40,8 +42,9 @@ require("./validate/index.js");
|
|
|
40
42
|
exports.AllowancePrerequisite = require_preview_prerequisites_AllowancePrerequisite.AllowancePrerequisite;
|
|
41
43
|
exports.BalancePrerequisite = require_preview_prerequisites_BalancePrerequisite.BalancePrerequisite;
|
|
42
44
|
exports.CreditAccountState = require_preview_preview_CreditAccountState.CreditAccountState;
|
|
43
|
-
exports.
|
|
45
|
+
exports.InvalidDelayedIntentError = require_onchain_accounts_withdrawal_compressor_errors.InvalidDelayedIntentError;
|
|
44
46
|
exports.Prerequisite = require_preview_prerequisites_Prerequisite.Prerequisite;
|
|
47
|
+
exports.PreviewSimulationError = require_preview_simulate_errors.PreviewSimulationError;
|
|
45
48
|
exports.RWAOpenRequirementsPrerequisite = require_preview_prerequisites_RWAOpenRequirementsPrerequisite.RWAOpenRequirementsPrerequisite;
|
|
46
49
|
exports.TransferAlignmentError = require_preview_trace_errors.TransferAlignmentError;
|
|
47
50
|
exports.UnexpectedFacadeEventOrderError = require_preview_trace_errors.UnexpectedFacadeEventOrderError;
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_market_zapper_errors = require("../../onchain/market/zapper/errors.js");
|
|
3
|
-
require("../../onchain/index.js");
|
|
4
3
|
//#region src/preview/parse/errors.ts
|
|
4
|
+
function unsupportedTarget(target) {
|
|
5
|
+
return {
|
|
6
|
+
code: "unsupportedTarget",
|
|
7
|
+
message: `unsupported transaction target: ${target}`,
|
|
8
|
+
target
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(unsupportedTarget, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedTarget" });
|
|
5
12
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
13
|
+
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
14
|
+
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
15
|
+
* the answer is never an `Error`.
|
|
8
16
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
+
const UnsupportedTargetError = unsupportedTarget;
|
|
18
|
+
function unsupportedPoolFunction(pool, functionName) {
|
|
19
|
+
return {
|
|
20
|
+
code: "unsupportedPoolFunction",
|
|
21
|
+
message: `unsupported pool function "${functionName}" on ${pool}`,
|
|
22
|
+
pool,
|
|
23
|
+
functionName
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(unsupportedPoolFunction, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedPoolFunction" });
|
|
17
27
|
/**
|
|
18
|
-
*
|
|
28
|
+
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
29
|
+
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
30
|
+
* the answer is never an `Error`.
|
|
19
31
|
*/
|
|
20
|
-
|
|
21
|
-
pool;
|
|
22
|
-
functionName;
|
|
23
|
-
constructor(pool, functionName) {
|
|
24
|
-
super(`unsupported pool function "${functionName}" on ${pool}`);
|
|
25
|
-
this.name = "UnsupportedPoolFunctionError";
|
|
26
|
-
this.pool = pool;
|
|
27
|
-
this.functionName = functionName;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
32
|
+
const UnsupportedPoolFunctionError = unsupportedPoolFunction;
|
|
30
33
|
//#endregion
|
|
31
34
|
exports.UnsupportedPoolFunctionError = UnsupportedPoolFunctionError;
|
|
32
35
|
exports.UnsupportedTargetError = UnsupportedTargetError;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/preview/preview/errors.ts
|
|
3
|
+
function unsupportedOperation(operation) {
|
|
4
|
+
return {
|
|
5
|
+
code: "unsupportedOperation",
|
|
6
|
+
message: `operation "${operation}" is not supported by previewOperation`,
|
|
7
|
+
operation
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(unsupportedOperation, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedOperation" });
|
|
3
11
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
12
|
+
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
13
|
+
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
14
|
+
* the answer is never an `Error`.
|
|
6
15
|
*/
|
|
7
|
-
|
|
8
|
-
/** The parsed operation kind (the `operation` discriminant). */
|
|
9
|
-
operation;
|
|
10
|
-
constructor(operation) {
|
|
11
|
-
super(`operation "${operation}" is not supported by previewOperation`);
|
|
12
|
-
this.name = "UnsupportedOperationError";
|
|
13
|
-
this.operation = operation;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
+
const UnsupportedOperationError = unsupportedOperation;
|
|
16
17
|
//#endregion
|
|
17
18
|
exports.UnsupportedOperationError = UnsupportedOperationError;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_result = require("../../model/result.js");
|
|
3
|
+
require("../../model/index.js");
|
|
4
|
+
const require_onchain_market_zapper_errors = require("../../onchain/market/zapper/errors.js");
|
|
5
|
+
const require_onchain_accounts_withdrawal_compressor_errors = require("../../onchain/accounts/withdrawal-compressor/errors.js");
|
|
6
|
+
require("../../onchain/index.js");
|
|
7
|
+
const require_preview_parse_errors = require("../parse/errors.js");
|
|
2
8
|
const require_preview_parse_parseOperationCalldata = require("../parse/parseOperationCalldata.js");
|
|
3
9
|
const require_preview_parse_types = require("../parse/types.js");
|
|
4
10
|
require("../parse/index.js");
|
|
@@ -11,25 +17,50 @@ const require_preview_preview_estimateClaimableAt = require("./estimateClaimable
|
|
|
11
17
|
const require_preview_preview_replayMulticall = require("./replayMulticall.js");
|
|
12
18
|
const require_preview_preview_previewAdjustStrategyPosition = require("./previewAdjustStrategyPosition.js");
|
|
13
19
|
const require_preview_preview_previewExitOrRepayStrategyPosition = require("./previewExitOrRepayStrategyPosition.js");
|
|
20
|
+
const require_preview_simulate_errors = require("../simulate/errors.js");
|
|
14
21
|
const require_preview_preview_previewOpenStrategyPosition = require("./previewOpenStrategyPosition.js");
|
|
15
22
|
const require_preview_preview_previewPoolPositionOperation = require("./previewPoolPositionOperation.js");
|
|
16
23
|
//#region src/preview/preview/previewOperation.ts
|
|
17
24
|
/**
|
|
25
|
+
* Narrows a raised value to the verdict vocabulary: a plain non-`Error`
|
|
26
|
+
* object whose `code` is one of the preview verdicts. Genuine exceptions —
|
|
27
|
+
* bugs, outages, calldata the parser cannot read at all — fail the check and
|
|
28
|
+
* keep propagating as throws.
|
|
29
|
+
*/
|
|
30
|
+
function isPreviewVerdict(raised) {
|
|
31
|
+
if (typeof raised !== "object" || raised === null || raised instanceof Error) return false;
|
|
32
|
+
return raised instanceof require_preview_parse_errors.UnsupportedTargetError || raised instanceof require_preview_parse_errors.UnsupportedPoolFunctionError || raised instanceof require_onchain_market_zapper_errors.UnsupportedZapperFunctionError || raised instanceof require_preview_preview_errors.UnsupportedOperationError || raised instanceof require_onchain_accounts_withdrawal_compressor_errors.InvalidDelayedIntentError || raised instanceof require_preview_simulate_errors.PreviewSimulationError;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
18
35
|
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
19
36
|
* assembles an operation-specific, human-displayable preview.
|
|
37
|
+
*
|
|
38
|
+
* Answers an {@link SDKReturn} envelope: the preview behind `ok: true`, or —
|
|
39
|
+
* when the transaction is one the previewer refuses to read — a
|
|
40
|
+
* {@link PreviewVerdictError} behind `ok: false`. A thrown exception still
|
|
41
|
+
* means the SDK could not do its job (a read failed, the targeted credit
|
|
42
|
+
* account could not be resolved), not a verdict on the transaction.
|
|
20
43
|
*/
|
|
21
44
|
async function previewOperation(input, options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
try {
|
|
46
|
+
const operation = require_preview_parse_parseOperationCalldata.parseOperationCalldata(input);
|
|
47
|
+
if (require_preview_parse_types.isPoolOperation(operation)) return require_model_result.sdkOk(await require_preview_preview_previewPoolPositionOperation.previewPoolPositionOperation(input, operation, options));
|
|
48
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return require_model_result.sdkOk(await require_preview_preview_previewOpenStrategyPosition.previewOpenStrategyPosition(input, operation));
|
|
49
|
+
if (operation.operation === "CloseCreditAccount") {
|
|
50
|
+
const resolved = await resolveCreditAccount(input, operation, options);
|
|
51
|
+
const preview = require_preview_preview_previewExitOrRepayStrategyPosition.previewExitOrRepayStrategyPosition(input, operation, true, resolved);
|
|
52
|
+
preview.intent = await require_preview_preview_detectDelayedClaim.resolveDelayedClaimIntent(input.sdk, operation.multicall, options?.blockNumber);
|
|
53
|
+
return require_model_result.sdkOk(preview);
|
|
54
|
+
}
|
|
55
|
+
if (operation.operation === "MultiCall" || operation.operation === "BotMulticall" || operation.operation === "RWAMulticall") {
|
|
56
|
+
const resolved = await resolveCreditAccount(input, operation, options);
|
|
57
|
+
return require_model_result.sdkOk(await previewMulticallOperation(input, operation, resolved));
|
|
58
|
+
}
|
|
59
|
+
return require_model_result.sdkErr(require_preview_preview_errors.UnsupportedOperationError(operation.operation));
|
|
60
|
+
} catch (raised) {
|
|
61
|
+
if (isPreviewVerdict(raised)) return require_model_result.sdkErr(raised);
|
|
62
|
+
throw raised;
|
|
30
63
|
}
|
|
31
|
-
if (operation.operation === "MultiCall" || operation.operation === "BotMulticall" || operation.operation === "RWAMulticall") return previewMulticallOperation(input, operation, await resolveCreditAccount(input, operation, options));
|
|
32
|
-
throw new require_preview_preview_errors.UnsupportedOperationError(operation.operation);
|
|
33
64
|
}
|
|
34
65
|
/**
|
|
35
66
|
* Resolves the pre-state of the credit account an operation targets: uses the
|
|
@@ -2,33 +2,34 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_abi_errors = require("../../abi/errors.js");
|
|
3
3
|
let viem = require("viem");
|
|
4
4
|
//#region src/preview/simulate/errors.ts
|
|
5
|
+
function previewSimulationFailed(failures) {
|
|
6
|
+
const message = failures.length <= 1 ? failures[0]?.detail.reason ?? "simulation failed" : "all simulation flows failed";
|
|
7
|
+
const cause = failures.find((f) => f.detail.cause instanceof Error)?.detail.cause;
|
|
8
|
+
const verdict = {
|
|
9
|
+
code: "previewSimulationFailed",
|
|
10
|
+
message,
|
|
11
|
+
failures
|
|
12
|
+
};
|
|
13
|
+
if (cause) verdict.cause = cause;
|
|
14
|
+
return verdict;
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(previewSimulationFailed, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "previewSimulationFailed" });
|
|
5
17
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
18
|
+
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
19
|
+
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
20
|
+
* the answer is never an `Error`.
|
|
8
21
|
*/
|
|
9
|
-
|
|
10
|
-
name = "PreviewSimulationError";
|
|
11
|
-
/** Per-flow decoded failures behind this error. */
|
|
12
|
-
failures;
|
|
13
|
-
constructor(failures) {
|
|
14
|
-
const shortMessage = failures.length <= 1 ? failures[0]?.detail.reason ?? "simulation failed" : "all simulation flows failed";
|
|
15
|
-
const cause = failures.find((f) => f.detail.cause instanceof Error)?.detail.cause;
|
|
16
|
-
super(shortMessage, {
|
|
17
|
-
metaMessages: failures.map((f) => `[${f.source}] ${f.detail.reason}`),
|
|
18
|
-
cause
|
|
19
|
-
});
|
|
20
|
-
this.failures = failures;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
22
|
+
const PreviewSimulationError = previewSimulationFailed;
|
|
23
23
|
/**
|
|
24
24
|
* Normalises an unknown rejection reason into a {@link PreviewSimulationError}.
|
|
25
25
|
* Pass-through when it already is one; otherwise decodes it under `source`.
|
|
26
26
|
*/
|
|
27
27
|
function asPreviewSimulationError(reason, source) {
|
|
28
28
|
if (reason instanceof PreviewSimulationError) return reason;
|
|
29
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
29
30
|
return new PreviewSimulationError([{
|
|
30
31
|
source,
|
|
31
|
-
detail: decodeSimulationError({ error
|
|
32
|
+
detail: decodeSimulationError({ error })
|
|
32
33
|
}]);
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
@@ -23,7 +23,7 @@ var ExecuteApi = class {
|
|
|
23
23
|
};
|
|
24
24
|
function poolTx(sdk, request) {
|
|
25
25
|
const { pool, wallet, sim } = request;
|
|
26
|
-
const { tokenIn, tokenOut } = sim.state;
|
|
26
|
+
const { tokenIn, tokenOut } = sim.data.state;
|
|
27
27
|
if (request.op === "deposit") {
|
|
28
28
|
const meta = sdk.pools.getDepositMetadata(pool, tokenIn.token.address, tokenOut.token.address);
|
|
29
29
|
const result = sdk.pools.addLiquidity({
|
|
@@ -50,7 +50,7 @@ function poolTx(sdk, request) {
|
|
|
50
50
|
}
|
|
51
51
|
async function openTx(sdk, request) {
|
|
52
52
|
const { creditManager, wallet, collateral, ethAmount, sim } = request;
|
|
53
|
-
const { state } = sim;
|
|
53
|
+
const { state } = sim.data;
|
|
54
54
|
return sdk.accounts.openCA({
|
|
55
55
|
creditManager,
|
|
56
56
|
to: wallet,
|
|
@@ -83,7 +83,7 @@ async function openRwaOptions(sdk, request) {
|
|
|
83
83
|
async function accountTx(sdk, request) {
|
|
84
84
|
const account = await sdk.accounts.getCreditAccountData(request.creditAccount);
|
|
85
85
|
if (!account) throw new Error(`credit account not found: ${request.creditAccount}`);
|
|
86
|
-
return sdk.accounts.executeCaUpdate(account, request.sim.calls, { ethAmount: nativeValue(request.sim.operations) });
|
|
86
|
+
return sdk.accounts.executeCaUpdate(account, request.sim.data.calls, { ethAmount: nativeValue(request.sim.data.operations) });
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* The coin the preparation asked the wallet for, which the facade wraps out of
|
package/dist/cjs/sdk/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const require_sdk_liquidations_LiquidationsNamespace = require("./liquidations/L
|
|
|
13
13
|
require("./liquidations/index.js");
|
|
14
14
|
const require_sdk_execute_ExecuteApi = require("./execute/ExecuteApi.js");
|
|
15
15
|
require("./execute/index.js");
|
|
16
|
+
const require_sdk_prepare_errors = require("./prepare/errors.js");
|
|
16
17
|
const require_sdk_prepare_PrepareApi = require("./prepare/PrepareApi.js");
|
|
17
18
|
require("./prepare/index.js");
|
|
18
19
|
const require_sdk_utils_filterResponse = require("./utils/filterResponse.js");
|
|
@@ -43,9 +44,13 @@ exports.PreviewNamespace = require_sdk_preview_PreviewNamespace.PreviewNamespace
|
|
|
43
44
|
exports.SourceChainMismatchError = require_sdk_errors_SourceChainMismatchError.SourceChainMismatchError;
|
|
44
45
|
exports.SourceUnavailableError = require_sdk_errors_SourceUnavailableError.SourceUnavailableError;
|
|
45
46
|
exports.assertSameChains = require_sdk_errors_assertSameChains.assertSameChains;
|
|
47
|
+
exports.creditAccountNotFound = require_sdk_prepare_errors.creditAccountNotFound;
|
|
46
48
|
exports.everyChainFailed = require_sdk_errors_everyChainFailed.everyChainFailed;
|
|
47
49
|
exports.filterResponse = require_sdk_utils_filterResponse.filterResponse;
|
|
48
50
|
exports.mergeChainList = require_sdk_utils_mergeChains.mergeChainList;
|
|
49
51
|
exports.mergeChainOne = require_sdk_utils_mergeChains.mergeChainOne;
|
|
52
|
+
exports.noStrategyTargetCollateral = require_sdk_prepare_errors.noStrategyTargetCollateral;
|
|
50
53
|
exports.raise = require_onchain_validation_refusal.raise;
|
|
51
54
|
exports.refuse = require_onchain_validation_refusal.refuse;
|
|
55
|
+
exports.toRefusalError = require_sdk_prepare_errors.toRefusalError;
|
|
56
|
+
exports.unexpectedFailure = require_sdk_prepare_errors.unexpectedFailure;
|