@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
|
@@ -253,50 +253,6 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
253
253
|
* ```
|
|
254
254
|
*/
|
|
255
255
|
getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
256
|
-
/**
|
|
257
|
-
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
258
|
-
* counting the public-allocator liquidity reallocatable into it.
|
|
259
|
-
*
|
|
260
|
-
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
261
|
-
* `target` wording wrongly implied a market's configured supply-target
|
|
262
|
-
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
263
|
-
* Delegates to the new method; will be removed in the next major.
|
|
264
|
-
*
|
|
265
|
-
* @param marketId - Target market to borrow from.
|
|
266
|
-
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
267
|
-
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
268
|
-
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
269
|
-
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
270
|
-
* @example
|
|
271
|
-
* ```ts
|
|
272
|
-
* import { createPublicClient, http, parseEther } from "viem";
|
|
273
|
-
* import { mainnet } from "viem/chains";
|
|
274
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
275
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
276
|
-
*
|
|
277
|
-
* const client = createPublicClient({
|
|
278
|
-
* chain: mainnet,
|
|
279
|
-
* transport: http(),
|
|
280
|
-
* }).extend(morphoViemExtension());
|
|
281
|
-
*
|
|
282
|
-
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
283
|
-
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
284
|
-
* const block = await client.getBlock();
|
|
285
|
-
* const reallocationData = await market.getReallocationData({
|
|
286
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
287
|
-
* block: { number: block.number, timestamp: block.timestamp },
|
|
288
|
-
* });
|
|
289
|
-
*
|
|
290
|
-
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
291
|
-
* const available: bigint =
|
|
292
|
-
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
293
|
-
* marketParams.id,
|
|
294
|
-
* parseEther("0.9"),
|
|
295
|
-
* { timestamp: block.timestamp },
|
|
296
|
-
* );
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
getAvailableLiquidityToTargetUtilization(marketId: MarketId, targetUtilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
300
256
|
/**
|
|
301
257
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
302
258
|
*
|
|
@@ -414,53 +414,6 @@ class ReallocationData {
|
|
|
414
414
|
totalBorrowAssets: market.totalBorrowAssets,
|
|
415
415
|
}, utilization);
|
|
416
416
|
}
|
|
417
|
-
/**
|
|
418
|
-
* Computes the liquidity available to bring `marketId` to `utilization`,
|
|
419
|
-
* counting the public-allocator liquidity reallocatable into it.
|
|
420
|
-
*
|
|
421
|
-
* @deprecated Renamed to {@link getAvailableLiquidityToUtilization} — the
|
|
422
|
-
* `target` wording wrongly implied a market's configured supply-target
|
|
423
|
-
* utilization, whereas the argument is an arbitrary utilization ceiling.
|
|
424
|
-
* Delegates to the new method; will be removed in the next major.
|
|
425
|
-
*
|
|
426
|
-
* @param marketId - Target market to borrow from.
|
|
427
|
-
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
428
|
-
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
429
|
-
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
430
|
-
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
431
|
-
* @example
|
|
432
|
-
* ```ts
|
|
433
|
-
* import { createPublicClient, http, parseEther } from "viem";
|
|
434
|
-
* import { mainnet } from "viem/chains";
|
|
435
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
436
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
437
|
-
*
|
|
438
|
-
* const client = createPublicClient({
|
|
439
|
-
* chain: mainnet,
|
|
440
|
-
* transport: http(),
|
|
441
|
-
* }).extend(morphoViemExtension());
|
|
442
|
-
*
|
|
443
|
-
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
444
|
-
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
445
|
-
* const block = await client.getBlock();
|
|
446
|
-
* const reallocationData = await market.getReallocationData({
|
|
447
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
448
|
-
* block: { number: block.number, timestamp: block.timestamp },
|
|
449
|
-
* });
|
|
450
|
-
*
|
|
451
|
-
* // Deprecated: prefer reallocationData.getAvailableLiquidityToUtilization.
|
|
452
|
-
* const available: bigint =
|
|
453
|
-
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
454
|
-
* marketParams.id,
|
|
455
|
-
* parseEther("0.9"),
|
|
456
|
-
* { timestamp: block.timestamp },
|
|
457
|
-
* );
|
|
458
|
-
* ```
|
|
459
|
-
*/
|
|
460
|
-
// biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
|
|
461
|
-
getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
462
|
-
return this.getAvailableLiquidityToUtilization(marketId, targetUtilization, options);
|
|
463
|
-
}
|
|
464
417
|
/**
|
|
465
418
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
466
419
|
*
|
|
@@ -470,7 +423,7 @@ class ReallocationData {
|
|
|
470
423
|
* @internal
|
|
471
424
|
*/
|
|
472
425
|
getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
|
|
473
|
-
return (0,
|
|
426
|
+
return (0, morpho_ts_1._try)(() => {
|
|
474
427
|
const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
|
|
475
428
|
const validCap = pendingCap.validAt >= timestamp
|
|
476
429
|
? blue_sdk_1.MathLib.min(pendingCap.value, cap)
|
|
@@ -481,7 +434,7 @@ class ReallocationData {
|
|
|
481
434
|
.withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
|
|
482
435
|
!withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
|
|
483
436
|
.map((srcMarketId) => {
|
|
484
|
-
const withdrawal = (0,
|
|
437
|
+
const withdrawal = (0, morpho_ts_1._try)(() => {
|
|
485
438
|
const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
|
|
486
439
|
const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
|
|
487
440
|
defaultMaxWithdrawalUtilization);
|
|
@@ -557,7 +510,7 @@ class ReallocationData {
|
|
|
557
510
|
.supply(withdrawal.assets, 0n, timestamp);
|
|
558
511
|
data.markets[supplyMarketId] = cloneMarket(supplyPosition.market);
|
|
559
512
|
data.positions[vault][supplyMarketId] = clonePosition(supplyPosition);
|
|
560
|
-
void (0,
|
|
513
|
+
void (0, morpho_ts_1._try)(() => {
|
|
561
514
|
const vaultData = data.getVault(vault);
|
|
562
515
|
vaultData.totalAssets = vaultData.withdrawQueue.reduce((total, marketId) => total + data.getAccrualPosition(vault, marketId).supplyAssets, 0n);
|
|
563
516
|
}, blue_sdk_1.UnknownDataError);
|
|
@@ -2,7 +2,7 @@ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
-
import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
5
|
+
import { type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data with accrued interest.
|
|
@@ -30,10 +30,10 @@ export interface VaultV1Actions {
|
|
|
30
30
|
vaultData: AccrualVault;
|
|
31
31
|
slippageTolerance?: bigint;
|
|
32
32
|
} & DepositAmountArgs) => {
|
|
33
|
-
buildTx: (
|
|
33
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
34
34
|
getRequirements: (params?: {
|
|
35
35
|
useSimplePermit?: boolean;
|
|
36
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
36
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
* Prepares a withdraw from a VaultV1 (MetaMorpho) contract.
|
|
@@ -84,8 +84,8 @@ export interface VaultV1Actions {
|
|
|
84
84
|
shares: bigint;
|
|
85
85
|
slippageTolerance?: bigint;
|
|
86
86
|
}) => {
|
|
87
|
-
buildTx: (
|
|
88
|
-
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
87
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
88
|
+
getRequirements: () => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
@@ -101,8 +101,8 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
101
101
|
} & DepositAmountArgs): {
|
|
102
102
|
getRequirements: (params?: {
|
|
103
103
|
useSimplePermit?: boolean;
|
|
104
|
-
}) => Promise<(
|
|
105
|
-
buildTx: (
|
|
104
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
105
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
106
106
|
};
|
|
107
107
|
withdraw({ amount, userAddress }: {
|
|
108
108
|
amount: bigint;
|
|
@@ -123,7 +123,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
123
123
|
shares: bigint;
|
|
124
124
|
slippageTolerance?: bigint;
|
|
125
125
|
}): {
|
|
126
|
-
getRequirements: () => Promise<(
|
|
127
|
-
buildTx: (
|
|
126
|
+
getRequirements: () => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
127
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
128
128
|
};
|
|
129
129
|
}
|
|
@@ -68,7 +68,7 @@ class MorphoVaultV1 {
|
|
|
68
68
|
}
|
|
69
69
|
const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
70
70
|
return {
|
|
71
|
-
getRequirements:
|
|
71
|
+
getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
72
72
|
address: vaultData.asset,
|
|
73
73
|
chainId: this.chainId,
|
|
74
74
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -79,21 +79,26 @@ class MorphoVaultV1 {
|
|
|
79
79
|
from: userAddress,
|
|
80
80
|
},
|
|
81
81
|
}),
|
|
82
|
-
buildTx: (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
buildTx: (signatures) => {
|
|
83
|
+
const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
84
|
+
permit: true,
|
|
85
|
+
});
|
|
86
|
+
return (0, index_js_1.vaultV1Deposit)({
|
|
87
|
+
vault: {
|
|
88
|
+
chainId: this.chainId,
|
|
89
|
+
address: this.vault,
|
|
90
|
+
asset: vaultData.asset,
|
|
91
|
+
},
|
|
92
|
+
args: {
|
|
93
|
+
amount,
|
|
94
|
+
maxSharePrice,
|
|
95
|
+
recipient: userAddress,
|
|
96
|
+
requirementSignature: permit,
|
|
97
|
+
nativeAmount,
|
|
98
|
+
},
|
|
99
|
+
metadata: this.client.options.metadata,
|
|
100
|
+
});
|
|
101
|
+
},
|
|
97
102
|
};
|
|
98
103
|
}
|
|
99
104
|
withdraw({ amount, userAddress }) {
|
|
@@ -158,7 +163,7 @@ class MorphoVaultV1 {
|
|
|
158
163
|
}
|
|
159
164
|
const maxSharePriceVaultV2 = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), v2RefShares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
160
165
|
return {
|
|
161
|
-
getRequirements:
|
|
166
|
+
getRequirements: () => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
162
167
|
address: this.vault,
|
|
163
168
|
chainId: this.chainId,
|
|
164
169
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -170,23 +175,28 @@ class MorphoVaultV1 {
|
|
|
170
175
|
from: userAddress,
|
|
171
176
|
},
|
|
172
177
|
}),
|
|
173
|
-
buildTx: (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
178
|
+
buildTx: (signatures) => {
|
|
179
|
+
const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
|
|
180
|
+
permit: true,
|
|
181
|
+
});
|
|
182
|
+
return (0, index_js_1.vaultV1MigrateToV2)({
|
|
183
|
+
vault: {
|
|
184
|
+
chainId: this.chainId,
|
|
185
|
+
address: this.vault,
|
|
186
|
+
asset: sourceVault.asset,
|
|
187
|
+
},
|
|
188
|
+
args: {
|
|
189
|
+
targetVault: targetVault.address,
|
|
190
|
+
targetAsset: targetVault.asset,
|
|
191
|
+
shares,
|
|
192
|
+
minSharePriceVaultV1,
|
|
193
|
+
maxSharePriceVaultV2,
|
|
194
|
+
recipient: userAddress,
|
|
195
|
+
requirementSignature: permit,
|
|
196
|
+
},
|
|
197
|
+
metadata: this.client.options.metadata,
|
|
198
|
+
});
|
|
199
|
+
},
|
|
190
200
|
};
|
|
191
201
|
}
|
|
192
202
|
}
|
|
@@ -2,7 +2,7 @@ import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
-
import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
5
|
+
import { type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV2Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data.
|
|
@@ -29,17 +29,17 @@ export interface VaultV2Actions {
|
|
|
29
29
|
* @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative.
|
|
30
30
|
* @returns {Object} The result object.
|
|
31
31
|
* @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
|
|
32
|
-
* @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
32
|
+
* @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
33
33
|
*/
|
|
34
34
|
deposit: (params: {
|
|
35
35
|
userAddress: Address;
|
|
36
36
|
vaultData: AccrualVaultV2;
|
|
37
37
|
slippageTolerance?: bigint;
|
|
38
38
|
} & DepositAmountArgs) => {
|
|
39
|
-
buildTx: (
|
|
39
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
40
40
|
getRequirements: (params?: {
|
|
41
41
|
useSimplePermit?: boolean;
|
|
42
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
42
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Prepares a withdraw transaction for the VaultV2 contract.
|
|
@@ -144,8 +144,8 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
144
144
|
} & DepositAmountArgs): {
|
|
145
145
|
getRequirements: (params?: {
|
|
146
146
|
useSimplePermit?: boolean;
|
|
147
|
-
}) => Promise<(
|
|
148
|
-
buildTx: (
|
|
147
|
+
}) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
148
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
149
149
|
};
|
|
150
150
|
withdraw({ amount, userAddress }: {
|
|
151
151
|
amount: bigint;
|
|
@@ -71,7 +71,7 @@ class MorphoVaultV2 {
|
|
|
71
71
|
}
|
|
72
72
|
const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), blue_sdk_1.MathLib.RAY * 100n);
|
|
73
73
|
return {
|
|
74
|
-
getRequirements:
|
|
74
|
+
getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
|
|
75
75
|
address: vaultData.asset,
|
|
76
76
|
chainId: this.chainId,
|
|
77
77
|
supportSignature: this.client.options.supportSignature,
|
|
@@ -82,21 +82,26 @@ class MorphoVaultV2 {
|
|
|
82
82
|
from: userAddress,
|
|
83
83
|
},
|
|
84
84
|
}),
|
|
85
|
-
buildTx: (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
buildTx: (signatures) => {
|
|
86
|
+
const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, {
|
|
87
|
+
permit: true,
|
|
88
|
+
});
|
|
89
|
+
return (0, index_js_1.vaultV2Deposit)({
|
|
90
|
+
vault: {
|
|
91
|
+
chainId: this.chainId,
|
|
92
|
+
address: this.vault,
|
|
93
|
+
asset: vaultData.asset,
|
|
94
|
+
},
|
|
95
|
+
args: {
|
|
96
|
+
amount,
|
|
97
|
+
maxSharePrice,
|
|
98
|
+
recipient: userAddress,
|
|
99
|
+
requirementSignature: permit,
|
|
100
|
+
nativeAmount,
|
|
101
|
+
},
|
|
102
|
+
metadata: this.client.options.metadata,
|
|
103
|
+
});
|
|
104
|
+
},
|
|
100
105
|
};
|
|
101
106
|
}
|
|
102
107
|
withdraw({ amount, userAddress }) {
|
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
1
|
+
export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
3
|
+
export { _try } from "@morpho-org/morpho-ts";
|
package/lib/cjs/errors.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownFactory = exports.UnknownDataError = exports.InvalidMarketParamsError = exports.
|
|
3
|
+
exports._try = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownOfFactory = exports.UnknownMarketParamsError = exports.UnknownFactory = exports.UnknownDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
-
Object.defineProperty(exports, "_try", { enumerable: true, get: function () { return blue_sdk_1._try; } });
|
|
6
5
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
6
|
+
Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
|
|
7
7
|
Object.defineProperty(exports, "InvalidMarketParamsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidMarketParamsError; } });
|
|
8
|
+
Object.defineProperty(exports, "UnknownAddressError", { enumerable: true, get: function () { return blue_sdk_1.UnknownAddressError; } });
|
|
8
9
|
Object.defineProperty(exports, "UnknownDataError", { enumerable: true, get: function () { return blue_sdk_1.UnknownDataError; } });
|
|
9
10
|
Object.defineProperty(exports, "UnknownFactory", { enumerable: true, get: function () { return blue_sdk_1.UnknownFactory; } });
|
|
10
11
|
Object.defineProperty(exports, "UnknownMarketParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnknownMarketParamsError; } });
|
|
@@ -16,3 +17,5 @@ Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, ge
|
|
|
16
17
|
Object.defineProperty(exports, "UnsupportedPreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
|
|
17
18
|
Object.defineProperty(exports, "UnsupportedVaultV2AdapterError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedVaultV2AdapterError; } });
|
|
18
19
|
Object.defineProperty(exports, "VaultV2Errors", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Errors; } });
|
|
20
|
+
var morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
21
|
+
Object.defineProperty(exports, "_try", { enumerable: true, get: function () { return morpho_ts_1._try; } });
|
|
@@ -2,4 +2,4 @@ export { computeReallocations } from "./computeReallocations.js";
|
|
|
2
2
|
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
|
|
3
3
|
export { addTransactionMetadata } from "./metadata.js";
|
|
4
4
|
export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
|
|
5
|
-
export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount,
|
|
5
|
+
export { validateAccrualPosition, validateChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
|
package/lib/cjs/helpers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeReallocations = void 0;
|
|
4
4
|
var computeReallocations_js_1 = require("./computeReallocations.js");
|
|
5
5
|
Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return computeReallocations_js_1.computeReallocations; } });
|
|
6
6
|
var constant_js_1 = require("./constant.js");
|
|
@@ -26,7 +26,6 @@ Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get
|
|
|
26
26
|
Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return validate_js_1.validatePositionHealthAfterWithdraw; } });
|
|
27
27
|
Object.defineProperty(exports, "validateReallocations", { enumerable: true, get: function () { return validate_js_1.validateReallocations; } });
|
|
28
28
|
Object.defineProperty(exports, "validateRepayAmount", { enumerable: true, get: function () { return validate_js_1.validateRepayAmount; } });
|
|
29
|
-
Object.defineProperty(exports, "validateRepayParams", { enumerable: true, get: function () { return validate_js_1.validateRepayParams; } });
|
|
30
29
|
Object.defineProperty(exports, "validateRepayShares", { enumerable: true, get: function () { return validate_js_1.validateRepayShares; } });
|
|
31
30
|
Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true, get: function () { return validate_js_1.validateSlippageTolerance; } });
|
|
32
31
|
Object.defineProperty(exports, "validateUserAddress", { enumerable: true, get: function () { return validate_js_1.validateUserAddress; } });
|
|
@@ -2,13 +2,13 @@ import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { type Address } from "viem";
|
|
3
3
|
import { type VaultReallocation } from "../types/index.js";
|
|
4
4
|
/** @internal */
|
|
5
|
-
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) =>
|
|
5
|
+
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => 1 | 0 | -1;
|
|
6
6
|
/**
|
|
7
7
|
* Asserts that the client has a connected account AND that it matches
|
|
8
8
|
* the provided user address.
|
|
9
9
|
*
|
|
10
10
|
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
11
|
-
* `
|
|
11
|
+
* `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
|
|
12
12
|
* the signing flow is the only path where an account/address mismatch
|
|
13
13
|
* is a real security concern (rather than just an integrator footgun).
|
|
14
14
|
*
|
|
@@ -121,24 +121,6 @@ export declare const validateRepayShares: (params: {
|
|
|
121
121
|
repayShares: bigint;
|
|
122
122
|
marketId: MarketId;
|
|
123
123
|
}) => void;
|
|
124
|
-
/**
|
|
125
|
-
* Validates the common repay input parameters shared by `blueRepay`
|
|
126
|
-
* and `blueRepayWithdrawCollateral`.
|
|
127
|
-
*
|
|
128
|
-
* @param params - Validation parameters.
|
|
129
|
-
* @param params.assets - Repay assets amount (0n when repaying by shares).
|
|
130
|
-
* @param params.shares - Repay shares amount (0n when repaying by assets).
|
|
131
|
-
* @param params.transferAmount - ERC20 amount to transfer to GeneralAdapter1.
|
|
132
|
-
* @param params.maxSharePrice - Maximum repay share price (in ray). Must be positive.
|
|
133
|
-
* @param params.marketId - The market identifier (for error messages).
|
|
134
|
-
*/
|
|
135
|
-
export declare const validateRepayParams: (params: {
|
|
136
|
-
assets: bigint;
|
|
137
|
-
shares: bigint;
|
|
138
|
-
transferAmount: bigint;
|
|
139
|
-
maxSharePrice: bigint;
|
|
140
|
-
marketId: MarketId;
|
|
141
|
-
}) => void;
|
|
142
124
|
/**
|
|
143
125
|
* Validates that vault reallocations are well-formed.
|
|
144
126
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateReallocations = exports.
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.compareMarketIds = void 0;
|
|
4
4
|
exports.validateUserAddress = validateUserAddress;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
@@ -23,7 +23,7 @@ exports.compareMarketIds = compareMarketIds;
|
|
|
23
23
|
* the provided user address.
|
|
24
24
|
*
|
|
25
25
|
* Used internally by the signature requirements (`encodeErc20Permit`,
|
|
26
|
-
* `
|
|
26
|
+
* `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
|
|
27
27
|
* the signing flow is the only path where an account/address mismatch
|
|
28
28
|
* is a real security concern (rather than just an integrator footgun).
|
|
29
29
|
*
|
|
@@ -211,43 +211,6 @@ const validateRepayShares = (params) => {
|
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
213
|
exports.validateRepayShares = validateRepayShares;
|
|
214
|
-
/**
|
|
215
|
-
* Validates the common repay input parameters shared by `blueRepay`
|
|
216
|
-
* and `blueRepayWithdrawCollateral`.
|
|
217
|
-
*
|
|
218
|
-
* @param params - Validation parameters.
|
|
219
|
-
* @param params.assets - Repay assets amount (0n when repaying by shares).
|
|
220
|
-
* @param params.shares - Repay shares amount (0n when repaying by assets).
|
|
221
|
-
* @param params.transferAmount - ERC20 amount to transfer to GeneralAdapter1.
|
|
222
|
-
* @param params.maxSharePrice - Maximum repay share price (in ray). Must be positive.
|
|
223
|
-
* @param params.marketId - The market identifier (for error messages).
|
|
224
|
-
*/
|
|
225
|
-
const validateRepayParams = (params) => {
|
|
226
|
-
const { assets, shares, transferAmount, maxSharePrice, marketId } = params;
|
|
227
|
-
if (maxSharePrice <= 0n) {
|
|
228
|
-
throw new index_js_1.NonPositiveRepayMaxSharePriceError(marketId);
|
|
229
|
-
}
|
|
230
|
-
if (assets < 0n || shares < 0n) {
|
|
231
|
-
throw new index_js_1.NonPositiveRepayAmountError(marketId);
|
|
232
|
-
}
|
|
233
|
-
if (assets > 0n && shares > 0n) {
|
|
234
|
-
throw new index_js_1.MutuallyExclusiveRepayAmountsError(marketId);
|
|
235
|
-
}
|
|
236
|
-
if (assets === 0n && shares === 0n) {
|
|
237
|
-
throw new index_js_1.NonPositiveRepayAmountError(marketId);
|
|
238
|
-
}
|
|
239
|
-
if (transferAmount <= 0n) {
|
|
240
|
-
throw new index_js_1.NonPositiveTransferAmountError(marketId);
|
|
241
|
-
}
|
|
242
|
-
if (assets > 0n && transferAmount !== assets) {
|
|
243
|
-
throw new index_js_1.TransferAmountNotEqualToAssetsError({
|
|
244
|
-
transferAmount,
|
|
245
|
-
assets,
|
|
246
|
-
market: marketId,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
exports.validateRepayParams = validateRepayParams;
|
|
251
214
|
/**
|
|
252
215
|
* Validates that vault reallocations are well-formed.
|
|
253
216
|
*
|