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