@morpho-org/morpho-sdk 5.9.0 → 6.0.0-next.1

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 (243) hide show
  1. package/MIGRATION-v5-to-v6.md +404 -0
  2. package/README.md +127 -69
  3. package/lib/cjs/abis.d.ts +210 -0
  4. package/lib/cjs/abis.js +142 -2
  5. package/lib/cjs/actions/blue/borrow.d.ts +62 -61
  6. package/lib/cjs/actions/blue/borrow.js +48 -80
  7. package/lib/cjs/actions/blue/common.d.ts +86 -0
  8. package/lib/cjs/actions/blue/common.js +205 -0
  9. package/lib/cjs/actions/blue/refinance.d.ts +72 -112
  10. package/lib/cjs/actions/blue/refinance.js +97 -199
  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 -90
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
  21. package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
  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/bundles/common.d.ts +200 -0
  26. package/lib/cjs/actions/bundles/common.js +469 -0
  27. package/lib/cjs/actions/bundles/index.d.ts +3 -0
  28. package/lib/cjs/actions/bundles/index.js +23 -0
  29. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  30. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
  31. package/lib/cjs/actions/index.d.ts +2 -1
  32. package/lib/cjs/actions/index.js +1 -0
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  34. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  35. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  36. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  37. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  38. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  39. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
  41. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  42. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
  43. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  44. package/lib/cjs/actions/requirements/blue/index.js +1 -0
  45. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  46. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +8 -2
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -6
  51. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  52. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +123 -0
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  58. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +6 -4
  59. package/lib/cjs/actions/requirements/getRequirementsApproval.js +6 -4
  60. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  61. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
  62. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
  64. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  65. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  66. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  67. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  68. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  69. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  70. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  71. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  72. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  73. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  74. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  75. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  76. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  77. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  78. package/lib/cjs/bundler/actions.d.ts +4 -4
  79. package/lib/cjs/bundler/actions.js +4 -4
  80. package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
  81. package/lib/cjs/client/morphoViemExtension.js +2 -1
  82. package/lib/cjs/entities/blue/blue.d.ts +806 -374
  83. package/lib/cjs/entities/blue/blue.js +449 -696
  84. package/lib/cjs/entities/index.d.ts +2 -0
  85. package/lib/cjs/entities/index.js +15 -0
  86. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  87. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  88. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +203 -0
  89. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  90. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  91. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  92. package/lib/cjs/entities/requirements/index.js +17 -0
  93. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
  94. package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
  95. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
  96. package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
  97. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
  98. package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
  99. package/lib/cjs/helpers/index.d.ts +2 -1
  100. package/lib/cjs/helpers/index.js +5 -1
  101. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  102. package/lib/cjs/helpers/referralFee.js +35 -0
  103. package/lib/cjs/helpers/slippage.d.ts +90 -1
  104. package/lib/cjs/helpers/slippage.js +123 -0
  105. package/lib/cjs/helpers/validate.d.ts +16 -23
  106. package/lib/cjs/helpers/validate.js +41 -48
  107. package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
  108. package/lib/cjs/helpers/validateRequirementSpender.js +3 -0
  109. package/lib/cjs/index.d.ts +1 -0
  110. package/lib/cjs/index.js +1 -0
  111. package/lib/cjs/types/action.d.ts +303 -210
  112. package/lib/cjs/types/action.js +29 -2
  113. package/lib/cjs/types/client.d.ts +9 -0
  114. package/lib/cjs/types/error.d.ts +193 -18
  115. package/lib/cjs/types/error.js +267 -24
  116. package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
  117. package/lib/esm/abis.d.ts +210 -0
  118. package/lib/esm/abis.js +140 -0
  119. package/lib/esm/actions/blue/borrow.d.ts +62 -61
  120. package/lib/esm/actions/blue/borrow.js +48 -80
  121. package/lib/esm/actions/blue/common.d.ts +86 -0
  122. package/lib/esm/actions/blue/common.js +193 -0
  123. package/lib/esm/actions/blue/refinance.d.ts +72 -112
  124. package/lib/esm/actions/blue/refinance.js +98 -200
  125. package/lib/esm/actions/blue/repay.d.ts +72 -68
  126. package/lib/esm/actions/blue/repay.js +56 -118
  127. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  128. package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
  129. package/lib/esm/actions/blue/supply.d.ts +62 -45
  130. package/lib/esm/actions/blue/supply.js +94 -70
  131. package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
  132. package/lib/esm/actions/blue/supplyCollateral.js +52 -69
  133. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  134. package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
  135. package/lib/esm/actions/blue/withdraw.d.ts +68 -79
  136. package/lib/esm/actions/blue/withdraw.js +100 -96
  137. package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
  138. package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
  139. package/lib/esm/actions/bundles/common.d.ts +200 -0
  140. package/lib/esm/actions/bundles/common.js +457 -0
  141. package/lib/esm/actions/bundles/index.d.ts +3 -0
  142. package/lib/esm/actions/bundles/index.js +2 -0
  143. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  144. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  145. package/lib/esm/actions/index.d.ts +2 -1
  146. package/lib/esm/actions/index.js +1 -0
  147. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  148. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  149. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  150. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  151. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  152. package/lib/esm/actions/midnight/takeLend.js +2 -2
  153. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  154. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
  155. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  156. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
  157. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  158. package/lib/esm/actions/requirements/blue/index.js +1 -0
  159. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  160. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
  161. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  162. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -3
  163. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  164. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -7
  165. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  166. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +119 -0
  167. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  168. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  169. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  170. package/lib/esm/actions/requirements/encode/index.js +1 -0
  171. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  172. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +6 -4
  173. package/lib/esm/actions/requirements/getRequirementsApproval.js +6 -4
  174. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  175. package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
  176. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  177. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
  178. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  179. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  180. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  181. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  182. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  183. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  184. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  185. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  186. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  187. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  188. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  189. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  190. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  191. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  192. package/lib/esm/bundler/actions.d.ts +4 -4
  193. package/lib/esm/bundler/actions.js +4 -4
  194. package/lib/esm/client/morphoViemExtension.d.ts +2 -1
  195. package/lib/esm/client/morphoViemExtension.js +2 -1
  196. package/lib/esm/entities/blue/blue.d.ts +806 -374
  197. package/lib/esm/entities/blue/blue.js +455 -702
  198. package/lib/esm/entities/index.d.ts +2 -0
  199. package/lib/esm/entities/index.js +1 -0
  200. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +199 -0
  203. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  204. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  205. package/lib/esm/entities/requirements/index.d.ts +1 -0
  206. package/lib/esm/entities/requirements/index.js +1 -0
  207. package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
  208. package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
  209. package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
  210. package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
  211. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
  212. package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
  213. package/lib/esm/helpers/index.d.ts +2 -1
  214. package/lib/esm/helpers/index.js +2 -1
  215. package/lib/esm/helpers/referralFee.d.ts +21 -0
  216. package/lib/esm/helpers/referralFee.js +31 -0
  217. package/lib/esm/helpers/slippage.d.ts +90 -1
  218. package/lib/esm/helpers/slippage.js +122 -2
  219. package/lib/esm/helpers/validate.d.ts +16 -23
  220. package/lib/esm/helpers/validate.js +40 -48
  221. package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
  222. package/lib/esm/helpers/validateRequirementSpender.js +3 -0
  223. package/lib/esm/index.d.ts +1 -0
  224. package/lib/esm/index.js +1 -0
  225. package/lib/esm/types/action.d.ts +303 -210
  226. package/lib/esm/types/action.js +28 -2
  227. package/lib/esm/types/client.d.ts +9 -0
  228. package/lib/esm/types/error.d.ts +193 -18
  229. package/lib/esm/types/error.js +252 -21
  230. package/lib/esm/types/sharedLiquidity.d.ts +0 -7
  231. package/package.json +6 -5
  232. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
  233. package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
  234. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
  235. package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
  236. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
  237. package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
  238. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
  239. package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
  240. package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
  241. package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
  242. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
  243. package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
