@gearbox-protocol/sdk 16.0.0-next.41 → 16.0.0-next.42

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.
@@ -0,0 +1,90 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/sdk/prepare/errors.ts
3
+ /**
4
+ * One sentence per refusal, naming what was ruled out rather than restating the
5
+ * numbers the error already carries.
6
+ *
7
+ * English and loggable, not a string to put on a screen: a form renders the
8
+ * code and the amounts in its own words, see {@link IGearboxError.message}.
9
+ **/
10
+ const MESSAGES = {
11
+ debtOutOfRange: "The debt this request implies is outside the market's band.",
12
+ leverageOutOfRange: "The leverage asked for cannot be expressed as a plan.",
13
+ insufficientSourceBalance: "Neither the account nor the wallet holds enough to fund this request.",
14
+ unsupportedCollateralToken: "This flow does not accept that token.",
15
+ unsupportedTokenPair: "No route exists between these two tokens.",
16
+ noDelayedRoute: "This request cannot be served as a delayed redemption.",
17
+ multipleDelayedWithdrawals: "The source asset has several redemption venues and none was named.",
18
+ withdrawalInProgress: "A redemption of this asset is already in flight on the account.",
19
+ noRecordedIntent: "The claim names no operation to resume.",
20
+ marketPaused: "The market is paused.",
21
+ marketExpired: "The market is past its expiration date.",
22
+ insufficientPoolLiquidity: "The pool cannot lend what this plan draws.",
23
+ quotaLimitReached: "The market takes no more quota for a token this plan holds.",
24
+ forbiddenToken: "This plan would increase the balance of a forbidden token.",
25
+ insufficientCollateral: "The account would end this transaction under-collateralised.",
26
+ poolSunset: "The pool is winding down and takes no more deposits.",
27
+ quotaCountExceeded: "The account would hold more quoted tokens than the facade enables at once.",
28
+ malformedTransaction: "The transaction could not be replayed."
29
+ };
30
+ /**
31
+ * The engine's refusal, as the error the namespace answers with.
32
+ *
33
+ * One place does the lifting, so the two shapes cannot drift: `reason` becomes
34
+ * `code`, the detail is spread onto the error, and the sentence comes from
35
+ * {@link MESSAGES}. A malformed transaction is spelled out rather than spread,
36
+ * because its detail names a `code` and a `message` of its own and they are not
37
+ * the envelope's.
38
+ **/
39
+ function toPrepareError(issue) {
40
+ if (issue.reason === "malformedTransaction") return {
41
+ code: "malformedTransaction",
42
+ message: MESSAGES.malformedTransaction,
43
+ previewCode: issue.detail.code,
44
+ detail: issue.detail.message
45
+ };
46
+ return {
47
+ code: issue.reason,
48
+ message: MESSAGES[issue.reason],
49
+ ...issue.detail
50
+ };
51
+ }
52
+ /**
53
+ * {@inheritDoc NoStrategyTargetCollateralError}
54
+ **/
55
+ function noStrategyTargetCollateral(creditManager) {
56
+ return {
57
+ code: "noStrategyTargetCollateral",
58
+ message: `Credit manager ${creditManager} has no strategy target collateral, and none was named.`,
59
+ creditManager
60
+ };
61
+ }
62
+ /**
63
+ * {@inheritDoc CreditAccountNotFoundError}
64
+ **/
65
+ function creditAccountNotFound(creditAccount) {
66
+ return {
67
+ code: "creditAccountNotFound",
68
+ message: `Credit account not found: ${creditAccount}.`,
69
+ creditAccount
70
+ };
71
+ }
72
+ /**
73
+ * {@inheritDoc UnexpectedFailureError}
74
+ *
75
+ * Takes what was thrown, whatever that is: a `throw` is not obliged to raise an
76
+ * `Error`, and `cause` promises one.
77
+ **/
78
+ function unexpectedFailure(thrown) {
79
+ const cause = thrown instanceof Error ? thrown : new Error(String(thrown));
80
+ return {
81
+ code: "unexpectedFailure",
82
+ message: `The SDK could not prepare this operation: ${cause.message}`,
83
+ cause
84
+ };
85
+ }
86
+ //#endregion
87
+ exports.creditAccountNotFound = creditAccountNotFound;
88
+ exports.noStrategyTargetCollateral = noStrategyTargetCollateral;
89
+ exports.toPrepareError = toPrepareError;
90
+ exports.unexpectedFailure = unexpectedFailure;
@@ -1,8 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_onchain_validation_refusal = require("../../onchain/validation/refusal.js");
3
+ const require_sdk_prepare_errors = require("./errors.js");
3
4
  const require_sdk_prepare_PrepareApi = require("./PrepareApi.js");
4
5
  require("./types.js");
5
6
  exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
6
7
  exports.PrepareApi = require_sdk_prepare_PrepareApi.PrepareApi;
8
+ exports.creditAccountNotFound = require_sdk_prepare_errors.creditAccountNotFound;
9
+ exports.noStrategyTargetCollateral = require_sdk_prepare_errors.noStrategyTargetCollateral;
7
10
  exports.raise = require_onchain_validation_refusal.raise;
