@morpho-org/calldata-verifier 0.0.0 → 0.2.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 +1 -0
- package/lib/cjs/midnight.js +51 -2
- package/lib/cjs/types.d.ts +1 -0
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/midnight.js +52 -3
- package/lib/esm/types.d.ts +1 -0
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ For Blue and Midnight, pass the market ID as `market` and the chain separately a
|
|
|
58
58
|
- Blue reallocations with a nonzero penalty are rejected.
|
|
59
59
|
- 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`.
|
|
60
60
|
- For Midnight, an approval, if included, must cover the encoded loan-token or collateral pull.
|
|
61
|
+
- 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).
|
|
61
62
|
- 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.
|
|
62
63
|
- 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.
|
|
63
64
|
- The verifier does not check slippage, expiry or attribution tags, or verify typed-data signing requests.
|
package/lib/cjs/midnight.js
CHANGED
|
@@ -235,9 +235,11 @@ function checkCoreWithdrawals(decoded, context) {
|
|
|
235
235
|
})
|
|
236
236
|
: first.result;
|
|
237
237
|
}
|
|
238
|
-
function checkNative(wrappedNative, { intent, chain, call, cap }) {
|
|
238
|
+
function checkNative(wrappedNative, { intent, chain, call, cap, requireValue = false, }) {
|
|
239
239
|
const value = (0, checks_js_1.uint)(call.value, { field: "value", call });
|
|
240
|
-
if (
|
|
240
|
+
if (!requireValue &&
|
|
241
|
+
value === 0n &&
|
|
242
|
+
(0, checks_js_1.sameAddress)(wrappedNative, viem_1.zeroAddress)) {
|
|
241
243
|
return;
|
|
242
244
|
}
|
|
243
245
|
if (value === 0n ||
|
|
@@ -437,6 +439,50 @@ function checkSell(decoded, context) {
|
|
|
437
439
|
});
|
|
438
440
|
return collateral;
|
|
439
441
|
}
|
|
442
|
+
function checkSupplyCollateralWithNative(decoded, context) {
|
|
443
|
+
const { intent, call } = context;
|
|
444
|
+
if (intent.action !== "midnight.supply_collateral") {
|
|
445
|
+
throw new errors_js_1.CalldataCallError("function", call.id);
|
|
446
|
+
}
|
|
447
|
+
const [blueMarket, assetsToPark, callbackSalt, market, supplies, ratifier, newRoot, signatureHeight, signatureNonce, signatureDeadline, v, r, s, groupsToCancel, payload, deadline, wrappedNative,] = decoded.args;
|
|
448
|
+
const emptyBlueMarket = (0, checks_js_1.sameAddress)(blueMarket.loanToken, viem_1.zeroAddress) &&
|
|
449
|
+
(0, checks_js_1.sameAddress)(blueMarket.collateralToken, viem_1.zeroAddress) &&
|
|
450
|
+
(0, checks_js_1.sameAddress)(blueMarket.oracle, viem_1.zeroAddress) &&
|
|
451
|
+
(0, checks_js_1.sameAddress)(blueMarket.irm, viem_1.zeroAddress) &&
|
|
452
|
+
blueMarket.lltv === 0n;
|
|
453
|
+
const emptyPublication = (0, checks_js_1.sameAddress)(ratifier, viem_1.zeroAddress) &&
|
|
454
|
+
(0, checks_js_1.sameHex)(newRoot, viem_1.zeroHash) &&
|
|
455
|
+
signatureHeight === 0n &&
|
|
456
|
+
signatureNonce === 0n &&
|
|
457
|
+
signatureDeadline === 0n &&
|
|
458
|
+
v === 0 &&
|
|
459
|
+
(0, checks_js_1.sameHex)(r, viem_1.zeroHash) &&
|
|
460
|
+
(0, checks_js_1.sameHex)(s, viem_1.zeroHash) &&
|
|
461
|
+
groupsToCancel.length === 0 &&
|
|
462
|
+
(0, checks_js_1.sameHex)(payload, "0x");
|
|
463
|
+
if (!emptyBlueMarket ||
|
|
464
|
+
assetsToPark !== 0n ||
|
|
465
|
+
!(0, checks_js_1.sameHex)(callbackSalt, viem_1.zeroHash) ||
|
|
466
|
+
!emptyPublication) {
|
|
467
|
+
throw new errors_js_1.CalldataCallError("cancel_and_make", call.id);
|
|
468
|
+
}
|
|
469
|
+
if (deadline === 0n) {
|
|
470
|
+
throw new errors_js_1.CalldataAmountError("deadline", call.id);
|
|
471
|
+
}
|
|
472
|
+
requireMarket(market, context);
|
|
473
|
+
const collateral = checkCollateral(supplies, {
|
|
474
|
+
requested: [intent],
|
|
475
|
+
market,
|
|
476
|
+
call,
|
|
477
|
+
});
|
|
478
|
+
const nativeCollateral = collateral.find(({ token }) => (0, checks_js_1.sameAddress)(token, wrappedNative));
|
|
479
|
+
checkNative(wrappedNative, {
|
|
480
|
+
...context,
|
|
481
|
+
cap: nativeCollateral?.assets ?? 0n,
|
|
482
|
+
requireValue: true,
|
|
483
|
+
});
|
|
484
|
+
return collateral;
|
|
485
|
+
}
|
|
440
486
|
function checkFills(fills, context) {
|
|
441
487
|
for (const { offer, units } of fills) {
|
|
442
488
|
requireMarket(offer.market, context);
|
|
@@ -504,6 +550,9 @@ function verifyMidnight(intent, { calls, chain, }) {
|
|
|
504
550
|
case "midnightBundlesV2SupplyCollateralAndSellWithUnitsTarget":
|
|
505
551
|
pulls = checkSell(decoded, context);
|
|
506
552
|
break;
|
|
553
|
+
case "midnightBundlesV2CancelAndMake":
|
|
554
|
+
pulls = checkSupplyCollateralWithNative(decoded, context);
|
|
555
|
+
break;
|
|
507
556
|
default:
|
|
508
557
|
throw new errors_js_1.CalldataCallError("function", call.id);
|
|
509
558
|
}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -232,6 +232,7 @@ export type MidnightMarketIntent = MidnightMarket & (({
|
|
|
232
232
|
readonly referral_fee?: never;
|
|
233
233
|
})) | ({
|
|
234
234
|
readonly action: "midnight.supply_collateral";
|
|
235
|
+
readonly funding?: Funding;
|
|
235
236
|
} & MidnightCollateral<Amount<"assets">>) | ({
|
|
236
237
|
readonly action: "midnight.withdraw_collateral";
|
|
237
238
|
} & MidnightWithdrawals));
|
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.2.0";
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/midnight.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MarketUtils, midnightAbi, midnightBundlesV2Abi, } from "@morpho-org/midnight-sdk";
|
|
2
|
-
import { maxUint256, zeroAddress } from "viem";
|
|
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
5
|
function isTake(intent) {
|
|
@@ -232,9 +232,11 @@ function checkCoreWithdrawals(decoded, context) {
|
|
|
232
232
|
})
|
|
233
233
|
: first.result;
|
|
234
234
|
}
|
|
235
|
-
function checkNative(wrappedNative, { intent, chain, call, cap }) {
|
|
235
|
+
function checkNative(wrappedNative, { intent, chain, call, cap, requireValue = false, }) {
|
|
236
236
|
const value = uint(call.value, { field: "value", call });
|
|
237
|
-
if (
|
|
237
|
+
if (!requireValue &&
|
|
238
|
+
value === 0n &&
|
|
239
|
+
sameAddress(wrappedNative, zeroAddress)) {
|
|
238
240
|
return;
|
|
239
241
|
}
|
|
240
242
|
if (value === 0n ||
|
|
@@ -434,6 +436,50 @@ function checkSell(decoded, context) {
|
|
|
434
436
|
});
|
|
435
437
|
return collateral;
|
|
436
438
|
}
|
|
439
|
+
function checkSupplyCollateralWithNative(decoded, context) {
|
|
440
|
+
const { intent, call } = context;
|
|
441
|
+
if (intent.action !== "midnight.supply_collateral") {
|
|
442
|
+
throw new CalldataCallError("function", call.id);
|
|
443
|
+
}
|
|
444
|
+
const [blueMarket, assetsToPark, callbackSalt, market, supplies, ratifier, newRoot, signatureHeight, signatureNonce, signatureDeadline, v, r, s, groupsToCancel, payload, deadline, wrappedNative,] = decoded.args;
|
|
445
|
+
const emptyBlueMarket = sameAddress(blueMarket.loanToken, zeroAddress) &&
|
|
446
|
+
sameAddress(blueMarket.collateralToken, zeroAddress) &&
|
|
447
|
+
sameAddress(blueMarket.oracle, zeroAddress) &&
|
|
448
|
+
sameAddress(blueMarket.irm, zeroAddress) &&
|
|
449
|
+
blueMarket.lltv === 0n;
|
|
450
|
+
const emptyPublication = sameAddress(ratifier, zeroAddress) &&
|
|
451
|
+
sameHex(newRoot, zeroHash) &&
|
|
452
|
+
signatureHeight === 0n &&
|
|
453
|
+
signatureNonce === 0n &&
|
|
454
|
+
signatureDeadline === 0n &&
|
|
455
|
+
v === 0 &&
|
|
456
|
+
sameHex(r, zeroHash) &&
|
|
457
|
+
sameHex(s, zeroHash) &&
|
|
458
|
+
groupsToCancel.length === 0 &&
|
|
459
|
+
sameHex(payload, "0x");
|
|
460
|
+
if (!emptyBlueMarket ||
|
|
461
|
+
assetsToPark !== 0n ||
|
|
462
|
+
!sameHex(callbackSalt, zeroHash) ||
|
|
463
|
+
!emptyPublication) {
|
|
464
|
+
throw new CalldataCallError("cancel_and_make", call.id);
|
|
465
|
+
}
|
|
466
|
+
if (deadline === 0n) {
|
|
467
|
+
throw new CalldataAmountError("deadline", call.id);
|
|
468
|
+
}
|
|
469
|
+
requireMarket(market, context);
|
|
470
|
+
const collateral = checkCollateral(supplies, {
|
|
471
|
+
requested: [intent],
|
|
472
|
+
market,
|
|
473
|
+
call,
|
|
474
|
+
});
|
|
475
|
+
const nativeCollateral = collateral.find(({ token }) => sameAddress(token, wrappedNative));
|
|
476
|
+
checkNative(wrappedNative, {
|
|
477
|
+
...context,
|
|
478
|
+
cap: nativeCollateral?.assets ?? 0n,
|
|
479
|
+
requireValue: true,
|
|
480
|
+
});
|
|
481
|
+
return collateral;
|
|
482
|
+
}
|
|
437
483
|
function checkFills(fills, context) {
|
|
438
484
|
for (const { offer, units } of fills) {
|
|
439
485
|
requireMarket(offer.market, context);
|
|
@@ -501,6 +547,9 @@ function verifyMidnight(intent, { calls, chain, }) {
|
|
|
501
547
|
case "midnightBundlesV2SupplyCollateralAndSellWithUnitsTarget":
|
|
502
548
|
pulls = checkSell(decoded, context);
|
|
503
549
|
break;
|
|
550
|
+
case "midnightBundlesV2CancelAndMake":
|
|
551
|
+
pulls = checkSupplyCollateralWithNative(decoded, context);
|
|
552
|
+
break;
|
|
504
553
|
default:
|
|
505
554
|
throw new CalldataCallError("function", call.id);
|
|
506
555
|
}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -232,6 +232,7 @@ export type MidnightMarketIntent = MidnightMarket & (({
|
|
|
232
232
|
readonly referral_fee?: never;
|
|
233
233
|
})) | ({
|
|
234
234
|
readonly action: "midnight.supply_collateral";
|
|
235
|
+
readonly funding?: Funding;
|
|
235
236
|
} & MidnightCollateral<Amount<"assets">>) | ({
|
|
236
237
|
readonly action: "midnight.withdraw_collateral";
|
|
237
238
|
} & MidnightWithdrawals));
|
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.2.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.2.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@morpho-org/blue-sdk-viem": "^7.6.0",
|
|
31
|
-
"@morpho-org/midnight-sdk": "^2.9.
|
|
32
|
-
"@morpho-org/morpho-sdk": "^10.
|
|
33
|
-
"@morpho-org/morpho-ts": "^4.5.
|
|
31
|
+
"@morpho-org/midnight-sdk": "^2.9.1",
|
|
32
|
+
"@morpho-org/morpho-sdk": "^10.3.1",
|
|
33
|
+
"@morpho-org/morpho-ts": "^4.5.1",
|
|
34
34
|
"@noble/curves": "1.9.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|