@morpho-org/morpho-sdk 5.8.0 → 6.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/MIGRATION-v5-to-v6.md +201 -0
  2. package/README.md +62 -40
  3. package/lib/cjs/abis.d.ts +543 -0
  4. package/lib/cjs/abis.js +738 -0
  5. package/lib/cjs/actions/blue/borrow.d.ts +62 -58
  6. package/lib/cjs/actions/blue/borrow.js +48 -80
  7. package/lib/cjs/actions/blue/common.d.ts +99 -0
  8. package/lib/cjs/actions/blue/common.js +318 -0
  9. package/lib/cjs/actions/blue/refinance.d.ts +72 -107
  10. package/lib/cjs/actions/blue/refinance.js +97 -197
  11. package/lib/cjs/actions/blue/repay.d.ts +72 -68
  12. package/lib/cjs/actions/blue/repay.js +56 -118
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
  15. package/lib/cjs/actions/blue/supply.d.ts +62 -45
  16. package/lib/cjs/actions/blue/supply.js +94 -70
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
  18. package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -86
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -119
  21. package/lib/cjs/actions/blue/withdraw.d.ts +68 -78
  22. package/lib/cjs/actions/blue/withdraw.js +101 -97
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
  25. package/lib/cjs/actions/index.d.ts +1 -1
  26. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  27. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
  28. package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
  29. package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +207 -0
  30. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  31. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
  32. package/lib/cjs/actions/requirements/blue/index.d.ts +2 -0
  33. package/lib/cjs/actions/requirements/blue/index.js +2 -0
  34. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  35. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
  36. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  37. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +7 -2
  38. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  39. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -6
  40. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
  41. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +123 -0
  42. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  43. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  44. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  45. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -4
  46. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -4
  47. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  48. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
  49. package/lib/cjs/blue/types.d.ts +3 -1
  50. package/lib/cjs/blue/utils.d.ts +3 -1
  51. package/lib/cjs/blue/utils.js +1 -0
  52. package/lib/cjs/bundler/actions.d.ts +6 -4
  53. package/lib/cjs/bundler/actions.js +6 -4
  54. package/lib/cjs/bundler/types.d.ts +10 -1
  55. package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
  56. package/lib/cjs/client/morphoViemExtension.js +2 -1
  57. package/lib/cjs/entities/blue/blue.d.ts +817 -360
  58. package/lib/cjs/entities/blue/blue.js +455 -698
  59. package/lib/cjs/entities/index.d.ts +1 -0
  60. package/lib/cjs/entities/vaultV1/vaultV1.js +4 -12
  61. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +18 -3
  62. package/lib/cjs/entities/vaultV1ReallocationData.js +11 -1
  63. package/lib/cjs/entities/vaultV2/vaultV2.js +6 -18
  64. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +7 -10
  65. package/lib/cjs/helpers/computeVaultV1Reallocations.js +7 -10
  66. package/lib/cjs/helpers/validate.d.ts +16 -23
  67. package/lib/cjs/helpers/validate.js +32 -48
  68. package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
  69. package/lib/cjs/helpers/validateRequirementSpender.js +2 -0
  70. package/lib/cjs/types/action.d.ts +146 -162
  71. package/lib/cjs/types/action.js +29 -2
  72. package/lib/cjs/types/client.d.ts +9 -0
  73. package/lib/cjs/types/error.d.ts +173 -18
  74. package/lib/cjs/types/error.js +230 -25
  75. package/lib/cjs/types/sharedLiquidity.d.ts +20 -4
  76. package/lib/cjs/types.d.ts +3 -1
  77. package/lib/cjs/utils.d.ts +3 -1
  78. package/lib/cjs/utils.js +1 -0
  79. package/lib/esm/abis.d.ts +543 -0
  80. package/lib/esm/abis.js +737 -0
  81. package/lib/esm/actions/blue/borrow.d.ts +62 -58
  82. package/lib/esm/actions/blue/borrow.js +48 -80
  83. package/lib/esm/actions/blue/common.d.ts +99 -0
  84. package/lib/esm/actions/blue/common.js +306 -0
  85. package/lib/esm/actions/blue/refinance.d.ts +72 -107
  86. package/lib/esm/actions/blue/refinance.js +98 -198
  87. package/lib/esm/actions/blue/repay.d.ts +72 -68
  88. package/lib/esm/actions/blue/repay.js +56 -118
  89. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  90. package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
  91. package/lib/esm/actions/blue/supply.d.ts +62 -45
  92. package/lib/esm/actions/blue/supply.js +94 -70
  93. package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
  94. package/lib/esm/actions/blue/supplyCollateral.js +52 -69
  95. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -86
  96. package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -120
  97. package/lib/esm/actions/blue/withdraw.d.ts +68 -78
  98. package/lib/esm/actions/blue/withdraw.js +100 -96
  99. package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
  100. package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
  101. package/lib/esm/actions/index.d.ts +1 -1
  102. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  103. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
  104. package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
  105. package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +203 -0
  106. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  107. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
  108. package/lib/esm/actions/requirements/blue/index.d.ts +2 -0
  109. package/lib/esm/actions/requirements/blue/index.js +2 -0
  110. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  111. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
  112. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  113. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +8 -3
  114. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  115. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -7
  116. package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
  117. package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +119 -0
  118. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  119. package/lib/esm/actions/requirements/encode/index.js +1 -0
  120. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  121. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -4
  122. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -4
  123. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  124. package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
  125. package/lib/esm/blue/types.d.ts +3 -1
  126. package/lib/esm/blue/utils.d.ts +3 -1
  127. package/lib/esm/blue/utils.js +3 -1
  128. package/lib/esm/bundler/actions.d.ts +6 -4
  129. package/lib/esm/bundler/actions.js +6 -4
  130. package/lib/esm/bundler/types.d.ts +10 -1
  131. package/lib/esm/client/morphoViemExtension.d.ts +2 -1
  132. package/lib/esm/client/morphoViemExtension.js +2 -1
  133. package/lib/esm/entities/blue/blue.d.ts +817 -360
  134. package/lib/esm/entities/blue/blue.js +461 -704
  135. package/lib/esm/entities/index.d.ts +1 -0
  136. package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
  137. package/lib/esm/entities/vaultV1ReallocationData.d.ts +18 -3
  138. package/lib/esm/entities/vaultV1ReallocationData.js +13 -2
  139. package/lib/esm/entities/vaultV2/vaultV2.js +7 -19
  140. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +7 -10
  141. package/lib/esm/helpers/computeVaultV1Reallocations.js +7 -10
  142. package/lib/esm/helpers/validate.d.ts +16 -23
  143. package/lib/esm/helpers/validate.js +32 -48
  144. package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
  145. package/lib/esm/helpers/validateRequirementSpender.js +2 -0
  146. package/lib/esm/types/action.d.ts +146 -162
  147. package/lib/esm/types/action.js +28 -2
  148. package/lib/esm/types/client.d.ts +9 -0
  149. package/lib/esm/types/error.d.ts +173 -18
  150. package/lib/esm/types/error.js +216 -21
  151. package/lib/esm/types/sharedLiquidity.d.ts +20 -4
  152. package/lib/esm/types.d.ts +3 -1
  153. package/lib/esm/utils.d.ts +3 -1
  154. package/lib/esm/utils.js +3 -1
  155. package/package.json +7 -6
  156. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
  157. package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
  158. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
  159. package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
  160. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
  161. package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
  162. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
  163. package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
  164. package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
  165. package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
  166. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
  167. package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
