@morpho-org/morpho-sdk 4.2.0 → 5.0.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/README.md +12 -12
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- 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 +6 -5
- package/lib/cjs/actions/blue/repay.js +10 -18
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/cjs/actions/blue/supply.d.ts +7 -7
- package/lib/cjs/actions/blue/supply.js +10 -20
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/cjs/actions/blue/supplyCollateral.js +11 -21
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -19
- 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 +171 -125
- 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/validate.d.ts +2 -2
- package/lib/cjs/helpers/validate.js +1 -1
- package/lib/cjs/types/action.d.ts +113 -9
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +73 -0
- package/lib/cjs/types/error.js +89 -4
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +1 -1
- package/lib/cjs/utils.js +2 -3
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- 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 +6 -5
- package/lib/esm/actions/blue/repay.js +10 -18
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/esm/actions/blue/supply.d.ts +7 -7
- package/lib/esm/actions/blue/supply.js +10 -20
- package/lib/esm/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/esm/actions/blue/supplyCollateral.js +11 -21
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +17 -19
- 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 +173 -127
- 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/validate.d.ts +2 -2
- package/lib/esm/helpers/validate.js +1 -1
- package/lib/esm/types/action.d.ts +113 -9
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +73 -0
- package/lib/esm/types/error.js +84 -2
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +1 -1
- package/lib/esm/utils.js +1 -1
- package/package.json +6 -6
- 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/lib/cjs/types/action.js
CHANGED
|
@@ -1,26 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isRequirementApproval = isRequirementApproval;
|
|
4
|
-
exports.
|
|
4
|
+
exports.isRequirementBlueAuthorization = isRequirementBlueAuthorization;
|
|
5
5
|
exports.isRequirementSignature = isRequirementSignature;
|
|
6
|
+
exports.isPermitSignature = isPermitSignature;
|
|
7
|
+
exports.isAuthorizationSignature = isAuthorizationSignature;
|
|
8
|
+
exports.selectRequirementSignatures = selectRequirementSignatures;
|
|
9
|
+
const error_js_1 = require("./error.js");
|
|
6
10
|
function isRequirementApproval(requirement) {
|
|
7
|
-
return (requirement
|
|
11
|
+
return (typeof requirement === "object" &&
|
|
12
|
+
requirement !== null &&
|
|
8
13
|
"to" in requirement &&
|
|
9
14
|
"value" in requirement &&
|
|
10
15
|
"data" in requirement &&
|
|
11
16
|
"action" in requirement &&
|
|
17
|
+
typeof requirement.action === "object" &&
|
|
18
|
+
requirement.action !== null &&
|
|
19
|
+
"type" in requirement.action &&
|
|
12
20
|
requirement.action.type === "erc20Approval");
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
/** Checks whether an action requirement is a Blue authorization transaction. */
|
|
23
|
+
function isRequirementBlueAuthorization(requirement) {
|
|
24
|
+
return (typeof requirement === "object" &&
|
|
25
|
+
requirement !== null &&
|
|
16
26
|
"to" in requirement &&
|
|
17
27
|
"value" in requirement &&
|
|
18
28
|
"data" in requirement &&
|
|
19
29
|
"action" in requirement &&
|
|
20
|
-
requirement.action
|
|
30
|
+
typeof requirement.action === "object" &&
|
|
31
|
+
requirement.action !== null &&
|
|
32
|
+
"type" in requirement.action &&
|
|
33
|
+
requirement.action.type === "blueAuthorization");
|
|
21
34
|
}
|
|
22
35
|
function isRequirementSignature(requirement) {
|
|
23
36
|
return (requirement !== undefined &&
|
|
37
|
+
typeof requirement === "object" &&
|
|
38
|
+
requirement !== null &&
|
|
24
39
|
"sign" in requirement &&
|
|
25
40
|
typeof requirement.sign === "function");
|
|
26
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
|
|
44
|
+
*
|
|
45
|
+
* @param signature - The signed requirement to test.
|
|
46
|
+
* @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
|
|
47
|
+
*/
|
|
48
|
+
function isPermitSignature(signature) {
|
|
49
|
+
return (signature.action.type === "permit" || signature.action.type === "permit2");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Narrows a {@link RequirementSignature} to a signed Morpho authorization.
|
|
53
|
+
*
|
|
54
|
+
* @param signature - The signed requirement to test.
|
|
55
|
+
* @returns `true` when `signature.action.type` is `"authorization"`.
|
|
56
|
+
*/
|
|
57
|
+
function isAuthorizationSignature(signature) {
|
|
58
|
+
return signature.action.type === "authorization";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
|
|
62
|
+
* ambiguous or unexpected input so a path never silently consumes the wrong signature.
|
|
63
|
+
*
|
|
64
|
+
* A bundled path consumes at most one permit and one authorization signature. Passing several of
|
|
65
|
+
* the same kind, or a kind the path does not consume, is rejected with a typed error rather than
|
|
66
|
+
* silently dropping the extras — the latter could otherwise leave a required authorization or
|
|
67
|
+
* permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
|
|
68
|
+
*
|
|
69
|
+
* @param signatures - The signatures passed to `buildTx`.
|
|
70
|
+
* @param accepts - Which signature kinds this operation consumes.
|
|
71
|
+
* @param accepts.permit - Whether a permit / Permit2 signature is consumed.
|
|
72
|
+
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
73
|
+
* @returns The single permit and/or authorization signature, when present.
|
|
74
|
+
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
75
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { selectRequirementSignatures } from "@morpho-org/morpho-sdk";
|
|
79
|
+
*
|
|
80
|
+
* const { permit, authorization } = selectRequirementSignatures(signatures, {
|
|
81
|
+
* permit: true,
|
|
82
|
+
* authorization: true,
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
function selectRequirementSignatures(signatures, accepts) {
|
|
87
|
+
if (signatures == null)
|
|
88
|
+
return {};
|
|
89
|
+
const permits = signatures.filter(isPermitSignature);
|
|
90
|
+
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
91
|
+
if (!accepts.permit && permits.length > 0)
|
|
92
|
+
throw new error_js_1.UnexpectedRequirementSignatureError("permit");
|
|
93
|
+
if (!accepts.authorization && authorizations.length > 0)
|
|
94
|
+
throw new error_js_1.UnexpectedRequirementSignatureError("authorization");
|
|
95
|
+
if (permits.length > 1)
|
|
96
|
+
throw new error_js_1.AmbiguousRequirementSignaturesError("permit", permits.length);
|
|
97
|
+
if (authorizations.length > 1)
|
|
98
|
+
throw new error_js_1.AmbiguousRequirementSignaturesError("authorization", authorizations.length);
|
|
99
|
+
return { permit: permits[0], authorization: authorizations[0] };
|
|
100
|
+
}
|
package/lib/cjs/types/error.d.ts
CHANGED
|
@@ -43,6 +43,67 @@ export declare namespace BundlerErrors {
|
|
|
43
43
|
*/
|
|
44
44
|
constructor(type: string, chainId: number);
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Thrown when a Morpho authorization signature names a forbidden `authorized` account
|
|
48
|
+
* (for example Bundler3 itself), which would grant operator rights to an unintended address.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { BundlerErrors } from "@morpho-org/morpho-sdk";
|
|
53
|
+
*
|
|
54
|
+
* if (error instanceof BundlerErrors.UnexpectedSignature) {
|
|
55
|
+
* // Re-sign the authorization targeting GeneralAdapter1.
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
class UnexpectedSignature extends Error {
|
|
60
|
+
/**
|
|
61
|
+
* @param authorized - The forbidden `authorized` address carried by the signature.
|
|
62
|
+
*/
|
|
63
|
+
constructor(authorized: Address);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when `buildTx` receives more than one requirement signature of the same kind.
|
|
68
|
+
*
|
|
69
|
+
* A bundled path consumes at most one permit and one authorization signature; passing several of
|
|
70
|
+
* the same kind is ambiguous and would silently drop all but the first, so it is rejected instead.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { AmbiguousRequirementSignaturesError } from "@morpho-org/morpho-sdk";
|
|
75
|
+
*
|
|
76
|
+
* if (error instanceof AmbiguousRequirementSignaturesError) {
|
|
77
|
+
* // Pass a single permit (and at most one authorization) signature to buildTx.
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare class AmbiguousRequirementSignaturesError extends Error {
|
|
82
|
+
/**
|
|
83
|
+
* @param kind - The over-supplied signature kind (`"permit"` or `"authorization"`).
|
|
84
|
+
* @param count - How many signatures of that kind were received.
|
|
85
|
+
*/
|
|
86
|
+
constructor(kind: "permit" | "authorization", count: number);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Thrown when `buildTx` receives a requirement signature of a kind the operation does not consume
|
|
90
|
+
* (for example an authorization signature on a plain supply path). Surfacing it prevents a signed
|
|
91
|
+
* authorization or permit from being silently ignored.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { UnexpectedRequirementSignatureError } from "@morpho-org/morpho-sdk";
|
|
96
|
+
*
|
|
97
|
+
* if (error instanceof UnexpectedRequirementSignatureError) {
|
|
98
|
+
* // Remove the signature this operation does not use from the buildTx array.
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare class UnexpectedRequirementSignatureError extends Error {
|
|
103
|
+
/**
|
|
104
|
+
* @param kind - The unexpected signature kind (`"permit"` or `"authorization"`).
|
|
105
|
+
*/
|
|
106
|
+
constructor(kind: "permit" | "authorization");
|
|
46
107
|
}
|
|
47
108
|
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
48
109
|
export declare class NonPositiveAssetAmountError extends Error {
|
|
@@ -72,6 +133,18 @@ export declare class MissingClientPropertyError extends Error {
|
|
|
72
133
|
export declare class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
73
134
|
constructor();
|
|
74
135
|
}
|
|
136
|
+
/** Thrown when a requirement encoder targets an unsupported spender. */
|
|
137
|
+
export declare class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
138
|
+
constructor(params: {
|
|
139
|
+
readonly spender: Address;
|
|
140
|
+
readonly chainId: number;
|
|
141
|
+
readonly generalAdapter1: Address;
|
|
142
|
+
readonly permit2?: Address;
|
|
143
|
+
readonly midnight?: Address;
|
|
144
|
+
readonly midnightBundles?: Address;
|
|
145
|
+
readonly supportedSpenders?: readonly (Address | undefined)[];
|
|
146
|
+
});
|
|
147
|
+
}
|
|
75
148
|
/** Thrown when a slippage tolerance is negative. */
|
|
76
149
|
export declare class NegativeSlippageToleranceError extends Error {
|
|
77
150
|
constructor(slippageTolerance: bigint);
|
package/lib/cjs/types/error.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.RefinanceSharesMissingBorrowAssetsError = exports.RefinanceExceedsBorrowAssetsError = exports.RefinanceExceedsBorrowSharesError = exports.RefinanceExceedsCollateralError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.NegativeMaxRepaySharePriceError = exports.BorrowAmountAndSharesExclusiveError = exports.NegativeBorrowSharesError = exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.NegativeWithdrawMinSharePriceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = void 0;
|
|
3
|
+
exports.DisabledReallocationMarketError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.NativeAmountOnNonWNativeAssetError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.Permit2ExpirationMissingError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.UnsupportedErc20ApprovalSpenderError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.BundlerErrors = void 0;
|
|
4
|
+
exports.RefinanceSharesMissingBorrowAssetsError = exports.RefinanceExceedsBorrowAssetsError = exports.RefinanceExceedsBorrowSharesError = exports.RefinanceExceedsCollateralError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.NegativeMaxRepaySharePriceError = exports.BorrowAmountAndSharesExclusiveError = exports.NegativeBorrowSharesError = exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.NegativeWithdrawMinSharePriceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = void 0;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
/**
|
|
7
7
|
* Typed errors thrown while encoding supported Bundler3 actions.
|
|
@@ -53,7 +53,77 @@ var BundlerErrors;
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
BundlerErrors.UnexpectedAction = UnexpectedAction;
|
|
56
|
+
/**
|
|
57
|
+
* Thrown when a Morpho authorization signature names a forbidden `authorized` account
|
|
58
|
+
* (for example Bundler3 itself), which would grant operator rights to an unintended address.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { BundlerErrors } from "@morpho-org/morpho-sdk";
|
|
63
|
+
*
|
|
64
|
+
* if (error instanceof BundlerErrors.UnexpectedSignature) {
|
|
65
|
+
* // Re-sign the authorization targeting GeneralAdapter1.
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
class UnexpectedSignature extends Error {
|
|
70
|
+
/**
|
|
71
|
+
* @param authorized - The forbidden `authorized` address carried by the signature.
|
|
72
|
+
*/
|
|
73
|
+
constructor(authorized) {
|
|
74
|
+
super(`unexpected signature authorizing "${authorized}"`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
BundlerErrors.UnexpectedSignature = UnexpectedSignature;
|
|
56
78
|
})(BundlerErrors || (exports.BundlerErrors = BundlerErrors = {}));
|
|
79
|
+
/**
|
|
80
|
+
* Thrown when `buildTx` receives more than one requirement signature of the same kind.
|
|
81
|
+
*
|
|
82
|
+
* A bundled path consumes at most one permit and one authorization signature; passing several of
|
|
83
|
+
* the same kind is ambiguous and would silently drop all but the first, so it is rejected instead.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { AmbiguousRequirementSignaturesError } from "@morpho-org/morpho-sdk";
|
|
88
|
+
*
|
|
89
|
+
* if (error instanceof AmbiguousRequirementSignaturesError) {
|
|
90
|
+
* // Pass a single permit (and at most one authorization) signature to buildTx.
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
class AmbiguousRequirementSignaturesError extends Error {
|
|
95
|
+
/**
|
|
96
|
+
* @param kind - The over-supplied signature kind (`"permit"` or `"authorization"`).
|
|
97
|
+
* @param count - How many signatures of that kind were received.
|
|
98
|
+
*/
|
|
99
|
+
constructor(kind, count) {
|
|
100
|
+
super(`Expected at most one ${kind} signature but received ${count}. Pass a single ${kind} signature to buildTx.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.AmbiguousRequirementSignaturesError = AmbiguousRequirementSignaturesError;
|
|
104
|
+
/**
|
|
105
|
+
* Thrown when `buildTx` receives a requirement signature of a kind the operation does not consume
|
|
106
|
+
* (for example an authorization signature on a plain supply path). Surfacing it prevents a signed
|
|
107
|
+
* authorization or permit from being silently ignored.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { UnexpectedRequirementSignatureError } from "@morpho-org/morpho-sdk";
|
|
112
|
+
*
|
|
113
|
+
* if (error instanceof UnexpectedRequirementSignatureError) {
|
|
114
|
+
* // Remove the signature this operation does not use from the buildTx array.
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
class UnexpectedRequirementSignatureError extends Error {
|
|
119
|
+
/**
|
|
120
|
+
* @param kind - The unexpected signature kind (`"permit"` or `"authorization"`).
|
|
121
|
+
*/
|
|
122
|
+
constructor(kind) {
|
|
123
|
+
super(`Received a ${kind} signature that this operation does not consume. Remove it from the buildTx signatures array.`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.UnexpectedRequirementSignatureError = UnexpectedRequirementSignatureError;
|
|
57
127
|
/** Thrown when an asset amount is required to be positive but is zero or negative. */
|
|
58
128
|
class NonPositiveAssetAmountError extends Error {
|
|
59
129
|
constructor(origin) {
|
|
@@ -103,6 +173,21 @@ class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
|
103
173
|
}
|
|
104
174
|
}
|
|
105
175
|
exports.ApprovalAmountLessThanSpendAmountError = ApprovalAmountLessThanSpendAmountError;
|
|
176
|
+
/** Thrown when a requirement encoder targets an unsupported spender. */
|
|
177
|
+
class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
178
|
+
constructor(params) {
|
|
179
|
+
const supported = (params.supportedSpenders ?? [
|
|
180
|
+
params.generalAdapter1,
|
|
181
|
+
params.permit2,
|
|
182
|
+
params.midnight,
|
|
183
|
+
params.midnightBundles,
|
|
184
|
+
])
|
|
185
|
+
.filter((address) => address != null)
|
|
186
|
+
.join('", "');
|
|
187
|
+
super(`Requirement spender "${params.spender}" is not supported on chain "${params.chainId}". Use "${supported}".`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.UnsupportedErc20ApprovalSpenderError = UnsupportedErc20ApprovalSpenderError;
|
|
106
191
|
/** Thrown when a slippage tolerance is negative. */
|
|
107
192
|
class NegativeSlippageToleranceError extends Error {
|
|
108
193
|
constructor(slippageTolerance) {
|
|
@@ -134,14 +219,14 @@ exports.EmptyDeallocationsError = EmptyDeallocationsError;
|
|
|
134
219
|
/** Thrown when a deposit's amount differs from the amount the supplied permit / permit2 signature was issued for. */
|
|
135
220
|
class DepositAmountMismatchError extends Error {
|
|
136
221
|
constructor(depositAmount, signatureAmount) {
|
|
137
|
-
super(`Deposit amount ${depositAmount} does not match requirement signature amount ${signatureAmount}`);
|
|
222
|
+
super(`Deposit amount "${depositAmount}" does not match requirement signature amount "${signatureAmount}"`);
|
|
138
223
|
}
|
|
139
224
|
}
|
|
140
225
|
exports.DepositAmountMismatchError = DepositAmountMismatchError;
|
|
141
226
|
/** Thrown when a deposit's asset differs from the asset the supplied permit / permit2 signature was issued for. */
|
|
142
227
|
class DepositAssetMismatchError extends Error {
|
|
143
228
|
constructor(depositAsset, signatureAsset) {
|
|
144
|
-
super(`Deposit asset ${depositAsset} does not match requirement signature asset ${signatureAsset}`);
|
|
229
|
+
super(`Deposit asset "${depositAsset}" does not match requirement signature asset "${signatureAsset}"`);
|
|
145
230
|
}
|
|
146
231
|
}
|
|
147
232
|
exports.DepositAssetMismatchError = DepositAssetMismatchError;
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export type { BigIntish,
|
|
1
|
+
export type { BigIntish, CollateralAllocation, Eip712Field, Erc20AllowanceRecipient, Failable, Fetchable, InputMarketParams, IPermit2Allowance, Loadable, MarketId, MaxBorrowOptions, MaxPositionCapacities, MaxWithdrawCollateralOptions, Pending, Permit2Allowance, } from "@morpho-org/blue-sdk";
|
|
2
2
|
export type { DeploylessFetchParameters, FetchParameters, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
export type { ChainMetadata } from "@morpho-org/morpho-ts";
|
|
3
4
|
export * from "./types/index.js";
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { CapacityLimit, RoundingDirection } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { AdaptiveCurveIrmLib, CapacityLimitReason, MarketUtils, MathLib, SharesMath, VaultUtils, } from "@morpho-org/blue-sdk";
|
|
3
|
-
export { decodeBytes32String, getAuthorizationTypedData,
|
|
3
|
+
export { decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
4
4
|
export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, WithId, WithIndex, } from "@morpho-org/morpho-ts";
|
|
5
5
|
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
6
6
|
export { computeReallocations } from "./helpers/computeReallocations.js";
|
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 = exports.validateRepayShares =
|
|
3
|
+
exports.validateRepayParams = 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 = exports.validateRepayShares = 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; } });
|
|
@@ -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);
|
|
@@ -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,6 +1,6 @@
|
|
|
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, Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRepay}. */
|
|
5
5
|
export interface BlueRepayParams {
|
|
6
6
|
market: {
|
|
@@ -24,7 +24,8 @@ export interface BlueRepayParams {
|
|
|
24
24
|
receiver: Address;
|
|
25
25
|
/** Maximum repay share price (in ray). Protects against share price manipulation. */
|
|
26
26
|
maxSharePrice: bigint;
|
|
27
|
-
|
|
27
|
+
/** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
|
|
28
|
+
requirementSignature?: PermitRequirementSignature;
|
|
28
29
|
};
|
|
29
30
|
metadata?: Metadata;
|
|
30
31
|
}
|
|
@@ -64,11 +65,11 @@ export interface BlueRepayParams {
|
|
|
64
65
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
65
66
|
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
66
67
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
67
|
-
* @throws {DepositAssetMismatchError} from `
|
|
68
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
68
69
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
69
|
-
* @throws {DepositAmountMismatchError} from `
|
|
70
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
70
71
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
71
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
72
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
72
73
|
* signature is missing its expiration.
|
|
73
74
|
* @example
|
|
74
75
|
* ```ts
|
|
@@ -3,7 +3,7 @@ import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata, validateRepayParams, } from "../../helpers/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
|
|
7
7
|
/**
|
|
8
8
|
* Prepares a repay transaction for a Morpho Blue market.
|
|
9
9
|
*
|
|
@@ -40,11 +40,11 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
40
40
|
* @throws {MutuallyExclusiveRepayAmountsError} when both `assets` and `shares` are non-zero.
|
|
41
41
|
* @throws {NonPositiveTransferAmountError} when `transferAmount <= 0n`.
|
|
42
42
|
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and `transferAmount !== assets`.
|
|
43
|
-
* @throws {DepositAssetMismatchError} from `
|
|
43
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
44
44
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
45
|
-
* @throws {DepositAmountMismatchError} from `
|
|
45
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
46
46
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
47
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
47
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
48
48
|
* signature is missing its expiration.
|
|
49
49
|
* @example
|
|
50
50
|
* ```ts
|
|
@@ -74,20 +74,12 @@ export const blueRepay = ({ market: { chainId, marketParams }, args: { assets, s
|
|
|
74
74
|
});
|
|
75
75
|
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
76
76
|
const actions = [];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
actions.push({
|
|
87
|
-
type: "erc20TransferFrom",
|
|
88
|
-
args: [marketParams.loanToken, transferAmount, generalAdapter1, false],
|
|
89
|
-
});
|
|
90
|
-
}
|
|
77
|
+
actions.push(...getTokenRequirementActions({
|
|
78
|
+
asset: marketParams.loanToken,
|
|
79
|
+
amount: transferAmount,
|
|
80
|
+
recipient: generalAdapter1,
|
|
81
|
+
requirementSignature,
|
|
82
|
+
}));
|
|
91
83
|
actions.push({
|
|
92
84
|
type: "morphoRepay",
|
|
93
85
|
args: [marketParams, assets, shares, maxSharePrice, onBehalf, [], false],
|