@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,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRepayFunding = void 0;
|
|
4
|
+
const index_js_1 = require("../../types/index.js");
|
|
5
|
+
/**
|
|
6
|
+
* Resolves and validates the repay funding envelope shared by `blueRepay` and
|
|
7
|
+
* `blueRepayWithdrawCollateral`.
|
|
8
|
+
*
|
|
9
|
+
* Encode-only and synchronous — reads no on-chain state and does no amount arithmetic beyond
|
|
10
|
+
* deriving the bundle values from the pre-resolved args (the entity layer resolves the amounts
|
|
11
|
+
* upstream). Runs the shared mode/amount guards, discriminates assets vs shares mode on
|
|
12
|
+
* `shares > 0n`, then validates the funding so the assembled bundle neither strands over-pulled
|
|
13
|
+
* tokens nor under-funds the repay:
|
|
14
|
+
*
|
|
15
|
+
* - **assets mode** (`shares` `0n`): repays `transferAmount` (`= amount + nativeAmount`, additive
|
|
16
|
+
* like `blueSupply`); ERC-20 pulled = `amount`.
|
|
17
|
+
* - **shares mode** (`shares > 0n`): repays exact `shares`; ERC-20 pulled = `transferAmount` (already
|
|
18
|
+
* net of native).
|
|
19
|
+
*
|
|
20
|
+
* Single source of truth for the funding math both repay builders depend on — a correctness fix here
|
|
21
|
+
* applies to both paths instead of risking a silent divergence between two copies.
|
|
22
|
+
*
|
|
23
|
+
* @param input - The pre-resolved repay amounts plus the repay `maxSharePrice`.
|
|
24
|
+
* @param marketId - Market id used to tag the thrown errors.
|
|
25
|
+
* @returns `{ isSharesMode, repayAssets, repayShares, erc20Amount }` — the mode discriminator and the
|
|
26
|
+
* amounts the repay builders assemble the bundle from.
|
|
27
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
28
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
29
|
+
* @throws {NonPositiveRepayAmountError} when `amount` or `shares` is negative, when in assets mode and
|
|
30
|
+
* the repaid assets are `<= 0n`, or when in shares mode and `transferAmount` is negative or the total
|
|
31
|
+
* funding (`transferAmount + nativeAmount`) is `<= 0n`.
|
|
32
|
+
* @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`.
|
|
33
|
+
* @throws {TransferAmountNotEqualToAssetsError} when in assets mode and
|
|
34
|
+
* `transferAmount !== amount + nativeAmount`.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
const resolveRepayFunding = ({ amount, shares, nativeAmount, transferAmount, maxSharePrice, }, marketId) => {
|
|
38
|
+
if (maxSharePrice <= 0n) {
|
|
39
|
+
throw new index_js_1.NonPositiveRepayMaxSharePriceError(marketId);
|
|
40
|
+
}
|
|
41
|
+
if (nativeAmount < 0n) {
|
|
42
|
+
throw new index_js_1.NegativeNativeAmountError(nativeAmount);
|
|
43
|
+
}
|
|
44
|
+
if (amount < 0n || shares < 0n) {
|
|
45
|
+
throw new index_js_1.NonPositiveRepayAmountError(marketId);
|
|
46
|
+
}
|
|
47
|
+
if (amount > 0n && shares > 0n) {
|
|
48
|
+
throw new index_js_1.MutuallyExclusiveRepayAmountsError(marketId);
|
|
49
|
+
}
|
|
50
|
+
// Shares mode repays an exact share count and pulls `transferAmount` ERC-20
|
|
51
|
+
// (already net of native), skimming the residual. Assets mode repays
|
|
52
|
+
// `transferAmount` (= amount + native, additive) and pulls `amount`.
|
|
53
|
+
const isSharesMode = shares > 0n;
|
|
54
|
+
const repayAssets = isSharesMode ? 0n : transferAmount;
|
|
55
|
+
const repayShares = shares;
|
|
56
|
+
const erc20Amount = isSharesMode ? transferAmount : amount;
|
|
57
|
+
// Validate the pre-resolved funding. Assets mode is additive like `blueSupply`:
|
|
58
|
+
// the ERC-20 pulled (`amount`) plus the wrapped `nativeAmount` must equal the
|
|
59
|
+
// assets repaid, and the total must be positive — so the adapter neither strands
|
|
60
|
+
// over-pulled tokens nor under-funds the repay. Shares mode pulls `transferAmount`
|
|
61
|
+
// ERC-20 (0 on a fully-native repay) and wraps `nativeAmount`; the bundle must
|
|
62
|
+
// fund the repay with a non-negative transfer and a positive total.
|
|
63
|
+
if (isSharesMode) {
|
|
64
|
+
if (transferAmount < 0n || transferAmount + nativeAmount <= 0n) {
|
|
65
|
+
throw new index_js_1.NonPositiveRepayAmountError(marketId);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (transferAmount !== amount + nativeAmount) {
|
|
70
|
+
throw new index_js_1.TransferAmountNotEqualToAssetsError({
|
|
71
|
+
transferAmount,
|
|
72
|
+
assets: amount + nativeAmount,
|
|
73
|
+
market: marketId,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (repayAssets <= 0n) {
|
|
77
|
+
throw new index_js_1.NonPositiveRepayAmountError(marketId);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { isSharesMode, repayAssets, repayShares, erc20Amount };
|
|
81
|
+
};
|
|
82
|
+
exports.resolveRepayFunding = resolveRepayFunding;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueSupplyAction, type DepositAmountArgs, type Metadata, type
|
|
3
|
+
import { type BlueSupplyAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupply}. */
|
|
5
5
|
export interface BlueSupplyParams {
|
|
6
6
|
market: {
|
|
@@ -8,10 +8,12 @@ export interface BlueSupplyParams {
|
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
9
|
};
|
|
10
10
|
args: DepositAmountArgs & {
|
|
11
|
+
/** Address whose Morpho supply position is credited. */
|
|
11
12
|
onBehalf: Address;
|
|
12
13
|
/** Maximum supply share price (in ray). Slippage protection against inflation attacks. */
|
|
13
14
|
maxSharePrice: bigint;
|
|
14
|
-
|
|
15
|
+
/** Optional pre-signed permit/permit2 approval for the loan-token transfer. */
|
|
16
|
+
requirementSignature?: PermitRequirementSignature;
|
|
15
17
|
};
|
|
16
18
|
metadata?: Metadata;
|
|
17
19
|
}
|
|
@@ -34,9 +36,7 @@ export interface BlueSupplyParams {
|
|
|
34
36
|
* protection.
|
|
35
37
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
36
38
|
* supply. Requires the loan token to be the chain's wNative.
|
|
37
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
38
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
39
|
-
* approved `GeneralAdapter1`.
|
|
39
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
40
40
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
41
|
* @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
|
|
42
42
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -47,9 +47,9 @@ export interface BlueSupplyParams {
|
|
|
47
47
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
48
48
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
49
49
|
* the chain's wNative.
|
|
50
|
-
* @throws {DepositAssetMismatchError} from `
|
|
50
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
51
51
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
52
|
-
* @throws {DepositAmountMismatchError} from `
|
|
52
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
53
53
|
* is provided and the signed amount differs from `args.amount`.
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blueSupply = void 0;
|
|
4
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
5
|
const index_js_1 = require("../../bundler/index.js");
|
|
7
6
|
const index_js_2 = require("../../helpers/index.js");
|
|
8
7
|
const index_js_3 = require("../../types/index.js");
|
|
9
|
-
const
|
|
8
|
+
const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
|
|
10
9
|
/**
|
|
11
10
|
* Prepares a loan-asset supply transaction for a Morpho Blue market.
|
|
12
11
|
*
|
|
@@ -26,9 +25,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
26
25
|
* protection.
|
|
27
26
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
28
27
|
* supply. Requires the loan token to be the chain's wNative.
|
|
29
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
30
|
-
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
31
|
-
* approved `GeneralAdapter1`.
|
|
28
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
32
29
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
33
30
|
* @returns A deep-frozen `Transaction<BlueSupplyAction>` with `to`, `value`, `data`, and the
|
|
34
31
|
* typed `action` discriminator the simulation layer consumes.
|
|
@@ -39,9 +36,9 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
39
36
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
40
37
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
41
38
|
* the chain's wNative.
|
|
42
|
-
* @throws {DepositAssetMismatchError} from `
|
|
39
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
43
40
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
44
|
-
* @throws {DepositAmountMismatchError} from `
|
|
41
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
45
42
|
* is provided and the signed amount differs from `args.amount`.
|
|
46
43
|
* @example
|
|
47
44
|
* ```ts
|
|
@@ -72,34 +69,13 @@ const blueSupply = ({ market: { chainId, marketParams }, args: { amount = 0n, on
|
|
|
72
69
|
if (totalAssets === 0n) {
|
|
73
70
|
throw new index_js_3.ZeroSupplyAmountError(marketParams.id);
|
|
74
71
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}, {
|
|
83
|
-
type: "wrapNative",
|
|
84
|
-
args: [nativeAmount, generalAdapter1, false],
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (amount > 0n) {
|
|
88
|
-
if (requirementSignature) {
|
|
89
|
-
actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
|
|
90
|
-
asset: marketParams.loanToken,
|
|
91
|
-
amount,
|
|
92
|
-
recipient: generalAdapter1,
|
|
93
|
-
requirementSignature,
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
actions.push({
|
|
98
|
-
type: "erc20TransferFrom",
|
|
99
|
-
args: [marketParams.loanToken, amount, generalAdapter1, false],
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
72
|
+
const actions = (0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
|
|
73
|
+
chainId,
|
|
74
|
+
asset: marketParams.loanToken,
|
|
75
|
+
erc20Amount: amount,
|
|
76
|
+
nativeAmount: nativeAmount ?? 0n,
|
|
77
|
+
requirementSignature,
|
|
78
|
+
});
|
|
103
79
|
actions.push({
|
|
104
80
|
type: "morphoSupply",
|
|
105
81
|
args: [marketParams, totalAssets, 0n, maxSharePrice, onBehalf, [], false],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type
|
|
3
|
+
import { type BlueSupplyCollateralAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateral}. */
|
|
5
5
|
export interface BlueSupplyCollateralParams {
|
|
6
6
|
market: {
|
|
@@ -8,8 +8,10 @@ export interface BlueSupplyCollateralParams {
|
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
9
9
|
};
|
|
10
10
|
args: DepositAmountArgs & {
|
|
11
|
+
/** Address whose Morpho collateral position is credited. */
|
|
11
12
|
onBehalf: Address;
|
|
12
|
-
|
|
13
|
+
/** Optional pre-signed permit/permit2 approval for the collateral transfer. */
|
|
14
|
+
requirementSignature?: PermitRequirementSignature;
|
|
13
15
|
};
|
|
14
16
|
metadata?: Metadata;
|
|
15
17
|
}
|
|
@@ -27,9 +29,7 @@ export interface BlueSupplyCollateralParams {
|
|
|
27
29
|
* @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
|
|
28
30
|
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
29
31
|
* @param params.args.onBehalf - Address whose Morpho position is credited with the collateral.
|
|
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`.
|
|
32
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
33
33
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
34
34
|
* supply. Requires the collateral token to be the chain's wNative.
|
|
35
35
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -41,11 +41,11 @@ export interface BlueSupplyCollateralParams {
|
|
|
41
41
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
42
42
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
43
43
|
* token is not the chain's wNative.
|
|
44
|
-
* @throws {DepositAssetMismatchError} from `
|
|
44
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
45
45
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
46
|
-
* @throws {DepositAmountMismatchError} from `
|
|
46
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
47
47
|
* is provided and the signed amount differs from `args.amount`.
|
|
48
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
48
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
49
49
|
* signature is missing its expiration.
|
|
50
50
|
* @example
|
|
51
51
|
* ```ts
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blueSupplyCollateral = void 0;
|
|
4
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
5
|
const index_js_1 = require("../../bundler/index.js");
|
|
7
6
|
const index_js_2 = require("../../helpers/index.js");
|
|
8
7
|
const index_js_3 = require("../../types/index.js");
|
|
9
|
-
const
|
|
8
|
+
const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
|
|
10
9
|
/**
|
|
11
10
|
* Prepares a supply-collateral transaction for a Morpho Blue market.
|
|
12
11
|
*
|
|
@@ -21,9 +20,7 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
21
20
|
* @param params.args.amount - Amount of ERC-20 collateral to supply. At least one of `amount` or
|
|
22
21
|
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
23
22
|
* @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`.
|
|
23
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval.
|
|
27
24
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
28
25
|
* supply. Requires the collateral token to be the chain's wNative.
|
|
29
26
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -35,11 +32,11 @@ const getRequirementsAction_js_1 = require("../requirements/getRequirementsActio
|
|
|
35
32
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
36
33
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
37
34
|
* token is not the chain's wNative.
|
|
38
|
-
* @throws {DepositAssetMismatchError} from `
|
|
35
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
39
36
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
40
|
-
* @throws {DepositAmountMismatchError} from `
|
|
37
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
41
38
|
* is provided and the signed amount differs from `args.amount`.
|
|
42
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
39
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
43
40
|
* signature is missing its expiration.
|
|
44
41
|
* @example
|
|
45
42
|
* ```ts
|
|
@@ -63,34 +60,13 @@ const blueSupplyCollateral = ({ market: { chainId, marketParams }, args: { amoun
|
|
|
63
60
|
if (totalCollateral === 0n) {
|
|
64
61
|
throw new index_js_3.ZeroCollateralAmountError(marketParams.id);
|
|
65
62
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, {
|
|
74
|
-
type: "wrapNative",
|
|
75
|
-
args: [nativeAmount, generalAdapter1, false],
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (amount > 0n) {
|
|
79
|
-
if (requirementSignature) {
|
|
80
|
-
actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
|
|
81
|
-
asset: marketParams.collateralToken,
|
|
82
|
-
amount,
|
|
83
|
-
recipient: generalAdapter1,
|
|
84
|
-
requirementSignature,
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
actions.push({
|
|
89
|
-
type: "erc20TransferFrom",
|
|
90
|
-
args: [marketParams.collateralToken, amount, generalAdapter1, false],
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
63
|
+
const actions = (0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
|
|
64
|
+
chainId,
|
|
65
|
+
asset: marketParams.collateralToken,
|
|
66
|
+
erc20Amount: amount,
|
|
67
|
+
nativeAmount: nativeAmount ?? 0n,
|
|
68
|
+
requirementSignature,
|
|
69
|
+
});
|
|
94
70
|
actions.push({
|
|
95
71
|
type: "morphoSupplyCollateral",
|
|
96
72
|
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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>>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blueSupplyCollateralBorrow = void 0;
|
|
4
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
5
|
const index_js_1 = require("../../bundler/index.js");
|
|
7
6
|
const index_js_2 = require("../../helpers/index.js");
|
|
8
7
|
const index_js_3 = require("../../types/index.js");
|
|
9
|
-
const
|
|
8
|
+
const getBlueAuthorizationAction_js_1 = require("../signatures/getBlueAuthorizationAction.js");
|
|
9
|
+
const buildAssetFundingActions_js_1 = require("./buildAssetFundingActions.js");
|
|
10
10
|
const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
11
11
|
/**
|
|
12
12
|
* Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
|
|
@@ -35,6 +35,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
35
35
|
* collateral supply. Requires the collateral token to be the chain's wNative.
|
|
36
36
|
* @param params.args.reallocations - Optional vault reallocations to execute between the supply
|
|
37
37
|
* and borrow legs, 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.
|
|
38
40
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
39
41
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
40
42
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
@@ -46,11 +48,11 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
46
48
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
47
49
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
48
50
|
* token is not the chain's wNative.
|
|
49
|
-
* @throws {DepositAssetMismatchError} from `
|
|
51
|
+
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
50
52
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
51
|
-
* @throws {DepositAmountMismatchError} from `
|
|
53
|
+
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
52
54
|
* is provided and the signed amount differs from `args.amount`.
|
|
53
|
-
* @throws {Permit2ExpirationMissingError} from `
|
|
55
|
+
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
54
56
|
* signature is missing its expiration.
|
|
55
57
|
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
56
58
|
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
@@ -79,7 +81,7 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
79
81
|
* // tx satisfies Readonly<Transaction<BlueSupplyCollateralBorrowAction>>
|
|
80
82
|
* ```
|
|
81
83
|
*/
|
|
82
|
-
const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, }, metadata, }) => {
|
|
84
|
+
const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }) => {
|
|
83
85
|
if (amount < 0n) {
|
|
84
86
|
throw new index_js_3.NonPositiveAssetAmountError(marketParams.collateralToken);
|
|
85
87
|
}
|
|
@@ -96,34 +98,17 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
96
98
|
if (totalCollateral === 0n) {
|
|
97
99
|
throw new index_js_3.ZeroCollateralAmountError(marketParams.id);
|
|
98
100
|
}
|
|
99
|
-
const { bundler3: { generalAdapter1, bundler3 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
100
101
|
const actions = [];
|
|
101
|
-
if (
|
|
102
|
-
(0,
|
|
103
|
-
actions.push({
|
|
104
|
-
type: "nativeTransfer",
|
|
105
|
-
args: [bundler3, generalAdapter1, nativeAmount, false],
|
|
106
|
-
}, {
|
|
107
|
-
type: "wrapNative",
|
|
108
|
-
args: [nativeAmount, generalAdapter1, false],
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (amount > 0n) {
|
|
112
|
-
if (requirementSignature) {
|
|
113
|
-
actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
|
|
114
|
-
asset: marketParams.collateralToken,
|
|
115
|
-
amount,
|
|
116
|
-
recipient: generalAdapter1,
|
|
117
|
-
requirementSignature,
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
actions.push({
|
|
122
|
-
type: "erc20TransferFrom",
|
|
123
|
-
args: [marketParams.collateralToken, amount, generalAdapter1, false],
|
|
124
|
-
});
|
|
125
|
-
}
|
|
102
|
+
if (authorizationSignature) {
|
|
103
|
+
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
126
104
|
}
|
|
105
|
+
actions.push(...(0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
|
|
106
|
+
chainId,
|
|
107
|
+
asset: marketParams.collateralToken,
|
|
108
|
+
erc20Amount: amount,
|
|
109
|
+
nativeAmount: nativeAmount ?? 0n,
|
|
110
|
+
requirementSignature,
|
|
111
|
+
}));
|
|
127
112
|
actions.push({
|
|
128
113
|
type: "morphoSupplyCollateral",
|
|
129
114
|
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
@@ -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>;
|