@morpho-org/morpho-sdk 4.2.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
- package/lib/cjs/actions/blue/refinance.d.ts +13 -3
- package/lib/cjs/actions/blue/refinance.js +8 -2
- package/lib/cjs/actions/blue/repay.d.ts +44 -43
- package/lib/cjs/actions/blue/repay.js +70 -59
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
- package/lib/cjs/actions/blue/supply.d.ts +8 -8
- package/lib/cjs/actions/blue/supply.js +11 -35
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
- package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
- package/lib/cjs/actions/blue/withdraw.js +7 -1
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
- package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/index.js +2 -1
- package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
- package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/cjs/actions/requirements/index.d.ts +2 -5
- package/lib/cjs/actions/requirements/index.js +2 -5
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
- package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
- package/lib/cjs/actions/signatures/index.d.ts +2 -0
- package/lib/cjs/actions/signatures/index.js +18 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV1/deposit.js +11 -21
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV2/deposit.js +11 -21
- package/lib/cjs/addresses.d.ts +2 -2
- package/lib/cjs/addresses.js +2 -1
- package/lib/cjs/bundler/actions.d.ts +44 -4
- package/lib/cjs/bundler/actions.js +75 -2
- package/lib/cjs/bundler/types.d.ts +6 -0
- package/lib/cjs/constants.d.ts +2 -2
- package/lib/cjs/constants.js +3 -3
- package/lib/cjs/entities/blue/blue.d.ts +58 -33
- package/lib/cjs/entities/blue/blue.js +309 -189
- package/lib/cjs/entities/reallocationData.d.ts +0 -44
- package/lib/cjs/entities/reallocationData.js +3 -50
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
- package/lib/cjs/errors.d.ts +3 -2
- package/lib/cjs/errors.js +5 -2
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +1 -2
- package/lib/cjs/helpers/validate.d.ts +2 -20
- package/lib/cjs/helpers/validate.js +2 -39
- package/lib/cjs/types/action.d.ts +164 -12
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +97 -2
- package/lib/cjs/types/error.js +113 -7
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
- package/lib/esm/actions/blue/refinance.d.ts +13 -3
- package/lib/esm/actions/blue/refinance.js +8 -2
- package/lib/esm/actions/blue/repay.d.ts +44 -43
- package/lib/esm/actions/blue/repay.js +71 -60
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
- package/lib/esm/actions/blue/supply.d.ts +8 -8
- package/lib/esm/actions/blue/supply.js +12 -36
- package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/esm/actions/blue/supplyCollateral.js +13 -37
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
- package/lib/esm/actions/blue/withdraw.d.ts +10 -2
- package/lib/esm/actions/blue/withdraw.js +7 -1
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/index.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
- package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/index.js +2 -1
- package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
- package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/esm/actions/requirements/index.d.ts +2 -5
- package/lib/esm/actions/requirements/index.js +2 -5
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
- package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
- package/lib/esm/actions/signatures/index.d.ts +2 -0
- package/lib/esm/actions/signatures/index.js +2 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV1/deposit.js +11 -21
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV2/deposit.js +11 -21
- package/lib/esm/addresses.d.ts +2 -2
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/bundler/actions.d.ts +44 -4
- package/lib/esm/bundler/actions.js +77 -4
- package/lib/esm/bundler/types.d.ts +6 -0
- package/lib/esm/constants.d.ts +2 -2
- package/lib/esm/constants.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +58 -33
- package/lib/esm/entities/blue/blue.js +311 -191
- package/lib/esm/entities/reallocationData.d.ts +0 -44
- package/lib/esm/entities/reallocationData.js +2 -49
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
- package/lib/esm/errors.d.ts +3 -2
- package/lib/esm/errors.js +2 -1
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +2 -20
- package/lib/esm/helpers/validate.js +2 -38
- package/lib/esm/types/action.d.ts +164 -12
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +97 -2
- package/lib/esm/types/error.js +107 -5
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +22 -21
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
- package/lib/cjs/actions/requirements/getRequirements.js +0 -112
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
- package/lib/esm/actions/requirements/getRequirements.js +0 -108
- package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
- package/src/index.ts +0 -4
package/lib/cjs/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinBorrowSharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.computeReallocations = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.
|
|
4
|
-
exports.validateUserAddress = exports.validateSlippageTolerance =
|
|
3
|
+
exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinBorrowSharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.computeReallocations = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getAuthorizationTypedData = exports.decodeBytes32String = exports.VaultUtils = exports.SharesMath = exports.MathLib = exports.MarketUtils = exports.CapacityLimitReason = exports.AdaptiveCurveIrmLib = void 0;
|
|
4
|
+
exports.validateUserAddress = exports.validateSlippageTolerance = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "AdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
|
|
7
7
|
Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
|
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "VaultUtils", { enumerable: true, get: function (
|
|
|
12
12
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
13
13
|
Object.defineProperty(exports, "decodeBytes32String", { enumerable: true, get: function () { return blue_sdk_viem_1.decodeBytes32String; } });
|
|
14
14
|
Object.defineProperty(exports, "getAuthorizationTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getAuthorizationTypedData; } });
|
|
15
|
-
Object.defineProperty(exports, "getDaiPermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getDaiPermitTypedData; } });
|
|
16
15
|
Object.defineProperty(exports, "getPermit2PermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2PermitTypedData; } });
|
|
17
16
|
Object.defineProperty(exports, "getPermit2TransferFromTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermit2TransferFromTypedData; } });
|
|
18
17
|
Object.defineProperty(exports, "getPermitTypedData", { enumerable: true, get: function () { return blue_sdk_viem_1.getPermitTypedData; } });
|
|
@@ -59,7 +58,6 @@ Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get
|
|
|
59
58
|
Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return validate_js_1.validatePositionHealthAfterWithdraw; } });
|
|
60
59
|
Object.defineProperty(exports, "validateReallocations", { enumerable: true, get: function () { return validate_js_1.validateReallocations; } });
|
|
61
60
|
Object.defineProperty(exports, "validateRepayAmount", { enumerable: true, get: function () { return validate_js_1.validateRepayAmount; } });
|
|
62
|
-
Object.defineProperty(exports, "validateRepayParams", { enumerable: true, get: function () { return validate_js_1.validateRepayParams; } });
|
|
63
61
|
Object.defineProperty(exports, "validateRepayShares", { enumerable: true, get: function () { return validate_js_1.validateRepayShares; } });
|
|
64
62
|
Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true, get: function () { return validate_js_1.validateSlippageTolerance; } });
|
|
65
63
|
Object.defineProperty(exports, "validateUserAddress", { enumerable: true, get: function () { return validate_js_1.validateUserAddress; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueBorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueBorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueBorrow}. */
|
|
5
5
|
export interface BlueBorrowParams {
|
|
6
6
|
market: {
|
|
@@ -8,12 +8,20 @@ export interface BlueBorrowParams {
|
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
9
|
};
|
|
10
10
|
args: {
|
|
11
|
+
/** Amount of loan asset to borrow. */
|
|
11
12
|
amount: bigint;
|
|
13
|
+
/** Address that receives the borrowed assets. */
|
|
12
14
|
receiver: Address;
|
|
13
15
|
/** Minimum borrow share price (in ray). Protects against share price manipulation. */
|
|
14
16
|
minSharePrice: bigint;
|
|
15
17
|
/** Vault reallocations to execute before borrowing (computed by entity). */
|
|
16
18
|
reallocations?: readonly VaultReallocation[];
|
|
19
|
+
/**
|
|
20
|
+
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
21
|
+
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
22
|
+
* standalone `setAuthorization` transaction.
|
|
23
|
+
*/
|
|
24
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
17
25
|
};
|
|
18
26
|
metadata?: Metadata;
|
|
19
27
|
}
|
|
@@ -35,6 +43,8 @@ export interface BlueBorrowParams {
|
|
|
35
43
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
36
44
|
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
37
45
|
* computed by the entity layer.
|
|
46
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
47
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
38
48
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
39
49
|
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
40
50
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -66,4 +76,4 @@ export interface BlueBorrowParams {
|
|
|
66
76
|
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
67
77
|
* ```
|
|
68
78
|
*/
|
|
69
|
-
export declare const blueBorrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
|
|
79
|
+
export declare const blueBorrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
|
|
@@ -2,6 +2,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { BundlerAction } from "../../bundler/index.js";
|
|
3
3
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
4
|
import { NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, } from "../../types/index.js";
|
|
5
|
+
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
5
6
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
6
7
|
/**
|
|
7
8
|
* Prepares a borrow transaction for a Morpho Blue market.
|
|
@@ -21,6 +22,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
21
22
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
22
23
|
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
23
24
|
* computed by the entity layer.
|
|
25
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
26
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
24
27
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
25
28
|
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
26
29
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -52,7 +55,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
52
55
|
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
53
56
|
* ```
|
|
54
57
|
*/
|
|
55
|
-
export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
|
|
58
|
+
export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
|
|
56
59
|
if (amount <= 0n) {
|
|
57
60
|
throw new NonPositiveBorrowAmountError(marketParams.id);
|
|
58
61
|
}
|
|
@@ -61,6 +64,9 @@ export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount,
|
|
|
61
64
|
}
|
|
62
65
|
const actions = [];
|
|
63
66
|
let reallocationFee = 0n;
|
|
67
|
+
if (authorizationSignature) {
|
|
68
|
+
actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
|
|
69
|
+
}
|
|
64
70
|
if (reallocations && reallocations.length > 0) {
|
|
65
71
|
const result = buildReallocationActions(reallocations, marketParams);
|
|
66
72
|
actions.push(...result.actions);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { Action } from "../../bundler/index.js";
|
|
3
|
+
import type { PermitRequirementSignature } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link buildAssetFundingActions}. */
|
|
5
|
+
export interface BuildAssetFundingActionsParams {
|
|
6
|
+
/** Chain the operation runs on — resolves adapter addresses and validates wNative. */
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
/** Asset wrapped and/or pulled into `GeneralAdapter1` (loan token, collateral token, …). */
|
|
9
|
+
readonly asset: Address;
|
|
10
|
+
/** ERC-20 amount of `asset` to pull from the payer (`0n` on a fully-native funding). */
|
|
11
|
+
readonly erc20Amount: bigint;
|
|
12
|
+
/** Native ETH to wrap into wNative before the pull (`0n` when not wrapping). */
|
|
13
|
+
readonly nativeAmount: bigint;
|
|
14
|
+
/** Optional pre-signed permit/permit2 approval for the ERC-20 pull. */
|
|
15
|
+
readonly requirementSignature?: PermitRequirementSignature;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds the shared asset-funding actions — native wrapping followed by the ERC-20 pull — that move
|
|
19
|
+
* `asset` into `GeneralAdapter1` before a bundled Morpho operation (`blueSupply`,
|
|
20
|
+
* `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
|
|
21
|
+
*
|
|
22
|
+
* Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
|
|
23
|
+
* `buildReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
|
|
24
|
+
* `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
|
|
25
|
+
* pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
|
|
26
|
+
* `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
|
|
27
|
+
* supplied. A fully-native funding emits no ERC-20 action; funding nothing returns `[]`.
|
|
28
|
+
*
|
|
29
|
+
* Single source of truth for the native-wrap + ERC-20-pull composition every bundled Blue funding
|
|
30
|
+
* path depends on — a fix here applies to all of them instead of risking a silent divergence
|
|
31
|
+
* between copies.
|
|
32
|
+
*
|
|
33
|
+
* @param params - See {@link BuildAssetFundingActionsParams}.
|
|
34
|
+
* @returns The `nativeTransfer`/`wrapNative`/pull actions, in bundle order (empty when nothing is
|
|
35
|
+
* funded).
|
|
36
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
37
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but `asset` is not the
|
|
38
|
+
* chain's wNative.
|
|
39
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
|
|
40
|
+
* provided and the signed asset differs from `asset`.
|
|
41
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
|
|
42
|
+
* provided and the signed amount differs from `erc20Amount`.
|
|
43
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
44
|
+
* signature is missing its expiration.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export declare const buildAssetFundingActions: ({ chainId, asset, erc20Amount, nativeAmount, requirementSignature, }: BuildAssetFundingActionsParams) => Action[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { validateNativeAsset } from "../../helpers/index.js";
|
|
3
|
+
import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builds the shared asset-funding actions — native wrapping followed by the ERC-20 pull — that move
|
|
6
|
+
* `asset` into `GeneralAdapter1` before a bundled Morpho operation (`blueSupply`,
|
|
7
|
+
* `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
|
|
8
|
+
*
|
|
9
|
+
* Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
|
|
10
|
+
* `buildReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
|
|
11
|
+
* `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
|
|
12
|
+
* pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
|
|
13
|
+
* `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
|
|
14
|
+
* supplied. A fully-native funding emits no ERC-20 action; funding nothing returns `[]`.
|
|
15
|
+
*
|
|
16
|
+
* Single source of truth for the native-wrap + ERC-20-pull composition every bundled Blue funding
|
|
17
|
+
* path depends on — a fix here applies to all of them instead of risking a silent divergence
|
|
18
|
+
* between copies.
|
|
19
|
+
*
|
|
20
|
+
* @param params - See {@link BuildAssetFundingActionsParams}.
|
|
21
|
+
* @returns The `nativeTransfer`/`wrapNative`/pull actions, in bundle order (empty when nothing is
|
|
22
|
+
* funded).
|
|
23
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
24
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but `asset` is not the
|
|
25
|
+
* chain's wNative.
|
|
26
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
|
|
27
|
+
* provided and the signed asset differs from `asset`.
|
|
28
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` is
|
|
29
|
+
* provided and the signed amount differs from `erc20Amount`.
|
|
30
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
31
|
+
* signature is missing its expiration.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export const buildAssetFundingActions = ({ chainId, asset, erc20Amount, nativeAmount, requirementSignature, }) => {
|
|
35
|
+
const { bundler3: { generalAdapter1, bundler3 }, } = getChainAddresses(chainId);
|
|
36
|
+
const actions = [];
|
|
37
|
+
// Wrap native into wNative before pulling the ERC-20 remainder.
|
|
38
|
+
if (nativeAmount > 0n) {
|
|
39
|
+
validateNativeAsset(chainId, asset);
|
|
40
|
+
actions.push({
|
|
41
|
+
type: "nativeTransfer",
|
|
42
|
+
args: [bundler3, generalAdapter1, nativeAmount, false],
|
|
43
|
+
}, {
|
|
44
|
+
type: "wrapNative",
|
|
45
|
+
args: [nativeAmount, generalAdapter1, false],
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Pull the ERC-20 portion (0 on a fully native funding). getTokenRequirementActions emits a plain
|
|
49
|
+
// erc20TransferFrom itself when no permit/permit2 signature is supplied.
|
|
50
|
+
if (erc20Amount > 0n) {
|
|
51
|
+
actions.push(...getTokenRequirementActions({
|
|
52
|
+
asset,
|
|
53
|
+
amount: erc20Amount,
|
|
54
|
+
recipient: generalAdapter1,
|
|
55
|
+
requirementSignature,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
return actions;
|
|
59
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type BlueRefinanceAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueRefinanceAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRefinance}. */
|
|
5
5
|
export interface BlueRefinanceParams {
|
|
6
6
|
source: {
|
|
@@ -11,7 +11,9 @@ export interface BlueRefinanceParams {
|
|
|
11
11
|
readonly marketParams: MarketParams;
|
|
12
12
|
};
|
|
13
13
|
args: {
|
|
14
|
+
/** Address whose position is refinanced from the source to the target market. */
|
|
14
15
|
user: Address;
|
|
16
|
+
/** Amount of collateral moved from the source market to the target market. */
|
|
15
17
|
collateralAmount: bigint;
|
|
16
18
|
/**
|
|
17
19
|
* Loan assets to borrow on the target. Assets mode: the exact borrow (exclusive with
|
|
@@ -27,6 +29,12 @@ export interface BlueRefinanceParams {
|
|
|
27
29
|
maxRepaySharePrice: bigint;
|
|
28
30
|
/** PublicAllocator reallocations into the target market, run before the bundle. Fees add to `tx.value`. */
|
|
29
31
|
targetReallocations?: readonly VaultReallocation[];
|
|
32
|
+
/**
|
|
33
|
+
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
34
|
+
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
35
|
+
* standalone `setAuthorization` transaction.
|
|
36
|
+
*/
|
|
37
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
30
38
|
};
|
|
31
39
|
metadata?: Metadata;
|
|
32
40
|
}
|
|
@@ -64,7 +72,7 @@ export interface BlueRefinanceParams {
|
|
|
64
72
|
* then an `erc20Transfer` skims any residual to the user if that repay is skipped.
|
|
65
73
|
* - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
|
|
66
74
|
*
|
|
67
|
-
* Prerequisite: GA1 must be authorized on
|
|
75
|
+
* Prerequisite: GA1 must be authorized on Blue — the entity's `getRequirements()` returns the
|
|
68
76
|
* `setAuthorization` transaction when needed.
|
|
69
77
|
*
|
|
70
78
|
* @param params.source.chainId - The chain both markets live on.
|
|
@@ -77,6 +85,8 @@ export interface BlueRefinanceParams {
|
|
|
77
85
|
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
78
86
|
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
79
87
|
* @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
|
|
88
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
89
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
80
90
|
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
81
91
|
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
82
92
|
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
@@ -114,4 +124,4 @@ export interface BlueRefinanceParams {
|
|
|
114
124
|
* // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
|
|
115
125
|
* ```
|
|
116
126
|
*/
|
|
117
|
-
export declare const blueRefinance: ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets, borrowShares, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }: BlueRefinanceParams) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
127
|
+
export declare const blueRefinance: ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets, borrowShares, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }: BlueRefinanceParams) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
@@ -4,6 +4,7 @@ import { isAddressEqual, maxUint256 } from "viem";
|
|
|
4
4
|
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
6
|
import { NegativeBorrowSharesError, NegativeMaxRepaySharePriceError, NonPositiveAssetAmountError, NonPositiveMinBorrowSharePriceError, NonPositiveRepayMaxSharePriceError, RefinanceSameMarketError, RefinanceSharesMissingBorrowAssetsError, RefinanceTokenMismatchError, ZeroCollateralAmountError, } from "../../types/index.js";
|
|
7
|
+
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
7
8
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
8
9
|
/**
|
|
9
10
|
* Prepares an atomic refinance migrating a Morpho Blue position to another market on the same
|
|
@@ -39,7 +40,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
39
40
|
* then an `erc20Transfer` skims any residual to the user if that repay is skipped.
|
|
40
41
|
* - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
|
|
41
42
|
*
|
|
42
|
-
* Prerequisite: GA1 must be authorized on
|
|
43
|
+
* Prerequisite: GA1 must be authorized on Blue — the entity's `getRequirements()` returns the
|
|
43
44
|
* `setAuthorization` transaction when needed.
|
|
44
45
|
*
|
|
45
46
|
* @param params.source.chainId - The chain both markets live on.
|
|
@@ -52,6 +53,8 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
52
53
|
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
53
54
|
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
54
55
|
* @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
|
|
56
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
57
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
55
58
|
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
56
59
|
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
57
60
|
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
@@ -89,7 +92,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
89
92
|
* // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
|
|
90
93
|
* ```
|
|
91
94
|
*/
|
|
92
|
-
export const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }) => {
|
|
95
|
+
export const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, authorizationSignature, }, metadata, }) => {
|
|
93
96
|
if (collateralAmount <= 0n) {
|
|
94
97
|
throw new ZeroCollateralAmountError(sourceParams.id);
|
|
95
98
|
}
|
|
@@ -181,6 +184,9 @@ export const blueRefinance = ({ source: { chainId, marketParams: sourceParams },
|
|
|
181
184
|
});
|
|
182
185
|
const actions = [];
|
|
183
186
|
let reallocationFee = 0n;
|
|
187
|
+
if (authorizationSignature) {
|
|
188
|
+
actions.push(getBlueAuthorizationAction(chainId, authorizationSignature));
|
|
189
|
+
}
|
|
184
190
|
if (targetReallocations && targetReallocations.length > 0) {
|
|
185
191
|
const result = buildReallocationActions(targetReallocations, targetParams);
|
|
186
192
|
actions.push(...result.actions);
|
|
@@ -1,54 +1,49 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import type { BlueRepayAction, Metadata,
|
|
3
|
+
import type { BlueRepayAction, Metadata, PermitRequirementSignature, RepayActionAmountArgs, Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRepay}. */
|
|
5
5
|
export interface BlueRepayParams {
|
|
6
6
|
market: {
|
|
7
7
|
readonly chainId: number;
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
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;
|
|
10
|
+
args: RepayActionAmountArgs & {
|
|
21
11
|
/** Address whose debt is being repaid. */
|
|
22
12
|
onBehalf: Address;
|
|
23
13
|
/** Receives residual loan tokens in shares mode. */
|
|
24
14
|
receiver: Address;
|
|
25
15
|
/** Maximum repay share price (in ray). Protects against share price manipulation. */
|
|
26
16
|
maxSharePrice: bigint;
|
|
27
|
-
|
|
17
|
+
/** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
|
|
18
|
+
requirementSignature?: PermitRequirementSignature;
|
|
28
19
|
};
|
|
29
20
|
metadata?: Metadata;
|
|
30
21
|
}
|
|
31
22
|
/**
|
|
32
23
|
* Prepares a repay transaction for a Morpho Blue market.
|
|
33
24
|
*
|
|
34
|
-
* Routed through bundler3 via `GeneralAdapter1`.
|
|
25
|
+
* Routed through bundler3 via `GeneralAdapter1`. All amount arithmetic is done upstream (see
|
|
26
|
+
* `MorphoBlue.repay`); this builder just assembles the bundle from the pre-resolved
|
|
27
|
+
* {@link RepayActionAmountArgs}. The mode is discriminated on `shares`, plus optional native wrapping
|
|
28
|
+
* (when `nativeAmount > 0`, native ETH is wrapped via `GeneralAdapter1.wrapNative()` before the
|
|
29
|
+
* repay; the loan token must be the chain's wNative):
|
|
35
30
|
*
|
|
36
|
-
* - **
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
31
|
+
* - **assets mode** (`shares` unset/`0n`): repays `transferAmount` assets (`= amount + nativeAmount`,
|
|
32
|
+
* additive like `blueSupply`), pulling `amount` ERC-20 and wrapping `nativeAmount`. No residual.
|
|
33
|
+
* - **shares mode** (`shares > 0n`): repays exact shares (full repay), pulling `transferAmount`
|
|
34
|
+
* ERC-20 (already net of native) and wrapping `nativeAmount`. Residual loan tokens are skimmed
|
|
35
|
+
* back to `receiver` after the call.
|
|
40
36
|
*
|
|
41
|
-
*
|
|
42
|
-
* share price manipulation between transaction construction and execution.
|
|
37
|
+
* Uses `maxSharePrice` to protect against share price manipulation between construction and execution.
|
|
43
38
|
*
|
|
44
39
|
* @param params.market.chainId - The chain the market lives on.
|
|
45
40
|
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
46
|
-
* @param params.args.
|
|
47
|
-
* @param params.args.shares - Repay amount in borrow shares.
|
|
48
|
-
* @param params.args.transferAmount -
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
41
|
+
* @param params.args.amount - (assets mode) ERC-20 loan tokens pulled from the payer. Defaults to `0n`.
|
|
42
|
+
* @param params.args.shares - (shares mode) Repay amount in borrow shares. Discriminates the mode.
|
|
43
|
+
* @param params.args.transferAmount - Loan tokens routed into `GeneralAdapter1`: assets mode = the
|
|
44
|
+
* total repaid (`amount + nativeAmount`); shares mode = the ERC-20 pulled (net of native).
|
|
45
|
+
* @param params.args.nativeAmount - Optional native token to wrap into wNative to fund the repay.
|
|
46
|
+
* Requires the loan token to be the chain's wNative.
|
|
52
47
|
* @param params.args.onBehalf - Address whose Morpho debt is being repaid.
|
|
53
48
|
* @param params.args.receiver - Address that receives residual loan tokens in shares mode.
|
|
54
49
|
* @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage
|
|
@@ -56,36 +51,42 @@ export interface BlueRepayParams {
|
|
|
56
51
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
57
52
|
* loan-token transfer.
|
|
58
53
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
59
|
-
* @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value
|
|
60
|
-
* typed `action` discriminator the simulation layer consumes.
|
|
54
|
+
* @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value` (= `nativeAmount`),
|
|
55
|
+
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
61
56
|
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
62
|
-
* @throws {
|
|
63
|
-
*
|
|
64
|
-
* @throws {
|
|
65
|
-
*
|
|
66
|
-
* @throws {
|
|
67
|
-
*
|
|
57
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
58
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
59
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
60
|
+
* `transferAmount !== amount + nativeAmount`.
|
|
61
|
+
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode
|
|
62
|
+
* and `transferAmount <= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
63
|
+
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
64
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
65
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
66
|
+
* the chain's wNative.
|
|
67
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
68
68
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
69
|
-
* @throws {DepositAmountMismatchError} from `
|
|
70
|
-
* is provided and the signed amount differs from
|
|
71
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
69
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
70
|
+
* is provided and the signed amount differs from the ERC-20 amount pulled.
|
|
71
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
72
72
|
* signature is missing its expiration.
|
|
73
73
|
* @example
|
|
74
74
|
* ```ts
|
|
75
75
|
* import { blueRepay } from "@morpho-org/morpho-sdk";
|
|
76
76
|
*
|
|
77
|
+
* // Repay 0.5 loan-asset units, 0.2 of them funded by wrapping native ETH.
|
|
77
78
|
* const tx = blueRepay({
|
|
78
|
-
* market: { chainId: 1, marketParams },
|
|
79
|
+
* market: { chainId: 1, marketParams }, // marketParams.loanToken === wNative
|
|
79
80
|
* args: {
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* transferAmount:
|
|
81
|
+
* amount: 300_000_000_000_000_000n, // ERC-20 part
|
|
82
|
+
* nativeAmount: 200_000_000_000_000_000n, // wrapped ETH part
|
|
83
|
+
* transferAmount: 500_000_000_000_000_000n, // total repaid = amount + nativeAmount
|
|
83
84
|
* onBehalf: borrower,
|
|
84
85
|
* receiver: borrower,
|
|
85
86
|
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
86
87
|
* },
|
|
87
88
|
* });
|
|
88
|
-
* // tx
|
|
89
|
+
* // tx.value === 200_000_000_000_000_000n
|
|
89
90
|
* ```
|
|
90
91
|
*/
|
|
91
|
-
export declare const blueRepay: ({ market: { chainId, marketParams }, args
|
|
92
|
+
export declare const blueRepay: ({ market: { chainId, marketParams }, args, metadata, }: BlueRepayParams) => Readonly<Transaction<BlueRepayAction>>;
|