@morpho-org/morpho-sdk 6.5.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.
Files changed (167) hide show
  1. package/MIGRATION-v6-to-v7.md +291 -0
  2. package/README.md +26 -12
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +3 -2
  5. package/lib/cjs/actions/bundles/common.d.ts +9 -5
  6. package/lib/cjs/actions/bundles/common.js +22 -13
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
  8. package/lib/cjs/actions/midnight/authorization.js +3 -2
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +3 -3
  12. package/lib/cjs/actions/midnight/index.js +3 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
  18. package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
  20. package/lib/cjs/actions/midnight/takeLend.js +111 -54
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
  25. package/lib/cjs/actions/midnight/types.d.ts +7 -26
  26. package/lib/cjs/actions/midnight/types.js +0 -13
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
  32. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  37. package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
  38. package/lib/cjs/actions/requirements/midnight/index.js +0 -1
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +3 -1
  41. package/lib/cjs/entities/blue/blue.d.ts +10 -6
  42. package/lib/cjs/entities/blue/blue.js +5 -3
  43. package/lib/cjs/entities/index.d.ts +2 -2
  44. package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
  45. package/lib/cjs/entities/midnight/midnight.js +981 -509
  46. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  47. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
  48. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -3
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +119 -43
  53. package/lib/cjs/helpers/callback.d.ts +54 -0
  54. package/lib/cjs/helpers/callback.js +73 -0
  55. package/lib/cjs/helpers/constant.d.ts +10 -0
  56. package/lib/cjs/helpers/constant.js +11 -1
  57. package/lib/cjs/helpers/index.d.ts +3 -2
  58. package/lib/cjs/helpers/index.js +7 -1
  59. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  60. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  61. package/lib/cjs/helpers/utilization.d.ts +13 -0
  62. package/lib/cjs/helpers/utilization.js +26 -1
  63. package/lib/cjs/helpers/validate.d.ts +43 -2
  64. package/lib/cjs/helpers/validate.js +60 -3
  65. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  66. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  67. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  68. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  69. package/lib/cjs/midnight/abis.d.ts +1 -1
  70. package/lib/cjs/midnight/abis.js +3 -2
  71. package/lib/cjs/midnight/types.d.ts +1 -1
  72. package/lib/cjs/types/action.d.ts +117 -89
  73. package/lib/cjs/types/action.js +1 -19
  74. package/lib/cjs/types/error.d.ts +126 -40
  75. package/lib/cjs/types/error.js +154 -49
  76. package/lib/cjs/types/sharedLiquidity.d.ts +17 -0
  77. package/lib/esm/abis.d.ts +1 -1
  78. package/lib/esm/abis.js +1 -1
  79. package/lib/esm/actions/bundles/common.d.ts +9 -5
  80. package/lib/esm/actions/bundles/common.js +22 -13
  81. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  82. package/lib/esm/actions/midnight/authorization.js +3 -2
  83. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  84. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  85. package/lib/esm/actions/midnight/index.d.ts +3 -3
  86. package/lib/esm/actions/midnight/index.js +3 -3
  87. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  88. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  89. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  90. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  91. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  92. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  93. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  94. package/lib/esm/actions/midnight/takeLend.js +114 -57
  95. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  96. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  97. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  98. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  99. package/lib/esm/actions/midnight/types.d.ts +7 -26
  100. package/lib/esm/actions/midnight/types.js +1 -12
  101. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  102. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  105. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  106. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  107. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  108. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  109. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  110. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  111. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  112. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  113. package/lib/esm/constants.d.ts +1 -1
  114. package/lib/esm/constants.js +1 -1
  115. package/lib/esm/entities/blue/blue.d.ts +10 -6
  116. package/lib/esm/entities/blue/blue.js +5 -3
  117. package/lib/esm/entities/index.d.ts +2 -2
  118. package/lib/esm/entities/midnight/midnight.d.ts +582 -108
  119. package/lib/esm/entities/midnight/midnight.js +987 -515
  120. package/lib/esm/entities/midnight/types.d.ts +142 -60
  121. package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
  122. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  123. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
  124. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  125. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -3
  126. package/lib/esm/entities/vaultV2BlueReallocationData.js +120 -44
  127. package/lib/esm/helpers/callback.d.ts +54 -0
  128. package/lib/esm/helpers/callback.js +68 -0
  129. package/lib/esm/helpers/constant.d.ts +10 -0
  130. package/lib/esm/helpers/constant.js +10 -0
  131. package/lib/esm/helpers/index.d.ts +3 -2
  132. package/lib/esm/helpers/index.js +3 -2
  133. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  134. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  135. package/lib/esm/helpers/utilization.d.ts +13 -0
  136. package/lib/esm/helpers/utilization.js +25 -1
  137. package/lib/esm/helpers/validate.d.ts +43 -2
  138. package/lib/esm/helpers/validate.js +58 -2
  139. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  140. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  141. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  142. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  143. package/lib/esm/midnight/abis.d.ts +1 -1
  144. package/lib/esm/midnight/abis.js +1 -1
  145. package/lib/esm/midnight/types.d.ts +1 -1
  146. package/lib/esm/types/action.d.ts +117 -89
  147. package/lib/esm/types/action.js +1 -18
  148. package/lib/esm/types/error.d.ts +126 -40
  149. package/lib/esm/types/error.js +135 -38
  150. package/lib/esm/types/sharedLiquidity.d.ts +17 -0
  151. package/package.json +9 -8
  152. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  153. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  154. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  155. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  156. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  157. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  158. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  159. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  160. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  161. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  162. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  163. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  164. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  165. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  166. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  167. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -1,42 +0,0 @@
