@morpho-org/morpho-sdk 4.2.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
- package/lib/cjs/actions/blue/refinance.d.ts +13 -3
- package/lib/cjs/actions/blue/refinance.js +8 -2
- package/lib/cjs/actions/blue/repay.d.ts +44 -43
- package/lib/cjs/actions/blue/repay.js +70 -59
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
- package/lib/cjs/actions/blue/supply.d.ts +8 -8
- package/lib/cjs/actions/blue/supply.js +11 -35
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
- package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
- package/lib/cjs/actions/blue/withdraw.js +7 -1
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
- package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/index.js +2 -1
- package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
- package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/cjs/actions/requirements/index.d.ts +2 -5
- package/lib/cjs/actions/requirements/index.js +2 -5
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
- package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
- package/lib/cjs/actions/signatures/index.d.ts +2 -0
- package/lib/cjs/actions/signatures/index.js +18 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV1/deposit.js +11 -21
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/cjs/actions/vaultV2/deposit.js +11 -21
- package/lib/cjs/addresses.d.ts +2 -2
- package/lib/cjs/addresses.js +2 -1
- package/lib/cjs/bundler/actions.d.ts +44 -4
- package/lib/cjs/bundler/actions.js +75 -2
- package/lib/cjs/bundler/types.d.ts +6 -0
- package/lib/cjs/constants.d.ts +2 -2
- package/lib/cjs/constants.js +3 -3
- package/lib/cjs/entities/blue/blue.d.ts +58 -33
- package/lib/cjs/entities/blue/blue.js +309 -189
- package/lib/cjs/entities/reallocationData.d.ts +0 -44
- package/lib/cjs/entities/reallocationData.js +3 -50
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
- package/lib/cjs/errors.d.ts +3 -2
- package/lib/cjs/errors.js +5 -2
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +1 -2
- package/lib/cjs/helpers/validate.d.ts +2 -20
- package/lib/cjs/helpers/validate.js +2 -39
- package/lib/cjs/types/action.d.ts +164 -12
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +97 -2
- package/lib/cjs/types/error.js +113 -7
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
- package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
- package/lib/esm/actions/blue/refinance.d.ts +13 -3
- package/lib/esm/actions/blue/refinance.js +8 -2
- package/lib/esm/actions/blue/repay.d.ts +44 -43
- package/lib/esm/actions/blue/repay.js +71 -60
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
- package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
- package/lib/esm/actions/blue/supply.d.ts +8 -8
- package/lib/esm/actions/blue/supply.js +12 -36
- package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
- package/lib/esm/actions/blue/supplyCollateral.js +13 -37
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
- package/lib/esm/actions/blue/withdraw.d.ts +10 -2
- package/lib/esm/actions/blue/withdraw.js +7 -1
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
- package/lib/esm/actions/requirements/blue/index.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
- package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/index.js +2 -1
- package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
- package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
- package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
- package/lib/esm/actions/requirements/index.d.ts +2 -5
- package/lib/esm/actions/requirements/index.js +2 -5
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
- package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
- package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
- package/lib/esm/actions/signatures/index.d.ts +2 -0
- package/lib/esm/actions/signatures/index.js +2 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV1/deposit.js +11 -21
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
- package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
- package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
- package/lib/esm/actions/vaultV2/deposit.js +11 -21
- package/lib/esm/addresses.d.ts +2 -2
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/bundler/actions.d.ts +44 -4
- package/lib/esm/bundler/actions.js +77 -4
- package/lib/esm/bundler/types.d.ts +6 -0
- package/lib/esm/constants.d.ts +2 -2
- package/lib/esm/constants.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +58 -33
- package/lib/esm/entities/blue/blue.js +311 -191
- package/lib/esm/entities/reallocationData.d.ts +0 -44
- package/lib/esm/entities/reallocationData.js +2 -49
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
- package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
- package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
- package/lib/esm/errors.d.ts +3 -2
- package/lib/esm/errors.js +2 -1
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +2 -20
- package/lib/esm/helpers/validate.js +2 -38
- package/lib/esm/types/action.d.ts +164 -12
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +97 -2
- package/lib/esm/types/error.js +107 -5
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +22 -21
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
- package/lib/cjs/actions/requirements/getRequirements.js +0 -112
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
- package/lib/esm/actions/requirements/getRequirements.js +0 -108
- package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
- package/src/index.ts +0 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBlueAuthorizationAction = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const index_js_1 = require("../../types/index.js");
|
|
7
|
+
/**
|
|
8
|
+
* Encodes the bundler action that consumes a signed Morpho authorization, granting
|
|
9
|
+
* `authorized` (GeneralAdapter1) operator rights on behalf of the signer via
|
|
10
|
+
* `setAuthorizationWithSig` — replacing a standalone `setAuthorization` transaction.
|
|
11
|
+
*
|
|
12
|
+
* The signature's `authorized` is pinned to the chain's `GeneralAdapter1`: an authorization
|
|
13
|
+
* targeting any other account is rejected so the bundle can never hand operator rights over the
|
|
14
|
+
* user's Morpho position to an unintended address. The action is emitted with `skipRevert: false`
|
|
15
|
+
* so a rejected or stale authorization fails the whole bundle rather than letting a later
|
|
16
|
+
* on-behalf Morpho call revert opaquely.
|
|
17
|
+
*
|
|
18
|
+
* @param chainId - Chain whose `GeneralAdapter1` the signature must authorize.
|
|
19
|
+
* @param signature - The signed authorization produced by `Requirement.sign()`.
|
|
20
|
+
* @returns A single `morphoSetAuthorizationWithSig` bundler `Action`.
|
|
21
|
+
* @throws {BundlerErrors.UnexpectedSignature} when `signature.args.authorized` is not the chain's
|
|
22
|
+
* `GeneralAdapter1`.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { getBlueAuthorizationAction } from "@morpho-org/morpho-sdk";
|
|
26
|
+
*
|
|
27
|
+
* // `requirement` comes from `getBlueAuthorizationRequirement` with `supportSignature: true`.
|
|
28
|
+
* const signed = await requirement.sign(walletClient, borrower);
|
|
29
|
+
* const action = getBlueAuthorizationAction(1, signed);
|
|
30
|
+
* // action satisfies { type: "morphoSetAuthorizationWithSig"; args: [...] }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
const getBlueAuthorizationAction = (chainId, signature) => {
|
|
34
|
+
const { owner, authorized, isAuthorized, nonce, deadline } = signature.args;
|
|
35
|
+
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
36
|
+
if (!(0, viem_1.isAddressEqual)(authorized, generalAdapter1)) {
|
|
37
|
+
throw new index_js_1.BundlerErrors.UnexpectedSignature(authorized);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
type: "morphoSetAuthorizationWithSig",
|
|
41
|
+
args: [
|
|
42
|
+
{ authorizer: owner, authorized, isAuthorized, nonce, deadline },
|
|
43
|
+
signature.args.signature,
|
|
44
|
+
false /* skipRevert */,
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.getBlueAuthorizationAction = getBlueAuthorizationAction;
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
2
|
import type { Action } from "../../bundler/index.js";
|
|
3
|
-
import { type
|
|
4
|
-
interface
|
|
3
|
+
import { type PermitRequirementSignature } from "../../types/index.js";
|
|
4
|
+
interface GetTokenRequirementActionsParams {
|
|
5
5
|
asset: Address;
|
|
6
6
|
amount: bigint;
|
|
7
7
|
recipient: Address;
|
|
8
|
-
requirementSignature
|
|
9
|
-
args: PermitArgs;
|
|
10
|
-
action: PermitAction | Permit2Action;
|
|
11
|
-
};
|
|
8
|
+
requirementSignature?: PermitRequirementSignature;
|
|
12
9
|
}
|
|
13
10
|
/**
|
|
14
|
-
* Encodes the bundler actions that
|
|
15
|
-
*
|
|
11
|
+
* Encodes the bundler actions that pull the asset to `recipient`, optionally consuming a
|
|
12
|
+
* pre-signed permit / permit2 requirement first.
|
|
16
13
|
*
|
|
17
14
|
* Permit2 path emits `approve2` + `transferFrom2`; classic permit path emits `permit` +
|
|
18
|
-
* `erc20TransferFrom`.
|
|
19
|
-
* `
|
|
20
|
-
*
|
|
15
|
+
* `erc20TransferFrom`. When no signature is provided, the function emits a plain
|
|
16
|
+
* `erc20TransferFrom` against an existing ERC-20 allowance.
|
|
17
|
+
*
|
|
18
|
+
* The signed `asset` and `amount` must match the pulled `asset` and `amount` exactly, otherwise
|
|
19
|
+
* the function throws so the caller does not silently spend a wider-than-expected approval.
|
|
21
20
|
*
|
|
22
21
|
* @param params.asset - The ERC-20 to pull.
|
|
23
22
|
* @param params.amount - The amount to pull, in the asset's smallest unit.
|
|
24
23
|
* @param params.recipient - The address that receives the transfer.
|
|
25
|
-
* @param params.requirementSignature -
|
|
26
|
-
* @returns
|
|
24
|
+
* @param params.requirementSignature - Optional signed permit / permit2 to apply before the transfer.
|
|
25
|
+
* @returns Bundler `Action`s needed to pull the token.
|
|
27
26
|
* @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
|
|
28
27
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
29
28
|
* @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
|
|
@@ -31,7 +30,7 @@ interface GetRequirementsActionParams {
|
|
|
31
30
|
* ```ts
|
|
32
31
|
* import { createWalletClient, http } from "viem";
|
|
33
32
|
* import { mainnet } from "viem/chains";
|
|
34
|
-
* import {
|
|
33
|
+
* import { getTokenRequirementActions } from "@morpho-org/morpho-sdk";
|
|
35
34
|
*
|
|
36
35
|
* const walletClient = createWalletClient({
|
|
37
36
|
* chain: mainnet,
|
|
@@ -39,10 +38,10 @@ interface GetRequirementsActionParams {
|
|
|
39
38
|
* account: borrower,
|
|
40
39
|
* });
|
|
41
40
|
*
|
|
42
|
-
* // `requirement` comes from
|
|
41
|
+
* // `requirement` comes from a requirement helper; signing produces a `RequirementSignature`.
|
|
43
42
|
* const requirementSignature = await requirement.sign(walletClient, borrower);
|
|
44
43
|
*
|
|
45
|
-
* const actions =
|
|
44
|
+
* const actions = getTokenRequirementActions({
|
|
46
45
|
* asset: loanToken,
|
|
47
46
|
* amount: 1_000_000n,
|
|
48
47
|
* recipient: generalAdapter1,
|
|
@@ -51,7 +50,8 @@ interface GetRequirementsActionParams {
|
|
|
51
50
|
* // actions satisfies Action[]
|
|
52
51
|
* // - permit2 path: [{ type: "approve2", ... }, { type: "transferFrom2", ... }]
|
|
53
52
|
* // - classic permit path: [{ type: "permit", ... }, { type: "erc20TransferFrom", ... }]
|
|
53
|
+
* // - no signature: [{ type: "erc20TransferFrom", ... }]
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
|
-
export declare const
|
|
56
|
+
export declare const getTokenRequirementActions: ({ asset, amount, recipient, requirementSignature, }: GetTokenRequirementActionsParams) => Action[];
|
|
57
57
|
export {};
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getTokenRequirementActions = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const index_js_1 = require("../../types/index.js");
|
|
6
6
|
/**
|
|
7
|
-
* Encodes the bundler actions that
|
|
8
|
-
*
|
|
7
|
+
* Encodes the bundler actions that pull the asset to `recipient`, optionally consuming a
|
|
8
|
+
* pre-signed permit / permit2 requirement first.
|
|
9
9
|
*
|
|
10
10
|
* Permit2 path emits `approve2` + `transferFrom2`; classic permit path emits `permit` +
|
|
11
|
-
* `erc20TransferFrom`.
|
|
12
|
-
* `
|
|
13
|
-
*
|
|
11
|
+
* `erc20TransferFrom`. When no signature is provided, the function emits a plain
|
|
12
|
+
* `erc20TransferFrom` against an existing ERC-20 allowance.
|
|
13
|
+
*
|
|
14
|
+
* The signed `asset` and `amount` must match the pulled `asset` and `amount` exactly, otherwise
|
|
15
|
+
* the function throws so the caller does not silently spend a wider-than-expected approval.
|
|
14
16
|
*
|
|
15
17
|
* @param params.asset - The ERC-20 to pull.
|
|
16
18
|
* @param params.amount - The amount to pull, in the asset's smallest unit.
|
|
17
19
|
* @param params.recipient - The address that receives the transfer.
|
|
18
|
-
* @param params.requirementSignature -
|
|
19
|
-
* @returns
|
|
20
|
+
* @param params.requirementSignature - Optional signed permit / permit2 to apply before the transfer.
|
|
21
|
+
* @returns Bundler `Action`s needed to pull the token.
|
|
20
22
|
* @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
|
|
21
23
|
* @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
|
|
22
24
|
* @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
|
|
@@ -24,7 +26,7 @@ const index_js_1 = require("../../types/index.js");
|
|
|
24
26
|
* ```ts
|
|
25
27
|
* import { createWalletClient, http } from "viem";
|
|
26
28
|
* import { mainnet } from "viem/chains";
|
|
27
|
-
* import {
|
|
29
|
+
* import { getTokenRequirementActions } from "@morpho-org/morpho-sdk";
|
|
28
30
|
*
|
|
29
31
|
* const walletClient = createWalletClient({
|
|
30
32
|
* chain: mainnet,
|
|
@@ -32,10 +34,10 @@ const index_js_1 = require("../../types/index.js");
|
|
|
32
34
|
* account: borrower,
|
|
33
35
|
* });
|
|
34
36
|
*
|
|
35
|
-
* // `requirement` comes from
|
|
37
|
+
* // `requirement` comes from a requirement helper; signing produces a `RequirementSignature`.
|
|
36
38
|
* const requirementSignature = await requirement.sign(walletClient, borrower);
|
|
37
39
|
*
|
|
38
|
-
* const actions =
|
|
40
|
+
* const actions = getTokenRequirementActions({
|
|
39
41
|
* asset: loanToken,
|
|
40
42
|
* amount: 1_000_000n,
|
|
41
43
|
* recipient: generalAdapter1,
|
|
@@ -44,12 +46,23 @@ const index_js_1 = require("../../types/index.js");
|
|
|
44
46
|
* // actions satisfies Action[]
|
|
45
47
|
* // - permit2 path: [{ type: "approve2", ... }, { type: "transferFrom2", ... }]
|
|
46
48
|
* // - classic permit path: [{ type: "permit", ... }, { type: "erc20TransferFrom", ... }]
|
|
49
|
+
* // - no signature: [{ type: "erc20TransferFrom", ... }]
|
|
47
50
|
* ```
|
|
48
51
|
*/
|
|
49
|
-
const
|
|
52
|
+
const getTokenRequirementActions = ({ asset, amount, recipient, requirementSignature, }) => {
|
|
53
|
+
if (requirementSignature == null) {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
type: "erc20TransferFrom",
|
|
57
|
+
args: [asset, amount, recipient, false /* skipRevert */],
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
50
61
|
if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, asset)) {
|
|
51
62
|
throw new index_js_1.DepositAssetMismatchError(asset, requirementSignature.args.asset);
|
|
52
63
|
}
|
|
64
|
+
// Permit2 and ERC-2612 overwrite the previous allowance with the signed amount.
|
|
65
|
+
// It must exactly cover the transfer: less would fail, more would leave residual allowance.
|
|
53
66
|
if (requirementSignature.args.amount !== amount) {
|
|
54
67
|
throw new index_js_1.DepositAmountMismatchError(amount, requirementSignature.args.amount);
|
|
55
68
|
}
|
|
@@ -99,4 +112,4 @@ const getRequirementsAction = ({ asset, amount, recipient, requirementSignature,
|
|
|
99
112
|
},
|
|
100
113
|
];
|
|
101
114
|
};
|
|
102
|
-
exports.
|
|
115
|
+
exports.getTokenRequirementActions = getTokenRequirementActions;
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./getBlueAuthorizationAction.js"), exports);
|
|
18
|
+
__exportStar(require("./getTokenRequirementActions.js"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import { type DepositAmountArgs, type Metadata, type
|
|
2
|
+
import { type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction, type VaultV1DepositAction } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link vaultV1Deposit}. */
|
|
4
4
|
export interface VaultV1DepositParams {
|
|
5
5
|
vault: {
|
|
@@ -10,7 +10,7 @@ export interface VaultV1DepositParams {
|
|
|
10
10
|
args: DepositAmountArgs & {
|
|
11
11
|
maxSharePrice: bigint;
|
|
12
12
|
recipient: Address;
|
|
13
|
-
requirementSignature?:
|
|
13
|
+
requirementSignature?: PermitRequirementSignature;
|
|
14
14
|
};
|
|
15
15
|
metadata?: Metadata;
|
|
16
16
|
}
|
|
@@ -33,9 +33,7 @@ export interface VaultV1DepositParams {
|
|
|
33
33
|
* @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
|
|
34
34
|
* protection enforced on-chain by `GeneralAdapter1`).
|
|
35
35
|
* @param params.args.recipient - Address that receives the minted vault shares.
|
|
36
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
37
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
38
|
-
* approved `GeneralAdapter1`.
|
|
36
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
39
37
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
40
38
|
* deposit. Requires the vault asset to be the chain's wNative.
|
|
41
39
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -48,12 +46,12 @@ export interface VaultV1DepositParams {
|
|
|
48
46
|
* configured wNative.
|
|
49
47
|
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
50
48
|
* asset is not the chain's wNative.
|
|
51
|
-
* @throws {DepositAssetMismatchError} from `
|
|
49
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
52
50
|
* `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
|
|
53
51
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
54
|
-
* @throws {DepositAmountMismatchError} from `
|
|
52
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
55
53
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
56
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
54
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
|
|
57
55
|
* Permit2 requirement signature is missing its expiration.
|
|
58
56
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
59
57
|
* @example
|
|
@@ -7,7 +7,7 @@ const viem_1 = require("viem");
|
|
|
7
7
|
const index_js_1 = require("../../bundler/index.js");
|
|
8
8
|
const index_js_2 = require("../../helpers/index.js");
|
|
9
9
|
const index_js_3 = require("../../types/index.js");
|
|
10
|
-
const
|
|
10
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
11
11
|
/**
|
|
12
12
|
* Prepares a deposit transaction for a VaultV1 (MetaMorpho) contract.
|
|
13
13
|
*
|
|
@@ -27,9 +27,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
27
27
|
* @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
|
|
28
28
|
* protection enforced on-chain by `GeneralAdapter1`).
|
|
29
29
|
* @param params.args.recipient - Address that receives the minted vault shares.
|
|
30
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
31
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
32
|
-
* approved `GeneralAdapter1`.
|
|
30
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
33
31
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
34
32
|
* deposit. Requires the vault asset to be the chain's wNative.
|
|
35
33
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -42,12 +40,12 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
42
40
|
* configured wNative.
|
|
43
41
|
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
44
42
|
* asset is not the chain's wNative.
|
|
45
|
-
* @throws {DepositAssetMismatchError} from `
|
|
43
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
46
44
|
* `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
|
|
47
45
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
48
|
-
* @throws {DepositAmountMismatchError} from `
|
|
46
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
49
47
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
50
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
48
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
|
|
51
49
|
* Permit2 requirement signature is missing its expiration.
|
|
52
50
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
53
51
|
* @example
|
|
@@ -95,20 +93,12 @@ const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args
|
|
|
95
93
|
});
|
|
96
94
|
}
|
|
97
95
|
if (amount > 0n) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
actions.push({
|
|
108
|
-
type: "erc20TransferFrom",
|
|
109
|
-
args: [asset, amount, generalAdapter1, false /* skipRevert */],
|
|
110
|
-
});
|
|
111
|
-
}
|
|
96
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
97
|
+
asset,
|
|
98
|
+
amount,
|
|
99
|
+
recipient: generalAdapter1,
|
|
100
|
+
requirementSignature,
|
|
101
|
+
}));
|
|
112
102
|
}
|
|
113
103
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
114
104
|
if (totalAssets === 0n) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import { type Metadata, type
|
|
2
|
+
import { type Metadata, type PermitRequirementSignature, type Transaction, type VaultV1MigrateToV2Action } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link vaultV1MigrateToV2}. */
|
|
4
4
|
export interface VaultV1MigrateToV2Params {
|
|
5
5
|
vault: {
|
|
@@ -21,7 +21,7 @@ export interface VaultV1MigrateToV2Params {
|
|
|
21
21
|
/** Receives the V2 vault shares. */
|
|
22
22
|
recipient: Address;
|
|
23
23
|
/** Pre-signed permit/permit2 approval for V1 share transfer. */
|
|
24
|
-
requirementSignature?:
|
|
24
|
+
requirementSignature?: PermitRequirementSignature;
|
|
25
25
|
};
|
|
26
26
|
metadata?: Metadata;
|
|
27
27
|
}
|
|
@@ -51,7 +51,7 @@ export interface VaultV1MigrateToV2Params {
|
|
|
51
51
|
* for the deposit leg).
|
|
52
52
|
* @param params.args.recipient - Address that receives the V2 vault shares.
|
|
53
53
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
|
|
54
|
-
* transfer.
|
|
54
|
+
* transfer.
|
|
55
55
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
56
56
|
* @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
|
|
57
57
|
* the typed `action` discriminator the simulation layer consumes.
|
|
@@ -59,11 +59,11 @@ export interface VaultV1MigrateToV2Params {
|
|
|
59
59
|
* @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
|
|
60
60
|
* @throws {NegativeMinSharePriceError} when `minSharePriceVaultV1 < 0n`.
|
|
61
61
|
* @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
|
|
62
|
-
* @throws {DepositAssetMismatchError} from `
|
|
62
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
63
63
|
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
64
|
-
* @throws {DepositAmountMismatchError} from `
|
|
64
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
65
65
|
* is provided and the signed amount differs from `args.shares`.
|
|
66
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
66
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
67
67
|
* signature is missing its expiration.
|
|
68
68
|
* @example
|
|
69
69
|
* ```ts
|
|
@@ -7,7 +7,7 @@ const viem_1 = require("viem");
|
|
|
7
7
|
const index_js_1 = require("../../bundler/index.js");
|
|
8
8
|
const index_js_2 = require("../../helpers/index.js");
|
|
9
9
|
const index_js_3 = require("../../types/index.js");
|
|
10
|
-
const
|
|
10
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
11
11
|
/**
|
|
12
12
|
* Prepares an atomic full-migration transaction from VaultV1 to VaultV2.
|
|
13
13
|
*
|
|
@@ -34,7 +34,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
34
34
|
* for the deposit leg).
|
|
35
35
|
* @param params.args.recipient - Address that receives the V2 vault shares.
|
|
36
36
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
|
|
37
|
-
* transfer.
|
|
37
|
+
* transfer.
|
|
38
38
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
39
39
|
* @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
|
|
40
40
|
* the typed `action` discriminator the simulation layer consumes.
|
|
@@ -42,11 +42,11 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
42
42
|
* @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
|
|
43
43
|
* @throws {NegativeMinSharePriceError} when `minSharePriceVaultV1 < 0n`.
|
|
44
44
|
* @throws {NonPositiveMaxSharePriceError} when `maxSharePriceVaultV2 <= 0n`.
|
|
45
|
-
* @throws {DepositAssetMismatchError} from `
|
|
45
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
46
46
|
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
47
|
-
* @throws {DepositAmountMismatchError} from `
|
|
47
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
48
48
|
* is provided and the signed amount differs from `args.shares`.
|
|
49
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
49
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
50
50
|
* signature is missing its expiration.
|
|
51
51
|
* @example
|
|
52
52
|
* ```ts
|
|
@@ -85,21 +85,13 @@ const vaultV1MigrateToV2 = ({ vault: { chainId, address: sourceVault, asset: sou
|
|
|
85
85
|
const actions = [];
|
|
86
86
|
// Transfer V1 shares from user to GA1.
|
|
87
87
|
// With a signature: permit/permit2 + transferFrom for the signed amount.
|
|
88
|
-
// Without:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
actions.push({
|
|
99
|
-
type: "erc20TransferFrom",
|
|
100
|
-
args: [sourceVault, shares, generalAdapter1, false /* skipRevert */],
|
|
101
|
-
});
|
|
102
|
-
}
|
|
88
|
+
// Without a signature: use ERC-20 transferFrom for the specified shares amount.
|
|
89
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
90
|
+
asset: sourceVault,
|
|
91
|
+
amount: shares,
|
|
92
|
+
recipient: generalAdapter1,
|
|
93
|
+
requirementSignature,
|
|
94
|
+
}));
|
|
103
95
|
// GA1 redeems its own shares (owner = GA1, no allowance check).
|
|
104
96
|
actions.push({
|
|
105
97
|
type: "erc4626Redeem",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import { type DepositAmountArgs, type Metadata, type
|
|
2
|
+
import { type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction, type VaultV2DepositAction } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link vaultV2Deposit}. */
|
|
4
4
|
export interface VaultV2DepositParams {
|
|
5
5
|
vault: {
|
|
@@ -10,7 +10,7 @@ export interface VaultV2DepositParams {
|
|
|
10
10
|
args: DepositAmountArgs & {
|
|
11
11
|
maxSharePrice: bigint;
|
|
12
12
|
recipient: Address;
|
|
13
|
-
requirementSignature?:
|
|
13
|
+
requirementSignature?: PermitRequirementSignature;
|
|
14
14
|
};
|
|
15
15
|
metadata?: Metadata;
|
|
16
16
|
}
|
|
@@ -33,9 +33,7 @@ export interface VaultV2DepositParams {
|
|
|
33
33
|
* @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
|
|
34
34
|
* protection enforced on-chain by `GeneralAdapter1`).
|
|
35
35
|
* @param params.args.recipient - Address that receives the minted vault shares.
|
|
36
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
37
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
38
|
-
* approved `GeneralAdapter1`.
|
|
36
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
39
37
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
40
38
|
* deposit. Requires the vault asset to be the chain's wNative.
|
|
41
39
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -48,12 +46,12 @@ export interface VaultV2DepositParams {
|
|
|
48
46
|
* configured wNative.
|
|
49
47
|
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
50
48
|
* asset is not the chain's wNative.
|
|
51
|
-
* @throws {DepositAssetMismatchError} from `
|
|
49
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
52
50
|
* `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
|
|
53
51
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
54
|
-
* @throws {DepositAmountMismatchError} from `
|
|
52
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
55
53
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
56
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
54
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
|
|
57
55
|
* Permit2 requirement signature is missing its expiration.
|
|
58
56
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
59
57
|
* @example
|
|
@@ -7,7 +7,7 @@ const viem_1 = require("viem");
|
|
|
7
7
|
const index_js_1 = require("../../bundler/index.js");
|
|
8
8
|
const index_js_2 = require("../../helpers/index.js");
|
|
9
9
|
const index_js_3 = require("../../types/index.js");
|
|
10
|
-
const
|
|
10
|
+
const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequirementActions.js");
|
|
11
11
|
/**
|
|
12
12
|
* Prepares a deposit transaction for a VaultV2 contract.
|
|
13
13
|
*
|
|
@@ -27,9 +27,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
27
27
|
* @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
|
|
28
28
|
* protection enforced on-chain by `GeneralAdapter1`).
|
|
29
29
|
* @param params.args.recipient - Address that receives the minted vault shares.
|
|
30
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
31
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
32
|
-
* approved `GeneralAdapter1`.
|
|
30
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
33
31
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
34
32
|
* deposit. Requires the vault asset to be the chain's wNative.
|
|
35
33
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -42,12 +40,12 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
42
40
|
* configured wNative.
|
|
43
41
|
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
44
42
|
* asset is not the chain's wNative.
|
|
45
|
-
* @throws {DepositAssetMismatchError} from `
|
|
43
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
46
44
|
* `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
|
|
47
45
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
48
|
-
* @throws {DepositAmountMismatchError} from `
|
|
46
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `amount > 0n` and
|
|
49
47
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
50
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
48
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when `amount > 0n` and a
|
|
51
49
|
* Permit2 requirement signature is missing its expiration.
|
|
52
50
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
53
51
|
* @example
|
|
@@ -95,20 +93,12 @@ const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args
|
|
|
95
93
|
});
|
|
96
94
|
}
|
|
97
95
|
if (amount > 0n) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
actions.push({
|
|
108
|
-
type: "erc20TransferFrom",
|
|
109
|
-
args: [asset, amount, generalAdapter1, false /* skipRevert */],
|
|
110
|
-
});
|
|
111
|
-
}
|
|
96
|
+
actions.push(...(0, getTokenRequirementActions_js_1.getTokenRequirementActions)({
|
|
97
|
+
asset,
|
|
98
|
+
amount,
|
|
99
|
+
recipient: generalAdapter1,
|
|
100
|
+
requirementSignature,
|
|
101
|
+
}));
|
|
112
102
|
}
|
|
113
103
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
114
104
|
if (totalAssets === 0n) {
|
package/lib/cjs/addresses.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { AddressLabel, ChainAddresses, ChainDeployments, } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { addresses, addressesRegistry, convexWrapperTokens, deployments, erc20WrapperTokens, getChainAddresses, getPermissionedCoinbaseTokens, getUnwrappedToken, NATIVE_ADDRESS, permissionedBackedTokens, permissionedCoinbaseTokens, permissionedWrapperTokens, registerCustomAddresses, unwrappedTokensMapping, } from "@morpho-org/blue-sdk";
|
|
1
|
+
export type { AddressLabel, AddressRegistry, ChainAddresses, ChainDeployments, DeploymentRegistry, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { addresses, addressesRegistry, convexWrapperTokens, deployments, erc20WrapperTokens, getChainAddress, getChainAddresses, getPermissionedCoinbaseTokens, getUnwrappedToken, NATIVE_ADDRESS, permissionedBackedTokens, permissionedCoinbaseTokens, permissionedWrapperTokens, registerCustomAddresses, unwrappedTokensMapping, } from "@morpho-org/blue-sdk";
|
package/lib/cjs/addresses.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unwrappedTokensMapping = exports.registerCustomAddresses = exports.permissionedWrapperTokens = exports.permissionedCoinbaseTokens = exports.permissionedBackedTokens = exports.NATIVE_ADDRESS = exports.getUnwrappedToken = exports.getPermissionedCoinbaseTokens = exports.getChainAddresses = exports.erc20WrapperTokens = exports.deployments = exports.convexWrapperTokens = exports.addressesRegistry = exports.addresses = void 0;
|
|
3
|
+
exports.unwrappedTokensMapping = exports.registerCustomAddresses = exports.permissionedWrapperTokens = exports.permissionedCoinbaseTokens = exports.permissionedBackedTokens = exports.NATIVE_ADDRESS = exports.getUnwrappedToken = exports.getPermissionedCoinbaseTokens = exports.getChainAddresses = exports.getChainAddress = exports.erc20WrapperTokens = exports.deployments = exports.convexWrapperTokens = exports.addressesRegistry = exports.addresses = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "addresses", { enumerable: true, get: function () { return blue_sdk_1.addresses; } });
|
|
6
6
|
Object.defineProperty(exports, "addressesRegistry", { enumerable: true, get: function () { return blue_sdk_1.addressesRegistry; } });
|
|
7
7
|
Object.defineProperty(exports, "convexWrapperTokens", { enumerable: true, get: function () { return blue_sdk_1.convexWrapperTokens; } });
|
|
8
8
|
Object.defineProperty(exports, "deployments", { enumerable: true, get: function () { return blue_sdk_1.deployments; } });
|
|
9
9
|
Object.defineProperty(exports, "erc20WrapperTokens", { enumerable: true, get: function () { return blue_sdk_1.erc20WrapperTokens; } });
|
|
10
|
+
Object.defineProperty(exports, "getChainAddress", { enumerable: true, get: function () { return blue_sdk_1.getChainAddress; } });
|
|
10
11
|
Object.defineProperty(exports, "getChainAddresses", { enumerable: true, get: function () { return blue_sdk_1.getChainAddresses; } });
|
|
11
12
|
Object.defineProperty(exports, "getPermissionedCoinbaseTokens", { enumerable: true, get: function () { return blue_sdk_1.getPermissionedCoinbaseTokens; } });
|
|
12
13
|
Object.defineProperty(exports, "getUnwrappedToken", { enumerable: true, get: function () { return blue_sdk_1.getUnwrappedToken; } });
|