@morpho-org/morpho-sdk 4.1.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 +12 -12
- package/lib/cjs/entities/reallocationData.js +19 -19
- 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 +12 -12
- package/lib/esm/entities/reallocationData.js +18 -18
- 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
|
@@ -6,7 +6,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const index_js_1 = require("../../bundler/index.js");
|
|
7
7
|
const index_js_2 = require("../../helpers/index.js");
|
|
8
8
|
const index_js_3 = require("../../types/index.js");
|
|
9
|
-
const
|
|
9
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
10
10
|
/**
|
|
11
11
|
* Prepares a supply-collateral transaction for a Morpho Blue market.
|
|
12
12
|
*
|
|
@@ -21,9 +21,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
21
21
|
* @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
|
|
22
22
|
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
23
23
|
* @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
|
|
24
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
25
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
26
|
-
* approved `GeneralAdapter1`.
|
|
24
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
27
25
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
28
26
|
* supply. Requires the collateral token to be the chain's wNative.
|
|
29
27
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -35,11 +33,11 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
35
33
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
36
34
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
37
35
|
* token is not the chain's wNative.
|
|
38
|
-
* @throws {DepositAssetMismatchError} from `
|
|
36
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
39
37
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
40
|
-
* @throws {DepositAmountMismatchError} from `
|
|
38
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
41
39
|
* is provided and the signed amount differs from `args.amount`.
|
|
42
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
40
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
43
41
|
* signature is missing its expiration.
|
|
44
42
|
* @example
|
|
45
43
|
* ```ts
|
|
@@ -76,20 +74,12 @@ const blueSupplyCollateral = ({ market: { chainId, marketParams }, args: { amoun
|
|
|
76
74
|
});
|
|
77
75
|
}
|
|
78
76
|
if (amount > 0n) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
actions.push({
|
|
89
|
-
type: "erc20TransferFrom",
|
|
90
|
-
args: [marketParams.collateralToken, amount, generalAdapter1, false],
|
|
91
|
-
});
|
|
92
|
-
}
|
|
77
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
78
|
+
asset: marketParams.collateralToken,
|
|
79
|
+
amount,
|
|
80
|
+
recipient: generalAdapter1,
|
|
81
|
+
requirementSignature,
|
|
82
|
+
}));
|
|
93
83
|
}
|
|
94
84
|
actions.push({
|
|
95
85
|
type: "morphoSupplyCollateral",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueSupplyCollateralBorrowAction, type DepositAmountArgs, type Metadata, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueSupplyCollateralBorrowAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateralBorrow}. */
|
|
5
5
|
export interface BlueSupplyCollateralBorrowParams {
|
|
6
6
|
market: {
|
|
@@ -8,14 +8,24 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
9
|
};
|
|
10
10
|
args: DepositAmountArgs & {
|
|
11
|
+
/** Amount of loan asset to borrow after the collateral is supplied. */
|
|
11
12
|
borrowAmount: bigint;
|
|
13
|
+
/** Address whose Morpho collateral and borrow positions are credited. */
|
|
12
14
|
onBehalf: Address;
|
|
15
|
+
/** Address that receives the borrowed assets. */
|
|
13
16
|
receiver: Address;
|
|
14
17
|
/** Minimum borrow share price (in ray). Protects against share price manipulation. */
|
|
15
18
|
minSharePrice: bigint;
|
|
16
|
-
|
|
19
|
+
/** Optional pre-signed permit/permit2 approval for the collateral transfer. */
|
|
20
|
+
requirementSignature?: PermitRequirementSignature;
|
|
17
21
|
/** Vault reallocations to execute before borrowing (computed by entity). */
|
|
18
22
|
reallocations?: readonly VaultReallocation[];
|
|
23
|
+
/**
|
|
24
|
+
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
25
|
+
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
26
|
+
* standalone `setAuthorization` transaction.
|
|
27
|
+
*/
|
|
28
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
19
29
|
};
|
|
20
30
|
metadata?: Metadata;
|
|
21
31
|
}
|
|
@@ -46,6 +56,8 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
46
56
|
* collateral supply. Requires the collateral token to be the chain's wNative.
|
|
47
57
|
* @param params.args.reallocations - Optional vault reallocations to execute between the supply
|
|
48
58
|
* and borrow legs, computed by the entity layer.
|
|
59
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
60
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
49
61
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
50
62
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
51
63
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
@@ -57,11 +69,11 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
57
69
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
58
70
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
59
71
|
* token is not the chain's wNative.
|
|
60
|
-
* @throws {DepositAssetMismatchError} from `
|
|
72
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
61
73
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
62
|
-
* @throws {DepositAmountMismatchError} from `
|
|
74
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
63
75
|
* is provided and the signed amount differs from `args.amount`.
|
|
64
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
76
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
65
77
|
* signature is missing its expiration.
|
|
66
78
|
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
67
79
|
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
@@ -90,4 +102,4 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
90
102
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
91
103
|
* ```
|
|
92
104
|
*/
|
|
93
|
-
export declare const blueSupplyCollateralBorrow: ({ market: { chainId, marketParams }, args: { amount, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }: BlueSupplyCollateralBorrowParams) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
105
|
+
export declare const blueSupplyCollateralBorrow: ({ market: { chainId, marketParams }, args: { amount, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }: BlueSupplyCollateralBorrowParams) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
@@ -6,7 +6,8 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const index_js_1 = require("../../bundler/index.js");
|
|
7
7
|
const index_js_2 = require("../../helpers/index.js");
|
|
8
8
|
const index_js_3 = require("../../types/index.js");
|
|
9
|
-
const
|
|
9
|
+
const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
|
|
10
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
10
11
|
const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
11
12
|
/**
|
|
12
13
|
* Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
|
|
@@ -35,6 +36,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
35
36
|
* collateral supply. Requires the collateral token to be the chain's wNative.
|
|
36
37
|
* @param params.args.reallocations - Optional vault reallocations to execute between the supply
|
|
37
38
|
* and borrow legs, computed by the entity layer.
|
|
39
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
40
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
38
41
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
39
42
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
40
43
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
@@ -46,11 +49,11 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
46
49
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
47
50
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
48
51
|
* token is not the chain's wNative.
|
|
49
|
-
* @throws {DepositAssetMismatchError} from `
|
|
52
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
50
53
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
51
|
-
* @throws {DepositAmountMismatchError} from `
|
|
54
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
52
55
|
* is provided and the signed amount differs from `args.amount`.
|
|
53
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
56
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
54
57
|
* signature is missing its expiration.
|
|
55
58
|
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
56
59
|
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
@@ -79,7 +82,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
79
82
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
80
83
|
* ```
|
|
81
84
|
*/
|
|
82
|
-
const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }) => {
|
|
85
|
+
const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }) => {
|
|
83
86
|
if (amount < 0n) {
|
|
84
87
|
throw new index_js_3.NonPositiveAssetAmountError(marketParams.collateralToken);
|
|
85
88
|
}
|
|
@@ -98,6 +101,9 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
98
101
|
}
|
|
99
102
|
const { bundler3: { generalAdapter1, bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
100
103
|
const actions = [];
|
|
104
|
+
if (authorizationSignature) {
|
|
105
|
+
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
106
|
+
}
|
|
101
107
|
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
102
108
|
(0, index_js_2.validateNativeAsset)(chainId, marketParams.collateralToken);
|
|
103
109
|
actions.push({
|
|
@@ -109,20 +115,12 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
109
115
|
});
|
|
110
116
|
}
|
|
111
117
|
if (amount > 0n) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
actions.push({
|
|
122
|
-
type: "erc20TransferFrom",
|
|
123
|
-
args: [marketParams.collateralToken, amount, generalAdapter1, false],
|
|
124
|
-
});
|
|
125
|
-
}
|
|
118
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
119
|
+
asset: marketParams.collateralToken,
|
|
120
|
+
amount,
|
|
121
|
+
recipient: generalAdapter1,
|
|
122
|
+
requirementSignature,
|
|
123
|
+
}));
|
|
126
124
|
}
|
|
127
125
|
actions.push({
|
|
128
126
|
type: "morphoSupplyCollateral",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueWithdrawAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueWithdrawAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueWithdraw}. */
|
|
5
5
|
export interface BlueWithdrawParams {
|
|
6
6
|
market: {
|
|
@@ -22,6 +22,12 @@ export interface BlueWithdrawParams {
|
|
|
22
22
|
* `computeReallocations({ operation: "withdraw", amount, ... })`.
|
|
23
23
|
*/
|
|
24
24
|
reallocations?: readonly VaultReallocation[];
|
|
25
|
+
/**
|
|
26
|
+
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
27
|
+
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
28
|
+
* standalone `setAuthorization` transaction.
|
|
29
|
+
*/
|
|
30
|
+
authorizationSignature?: AuthorizationRequirementSignature;
|
|
25
31
|
};
|
|
26
32
|
metadata?: Metadata;
|
|
27
33
|
}
|
|
@@ -53,6 +59,8 @@ export interface BlueWithdrawParams {
|
|
|
53
59
|
* protection.
|
|
54
60
|
* @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
|
|
55
61
|
* computed by the entity layer.
|
|
62
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
63
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
56
64
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
57
65
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
58
66
|
* the typed `action` discriminator the simulation layer consumes.
|
|
@@ -80,4 +88,4 @@ export interface BlueWithdrawParams {
|
|
|
80
88
|
* // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
|
|
81
89
|
* ```
|
|
82
90
|
*/
|
|
83
|
-
export declare const blueWithdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }: BlueWithdrawParams) => Readonly<Transaction<BlueWithdrawAction>>;
|
|
91
|
+
export declare const blueWithdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }: BlueWithdrawParams) => Readonly<Transaction<BlueWithdrawAction>>;
|
|
@@ -5,6 +5,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
5
5
|
const index_js_1 = require("../../bundler/index.js");
|
|
6
6
|
const index_js_2 = require("../../helpers/index.js");
|
|
7
7
|
const index_js_3 = require("../../types/index.js");
|
|
8
|
+
const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
|
|
8
9
|
const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
9
10
|
/**
|
|
10
11
|
* Prepares a loan-asset withdraw transaction for a Morpho Blue market.
|
|
@@ -34,6 +35,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
34
35
|
* protection.
|
|
35
36
|
* @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
|
|
36
37
|
* computed by the entity layer.
|
|
38
|
+
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
39
|
+
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
37
40
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
38
41
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
39
42
|
* the typed `action` discriminator the simulation layer consumes.
|
|
@@ -61,7 +64,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
61
64
|
* // tx satisfies Readonly<Transaction<BlueWithdrawAction>>
|
|
62
65
|
* ```
|
|
63
66
|
*/
|
|
64
|
-
const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }) => {
|
|
67
|
+
const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations, authorizationSignature, }, metadata, }) => {
|
|
65
68
|
// Mutual exclusion is detected on "both values present" (either non-zero),
|
|
66
69
|
// before sign checks — otherwise `{ assets: -1n, shares: 5n }` would be
|
|
67
70
|
// misreported as a positivity error rather than the actual mode conflict.
|
|
@@ -76,6 +79,9 @@ const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, share
|
|
|
76
79
|
}
|
|
77
80
|
const actions = [];
|
|
78
81
|
let reallocationFee = 0n;
|
|
82
|
+
if (authorizationSignature) {
|
|
83
|
+
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
84
|
+
}
|
|
79
85
|
if (reallocations && reallocations.length > 0) {
|
|
80
86
|
const result = (0, buildReallocationActions_js_1.buildReallocationActions)(reallocations, marketParams);
|
|
81
87
|
actions.push(...result.actions);
|
|
@@ -3,5 +3,6 @@ export type { VaultV1Actions } from "../entities/vaultV1/index.js";
|
|
|
3
3
|
export type { VaultV2Actions } from "../entities/vaultV2/index.js";
|
|
4
4
|
export * from "./blue/index.js";
|
|
5
5
|
export * from "./requirements/index.js";
|
|
6
|
+
export * from "./signatures/index.js";
|
|
6
7
|
export * from "./vaultV1/index.js";
|
|
7
8
|
export * from "./vaultV2/index.js";
|
package/lib/cjs/actions/index.js
CHANGED
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./blue/index.js"), exports);
|
|
18
18
|
__exportStar(require("./requirements/index.js"), exports);
|
|
19
|
+
__exportStar(require("./signatures/index.js"), exports);
|
|
19
20
|
__exportStar(require("./vaultV1/index.js"), exports);
|
|
20
21
|
__exportStar(require("./vaultV2/index.js"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Client } from "viem";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, type Requirement, type Transaction } from "../../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves whether `GeneralAdapter1` needs Blue authorization for the given user, and returns
|
|
6
|
+
* the requirement to satisfy it when it does.
|
|
7
|
+
*
|
|
8
|
+
* Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
|
|
9
|
+
* any bundled Blue path that operates on behalf of the user (`borrow`, `withdraw`,
|
|
10
|
+
* `supplyCollateralBorrow`, `repayWithdrawCollateral`, `refinance`).
|
|
11
|
+
*
|
|
12
|
+
* - When `supportSignature` is falsy (default), returns the
|
|
13
|
+
* `setAuthorization(generalAdapter1, true)` transaction the user submits before the bundle.
|
|
14
|
+
* - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
|
|
15
|
+
* `Requirement`; the signed authorization is folded into the bundle via
|
|
16
|
+
* `setAuthorizationWithSig`, removing the standalone transaction.
|
|
17
|
+
*
|
|
18
|
+
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
19
|
+
* @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
|
|
20
|
+
* @param params.userAddress - The user that must authorize `GeneralAdapter1`.
|
|
21
|
+
* @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
|
|
22
|
+
* transaction so authorization can be bundled via `setAuthorizationWithSig`.
|
|
23
|
+
* @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
|
|
24
|
+
* `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
|
|
25
|
+
* place.
|
|
26
|
+
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { createPublicClient, http } from "viem";
|
|
30
|
+
* import { mainnet } from "viem/chains";
|
|
31
|
+
* import { getBlueAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
32
|
+
*
|
|
33
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
34
|
+
* const requirement = await getBlueAuthorizationRequirement({
|
|
35
|
+
* viemClient: client,
|
|
36
|
+
* chainId: 1,
|
|
37
|
+
* userAddress: borrower,
|
|
38
|
+
* supportSignature: true,
|
|
39
|
+
* });
|
|
40
|
+
* // requirement is null when already authorized, a Requirement when supportSignature is true,
|
|
41
|
+
* // otherwise Readonly<Transaction<BlueAuthorizationAction>>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const getBlueAuthorizationRequirement: (params: {
|
|
45
|
+
viemClient: Client;
|
|
46
|
+
chainId: number;
|
|
47
|
+
userAddress: Address;
|
|
48
|
+
supportSignature?: boolean;
|
|
49
|
+
}) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBlueAuthorizationRequirement = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSignatureAuthorization.js");
|
|
10
|
+
/**
|
|
11
|
+
* Resolves whether `GeneralAdapter1` needs Blue authorization for the given user, and returns
|
|
12
|
+
* the requirement to satisfy it when it does.
|
|
13
|
+
*
|
|
14
|
+
* Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
|
|
15
|
+
* any bundled Blue path that operates on behalf of the user (`borrow`, `withdraw`,
|
|
16
|
+
* `supplyCollateralBorrow`, `repayWithdrawCollateral`, `refinance`).
|
|
17
|
+
*
|
|
18
|
+
* - When `supportSignature` is falsy (default), returns the
|
|
19
|
+
* `setAuthorization(generalAdapter1, true)` transaction the user submits before the bundle.
|
|
20
|
+
* - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
|
|
21
|
+
* `Requirement`; the signed authorization is folded into the bundle via
|
|
22
|
+
* `setAuthorizationWithSig`, removing the standalone transaction.
|
|
23
|
+
*
|
|
24
|
+
* @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
25
|
+
* @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
|
|
26
|
+
* @param params.userAddress - The user that must authorize `GeneralAdapter1`.
|
|
27
|
+
* @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
|
|
28
|
+
* transaction so authorization can be bundled via `setAuthorizationWithSig`.
|
|
29
|
+
* @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
|
|
30
|
+
* `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
|
|
31
|
+
* place.
|
|
32
|
+
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createPublicClient, http } from "viem";
|
|
36
|
+
* import { mainnet } from "viem/chains";
|
|
37
|
+
* import { getBlueAuthorizationRequirement } from "@morpho-org/morpho-sdk";
|
|
38
|
+
*
|
|
39
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
40
|
+
* const requirement = await getBlueAuthorizationRequirement({
|
|
41
|
+
* viemClient: client,
|
|
42
|
+
* chainId: 1,
|
|
43
|
+
* userAddress: borrower,
|
|
44
|
+
* supportSignature: true,
|
|
45
|
+
* });
|
|
46
|
+
* // requirement is null when already authorized, a Requirement when supportSignature is true,
|
|
47
|
+
* // otherwise Readonly<Transaction<BlueAuthorizationAction>>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
const getBlueAuthorizationRequirement = async (params) => {
|
|
51
|
+
const { viemClient, chainId, userAddress, supportSignature } = params;
|
|
52
|
+
if (viemClient.chain?.id !== chainId) {
|
|
53
|
+
throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
54
|
+
}
|
|
55
|
+
const { morpho, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
56
|
+
const pc = viemClient.extend(viem_1.publicActions);
|
|
57
|
+
if (supportSignature) {
|
|
58
|
+
// The signable path needs the user's Morpho nonce; fetch it alongside the
|
|
59
|
+
// authorization status so both reads share a round-trip (batched into a
|
|
60
|
+
// single multicall when the client enables batching) instead of
|
|
61
|
+
// serializing the nonce read behind isAuthorized.
|
|
62
|
+
const [isAuthorized, nonce] = await Promise.all([
|
|
63
|
+
pc.readContract({
|
|
64
|
+
address: morpho,
|
|
65
|
+
abi: blue_sdk_viem_1.blueAbi,
|
|
66
|
+
functionName: "isAuthorized",
|
|
67
|
+
args: [userAddress, generalAdapter1],
|
|
68
|
+
}),
|
|
69
|
+
pc.readContract({
|
|
70
|
+
address: morpho,
|
|
71
|
+
abi: blue_sdk_viem_1.blueAbi,
|
|
72
|
+
functionName: "nonce",
|
|
73
|
+
args: [userAddress],
|
|
74
|
+
}),
|
|
75
|
+
]);
|
|
76
|
+
if (isAuthorized) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return (0, encodeBlueSignatureAuthorization_js_1.encodeBlueSignatureAuthorization)(viemClient, {
|
|
80
|
+
authorized: generalAdapter1,
|
|
81
|
+
chainId,
|
|
82
|
+
nonce,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const isAuthorized = await pc.readContract({
|
|
86
|
+
address: morpho,
|
|
87
|
+
abi: blue_sdk_viem_1.blueAbi,
|
|
88
|
+
functionName: "isAuthorized",
|
|
89
|
+
args: [userAddress, generalAdapter1],
|
|
90
|
+
});
|
|
91
|
+
if (isAuthorized) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
95
|
+
to: morpho,
|
|
96
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
97
|
+
abi: blue_sdk_viem_1.blueAbi,
|
|
98
|
+
functionName: "setAuthorization",
|
|
99
|
+
args: [generalAdapter1, true],
|
|
100
|
+
}),
|
|
101
|
+
value: 0n,
|
|
102
|
+
action: {
|
|
103
|
+
type: "blueAuthorization",
|
|
104
|
+
args: {
|
|
105
|
+
authorized: generalAdapter1,
|
|
106
|
+
isAuthorized: true,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
exports.getBlueAuthorizationRequirement = getBlueAuthorizationRequirement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./getBlueAuthorizationRequirement.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getBlueAuthorizationRequirement.js"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Client } from "viem";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
|
|
4
|
+
/** Parameters for {@link encodeBlueSignatureAuthorization}. */
|
|
5
|
+
interface EncodeBlueSignatureAuthorizationParams {
|
|
6
|
+
/** Account to authorize on Morpho (GeneralAdapter1). */
|
|
7
|
+
authorized: Address;
|
|
8
|
+
/** Target chain id; must match `viemClient.chain.id`. */
|
|
9
|
+
chainId: number;
|
|
10
|
+
/** The signer's current Morpho authorization nonce. */
|
|
11
|
+
nonce: bigint;
|
|
12
|
+
/** Whether to grant (`true`, default) or revoke (`false`) the authorization. */
|
|
13
|
+
isAuthorized?: boolean;
|
|
14
|
+
/** Signature deadline in seconds. Defaults to two hours from now. */
|
|
15
|
+
deadline?: bigint;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
|
|
19
|
+
* Morpho on the signer's behalf through `setAuthorizationWithSig` — the offchain-signature
|
|
20
|
+
* alternative to a standalone `setAuthorization` transaction.
|
|
21
|
+
*
|
|
22
|
+
* The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
|
|
23
|
+
* typed data, verifies it against the connected account, and returns a deep-frozen
|
|
24
|
+
* `RequirementSignature` the bundler action helpers consume. Deadline defaults to two hours from
|
|
25
|
+
* `Time.timestamp()`.
|
|
26
|
+
*
|
|
27
|
+
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
28
|
+
* @param params - Authorization encoding parameters.
|
|
29
|
+
* @param params.authorized - Account to authorize (GeneralAdapter1).
|
|
30
|
+
* @param params.chainId - Target chain id.
|
|
31
|
+
* @param params.nonce - The signer's current Morpho authorization nonce.
|
|
32
|
+
* @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
|
|
33
|
+
* @param params.deadline - Optional signature deadline in seconds.
|
|
34
|
+
* @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
|
|
35
|
+
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
36
|
+
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
37
|
+
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
38
|
+
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { createWalletClient, http } from "viem";
|
|
42
|
+
* import { mainnet } from "viem/chains";
|
|
43
|
+
* import { encodeBlueSignatureAuthorization } from "@morpho-org/morpho-sdk";
|
|
44
|
+
*
|
|
45
|
+
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
46
|
+
* const requirement = await encodeBlueSignatureAuthorization(client, {
|
|
47
|
+
* authorized: generalAdapter1,
|
|
48
|
+
* chainId: 1,
|
|
49
|
+
* nonce: 0n,
|
|
50
|
+
* });
|
|
51
|
+
* // requirement satisfies Requirement
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const encodeBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => Promise<Requirement<AuthorizationRequirementSignature>>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeBlueSignatureAuthorization = void 0;
|
|
4
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const actions_1 = require("viem/actions");
|
|
8
|
+
const validate_js_1 = require("../../../helpers/validate.js");
|
|
9
|
+
const index_js_1 = require("../../../types/index.js");
|
|
10
|
+
/**
|
|
11
|
+
* Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
|
|
12
|
+
* Morpho on the signer's behalf through `setAuthorizationWithSig` — the offchain-signature
|
|
13
|
+
* alternative to a standalone `setAuthorization` transaction.
|
|
14
|
+
*
|
|
15
|
+
* The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
|
|
16
|
+
* typed data, verifies it against the connected account, and returns a deep-frozen
|
|
17
|
+
* `RequirementSignature` the bundler action helpers consume. Deadline defaults to two hours from
|
|
18
|
+
* `Time.timestamp()`.
|
|
19
|
+
*
|
|
20
|
+
* @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
|
|
21
|
+
* @param params - Authorization encoding parameters.
|
|
22
|
+
* @param params.authorized - Account to authorize (GeneralAdapter1).
|
|
23
|
+
* @param params.chainId - Target chain id.
|
|
24
|
+
* @param params.nonce - The signer's current Morpho authorization nonce.
|
|
25
|
+
* @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
|
|
26
|
+
* @param params.deadline - Optional signature deadline in seconds.
|
|
27
|
+
* @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
|
|
28
|
+
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|
|
29
|
+
* @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
|
|
30
|
+
* @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
|
|
31
|
+
* @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { createWalletClient, http } from "viem";
|
|
35
|
+
* import { mainnet } from "viem/chains";
|
|
36
|
+
* import { encodeBlueSignatureAuthorization } from "@morpho-org/morpho-sdk";
|
|
37
|
+
*
|
|
38
|
+
* const client = createWalletClient({ chain: mainnet, transport: http() });
|
|
39
|
+
* const requirement = await encodeBlueSignatureAuthorization(client, {
|
|
40
|
+
* authorized: generalAdapter1,
|
|
41
|
+
* chainId: 1,
|
|
42
|
+
* nonce: 0n,
|
|
43
|
+
* });
|
|
44
|
+
* // requirement satisfies Requirement
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const encodeBlueSignatureAuthorization = async (viemClient, params) => {
|
|
48
|
+
const { authorized, chainId, nonce, isAuthorized = true } = params;
|
|
49
|
+
if (viemClient.chain?.id !== chainId) {
|
|
50
|
+
throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
51
|
+
}
|
|
52
|
+
const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
|
|
53
|
+
const action = {
|
|
54
|
+
type: "authorization",
|
|
55
|
+
args: { authorized, isAuthorized, deadline },
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
action,
|
|
59
|
+
async sign(client, userAddress) {
|
|
60
|
+
const account = client.account;
|
|
61
|
+
(0, validate_js_1.validateUserAddress)(account?.address, userAddress);
|
|
62
|
+
const typedData = (0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: userAddress, authorized, isAuthorized, nonce, deadline }, chainId);
|
|
63
|
+
const signature = await (0, actions_1.signTypedData)(client, {
|
|
64
|
+
...typedData,
|
|
65
|
+
account,
|
|
66
|
+
});
|
|
67
|
+
const isValid = await (0, viem_1.verifyTypedData)({
|
|
68
|
+
...typedData,
|
|
69
|
+
address: userAddress, // Verify against the authorizer.
|
|
70
|
+
signature,
|
|
71
|
+
});
|
|
72
|
+
if (!isValid) {
|
|
73
|
+
throw new index_js_1.InvalidSignatureError();
|
|
74
|
+
}
|
|
75
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
76
|
+
args: {
|
|
77
|
+
owner: userAddress,
|
|
78
|
+
authorized,
|
|
79
|
+
isAuthorized,
|
|
80
|
+
nonce,
|
|
81
|
+
deadline,
|
|
82
|
+
signature,
|
|
83
|
+
},
|
|
84
|
+
action,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.encodeBlueSignatureAuthorization = encodeBlueSignatureAuthorization;
|