@@ -1,100 +1,124 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blueSupply = void 0;
4
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
- const index_js_1 = require("../../bundler/index.js");
6
- const index_js_2 = require("../../helpers/index.js");
7
- const index_js_3 = require("../../types/index.js");
8
- const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
4
+ const viem_1 = require("viem");
5
+ const abis_js_1 = require("../../abis.js");
6
+ const index_js_1 = require("../../types/index.js");
7
+ const common_js_1 = require("./common.js");
9
8
  /**
10
- * Prepares a loan-asset supply transaction for a Morpho Blue market.
9
+ * Encodes a direct BlueBundlesV1 loan-asset supply transaction.
11
10
  *
12
- * Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
13
- * via `GeneralAdapter1.wrapNative()` before the supply; the loan token must be the chain's
14
- * wNative for that path. Uses `maxSharePrice` to protect against share-price inflation between
15
- * transaction construction and execution.
11
+ * `assets` is the gross funded amount; BlueBundlesV1 deducts the referral fee before supplying.
12
+ * This route has no Bundler3 share-price bound or `slippageTolerance` input.
16
13
  *
17
- * Zero loss: all supplied assets reach Morpho. No dust left in bundler or adapter.
18
- *
19
- * @param params.market.chainId - The chain the market lives on.
20
- * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
21
- * @param params.args.amount - Amount of ERC-20 loan asset to supply. At least one of `amount` or
22
- * `nativeAmount` must be positive. Defaults to `0n`.
23
- * @param params.args.onBehalf - Address whose Morpho supply position is credited.
24
- * @param params.args.maxSharePrice - Maximum acceptable supply share price (in ray). Slippage
25
- * protection.
26
- * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
27
- * supply. Requires the loan token to be the chain's wNative.
28
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
29
- * @param params.metadata - Optional analytics metadata attached to the bundle.
30
- * @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
31
- * typed `action` discriminator the simulation layer consumes.
32
- * @throws {NegativeInputError} when `amount`, `nativeAmount`, or `maxSharePrice` is negative.
33
- * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
34
- * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
35
- * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
36
- * the chain's wNative.
37
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
38
- * is provided and the signed asset differs from `marketParams.loanToken`.
39
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
40
- * is provided and the signed amount differs from `args.amount`.
14
+ * @param params - Supply encoding parameters.
15
+ * @param params.market.chainId - Chain containing the BlueBundlesV1 deployment.
16
+ * @param params.market.marketParams - Scoped Morpho Blue market parameters.
17
+ * @param params.args.userAddress - User funding and receiving the position.
18
+ * @param params.args.assets - Gross loan-token funding amount.
19
+ * @param params.args.nativeAmount - Exclusive native funding; must equal `assets`.
20
+ * @param params.args.deadline - Final call deadline in Unix seconds.
21
+ * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
22
+ * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
23
+ * @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer result.
24
+ * @param params.metadata - Optional transaction metadata.
25
+ * @returns A deep-frozen `Readonly<Transaction<BlueSupplyAction>>` whose `to` address is
26
+ * BlueBundlesV1 and whose `action` records the normalized supply inputs.
27
+ * @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
28
+ * @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
29
+ * @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
30
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
31
+ * @throws {NativeFundingAmountMismatchError} when native funding does not equal `assets`.
32
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
33
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
34
+ * @throws {UnexpectedRequirementSignatureError} when native funding also supplies a token signature.
35
+ * @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
36
+ * @throws {DepositAssetMismatchError} when the signed asset differs from the loan token.
37
+ * @throws {DepositAmountMismatchError} when the signed amount differs from `assets`.
38
+ * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
39
+ * @throws {BundlesRequirementSignatureMismatchError} when the signature kind or encoding is invalid.
40
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
41
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
41
42
  * @example
42
43
  * ```ts
44
+ * import { markets } from "@morpho-org/morpho-test";
43
45
  * import { blueSupply } from "@morpho-org/morpho-sdk";
46
+ * import { zeroAddress } from "viem";
47
+ * import { mainnet } from "viem/chains";
44
48
  *
49
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
45
50
  * const tx = blueSupply({
46
- * market: { chainId: 1, marketParams },
51
+ * market: { chainId: mainnet.id, marketParams },
47
52
  * args: {
48
- * amount: 1_000_000_000n,
49
- * onBehalf: supplier,
50
- * maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
53
+ * userAddress: zeroAddress,
54
+ * assets: 1_000_000n,
55
+ * deadline: 1_900_000_000n,
51
56
  * },
52
57
  * });
53
58
  * // tx satisfies Readonly<Transaction<BlueSupplyAction>>
54
59
  * ```
55
60
  */
