@morpho-org/morpho-sdk 5.5.0 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -7
- package/lib/cjs/abis.d.ts +15 -3
- package/lib/cjs/abis.js +15 -1
- package/lib/cjs/actions/blue/borrow.d.ts +21 -15
- package/lib/cjs/actions/blue/borrow.js +25 -18
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
- package/lib/cjs/actions/blue/refinance.d.ts +14 -7
- package/lib/cjs/actions/blue/refinance.js +18 -10
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
- package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
- package/lib/cjs/actions/blue/withdraw.js +23 -18
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +2 -2
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +2 -2
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -1
- package/lib/cjs/blue/abis.d.ts +2 -0
- package/lib/cjs/blue/abis.js +33 -0
- package/lib/cjs/blue/addresses.d.ts +2 -0
- package/lib/cjs/blue/addresses.js +19 -0
- package/lib/cjs/blue/constants.d.ts +1 -0
- package/lib/cjs/blue/constants.js +13 -0
- package/lib/cjs/blue/entities.d.ts +2 -0
- package/lib/cjs/blue/entities.js +37 -0
- package/lib/cjs/blue/errors.d.ts +2 -0
- package/lib/cjs/blue/errors.js +29 -0
- package/lib/cjs/blue/fetch.d.ts +1 -0
- package/lib/cjs/blue/fetch.js +33 -0
- package/lib/cjs/blue/types.d.ts +2 -0
- package/lib/cjs/blue/types.js +2 -0
- package/lib/cjs/blue/utils.d.ts +3 -0
- package/lib/cjs/blue/utils.js +29 -0
- package/lib/cjs/bundler/actions.d.ts +122 -3
- package/lib/cjs/bundler/actions.js +216 -7
- package/lib/cjs/bundler/types.d.ts +20 -0
- package/lib/cjs/constants.d.ts +37 -3
- package/lib/cjs/constants.js +41 -1
- package/lib/cjs/entities/blue/blue.d.ts +362 -71
- package/lib/cjs/entities/blue/blue.js +286 -52
- package/lib/cjs/entities/index.d.ts +64 -4
- package/lib/cjs/entities/index.js +37 -22
- package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
- package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +29 -16
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +1 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1300 -0
- package/lib/cjs/errors.d.ts +48 -3
- package/lib/cjs/errors.js +62 -1
- package/lib/cjs/fetch.d.ts +16 -1
- package/lib/cjs/fetch.js +24 -1
- package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
- package/lib/cjs/helpers/constant.d.ts +5 -3
- package/lib/cjs/helpers/constant.js +6 -4
- package/lib/cjs/helpers/index.d.ts +2 -2
- package/lib/cjs/helpers/index.js +6 -3
- package/lib/cjs/helpers/validate.d.ts +32 -16
- package/lib/cjs/helpers/validate.js +142 -29
- package/lib/cjs/midnight/abis.d.ts +1 -0
- package/lib/cjs/midnight/abis.js +8 -0
- package/lib/cjs/midnight/constants.d.ts +1 -0
- package/lib/cjs/midnight/constants.js +19 -0
- package/lib/cjs/midnight/entities.d.ts +2 -0
- package/lib/cjs/midnight/entities.js +11 -0
- package/lib/cjs/midnight/errors.d.ts +1 -0
- package/lib/cjs/midnight/errors.js +24 -0
- package/lib/cjs/midnight/fetch.d.ts +1 -0
- package/lib/cjs/midnight/fetch.js +9 -0
- package/lib/cjs/midnight/types.d.ts +1 -0
- package/lib/cjs/midnight/types.js +2 -0
- package/lib/cjs/midnight/utils.d.ts +1 -0
- package/lib/cjs/midnight/utils.js +17 -0
- package/lib/cjs/types/action.d.ts +12 -0
- package/lib/cjs/types/error.d.ts +224 -5
- package/lib/cjs/types/error.js +269 -7
- package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
- package/lib/cjs/types.d.ts +17 -2
- package/lib/cjs/utils.d.ts +31 -4
- package/lib/cjs/utils.js +44 -4
- package/lib/esm/abis.d.ts +15 -3
- package/lib/esm/abis.js +15 -3
- package/lib/esm/actions/blue/borrow.d.ts +21 -15
- package/lib/esm/actions/blue/borrow.js +26 -19
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
- package/lib/esm/actions/blue/refinance.d.ts +14 -7
- package/lib/esm/actions/blue/refinance.js +19 -11
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
- package/lib/esm/actions/blue/withdraw.d.ts +20 -13
- package/lib/esm/actions/blue/withdraw.js +24 -19
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +2 -2
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +2 -2
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -1
- package/lib/esm/blue/abis.d.ts +2 -0
- package/lib/esm/blue/abis.js +2 -0
- package/lib/esm/blue/addresses.d.ts +2 -0
- package/lib/esm/blue/addresses.js +1 -0
- package/lib/esm/blue/constants.d.ts +1 -0
- package/lib/esm/blue/constants.js +1 -0
- package/lib/esm/blue/entities.d.ts +2 -0
- package/lib/esm/blue/entities.js +1 -0
- package/lib/esm/blue/errors.d.ts +2 -0
- package/lib/esm/blue/errors.js +2 -0
- package/lib/esm/blue/fetch.d.ts +1 -0
- package/lib/esm/blue/fetch.js +1 -0
- package/lib/esm/blue/types.d.ts +2 -0
- package/lib/esm/blue/types.js +1 -0
- package/lib/esm/blue/utils.d.ts +3 -0
- package/lib/esm/blue/utils.js +2 -0
- package/lib/esm/bundler/actions.d.ts +122 -3
- package/lib/esm/bundler/actions.js +219 -10
- package/lib/esm/bundler/types.d.ts +20 -0
- package/lib/esm/constants.d.ts +37 -3
- package/lib/esm/constants.js +37 -3
- package/lib/esm/entities/blue/blue.d.ts +362 -71
- package/lib/esm/entities/blue/blue.js +289 -55
- package/lib/esm/entities/index.d.ts +64 -4
- package/lib/esm/entities/index.js +19 -3
- package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
- package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +32 -14
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +1 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1296 -0
- package/lib/esm/errors.d.ts +48 -3
- package/lib/esm/errors.js +48 -3
- package/lib/esm/fetch.d.ts +16 -1
- package/lib/esm/fetch.js +16 -1
- package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
- package/lib/esm/helpers/constant.d.ts +5 -3
- package/lib/esm/helpers/constant.js +5 -3
- package/lib/esm/helpers/index.d.ts +2 -2
- package/lib/esm/helpers/index.js +2 -2
- package/lib/esm/helpers/validate.d.ts +32 -16
- package/lib/esm/helpers/validate.js +143 -32
- package/lib/esm/midnight/abis.d.ts +1 -0
- package/lib/esm/midnight/abis.js +1 -0
- package/lib/esm/midnight/constants.d.ts +1 -0
- package/lib/esm/midnight/constants.js +1 -0
- package/lib/esm/midnight/entities.d.ts +2 -0
- package/lib/esm/midnight/entities.js +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -0
- package/lib/esm/midnight/errors.js +1 -0
- package/lib/esm/midnight/fetch.d.ts +1 -0
- package/lib/esm/midnight/fetch.js +1 -0
- package/lib/esm/midnight/types.d.ts +1 -0
- package/lib/esm/midnight/types.js +1 -0
- package/lib/esm/midnight/utils.d.ts +1 -0
- package/lib/esm/midnight/utils.js +1 -0
- package/lib/esm/types/action.d.ts +12 -0
- package/lib/esm/types/error.d.ts +224 -5
- package/lib/esm/types/error.js +253 -4
- package/lib/esm/types/sharedLiquidity.d.ts +72 -8
- package/lib/esm/types.d.ts +17 -2
- package/lib/esm/utils.d.ts +31 -4
- package/lib/esm/utils.js +31 -4
- package/package.json +23 -7
|
@@ -20,8 +20,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
20
20
|
* Bundle shape (callback contents depend on borrow mode):
|
|
21
21
|
*
|
|
22
22
|
* ```text
|
|
23
|
-
* // optional
|
|
24
|
-
* reallocateTo(
|
|
23
|
+
* // optional targetReallocations run first:
|
|
24
|
+
* reallocateTo(...) | reallocate(...) | allocateFromIdle(...),
|
|
25
25
|
*
|
|
26
26
|
* morphoSupplyCollateral(target, collateralAmount, user, [
|
|
27
27
|
* // omitted in collat-only mode
|
|
@@ -55,7 +55,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
55
55
|
* @param params.args.borrowShares - Borrow shares to repay on the source; exclusive with `borrowAssets`. Defaults to `0n`.
|
|
56
56
|
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
57
57
|
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
58
|
-
* @param params.args.targetReallocations -
|
|
58
|
+
* @param params.args.targetReallocations - Homogeneous Vault V1 or Vault V2 reallocations into the
|
|
59
|
+
* target, run before the supply leg. V1 fees add to `tx.value`; V2 penalties are paid in the target loan token.
|
|
59
60
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
60
61
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
61
62
|
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
@@ -64,8 +65,14 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
64
65
|
* repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
|
|
65
66
|
* @throws {NonPositiveInputError} when `collateralAmount <= 0n`, a repay leg has a non-positive
|
|
66
67
|
* `maxRepaySharePrice`, or any reallocation withdrawal amount is non-positive.
|
|
68
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
69
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
70
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
71
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
72
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
73
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
67
74
|
* @throws {NegativeInputError} when `borrowAssets`, `borrowShares`, `minBorrowSharePrice`,
|
|
68
|
-
* `maxRepaySharePrice`, or
|
|
75
|
+
* `maxRepaySharePrice`, a V1 fee, or a V2 penalty is negative.
|
|
69
76
|
* @throws {RefinanceSameMarketError} when source and target market ids are equal.
|
|
70
77
|
* @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
|
|
71
78
|
* @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
|
|
@@ -182,15 +189,15 @@ const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target
|
|
|
182
189
|
args: [sourceParams, collateralAmount, generalAdapter1, false],
|
|
183
190
|
});
|
|
184
191
|
const actions = [];
|
|
185
|
-
let reallocationFee = 0n;
|
|
186
192
|
if (authorizationSignature) {
|
|
187
193
|
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
188
194
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
195
|
+
const { actions: reallocationActions, fee: reallocationFee, penaltyAssets: reallocationPenaltyAssets, } = (0, buildReallocationActions_js_1.buildBlueReallocationActions)({
|
|
196
|
+
chainId,
|
|
197
|
+
reallocations: targetReallocations,
|
|
198
|
+
targetMarketParams: targetParams,
|
|
199
|
+
});
|
|
200
|
+
actions.push(...reallocationActions);
|
|
194
201
|
actions.push({
|
|
195
202
|
type: "morphoSupplyCollateral",
|
|
196
203
|
args: [targetParams, collateralAmount, user, callback, false],
|
|
@@ -213,6 +220,7 @@ const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target
|
|
|
213
220
|
maxRepaySharePrice,
|
|
214
221
|
user,
|
|
215
222
|
reallocationFee,
|
|
223
|
+
reallocationPenaltyAssets,
|
|
216
224
|
},
|
|
217
225
|
},
|
|
218
226
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type
|
|
3
|
-
import { type AuthorizationRequirementSignature, type BlueSupplyCollateralBorrowAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueReallocationPlan, type BlueSupplyCollateralBorrowAction, type DepositAmountArgs, type Metadata, type PermitRequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueSupplyCollateralBorrow}. */
|
|
5
5
|
export interface BlueSupplyCollateralBorrowParams {
|
|
6
6
|
market: {
|
|
@@ -18,8 +18,8 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
18
18
|
minSharePrice: bigint;
|
|
19
19
|
/** Optional pre-signed permit/permit2 approval for the collateral transfer. */
|
|
20
20
|
requirementSignature?: PermitRequirementSignature;
|
|
21
|
-
/** Vault reallocations to execute before borrowing
|
|
22
|
-
reallocations?:
|
|
21
|
+
/** Homogeneous Vault V1 or Vault V2 reallocations to execute before borrowing. */
|
|
22
|
+
reallocations?: BlueReallocationPlan;
|
|
23
23
|
/**
|
|
24
24
|
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
25
25
|
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
@@ -32,9 +32,13 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
32
32
|
/**
|
|
33
33
|
* Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
|
|
34
34
|
*
|
|
35
|
-
* Routed through bundler3: collateral
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* Routed through bundler3: collateral funding → `morphoSupplyCollateral` → optional Public
|
|
36
|
+
* Allocator calls → `morphoBorrow`. Each plan contains either V1 or V2 entries,
|
|
37
|
+
* never both. When `nativeAmount > 0`, native ETH is wrapped via
|
|
38
|
+
* `GeneralAdapter1.wrapNative()` before the supply leg. V1 fees add to
|
|
39
|
+
* `tx.value`; V2 penalties are paid in the target loan token and donated to the vaults. When the
|
|
40
|
+
* collateral and loan tokens match, one combined pull funds both collateral and penalties through
|
|
41
|
+
* `GeneralAdapter1`.
|
|
38
42
|
*
|
|
39
43
|
* Prerequisite: `GeneralAdapter1` must be authorized on Morpho to borrow on behalf of the user.
|
|
40
44
|
* Use `getRequirements()` on the entity to check and obtain the authorization transaction.
|
|
@@ -51,35 +55,40 @@ export interface BlueSupplyCollateralBorrowParams {
|
|
|
51
55
|
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
52
56
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
53
57
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
54
|
-
* collateral
|
|
58
|
+
* collateral funding. When collateral and loan tokens match, its amount includes V2 penalties.
|
|
55
59
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
56
60
|
* collateral supply. Requires the collateral token to be the chain's wNative.
|
|
57
|
-
* @param params.args.reallocations - Optional
|
|
58
|
-
*
|
|
61
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
62
|
+
* execute between the supply and borrow legs.
|
|
59
63
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
60
64
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
61
65
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
62
66
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
63
67
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
64
|
-
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or
|
|
65
|
-
*
|
|
68
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, a V1 fee, or a V2
|
|
69
|
+
* penalty is negative.
|
|
66
70
|
* @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
|
|
67
71
|
* zero, or any reallocation withdrawal amount is non-positive.
|
|
72
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
73
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
74
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
75
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
76
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
77
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
68
78
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
69
79
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
70
80
|
* token is not the chain's wNative.
|
|
71
81
|
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
72
82
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
73
83
|
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
74
|
-
* is provided and the signed amount differs from
|
|
84
|
+
* is provided and the signed amount differs from the total ERC-20 funding amount.
|
|
75
85
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
76
86
|
* signature is missing its expiration.
|
|
77
|
-
* @throws {EmptyReallocationWithdrawalsError}
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* reallocation withdrawals are not strictly sorted by market id.
|
|
87
|
+
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
88
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
89
|
+
* the target market.
|
|
90
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
91
|
+
* sorted by market id.
|
|
83
92
|
* @example
|
|
84
93
|
* ```ts
|
|
85
94
|
* import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blueSupplyCollateralBorrow = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const viem_1 = require("viem");
|
|
5
6
|
const index_js_1 = require("../../bundler/index.js");
|
|
6
7
|
const index_js_2 = require("../../helpers/index.js");
|
|
7
8
|
const index_js_3 = require("../../types/index.js");
|
|
@@ -11,9 +12,13 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
11
12
|
/**
|
|
12
13
|
* Prepares an atomic supply-collateral-and-borrow transaction for a Morpho Blue market.
|
|
13
14
|
*
|
|
14
|
-
* Routed through bundler3: collateral
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Routed through bundler3: collateral funding → `morphoSupplyCollateral` → optional Public
|
|
16
|
+
* Allocator calls → `morphoBorrow`. Each plan contains either V1 or V2 entries,
|
|
17
|
+
* never both. When `nativeAmount > 0`, native ETH is wrapped via
|
|
18
|
+
* `GeneralAdapter1.wrapNative()` before the supply leg. V1 fees add to
|
|
19
|
+
* `tx.value`; V2 penalties are paid in the target loan token and donated to the vaults. When the
|
|
20
|
+
* collateral and loan tokens match, one combined pull funds both collateral and penalties through
|
|
21
|
+
* `GeneralAdapter1`.
|
|
17
22
|
*
|
|
18
23
|
* Prerequisite: `GeneralAdapter1` must be authorized on Morpho to borrow on behalf of the user.
|
|
19
24
|
* Use `getRequirements()` on the entity to check and obtain the authorization transaction.
|
|
@@ -30,35 +35,40 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
30
35
|
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
31
36
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
32
37
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
33
|
-
* collateral
|
|
38
|
+
* collateral funding. When collateral and loan tokens match, its amount includes V2 penalties.
|
|
34
39
|
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
35
40
|
* collateral supply. Requires the collateral token to be the chain's wNative.
|
|
36
|
-
* @param params.args.reallocations - Optional
|
|
37
|
-
*
|
|
41
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
42
|
+
* execute between the supply and borrow legs.
|
|
38
43
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
39
44
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
40
45
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
46
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
42
47
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
43
|
-
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or
|
|
44
|
-
*
|
|
48
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, a V1 fee, or a V2
|
|
49
|
+
* penalty is negative.
|
|
45
50
|
* @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
|
|
46
51
|
* zero, or any reallocation withdrawal amount is non-positive.
|
|
52
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
53
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
54
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
55
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
56
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
57
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
47
58
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
48
59
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
49
60
|
* token is not the chain's wNative.
|
|
50
61
|
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
51
62
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
52
63
|
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
53
|
-
* is provided and the signed amount differs from
|
|
64
|
+
* is provided and the signed amount differs from the total ERC-20 funding amount.
|
|
54
65
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
55
66
|
* signature is missing its expiration.
|
|
56
|
-
* @throws {EmptyReallocationWithdrawalsError}
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* reallocation withdrawals are not strictly sorted by market id.
|
|
67
|
+
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
68
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
69
|
+
* the target market.
|
|
70
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
71
|
+
* sorted by market id.
|
|
62
72
|
* @example
|
|
63
73
|
* ```ts
|
|
64
74
|
* import { blueSupplyCollateralBorrow } from "@morpho-org/morpho-sdk";
|
|
@@ -93,6 +103,16 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
93
103
|
if (totalCollateral === 0n) {
|
|
94
104
|
throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
|
|
95
105
|
}
|
|
106
|
+
const usesSharedFundingToken = (0, viem_1.isAddressEqual)(marketParams.collateralToken, marketParams.loanToken);
|
|
107
|
+
const reallocationResult = (0, buildReallocationActions_js_1.buildBlueReallocationActions)({
|
|
108
|
+
chainId,
|
|
109
|
+
reallocations,
|
|
110
|
+
targetMarketParams: marketParams,
|
|
111
|
+
penaltyFundingSource: usesSharedFundingToken
|
|
112
|
+
? "generalAdapter1"
|
|
113
|
+
: "initiator",
|
|
114
|
+
});
|
|
115
|
+
const erc20FundingAmount = amount + (usesSharedFundingToken ? reallocationResult.penaltyAssets : 0n);
|
|
96
116
|
const actions = [];
|
|
97
117
|
if (authorizationSignature) {
|
|
98
118
|
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
@@ -100,7 +120,7 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
100
120
|
actions.push(...(0, buildAssetFundingActions_js_1.buildAssetFundingActions)({
|
|
101
121
|
chainId,
|
|
102
122
|
asset: marketParams.collateralToken,
|
|
103
|
-
erc20Amount:
|
|
123
|
+
erc20Amount: erc20FundingAmount,
|
|
104
124
|
nativeAmount: nativeAmount ?? 0n,
|
|
105
125
|
requirementSignature,
|
|
106
126
|
}));
|
|
@@ -108,12 +128,7 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
108
128
|
type: "morphoSupplyCollateral",
|
|
109
129
|
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
110
130
|
});
|
|
111
|
-
|
|
112
|
-
if (reallocations && reallocations.length > 0) {
|
|
113
|
-
const result = (0, buildReallocationActions_js_1.buildReallocationActions)(reallocations, marketParams);
|
|
114
|
-
actions.push(...result.actions);
|
|
115
|
-
reallocationFee = result.fee;
|
|
116
|
-
}
|
|
131
|
+
actions.push(...reallocationResult.actions);
|
|
117
132
|
actions.push({
|
|
118
133
|
type: "morphoBorrow",
|
|
119
134
|
args: [marketParams, borrowAmount, 0n, minSharePrice, receiver, false],
|
|
@@ -134,7 +149,8 @@ const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: {
|
|
|
134
149
|
onBehalf,
|
|
135
150
|
receiver,
|
|
136
151
|
nativeAmount,
|
|
137
|
-
reallocationFee,
|
|
152
|
+
reallocationFee: reallocationResult.fee,
|
|
153
|
+
reallocationPenaltyAssets: reallocationResult.penaltyAssets,
|
|
138
154
|
},
|
|
139
155
|
},
|
|
140
156
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueReallocationPlan, type BlueWithdrawAction, type Metadata, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueWithdraw}. */
|
|
5
5
|
export interface BlueWithdrawParams {
|
|
6
6
|
market: {
|
|
@@ -17,11 +17,11 @@ export interface BlueWithdrawParams {
|
|
|
17
17
|
/** Minimum withdraw share price (in ray). Slippage protection. */
|
|
18
18
|
minSharePrice: bigint;
|
|
19
19
|
/**
|
|
20
|
-
* Vault reallocations to execute before withdrawing.
|
|
21
|
-
* `MorphoBlue.
|
|
22
|
-
* `
|
|
20
|
+
* Homogeneous Vault V1 or Vault V2 reallocations to execute before withdrawing. V1 entries can be
|
|
21
|
+
* computed via `MorphoBlue.getVaultV1Reallocations({ operation: "withdraw", amount })` or directly
|
|
22
|
+
* via `computeVaultV1Reallocations({ operation: "withdraw", amount, ... })`.
|
|
23
23
|
*/
|
|
24
|
-
reallocations?:
|
|
24
|
+
reallocations?: BlueReallocationPlan;
|
|
25
25
|
/**
|
|
26
26
|
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
27
27
|
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
@@ -40,10 +40,11 @@ export interface BlueWithdrawParams {
|
|
|
40
40
|
* - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
|
|
41
41
|
* supplier position close; immune to interest accrual between tx construction and execution).
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
43
|
+
* A `reallocations` plan contains either V1 entries or V2 market/idle entries,
|
|
44
|
+
* never both. The calls run before the withdraw. V1
|
|
45
|
+
* fees accumulate in `tx.value`; V2 penalties are paid in the target loan
|
|
46
|
+
* token and donated to the vaults. The on-chain `morphoWithdraw` sends the
|
|
47
|
+
* assets computed on-chain directly to `receiver`; no skim is required.
|
|
47
48
|
*
|
|
48
49
|
* The withdraw is performed on behalf of the transaction initiator (signer) — there is no
|
|
49
50
|
* separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
|
|
@@ -57,17 +58,23 @@ export interface BlueWithdrawParams {
|
|
|
57
58
|
* @param params.args.receiver - Address that receives the withdrawn assets.
|
|
58
59
|
* @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
|
|
59
60
|
* protection.
|
|
60
|
-
* @param params.args.reallocations - Optional
|
|
61
|
-
*
|
|
61
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
62
|
+
* execute before withdrawing.
|
|
62
63
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
63
64
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
64
65
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
65
66
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
66
67
|
* the typed `action` discriminator the simulation layer consumes.
|
|
67
|
-
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or
|
|
68
|
-
* is negative.
|
|
68
|
+
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, a V1 fee, or a V2
|
|
69
|
+
* penalty is negative.
|
|
69
70
|
* @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
|
|
70
71
|
* withdrawal amount is non-positive.
|
|
72
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
73
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
74
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
75
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
76
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
77
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
71
78
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
72
79
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
73
80
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
|
|
@@ -16,10 +16,11 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
16
16
|
* - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
|
|
17
17
|
* supplier position close; immune to interest accrual between tx construction and execution).
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* A `reallocations` plan contains either V1 entries or V2 market/idle entries,
|
|
20
|
+
* never both. The calls run before the withdraw. V1
|
|
21
|
+
* fees accumulate in `tx.value`; V2 penalties are paid in the target loan
|
|
22
|
+
* token and donated to the vaults. The on-chain `morphoWithdraw` sends the
|
|
23
|
+
* assets computed on-chain directly to `receiver`; no skim is required.
|
|
23
24
|
*
|
|
24
25
|
* The withdraw is performed on behalf of the transaction initiator (signer) — there is no
|
|
25
26
|
* separate `onBehalf` field; mirror `blueBorrow`. The entity layer keeps `receiver` aligned
|
|
@@ -33,17 +34,23 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
33
34
|
* @param params.args.receiver - Address that receives the withdrawn assets.
|
|
34
35
|
* @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
|
|
35
36
|
* protection.
|
|
36
|
-
* @param params.args.reallocations - Optional
|
|
37
|
-
*
|
|
37
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
38
|
+
* execute before withdrawing.
|
|
38
39
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
39
40
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
40
41
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
42
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
42
43
|
* the typed `action` discriminator the simulation layer consumes.
|
|
43
|
-
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or
|
|
44
|
-
* is negative.
|
|
44
|
+
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, a V1 fee, or a V2
|
|
45
|
+
* penalty is negative.
|
|
45
46
|
* @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
|
|
46
47
|
* withdrawal amount is non-positive.
|
|
48
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
49
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
50
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
51
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
52
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
53
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
47
54
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
48
55
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
49
56
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
|
|
@@ -86,23 +93,20 @@ const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, share
|
|
|
86
93
|
throw new index_js_3.NegativeInputError("minSharePrice", minSharePrice);
|
|
87
94
|
}
|
|
88
95
|
const actions = [];
|
|
89
|
-
let reallocationFee = 0n;
|
|
90
96
|
if (authorizationSignature) {
|
|
91
97
|
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
92
98
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
99
|
+
const { actions: reallocationActions, fee: reallocationFee, penaltyAssets: reallocationPenaltyAssets, } = (0, buildReallocationActions_js_1.buildBlueReallocationActions)({
|
|
100
|
+
chainId,
|
|
101
|
+
reallocations,
|
|
102
|
+
targetMarketParams: marketParams,
|
|
103
|
+
});
|
|
104
|
+
actions.push(...reallocationActions);
|
|
98
105
|
actions.push({
|
|
99
106
|
type: "morphoWithdraw",
|
|
100
107
|
args: [marketParams, assets, shares, minSharePrice, receiver, false],
|
|
101
108
|
});
|
|
102
|
-
let tx =
|
|
103
|
-
...index_js_1.BundlerAction.encodeBundle(chainId, actions),
|
|
104
|
-
value: reallocationFee,
|
|
105
|
-
};
|
|
109
|
+
let tx = index_js_1.BundlerAction.encodeBundle(chainId, actions);
|
|
106
110
|
if (metadata) {
|
|
107
111
|
tx = (0, index_js_2.addTransactionMetadata)(tx, metadata);
|
|
108
112
|
}
|
|
@@ -117,6 +121,7 @@ const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, share
|
|
|
117
121
|
receiver,
|
|
118
122
|
minSharePrice,
|
|
119
123
|
reallocationFee,
|
|
124
|
+
reallocationPenaltyAssets,
|
|
120
125
|
},
|
|
121
126
|
},
|
|
122
127
|
});
|
|
@@ -33,10 +33,10 @@ export interface MempoolSubmitOffersParams {
|
|
|
33
33
|
* @throws {InvalidTreeError} when `offers <= 0`.
|
|
34
34
|
* @example
|
|
35
35
|
* ```ts
|
|
36
|
-
* import {
|
|
36
|
+
* import { MidnightPayload } from "@morpho-org/morpho-sdk/utils";
|
|
37
37
|
* import { mempoolSubmitOffers } from "@morpho-org/morpho-sdk";
|
|
38
38
|
*
|
|
39
|
-
* const payload = await
|
|
39
|
+
* const payload = await MidnightPayload.encode(items);
|
|
40
40
|
* const tx = mempoolSubmitOffers({
|
|
41
41
|
* chainId: 8453,
|
|
42
42
|
* groups,
|
|
@@ -25,10 +25,10 @@ const index_js_1 = require("../../helpers/index.js");
|
|
|
25
25
|
* @throws {InvalidTreeError} when `offers <= 0`.
|
|
26
26
|
* @example
|
|
27
27
|
* ```ts
|
|
28
|
-
* import {
|
|
28
|
+
* import { MidnightPayload } from "@morpho-org/morpho-sdk/utils";
|
|
29
29
|
* import { mempoolSubmitOffers } from "@morpho-org/morpho-sdk";
|
|
30
30
|
*
|
|
31
|
-
* const payload = await
|
|
31
|
+
* const payload = await MidnightPayload.encode(items);
|
|
32
32
|
* const tx = mempoolSubmitOffers({
|
|
33
33
|
* chainId: 8453,
|
|
34
34
|
* groups,
|
package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ interface GeneralAdapterPermit2Erc20Allowances {
|
|
|
28
28
|
* bookkeeping invariants break (should not happen with the values this function passes).
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
|
-
* import { getChainAddresses } from "@morpho-org/
|
|
31
|
+
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
32
32
|
* import { getGeneralAdapterRequirementsPermit2 } from "@morpho-org/morpho-sdk";
|
|
33
33
|
*
|
|
34
34
|
* const { permit2 } = getChainAddresses(1);
|
|
@@ -29,7 +29,7 @@ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
|
|
|
29
29
|
* bookkeeping invariants break (should not happen with the values this function passes).
|
|
30
30
|
* @example
|
|
31
31
|
* ```ts
|
|
32
|
-
* import { getChainAddresses } from "@morpho-org/
|
|
32
|
+
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
33
33
|
* import { getGeneralAdapterRequirementsPermit2 } from "@morpho-org/morpho-sdk";
|
|
34
34
|
*
|
|
35
35
|
* const { permit2 } = getChainAddresses(1);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRequirementsApproval = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
4
5
|
const constant_js_1 = require("../../helpers/constant.js");
|
|
5
6
|
const index_js_1 = require("../../types/index.js");
|
|
6
7
|
const encodeErc20Approval_js_1 = require("./encode/encodeErc20Approval.js");
|
|
@@ -50,7 +51,7 @@ const getRequirementsApproval = (params) => {
|
|
|
50
51
|
}
|
|
51
52
|
const approvals = [];
|
|
52
53
|
if (allowances < spendAmount) {
|
|
53
|
-
if (constant_js_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.
|
|
54
|
+
if (constant_js_1.APPROVE_ONLY_ONCE_TOKENS[chainId]?.some((token) => (0, viem_1.isAddressEqual)(token, address)) &&
|
|
54
55
|
allowances > 0n) {
|
|
55
56
|
approvals.push((0, encodeErc20Approval_js_1.encodeErc20Approval)({
|
|
56
57
|
token: address,
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { marketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi, preLiquidationFactoryAbi, publicAllocatorAbi, vaultV1AdapterAbi, vaultV1AdapterFactoryAbi, vaultV1PublicAllocatorAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.vaultV1PublicAllocatorAbi = exports.vaultV1AdapterFactoryAbi = exports.vaultV1AdapterAbi = exports.publicAllocatorAbi = exports.preLiquidationFactoryAbi = exports.preLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.adaptiveCurveIrmAbi = exports.marketParamsAbi = void 0;
|
|
4
|
+
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
Object.defineProperty(exports, "marketParamsAbi", { enumerable: true, get: function () { return blue_sdk_1.marketParamsAbi; } });
|
|
6
|
+
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
7
|
+
Object.defineProperty(exports, "adaptiveCurveIrmAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.adaptiveCurveIrmAbi; } });
|
|
8
|
+
Object.defineProperty(exports, "blueAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueAbi; } });
|
|
9
|
+
Object.defineProperty(exports, "blueOracleAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueOracleAbi; } });
|
|
10
|
+
Object.defineProperty(exports, "erc2612Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc2612Abi; } });
|
|
11
|
+
Object.defineProperty(exports, "erc5267Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc5267Abi; } });
|
|
12
|
+
Object.defineProperty(exports, "metaMorphoAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoAbi; } });
|
|
13
|
+
Object.defineProperty(exports, "metaMorphoFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoFactoryAbi; } });
|
|
14
|
+
Object.defineProperty(exports, "morphoMarketV1AdapterAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoMarketV1AdapterAbi; } });
|
|
15
|
+
Object.defineProperty(exports, "morphoMarketV1AdapterFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoMarketV1AdapterFactoryAbi; } });
|
|
16
|
+
Object.defineProperty(exports, "morphoMarketV1AdapterV2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoMarketV1AdapterV2Abi; } });
|
|
17
|
+
Object.defineProperty(exports, "morphoMarketV1AdapterV2FactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoMarketV1AdapterV2FactoryAbi; } });
|
|
18
|
+
Object.defineProperty(exports, "morphoVaultV1AdapterAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoVaultV1AdapterAbi; } });
|
|
19
|
+
Object.defineProperty(exports, "morphoVaultV1AdapterFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoVaultV1AdapterFactoryAbi; } });
|
|
20
|
+
Object.defineProperty(exports, "permissionedErc20WrapperAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.permissionedErc20WrapperAbi; } });
|
|
21
|
+
Object.defineProperty(exports, "permit2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.permit2Abi; } });
|
|
22
|
+
Object.defineProperty(exports, "preLiquidationAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.preLiquidationAbi; } });
|
|
23
|
+
Object.defineProperty(exports, "preLiquidationFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.preLiquidationFactoryAbi; } });
|
|
24
|
+
Object.defineProperty(exports, "publicAllocatorAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.publicAllocatorAbi; } });
|
|
25
|
+
Object.defineProperty(exports, "vaultV1AdapterAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV1AdapterAbi; } });
|
|
26
|
+
Object.defineProperty(exports, "vaultV1AdapterFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV1AdapterFactoryAbi; } });
|
|
27
|
+
Object.defineProperty(exports, "vaultV1PublicAllocatorAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV1PublicAllocatorAbi; } });
|
|
28
|
+
Object.defineProperty(exports, "vaultV2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV2Abi; } });
|
|
29
|
+
Object.defineProperty(exports, "vaultV2BluePublicAllocatorAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV2BluePublicAllocatorAbi; } });
|
|
30
|
+
Object.defineProperty(exports, "vaultV2FactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV2FactoryAbi; } });
|
|
31
|
+
Object.defineProperty(exports, "whitelistControllerAggregatorV2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.whitelistControllerAggregatorV2Abi; } });
|
|
32
|
+
Object.defineProperty(exports, "wrappedBackedTokenAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wrappedBackedTokenAbi; } });
|
|
33
|
+
Object.defineProperty(exports, "wstEthAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wstEthAbi; } });
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { AddressLabel, AddressRegistry, ChainAddresses, ChainDeployments, DeploymentRegistry, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { addresses, addressesRegistry, convexWrapperTokens, deployments, erc20WrapperTokens, getChainAddress, getChainAddresses, getPermissionedCoinbaseTokens, getUnwrappedToken, NATIVE_ADDRESS, permissionedBackedTokens, permissionedCoinbaseTokens, permissionedWrapperTokens, registerCustomAddresses, unwrappedTokensMapping, } from "@morpho-org/blue-sdk";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unwrappedTokensMapping = exports.registerCustomAddresses = exports.permissionedWrapperTokens = exports.permissionedCoinbaseTokens = exports.permissionedBackedTokens = exports.NATIVE_ADDRESS = exports.getUnwrappedToken = exports.getPermissionedCoinbaseTokens = exports.getChainAddresses = exports.getChainAddress = exports.erc20WrapperTokens = exports.deployments = exports.convexWrapperTokens = exports.addressesRegistry = exports.addresses = void 0;
|
|
4
|
+
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
Object.defineProperty(exports, "addresses", { enumerable: true, get: function () { return blue_sdk_1.addresses; } });
|
|
6
|
+
Object.defineProperty(exports, "addressesRegistry", { enumerable: true, get: function () { return blue_sdk_1.addressesRegistry; } });
|
|
7
|
+
Object.defineProperty(exports, "convexWrapperTokens", { enumerable: true, get: function () { return blue_sdk_1.convexWrapperTokens; } });
|
|
8
|
+
Object.defineProperty(exports, "deployments", { enumerable: true, get: function () { return blue_sdk_1.deployments; } });
|
|
9
|
+
Object.defineProperty(exports, "erc20WrapperTokens", { enumerable: true, get: function () { return blue_sdk_1.erc20WrapperTokens; } });
|
|
10
|
+
Object.defineProperty(exports, "getChainAddress", { enumerable: true, get: function () { return blue_sdk_1.getChainAddress; } });
|
|
11
|
+
Object.defineProperty(exports, "getChainAddresses", { enumerable: true, get: function () { return blue_sdk_1.getChainAddresses; } });
|
|
12
|
+
Object.defineProperty(exports, "getPermissionedCoinbaseTokens", { enumerable: true, get: function () { return blue_sdk_1.getPermissionedCoinbaseTokens; } });
|
|
13
|
+
Object.defineProperty(exports, "getUnwrappedToken", { enumerable: true, get: function () { return blue_sdk_1.getUnwrappedToken; } });
|
|
14
|
+
Object.defineProperty(exports, "NATIVE_ADDRESS", { enumerable: true, get: function () { return blue_sdk_1.NATIVE_ADDRESS; } });
|
|
15
|
+
Object.defineProperty(exports, "permissionedBackedTokens", { enumerable: true, get: function () { return blue_sdk_1.permissionedBackedTokens; } });
|
|
16
|
+
Object.defineProperty(exports, "permissionedCoinbaseTokens", { enumerable: true, get: function () { return blue_sdk_1.permissionedCoinbaseTokens; } });
|
|
17
|
+
Object.defineProperty(exports, "permissionedWrapperTokens", { enumerable: true, get: function () { return blue_sdk_1.permissionedWrapperTokens; } });
|
|
18
|
+
Object.defineProperty(exports, "registerCustomAddresses", { enumerable: true, get: function () { return blue_sdk_1.registerCustomAddresses; } });
|
|
19
|
+
Object.defineProperty(exports, "unwrappedTokensMapping", { enumerable: true, get: function () { return blue_sdk_1.unwrappedTokensMapping; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.LIQUIDATION_CURSOR = exports.isMarketId = exports.ERC20_ALLOWANCE_RECIPIENTS = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = void 0;
|
|
4
|
+
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
Object.defineProperty(exports, "DEFAULT_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE; } });
|
|
6
|
+
Object.defineProperty(exports, "EIP_712_FIELDS", { enumerable: true, get: function () { return blue_sdk_1.EIP_712_FIELDS; } });
|
|
7
|
+
Object.defineProperty(exports, "ERC20_ALLOWANCE_RECIPIENTS", { enumerable: true, get: function () { return blue_sdk_1.ERC20_ALLOWANCE_RECIPIENTS; } });
|
|
8
|
+
Object.defineProperty(exports, "isMarketId", { enumerable: true, get: function () { return blue_sdk_1.isMarketId; } });
|
|
9
|
+
Object.defineProperty(exports, "LIQUIDATION_CURSOR", { enumerable: true, get: function () { return blue_sdk_1.LIQUIDATION_CURSOR; } });
|
|
10
|
+
Object.defineProperty(exports, "MAX_LIQUIDATION_INCENTIVE_FACTOR", { enumerable: true, get: function () { return blue_sdk_1.MAX_LIQUIDATION_INCENTIVE_FACTOR; } });
|
|
11
|
+
Object.defineProperty(exports, "ORACLE_PRICE_SCALE", { enumerable: true, get: function () { return blue_sdk_1.ORACLE_PRICE_SCALE; } });
|
|
12
|
+
Object.defineProperty(exports, "SECONDS_PER_YEAR", { enumerable: true, get: function () { return blue_sdk_1.SECONDS_PER_YEAR; } });
|
|
13
|
+
Object.defineProperty(exports, "TransactionType", { enumerable: true, get: function () { return blue_sdk_1.TransactionType; } });
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition, IPreLiquidationParams, IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|