@morpho-org/morpho-sdk 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +31 -33
- package/lib/cjs/actions/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/index.js +4 -4
- package/lib/cjs/actions/marketV1/borrow.d.ts +69 -0
- package/lib/cjs/actions/marketV1/borrow.js +97 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.js +47 -0
- package/lib/cjs/actions/marketV1/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/marketV1/index.js +6 -6
- package/lib/cjs/actions/marketV1/repay.d.ts +89 -0
- package/lib/cjs/actions/marketV1/repay.js +134 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +155 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.js +116 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +163 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.js +72 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Approval.js +25 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +108 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Permit2.js +36 -4
- package/lib/cjs/actions/requirements/encode/index.d.ts +3 -0
- package/lib/{actions → cjs/actions}/requirements/encode/index.js +3 -3
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +71 -0
- package/lib/cjs/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/cjs/actions/requirements/getRequirements.js +112 -0
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/{actions → cjs/actions}/requirements/getRequirementsAction.js +20 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +57 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +85 -0
- package/lib/cjs/actions/requirements/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/requirements/index.js +6 -6
- package/lib/cjs/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV1/deposit.js +146 -0
- package/lib/cjs/actions/vaultV1/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/vaultV1/index.js +4 -4
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +143 -0
- package/lib/cjs/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/redeem.js +57 -0
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/withdraw.js +57 -0
- package/lib/cjs/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV2/deposit.js +146 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.js +99 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +94 -0
- package/lib/cjs/actions/vaultV2/index.d.ts +5 -0
- package/lib/{actions → cjs/actions}/vaultV2/index.js +5 -5
- package/lib/cjs/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/redeem.js +58 -0
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/withdraw.js +58 -0
- package/lib/cjs/client/index.d.ts +2 -0
- package/lib/{client → cjs/client}/index.js +2 -2
- package/lib/cjs/client/morphoClient.d.ts +113 -0
- package/lib/cjs/client/morphoClient.js +123 -0
- package/lib/cjs/client/morphoViemExtension.d.ts +45 -0
- package/lib/cjs/client/morphoViemExtension.js +46 -0
- package/lib/cjs/entities/index.d.ts +3 -0
- package/lib/{entities → cjs/entities}/index.js +3 -3
- package/lib/cjs/entities/marketV1/index.d.ts +1 -0
- package/lib/{entities/vaultV1 → cjs/entities/marketV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/marketV1/marketV1.d.ts +9 -6
- package/lib/{entities → cjs/entities}/marketV1/marketV1.js +89 -87
- package/lib/cjs/entities/vaultV1/index.d.ts +1 -0
- package/lib/{entities/marketV1 → cjs/entities/vaultV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.d.ts +4 -8
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.js +39 -35
- package/lib/cjs/entities/vaultV2/index.d.ts +1 -0
- package/lib/{entities → cjs/entities}/vaultV2/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.d.ts +2 -2
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.js +25 -24
- package/lib/{helpers → cjs/helpers}/computeReallocations.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/computeReallocations.js +2 -2
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.js +2 -2
- package/lib/{helpers → cjs/helpers}/index.d.ts +4 -4
- package/lib/{helpers → cjs/helpers}/index.js +19 -19
- package/lib/{helpers → cjs/helpers}/metadata.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/slippage.js +7 -7
- package/lib/{helpers → cjs/helpers}/validate.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/validate.js +33 -33
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/package.json +1 -0
- package/lib/{types → cjs/types}/action.d.ts +1 -1
- package/lib/{types → cjs/types}/client.d.ts +6 -2
- package/lib/{types → cjs/types}/error.d.ts +46 -7
- package/lib/{types → cjs/types}/error.js +47 -7
- package/lib/cjs/types/index.d.ts +7 -0
- package/lib/cjs/types/index.js +23 -0
- package/lib/esm/actions/index.d.ts +4 -0
- package/lib/esm/actions/index.js +4 -0
- package/lib/esm/actions/marketV1/borrow.d.ts +69 -0
- package/lib/esm/actions/marketV1/borrow.js +93 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.js +43 -0
- package/lib/esm/actions/marketV1/index.d.ts +6 -0
- package/lib/esm/actions/marketV1/index.js +6 -0
- package/lib/esm/actions/marketV1/repay.d.ts +89 -0
- package/lib/esm/actions/marketV1/repay.js +130 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +151 -0
- package/lib/esm/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/esm/actions/marketV1/supplyCollateral.js +112 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +159 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.js +68 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +46 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +104 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +98 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/index.js +3 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +67 -0
- package/lib/esm/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/esm/actions/requirements/getRequirements.js +108 -0
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/esm/actions/requirements/getRequirementsAction.js +76 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.js +59 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.js +53 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +81 -0
- package/lib/esm/actions/requirements/index.d.ts +6 -0
- package/lib/esm/actions/requirements/index.js +6 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV1/deposit.js +142 -0
- package/lib/esm/actions/vaultV1/index.d.ts +4 -0
- package/lib/esm/actions/vaultV1/index.js +4 -0
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +139 -0
- package/lib/esm/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/esm/actions/vaultV1/redeem.js +53 -0
- package/lib/esm/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/esm/actions/vaultV1/withdraw.js +53 -0
- package/lib/esm/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV2/deposit.js +142 -0
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/esm/actions/vaultV2/forceRedeem.js +95 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.js +90 -0
- package/lib/esm/actions/vaultV2/index.d.ts +5 -0
- package/lib/esm/actions/vaultV2/index.js +5 -0
- package/lib/esm/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/esm/actions/vaultV2/redeem.js +54 -0
- package/lib/esm/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/esm/actions/vaultV2/withdraw.js +54 -0
- package/lib/esm/client/index.d.ts +2 -0
- package/lib/esm/client/index.js +2 -0
- package/lib/esm/client/morphoClient.d.ts +113 -0
- package/lib/esm/client/morphoClient.js +119 -0
- package/lib/esm/client/morphoViemExtension.d.ts +45 -0
- package/lib/esm/client/morphoViemExtension.js +43 -0
- package/lib/esm/entities/index.d.ts +3 -0
- package/lib/esm/entities/index.js +3 -0
- package/lib/esm/entities/marketV1/index.d.ts +1 -0
- package/lib/esm/entities/marketV1/index.js +1 -0
- package/lib/esm/entities/marketV1/marketV1.d.ts +293 -0
- package/lib/esm/entities/marketV1/marketV1.js +529 -0
- package/lib/esm/entities/vaultV1/index.d.ts +1 -0
- package/lib/esm/entities/vaultV1/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +129 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +186 -0
- package/lib/esm/entities/vaultV2/index.d.ts +1 -0
- package/lib/esm/entities/vaultV2/index.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +180 -0
- package/lib/esm/entities/vaultV2/vaultV2.js +164 -0
- package/lib/esm/helpers/computeReallocations.d.ts +23 -0
- package/lib/esm/helpers/computeReallocations.js +94 -0
- package/lib/esm/helpers/constant.d.ts +6 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +10 -0
- package/lib/esm/helpers/encodeDeallocation.js +34 -0
- package/lib/esm/helpers/index.d.ts +4 -0
- package/lib/esm/helpers/index.js +4 -0
- package/lib/esm/helpers/metadata.d.ts +33 -0
- package/lib/esm/helpers/metadata.js +46 -0
- package/lib/esm/helpers/slippage.d.ts +46 -0
- package/lib/esm/helpers/slippage.js +69 -0
- package/lib/esm/helpers/validate.d.ts +156 -0
- package/lib/esm/helpers/validate.js +273 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/types/action.d.ts +216 -0
- package/lib/esm/types/action.js +21 -0
- package/lib/esm/types/client.d.ts +19 -0
- package/lib/esm/types/client.js +1 -0
- package/lib/esm/types/data.d.ts +2 -0
- package/lib/esm/types/data.js +1 -0
- package/lib/esm/types/deallocation.d.ts +15 -0
- package/lib/esm/types/deallocation.js +1 -0
- package/lib/esm/types/entity.d.ts +5 -0
- package/lib/esm/types/entity.js +1 -0
- package/lib/esm/types/error.d.ts +205 -0
- package/lib/esm/types/error.js +276 -0
- package/lib/esm/types/index.d.ts +7 -0
- package/lib/esm/types/index.js +7 -0
- package/lib/esm/types/metadata.d.ts +4 -0
- package/lib/esm/types/metadata.js +1 -0
- package/lib/esm/types/sharedLiquidity.d.ts +41 -0
- package/lib/esm/types/sharedLiquidity.js +1 -0
- package/package.json +33 -56
- package/src/index.ts +5 -0
- package/lib/actions/index.d.ts +0 -4
- package/lib/actions/marketV1/borrow.d.ts +0 -34
- package/lib/actions/marketV1/borrow.js +0 -62
- package/lib/actions/marketV1/buildReallocationActions.d.ts +0 -17
- package/lib/actions/marketV1/buildReallocationActions.js +0 -36
- package/lib/actions/marketV1/index.d.ts +0 -6
- package/lib/actions/marketV1/repay.d.ts +0 -44
- package/lib/actions/marketV1/repay.js +0 -93
- package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +0 -51
- package/lib/actions/marketV1/repayWithdrawCollateral.js +0 -108
- package/lib/actions/marketV1/supplyCollateral.d.ts +0 -28
- package/lib/actions/marketV1/supplyCollateral.js +0 -85
- package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +0 -37
- package/lib/actions/marketV1/supplyCollateralBorrow.js +0 -109
- package/lib/actions/marketV1/withdrawCollateral.d.ts +0 -28
- package/lib/actions/marketV1/withdrawCollateral.js +0 -51
- package/lib/actions/requirements/encode/encodeErc20Approval.d.ts +0 -10
- package/lib/actions/requirements/encode/encodeErc20Permit.d.ts +0 -13
- package/lib/actions/requirements/encode/encodeErc20Permit.js +0 -70
- package/lib/actions/requirements/encode/encodeErc20Permit2.d.ts +0 -11
- package/lib/actions/requirements/encode/index.d.ts +0 -3
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -21
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +0 -55
- package/lib/actions/requirements/getRequirements.d.ts +0 -42
- package/lib/actions/requirements/getRequirements.js +0 -80
- package/lib/actions/requirements/getRequirementsAction.d.ts +0 -17
- package/lib/actions/requirements/getRequirementsApproval.d.ts +0 -31
- package/lib/actions/requirements/getRequirementsApproval.js +0 -51
- package/lib/actions/requirements/getRequirementsPermit.d.ts +0 -28
- package/lib/actions/requirements/getRequirementsPermit.js +0 -40
- package/lib/actions/requirements/getRequirementsPermit2.d.ts +0 -37
- package/lib/actions/requirements/getRequirementsPermit2.js +0 -59
- package/lib/actions/requirements/index.d.ts +0 -6
- package/lib/actions/vaultV1/deposit.d.ts +0 -41
- package/lib/actions/vaultV1/deposit.js +0 -116
- package/lib/actions/vaultV1/index.d.ts +0 -4
- package/lib/actions/vaultV1/migrateToV2.d.ts +0 -50
- package/lib/actions/vaultV1/migrateToV2.js +0 -108
- package/lib/actions/vaultV1/redeem.d.ts +0 -29
- package/lib/actions/vaultV1/redeem.js +0 -48
- package/lib/actions/vaultV1/withdraw.d.ts +0 -29
- package/lib/actions/vaultV1/withdraw.js +0 -48
- package/lib/actions/vaultV2/deposit.d.ts +0 -41
- package/lib/actions/vaultV2/deposit.js +0 -116
- package/lib/actions/vaultV2/forceRedeem.d.ts +0 -48
- package/lib/actions/vaultV2/forceRedeem.js +0 -85
- package/lib/actions/vaultV2/forceWithdraw.d.ts +0 -40
- package/lib/actions/vaultV2/forceWithdraw.js +0 -85
- package/lib/actions/vaultV2/index.d.ts +0 -5
- package/lib/actions/vaultV2/redeem.d.ts +0 -32
- package/lib/actions/vaultV2/redeem.js +0 -51
- package/lib/actions/vaultV2/withdraw.d.ts +0 -32
- package/lib/actions/vaultV2/withdraw.js +0 -51
- package/lib/client/index.d.ts +0 -2
- package/lib/client/morphoClient.d.ts +0 -25
- package/lib/client/morphoClient.js +0 -28
- package/lib/client/morphoViemExtension.d.ts +0 -39
- package/lib/client/morphoViemExtension.js +0 -40
- package/lib/entities/index.d.ts +0 -3
- package/lib/entities/marketV1/index.d.ts +0 -1
- package/lib/entities/vaultV1/index.d.ts +0 -1
- package/lib/entities/vaultV2/index.d.ts +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -21
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -23
- /package/lib/{helpers → cjs/helpers}/constant.d.ts +0 -0
- /package/lib/{helpers → cjs/helpers}/constant.js +0 -0
- /package/lib/{helpers → cjs/helpers}/metadata.js +0 -0
- /package/lib/{helpers → cjs/helpers}/slippage.d.ts +0 -0
- /package/lib/{types → cjs/types}/action.js +0 -0
- /package/lib/{types → cjs/types}/client.js +0 -0
- /package/lib/{types → cjs/types}/data.d.ts +0 -0
- /package/lib/{types → cjs/types}/data.js +0 -0
- /package/lib/{types → cjs/types}/deallocation.d.ts +0 -0
- /package/lib/{types → cjs/types}/deallocation.js +0 -0
- /package/lib/{types → cjs/types}/entity.d.ts +0 -0
- /package/lib/{types → cjs/types}/entity.js +0 -0
- /package/lib/{types → cjs/types}/metadata.d.ts +0 -0
- /package/lib/{types → cjs/types}/metadata.js +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.d.ts +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.js +0 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.marketV1Repay = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const getRequirementsAction_js_1 = require("../requirements/getRequirementsAction.js");
|
|
10
|
+
/**
|
|
11
|
+
* Prepares a repay transaction for a Morpho Blue market.
|
|
12
|
+
*
|
|
13
|
+
* Routed through bundler3 via `GeneralAdapter1`. Supports two modes:
|
|
14
|
+
*
|
|
15
|
+
* - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
|
|
16
|
+
* - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with
|
|
17
|
+
* `transferAmount` set to an upper-bound asset estimate; residual loan tokens are skimmed back
|
|
18
|
+
* to `receiver` after the call.
|
|
19
|
+
*
|
|
20
|
+
* Exactly one of `assets` / `shares` must be non-zero. Uses `maxSharePrice` to protect against
|
|
21
|
+
* share price manipulation between transaction construction and execution.
|
|
22
|
+
*
|
|
23
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
24
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
25
|
+
* @param params.args.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
|
|
26
|
+
* @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
|
|
27
|
+
* @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
|
|
28
|
+
* mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
|
|
29
|
+
* In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
|
|
30
|
+
* tokens are skimmed back to `receiver`.
|
|
31
|
+
* @param params.args.onBehalf - Address whose Morpho debt is being repaid.
|
|
32
|
+
* @param params.args.receiver - Address that receives residual loan tokens in shares mode.
|
|
33
|
+
* @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
|
|
34
|
+
* protection.
|
|
35
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
36
|
+
* loan-token transfer.
|
|
37
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
38
|
+
* @returns A deep-frozen `Transaction<MarketV1RepayAction>` with `to`, `value`, `data`, and the
|
|
39
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
40
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
41
|
+
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
42
|
+
* both are zero.
|
|
43
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
44
|
+
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
45
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
46
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
47
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
48
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
49
|
+
* is provided and the signed amount differs from `args.transferAmount`.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { marketV1Repay } from "@morpho-org/morpho-sdk";
|
|
53
|
+
*
|
|
54
|
+
* const tx = marketV1Repay({
|
|
55
|
+
* market: { chainId: 1, marketParams },
|
|
56
|
+
* args: {
|
|
57
|
+
* assets: 500_000_000n,
|
|
58
|
+
* shares: 0n,
|
|
59
|
+
* transferAmount: 500_000_000n,
|
|
60
|
+
* onBehalf: borrower,
|
|
61
|
+
* receiver: borrower,
|
|
62
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
* // tx satisfies Readonly<Transaction<MarketV1RepayAction>>
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
const marketV1Repay = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }) => {
|
|
69
|
+
(0, index_js_1.validateRepayParams)({
|
|
70
|
+
assets,
|
|
71
|
+
shares,
|
|
72
|
+
transferAmount,
|
|
73
|
+
maxSharePrice,
|
|
74
|
+
marketId: marketParams.id,
|
|
75
|
+
});
|
|
76
|
+
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
77
|
+
const actions = [];
|
|
78
|
+
if (requirementSignature) {
|
|
79
|
+
actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
|
|
80
|
+
chainId,
|
|
81
|
+
asset: marketParams.loanToken,
|
|
82
|
+
amount: transferAmount,
|
|
83
|
+
requirementSignature,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
actions.push({
|
|
88
|
+
type: "erc20TransferFrom",
|
|
89
|
+
args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
actions.push({
|
|
93
|
+
type: "morphoRepay",
|
|
94
|
+
args: [marketParams, assets, shares, maxSharePrice, onBehalf, [], false],
|
|
95
|
+
});
|
|
96
|
+
// Skim residual loan tokens back to the payer when repaying by shares.
|
|
97
|
+
// In shares mode, transferAmount is an upper-bound estimate; morphoRepay
|
|
98
|
+
// consumes only the exact amount needed, leaving a residual in the adapter.
|
|
99
|
+
if (shares > 0n) {
|
|
100
|
+
actions.push({
|
|
101
|
+
type: "erc20Transfer",
|
|
102
|
+
args: [
|
|
103
|
+
marketParams.loanToken,
|
|
104
|
+
receiver,
|
|
105
|
+
viem_1.maxUint256,
|
|
106
|
+
generalAdapter1,
|
|
107
|
+
false,
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
let tx = {
|
|
112
|
+
...bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions),
|
|
113
|
+
value: 0n,
|
|
114
|
+
};
|
|
115
|
+
if (metadata) {
|
|
116
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
|
|
117
|
+
}
|
|
118
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
119
|
+
...tx,
|
|
120
|
+
action: {
|
|
121
|
+
type: "marketV1Repay",
|
|
122
|
+
args: {
|
|
123
|
+
market: marketParams.id,
|
|
124
|
+
assets,
|
|
125
|
+
shares,
|
|
126
|
+
transferAmount,
|
|
127
|
+
onBehalf,
|
|
128
|
+
receiver,
|
|
129
|
+
maxSharePrice,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
exports.marketV1Repay = marketV1Repay;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type MarketV1RepayWithdrawCollateralAction, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link marketV1RepayWithdrawCollateral}. */
|
|
5
|
+
export interface MarketV1RepayWithdrawCollateralParams {
|
|
6
|
+
market: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly marketParams: MarketParams;
|
|
9
|
+
};
|
|
10
|
+
args: {
|
|
11
|
+
/** Repay assets amount (0n when repaying by shares). */
|
|
12
|
+
assets: bigint;
|
|
13
|
+
/** Repay shares amount (0n when repaying by assets). */
|
|
14
|
+
shares: bigint;
|
|
15
|
+
/**
|
|
16
|
+
* ERC-20 amount to pull into `GeneralAdapter1`. In assets mode, must equal `assets`
|
|
17
|
+
* exactly (`TransferAmountNotEqualToAssetsError` fires otherwise). In shares mode, an
|
|
18
|
+
* upper-bound estimate to absorb share-price drift; residual loan tokens are skimmed
|
|
19
|
+
* back to `receiver`.
|
|
20
|
+
*/
|
|
21
|
+
transferAmount: bigint;
|
|
22
|
+
/** Amount of collateral to withdraw. */
|
|
23
|
+
withdrawAmount: bigint;
|
|
24
|
+
/** Address whose debt is being repaid. */
|
|
25
|
+
onBehalf: Address;
|
|
26
|
+
/** Receives withdrawn collateral and residual loan tokens in shares mode. */
|
|
27
|
+
receiver: Address;
|
|
28
|
+
/** Maximum repay share price (in ray). Protects against share price manipulation. */
|
|
29
|
+
maxSharePrice: bigint;
|
|
30
|
+
requirementSignature?: RequirementSignature;
|
|
31
|
+
};
|
|
32
|
+
metadata?: Metadata;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Prepares an atomic repay-and-withdraw-collateral transaction for a Morpho Blue market.
|
|
36
|
+
*
|
|
37
|
+
* Routed through bundler3. The bundle order is critical:
|
|
38
|
+
*
|
|
39
|
+
* 1. ERC-20 transfer of the loan token to `GeneralAdapter1`.
|
|
40
|
+
* 2. `morphoRepay` — reduces debt **first**.
|
|
41
|
+
* 3. `morphoWithdrawCollateral` — then withdraws collateral.
|
|
42
|
+
*
|
|
43
|
+
* If the order were reversed, Morpho would revert because the position would be insolvent at the
|
|
44
|
+
* time of the withdraw. Supports two repay modes:
|
|
45
|
+
*
|
|
46
|
+
* - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
|
|
47
|
+
* - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with residual
|
|
48
|
+
* loan tokens skimmed back to `receiver`.
|
|
49
|
+
*
|
|
50
|
+
* Prerequisites: ERC-20 approval for the loan token to `GeneralAdapter1` (for the repay) **and**
|
|
51
|
+
* `GeneralAdapter1` must be authorized on Morpho (for the withdraw).
|
|
52
|
+
*
|
|
53
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
54
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
55
|
+
* @param params.args.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
|
|
56
|
+
* @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
|
|
57
|
+
* @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
|
|
58
|
+
* mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
|
|
59
|
+
* In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
|
|
60
|
+
* tokens are skimmed back to `receiver`.
|
|
61
|
+
* @param params.args.withdrawAmount - Amount of collateral to withdraw after the repay leg
|
|
62
|
+
* completes.
|
|
63
|
+
* @param params.args.onBehalf - Address whose Morpho debt is being repaid.
|
|
64
|
+
* @param params.args.receiver - Address that receives the withdrawn collateral and any residual
|
|
65
|
+
* loan tokens in shares mode.
|
|
66
|
+
* @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
|
|
67
|
+
* protection.
|
|
68
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
69
|
+
* loan-token transfer.
|
|
70
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
71
|
+
* @returns A deep-frozen `Transaction<MarketV1RepayWithdrawCollateralAction>` with `to`,
|
|
72
|
+
* `value`, `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
73
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
74
|
+
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
75
|
+
* both are zero.
|
|
76
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
77
|
+
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
78
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
79
|
+
* @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
|
|
80
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
81
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
82
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
83
|
+
* is provided and the signed amount differs from `args.transferAmount`.
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { marketV1RepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
87
|
+
*
|
|
88
|
+
* const tx = marketV1RepayWithdrawCollateral({
|
|
89
|
+
* market: { chainId: 1, marketParams },
|
|
90
|
+
* args: {
|
|
91
|
+
* assets: 500_000_000n,
|
|
92
|
+
* shares: 0n,
|
|
93
|
+
* transferAmount: 500_000_000n,
|
|
94
|
+
* withdrawAmount: 1_000_000_000_000_000_000n,
|
|
95
|
+
* onBehalf: borrower,
|
|
96
|
+
* receiver: borrower,
|
|
97
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
98
|
+
* },
|
|
99
|
+
* });
|
|
100
|
+
* // tx satisfies Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare const marketV1RepayWithdrawCollateral: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }: MarketV1RepayWithdrawCollateralParams) => Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.marketV1RepayWithdrawCollateral = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const index_js_2 = require("../../types/index.js");
|
|
10
|
+
const getRequirementsAction_js_1 = require("../requirements/getRequirementsAction.js");
|
|
11
|
+
/**
|
|
12
|
+
* Prepares an atomic repay-and-withdraw-collateral transaction for a Morpho Blue market.
|
|
13
|
+
*
|
|
14
|
+
* Routed through bundler3. The bundle order is critical:
|
|
15
|
+
*
|
|
16
|
+
* 1. ERC-20 transfer of the loan token to `GeneralAdapter1`.
|
|
17
|
+
* 2. `morphoRepay` — reduces debt **first**.
|
|
18
|
+
* 3. `morphoWithdrawCollateral` — then withdraws collateral.
|
|
19
|
+
*
|
|
20
|
+
* If the order were reversed, Morpho would revert because the position would be insolvent at the
|
|
21
|
+
* time of the withdraw. Supports two repay modes:
|
|
22
|
+
*
|
|
23
|
+
* - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
|
|
24
|
+
* - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with residual
|
|
25
|
+
* loan tokens skimmed back to `receiver`.
|
|
26
|
+
*
|
|
27
|
+
* Prerequisites: ERC-20 approval for the loan token to `GeneralAdapter1` (for the repay) **and**
|
|
28
|
+
* `GeneralAdapter1` must be authorized on Morpho (for the withdraw).
|
|
29
|
+
*
|
|
30
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
31
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
32
|
+
* @param params.args.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
|
|
33
|
+
* @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
|
|
34
|
+
* @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
|
|
35
|
+
* mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
|
|
36
|
+
* In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
|
|
37
|
+
* tokens are skimmed back to `receiver`.
|
|
38
|
+
* @param params.args.withdrawAmount - Amount of collateral to withdraw after the repay leg
|
|
39
|
+
* completes.
|
|
40
|
+
* @param params.args.onBehalf - Address whose Morpho debt is being repaid.
|
|
41
|
+
* @param params.args.receiver - Address that receives the withdrawn collateral and any residual
|
|
42
|
+
* loan tokens in shares mode.
|
|
43
|
+
* @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
|
|
44
|
+
* protection.
|
|
45
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
46
|
+
* loan-token transfer.
|
|
47
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
48
|
+
* @returns A deep-frozen `Transaction<MarketV1RepayWithdrawCollateralAction>` with `to`,
|
|
49
|
+
* `value`, `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
50
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
51
|
+
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
52
|
+
* both are zero.
|
|
53
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
54
|
+
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
55
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
56
|
+
* @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
|
|
57
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
58
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
59
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
60
|
+
* is provided and the signed amount differs from `args.transferAmount`.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { marketV1RepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
64
|
+
*
|
|
65
|
+
* const tx = marketV1RepayWithdrawCollateral({
|
|
66
|
+
* market: { chainId: 1, marketParams },
|
|
67
|
+
* args: {
|
|
68
|
+
* assets: 500_000_000n,
|
|
69
|
+
* shares: 0n,
|
|
70
|
+
* transferAmount: 500_000_000n,
|
|
71
|
+
* withdrawAmount: 1_000_000_000_000_000_000n,
|
|
72
|
+
* onBehalf: borrower,
|
|
73
|
+
* receiver: borrower,
|
|
74
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
75
|
+
* },
|
|
76
|
+
* });
|
|
77
|
+
* // tx satisfies Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
const marketV1RepayWithdrawCollateral = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }) => {
|
|
81
|
+
(0, index_js_1.validateRepayParams)({
|
|
82
|
+
assets,
|
|
83
|
+
shares,
|
|
84
|
+
transferAmount,
|
|
85
|
+
maxSharePrice,
|
|
86
|
+
marketId: marketParams.id,
|
|
87
|
+
});
|
|
88
|
+
if (withdrawAmount <= 0n) {
|
|
89
|
+
throw new index_js_2.NonPositiveWithdrawCollateralAmountError(marketParams.id);
|
|
90
|
+
}
|
|
91
|
+
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
92
|
+
const actions = [];
|
|
93
|
+
if (requirementSignature) {
|
|
94
|
+
actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
|
|
95
|
+
chainId,
|
|
96
|
+
asset: marketParams.loanToken,
|
|
97
|
+
amount: transferAmount,
|
|
98
|
+
requirementSignature,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
actions.push({
|
|
103
|
+
type: "erc20TransferFrom",
|
|
104
|
+
args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// REPAY FIRST — reduces debt before withdrawing collateral
|
|
108
|
+
actions.push({
|
|
109
|
+
type: "morphoRepay",
|
|
110
|
+
args: [marketParams, assets, shares, maxSharePrice, onBehalf, [], false],
|
|
111
|
+
});
|
|
112
|
+
// Skim residual loan tokens back to the payer when repaying by shares.
|
|
113
|
+
// In shares mode, transferAmount is an upper-bound estimate; morphoRepay
|
|
114
|
+
// consumes only the exact amount needed, leaving a residual in the adapter.
|
|
115
|
+
if (shares > 0n) {
|
|
116
|
+
actions.push({
|
|
117
|
+
type: "erc20Transfer",
|
|
118
|
+
args: [
|
|
119
|
+
marketParams.loanToken,
|
|
120
|
+
receiver,
|
|
121
|
+
viem_1.maxUint256,
|
|
122
|
+
generalAdapter1,
|
|
123
|
+
false,
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
actions.push({
|
|
128
|
+
type: "morphoWithdrawCollateral",
|
|
129
|
+
args: [marketParams, withdrawAmount, receiver, false],
|
|
130
|
+
});
|
|
131
|
+
let tx = {
|
|
132
|
+
...bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions),
|
|
133
|
+
value: 0n,
|
|
134
|
+
};
|
|
135
|
+
if (metadata) {
|
|
136
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
|
|
137
|
+
}
|
|
138
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
139
|
+
...tx,
|
|
140
|
+
action: {
|
|
141
|
+
type: "marketV1RepayWithdrawCollateral",
|
|
142
|
+
args: {
|
|
143
|
+
market: marketParams.id,
|
|
144
|
+
repayAssets: assets,
|
|
145
|
+
repayShares: shares,
|
|
146
|
+
transferAmount,
|
|
147
|
+
withdrawAmount,
|
|
148
|
+
maxSharePrice,
|
|
149
|
+
onBehalf,
|
|
150
|
+
receiver,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
exports.marketV1RepayWithdrawCollateral = marketV1RepayWithdrawCollateral;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import { type DepositAmountArgs, type MarketV1SupplyCollateralAction, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link marketV1SupplyCollateral}. */
|
|
5
|
+
export interface MarketV1SupplyCollateralParams {
|
|
6
|
+
market: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly marketParams: MarketParams;
|
|
9
|
+
};
|
|
10
|
+
args: DepositAmountArgs & {
|
|
11
|
+
onBehalf: Address;
|
|
12
|
+
requirementSignature?: RequirementSignature;
|
|
13
|
+
};
|
|
14
|
+
metadata?: Metadata;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Prepares a supply-collateral transaction for a Morpho Blue market.
|
|
18
|
+
*
|
|
19
|
+
* Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
|
|
20
|
+
* via `GeneralAdapter1.wrapNative()` before the collateral supply; the collateral token must be
|
|
21
|
+
* the chain's wNative for that path.
|
|
22
|
+
*
|
|
23
|
+
* Zero loss: all collateral reaches Morpho. No dust left in bundler or adapter.
|
|
24
|
+
*
|
|
25
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
26
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
27
|
+
* @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
|
|
28
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
29
|
+
* @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
|
|
30
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
|
|
31
|
+
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
32
|
+
* approved `GeneralAdapter1`.
|
|
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<MarketV1SupplyCollateralAction>` with `to`, `value`, `data`,
|
|
37
|
+
* and the typed `action` discriminator the simulation layer consumes.
|
|
38
|
+
* @throws {NonPositiveAssetAmountError} when `amount < 0n`.
|
|
39
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
40
|
+
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
41
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
42
|
+
* @throws {NativeAmountOnNonWNativeCollateralError} when `nativeAmount > 0n` but the collateral
|
|
43
|
+
* token is not the chain's wNative.
|
|
44
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
45
|
+
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
46
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
47
|
+
* is provided and the signed amount differs from `args.amount`.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { marketV1SupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
51
|
+
*
|
|
52
|
+
* const tx = marketV1SupplyCollateral({
|
|
53
|
+
* market: { chainId: 1, marketParams },
|
|
54
|
+
* args: { amount: 1_000_000_000_000_000_000n, onBehalf },
|
|
55
|
+
* });
|
|
56
|
+
* // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralAction>>
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const marketV1SupplyCollateral: ({ market: { chainId, marketParams }, args: { amount, onBehalf, requirementSignature, nativeAmount }, metadata, }: MarketV1SupplyCollateralParams) => Readonly<Transaction<MarketV1SupplyCollateralAction>>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.marketV1SupplyCollateral = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
8
|
+
const index_js_2 = require("../../types/index.js");
|
|
9
|
+
const getRequirementsAction_js_1 = require("../requirements/getRequirementsAction.js");
|
|
10
|
+
/**
|
|
11
|
+
* Prepares a supply-collateral transaction for a Morpho Blue market.
|
|
12
|
+
*
|
|
13
|
+
* Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
|
|
14
|
+
* via `GeneralAdapter1.wrapNative()` before the collateral supply; the collateral token must be
|
|
15
|
+
* the chain's wNative for that path.
|
|
16
|
+
*
|
|
17
|
+
* Zero loss: all collateral reaches 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 collateral to supply. At least one of `amount` or
|
|
22
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
23
|
+
* @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
|
|
24
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
|
|
25
|
+
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
26
|
+
* approved `GeneralAdapter1`.
|
|
27
|
+
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
28
|
+
* supply. Requires the collateral token to be the chain's wNative.
|
|
29
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
30
|
+
* @returns A deep-frozen `Transaction<MarketV1SupplyCollateralAction>` with `to`, `value`, `data`,
|
|
31
|
+
* and the typed `action` discriminator the simulation layer consumes.
|
|
32
|
+
* @throws {NonPositiveAssetAmountError} when `amount < 0n`.
|
|
33
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
34
|
+
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
35
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
36
|
+
* @throws {NativeAmountOnNonWNativeCollateralError} when `nativeAmount > 0n` but the collateral
|
|
37
|
+
* token is not the chain's wNative.
|
|
38
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
39
|
+
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
40
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
41
|
+
* is provided and the signed amount differs from `args.amount`.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { marketV1SupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
45
|
+
*
|
|
46
|
+
* const tx = marketV1SupplyCollateral({
|
|
47
|
+
* market: { chainId: 1, marketParams },
|
|
48
|
+
* args: { amount: 1_000_000_000_000_000_000n, onBehalf },
|
|
49
|
+
* });
|
|
50
|
+
* // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralAction>>
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const marketV1SupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
|
|
54
|
+
if (amount < 0n) {
|
|
55
|
+
throw new index_js_2.NonPositiveAssetAmountError(marketParams.collateralToken);
|
|
56
|
+
}
|
|
57
|
+
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
58
|
+
throw new index_js_2.NegativeNativeAmountError(nativeAmount);
|
|
59
|
+
}
|
|
60
|
+
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
61
|
+
if (totalCollateral === 0n) {
|
|
62
|
+
throw new index_js_2.ZeroCollateralAmountError(marketParams.id);
|
|
63
|
+
}
|
|
64
|
+
const { bundler3: { generalAdapter1, bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
65
|
+
const actions = [];
|
|
66
|
+
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
67
|
+
(0, index_js_1.validateNativeCollateral)(chainId, marketParams.collateralToken);
|
|
68
|
+
actions.push({
|
|
69
|
+
type: "nativeTransfer",
|
|
70
|
+
args: [bundler3, generalAdapter1, nativeAmount, false],
|
|
71
|
+
}, {
|
|
72
|
+
type: "wrapNative",
|
|
73
|
+
args: [nativeAmount, generalAdapter1, false],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (amount > 0n) {
|
|
77
|
+
if (requirementSignature) {
|
|
78
|
+
actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
|
|
79
|
+
chainId,
|
|
80
|
+
asset: marketParams.collateralToken,
|
|
81
|
+
amount,
|
|
82
|
+
requirementSignature,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
actions.push({
|
|
87
|
+
type: "erc20TransferFrom",
|
|
88
|
+
args: [marketParams.collateralToken, amount, generalAdapter1, false],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
actions.push({
|
|
93
|
+
type: "morphoSupplyCollateral",
|
|
94
|
+
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
95
|
+
});
|
|
96
|
+
let tx = {
|
|
97
|
+
...bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions),
|
|
98
|
+
value: nativeAmount ?? 0n,
|
|
99
|
+
};
|
|
100
|
+
if (metadata) {
|
|
101
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
|
|
102
|
+
}
|
|
103
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
104
|
+
...tx,
|
|
105
|
+
action: {
|
|
106
|
+
type: "marketV1SupplyCollateral",
|
|
107
|
+
args: {
|
|
108
|
+
market: marketParams.id,
|
|
109
|
+
amount: totalCollateral,
|
|
110
|
+
onBehalf,
|
|
111
|
+
nativeAmount,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
exports.marketV1SupplyCollateral = marketV1SupplyCollateral;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import { type DepositAmountArgs, type MarketV1SupplyCollateralBorrowAction, type Metadata, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link marketV1SupplyCollateralBorrow}. */
|
|
5
|
+
export interface MarketV1SupplyCollateralBorrowParams {
|
|
6
|
+
market: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly marketParams: MarketParams;
|
|
9
|
+
};
|
|
10
|
+
args: DepositAmountArgs & {
|
|
11
|
+
borrowAmount: bigint;
|
|
12
|
+
onBehalf: Address;
|
|
13
|
+
receiver: Address;
|
|
14
|
+
/** Minimum borrow share price (in ray). Protects against share price manipulation. */
|
|
15
|
+
minSharePrice: bigint;
|
|
16
|
+
requirementSignature?: RequirementSignature;
|
|
17
|
+
/** Vault reallocations to execute before borrowing (computed by entity). */
|
|
18
|
+
reallocations?: readonly VaultReallocation[];
|
|
19
|
+
};
|
|
20
|
+
metadata?: Metadata;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
|
|
24
|
+
*
|
|
25
|
+
* Routed through bundler3: collateral transfer → `morphoSupplyCollateral` → optional
|
|
26
|
+
* `reallocateTo` calls → `morphoBorrow`. When `nativeAmount > 0`, native ETH is wrapped via
|
|
27
|
+
* `GeneralAdapter1.wrapNative()` before the supply leg.
|
|
28
|
+
*
|
|
29
|
+
* Prerequisite: `GeneralAdapter1` must be authorized on Morpho to borrow on behalf of the user.
|
|
30
|
+
* Use `getRequirements()` on the entity to check and obtain the authorization transaction.
|
|
31
|
+
*
|
|
32
|
+
* Zero loss: all collateral reaches Morpho, all borrowed tokens reach the receiver. No dust left
|
|
33
|
+
* in bundler or adapter.
|
|
34
|
+
*
|
|
35
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
36
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
37
|
+
* @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
|
|
38
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
39
|
+
* @param params.args.borrowAmount - Loan asset amount to borrow.
|
|
40
|
+
* @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
|
|
41
|
+
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
42
|
+
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
43
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
44
|
+
* collateral transfer.
|
|
45
|
+
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
46
|
+
* collateral supply. Requires the collateral token to be the chain's wNative.
|
|
47
|
+
* @param params.args.reallocations - Optional vault reallocations to execute between the supply
|
|
48
|
+
* and borrow legs, computed by the entity layer.
|
|
49
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
50
|
+
* @returns A deep-frozen `Transaction<MarketV1SupplyCollateralBorrowAction>` with `to`, `value`,
|
|
51
|
+
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
52
|
+
* @throws {NonPositiveAssetAmountError} when `amount < 0n`.
|
|
53
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
54
|
+
* @throws {NonPositiveBorrowAmountError} when `borrowAmount <= 0n`.
|
|
55
|
+
* @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n`.
|
|
56
|
+
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
57
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
58
|
+
* @throws {NativeAmountOnNonWNativeCollateralError} when `nativeAmount > 0n` but the collateral
|
|
59
|
+
* token is not the chain's wNative.
|
|
60
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
61
|
+
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
62
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
63
|
+
* is provided and the signed amount differs from `args.amount`.
|
|
64
|
+
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
65
|
+
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
66
|
+
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
67
|
+
* `reallocation.withdrawals` is empty.
|
|
68
|
+
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
69
|
+
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
70
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
71
|
+
* reallocation withdrawal references the target market.
|
|
72
|
+
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
73
|
+
* reallocation withdrawals are not strictly sorted by market id.
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { marketV1SupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
77
|
+
*
|
|
78
|
+
* const tx = marketV1SupplyCollateralBorrow({
|
|
79
|
+
* market: { chainId: 1, marketParams },
|
|
80
|
+
* args: {
|
|
81
|
+
* amount: 1_000_000_000_000_000_000n,
|
|
82
|
+
* borrowAmount: 500_000_000n,
|
|
83
|
+
* onBehalf: borrower,
|
|
84
|
+
* receiver: borrower,
|
|
85
|
+
* minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
|
|
86
|
+
* },
|
|
87
|
+
* });
|
|
88
|
+
* // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const marketV1SupplyCollateralBorrow: ({ market: { chainId, marketParams }, args: { amount, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }: MarketV1SupplyCollateralBorrowParams) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
|