@morpho-org/calldata-verifier 0.3.0 → 0.4.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 +3 -2
- package/lib/cjs/blue.js +8 -9
- package/lib/cjs/midnight.js +9 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/blue.js +8 -9
- package/lib/esm/midnight.js +9 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Use [`@morpho-org/evm-simulation`](../evm-simulation) for execution-dependent ch
|
|
|
19
19
|
- Whether the caller-supplied Vault `asset` matches the actual `vault.asset()`. Read `vault.asset()` at the pinned block and compare it with `asset`. For deposits and standard withdrawals or redemptions, typed-input simulation can establish an exact match if you pass a canonical ERC-20 address as the token override (`assetPaid` for deposits, `assetReceived` for exits). Simulation also accepts `ethAddress` for a vault whose asset is the chain's wrapped-native token, so use the pinned read if your source might supply a native alias. Force withdrawals, force redemptions, and in-kind redemptions do not support typed inputs; use the pinned read for those. Quote-only limits can accept a token override without comparing it with `vault.asset()`.
|
|
20
20
|
- Whether existing onchain allowances suffice and whether a call succeeds or reverts.
|
|
21
21
|
- Blue ERC-20 repay by shares or for all debt: before signing, compare the decoded `maxRepayAssets`, which is `args[3]` of the verified `blueBundlesV1RepayAndWithdrawCollateral` call, against an independently chosen funding cap. Apply this check whenever that call's `value` is zero, including for requests that allowed native funding, because such requests don't have to use it. Simulating net spend does not bound the upfront pull because unused funds can be refunded.
|
|
22
|
-
- Blue public-allocator reallocations: the verifier checks zero penalty, the destination market and loan token, positive
|
|
22
|
+
- Blue public-allocator reallocations: the verifier checks each leg in calldata order for zero penalty, the destination market and loan token, a positive amount, and nonzero vault and destination adapter addresses. Market-funded legs require a nonzero source adapter and may revisit a route. Idle-funded legs require a zero source adapter and must be unique per vault and destination adapter. Adapter eligibility, whether a reallocation is needed, and whether its source and amount are appropriate require onchain checks.
|
|
23
23
|
- Blue embedded Morpho authorizations: the verifier checks signature structure. The bundle supplies the transaction sender and its own address as the authorizer and authorized spender; signature validity, nonce and expiry are execution checks.
|
|
24
24
|
- Midnight full direct repays, and units-target lends, market repays and `midnight.take_lend` takes: compare the decoded `maxBuyerAssets` against an independently chosen upfront funding cap before signing. For full direct repays, this applies to ERC-20, native, and auto funding: when ETH is sent, the bundle wraps it to the signer's balance and then pulls the encoded `maxBuyerAssets` from that wrapped-native balance. `max_native_assets` caps only the ETH sent, not the token pull. For the units-target cases, you can instead set a `max_assets` guard to enforce the upfront funding cap. Simulation's `assetsPaid` measures net spend after refunds, not the upfront pull.
|
|
25
25
|
- Midnight buy bundles for lend, market repay, and `midnight.take_lend`: the verifier does not bound the encoded `maxContinuousFee`. Compare it with an independently chosen ceiling. To check the market's actual fee against that ceiling, read Midnight's `continuousFee(marketId)` at the simulation block or use a simulation `assertBefore` view call.
|
|
@@ -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
|
-
-
|
|
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
|
|
package/lib/cjs/blue.js
CHANGED
|
@@ -61,28 +61,27 @@ function requireMarket(params, { chainId, selector, call, field = "market", }) {
|
|
|
61
61
|
}
|
|
62
62
|
function requireReallocations(entries, { params, call }) {
|
|
63
63
|
const expected = marketId(params);
|
|
64
|
-
const
|
|
64
|
+
const idleDestinations = new Set();
|
|
65
65
|
for (const entry of entries) {
|
|
66
|
-
const source = marketId(entry.sourceMarketParams);
|
|
67
66
|
const destination = `${entry.vault}:${entry.adapter}`;
|
|
68
|
-
const route = entry.fromIdle
|
|
69
|
-
? destination
|
|
70
|
-
: `${destination}:${entry.sourceAdapter}:${source}`;
|
|
71
67
|
if (entry.penalty !== 0n) {
|
|
72
68
|
throw new errors_js_1.CalldataFeeError("reallocations.penalty", call.id);
|
|
73
69
|
}
|
|
74
70
|
if (entry.assets === 0n ||
|
|
75
|
-
used.has(route) ||
|
|
76
71
|
(0, checks_js_1.sameAddress)(entry.vault, viem_1.zeroAddress) ||
|
|
77
72
|
(0, checks_js_1.sameAddress)(entry.adapter, viem_1.zeroAddress) ||
|
|
78
73
|
marketId(entry.marketParams) !== expected ||
|
|
79
74
|
!(0, checks_js_1.sameAddress)(entry.sourceMarketParams.loanToken, params.loanToken) ||
|
|
80
75
|
(entry.fromIdle
|
|
81
|
-
? !(0, checks_js_1.sameAddress)(entry.sourceAdapter, viem_1.zeroAddress)
|
|
82
|
-
|
|
76
|
+
? !(0, checks_js_1.sameAddress)(entry.sourceAdapter, viem_1.zeroAddress) ||
|
|
77
|
+
idleDestinations.has(destination)
|
|
78
|
+
: (0, checks_js_1.sameAddress)(entry.sourceAdapter, viem_1.zeroAddress) ||
|
|
79
|
+
marketId(entry.sourceMarketParams) === expected)) {
|
|
83
80
|
throw new errors_js_1.CalldataCallError("reallocations", call.id);
|
|
84
81
|
}
|
|
85
|
-
|
|
82
|
+
if (entry.fromIdle) {
|
|
83
|
+
idleDestinations.add(destination);
|
|
84
|
+
}
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
function requirePositionAmount(amount, { assets, shares, call, }) {
|
package/lib/cjs/midnight.js
CHANGED
|
@@ -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"
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Installed @morpho-org/calldata-verifier package version. */
|
|
2
|
-
export declare const version = "0.
|
|
2
|
+
export declare const version = "0.4.0";
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/blue.js
CHANGED
|
@@ -58,28 +58,27 @@ function requireMarket(params, { chainId, selector, call, field = "market", }) {
|
|
|
58
58
|
}
|
|
59
59
|
function requireReallocations(entries, { params, call }) {
|
|
60
60
|
const expected = marketId(params);
|
|
61
|
-
const
|
|
61
|
+
const idleDestinations = new Set();
|
|
62
62
|
for (const entry of entries) {
|
|
63
|
-
const source = marketId(entry.sourceMarketParams);
|
|
64
63
|
const destination = `${entry.vault}:${entry.adapter}`;
|
|
65
|
-
const route = entry.fromIdle
|
|
66
|
-
? destination
|
|
67
|
-
: `${destination}:${entry.sourceAdapter}:${source}`;
|
|
68
64
|
if (entry.penalty !== 0n) {
|
|
69
65
|
throw new CalldataFeeError("reallocations.penalty", call.id);
|
|
70
66
|
}
|
|
71
67
|
if (entry.assets === 0n ||
|
|
72
|
-
used.has(route) ||
|
|
73
68
|
sameAddress(entry.vault, zeroAddress) ||
|
|
74
69
|
sameAddress(entry.adapter, zeroAddress) ||
|
|
75
70
|
marketId(entry.marketParams) !== expected ||
|
|
76
71
|
!sameAddress(entry.sourceMarketParams.loanToken, params.loanToken) ||
|
|
77
72
|
(entry.fromIdle
|
|
78
|
-
? !sameAddress(entry.sourceAdapter, zeroAddress)
|
|
79
|
-
|
|
73
|
+
? !sameAddress(entry.sourceAdapter, zeroAddress) ||
|
|
74
|
+
idleDestinations.has(destination)
|
|
75
|
+
: sameAddress(entry.sourceAdapter, zeroAddress) ||
|
|
76
|
+
marketId(entry.sourceMarketParams) === expected)) {
|
|
80
77
|
throw new CalldataCallError("reallocations", call.id);
|
|
81
78
|
}
|
|
82
|
-
|
|
79
|
+
if (entry.fromIdle) {
|
|
80
|
+
idleDestinations.add(destination);
|
|
81
|
+
}
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
function requirePositionAmount(amount, { assets, shares, call, }) {
|
package/lib/esm/midnight.js
CHANGED
|
@@ -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"
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Installed @morpho-org/calldata-verifier package version. */
|
|
2
|
-
export declare const version = "0.
|
|
2
|
+
export declare const version = "0.4.0";
|
package/lib/esm/version.js
CHANGED
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.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@morpho-org/blue-sdk-viem": "^7.6.0",
|
|
31
31
|
"@morpho-org/midnight-sdk": "^2.10.0",
|
|
32
|
-
"@morpho-org/morpho-sdk": "^10.
|
|
32
|
+
"@morpho-org/morpho-sdk": "^10.5.0",
|
|
33
33
|
"@morpho-org/morpho-ts": "^4.5.1",
|
|
34
34
|
"@noble/curves": "1.9.1",
|
|
35
35
|
"fflate": "0.8.3"
|