@@ -2,6 +2,9 @@ import type { BigIntish, MarketId, MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
3
  /**
4
4
  * Options controlling public allocator withdrawal discovery.
5
+ *
6
+ * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
7
+ * {@link VaultV2BluePublicAllocatorOptions}.
5
8
  */
6
9
  export interface PublicAllocatorOptions {
7
10
  /** Whether public allocator reallocation discovery is enabled. */
@@ -63,6 +66,9 @@ export interface VaultV2BluePublicAllocatorOptions {
63
66
  }
64
67
  /**
65
68
  * A computed source-market withdrawal before it is grouped by vault.
69
+ *
70
+ * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
71
+ * {@link VaultV2BlueReallocation}.
66
72
  */
67
73
  export interface PublicReallocation {
68
74
  /** Source market id to withdraw from. */
@@ -72,7 +78,12 @@ export interface PublicReallocation {
72
78
  /** Assets to withdraw from the source market. */
73
79
  readonly assets: bigint;
74
80
  }
75
- /** A single withdrawal from a source market within a vault reallocation. */
81
+ /**
82
+ * A single withdrawal from a source market within a vault reallocation.
83
+ *
84
+ * @deprecated Vault V1 shared-liquidity support will be removed in the next major. Use
85
+ * {@link VaultV2BlueReallocation}.
86
+ */
76
87
  export interface ReallocationWithdrawal {
77
88
  /** Source market parameters to pass to the public allocator. */
78
89
  readonly marketParams: MarketParams;
@@ -84,6 +95,9 @@ export interface ReallocationWithdrawal {
84
95
  *
85
96
  * Maps 1:1 to a `PublicAllocator.reallocateTo()` call.
86
97
  * Withdraws from source markets and supplies to the target market.
98
+ *
99
+ * @deprecated Vault V1 shared-liquidity support will be removed in the next major. Use
100
+ * {@link VaultV2BlueReallocation}.
87
101
  */
88
102
  export interface VaultV1Reallocation {
89
103
  readonly vault: Address;
@@ -123,12 +137,11 @@ export interface VaultV2BlueReallocation {
123
137
  /** Vault-configured WAD-scaled penalty rate passed to the allocator. */
124
138
  readonly penalty: bigint;
125
139
  }
126
- /** A homogeneous Blue action plan containing only Vault V1 or only Vault V2 reallocations. */
127
- export type BlueReallocationPlan = Iterable<VaultV1Reallocation> | Iterable<VaultV2BlueReallocation>;
128
140
  /**
129
141
  * Deprecated name for a Vault V1 reallocation.
130
142
  *
131
- * @deprecated Use {@link VaultV1Reallocation} instead.
143
+ * @deprecated Vault V1 shared-liquidity support will be removed in the next major. Use
144
+ * {@link VaultV2BlueReallocation}.
132
145
  */
133
146
  export type VaultReallocation = VaultV1Reallocation;
134
147
  /**
@@ -136,6 +149,9 @@ export type VaultReallocation = VaultV1Reallocation;
136
149
  *
137
150
  * Extends {@link PublicAllocatorOptions} with supply-side utilization targets
138
151
  * that determine when reallocation is triggered.
152
+ *
153
+ * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
154
+ * {@link VaultV2BluePublicAllocatorOptions}.
139
155
  */
140
156
  export interface ReallocationComputeOptions extends PublicAllocatorOptions {
141
157
  /**
@@ -9,7 +9,9 @@ MaxBorrowOptions, MaxPositionCapacities as BlueMaxPositionCapacities,
9
9
  MaxPositionCapacities, MaxWithdrawCollateralOptions as BlueMaxWithdrawCollateralOptions,
10
10
  /** @deprecated Use `BlueMaxWithdrawCollateralOptions` or the raw `/blue/types` subpath. */
11
11
  MaxWithdrawCollateralOptions, Pending, Permit2Allowance, } from "@morpho-org/blue-sdk";
12
- export type { AuthorizationArgs as BlueAuthorizationTypedDataArgs, DaiPermitArgs, DeploylessFetchParameters as BlueDeploylessFetchParameters,
12
+ export type { AuthorizationArgs as BlueAuthorizationTypedDataArgs,
13
+ /** @deprecated Args for the deprecated getDaiPermitTypedData; scheduled for removal in the next major. */
14
+ DaiPermitArgs, DeploylessFetchParameters as BlueDeploylessFetchParameters,
13
15
  /** @deprecated Use `BlueDeploylessFetchParameters` or the raw `/blue/types` subpath. */
14
16
  DeploylessFetchParameters, FetchParameters as BlueFetchParameters,
15
17
  /** @deprecated Use `BlueFetchParameters` or the raw `/blue/types` subpath. */
@@ -8,7 +8,9 @@ MarketUtils, MathLib, SharesMath as BlueSharesMath,
8
8
  SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
9
9
  export { decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData,
10
10
  /** @deprecated Use getBlueAuthorizationTypedData or the raw protocol subpath. */
11
- getAuthorizationTypedData, getDaiPermitTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
11
+ getAuthorizationTypedData,
12
+ /** @deprecated DAI is routed through Permit2 internally; scheduled for removal in the next major. */
13
+ getDaiPermitTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
12
14
  export { EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils,
13
15
  /** @deprecated Use MidnightEcrecoverRatifierUtils or the raw protocol subpath. */
14
16
  EcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils,
package/lib/esm/utils.js CHANGED
@@ -7,7 +7,9 @@ MarketUtils, MathLib, SharesMath as BlueSharesMath,
7
7
  SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
8
8
  export { decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData,
9
9
  /** @deprecated Use getBlueAuthorizationTypedData or the raw protocol subpath. */
10
- getAuthorizationTypedData, getDaiPermitTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
10
+ getAuthorizationTypedData,
11
+ /** @deprecated DAI is routed through Permit2 internally; scheduled for removal in the next major. */
12
+ getDaiPermitTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
11
13
  export { EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils,
12
14
  /** @deprecated Use MidnightEcrecoverRatifierUtils or the raw protocol subpath. */
13
15
  EcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/morpho-sdk",
3
3
  "description": "Abstraction layer for Morpho's complexity.",
4
- "version": "5.8.0",
4
+ "version": "6.0.0-next.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Foulks-Plb <https://x.com/FoulkPlb>"
@@ -157,14 +157,15 @@
157
157
  "./lib/*/augment/*.js"
158
158
  ],
159
159
  "files": [
160
- "lib"
160
+ "lib",
161
+ "MIGRATION-v5-to-v6.md"
161
162
  ],
162
163
  "dependencies": {
163
164
  "zod": "^4.4.3",
164
165
  "@morpho-org/blue-sdk": "^6.7.0",
165
- "@morpho-org/blue-sdk-viem": "^5.4.0",
166
- "@morpho-org/midnight-sdk": "^1.3.0",
167
- "@morpho-org/morpho-ts": "^2.11.0"
166
+ "@morpho-org/blue-sdk-viem": "^5.5.0",
167
+ "@morpho-org/midnight-sdk": "^1.3.1",
168
+ "@morpho-org/morpho-ts": "^2.11.1"
168
169
  },
169
170
  "peerDependencies": {
170
171
  "viem": "^2.0.0"
@@ -172,7 +173,7 @@
172
173
  "devDependencies": {
173
174
  "dotenv": "^17.4.2",
174
175
  "fast-check": "^4.9.0",
175
- "typescript": "^7.0.2",
176
+ "typescript": "7.0.2",
176
177
  "viem": "^2.55.10",
177
178
  "vitest": "^4.1.10",
178
179
  "@morpho-org/test": "^2.10.0"
@@ -1,47 +0,0 @@
1
- import type { Address } from "viem";
2
- import type { Action } from "../../bundler/index.js";
3
- import type { PermitRequirementSignature } from "../../types/index.js";
4
- /** Parameters for {@link buildAssetFundingActions}. */
5
- export interface BuildAssetFundingActionsParams {
6
- /** Chain the operation runs on — resolves adapter addresses and validates wNative. */
7
- readonly chainId: number;
8
- /** Asset wrapped and/or pulled into `GeneralAdapter1` (loan token, collateral token, …). */
9
- readonly asset: Address;
10
- /** ERC-20 amount of `asset` to pull from the payer (`0n` on a fully-native funding). */
11
- readonly erc20Amount: bigint;
12
- /** Native ETH to wrap into wNative before the pull (`0n` when not wrapping). */
13
- readonly nativeAmount: bigint;
14
- /** Optional pre-signed permit/permit2 approval for the ERC-20 pull. */
15
- readonly requirementSignature?: PermitRequirementSignature;
16
- }
17
- /**
18
- * Builds the shared asset-funding actions — native wrapping followed by the ERC-20 pull — that move
19
- * `asset` into `GeneralAdapter1` before a bundled Morpho operation (`blueSupply`,
20
- * `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
21
- *
22
- * Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
23
- * `buildVaultV2BlueReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
24
- * `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
25
- * pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
26
- * `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
27
- * supplied. A fully-native funding emits no ERC-20 action; funding nothing returns `[]`.
28
- *
29
- * Single source of truth for the native-wrap + ERC-20-pull composition every bundled Blue funding
30
- * path depends on — a fix here applies to all of them instead of risking a silent divergence
31
- * between copies.
32
- *
33
- * @param params - See {@link BuildAssetFundingActionsParams}.
34
- * @returns The `nativeTransfer`/`wrapNative`/pull actions, in bundle order (empty when nothing is
35
- * funded).
36
- * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
37
- * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but `asset` is not the
38
- * chain's wNative.
39
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
40
- * provided and the signed asset differs from `asset`.
41
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
42
- * provided and the signed amount differs from `erc20Amount`.
43
- * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
44
- * signature is missing its expiration.
45
- * @internal
46
- */
47
- export declare const buildAssetFundingActions: ({ chainId, asset, erc20Amount, nativeAmount, requirementSignature, }: BuildAssetFundingActionsParams) => Action[];
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildAssetFundingActions = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const index_js_1 = require("../../helpers/index.js");
6
- const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
7
- /**
8
- * Builds the shared asset-funding actions — native wrapping followed by the ERC-20 pull — that move
9
- * `asset` into `GeneralAdapter1` before a bundled Morpho operation (`blueSupply`,
10
- * `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
11
- *
12
- * Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
13
- * `buildVaultV2BlueReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
14
- * `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
15
- * pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
16
- * `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
17
- * supplied. A fully-native funding emits no ERC-20 action; funding nothing returns `[]`.
18
- *
19
- * Single source of truth for the native-wrap + ERC-20-pull composition every bundled Blue funding
20
- * path depends on — a fix here applies to all of them instead of risking a silent divergence
21
- * between copies.
22
- *
23
- * @param params - See {@link BuildAssetFundingActionsParams}.
24
- * @returns The `nativeTransfer`/`wrapNative`/pull actions, in bundle order (empty when nothing is
25
- * funded).
26
- * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
27
- * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but `asset` is not the
28
- * chain's wNative.
29
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
30
- * provided and the signed asset differs from `asset`.
31
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
32
- * provided and the signed amount differs from `erc20Amount`.
33
- * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
34
- * signature is missing its expiration.
35
- * @internal
36
- */
37
- const buildAssetFundingActions = ({ chainId, asset, erc20Amount, nativeAmount, requirementSignature, }) => {
38
- const { bundler3: { generalAdapter1, bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
39
- const actions = [];
40
- // Wrap native into wNative before pulling the ERC-20 remainder.
41
- if (nativeAmount > 0n) {
42
- (0, index_js_1.validateNativeAsset)(chainId, asset);
43
- actions.push({
44
- type: "nativeTransfer",
45
- args: [bundler3, generalAdapter1, nativeAmount, false],
46
- }, {
47
- type: "wrapNative",
48
- args: [nativeAmount, generalAdapter1, false],
49
- });
50
- }
51
- // Pull the ERC-20 portion (0 on a fully native funding). getTokenRequirementActions emits a plain
52
- // erc20TransferFrom itself when no permit/permit2 signature is supplied.
53
- if (erc20Amount > 0n) {
54
- actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
55
- asset,
56
- amount: erc20Amount,
57
- recipient: generalAdapter1,
58
- requirementSignature,
59
- }));
60
- }
61
- return actions;
62
- };
63
- exports.buildAssetFundingActions = buildAssetFundingActions;
@@ -1,69 +0,0 @@
1
- import { type MarketParams } from "@morpho-org/blue-sdk";
2
- import type { Action } from "../../bundler/index.js";
3
- import type { BlueReallocationPlan, VaultV1Reallocation, VaultV2BlueReallocation } from "../../types/index.js";
4
- /**
5
- * Builds PublicAllocator V1 reallocation actions for a Morpho Blue target market.
6
- *
7
- * Preserves the supplied reallocation order and aggregates each allocator call's native fee.
8
- *
9
- * @param params.reallocations - Validated Vault V1 reallocations to execute.
10
- * @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
11
- * @returns The reallocation actions and aggregate native fee, with zero V2 penalty assets.
12
- * @internal
13
- */
14
- export declare const buildVaultV1ReallocationActions: ({ reallocations, targetMarketParams, }: {
15
- readonly reallocations: readonly VaultV1Reallocation[];
16
- readonly targetMarketParams: MarketParams;
17
- }) => {
18
- actions: Action[];
19
- fee: bigint;
20
- penaltyAssets: bigint;
21
- };
22
- /**
23
- * Builds BluePublicAllocator reallocation actions for a Morpho Blue target market.
24
- *
25
- * Prepends one aggregate loan-token funding action when penalties are non-zero, then builds one
26
- * allocator action per validated Vault V2 reallocation.
27
- *
28
- * @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
29
- * @param params.reallocations - Validated Vault V2 Blue reallocations to execute.
30
- * @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
31
- * @param params.penaltyFundingSource - Optional source of penalty assets. Defaults to the
32
- * transaction initiator.
33
- * @returns The funding and reallocation actions and aggregate penalty assets, with zero native fee.
34
- * @internal
35
- */
36
- export declare const buildVaultV2BlueReallocationActions: ({ chainId, reallocations, targetMarketParams, penaltyFundingSource, }: {
37
- readonly chainId: number;
38
- readonly reallocations: readonly VaultV2BlueReallocation[];
39
- readonly targetMarketParams: MarketParams;
40
- readonly penaltyFundingSource?: "initiator" | "generalAdapter1";
41
- }) => {
42
- actions: Action[];
43
- fee: bigint;
44
- penaltyAssets: bigint;
45
- };
46
- /**
47
- * Validates a homogeneous Blue reallocation plan and builds its Bundler actions.
48
- *
49
- * Dispatches Vault V1 and Vault V2 plans to their version-specific builders. V1 plans aggregate
50
- * native fees, while V2 plans aggregate loan-token penalties using the selected funding source.
51
- *
52
- * @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
53
- * @param params.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocation plan.
54
- * @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
55
- * @param params.penaltyFundingSource - Optional source of V2 penalty assets. Defaults to the
56
- * transaction initiator.
57
- * @returns The reallocation actions, aggregate V1 native fee, and aggregate V2 penalty assets.
58
- * @internal
59
- */
60
- export declare const buildBlueReallocationActions: ({ chainId, reallocations, targetMarketParams, penaltyFundingSource, }: {
61
- readonly chainId: number;
62
- readonly reallocations: BlueReallocationPlan | undefined;
63
- readonly targetMarketParams: MarketParams;
64
- readonly penaltyFundingSource?: "initiator" | "generalAdapter1";
65
- }) => {
66
- actions: Action[];
67
- fee: bigint;
68
- penaltyAssets: bigint;
69
- };
@@ -1,141 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildBlueReallocationActions = exports.buildVaultV2BlueReallocationActions = exports.buildVaultV1ReallocationActions = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const validate_js_1 = require("../../helpers/validate.js");
6
- /**
7
- * Builds PublicAllocator V1 reallocation actions for a Morpho Blue target market.
8
- *
9
- * Preserves the supplied reallocation order and aggregates each allocator call's native fee.
10
- *
11
- * @param params.reallocations - Validated Vault V1 reallocations to execute.
12
- * @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
13
- * @returns The reallocation actions and aggregate native fee, with zero V2 penalty assets.
14
- * @internal
15
- */
16
- const buildVaultV1ReallocationActions = ({ reallocations, targetMarketParams, }) => {
17
- let fee = 0n;
18
- const actions = [];
19
- for (const reallocation of reallocations) {
20
- actions.push({
21
- type: "reallocateTo",
22
- args: [
23
- reallocation.vault,
24
- reallocation.fee,
25
- reallocation.withdrawals.map((withdrawal) => ({
26
- marketParams: withdrawal.marketParams,
27
- amount: withdrawal.amount,
28
- })),
29
- targetMarketParams,
30
- false,
31
- ],
32
- });
33
- fee += reallocation.fee;
34
- }
35
- return { actions, fee, penaltyAssets: 0n };
36
- };
37
- exports.buildVaultV1ReallocationActions = buildVaultV1ReallocationActions;
38
- /**
39
- * Builds BluePublicAllocator reallocation actions for a Morpho Blue target market.
40
- *
41
- * Prepends one aggregate loan-token funding action when penalties are non-zero, then builds one
42
- * allocator action per validated Vault V2 reallocation.
43
- *
44
- * @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
45
- * @param params.reallocations - Validated Vault V2 Blue reallocations to execute.
46
- * @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
47
- * @param params.penaltyFundingSource - Optional source of penalty assets. Defaults to the
48
- * transaction initiator.
49
- * @returns The funding and reallocation actions and aggregate penalty assets, with zero native fee.
50
- * @internal
51
- */
52
- const buildVaultV2BlueReallocationActions = ({ chainId, reallocations, targetMarketParams, penaltyFundingSource = "initiator", }) => {
53
- const actions = [];
54
- const penaltyAssets = reallocations.reduce((total, reallocation) => total +
55
- blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets(reallocation, reallocation.assets), 0n);
56
- if (penaltyAssets > 0n) {
57
- const { bundler3: { bundler3, generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
58
- actions.push(penaltyFundingSource === "generalAdapter1"
59
- ? {
60
- type: "erc20Transfer",
61
- args: [
62
- targetMarketParams.loanToken,
63
- bundler3,
64
- penaltyAssets,
65
- generalAdapter1,
66
- false,
67
- ],
68
- }
69
- : {
70
- type: "erc20TransferFrom",
71
- args: [
72
- targetMarketParams.loanToken,
73
- penaltyAssets,
74
- bundler3,
75
- false,
76
- ],
77
- });
78
- }
79
- for (const reallocation of reallocations) {
80
- actions.push(reallocation.from.type === "market"
81
- ? {
82
- type: "vaultV2BluePublicAllocatorReallocate",
83
- args: [
84
- reallocation.vault,
85
- reallocation.from.adapter,
86
- reallocation.from.marketParams,
87
- reallocation.to.adapter,
88
- targetMarketParams,
89
- reallocation.assets,
90
- reallocation.penalty,
91
- false,
92
- ],
93
- }
94
- : {
95
- type: "vaultV2BluePublicAllocatorAllocateFromIdle",
96
- args: [
97
- reallocation.vault,
98
- reallocation.to.adapter,
99
- targetMarketParams,
100
- reallocation.assets,
101
- reallocation.penalty,
102
- false,
103
- ],
104
- });
105
- }
106
- return { actions, fee: 0n, penaltyAssets };
107
- };
108
- exports.buildVaultV2BlueReallocationActions = buildVaultV2BlueReallocationActions;
109
- /**
110
- * Validates a homogeneous Blue reallocation plan and builds its Bundler actions.
111
- *
112
- * Dispatches Vault V1 and Vault V2 plans to their version-specific builders. V1 plans aggregate
113
- * native fees, while V2 plans aggregate loan-token penalties using the selected funding source.
114
- *
115
- * @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
116
- * @param params.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocation plan.
117
- * @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
118
- * @param params.penaltyFundingSource - Optional source of V2 penalty assets. Defaults to the
119
- * transaction initiator.
120
- * @returns The reallocation actions, aggregate V1 native fee, and aggregate V2 penalty assets.
121
- * @internal
122
- */
123
- const buildBlueReallocationActions = ({ chainId, reallocations, targetMarketParams, penaltyFundingSource, }) => {
124
- const reallocationPlan = (0, validate_js_1.validateAndNormalizeReallocations)({
125
- reallocations,
126
- targetMarketId: targetMarketParams.id,
127
- chainId,
128
- });
129
- return reallocationPlan.type === "vaultV1"
130
- ? (0, exports.buildVaultV1ReallocationActions)({
131
- reallocations: reallocationPlan.reallocations,
132
- targetMarketParams,
133
- })
134
- : (0, exports.buildVaultV2BlueReallocationActions)({
135
- chainId,
136
- reallocations: reallocationPlan.reallocations,
137
- targetMarketParams,
138
- penaltyFundingSource,
139
- });
140
- };
141
- exports.buildBlueReallocationActions = buildBlueReallocationActions;
@@ -1,66 +0,0 @@
1
- import type { MarketId } from "@morpho-org/blue-sdk";
2
- /**
3
- * Pre-resolved repay amounts (plus `maxSharePrice`) validated by {@link resolveRepayFunding}.
4
- *
5
- * These are the fields the entity layer (`MorphoBlue.repay` / `repayWithdrawCollateral`) resolves
6
- * from live market/position state before either repay builder assembles the bundle.
7
- *
8
- * @internal
9
- */
10
- export interface RepayFundingInput {
11
- /** (assets mode) ERC-20 loan tokens pulled from the payer. */
12
- readonly amount: bigint;
13
- /** (shares mode) Borrow shares to repay. Discriminates the mode when `> 0n`. */
14
- readonly shares: bigint;
15
- /** Native ETH wrapped into wNative to help fund the repay. */
16
- readonly nativeAmount: bigint;
17
- /** Loan tokens routed into `GeneralAdapter1` (see `RepayActionAmountArgs`). */
18
- readonly transferAmount: bigint;
19
- /** Maximum acceptable repay share price (in ray). */
20
- readonly maxSharePrice: bigint;
21
- }
22
- /**
23
- * Derived repay funding values consumed by the repay builders.
24
- *
25
- * @internal
26
- */
27
- export interface RepayFunding {
28
- /** `true` when repaying an exact share count (full close); `false` in assets mode. */
29
- readonly isSharesMode: boolean;
30
- /** Assets passed to `morphoRepay` (`transferAmount` in assets mode, `0n` in shares mode). */
31
- readonly repayAssets: bigint;
32
- /** Shares passed to `morphoRepay` (`shares` in shares mode, `0n` in assets mode). */
33
- readonly repayShares: bigint;
34
- /** ERC-20 loan tokens pulled into `GeneralAdapter1` (net of any wrapped native). */
35
- readonly erc20Amount: bigint;
36
- }
37
- /**
38
- * Resolves and validates the repay funding envelope shared by `blueRepay` and
39
- * `blueRepayWithdrawCollateral`.
40
- *
41
- * Encode-only and synchronous — reads no on-chain state and does no amount arithmetic beyond
42
- * deriving the bundle values from the pre-resolved args (the entity layer resolves the amounts
43
- * upstream). Runs the shared mode/amount guards, discriminates assets vs shares mode on
44
- * `shares > 0n`, then validates the funding so the assembled bundle neither strands over-pulled
45
- * tokens nor under-funds the repay:
46
- *
47
- * - **assets mode** (`shares` `0n`): repays `transferAmount` (`= amount + nativeAmount`, additive
48
- * like `blueSupply`); ERC-20 pulled = `amount`.
49
- * - **shares mode** (`shares > 0n`): repays exact `shares`; ERC-20 pulled = `transferAmount` (already
50
- * net of native).
51
- *
52
- * Single source of truth for the funding math both repay builders depend on — a correctness fix here
53
- * applies to both paths instead of risking a silent divergence between two copies.
54
- *
55
- * @param input - The pre-resolved repay amounts plus the repay `maxSharePrice`.
56
- * @param marketId - Market id used to tag the thrown errors.
57
- * @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
58
- * amounts the repay builders assemble the bundle from.
59
- * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or total repay funding is zero.
60
- * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
61
- * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
62
- * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
63
- * `transferAmount !== amount + nativeAmount`.
64
- * @internal
65
- */
66
- export declare const resolveRepayFunding: ({ amount, shares, nativeAmount, transferAmount, maxSharePrice, }: RepayFundingInput, marketId: MarketId) => RepayFunding;
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRepayFunding = void 0;
4
- const index_js_1 = require("../../types/index.js");
5
- /**
6
- * Resolves and validates the repay funding envelope shared by `blueRepay` and
7
- * `blueRepayWithdrawCollateral`.
8
- *
9
- * Encode-only and synchronous — reads no on-chain state and does no amount arithmetic beyond
10
- * deriving the bundle values from the pre-resolved args (the entity layer resolves the amounts
11
- * upstream). Runs the shared mode/amount guards, discriminates assets vs shares mode on
12
- * `shares > 0n`, then validates the funding so the assembled bundle neither strands over-pulled
13
- * tokens nor under-funds the repay:
14
- *
15
- * - **assets mode** (`shares` `0n`): repays `transferAmount` (`= amount + nativeAmount`, additive
16
- * like `blueSupply`); ERC-20 pulled = `amount`.
17
- * - **shares mode** (`shares > 0n`): repays exact `shares`; ERC-20 pulled = `transferAmount` (already
18
- * net of native).
19
- *
20
- * Single source of truth for the funding math both repay builders depend on — a correctness fix here
21
- * applies to both paths instead of risking a silent divergence between two copies.
22
- *
23
- * @param input - The pre-resolved repay amounts plus the repay `maxSharePrice`.
24
- * @param marketId - Market id used to tag the thrown errors.
25
- * @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
26
- * amounts the repay builders assemble the bundle from.
27
- * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or total repay funding is zero.
28
- * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative.
29
- * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
30
- * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
31
- * `transferAmount !== amount + nativeAmount`.
32
- * @internal
33
- */
34
- const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmount, maxSharePrice, }, marketId) => {
35
- if (maxSharePrice <= 0n) {
36
- throw new index_js_1.NonPositiveInputError("maxSharePrice", maxSharePrice);
37
- }
38
- if (nativeAmount < 0n) {
39
- throw new index_js_1.NegativeInputError("nativeAmount", nativeAmount);
40
- }
41
- if (amount < 0n) {
42
- throw new index_js_1.NegativeInputError("amount", amount);
43
- }
44
- if (shares < 0n) {
45
- throw new index_js_1.NegativeInputError("shares", shares);
46
- }
47
- if (amount > 0n && shares > 0n) {
48
- throw new index_js_1.MutuallyExclusiveRepayAmountsError(marketId);
49
- }
50
- // Shares mode repays an exact share count and pulls `transferAmount` ERC-20
51
- // (already net of native), skimming the residual. Assets mode repays
52
- // `transferAmount` (= amount + native, additive) and pulls `amount`.
53
- const isSharesMode = shares > 0n;
54
- const repayAssets = isSharesMode ? 0n : transferAmount;
55
- const repayShares = shares;
56
- const erc20Amount = isSharesMode ? transferAmount : amount;
57
- // Validate the pre-resolved funding. Assets mode is additive like `blueSupply`:
58
- // the ERC-20 pulled (`amount`) plus the wrapped `nativeAmount` must equal the
59
- // assets repaid, and the total must be positive — so the adapter neither strands
60
- // over-pulled tokens nor under-funds the repay. Shares mode pulls `transferAmount`
61
- // ERC-20 (0 on a fully-native repay) and wraps `nativeAmount`; the bundle must
62
- // fund the repay with a non-negative transfer and a positive total.
63
- if (isSharesMode) {
64
- if (transferAmount < 0n) {
65
- throw new index_js_1.NegativeInputError("transferAmount", transferAmount);
66
- }
67
- if (transferAmount + nativeAmount <= 0n) {
68
- throw new index_js_1.NonPositiveInputError("transferAmount + nativeAmount", transferAmount + nativeAmount);
69
- }
70
- }
71
- else {
72
- if (transferAmount !== amount + nativeAmount) {
73
- throw new index_js_1.TransferAmountNotEqualToAssetsError({
74
- transferAmount,
75
- assets: amount + nativeAmount,
76
- market: marketId,
77
- });
78
- }
79
- if (repayAssets <= 0n) {
80
- throw new index_js_1.NonPositiveInputError("amount + nativeAmount", repayAssets);
81
- }
82
- }
83
- return { isSharesMode, repayAssets, repayShares, erc20Amount };
84
- };
85
- exports.resolveRepayFunding = resolveRepayFunding;