8
11
  exports.refuse = require_onchain_validation_refusal.refuse;
12
+ exports.toPrepareError = require_sdk_prepare_errors.toPrepareError;
13
+ exports.unexpectedFailure = require_sdk_prepare_errors.unexpectedFailure;
@@ -0,0 +1 @@
1
+ export {};
@@ -5,6 +5,7 @@ import { chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chart
5
5
  import "./curators.js";
6
6
  import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
7
7
  import "./delayed-intents.js";
8
+ import "./errors.js";
8
9
  import { FILTER_ALL, isFilterSet } from "./filters.js";
9
10
  import { booleanParamSchema, encodeFlag, filterAllSchema, filterable } from "./filters.schema.js";
10
11
  import { matchesLiquidatableAccountFilter } from "./liquidations.js";
@@ -10,7 +10,7 @@ import "./utils/index.js";
10
10
  const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
11
11
  /**
12
12
  * Builds the state opening a leveraged position out of wallet collateral would
13
- * land in.
13
+ * reach.
14
14
  *
15
15
  * Debt follows from the target leverage against the supplied margin
16
16
  * (`debt = margin * (L - 1)`, `totalValue = margin * L`); the collateral and the
@@ -11,7 +11,7 @@ var ExecuteApi = class {
11
11
  * {@inheritDoc IOpportunitiesExecute.buildTx}
12
12
  **/
13
13
  async buildTx(request) {
14
- if (!request.sim.ok) throw new Error(`cannot build a transaction from a failed ${request.kind} preparation`);
14
+ if (!request.sim.success) throw new Error(`cannot build a transaction from a failed ${request.kind} preparation`);
15
15
  const sdk = this.#chainOf(request.chainId);
16
16
  switch (request.kind) {
17
17
  case "pool": return poolTx(sdk, request);
@@ -22,7 +22,7 @@ var ExecuteApi = class {
22
22
  };
23
23
  function poolTx(sdk, request) {
24
24
  const { pool, wallet, sim } = request;
25
- const { tokenIn, tokenOut } = sim.state;
25
+ const { tokenIn, tokenOut } = sim.data.state;
26
26
  if (request.op === "deposit") {
27
27
  const meta = sdk.pools.getDepositMetadata(pool, tokenIn.token.address, tokenOut.token.address);
28
28
  const result = sdk.pools.addLiquidity({
@@ -49,7 +49,7 @@ function poolTx(sdk, request) {
49
49
  }
50
50
  async function openTx(sdk, request) {
51
51
  const { creditManager, wallet, collateral, ethAmount, sim } = request;
52
- const { state } = sim;
52
+ const { state } = sim.data;
53
53
  return sdk.accounts.openCA({
54
54
  creditManager,
55
55
  to: wallet,
@@ -82,7 +82,7 @@ async function openRwaOptions(sdk, request) {
82
82
  async function accountTx(sdk, request) {
83
83
  const account = await sdk.accounts.getCreditAccountData(request.creditAccount);
84
84
  if (!account) throw new Error(`credit account not found: ${request.creditAccount}`);
85
- return sdk.accounts.executeCaUpdate(account, request.sim.calls, { ethAmount: nativeValue(request.sim.operations) });
85
+ return sdk.accounts.executeCaUpdate(account, request.sim.data.calls, { ethAmount: nativeValue(request.sim.data.operations) });
86
86
  }
87
87
  /**
88
88
  * The coin the preparation asked the wallet for, which the facade wraps out of
@@ -12,6 +12,7 @@ import { LiquidationsNamespace } from "./liquidations/LiquidationsNamespace.js";
12
12
  import "./liquidations/index.js";
13
13
  import { ExecuteApi } from "./execute/ExecuteApi.js";
14
14
  import "./execute/index.js";
15
+ import { creditAccountNotFound, noStrategyTargetCollateral, toPrepareError, unexpectedFailure } from "./prepare/errors.js";
15
16
  import { PrepareApi } from "./prepare/PrepareApi.js";
16
17
  import "./prepare/index.js";
17
18
  import { filterResponse } from "./utils/filterResponse.js";
@@ -25,4 +26,4 @@ import { PreviewNamespace } from "./preview/PreviewNamespace.js";
25
26
  import "./preview/index.js";
26
27
  import { DEFAULT_MAX_STATE_AGE, GearboxSDK } from "./GearboxSDK.js";
27
28
  import "./types.js";
28
- export { AbstractNamespace, AllSourcesFailedError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, ExecuteApi, GearboxSDK, IntentPreviewError, LiquidationsNamespace, MissingSourceError, NoSourceServedError, OpportunitiesNamespace, PositionsNamespace, PrepareApi, PreviewNamespace, SourceChainMismatchError, SourceUnavailableError, assertSameChains, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, raise, refuse };
29
+ export { AbstractNamespace, AllSourcesFailedError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, ExecuteApi, GearboxSDK, IntentPreviewError, LiquidationsNamespace, MissingSourceError, NoSourceServedError, OpportunitiesNamespace, PositionsNamespace, PrepareApi, PreviewNamespace, SourceChainMismatchError, SourceUnavailableError, assertSameChains, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, raise, refuse, toPrepareError, unexpectedFailure };