@morpho-org/calldata-verifier 0.3.1-next.0 → 0.4.1-next.0

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/README.md CHANGED
@@ -59,10 +59,11 @@ For Blue and Midnight, pass the market ID as `market` and the chain separately a
59
59
  - Blue reallocations with a nonzero penalty are rejected.
60
60
  - Midnight accepts `slippage` or no guard, and checks explicit `min_units`/`max_assets` on buys and `max_units`/`min_assets` on sells and direct withdrawals. Unknown and wrong-side guards throw `CalldataUnsupportedError`.
61
61
  - For Midnight, an approval, if included, must cover the encoded loan-token or collateral pull.
62
+ - Midnight borrows (`midnight.borrow`, `midnight.take_borrow` and `midnight.supply_collateral_take_borrow`) are rejected when the encoded deadline is later than two hours before the market's maturity, matching the SDK's `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY`. The verifier has no clock, so this also rejects post-maturity borrow sells, which the SDK allows; sell credit with `midnight.withdraw` instead.
62
63
  - Standalone `midnight.supply_collateral` accepts direct Midnight `supplyCollateral` (zero native value, no authorization prerequisite) or native-funded `MidnightBundlesV2.midnightBundlesV2CancelAndMake` (positive native value on the chain's wrapped-native collateral up to `funding.max_native_assets` and the collateral amount, with all Blue-parking, offer-publication, and cancellation fields zero or empty, plus optional wrapped-native approval and `MidnightBundlesV2` authorization prerequisites).
63
64
  - Midnight `min_rate` and `max_rate` guards throw `CalldataUnsupportedError`: the rate is not encoded directly in the bundle, and its conversion depends on the quote and execution context.
64
65
  - Midnight core withdrawals transfer one loan asset per unit withdrawn after the contract updates the account's credit for losses. The verifier accepts exact asset and exact unit requests for this route.
65
- - The verifier does not check slippage, expiry or attribution tags, or verify typed-data signing requests.
66
+ - Apart from the Midnight borrow maturity cutoff, the verifier does not check slippage, expiry or attribution tags, or verify typed-data signing requests.
66
67
 
67
68
  ### Authenticate an Actions API response
68
69
 
@@ -7,6 +7,8 @@ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
7
7
  const viem_1 = require("viem");
8
8
  const checks_js_1 = require("./checks.js");
9
9
  const errors_js_1 = require("./errors.js");
10
+ /** Mirrors morpho-sdk's `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY`; a test keeps them equal. */
11
+ const MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = 7200n;
10
12
  function isTake(intent) {
11
13
  return (intent.action === "midnight.take_borrow" ||
12
14
  intent.action === "midnight.supply_collateral_take_borrow" ||
@@ -406,7 +408,7 @@ function checkSell(decoded, context) {
406
408
  intent.action !== "midnight.withdraw") {
407
409
  throw new errors_js_1.CalldataCallError("function", call.id);
408
410
  }
409
- const [market, target, bound, reduceOnly, receiver, supplies, fills, pct, recipient, , wrappedNative,] = decoded.args;
411
+ const [market, target, bound, reduceOnly, receiver, supplies, fills, pct, recipient, deadline, wrappedNative,] = decoded.args;
410
412
  requireMarket(market, context);
411
413
  const withdraw = intent.action === "midnight.withdraw";
412
414
  if (reduceOnly !== withdraw ||
@@ -414,6 +416,12 @@ function checkSell(decoded, context) {
414
416
  intent.amount?.unit === "all") {
415
417
  throw new errors_js_1.CalldataCallError("offers", call.id);
416
418
  }
419
+ // Without a clock, a borrow deadline past this cutoff can't be told apart from a pre-maturity
420
+ // borrow that the SDK rejects, so it fails closed.
421
+ if (!withdraw &&
422
+ deadline > market.maturity - MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY) {
423
+ throw new errors_js_1.CalldataAmountError("deadline", call.id);
424
+ }
417
425
  const unit = decoded.functionName ===
418
426
  "midnightBundlesV2SupplyCollateralAndSellWithAssetsTarget"
419
427
  ? "assets"
@@ -1,2 +1,2 @@
1
1
  /** Installed @morpho-org/calldata-verifier package version. */
2
- export declare const version = "0.3.1-next.0";
2
+ export declare const version = "0.4.1-next.0";
@@ -3,4 +3,4 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.version = void 0;
5
5
  /** Installed @morpho-org/calldata-verifier package version. */
6
- exports.version = "0.3.1-next.0";
6
+ exports.version = "0.4.1-next.0";
@@ -2,6 +2,8 @@ import { MarketUtils, midnightAbi, midnightBundlesV2Abi, } from "@morpho-org/mid
2
2
  import { maxUint256, zeroAddress, zeroHash } from "viem";
3
3
  import { approval, checked, decode, innerCall, mainCall, requireAccount, requireAmount, requireFee, requireNativeBudget, requireTarget, sameAddress, sameHex, uint, } from "./checks.js";
4
4
  import { CalldataAmountError, CalldataCallError, CalldataFeeError, CalldataTargetError, CalldataUnsupportedError, } from "./errors.js";
5
+ /** Mirrors morpho-sdk's `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY`; a test keeps them equal. */
6
+ const MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY = 7200n;
5
7
  function isTake(intent) {
6
8
  return (intent.action === "midnight.take_borrow" ||
7
9
  intent.action === "midnight.supply_collateral_take_borrow" ||
@@ -401,7 +403,7 @@ function checkSell(decoded, context) {
401
403
  intent.action !== "midnight.withdraw") {
402
404
  throw new CalldataCallError("function", call.id);
403
405
  }
404
- const [market, target, bound, reduceOnly, receiver, supplies, fills, pct, recipient, , wrappedNative,] = decoded.args;
406
+ const [market, target, bound, reduceOnly, receiver, supplies, fills, pct, recipient, deadline, wrappedNative,] = decoded.args;
405
407
  requireMarket(market, context);
406
408
  const withdraw = intent.action === "midnight.withdraw";
407
409
  if (reduceOnly !== withdraw ||
@@ -409,6 +411,12 @@ function checkSell(decoded, context) {
409
411
  intent.amount?.unit === "all") {
410
412
  throw new CalldataCallError("offers", call.id);
411
413
  }
414
+ // Without a clock, a borrow deadline past this cutoff can't be told apart from a pre-maturity
415
+ // borrow that the SDK rejects, so it fails closed.
416
+ if (!withdraw &&
417
+ deadline > market.maturity - MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY) {
418
+ throw new CalldataAmountError("deadline", call.id);
419
+ }
412
420
  const unit = decoded.functionName ===
413
421
  "midnightBundlesV2SupplyCollateralAndSellWithAssetsTarget"
414
422
  ? "assets"
@@ -1,2 +1,2 @@
1
1
  /** Installed @morpho-org/calldata-verifier package version. */
2
- export declare const version = "0.3.1-next.0";
2
+ export declare const version = "0.4.1-next.0";
@@ -1,3 +1,3 @@
1
1
  // Generated by scripts/generate-package-versions.ts. Do not edit.
2
2
  /** Installed @morpho-org/calldata-verifier package version. */
3
- export const version = "0.3.1-next.0";
3
+ export const version = "0.4.1-next.0";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/calldata-verifier",
3
3
  "description": "Verify Morpho action calldata locally before signing.",
4
- "version": "0.3.1-next.0",
4
+ "version": "0.4.1-next.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,10 +27,10 @@
27
27
  "build:esm": "tsc --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json"
28
28
  },
29
29
  "dependencies": {
30
- "@morpho-org/blue-sdk-viem": "^7.7.0-next.0",
31
- "@morpho-org/midnight-sdk": "^2.11.0-next.0",
32
- "@morpho-org/morpho-sdk": "^10.5.0-next.0",
33
- "@morpho-org/morpho-ts": "^4.6.0-next.1",
30
+ "@morpho-org/blue-sdk-viem": "^7.7.0-next.1",
31
+ "@morpho-org/midnight-sdk": "^2.11.0-next.1",
32
+ "@morpho-org/morpho-sdk": "^10.6.0-next.0",
33
+ "@morpho-org/morpho-ts": "^4.6.0-next.2",
34
34
  "@noble/curves": "1.9.1",
35
35
  "fflate": "0.8.3"
36
36
  },