@morpho-org/morpho-sdk 6.6.0 → 7.0.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/MIGRATION-v6-to-v7.md +291 -0
- package/README.md +26 -12
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +3 -2
- package/lib/cjs/actions/bundles/common.d.ts +9 -5
- package/lib/cjs/actions/bundles/common.js +22 -13
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
- package/lib/cjs/actions/midnight/authorization.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
- package/lib/cjs/actions/midnight/index.d.ts +3 -3
- package/lib/cjs/actions/midnight/index.js +3 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
- package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
- package/lib/cjs/actions/midnight/takeLend.js +111 -54
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
- package/lib/cjs/actions/midnight/types.d.ts +7 -26
- package/lib/cjs/actions/midnight/types.js +0 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/midnight/index.js +0 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/entities/index.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
- package/lib/cjs/entities/midnight/midnight.js +981 -509
- package/lib/cjs/entities/midnight/types.d.ts +142 -60
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
- package/lib/cjs/helpers/callback.d.ts +54 -0
- package/lib/cjs/helpers/callback.js +73 -0
- package/lib/cjs/helpers/constant.d.ts +2 -0
- package/lib/cjs/helpers/constant.js +3 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +6 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/cjs/helpers/validate.d.ts +43 -2
- package/lib/cjs/helpers/validate.js +60 -3
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -2
- package/lib/cjs/midnight/types.d.ts +1 -1
- package/lib/cjs/types/action.d.ts +117 -89
- package/lib/cjs/types/action.js +1 -19
- package/lib/cjs/types/error.d.ts +126 -40
- package/lib/cjs/types/error.js +154 -49
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +9 -5
- package/lib/esm/actions/bundles/common.js +22 -13
- package/lib/esm/actions/midnight/authorization.d.ts +3 -2
- package/lib/esm/actions/midnight/authorization.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
- package/lib/esm/actions/midnight/index.d.ts +3 -3
- package/lib/esm/actions/midnight/index.js +3 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
- package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/esm/actions/midnight/takeBorrow.js +98 -57
- package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
- package/lib/esm/actions/midnight/takeLend.js +114 -57
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
- package/lib/esm/actions/midnight/types.d.ts +7 -26
- package/lib/esm/actions/midnight/types.js +1 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/esm/actions/requirements/midnight/index.js +0 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/index.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +582 -108
- package/lib/esm/entities/midnight/midnight.js +987 -515
- package/lib/esm/entities/midnight/types.d.ts +142 -60
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
- package/lib/esm/helpers/callback.d.ts +54 -0
- package/lib/esm/helpers/callback.js +68 -0
- package/lib/esm/helpers/constant.d.ts +2 -0
- package/lib/esm/helpers/constant.js +2 -0
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/esm/helpers/validate.d.ts +43 -2
- package/lib/esm/helpers/validate.js +58 -2
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/esm/helpers/validateRequirementSpender.js +4 -5
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/types.d.ts +1 -1
- package/lib/esm/types/action.d.ts +117 -89
- package/lib/esm/types/action.js +1 -18
- package/lib/esm/types/error.d.ts +126 -40
- package/lib/esm/types/error.js +135 -38
- package/package.json +8 -7
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
- package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/esm/actions/midnight/cancelOffer.js +0 -69
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
|
@@ -203,18 +203,22 @@ export declare const selectBundlesTokenRequirementSignature: (signatures: readon
|
|
|
203
203
|
* @internal
|
|
204
204
|
*
|
|
205
205
|
* @param signatures - Signatures passed to the operation's `buildTx` function.
|
|
206
|
-
* @param expected - Immutable spender, amount, and deadline required by the operation.
|
|
206
|
+
* @param expected - Immutable spender, amount bounds, and deadline required by the operation.
|
|
207
207
|
* @param expected.spender - Fixed bundles contract the permit must authorize.
|
|
208
|
-
* @param expected.amount -
|
|
208
|
+
* @param expected.amount - Minimum share allowance the permit must cover.
|
|
209
|
+
* @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
|
|
210
|
+
* `expected.amount`, which accepts only an exact match.
|
|
209
211
|
* @param expected.deadline - Deadline the permit must carry.
|
|
210
212
|
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
211
|
-
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612
|
|
212
|
-
*
|
|
213
|
-
*
|
|
213
|
+
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
|
|
214
|
+
* deadline differ from the operation's, its signed amount differs from its action's amount, or
|
|
215
|
+
* its amount is outside `[expected.amount, expected.maxAmount ?? expected.amount]`.
|
|
216
|
+
* The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
|
|
214
217
|
*/
|
|
215
218
|
export declare const selectBundlesSharesPermitSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
|
|
216
219
|
readonly spender: Address;
|
|
217
220
|
readonly amount: bigint;
|
|
221
|
+
readonly maxAmount?: bigint;
|
|
218
222
|
readonly deadline: bigint;
|
|
219
223
|
}) => Erc2612RequirementSignature | undefined;
|
|
220
224
|
/** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
|
|
@@ -356,11 +356,7 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
356
356
|
if (selected.length !== signatures.length) {
|
|
357
357
|
const unexpected = signatures.find((signature) => signature.action.type !== "permit" &&
|
|
358
358
|
signature.action.type !== "permit2SignatureTransfer");
|
|
359
|
-
throw new UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization"
|
|
360
|
-
? "authorization"
|
|
361
|
-
: unexpected?.action.type === "midnightOfferRootSignature"
|
|
362
|
-
? "midnightOfferRootSignature"
|
|
363
|
-
: "permit");
|
|
359
|
+
throw new UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization" ? "authorization" : "permit");
|
|
364
360
|
}
|
|
365
361
|
if (selected.length > 1) {
|
|
366
362
|
throw new AmbiguousRequirementSignaturesError("permit", selected.length);
|
|
@@ -412,14 +408,17 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
412
408
|
* @internal
|
|
413
409
|
*
|
|
414
410
|
* @param signatures - Signatures passed to the operation's `buildTx` function.
|
|
415
|
-
* @param expected - Immutable spender, amount, and deadline required by the operation.
|
|
411
|
+
* @param expected - Immutable spender, amount bounds, and deadline required by the operation.
|
|
416
412
|
* @param expected.spender - Fixed bundles contract the permit must authorize.
|
|
417
|
-
* @param expected.amount -
|
|
413
|
+
* @param expected.amount - Minimum share allowance the permit must cover.
|
|
414
|
+
* @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
|
|
415
|
+
* `expected.amount`, which accepts only an exact match.
|
|
418
416
|
* @param expected.deadline - Deadline the permit must carry.
|
|
419
417
|
* @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
|
|
420
|
-
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612
|
|
421
|
-
*
|
|
422
|
-
*
|
|
418
|
+
* @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
|
|
419
|
+
* deadline differ from the operation's, its signed amount differs from its action's amount, or
|
|
420
|
+
* its amount is outside `[expected.amount, expected.maxAmount ?? expected.amount]`.
|
|
421
|
+
* The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
|
|
423
422
|
*/
|
|
424
423
|
export const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
425
424
|
const { permit } = selectRequirementSignatures(signatures, { permit: true });
|
|
@@ -440,11 +439,21 @@ export const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
|
440
439
|
actual: action.args.spender,
|
|
441
440
|
});
|
|
442
441
|
}
|
|
443
|
-
|
|
444
|
-
|
|
442
|
+
const maxAmount = expected.maxAmount ?? expected.amount;
|
|
443
|
+
const expectedAmount = expected.maxAmount == null || expected.maxAmount === expected.amount
|
|
444
|
+
? String(expected.amount)
|
|
445
|
+
: `[${expected.amount}, ${expected.maxAmount}]`;
|
|
446
|
+
if (permit.args.amount !== action.args.amount) {
|
|
445
447
|
throw new BundlesPermitMismatchError({
|
|
446
448
|
field: "amount",
|
|
447
|
-
expected: String(
|
|
449
|
+
expected: String(action.args.amount),
|
|
450
|
+
actual: String(permit.args.amount),
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
if (permit.args.amount < expected.amount || permit.args.amount > maxAmount) {
|
|
454
|
+
throw new BundlesPermitMismatchError({
|
|
455
|
+
field: "amount",
|
|
456
|
+
expected: expectedAmount,
|
|
448
457
|
actual: String(permit.args.amount),
|
|
449
458
|
});
|
|
450
459
|
}
|
|
@@ -9,7 +9,8 @@ export interface MidnightSetIsAuthorizedParams {
|
|
|
9
9
|
readonly metadata?: Metadata;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Encodes `Midnight.setIsAuthorized
|
|
12
|
+
* Encodes `Midnight.setIsAuthorized`. Grants target MidnightBundlesV2;
|
|
13
|
+
* revocations accept any operator.
|
|
13
14
|
*
|
|
14
15
|
* Prefer requirement helpers or entity `getRequirements()` in app flows; they
|
|
15
16
|
* read `isAuthorized` first and return this transaction only when needed. Use
|
|
@@ -29,7 +30,7 @@ export interface MidnightSetIsAuthorizedParams {
|
|
|
29
30
|
*
|
|
30
31
|
* const tx = midnightSetIsAuthorized({
|
|
31
32
|
* chainId: 8453,
|
|
32
|
-
* authorized:
|
|
33
|
+
* authorized: midnightBundlesV2,
|
|
33
34
|
* onBehalf: user,
|
|
34
35
|
* });
|
|
35
36
|
* ```
|
|
@@ -4,7 +4,8 @@ import { encodeFunctionData } from "viem";
|
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
5
|
import { validateMidnightAuthorizationTarget } from "../../helpers/validateMidnightAuthorizationTarget.js";
|
|
6
6
|
/**
|
|
7
|
-
* Encodes `Midnight.setIsAuthorized
|
|
7
|
+
* Encodes `Midnight.setIsAuthorized`. Grants target MidnightBundlesV2;
|
|
8
|
+
* revocations accept any operator.
|
|
8
9
|
*
|
|
9
10
|
* Prefer requirement helpers or entity `getRequirements()` in app flows; they
|
|
10
11
|
* read `isAuthorized` first and return this transaction only when needed. Use
|
|
@@ -24,7 +25,7 @@ import { validateMidnightAuthorizationTarget } from "../../helpers/validateMidni
|
|
|
24
25
|
*
|
|
25
26
|
* const tx = midnightSetIsAuthorized({
|
|
26
27
|
* chainId: 8453,
|
|
27
|
-
* authorized:
|
|
28
|
+
* authorized: midnightBundlesV2,
|
|
28
29
|
* onBehalf: user,
|
|
29
30
|
* });
|
|
30
31
|
* ```
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address, type Hex } from "viem";
|
|
3
|
+
import { type Metadata, type MidnightBlueSupply, type MidnightCancelAndMakeAction, type MidnightCollateralTransfer, type MidnightGroupCancellation, type Transaction } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Delegated root-activation signature passed to the ratifier's `setIsRootRatifiedWithSig`.
|
|
6
|
+
* Omit it to activate the root directly with `setIsRootRatified`.
|
|
7
|
+
*/
|
|
8
|
+
export interface MidnightRootActivationSignature {
|
|
9
|
+
/** Tree height committed by the signature. */
|
|
10
|
+
readonly height: bigint;
|
|
11
|
+
/** Ratifier signature nonce. */
|
|
12
|
+
readonly nonce: bigint;
|
|
13
|
+
/** Signature deadline timestamp, independent of the bundle deadline. */
|
|
14
|
+
readonly deadline: bigint;
|
|
15
|
+
readonly v: number;
|
|
16
|
+
readonly r: Hex;
|
|
17
|
+
readonly s: Hex;
|
|
18
|
+
}
|
|
19
|
+
/** Collateral supplied for the maker before root activation; every offer must target `market`. */
|
|
20
|
+
export interface MidnightMakeBorrowCollateral {
|
|
21
|
+
readonly market: MarketInput;
|
|
22
|
+
readonly supplies: readonly MidnightCollateralTransfer[];
|
|
23
|
+
}
|
|
24
|
+
/** Offer root activated and published by a Midnight Bundles V2 maker bundle. */
|
|
25
|
+
export interface MidnightOfferPublication {
|
|
26
|
+
/**
|
|
27
|
+
* The chain's registered `priceRatifierV1` or `rateRatifierV1`, which activates `root`.
|
|
28
|
+
* MidnightBundlesV2 authorizes it over the maker's whole Midnight account.
|
|
29
|
+
*/
|
|
30
|
+
readonly ratifier: Address;
|
|
31
|
+
/** Offer tree root to activate. */
|
|
32
|
+
readonly root: Hex;
|
|
33
|
+
/** Distinct offer groups contained in `root`. */
|
|
34
|
+
readonly groups: readonly Hex[];
|
|
35
|
+
/** Encoded offer payload for `root`, published to the Midnight log. */
|
|
36
|
+
readonly payload: Hex;
|
|
37
|
+
/** Optional delegated root-activation signature. */
|
|
38
|
+
readonly rootSignature?: MidnightRootActivationSignature;
|
|
39
|
+
/** Optional loan assets parked on Morpho Blue for the maker; share-price slippage is not checked. */
|
|
40
|
+
readonly blueSupply?: MidnightBlueSupply;
|
|
41
|
+
/** Optional collateral supplied to `market` for the maker before activation. */
|
|
42
|
+
readonly collateral?: MidnightMakeBorrowCollateral;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parameters for encoding a Midnight Bundles V2 maker bundle: an offer publication or repost, or,
|
|
46
|
+
* without a publication, a cancellation of offer groups only.
|
|
47
|
+
*/
|
|
48
|
+
export interface MidnightCancelAndMakeParams {
|
|
49
|
+
/** Chain id used to resolve `MidnightBundlesV2`. */
|
|
50
|
+
readonly chainId: number;
|
|
51
|
+
/** Offer groups to cancel, each with its largest accepted consumption. Empty for a new publication. */
|
|
52
|
+
readonly cancellations: readonly MidnightGroupCancellation[];
|
|
53
|
+
/** Bundle execution deadline timestamp. Pass `maxUint256` explicitly for no expiry. */
|
|
54
|
+
readonly deadline: bigint;
|
|
55
|
+
/**
|
|
56
|
+
* Optional native ETH sent as `value`; the bundle wraps it into the chain's wNative and transfers
|
|
57
|
+
* it to `msg.sender` before pulling. It may cover part or all of the maximum wNative amount this
|
|
58
|
+
* call can pull, but not more. Any wrapped native not pulled stays in the sender's wallet as
|
|
59
|
+
* wNative. The wNative approval to `MidnightBundlesV2` is still required for the full pulled amount.
|
|
60
|
+
*/
|
|
61
|
+
readonly nativeAmount?: bigint;
|
|
62
|
+
/** Optional analytics metadata appended to calldata. */
|
|
63
|
+
readonly metadata?: Metadata;
|
|
64
|
+
/** Offers to publish after the cancellations. Omit to cancel offer groups only. */
|
|
65
|
+
readonly publication?: MidnightOfferPublication;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
|
|
69
|
+
* groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
|
|
70
|
+
* `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
|
|
71
|
+
* Without `publication`, it only cancels groups (`cancelOffers` uses this).
|
|
72
|
+
* Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
|
|
73
|
+
*
|
|
74
|
+
* The contract does not check that `payload` matches `root`; callers must derive both from the
|
|
75
|
+
* same tree. Prefer `client.morpho.midnight(chainId).makeLend(...)`,
|
|
76
|
+
* `makeBorrow(...)`, `supplyCollateralMakeBorrow(...)`, or `supplyBlueMakeLend(...)`, which derive
|
|
77
|
+
* the tree data and resolve the requirements for each flow; `supplyBlueMakeLend` also runs the
|
|
78
|
+
* Blue parking checks (callback, callbackData, empty-market and zero-share guards) that this builder
|
|
79
|
+
* skips.
|
|
80
|
+
*
|
|
81
|
+
* @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
|
|
82
|
+
* @param params.cancellations - Offer groups to cancel and their consumption ceilings.
|
|
83
|
+
* @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
|
|
84
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
85
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
|
|
86
|
+
* maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
|
|
87
|
+
* the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
|
|
88
|
+
* for the full pulled amount.
|
|
89
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
90
|
+
* @param params.publication - Offers to publish after the cancellations; omit for cancellation only.
|
|
91
|
+
* @param params.publication.ratifier - The chain's registered `priceRatifierV1` or `rateRatifierV1`,
|
|
92
|
+
* which activates the offer root.
|
|
93
|
+
* @param params.publication.root - Offer tree root to activate.
|
|
94
|
+
* @param params.publication.groups - Distinct offer groups contained in the root.
|
|
95
|
+
* @param params.publication.payload - Encoded offer payload published to the Midnight log.
|
|
96
|
+
* @param params.publication.rootSignature - Optional delegated root-activation signature; omitted, all fields are zero.
|
|
97
|
+
* @param params.publication.rootSignature.height - Tree height committed by the signature.
|
|
98
|
+
* @param params.publication.rootSignature.nonce - Ratifier signature nonce.
|
|
99
|
+
* @param params.publication.rootSignature.deadline - Signature deadline timestamp, independent of the bundle `deadline`.
|
|
100
|
+
* @param params.publication.rootSignature.v - Signature recovery id.
|
|
101
|
+
* @param params.publication.rootSignature.r - Signature `r` component.
|
|
102
|
+
* @param params.publication.rootSignature.s - Signature `s` component.
|
|
103
|
+
* @param params.publication.blueSupply - Optional loan assets to supply on Blue for the maker's `BlueBuyCallback`.
|
|
104
|
+
* @param params.publication.blueSupply.market - Blue market receiving the loan assets.
|
|
105
|
+
* @param params.publication.blueSupply.assets - Loan assets pulled from `msg.sender` and supplied on Blue; must be positive.
|
|
106
|
+
* @param params.publication.blueSupply.callbackSalt - Salt selecting the maker's `BlueBuyCallback`.
|
|
107
|
+
* @param params.publication.collateral - Optional collateral to supply on `collateral.market` for `msg.sender`.
|
|
108
|
+
* @param params.publication.collateral.market - Midnight market receiving the collateral; every offer must target it.
|
|
109
|
+
* @param params.publication.collateral.supplies - Collateral index and assets per supply; must not be empty.
|
|
110
|
+
* @returns Deep-frozen transaction targeting `MidnightBundlesV2`.
|
|
111
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
112
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
113
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when the ratifier is not the chain's registered `priceRatifierV1` or `rateRatifierV1`.
|
|
114
|
+
* @throws {EmptyMidnightGroupCancellationsError} when nothing is published and no groups are cancelled.
|
|
115
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
116
|
+
* @throws {InvalidTreeError} when `root` is zero, or `payload` or `groups` is empty.
|
|
117
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
118
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
119
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
120
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
|
|
121
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, or `deadline` or a collateral supply amount exceeds `uint256`, or `nativeAmount` exceeds the maximum wNative pull, including zero when no wNative is pulled.
|
|
122
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
123
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when configured token pulls contain no wNative token.
|
|
124
|
+
* @throws {ChainIdMismatchError} when the collateral market targets another chain.
|
|
125
|
+
* @throws {MidnightMarketAddressMismatchError} when the collateral market targets another Midnight deployment.
|
|
126
|
+
* @throws {UnknownCollateralIndexError} when a collateral index is not configured on the market.
|
|
127
|
+
* @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
|
|
128
|
+
* @throws {NonPositiveInputError} when `blueSupply.assets` is non-positive.
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
132
|
+
* import { maxUint256, type Hex } from "viem";
|
|
133
|
+
* import { midnightCancelAndMake } from "@morpho-org/morpho-sdk";
|
|
134
|
+
*
|
|
135
|
+
* const rateRatifierV1 = getChainAddress(8453, "rateRatifierV1");
|
|
136
|
+
* declare const root: Hex;
|
|
137
|
+
* declare const group: Hex;
|
|
138
|
+
* declare const payload: Hex;
|
|
139
|
+
* declare const previousGroup: Hex;
|
|
140
|
+
* const tx = midnightCancelAndMake({
|
|
141
|
+
* chainId: 8453,
|
|
142
|
+
* cancellations: [{ group: previousGroup, maxConsumed: 0n }],
|
|
143
|
+
* deadline: maxUint256,
|
|
144
|
+
* publication: {
|
|
145
|
+
* ratifier: rateRatifierV1,
|
|
146
|
+
* root,
|
|
147
|
+
* groups: [group],
|
|
148
|
+
* payload,
|
|
149
|
+
* },
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare const midnightCancelAndMake: (params: MidnightCancelAndMakeParams) => Readonly<Transaction<MidnightCancelAndMakeAction>>;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { InvalidTreeError, MarketUtils, midnightBundlesV2Abi, } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress, getChainAddresses, } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { encodeFunctionData, isAddressEqual, maxUint128, maxUint256, zeroAddress, zeroHash, } from "viem";
|
|
4
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
+
import { validateDeadline, validateMidnightNativeAmount, } from "../../helpers/validate.js";
|
|
6
|
+
import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
|
|
7
|
+
import { DuplicateMidnightGroupCancellationError, EmptyMidnightCollateralSuppliesError, EmptyMidnightGroupCancellationsError, InputExceedsMaxError, MidnightReplacementGroupCancelledError, NegativeInputError, NonPositiveInputError, UnsupportedMidnightAuthorizationTargetError, } from "../../types/index.js";
|
|
8
|
+
/** Blue market argument for `MidnightBundlesV2` calls that park no loan assets. */
|
|
9
|
+
const emptyBlueMarket = {
|
|
10
|
+
loanToken: zeroAddress,
|
|
11
|
+
collateralToken: zeroAddress,
|
|
12
|
+
oracle: zeroAddress,
|
|
13
|
+
irm: zeroAddress,
|
|
14
|
+
lltv: 0n,
|
|
15
|
+
};
|
|
16
|
+
/** Midnight market argument for `MidnightBundlesV2` calls that supply no collateral. */
|
|
17
|
+
const emptyMidnightMarket = {
|
|
18
|
+
chainId: 0n,
|
|
19
|
+
midnight: zeroAddress,
|
|
20
|
+
loanToken: zeroAddress,
|
|
21
|
+
collateralParams: [],
|
|
22
|
+
maturity: 0n,
|
|
23
|
+
rcfThreshold: 0n,
|
|
24
|
+
enterGate: zeroAddress,
|
|
25
|
+
liquidatorGate: zeroAddress,
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
|
|
29
|
+
* groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
|
|
30
|
+
* `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
|
|
31
|
+
* Without `publication`, it only cancels groups (`cancelOffers` uses this).
|
|
32
|
+
* Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
|
|
33
|
+
*
|
|
34
|
+
* The contract does not check that `payload` matches `root`; callers must derive both from the
|
|
35
|
+
* same tree. Prefer `client.morpho.midnight(chainId).makeLend(...)`,
|
|
36
|
+
* `makeBorrow(...)`, `supplyCollateralMakeBorrow(...)`, or `supplyBlueMakeLend(...)`, which derive
|
|
37
|
+
* the tree data and resolve the requirements for each flow; `supplyBlueMakeLend` also runs the
|
|
38
|
+
* Blue parking checks (callback, callbackData, empty-market and zero-share guards) that this builder
|
|
39
|
+
* skips.
|
|
40
|
+
*
|
|
41
|
+
* @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
|
|
42
|
+
* @param params.cancellations - Offer groups to cancel and their consumption ceilings.
|
|
43
|
+
* @param params.deadline - Bundle execution deadline timestamp; pass `maxUint256` explicitly for no expiry.
|
|
44
|
+
* @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
|
|
45
|
+
* chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
|
|
46
|
+
* maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
|
|
47
|
+
* the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
|
|
48
|
+
* for the full pulled amount.
|
|
49
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
50
|
+
* @param params.publication - Offers to publish after the cancellations; omit for cancellation only.
|
|
51
|
+
* @param params.publication.ratifier - The chain's registered `priceRatifierV1` or `rateRatifierV1`,
|
|
52
|
+
* which activates the offer root.
|
|
53
|
+
* @param params.publication.root - Offer tree root to activate.
|
|
54
|
+
* @param params.publication.groups - Distinct offer groups contained in the root.
|
|
55
|
+
* @param params.publication.payload - Encoded offer payload published to the Midnight log.
|
|
56
|
+
* @param params.publication.rootSignature - Optional delegated root-activation signature; omitted, all fields are zero.
|
|
57
|
+
* @param params.publication.rootSignature.height - Tree height committed by the signature.
|
|
58
|
+
* @param params.publication.rootSignature.nonce - Ratifier signature nonce.
|
|
59
|
+
* @param params.publication.rootSignature.deadline - Signature deadline timestamp, independent of the bundle `deadline`.
|
|
60
|
+
* @param params.publication.rootSignature.v - Signature recovery id.
|
|
61
|
+
* @param params.publication.rootSignature.r - Signature `r` component.
|
|
62
|
+
* @param params.publication.rootSignature.s - Signature `s` component.
|
|
63
|
+
* @param params.publication.blueSupply - Optional loan assets to supply on Blue for the maker's `BlueBuyCallback`.
|
|
64
|
+
* @param params.publication.blueSupply.market - Blue market receiving the loan assets.
|
|
65
|
+
* @param params.publication.blueSupply.assets - Loan assets pulled from `msg.sender` and supplied on Blue; must be positive.
|
|
66
|
+
* @param params.publication.blueSupply.callbackSalt - Salt selecting the maker's `BlueBuyCallback`.
|
|
67
|
+
* @param params.publication.collateral - Optional collateral to supply on `collateral.market` for `msg.sender`.
|
|
68
|
+
* @param params.publication.collateral.market - Midnight market receiving the collateral; every offer must target it.
|
|
69
|
+
* @param params.publication.collateral.supplies - Collateral index and assets per supply; must not be empty.
|
|
70
|
+
* @returns Deep-frozen transaction targeting `MidnightBundlesV2`.
|
|
71
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
72
|
+
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
73
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when the ratifier is not the chain's registered `priceRatifierV1` or `rateRatifierV1`.
|
|
74
|
+
* @throws {EmptyMidnightGroupCancellationsError} when nothing is published and no groups are cancelled.
|
|
75
|
+
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
76
|
+
* @throws {InvalidTreeError} when `root` is zero, or `payload` or `groups` is empty.
|
|
77
|
+
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
78
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
79
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
80
|
+
* @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
|
|
81
|
+
* @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, or `deadline` or a collateral supply amount exceeds `uint256`, or `nativeAmount` exceeds the maximum wNative pull, including zero when no wNative is pulled.
|
|
82
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
83
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when configured token pulls contain no wNative token.
|
|
84
|
+
* @throws {ChainIdMismatchError} when the collateral market targets another chain.
|
|
85
|
+
* @throws {MidnightMarketAddressMismatchError} when the collateral market targets another Midnight deployment.
|
|
86
|
+
* @throws {UnknownCollateralIndexError} when a collateral index is not configured on the market.
|
|
87
|
+
* @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
|
|
88
|
+
* @throws {NonPositiveInputError} when `blueSupply.assets` is non-positive.
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
92
|
+
* import { maxUint256, type Hex } from "viem";
|
|
93
|
+
* import { midnightCancelAndMake } from "@morpho-org/morpho-sdk";
|
|
94
|
+
*
|
|
95
|
+
* const rateRatifierV1 = getChainAddress(8453, "rateRatifierV1");
|
|
96
|
+
* declare const root: Hex;
|
|
97
|
+
* declare const group: Hex;
|
|
98
|
+
* declare const payload: Hex;
|
|
99
|
+
* declare const previousGroup: Hex;
|
|
100
|
+
* const tx = midnightCancelAndMake({
|
|
101
|
+
* chainId: 8453,
|
|
102
|
+
* cancellations: [{ group: previousGroup, maxConsumed: 0n }],
|
|
103
|
+
* deadline: maxUint256,
|
|
104
|
+
* publication: {
|
|
105
|
+
* ratifier: rateRatifierV1,
|
|
106
|
+
* root,
|
|
107
|
+
* groups: [group],
|
|
108
|
+
* payload,
|
|
109
|
+
* },
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export const midnightCancelAndMake = (params) => {
|
|
114
|
+
validateDeadline(params.deadline);
|
|
115
|
+
const cancelledGroups = new Set();
|
|
116
|
+
for (const [index, { group, maxConsumed },] of params.cancellations.entries()) {
|
|
117
|
+
const field = `cancellations[${index}].maxConsumed`;
|
|
118
|
+
if (maxConsumed < 0n)
|
|
119
|
+
throw new NegativeInputError(field, maxConsumed);
|
|
120
|
+
if (maxConsumed > maxUint128) {
|
|
121
|
+
throw new InputExceedsMaxError({
|
|
122
|
+
field,
|
|
123
|
+
value: maxConsumed,
|
|
124
|
+
max: maxUint128,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const key = group.toLowerCase();
|
|
128
|
+
if (cancelledGroups.has(key)) {
|
|
129
|
+
throw new DuplicateMidnightGroupCancellationError({ index, group });
|
|
130
|
+
}
|
|
131
|
+
cancelledGroups.add(key);
|
|
132
|
+
}
|
|
133
|
+
const publication = params.publication;
|
|
134
|
+
if (publication == null) {
|
|
135
|
+
if (params.cancellations.length === 0) {
|
|
136
|
+
throw new EmptyMidnightGroupCancellationsError();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (publication.root === zeroHash) {
|
|
141
|
+
throw new InvalidTreeError("Offer root cannot be zero.");
|
|
142
|
+
}
|
|
143
|
+
if (publication.payload === "0x") {
|
|
144
|
+
throw new InvalidTreeError("Offer payload cannot be empty.");
|
|
145
|
+
}
|
|
146
|
+
if (publication.groups.length === 0) {
|
|
147
|
+
throw new InvalidTreeError("Offer groups cannot be empty.");
|
|
148
|
+
}
|
|
149
|
+
const { priceRatifierV1, rateRatifierV1 } = getChainAddresses(params.chainId);
|
|
150
|
+
const supportedTargets = [priceRatifierV1, rateRatifierV1].filter((target) => target != null);
|
|
151
|
+
if (!supportedTargets.some((target) => isAddressEqual(publication.ratifier, target))) {
|
|
152
|
+
throw new UnsupportedMidnightAuthorizationTargetError({
|
|
153
|
+
authorized: publication.ratifier,
|
|
154
|
+
chainId: params.chainId,
|
|
155
|
+
supportedTargets,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
for (const group of publication.groups) {
|
|
159
|
+
if (cancelledGroups.has(group.toLowerCase())) {
|
|
160
|
+
throw new MidnightReplacementGroupCancelledError({ group });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (publication.blueSupply != null && publication.blueSupply.assets <= 0n) {
|
|
164
|
+
throw new NonPositiveInputError("blueSupply.assets", publication.blueSupply.assets);
|
|
165
|
+
}
|
|
166
|
+
if (publication.collateral != null) {
|
|
167
|
+
if (publication.collateral.supplies.length === 0) {
|
|
168
|
+
throw new EmptyMidnightCollateralSuppliesError();
|
|
169
|
+
}
|
|
170
|
+
validateMidnightMarket({
|
|
171
|
+
market: publication.collateral.market,
|
|
172
|
+
chainId: params.chainId,
|
|
173
|
+
});
|
|
174
|
+
for (const [index, { collateralIndex, assets },] of publication.collateral.supplies.entries()) {
|
|
175
|
+
if (assets <= 0n) {
|
|
176
|
+
throw new NonPositiveInputError(`collateral.supplies[${index}].assets`, assets);
|
|
177
|
+
}
|
|
178
|
+
if (assets > maxUint256) {
|
|
179
|
+
throw new InputExceedsMaxError({
|
|
180
|
+
field: `collateral.supplies[${index}].assets`,
|
|
181
|
+
value: assets,
|
|
182
|
+
max: maxUint256,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// Throws UnknownCollateralIndexError when the index is not configured on the market.
|
|
186
|
+
MarketUtils.getCollateralByIndex(publication.collateral.market, collateralIndex);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const collateral = publication?.collateral;
|
|
191
|
+
const collateralPulls = collateral == null
|
|
192
|
+
? []
|
|
193
|
+
: collateral.supplies.map(({ collateralIndex, assets }) => ({
|
|
194
|
+
token: MarketUtils.getCollateralByIndex(collateral.market, collateralIndex).token,
|
|
195
|
+
assets,
|
|
196
|
+
}));
|
|
197
|
+
const nativeFunding = validateMidnightNativeAmount({
|
|
198
|
+
chainId: params.chainId,
|
|
199
|
+
nativeAmount: params.nativeAmount,
|
|
200
|
+
pulls: [
|
|
201
|
+
...(publication?.blueSupply != null && publication.blueSupply.assets > 0n
|
|
202
|
+
? [
|
|
203
|
+
{
|
|
204
|
+
token: publication.blueSupply.market.loanToken,
|
|
205
|
+
assets: publication.blueSupply.assets,
|
|
206
|
+
},
|
|
207
|
+
]
|
|
208
|
+
: []),
|
|
209
|
+
...collateralPulls,
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
const cancellations = params.cancellations.map(({ group, maxConsumed }) => ({
|
|
213
|
+
group,
|
|
214
|
+
maxConsumed,
|
|
215
|
+
}));
|
|
216
|
+
const supplies = (publication?.collateral?.supplies ?? []).map(({ collateralIndex, assets }) => ({ collateralIndex, assets }));
|
|
217
|
+
const blueSupply = publication?.blueSupply == null
|
|
218
|
+
? undefined
|
|
219
|
+
: {
|
|
220
|
+
market: {
|
|
221
|
+
loanToken: publication.blueSupply.market.loanToken,
|
|
222
|
+
collateralToken: publication.blueSupply.market.collateralToken,
|
|
223
|
+
oracle: publication.blueSupply.market.oracle,
|
|
224
|
+
irm: publication.blueSupply.market.irm,
|
|
225
|
+
lltv: publication.blueSupply.market.lltv,
|
|
226
|
+
},
|
|
227
|
+
assets: publication.blueSupply.assets,
|
|
228
|
+
callbackSalt: publication.blueSupply.callbackSalt,
|
|
229
|
+
};
|
|
230
|
+
const signature = publication?.rootSignature ?? {
|
|
231
|
+
height: 0n,
|
|
232
|
+
nonce: 0n,
|
|
233
|
+
deadline: 0n,
|
|
234
|
+
v: 0,
|
|
235
|
+
r: zeroHash,
|
|
236
|
+
s: zeroHash,
|
|
237
|
+
};
|
|
238
|
+
let tx = {
|
|
239
|
+
to: getChainAddress(params.chainId, "midnightBundlesV2"),
|
|
240
|
+
value: nativeFunding.value,
|
|
241
|
+
data: encodeFunctionData({
|
|
242
|
+
abi: midnightBundlesV2Abi,
|
|
243
|
+
functionName: "midnightBundlesV2CancelAndMake",
|
|
244
|
+
args: [
|
|
245
|
+
blueSupply?.market ?? emptyBlueMarket, // blueMarket
|
|
246
|
+
blueSupply?.assets ?? 0n, // assetsToPark
|
|
247
|
+
blueSupply?.callbackSalt ?? zeroHash, // callbackSalt
|
|
248
|
+
publication?.collateral == null
|
|
249
|
+
? emptyMidnightMarket
|
|
250
|
+
: MarketUtils.toStruct(publication.collateral.market), // market
|
|
251
|
+
supplies, // collateralSupplies
|
|
252
|
+
publication?.ratifier ?? zeroAddress, // ratifier
|
|
253
|
+
publication?.root ?? zeroHash, // newRoot
|
|
254
|
+
signature.height, // signatureHeight
|
|
255
|
+
signature.nonce, // signatureNonce
|
|
256
|
+
signature.deadline, // signatureDeadline
|
|
257
|
+
signature.v, // v
|
|
258
|
+
signature.r, // r
|
|
259
|
+
signature.s, // s
|
|
260
|
+
cancellations, // groupsToCancel
|
|
261
|
+
publication?.payload ?? "0x", // payload
|
|
262
|
+
params.deadline, // deadline
|
|
263
|
+
nativeFunding.wrappedNative, // wrappedNative
|
|
264
|
+
],
|
|
265
|
+
}),
|
|
266
|
+
};
|
|
267
|
+
if (params.metadata) {
|
|
268
|
+
tx = addTransactionMetadata(tx, params.metadata);
|
|
269
|
+
}
|
|
270
|
+
return deepFreeze({
|
|
271
|
+
...tx,
|
|
272
|
+
action: {
|
|
273
|
+
type: "midnightCancelAndMake",
|
|
274
|
+
args: {
|
|
275
|
+
market: publication?.collateral == null
|
|
276
|
+
? zeroHash
|
|
277
|
+
: MarketUtils.toId(publication.collateral.market),
|
|
278
|
+
ratifier: publication?.ratifier ?? zeroAddress,
|
|
279
|
+
root: publication?.root ?? zeroHash,
|
|
280
|
+
groups: [...(publication?.groups ?? [])],
|
|
281
|
+
cancellations,
|
|
282
|
+
collateralSupplies: supplies,
|
|
283
|
+
...(blueSupply && { blueSupply }),
|
|
284
|
+
deadline: params.deadline,
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from "./authorization.js";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./mempoolSubmitOffers.js";
|
|
2
|
+
export * from "./cancelAndMake.js";
|
|
4
3
|
export * from "./redeem.js";
|
|
5
4
|
export * from "./repayWithdrawCollateral.js";
|
|
6
|
-
export * from "./setterRatifierRatifyRoot.js";
|
|
7
5
|
export * from "./supplyCollateral.js";
|
|
8
6
|
export * from "./supplyCollateralTakeBorrow.js";
|
|
9
7
|
export * from "./takeBorrow.js";
|
|
10
8
|
export * from "./takeLend.js";
|
|
9
|
+
export * from "./takeRepayWithdrawCollateral.js";
|
|
10
|
+
export * from "./takeWithdraw.js";
|
|
11
11
|
export * from "./types.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from "./authorization.js";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./mempoolSubmitOffers.js";
|
|
2
|
+
export * from "./cancelAndMake.js";
|
|
4
3
|
export * from "./redeem.js";
|
|
5
4
|
export * from "./repayWithdrawCollateral.js";
|
|
6
|
-
export * from "./setterRatifierRatifyRoot.js";
|
|
7
5
|
export * from "./supplyCollateral.js";
|
|
8
6
|
export * from "./supplyCollateralTakeBorrow.js";
|
|
9
7
|
export * from "./takeBorrow.js";
|
|
10
8
|
export * from "./takeLend.js";
|
|
9
|
+
export * from "./takeRepayWithdrawCollateral.js";
|
|
10
|
+
export * from "./takeWithdraw.js";
|
|
11
11
|
export * from "./types.js";
|