@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,89 @@
|
|
|
1
|
+
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import type { MarketV1RepayAction, Metadata, RequirementSignature, Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link marketV1Repay}. */
|
|
5
|
+
export interface MarketV1RepayParams {
|
|
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 is skimmed back to `receiver`.
|
|
19
|
+
*/
|
|
20
|
+
transferAmount: bigint;
|
|
21
|
+
/** Address whose debt is being repaid. */
|
|
22
|
+
onBehalf: Address;
|
|
23
|
+
/** Receives residual loan tokens in shares mode. */
|
|
24
|
+
receiver: Address;
|
|
25
|
+
/** Maximum repay share price (in ray). Protects against share price manipulation. */
|
|
26
|
+
maxSharePrice: bigint;
|
|
27
|
+
requirementSignature?: RequirementSignature;
|
|
28
|
+
};
|
|
29
|
+
metadata?: Metadata;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Prepares a repay transaction for a Morpho Blue market.
|
|
33
|
+
*
|
|
34
|
+
* Routed through bundler3 via `GeneralAdapter1`. Supports two modes:
|
|
35
|
+
*
|
|
36
|
+
* - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
|
|
37
|
+
* - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with
|
|
38
|
+
* `transferAmount` set to an upper-bound asset estimate; residual loan tokens are skimmed back
|
|
39
|
+
* to `receiver` after the call.
|
|
40
|
+
*
|
|
41
|
+
* Exactly one of `assets` / `shares` must be non-zero. Uses `maxSharePrice` to protect against
|
|
42
|
+
* share price manipulation between transaction construction and execution.
|
|
43
|
+
*
|
|
44
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
45
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
46
|
+
* @param params.args.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
|
|
47
|
+
* @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
|
|
48
|
+
* @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
|
|
49
|
+
* mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
|
|
50
|
+
* In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
|
|
51
|
+
* tokens are skimmed back to `receiver`.
|
|
52
|
+
* @param params.args.onBehalf - Address whose Morpho debt is being repaid.
|
|
53
|
+
* @param params.args.receiver - Address that receives residual loan tokens in shares mode.
|
|
54
|
+
* @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
|
|
55
|
+
* protection.
|
|
56
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
57
|
+
* loan-token transfer.
|
|
58
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
59
|
+
* @returns A deep-frozen `Transaction<MarketV1RepayAction>` with `to`, `value`, `data`, and the
|
|
60
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
61
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
62
|
+
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
63
|
+
* both are zero.
|
|
64
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
65
|
+
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
66
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
67
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
68
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
69
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
70
|
+
* is provided and the signed amount differs from `args.transferAmount`.
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { marketV1Repay } from "@morpho-org/morpho-sdk";
|
|
74
|
+
*
|
|
75
|
+
* const tx = marketV1Repay({
|
|
76
|
+
* market: { chainId: 1, marketParams },
|
|
77
|
+
* args: {
|
|
78
|
+
* assets: 500_000_000n,
|
|
79
|
+
* shares: 0n,
|
|
80
|
+
* transferAmount: 500_000_000n,
|
|
81
|
+
* onBehalf: borrower,
|
|
82
|
+
* receiver: borrower,
|
|
83
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
84
|
+
* },
|
|
85
|
+
* });
|
|
86
|
+
* // tx satisfies Readonly<Transaction<MarketV1RepayAction>>
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare const marketV1Repay: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }: MarketV1RepayParams) => Readonly<Transaction<MarketV1RepayAction>>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
3
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
4
|
+
import { maxUint256 } from "viem";
|
|
5
|
+
import { addTransactionMetadata, validateRepayParams, } from "../../helpers/index.js";
|
|
6
|
+
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
7
|
+
/**
|
|
8
|
+
* Prepares a repay transaction for a Morpho Blue market.
|
|
9
|
+
*
|
|
10
|
+
* Routed through bundler3 via `GeneralAdapter1`. Supports two modes:
|
|
11
|
+
*
|
|
12
|
+
* - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
|
|
13
|
+
* - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with
|
|
14
|
+
* `transferAmount` set to an upper-bound asset estimate; residual loan tokens are skimmed back
|
|
15
|
+
* to `receiver` after the call.
|
|
16
|
+
*
|
|
17
|
+
* Exactly one of `assets` / `shares` must be non-zero. Uses `maxSharePrice` to protect against
|
|
18
|
+
* share price manipulation between transaction construction and execution.
|
|
19
|
+
*
|
|
20
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
21
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
22
|
+
* @param params.args.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
|
|
23
|
+
* @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
|
|
24
|
+
* @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
|
|
25
|
+
* mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
|
|
26
|
+
* In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
|
|
27
|
+
* tokens are skimmed back to `receiver`.
|
|
28
|
+
* @param params.args.onBehalf - Address whose Morpho debt is being repaid.
|
|
29
|
+
* @param params.args.receiver - Address that receives residual loan tokens in shares mode.
|
|
30
|
+
* @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
|
|
31
|
+
* protection.
|
|
32
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
33
|
+
* loan-token transfer.
|
|
34
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
35
|
+
* @returns A deep-frozen `Transaction<MarketV1RepayAction>` with `to`, `value`, `data`, and the
|
|
36
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
37
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
38
|
+
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
39
|
+
* both are zero.
|
|
40
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
41
|
+
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
42
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
43
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
44
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
45
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
46
|
+
* is provided and the signed amount differs from `args.transferAmount`.
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { marketV1Repay } from "@morpho-org/morpho-sdk";
|
|
50
|
+
*
|
|
51
|
+
* const tx = marketV1Repay({
|
|
52
|
+
* market: { chainId: 1, marketParams },
|
|
53
|
+
* args: {
|
|
54
|
+
* assets: 500_000_000n,
|
|
55
|
+
* shares: 0n,
|
|
56
|
+
* transferAmount: 500_000_000n,
|
|
57
|
+
* onBehalf: borrower,
|
|
58
|
+
* receiver: borrower,
|
|
59
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
60
|
+
* },
|
|
61
|
+
* });
|
|
62
|
+
* // tx satisfies Readonly<Transaction<MarketV1RepayAction>>
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export const marketV1Repay = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }) => {
|
|
66
|
+
validateRepayParams({
|
|
67
|
+
assets,
|
|
68
|
+
shares,
|
|
69
|
+
transferAmount,
|
|
70
|
+
maxSharePrice,
|
|
71
|
+
marketId: marketParams.id,
|
|
72
|
+
});
|
|
73
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
74
|
+
const actions = [];
|
|
75
|
+
if (requirementSignature) {
|
|
76
|
+
actions.push(...getRequirementsAction({
|
|
77
|
+
chainId,
|
|
78
|
+
asset: marketParams.loanToken,
|
|
79
|
+
amount: transferAmount,
|
|
80
|
+
requirementSignature,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
actions.push({
|
|
85
|
+
type: "erc20TransferFrom",
|
|
86
|
+
args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
actions.push({
|
|
90
|
+
type: "morphoRepay",
|
|
91
|
+
args: [marketParams, assets, shares, maxSharePrice, onBehalf, [], false],
|
|
92
|
+
});
|
|
93
|
+
// Skim residual loan tokens back to the payer when repaying by shares.
|
|
94
|
+
// In shares mode, transferAmount is an upper-bound estimate; morphoRepay
|
|
95
|
+
// consumes only the exact amount needed, leaving a residual in the adapter.
|
|
96
|
+
if (shares > 0n) {
|
|
97
|
+
actions.push({
|
|
98
|
+
type: "erc20Transfer",
|
|
99
|
+
args: [
|
|
100
|
+
marketParams.loanToken,
|
|
101
|
+
receiver,
|
|
102
|
+
maxUint256,
|
|
103
|
+
generalAdapter1,
|
|
104
|
+
false,
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
let tx = {
|
|
109
|
+
...BundlerAction.encodeBundle(chainId, actions),
|
|
110
|
+
value: 0n,
|
|
111
|
+
};
|
|
112
|
+
if (metadata) {
|
|
113
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
114
|
+
}
|
|
115
|
+
return deepFreeze({
|
|
116
|
+
...tx,
|
|
117
|
+
action: {
|
|
118
|
+
type: "marketV1Repay",
|
|
119
|
+
args: {
|
|
120
|
+
market: marketParams.id,
|
|
121
|
+
assets,
|
|
122
|
+
shares,
|
|
123
|
+
transferAmount,
|
|
124
|
+
onBehalf,
|
|
125
|
+
receiver,
|
|
126
|
+
maxSharePrice,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
};
|
|
@@ -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,151 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
3
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
4
|
+
import { maxUint256 } from "viem";
|
|
5
|
+
import { addTransactionMetadata, validateRepayParams, } from "../../helpers/index.js";
|
|
6
|
+
import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js";
|
|
7
|
+
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
8
|
+
/**
|
|
9
|
+
* Prepares an atomic repay-and-withdraw-collateral transaction for a Morpho Blue market.
|
|
10
|
+
*
|
|
11
|
+
* Routed through bundler3. The bundle order is critical:
|
|
12
|
+
*
|
|
13
|
+
* 1. ERC-20 transfer of the loan token to `GeneralAdapter1`.
|
|
14
|
+
* 2. `morphoRepay` — reduces debt **first**.
|
|
15
|
+
* 3. `morphoWithdrawCollateral` — then withdraws collateral.
|
|
16
|
+
*
|
|
17
|
+
* If the order were reversed, Morpho would revert because the position would be insolvent at the
|
|
18
|
+
* time of the withdraw. Supports two repay modes:
|
|
19
|
+
*
|
|
20
|
+
* - **By assets** (`assets > 0, shares = 0`): repays an exact asset amount.
|
|
21
|
+
* - **By shares** (`assets = 0, shares > 0`): repays exact shares (full repay), with residual
|
|
22
|
+
* loan tokens skimmed back to `receiver`.
|
|
23
|
+
*
|
|
24
|
+
* Prerequisites: ERC-20 approval for the loan token to `GeneralAdapter1` (for the repay) **and**
|
|
25
|
+
* `GeneralAdapter1` must be authorized on Morpho (for the withdraw).
|
|
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.assets - Repay amount in loan-token assets. Set to `0n` when repaying by shares.
|
|
30
|
+
* @param params.args.shares - Repay amount in borrow shares. Set to `0n` when repaying by assets.
|
|
31
|
+
* @param params.args.transferAmount - ERC-20 amount to pull into `GeneralAdapter1`. In assets
|
|
32
|
+
* mode, must equal `assets` exactly (`TransferAmountNotEqualToAssetsError` fires otherwise).
|
|
33
|
+
* In shares mode, this is an upper-bound estimate to absorb share-price drift; residual loan
|
|
34
|
+
* tokens are skimmed back to `receiver`.
|
|
35
|
+
* @param params.args.withdrawAmount - Amount of collateral to withdraw after the repay leg
|
|
36
|
+
* completes.
|
|
37
|
+
* @param params.args.onBehalf - Address whose Morpho debt is being repaid.
|
|
38
|
+
* @param params.args.receiver - Address that receives the withdrawn collateral and any residual
|
|
39
|
+
* loan tokens in shares mode.
|
|
40
|
+
* @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
|
|
41
|
+
* protection.
|
|
42
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
43
|
+
* loan-token transfer.
|
|
44
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
45
|
+
* @returns A deep-frozen `Transaction<MarketV1RepayWithdrawCollateralAction>` with `to`,
|
|
46
|
+
* `value`, `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
47
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
48
|
+
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
49
|
+
* both are zero.
|
|
50
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
51
|
+
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
52
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
53
|
+
* @throws {NonPositiveWithdrawCollateralAmountError} when `withdrawAmount <= 0n`.
|
|
54
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
55
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
56
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
57
|
+
* is provided and the signed amount differs from `args.transferAmount`.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { marketV1RepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
61
|
+
*
|
|
62
|
+
* const tx = marketV1RepayWithdrawCollateral({
|
|
63
|
+
* market: { chainId: 1, marketParams },
|
|
64
|
+
* args: {
|
|
65
|
+
* assets: 500_000_000n,
|
|
66
|
+
* shares: 0n,
|
|
67
|
+
* transferAmount: 500_000_000n,
|
|
68
|
+
* withdrawAmount: 1_000_000_000_000_000_000n,
|
|
69
|
+
* onBehalf: borrower,
|
|
70
|
+
* receiver: borrower,
|
|
71
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
72
|
+
* },
|
|
73
|
+
* });
|
|
74
|
+
* // tx satisfies Readonly<Transaction<MarketV1RepayWithdrawCollateralAction>>
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export const marketV1RepayWithdrawCollateral = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, withdrawAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }) => {
|
|
78
|
+
validateRepayParams({
|
|
79
|
+
assets,
|
|
80
|
+
shares,
|
|
81
|
+
transferAmount,
|
|
82
|
+
maxSharePrice,
|
|
83
|
+
marketId: marketParams.id,
|
|
84
|
+
});
|
|
85
|
+
if (withdrawAmount <= 0n) {
|
|
86
|
+
throw new NonPositiveWithdrawCollateralAmountError(marketParams.id);
|
|
87
|
+
}
|
|
88
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
89
|
+
const actions = [];
|
|
90
|
+
if (requirementSignature) {
|
|
91
|
+
actions.push(...getRequirementsAction({
|
|
92
|
+
chainId,
|
|
93
|
+
asset: marketParams.loanToken,
|
|
94
|
+
amount: transferAmount,
|
|
95
|
+
requirementSignature,
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
actions.push({
|
|
100
|
+
type: "erc20TransferFrom",
|
|
101
|
+
args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// REPAY FIRST — reduces debt before withdrawing collateral
|
|
105
|
+
actions.push({
|
|
106
|
+
type: "morphoRepay",
|
|
107
|
+
args: [marketParams, assets, shares, maxSharePrice, onBehalf, [], false],
|
|
108
|
+
});
|
|
109
|
+
// Skim residual loan tokens back to the payer when repaying by shares.
|
|
110
|
+
// In shares mode, transferAmount is an upper-bound estimate; morphoRepay
|
|
111
|
+
// consumes only the exact amount needed, leaving a residual in the adapter.
|
|
112
|
+
if (shares > 0n) {
|
|
113
|
+
actions.push({
|
|
114
|
+
type: "erc20Transfer",
|
|
115
|
+
args: [
|
|
116
|
+
marketParams.loanToken,
|
|
117
|
+
receiver,
|
|
118
|
+
maxUint256,
|
|
119
|
+
generalAdapter1,
|
|
120
|
+
false,
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
actions.push({
|
|
125
|
+
type: "morphoWithdrawCollateral",
|
|
126
|
+
args: [marketParams, withdrawAmount, receiver, false],
|
|
127
|
+
});
|
|
128
|
+
let tx = {
|
|
129
|
+
...BundlerAction.encodeBundle(chainId, actions),
|
|
130
|
+
value: 0n,
|
|
131
|
+
};
|
|
132
|
+
if (metadata) {
|
|
133
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
134
|
+
}
|
|
135
|
+
return deepFreeze({
|
|
136
|
+
...tx,
|
|
137
|
+
action: {
|
|
138
|
+
type: "marketV1RepayWithdrawCollateral",
|
|
139
|
+
args: {
|
|
140
|
+
market: marketParams.id,
|
|
141
|
+
repayAssets: assets,
|
|
142
|
+
repayShares: shares,
|
|
143
|
+
transferAmount,
|
|
144
|
+
withdrawAmount,
|
|
145
|
+
maxSharePrice,
|
|
146
|
+
onBehalf,
|
|
147
|
+
receiver,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
};
|
|
@@ -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,112 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
3
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
4
|
+
import { addTransactionMetadata, validateNativeCollateral, } from "../../helpers/index.js";
|
|
5
|
+
import { NegativeNativeAmountError, NonPositiveAssetAmountError, ZeroCollateralAmountError, } from "../../types/index.js";
|
|
6
|
+
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
7
|
+
/**
|
|
8
|
+
* Prepares a supply-collateral transaction for a Morpho Blue market.
|
|
9
|
+
*
|
|
10
|
+
* Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
|
|
11
|
+
* via `GeneralAdapter1.wrapNative()` before the collateral supply; the collateral token must be
|
|
12
|
+
* the chain's wNative for that path.
|
|
13
|
+
*
|
|
14
|
+
* Zero loss: all collateral reaches Morpho. No dust left in bundler or adapter.
|
|
15
|
+
*
|
|
16
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
17
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
18
|
+
* @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
|
|
19
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
20
|
+
* @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
|
|
21
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
|
|
22
|
+
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
23
|
+
* approved `GeneralAdapter1`.
|
|
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<MarketV1SupplyCollateralAction>` with `to`, `value`, `data`,
|
|
28
|
+
* and the typed `action` discriminator the simulation layer consumes.
|
|
29
|
+
* @throws {NonPositiveAssetAmountError} when `amount < 0n`.
|
|
30
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
31
|
+
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
32
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
33
|
+
* @throws {NativeAmountOnNonWNativeCollateralError} when `nativeAmount > 0n` but the collateral
|
|
34
|
+
* token is not the chain's wNative.
|
|
35
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
36
|
+
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
37
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
38
|
+
* is provided and the signed amount differs from `args.amount`.
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { marketV1SupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
42
|
+
*
|
|
43
|
+
* const tx = marketV1SupplyCollateral({
|
|
44
|
+
* market: { chainId: 1, marketParams },
|
|
45
|
+
* args: { amount: 1_000_000_000_000_000_000n, onBehalf },
|
|
46
|
+
* });
|
|
47
|
+
* // tx satisfies Readonly<Transaction<MarketV1SupplyCollateralAction>>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export const marketV1SupplyCollateral = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, requirementSignature, nativeAmount }, metadata, }) => {
|
|
51
|
+
if (amount < 0n) {
|
|
52
|
+
throw new NonPositiveAssetAmountError(marketParams.collateralToken);
|
|
53
|
+
}
|
|
54
|
+
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
55
|
+
throw new NegativeNativeAmountError(nativeAmount);
|
|
56
|
+
}
|
|
57
|
+
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
58
|
+
if (totalCollateral === 0n) {
|
|
59
|
+
throw new ZeroCollateralAmountError(marketParams.id);
|
|
60
|
+
}
|
|
61
|
+
const { bundler3: { generalAdapter1, bundler3 }, } = getChainAddresses(chainId);
|
|
62
|
+
const actions = [];
|
|
63
|
+
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
64
|
+
validateNativeCollateral(chainId, marketParams.collateralToken);
|
|
65
|
+
actions.push({
|
|
66
|
+
type: "nativeTransfer",
|
|
67
|
+
args: [bundler3, generalAdapter1, nativeAmount, false],
|
|
68
|
+
}, {
|
|
69
|
+
type: "wrapNative",
|
|
70
|
+
args: [nativeAmount, generalAdapter1, false],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (amount > 0n) {
|
|
74
|
+
if (requirementSignature) {
|
|
75
|
+
actions.push(...getRequirementsAction({
|
|
76
|
+
chainId,
|
|
77
|
+
asset: marketParams.collateralToken,
|
|
78
|
+
amount,
|
|
79
|
+
requirementSignature,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
actions.push({
|
|
84
|
+
type: "erc20TransferFrom",
|
|
85
|
+
args: [marketParams.collateralToken, amount, generalAdapter1, false],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
actions.push({
|
|
90
|
+
type: "morphoSupplyCollateral",
|
|
91
|
+
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
92
|
+
});
|
|
93
|
+
let tx = {
|
|
94
|
+
...BundlerAction.encodeBundle(chainId, actions),
|
|
95
|
+
value: nativeAmount ?? 0n,
|
|
96
|
+
};
|
|
97
|
+
if (metadata) {
|
|
98
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
99
|
+
}
|
|
100
|
+
return deepFreeze({
|
|
101
|
+
...tx,
|
|
102
|
+
action: {
|
|
103
|
+
type: "marketV1SupplyCollateral",
|
|
104
|
+
args: {
|
|
105
|
+
market: marketParams.id,
|
|
106
|
+
amount: totalCollateral,
|
|
107
|
+
onBehalf,
|
|
108
|
+
nativeAmount,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
};
|