@morpho-org/morpho-sdk 4.2.0 → 5.0.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 +12 -12
- package/lib/cjs/actions/blue/borrow.d.ts +12 -2
- package/lib/cjs/actions/blue/borrow.js +7 -1
- 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 +6 -5
- package/lib/cjs/actions/blue/repay.js +10 -18
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/cjs/actions/blue/supply.d.ts +7 -7
- package/lib/cjs/actions/blue/supply.js +10 -20
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/cjs/actions/blue/supplyCollateral.js +11 -21
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -19
- 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 +171 -125
- 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/validate.d.ts +2 -2
- package/lib/cjs/helpers/validate.js +1 -1
- package/lib/cjs/types/action.d.ts +113 -9
- package/lib/cjs/types/action.js +79 -5
- package/lib/cjs/types/error.d.ts +73 -0
- package/lib/cjs/types/error.js +89 -4
- package/lib/cjs/types.d.ts +2 -1
- package/lib/cjs/utils.d.ts +1 -1
- package/lib/cjs/utils.js +2 -3
- package/lib/esm/actions/blue/borrow.d.ts +12 -2
- package/lib/esm/actions/blue/borrow.js +7 -1
- 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 +6 -5
- package/lib/esm/actions/blue/repay.js +10 -18
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +15 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +16 -18
- package/lib/esm/actions/blue/supply.d.ts +7 -7
- package/lib/esm/actions/blue/supply.js +10 -20
- package/lib/esm/actions/blue/supplyCollateral.d.ts +8 -8
- package/lib/esm/actions/blue/supplyCollateral.js +11 -21
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +18 -6
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +17 -19
- 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 +173 -127
- 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/validate.d.ts +2 -2
- package/lib/esm/helpers/validate.js +1 -1
- package/lib/esm/types/action.d.ts +113 -9
- package/lib/esm/types/action.js +75 -4
- package/lib/esm/types/error.d.ts +73 -0
- package/lib/esm/types/error.js +84 -2
- package/lib/esm/types.d.ts +2 -1
- package/lib/esm/utils.d.ts +1 -1
- package/lib/esm/utils.js +1 -1
- package/package.json +6 -6
- 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
|
@@ -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,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
|
*
|
|
@@ -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
|
*
|
|
@@ -180,12 +180,13 @@ export type AssetsOrSharesArgs = {
|
|
|
180
180
|
};
|
|
181
181
|
/** @deprecated Use {@link AssetsOrSharesArgs}. Kept as an alias for back-compat. */
|
|
182
182
|
export type RepayAmountArgs = AssetsOrSharesArgs;
|
|
183
|
-
|
|
183
|
+
/** Metadata for a Blue authorization prerequisite transaction. */
|
|
184
|
+
export interface BlueAuthorizationAction extends BaseAction<"blueAuthorization", {
|
|
184
185
|
authorized: Address;
|
|
185
186
|
isAuthorized: boolean;
|
|
186
187
|
}> {
|
|
187
188
|
}
|
|
188
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction |
|
|
189
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction;
|
|
189
190
|
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
190
191
|
readonly to: Address;
|
|
191
192
|
readonly value: bigint;
|
|
@@ -223,9 +224,36 @@ export interface Permit2Args {
|
|
|
223
224
|
deadline: bigint;
|
|
224
225
|
expiration: bigint;
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Signed Morpho Blue authorization payload produced when an integrator opts into offchain
|
|
229
|
+
* signatures (`supportSignature: true`). Consumed by the action layer to emit a
|
|
230
|
+
* `setAuthorizationWithSig` bundler call in place of a standalone `setAuthorization` transaction.
|
|
231
|
+
*/
|
|
232
|
+
export interface AuthorizationSignatureArgs {
|
|
233
|
+
/** Account granting the authorization (the position owner). */
|
|
234
|
+
owner: Address;
|
|
235
|
+
/** Account being authorized to operate on Morpho on the owner's behalf (GeneralAdapter1). */
|
|
236
|
+
authorized: Address;
|
|
237
|
+
/** Whether the authorization is granted (`true`) or revoked (`false`). */
|
|
238
|
+
isAuthorized: boolean;
|
|
239
|
+
/** Morpho authorization nonce consumed by the signature. */
|
|
240
|
+
nonce: bigint;
|
|
241
|
+
/** Signature deadline timestamp in seconds. */
|
|
242
|
+
deadline: bigint;
|
|
243
|
+
/** EIP-712 signature over the Morpho `Authorization` typed data. */
|
|
244
|
+
signature: Hex;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A signable approval / authorization requirement. `sign()` returns the matching
|
|
248
|
+
* {@link RequirementSignature}; `action` describes the requirement without signing.
|
|
249
|
+
*
|
|
250
|
+
* Generic over the signature it produces so permit encoders narrow to
|
|
251
|
+
* {@link PermitRequirementSignature} and the authorization encoder to
|
|
252
|
+
* {@link AuthorizationRequirementSignature}; the default keeps the broad union for mixed arrays.
|
|
253
|
+
*/
|
|
254
|
+
export interface Requirement<TSignature extends RequirementSignature = RequirementSignature> {
|
|
255
|
+
sign: (client: WalletClient, userAddress: Address) => Promise<TSignature>;
|
|
256
|
+
action: TSignature["action"];
|
|
229
257
|
}
|
|
230
258
|
export interface PermitAction extends BaseAction<"permit", {
|
|
231
259
|
spender: Address;
|
|
@@ -240,10 +268,86 @@ export interface Permit2Action extends BaseAction<"permit2", {
|
|
|
240
268
|
expiration: bigint;
|
|
241
269
|
}> {
|
|
242
270
|
}
|
|
243
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Signable Morpho authorization requirement. Emitted by the entity layer when a bundled path
|
|
273
|
+
* needs GeneralAdapter1 authorized and the client opts into offchain signatures.
|
|
274
|
+
*/
|
|
275
|
+
export interface AuthorizationAction extends BaseAction<"authorization", {
|
|
276
|
+
authorized: Address;
|
|
277
|
+
isAuthorized: boolean;
|
|
278
|
+
deadline: bigint;
|
|
279
|
+
}> {
|
|
280
|
+
}
|
|
281
|
+
/** A signed ERC-2612 permit or Permit2 approval requirement. */
|
|
282
|
+
export interface PermitRequirementSignature {
|
|
244
283
|
args: PermitArgs | Permit2Args;
|
|
245
284
|
action: PermitAction | Permit2Action;
|
|
246
285
|
}
|
|
247
|
-
|
|
248
|
-
export
|
|
249
|
-
|
|
286
|
+
/** A signed Morpho authorization requirement (consumed via `setAuthorizationWithSig`). */
|
|
287
|
+
export interface AuthorizationRequirementSignature {
|
|
288
|
+
args: AuthorizationSignatureArgs;
|
|
289
|
+
action: AuthorizationAction;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The deep-frozen output of `Requirement.sign()`. Discriminated on `action.type`:
|
|
293
|
+
* `"permit"` / `"permit2"` carry token-approval args, `"authorization"` carries the signed
|
|
294
|
+
* Morpho authorization. Narrow with {@link isPermitSignature} / {@link isAuthorizationSignature}.
|
|
295
|
+
*/
|
|
296
|
+
export type RequirementSignature = PermitRequirementSignature | AuthorizationRequirementSignature;
|
|
297
|
+
/** Bundler3 token signature requirement. */
|
|
298
|
+
export type Bundler3TokenSignatureRequirement = Requirement<PermitRequirementSignature>;
|
|
299
|
+
export declare function isRequirementApproval(requirement: unknown): requirement is Transaction<ERC20ApprovalAction>;
|
|
300
|
+
/** Checks whether an action requirement is a Blue authorization transaction. */
|
|
301
|
+
export declare function isRequirementBlueAuthorization(requirement: unknown): requirement is Transaction<BlueAuthorizationAction>;
|
|
302
|
+
export declare function isRequirementSignature<T extends RequirementSignature = RequirementSignature>(requirement: Transaction<ERC20ApprovalAction> | Transaction<BlueAuthorizationAction> | Requirement<T> | undefined): requirement is Requirement<T>;
|
|
303
|
+
/**
|
|
304
|
+
* Narrows a {@link RequirementSignature} to a permit / Permit2 token-approval signature.
|
|
305
|
+
*
|
|
306
|
+
* @param signature - The signed requirement to test.
|
|
307
|
+
* @returns `true` when `signature.action.type` is `"permit"` or `"permit2"`.
|
|
308
|
+
*/
|
|
309
|
+
export declare function isPermitSignature(signature: RequirementSignature): signature is PermitRequirementSignature;
|
|
310
|
+
/**
|
|
311
|
+
* Narrows a {@link RequirementSignature} to a signed Morpho authorization.
|
|
312
|
+
*
|
|
313
|
+
* @param signature - The signed requirement to test.
|
|
314
|
+
* @returns `true` when `signature.action.type` is `"authorization"`.
|
|
315
|
+
*/
|
|
316
|
+
export declare function isAuthorizationSignature(signature: RequirementSignature): signature is AuthorizationRequirementSignature;
|
|
317
|
+
/** The typed permit / authorization slots a bundled path consumes, split from a `buildTx` array. */
|
|
318
|
+
export interface SelectedRequirementSignatures {
|
|
319
|
+
/** The single permit / Permit2 signature, when present. */
|
|
320
|
+
permit?: PermitRequirementSignature;
|
|
321
|
+
/** The single Morpho authorization signature, when present. */
|
|
322
|
+
authorization?: AuthorizationRequirementSignature;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Splits a `buildTx` signature array into its typed permit / authorization slots, rejecting
|
|
326
|
+
* ambiguous or unexpected input so a path never silently consumes the wrong signature.
|
|
327
|
+
*
|
|
328
|
+
* A bundled path consumes at most one permit and one authorization signature. Passing several of
|
|
329
|
+
* the same kind, or a kind the path does not consume, is rejected with a typed error rather than
|
|
330
|
+
* silently dropping the extras — the latter could otherwise leave a required authorization or
|
|
331
|
+
* permit unsigned (and the bundle reverting on-chain) or apply the wrong signature.
|
|
332
|
+
*
|
|
333
|
+
* @param signatures - The signatures passed to `buildTx`.
|
|
334
|
+
* @param accepts - Which signature kinds this operation consumes.
|
|
335
|
+
* @param accepts.permit - Whether a permit / Permit2 signature is consumed.
|
|
336
|
+
* @param accepts.authorization - Whether a Morpho authorization signature is consumed.
|
|
337
|
+
* @returns The single permit and/or authorization signature, when present.
|
|
338
|
+
* @throws {AmbiguousRequirementSignaturesError} when more than one signature of an accepted kind is present.
|
|
339
|
+
* @throws {UnexpectedRequirementSignatureError} when a signature of a kind the operation does not consume is present.
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* import { selectRequirementSignatures } from "@morpho-org/morpho-sdk";
|
|
343
|
+
*
|
|
344
|
+
* const { permit, authorization } = selectRequirementSignatures(signatures, {
|
|
345
|
+
* permit: true,
|
|
346
|
+
* authorization: true,
|
|
347
|
+
* });
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export declare function selectRequirementSignatures(signatures: readonly RequirementSignature[] | undefined, accepts: {
|
|
351
|
+
permit?: boolean;
|
|
352
|
+
authorization?: boolean;
|
|
353
|
+
}): SelectedRequirementSignatures;
|