1
- import { type Address, type Client, type Hex } from "viem";
2
- import type { SetterRatifierRatifyRootAction, Transaction } from "../../../types/index.js";
3
- /** Parameters for {@link getSetterRatifierRatifyRootRequirement}. */
4
- export interface GetSetterRatifierRatifyRootRequirementParams {
5
- readonly viemClient: Client;
6
- readonly chainId: number;
7
- readonly maker: Address;
8
- readonly root: Hex;
9
- }
10
- /**
11
- * Resolves the SetterRatifier root approval transaction for a maker offer tree.
12
- *
13
- * Call after building a Setter-ratified tree and before encoding/submitting its
14
- * payload. Entity make-offer flows call this from `getRequirements()` and omit
15
- * the transaction when the maker has already approved the root.
16
- *
17
- * @param params.viemClient - Viem client used to read root approval state.
18
- * @param params.chainId - Chain id expected by the viem client.
19
- * @param params.maker - Maker whose root approval is checked.
20
- * @param params.root - Offer-tree root that must be approved.
21
- * @returns Ratify-root transaction, or `null` when the root is already ratified.
22
- * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
23
- * @example
24
- * ```ts
25
- * import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
26
- *
27
- * const tx = await getSetterRatifierRatifyRootRequirement({
28
- * viemClient: client,
29
- * chainId: 8453,
30
- * maker: user,
31
- * root,
32
- * });
33
- * if (tx) {
34
- * await walletClient.sendTransaction({
35
- * to: tx.to,
36
- * data: tx.data,
37
- * value: tx.value,
38
- * });
39
- * }
40
- * ```
41
- */
42
- export declare const getSetterRatifierRatifyRootRequirement: (params: GetSetterRatifierRatifyRootRequirementParams) => Promise<Readonly<Transaction<SetterRatifierRatifyRootAction>> | null>;
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSetterRatifierRatifyRootRequirement = void 0;
4
- const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
- const actions_1 = require("viem/actions");
8
- const index_js_1 = require("../../../helpers/index.js");
9
- /**
10
- * Resolves the SetterRatifier root approval transaction for a maker offer tree.
11
- *
12
- * Call after building a Setter-ratified tree and before encoding/submitting its
13
- * payload. Entity make-offer flows call this from `getRequirements()` and omit
14
- * the transaction when the maker has already approved the root.
15
- *
16
- * @param params.viemClient - Viem client used to read root approval state.
17
- * @param params.chainId - Chain id expected by the viem client.
18
- * @param params.maker - Maker whose root approval is checked.
19
- * @param params.root - Offer-tree root that must be approved.
20
- * @returns Ratify-root transaction, or `null` when the root is already ratified.
21
- * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
22
- * @example
23
- * ```ts
24
- * import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
25
- *
26
- * const tx = await getSetterRatifierRatifyRootRequirement({
27
- * viemClient: client,
28
- * chainId: 8453,
29
- * maker: user,
30
- * root,
31
- * });
32
- * if (tx) {
33
- * await walletClient.sendTransaction({
34
- * to: tx.to,
35
- * data: tx.data,
36
- * value: tx.value,
37
- * });
38
- * }
39
- * ```
40
- */
41
- const getSetterRatifierRatifyRootRequirement = async (params) => {
42
- (0, index_js_1.validateChainId)(params.viemClient.chain?.id, params.chainId);
43
- const setterRatifier = (0, morpho_ts_1.getChainAddress)(params.chainId, "setterRatifier");
44
- const isRootRatified = await (0, actions_1.readContract)(params.viemClient, {
45
- address: setterRatifier,
46
- abi: midnight_sdk_1.setterRatifierAbi,
47
- functionName: "isRootRatified",
48
- args: [params.maker, params.root],
49
- });
50
- if (isRootRatified)
51
- return null;
52
- return (0, morpho_ts_1.deepFreeze)({
53
- to: setterRatifier,
54
- value: 0n,
55
- data: (0, viem_1.encodeFunctionData)({
56
- abi: midnight_sdk_1.setterRatifierAbi,
57
- functionName: "setIsRootRatified",
58
- args: [params.maker, params.root, true],
59
- }),
60
- action: {
61
- type: "setterRatifierRatifyRoot",
62
- args: {
63
- maker: params.maker,
64
- root: params.root,
65
- isRootRatified: true,
66
- },
67
- },
68
- });
69
- };
70
- exports.getSetterRatifierRatifyRootRequirement = getSetterRatifierRatifyRootRequirement;
@@ -1,38 +0,0 @@
1
- import { type Address, type Hex } from "viem";
2
- import type { Metadata, MidnightCancelOfferAction, Transaction } from "../../types/index.js";
3
- /** Parameters for encoding a Midnight group consumption update. */
4
- export interface MidnightCancelOfferParams {
5
- readonly chainId: number;
6
- readonly group: Hex;
7
- readonly onBehalf: Address;
8
- readonly amount?: bigint;
9
- readonly metadata?: Metadata;
10
- }
11
- /**
12
- * Encodes `Midnight.setConsumed` to cancel or partially consume an offer group.
13
- *
14
- * App flows should usually call `client.morpho.midnight(chainId).cancelOffer(...)`.
15
- * Use this builder directly when the group id is already known and no
16
- * additional requirements are needed. Omitting `amount` fully cancels the group
17
- * by setting consumption to {@link MAX_OFFER_CAP}.
18
- *
19
- * @param params.chainId - Chain id used to resolve `Midnight`.
20
- * @param params.group - Offer group id to mark consumed.
21
- * @param params.onBehalf - Maker whose group consumption is updated.
22
- * @param params.amount - Optional consumed amount; defaults to {@link MAX_OFFER_CAP} for full cancellation.
23
- * @param params.metadata - Optional analytics metadata appended to calldata.
24
- * @returns A deep-frozen `Transaction<MidnightCancelOfferAction>` targeting `Midnight`.
25
- * @throws {NegativeInputError} when `amount` is negative.
26
- * @throws {MidnightAmountExceedsMaxOfferCapError} when `amount` exceeds {@link MAX_OFFER_CAP}.
27
- * @example
28
- * ```ts
29
- * import { midnightCancelOffer } from "@morpho-org/morpho-sdk";
30
- *
31
- * const tx = midnightCancelOffer({
32
- * chainId: 8453,
33
- * group,
34
- * onBehalf: maker,
35
- * });
36
- * ```
37
- */
38
- export declare const midnightCancelOffer: (params: MidnightCancelOfferParams) => Readonly<Transaction<MidnightCancelOfferAction>>;
@@ -1,69 +0,0 @@
1
- import { MAX_OFFER_CAP, midnightAbi } from "@morpho-org/midnight-sdk";
2
- import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
- import { encodeFunctionData } from "viem";
4
- import { addTransactionMetadata } from "../../helpers/index.js";
5
- import { MidnightAmountExceedsMaxOfferCapError, NegativeInputError, } from "../../types/index.js";
6
- /**
7
- * Encodes `Midnight.setConsumed` to cancel or partially consume an offer group.
8
- *
9
- * App flows should usually call `client.morpho.midnight(chainId).cancelOffer(...)`.
10
- * Use this builder directly when the group id is already known and no
11
- * additional requirements are needed. Omitting `amount` fully cancels the group
12
- * by setting consumption to {@link MAX_OFFER_CAP}.
13
- *
14
- * @param params.chainId - Chain id used to resolve `Midnight`.
15
- * @param params.group - Offer group id to mark consumed.
16
- * @param params.onBehalf - Maker whose group consumption is updated.
17
- * @param params.amount - Optional consumed amount; defaults to {@link MAX_OFFER_CAP} for full cancellation.
18
- * @param params.metadata - Optional analytics metadata appended to calldata.
19
- * @returns A deep-frozen `Transaction<MidnightCancelOfferAction>` targeting `Midnight`.
20
- * @throws {NegativeInputError} when `amount` is negative.
21
- * @throws {MidnightAmountExceedsMaxOfferCapError} when `amount` exceeds {@link MAX_OFFER_CAP}.
22
- * @example
23
- * ```ts
24
- * import { midnightCancelOffer } from "@morpho-org/morpho-sdk";
25
- *
26
- * const tx = midnightCancelOffer({
27
- * chainId: 8453,
28
- * group,
29
- * onBehalf: maker,
30
- * });
31
- * ```
32
- */
33
- export const midnightCancelOffer = (params) => {
34
- const midnight = getChainAddress(params.chainId, "midnight");
35
- const amount = params.amount ?? MAX_OFFER_CAP;
36
- if (amount < 0n) {
37
- throw new NegativeInputError("amount", amount);
38
- }
39
- if (amount > MAX_OFFER_CAP) {
40
- throw new MidnightAmountExceedsMaxOfferCapError({
41
- label: "cancel amount",
42
- amount,
43
- maxOfferCap: MAX_OFFER_CAP,
44
- });
45
- }
46
- let tx = {
47
- to: midnight,
48
- value: 0n,
49
- data: encodeFunctionData({
50
- abi: midnightAbi,
51
- functionName: "setConsumed",
52
- args: [params.group, amount, params.onBehalf],
53
- }),
54
- };
55
- if (params.metadata) {
56
- tx = addTransactionMetadata(tx, params.metadata);
57
- }
58
- return deepFreeze({
59
- ...tx,
60
- action: {
61
- type: "midnightCancelOffer",
62
- args: {
63
- group: params.group,
64
- amount,
65
- onBehalf: params.onBehalf,
66
- },
67
- },
68
- });
69
- };
@@ -1,52 +0,0 @@
1
- import type { Address, Hex } from "viem";
2
- import type { MempoolSubmitOffersAction, Metadata, Transaction } from "../../types/index.js";
3
- /** Parameters for publishing an already ratified Midnight offer payload. */
4
- export interface MempoolSubmitOffersParams {
5
- readonly chainId: number;
6
- readonly groups: readonly Hex[];
7
- readonly root: Hex;
8
- readonly maker: Address;
9
- readonly ratifier: Address;
10
- readonly ratifierType: "ecrecover" | "setter";
11
- readonly offers: number;
12
- readonly payload: Hex;
13
- readonly metadata?: Metadata;
14
- }
15
- /**
16
- * Encodes a Midnight mempool payload submission transaction.
17
- *
18
- * App make-offer flows should call `getOffersData`, gather the returned
19
- * requirements, then call the output `buildTx(signatures)`. Use this builder
20
- * directly only when the payload has already been encoded with ratifier data
21
- * and the caller wants to submit those bytes to the mempool contract.
22
- *
23
- * @param params.chainId - Chain id used to resolve `MidnightMempool`.
24
- * @param params.groups - Group ids included in the payload.
25
- * @param params.root - Offer tree root committed by the maker.
26
- * @param params.maker - Maker whose offers are submitted.
27
- * @param params.ratifier - Ratifier address shared by the offer tree.
28
- * @param params.ratifierType - Ratifier route used to build the payload.
29
- * @param params.offers - Number of non-padding offers in the payload.
30
- * @param params.payload - Encoded mempool payload bytes.
31
- * @param params.metadata - Optional analytics metadata appended to calldata.
32
- * @returns A deep-frozen `Transaction<MempoolSubmitOffersAction>` targeting `MidnightMempool`.
33
- * @throws {InvalidTreeError} when `offers <= 0`.
34
- * @example
35
- * ```ts
36
- * import { MidnightPayload } from "@morpho-org/morpho-sdk/utils";
37
- * import { mempoolSubmitOffers } from "@morpho-org/morpho-sdk";
38
- *
39
- * const payload = await MidnightPayload.encode(items);
40
- * const tx = mempoolSubmitOffers({
41
- * chainId: 8453,
42
- * groups,
43
- * root: tree.root,
44
- * maker,
45
- * ratifier,
46
- * ratifierType: "ecrecover",
47
- * offers: tree.offers.length,
48
- * payload,
49
- * });
50
- * ```
51
- */
52
- export declare const mempoolSubmitOffers: (params: MempoolSubmitOffersParams) => Readonly<Transaction<MempoolSubmitOffersAction>>;
@@ -1,68 +0,0 @@
1
- import { InvalidTreeError } from "@morpho-org/midnight-sdk";
2
- import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
- import { addTransactionMetadata } from "../../helpers/index.js";
4
- /**
5
- * Encodes a Midnight mempool payload submission transaction.
6
- *
7
- * App make-offer flows should call `getOffersData`, gather the returned
8
- * requirements, then call the output `buildTx(signatures)`. Use this builder
9
- * directly only when the payload has already been encoded with ratifier data
10
- * and the caller wants to submit those bytes to the mempool contract.
11
- *
12
- * @param params.chainId - Chain id used to resolve `MidnightMempool`.
13
- * @param params.groups - Group ids included in the payload.
14
- * @param params.root - Offer tree root committed by the maker.
15
- * @param params.maker - Maker whose offers are submitted.
16
- * @param params.ratifier - Ratifier address shared by the offer tree.
17
- * @param params.ratifierType - Ratifier route used to build the payload.
18
- * @param params.offers - Number of non-padding offers in the payload.
19
- * @param params.payload - Encoded mempool payload bytes.
20
- * @param params.metadata - Optional analytics metadata appended to calldata.
21
- * @returns A deep-frozen `Transaction<MempoolSubmitOffersAction>` targeting `MidnightMempool`.
22
- * @throws {InvalidTreeError} when `offers <= 0`.
23
- * @example
24
- * ```ts
25
- * import { MidnightPayload } from "@morpho-org/morpho-sdk/utils";
26
- * import { mempoolSubmitOffers } from "@morpho-org/morpho-sdk";
27
- *
28
- * const payload = await MidnightPayload.encode(items);
29
- * const tx = mempoolSubmitOffers({
30
- * chainId: 8453,
31
- * groups,
32
- * root: tree.root,
33
- * maker,
34
- * ratifier,
35
- * ratifierType: "ecrecover",
36
- * offers: tree.offers.length,
37
- * payload,
38
- * });
39
- * ```
40
- */
41
- export const mempoolSubmitOffers = (params) => {
42
- if (params.offers <= 0) {
43
- throw new InvalidTreeError("Tree must contain at least one offer.");
44
- }
45
- const midnightMempool = getChainAddress(params.chainId, "midnightMempool");
46
- let tx = {
47
- to: midnightMempool,
48
- value: 0n,
49
- data: params.payload,
50
- };
51
- if (params.metadata) {
52
- tx = addTransactionMetadata(tx, params.metadata);
53
- }
54
- return deepFreeze({
55
- ...tx,
56
- action: {
57
- type: "mempoolSubmitOffers",
58
- args: {
59
- groups: [...params.groups],
60
- root: params.root,
61
- maker: params.maker,
62
- ratifier: params.ratifier,
63
- ratifierType: params.ratifierType,
64
- offers: params.offers,
65
- },
66
- },
67
- });
68
- };
@@ -1,40 +0,0 @@
1
- import { type Address, type Hex } from "viem";
2
- import type { Metadata, SetterRatifierRatifyRootAction, Transaction } from "../../types/index.js";
3
- /** Parameters for {@link setterRatifierRatifyRoot}. */
4
- export interface SetterRatifierRatifyRootParams {
5
- /** Chain id used to resolve the SetterRatifier deployment. */
6
- readonly chainId: number;
7
- /** Maker whose offer-tree root is being ratified. */
8
- readonly maker: Address;
9
- /** Offer-tree root to ratify or unratify. */
10
- readonly root: Hex;
11
- /** Whether the root should be ratified. Defaults to `true`. */
12
- readonly isRootRatified?: boolean;
13
- /** Optional metadata appended to the transaction calldata. */
14
- readonly metadata?: Metadata;
15
- }
16
- /**
17
- * Encodes a SetterRatifier root-ratification transaction.
18
- *
19
- * Use this after building a Setter-ratified offer tree and before submitting
20
- * its mempool payload. Entity make-offer flows expose the same transaction
21
- * through `getRequirements()` when the root is not already approved.
22
- *
23
- * @param params.chainId - Chain id used to resolve `SetterRatifier`.
24
- * @param params.maker - Maker whose root approval is updated.
25
- * @param params.root - Offer-tree root to approve or revoke.
26
- * @param params.isRootRatified - Optional target state; defaults to `true`.
27
- * @param params.metadata - Optional analytics metadata appended to calldata.
28
- * @returns A deep-frozen `Transaction<SetterRatifierRatifyRootAction>` targeting `SetterRatifier`.
29
- * @example
30
- * ```ts
31
- * import { setterRatifierRatifyRoot } from "@morpho-org/morpho-sdk";
32
- *
33
- * const tx = setterRatifierRatifyRoot({
34
- * chainId: 8453,
35
- * maker,
36
- * root,
37
- * });
38
- * ```
39
- */
40
- export declare const setterRatifierRatifyRoot: (params: SetterRatifierRatifyRootParams) => Readonly<Transaction<SetterRatifierRatifyRootAction>>;
@@ -1,55 +0,0 @@
1
- import { setterRatifierAbi } from "@morpho-org/midnight-sdk";
2
- import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
- import { encodeFunctionData } from "viem";
4
- import { addTransactionMetadata } from "../../helpers/index.js";
5
- /**
6
- * Encodes a SetterRatifier root-ratification transaction.
7
- *
8
- * Use this after building a Setter-ratified offer tree and before submitting
9
- * its mempool payload. Entity make-offer flows expose the same transaction
10
- * through `getRequirements()` when the root is not already approved.
11
- *
12
- * @param params.chainId - Chain id used to resolve `SetterRatifier`.
13
- * @param params.maker - Maker whose root approval is updated.
14
- * @param params.root - Offer-tree root to approve or revoke.
15
- * @param params.isRootRatified - Optional target state; defaults to `true`.
16
- * @param params.metadata - Optional analytics metadata appended to calldata.
17
- * @returns A deep-frozen `Transaction<SetterRatifierRatifyRootAction>` targeting `SetterRatifier`.
18
- * @example
19
- * ```ts
20
- * import { setterRatifierRatifyRoot } from "@morpho-org/morpho-sdk";
21
- *
22
- * const tx = setterRatifierRatifyRoot({
23
- * chainId: 8453,
24
- * maker,
25
- * root,
26
- * });
27
- * ```
28
- */
29
- export const setterRatifierRatifyRoot = (params) => {
30
- const isRootRatified = params.isRootRatified ?? true;
31
- const setterRatifier = getChainAddress(params.chainId, "setterRatifier");
32
- let tx = {
33
- to: setterRatifier,
34
- value: 0n,
35
- data: encodeFunctionData({
36
- abi: setterRatifierAbi,
37
- functionName: "setIsRootRatified",
38
- args: [params.maker, params.root, isRootRatified],
39
- }),
40
- };
41
- if (params.metadata) {
42
- tx = addTransactionMetadata(tx, params.metadata);
43
- }
44
- return deepFreeze({
45
- ...tx,
46
- action: {
47
- type: "setterRatifierRatifyRoot",
48
- args: {
49
- maker: params.maker,
50
- root: params.root,
51
- isRootRatified,
52
- },
53
- },
54
- });
55
- };
@@ -1,42 +0,0 @@
1
- import { type Address, type Client, type Hex } from "viem";
2
- import type { SetterRatifierRatifyRootAction, Transaction } from "../../../types/index.js";
3
- /** Parameters for {@link getSetterRatifierRatifyRootRequirement}. */
4
- export interface GetSetterRatifierRatifyRootRequirementParams {
5
- readonly viemClient: Client;
6
- readonly chainId: number;
7
- readonly maker: Address;
8
- readonly root: Hex;
9
- }
10
- /**
11
- * Resolves the SetterRatifier root approval transaction for a maker offer tree.
12
- *
13
- * Call after building a Setter-ratified tree and before encoding/submitting its
14
- * payload. Entity make-offer flows call this from `getRequirements()` and omit
15
- * the transaction when the maker has already approved the root.
16
- *
17
- * @param params.viemClient - Viem client used to read root approval state.
18
- * @param params.chainId - Chain id expected by the viem client.
19
- * @param params.maker - Maker whose root approval is checked.
20
- * @param params.root - Offer-tree root that must be approved.
21
- * @returns Ratify-root transaction, or `null` when the root is already ratified.
22
- * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
23
- * @example
24
- * ```ts
25
- * import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
26
- *
27
- * const tx = await getSetterRatifierRatifyRootRequirement({
28
- * viemClient: client,
29
- * chainId: 8453,
30
- * maker: user,
31
- * root,
32
- * });
33
- * if (tx) {
34
- * await walletClient.sendTransaction({
35
- * to: tx.to,
36
- * data: tx.data,
37
- * value: tx.value,
38
- * });
39
- * }
40
- * ```
41
- */
42
- export declare const getSetterRatifierRatifyRootRequirement: (params: GetSetterRatifierRatifyRootRequirementParams) => Promise<Readonly<Transaction<SetterRatifierRatifyRootAction>> | null>;
@@ -1,66 +0,0 @@
1
- import { setterRatifierAbi } from "@morpho-org/midnight-sdk";
2
- import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
- import { encodeFunctionData } from "viem";
4
- import { readContract } from "viem/actions";
5
- import { validateChainId } from "../../../helpers/index.js";
6
- /**
7
- * Resolves the SetterRatifier root approval transaction for a maker offer tree.
8
- *
9
- * Call after building a Setter-ratified tree and before encoding/submitting its
10
- * payload. Entity make-offer flows call this from `getRequirements()` and omit
11
- * the transaction when the maker has already approved the root.
12
- *
13
- * @param params.viemClient - Viem client used to read root approval state.
14
- * @param params.chainId - Chain id expected by the viem client.
15
- * @param params.maker - Maker whose root approval is checked.
16
- * @param params.root - Offer-tree root that must be approved.
17
- * @returns Ratify-root transaction, or `null` when the root is already ratified.
18
- * @throws {ChainIdMismatchError} when the viem client is connected to another chain.
19
- * @example
20
- * ```ts
21
- * import { getSetterRatifierRatifyRootRequirement } from "@morpho-org/morpho-sdk";
22
- *
23
- * const tx = await getSetterRatifierRatifyRootRequirement({
24
- * viemClient: client,
25
- * chainId: 8453,
26
- * maker: user,
27
- * root,
28
- * });
29
- * if (tx) {
30
- * await walletClient.sendTransaction({
31
- * to: tx.to,
32
- * data: tx.data,
33
- * value: tx.value,
34
- * });
35
- * }
36
- * ```
37
- */
38
- export const getSetterRatifierRatifyRootRequirement = async (params) => {
39
- validateChainId(params.viemClient.chain?.id, params.chainId);
40
- const setterRatifier = getChainAddress(params.chainId, "setterRatifier");
41
- const isRootRatified = await readContract(params.viemClient, {
42
- address: setterRatifier,
43
- abi: setterRatifierAbi,
44
- functionName: "isRootRatified",
45
- args: [params.maker, params.root],
46
- });
47
- if (isRootRatified)
48
- return null;
49
- return deepFreeze({
50
- to: setterRatifier,
51
- value: 0n,
52
- data: encodeFunctionData({
53
- abi: setterRatifierAbi,
54
- functionName: "setIsRootRatified",
55
- args: [params.maker, params.root, true],
56
- }),
57
- action: {
58
- type: "setterRatifierRatifyRoot",
59
- args: {
60
- maker: params.maker,
61
- root: params.root,
62
- isRootRatified: true,
63
- },
64
- },
65
- });
66
- };