56
- const blueSupply = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, maxSharePrice, requirementSignature, nativeAmount, }, metadata, }) => {
57
- if (amount < 0n) {
58
- throw new index_js_3.NegativeInputError("amount", amount);
59
- }
60
- if (nativeAmount !== undefined && nativeAmount < 0n) {
61
- throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
62
- }
63
- if (maxSharePrice < 0n) {
64
- throw new index_js_3.NegativeInputError("maxSharePrice", maxSharePrice);
61
+ const blueSupply = (params) => {
62
+ const { chainId, marketParams } = params.market;
63
+ const { assets, userAddress, requirementSignature } = params.args;
64
+ if (assets <= 0n) {
65
+ throw new index_js_1.NonPositiveInputError("assets", assets);
65
66
  }
66
- const totalAssets = amount + (nativeAmount ?? 0n);
67
- if (totalAssets === 0n) {
68
- throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
67
+ if (assets > viem_1.maxUint256) {
68
+ throw new index_js_1.InputExceedsMaxError({
69
+ field: "assets",
70
+ value: assets,
71
+ max: viem_1.maxUint256,
72
+ });
69
73
  }
70
- const actions = (0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
74
+ const common = {
75
+ chainId,
76
+ userAddress,
77
+ deadline: params.args.deadline,
78
+ referralFeePct: params.args.referralFeePct,
79
+ referralFeeRecipient: params.args.referralFeeRecipient,
80
+ metadata: params.metadata,
81
+ };
82
+ const { referralFeePct, referralFeeRecipient } = (0, common_js_1.normalizeBlueBundlesV1CommonParams)(common);
83
+ const value = (0, common_js_1.validateBlueBundlesV1NativeFunding)({
71
84
  chainId,
72
- asset: marketParams.loanToken,
73
- erc20Amount: amount,
74
- nativeAmount: nativeAmount ?? 0n,
85
+ token: marketParams.loanToken,
86
+ fundedAmount: assets,
87
+ nativeAmount: params.args.nativeAmount,
75
88
  requirementSignature,
76
89
  });
77
- actions.push({
78
- type: "morphoSupply",
79
- args: [marketParams, totalAssets, 0n, maxSharePrice, onBehalf, [], false],
90
+ const tokenPermit = (0, common_js_1.getBlueBundlesV1TokenPermit)({
91
+ chainId,
92
+ userAddress,
93
+ token: marketParams.loanToken,
94
+ amount: assets,
95
+ requirementSignature,
80
96
  });
81
- let tx = {
82
- ...index_js_1.BundlerAction.encodeBundle(chainId, actions),
83
- value: nativeAmount ?? 0n,
84
- };
85
- if (metadata) {
86
- tx = (0, index_js_2.addTransactionMetadata)(tx, metadata);
87
- }
88
- return (0, morpho_ts_1.deepFreeze)({
89
- ...tx,
97
+ return (0, common_js_1.finalizeBlueBundlesV1Transaction)({
98
+ common,
99
+ value,
100
+ data: (0, viem_1.encodeFunctionData)({
101
+ abi: abis_js_1.blueBundlesV1Abi,
102
+ functionName: "blueBundlesV1Supply",
103
+ args: [
104
+ marketParams,
105
+ assets,
106
+ tokenPermit,
107
+ referralFeePct,
108
+ referralFeeRecipient,
109
+ params.args.deadline,
110
+ ],
111
+ }),
90
112
  action: {
91
113
  type: "blueSupply",
92
114
  args: {
93
115
  market: marketParams.id,
94
- amount: totalAssets,
95
- onBehalf,
96
- maxSharePrice,
97
- nativeAmount,
116
+ assets,
117
+ onBehalf: userAddress,
118
+ nativeAmount: value > 0n ? value : undefined,
119
+ referralFeePct,
120
+ referralFeeRecipient,
121
+ deadline: params.args.deadline,
98
122
  },
99
123
  },
100
124
  });
@@ -1,60 +1,83 @@
1
1
  import type { MarketParams } from "@morpho-org/blue-sdk";
2
- import type { Address } from "viem";
3
- import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
2
+ import { type Address } from "viem";
3
+ import type { BlueSupplyCollateralAction, BundlesTokenRequirementSignature, Metadata, Transaction } from "../../types/index.js";
4
4
  /** Parameters for {@link blueSupplyCollateral}. */
5
5
  export interface BlueSupplyCollateralParams {
6
- market: {
6
+ /** Chain and scoped Morpho Blue market. */
7
+ readonly market: {
7
8
  readonly chainId: number;
8
9
  readonly marketParams: MarketParams;
9
10
  };
10
- args: DepositAmountArgs & {
11
- /** Address whose Morpho collateral position is credited. */
12
- onBehalf: Address;
13
- /** Optional pre-signed permit/permit2 approval for the collateral transfer. */
14
- requirementSignature?: PermitRequirementSignature;
11
+ /** Direct BlueBundlesV1 collateral-supply arguments. */
12
+ readonly args: {
13
+ /** User whose collateral position is credited. */
14
+ readonly userAddress: Address;
15
+ /** Gross collateral assets supplied. */
16
+ readonly collateralAssets: bigint;
17
+ /** Full native collateral funding; must equal `collateralAssets`. */
18
+ readonly nativeAmount?: bigint;
19
+ /** Final call deadline in Unix seconds. */
20
+ readonly deadline: bigint;
21
+ /** Optional WAD-scaled referral fee, strictly below 100%. */
22
+ readonly referralFeePct?: bigint;
23
+ /** Recipient required when `referralFeePct` is positive. */
24
+ readonly referralFeeRecipient?: Address;
25
+ /** Optional collateral ERC-2612 or Permit2 SignatureTransfer result. */
26
+ readonly requirementSignature?: BundlesTokenRequirementSignature;
15
27
  };
16
- metadata?: Metadata;
28
+ /** Optional transaction metadata suffix. */
29
+ readonly metadata?: Metadata;
17
30
  }
18
31
  /**
19
- * Prepares a supply-collateral transaction for a Morpho Blue market.
32
+ * Encodes a pure collateral supply through BlueBundlesV1.
20
33
  *
21
- * Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
22
- * via `GeneralAdapter1.wrapNative()` before the collateral supply; the collateral token must be
23
- * the chain's wNative for that path.
34
+ * Delegates to {@link blueSupplyCollateralBorrow} with a zero borrow leg and an unrestricted LTV
35
+ * cap. Native funding is exclusive with ERC-20 funding and no Bundler3 action is encoded.
24
36
  *
25
- * Zero loss: all collateral reaches Morpho. No dust left in bundler or adapter.
26
- *
27
- * @param params.market.chainId - The chain the market lives on.
28
- * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
29
- * @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
30
- * `nativeAmount` must be positive. Defaults to `0n`.
31
- * @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
32
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
33
- * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
34
- * supply. Requires the collateral token to be the chain's wNative.
35
- * @param params.metadata - Optional analytics metadata attached to the bundle.
36
- * @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
37
- * and the typed `action` discriminator the simulation layer consumes.
38
- * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
39
- * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
40
- * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
41
- * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
42
- * token is not the chain's wNative.
43
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
44
- * is provided and the signed asset differs from `marketParams.collateralToken`.
45
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
46
- * is provided and the signed amount differs from `args.amount`.
47
- * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
48
- * signature is missing its expiration.
37
+ * @param params - Collateral-supply encoding parameters.
38
+ * @param params.market.chainId - Chain containing BlueBundlesV1.
39
+ * @param params.market.marketParams - Scoped Morpho Blue market parameters.
40
+ * @param params.args.userAddress - User whose collateral position is credited.
41
+ * @param params.args.collateralAssets - Gross collateral assets supplied.
42
+ * @param params.args.nativeAmount - Exclusive native collateral funding.
43
+ * @param params.args.deadline - Final call deadline in Unix seconds.
44
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
45
+ * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
46
+ * @param params.args.requirementSignature - Optional collateral-token signature.
47
+ * @param params.metadata - Optional transaction metadata.
48
+ * @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
49
+ * invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
50
+ * @throws {NegativeInputError} when an amount or fee is negative.
51
+ * @throws {NonPositiveInputError} when collateral or deadline is not positive.
52
+ * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
53
+ * @throws {ChainWNativeMissingError} when native funding is requested without a registered wNative.
54
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another collateral token.
55
+ * @throws {UnexpectedRequirementSignatureError} when native funding also supplies a token signature.
56
+ * @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
57
+ * @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
58
+ * @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
59
+ * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
60
+ * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
61
+ * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
62
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
63
+ * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
64
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
49
65
  * @example
50
66
  * ```ts
67
+ * import { markets } from "@morpho-org/morpho-test";
51
68
  * import { blueSupplyCollateral } from "@morpho-org/morpho-sdk";
69
+ * import { zeroAddress } from "viem";
70
+ * import { mainnet } from "viem/chains";
52
71
  *
53
72
  * const tx = blueSupplyCollateral({
54
- * market: { chainId: 1, marketParams },
55
- * args: { amount: 1_000_000_000_000_000_000n, onBehalf },
73
+ * market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
74
+ * args: {
75
+ * userAddress: zeroAddress,
76
+ * collateralAssets: 1_000_000_000_000_000_000n,
77
+ * deadline: 1_900_000_000n,
78
+ * },
56
79
  * });
57
80
  * // tx satisfies Readonly<Transaction<BlueSupplyCollateralAction>>
58
81
  * ```
59
82
  */
60
- export declare const blueSupplyCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, requirementSignature, nativeAmount }, metadata, }: BlueSupplyCollateralParams) => Readonly<Transaction<BlueSupplyCollateralAction>>;
83
+ export declare const blueSupplyCollateral: (params: BlueSupplyCollateralParams) => Readonly<Transaction<BlueSupplyCollateralAction>>;
@@ -2,89 +2,72 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blueSupplyCollateral = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
- const index_js_1 = require("../../bundler/index.js");
6
- const index_js_2 = require("../../helpers/index.js");
7
- const index_js_3 = require("../../types/index.js");
8
- const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
5
+ const viem_1 = require("viem");
6
+ const supplyCollateralBorrow_js_1 = require("./supplyCollateralBorrow.js");
9
7
  /**
10
- * Prepares a supply-collateral transaction for a Morpho Blue market.
8
+ * Encodes a pure collateral supply through BlueBundlesV1.
11
9
  *
12
- * Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
13
- * via `GeneralAdapter1.wrapNative()` before the collateral supply; the collateral token must be
14
- * the chain's wNative for that path.
10
+ * Delegates to {@link blueSupplyCollateralBorrow} with a zero borrow leg and an unrestricted LTV
11
+ * cap. Native funding is exclusive with ERC-20 funding and no Bundler3 action is encoded.
15
12
  *
16
- * Zero loss: all collateral reaches Morpho. No dust left in bundler or adapter.
17
- *
18
- * @param params.market.chainId - The chain the market lives on.
19
- * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
20
- * @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
21
- * `nativeAmount` must be positive. Defaults to `0n`.
22
- * @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
23
- * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
24
- * @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
25
- * supply. Requires the collateral token to be the chain's wNative.
26
- * @param params.metadata - Optional analytics metadata attached to the bundle.
27
- * @returns A deep-frozen `Transaction<BlueSupplyCollateralAction>` with `to`, `value`, `data`,
28
- * and the typed `action` discriminator the simulation layer consumes.
29
- * @throws {NegativeInputError} when `amount < 0n` or `nativeAmount < 0n`.
30
- * @throws {NonPositiveInputError} when both `amount` and `nativeAmount` resolve to zero.
31
- * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
32
- * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
33
- * token is not the chain's wNative.
34
- * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
35
- * is provided and the signed asset differs from `marketParams.collateralToken`.
36
- * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
37
- * is provided and the signed amount differs from `args.amount`.
38
- * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
39
- * signature is missing its expiration.
13
+ * @param params - Collateral-supply encoding parameters.
14
+ * @param params.market.chainId - Chain containing BlueBundlesV1.
15
+ * @param params.market.marketParams - Scoped Morpho Blue market parameters.
16
+ * @param params.args.userAddress - User whose collateral position is credited.
17
+ * @param params.args.collateralAssets - Gross collateral assets supplied.
18
+ * @param params.args.nativeAmount - Exclusive native collateral funding.
19
+ * @param params.args.deadline - Final call deadline in Unix seconds.
20
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
21
+ * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
22
+ * @param params.args.requirementSignature - Optional collateral-token signature.
23
+ * @param params.metadata - Optional transaction metadata.
24
+ * @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
25
+ * invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
26
+ * @throws {NegativeInputError} when an amount or fee is negative.
27
+ * @throws {NonPositiveInputError} when collateral or deadline is not positive.
28
+ * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
29
+ * @throws {ChainWNativeMissingError} when native funding is requested without a registered wNative.
30
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another collateral token.
31
+ * @throws {UnexpectedRequirementSignatureError} when native funding also supplies a token signature.
32
+ * @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
33
+ * @throws {DepositAssetMismatchError} when the signed asset differs from the collateral token.
34
+ * @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
35
+ * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
36
+ * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
37
+ * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
38
+ * @throws {MissingReferralFeeRecipientError} when a positive fee has no recipient.
39
+ * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
40
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
40
41
  * @example
41
42
  * ```ts
43
+ * import { markets } from "@morpho-org/morpho-test";
42
44
  * import { blueSupplyCollateral } from "@morpho-org/morpho-sdk";
45
+ * import { zeroAddress } from "viem";
46
+ * import { mainnet } from "viem/chains";
43
47
  *
44
48
  * const tx = blueSupplyCollateral({
45
- * market: { chainId: 1, marketParams },
46
- * args: { amount: 1_000_000_000_000_000_000n, onBehalf },
49
+ * market: { chainId: mainnet.id, marketParams: markets[mainnet.id].usdc_wbtc },
50
+ * args: {
51
+ * userAddress: zeroAddress,
52
+ * collateralAssets: 1_000_000_000_000_000_000n,
53
+ * deadline: 1_900_000_000n,
54
+ * },
47
55
  * });
48
56
  * // tx satisfies Readonly<Transaction<BlueSupplyCollateralAction>>
49
57
  * ```
50
58
  */
51
- const blueSupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
52
- if (amount < 0n) {
53
- throw new index_js_3.NegativeInputError("amount", amount);
54
- }
55
- if (nativeAmount !== undefined && nativeAmount < 0n) {
56
- throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
57
- }
58
- const totalCollateral = amount + (nativeAmount ?? 0n);
59
- if (totalCollateral === 0n) {
60
- throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
61
- }
62
- const actions = (0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
63
- chainId,
64
- asset: marketParams.collateralToken,
65
- erc20Amount: amount,
66
- nativeAmount: nativeAmount ?? 0n,
67
- requirementSignature,
68
- });
69
- actions.push({
70
- type: "morphoSupplyCollateral",
71
- args: [marketParams, totalCollateral, onBehalf, [], false],
59
+ const blueSupplyCollateral = (params) => {
60
+ const transaction = (0, supplyCollateralBorrow_js_1.blueSupplyCollateralBorrow)({
61
+ ...params,
62
+ args: {
63
+ ...params.args,
64
+ borrowAssets: 0n,
65
+ maxLtv: viem_1.maxUint256,
66
+ },
72
67
  });
73
- let tx = index_js_1.BundlerAction.encodeBundle(chainId, actions);
74
- if (metadata) {
75
- tx = (0, index_js_2.addTransactionMetadata)(tx, metadata);
76
- }
77
68
  return (0, morpho_ts_1.deepFreeze)({
78
- ...tx,
79
- action: {
80
- type: "blueSupplyCollateral",
81
- args: {
82
- market: marketParams.id,
83
- amount: totalCollateral,
84
- onBehalf,
85
- nativeAmount,
86
- },
87
- },
69
+ ...transaction,
70
+ action: { ...transaction.action, type: "blueSupplyCollateral" },
88
71
  });
89
72
  };
90
73
  exports.blueSupplyCollateral = blueSupplyCollateral;