@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.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/MIGRATION-v5-to-v6.md +206 -3
- package/README.md +81 -41
- package/lib/cjs/abis.d.ts +210 -0
- package/lib/cjs/abis.js +142 -2
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +25 -138
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +200 -0
- package/lib/cjs/actions/bundles/common.js +469 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +13 -13
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/entities/blue/blue.d.ts +19 -19
- package/lib/cjs/entities/blue/blue.js +3 -1
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +61 -65
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +17 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
- package/lib/cjs/helpers/index.d.ts +2 -1
- package/lib/cjs/helpers/index.js +5 -1
- package/lib/cjs/helpers/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +90 -1
- package/lib/cjs/helpers/slippage.js +123 -0
- package/lib/cjs/helpers/validate.d.ts +2 -0
- package/lib/cjs/helpers/validate.js +12 -1
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +179 -70
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +62 -14
- package/lib/cjs/types/error.js +88 -22
- package/lib/esm/abis.d.ts +210 -0
- package/lib/esm/abis.js +140 -0
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +27 -140
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +1 -1
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +200 -0
- package/lib/esm/actions/bundles/common.js +457 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +1 -1
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +10 -4
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +12 -12
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +11 -11
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/entities/blue/blue.d.ts +19 -19
- package/lib/esm/entities/blue/blue.js +4 -2
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +21 -14
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +51 -55
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
- package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
- package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
- package/lib/esm/helpers/index.d.ts +2 -1
- package/lib/esm/helpers/index.js +2 -1
- package/lib/esm/helpers/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +90 -1
- package/lib/esm/helpers/slippage.js +122 -2
- package/lib/esm/helpers/validate.d.ts +2 -0
- package/lib/esm/helpers/validate.js +11 -1
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +179 -70
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +62 -14
- package/lib/esm/types/error.js +80 -16
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@ import { type AccrualVaultV2, type MarketParams } 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 ActionOutput, type
|
|
5
|
+
import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type Deallocation, type MorphoClientType, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV2Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data.
|
|
@@ -14,67 +14,208 @@ export interface VaultV2Actions {
|
|
|
14
14
|
*/
|
|
15
15
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
|
|
16
16
|
/**
|
|
17
|
-
* Prepares a deposit
|
|
17
|
+
* Prepares a Vault V2 deposit through the registered VaultBundlesV1 contract.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
|
|
20
|
+
* `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612 or
|
|
21
|
+
* Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
|
|
22
|
+
* always minted to the transaction sender, which must be `userAddress`.
|
|
23
|
+
* Concurrent requirement reads share the first caller's options; later calls refresh on-chain
|
|
24
|
+
* state using their own options. `buildTx()` accepts signatures from the latest completed read.
|
|
23
25
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
32
|
-
*
|
|
26
|
+
* @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
|
|
27
|
+
* @param params.vaultData - Pre-fetched Vault V2 snapshot used for asset and share conversion.
|
|
28
|
+
* @param params.amount - Optional gross ERC-20 assets; exclusive with `nativeAmount`.
|
|
29
|
+
* @param params.nativeAmount - Optional gross native assets; exclusive with `amount` and valid
|
|
30
|
+
* only for a wNative vault.
|
|
31
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to 0.03% and cannot
|
|
32
|
+
* exceed 10%.
|
|
33
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted before
|
|
34
|
+
* the vault deposit.
|
|
35
|
+
* @param params.referralFeeRecipient - Non-zero recipient required for a positive referral fee.
|
|
36
|
+
* @param params.deadline - Optional execution and permit deadline in Unix seconds; defaults to
|
|
37
|
+
* two hours from handle creation.
|
|
38
|
+
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
39
|
+
* transaction builder.
|
|
40
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
41
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
42
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
43
|
+
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
44
|
+
* @throws {NegativeInputError} when funding, slippage, the referral fee, or a Permit2 nonce is negative.
|
|
45
|
+
* @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
|
|
46
|
+
* @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
|
|
47
|
+
* @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
|
|
48
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
49
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
50
|
+
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
51
|
+
* @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is
|
|
52
|
+
* selected without an explicit nonce.
|
|
53
|
+
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
54
|
+
* explicit Permit2 nonce is consumed.
|
|
55
|
+
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
56
|
+
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
57
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
58
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
59
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature was not produced for
|
|
60
|
+
* this prepared handle.
|
|
61
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
62
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
|
|
63
|
+
* @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
|
|
64
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
65
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
|
|
66
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
70
|
+
* import { createPublicClient, http, type Address, zeroAddress } from "viem";
|
|
71
|
+
* import { mainnet } from "viem/chains";
|
|
72
|
+
*
|
|
73
|
+
* const keyrockUsdcVaultV2 =
|
|
74
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
75
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
76
|
+
* .extend(morphoViemExtension());
|
|
77
|
+
* const vault = client.morpho.vaultV2(keyrockUsdcVaultV2, mainnet.id);
|
|
78
|
+
* const vaultData = await vault.getData();
|
|
79
|
+
* const action = vault.deposit({
|
|
80
|
+
* amount: 1_000_000n,
|
|
81
|
+
* userAddress: zeroAddress,
|
|
82
|
+
* vaultData,
|
|
83
|
+
* });
|
|
84
|
+
* const requirements = await action.getRequirements(); // Satisfy these first.
|
|
85
|
+
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
86
|
+
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
87
|
+
* ```
|
|
33
88
|
*/
|
|
34
89
|
deposit: (params: {
|
|
35
|
-
userAddress: Address;
|
|
36
|
-
vaultData: AccrualVaultV2;
|
|
37
|
-
slippageTolerance?: bigint;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
43
|
-
};
|
|
90
|
+
readonly userAddress: Address;
|
|
91
|
+
readonly vaultData: AccrualVaultV2;
|
|
92
|
+
readonly slippageTolerance?: bigint;
|
|
93
|
+
readonly referralFeePct?: bigint;
|
|
94
|
+
readonly referralFeeRecipient?: Address;
|
|
95
|
+
readonly deadline?: bigint;
|
|
96
|
+
} & BundlesFundingArgs) => ActionOutput<VaultV2DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
|
|
44
97
|
/**
|
|
45
|
-
* Prepares
|
|
98
|
+
* Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
|
|
46
99
|
*
|
|
47
|
-
*
|
|
100
|
+
* Reads the vault accrual state on the first `getRequirements()` call, then reads the live
|
|
101
|
+
* vault-share allowance and, when a signature is needed, the permit nonce on each call.
|
|
102
|
+
* Captures the requested amount and owner at creation, so later changes to `params` do not
|
|
103
|
+
* change this handle's requirements or transaction.
|
|
48
104
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
*
|
|
53
|
-
*
|
|
105
|
+
* @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
106
|
+
* @param params.userAddress - Share owner that must sign and submit; receives the net assets.
|
|
107
|
+
* @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
|
|
108
|
+
* the share cap.
|
|
109
|
+
* Defaults to 0.03% and cannot exceed 10%.
|
|
110
|
+
* @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
|
|
111
|
+
* rounded down and deducted from the gross withdrawn assets.
|
|
112
|
+
* @param params.referralFeeRecipient - Optional nonzero recipient required for a positive fee.
|
|
113
|
+
* @param params.deadline - Optional execution and share-permit deadline in Unix seconds;
|
|
114
|
+
* defaults to two hours from handle creation.
|
|
115
|
+
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
116
|
+
* which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
|
|
117
|
+
* when the allowance equals the cap; otherwise they contain an exact approval or, with
|
|
118
|
+
* signature support, an ERC-2612 request. The cap stays pinned to the first resolution while
|
|
119
|
+
* each call re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
120
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
121
|
+
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
122
|
+
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
123
|
+
* at any `getRequirements()` call.
|
|
124
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
125
|
+
* @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
|
|
126
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
127
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
128
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
|
|
129
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
130
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
131
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
132
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
|
|
133
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed,
|
|
134
|
+
* was not resolved for this handle, or has incompatible vault, owner, spender, amount,
|
|
135
|
+
* deadline, or nonce values.
|
|
136
|
+
* @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
140
|
+
* import { createPublicClient, http, type Address } from "viem";
|
|
141
|
+
* import { mainnet } from "viem/chains";
|
|
142
|
+
*
|
|
143
|
+
* export async function prepareUsdcWithdrawal(userAddress: Address) {
|
|
144
|
+
* const vaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
145
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
146
|
+
* .extend(morphoViemExtension({ supportSignature: false }));
|
|
147
|
+
* const vault = client.morpho.vaultV2(vaultAddress, mainnet.id);
|
|
148
|
+
* const action = vault.withdraw({ amount: 1_000_000n, userAddress });
|
|
149
|
+
* const requirements = await action.getRequirements();
|
|
150
|
+
* // Send and confirm each approval before calling action.buildTx().
|
|
151
|
+
* // action.buildTx() returns Readonly<Transaction<VaultV2WithdrawAction>>.
|
|
152
|
+
* return { action, requirements }; // Prepared handle and its outstanding share approvals.
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
54
155
|
*/
|
|
55
156
|
withdraw: (params: {
|
|
56
|
-
amount: bigint;
|
|
57
|
-
userAddress: Address;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
157
|
+
readonly amount: bigint;
|
|
158
|
+
readonly userAddress: Address;
|
|
159
|
+
readonly slippageTolerance?: bigint;
|
|
160
|
+
readonly referralFeePct?: bigint;
|
|
161
|
+
readonly referralFeeRecipient?: Address;
|
|
162
|
+
readonly deadline?: bigint;
|
|
163
|
+
}) => ActionOutput<VaultV2WithdrawAction, readonly RequirementSignature[], undefined>;
|
|
61
164
|
/**
|
|
62
|
-
* Prepares
|
|
165
|
+
* Prepares an exact-shares Vault V2 redemption through VaultBundlesV1.
|
|
63
166
|
*
|
|
64
|
-
*
|
|
167
|
+
* Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
|
|
168
|
+
* The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
|
|
169
|
+
* `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
|
|
170
|
+
* `buildTx()` accepts permits from the latest completed requirement resolution.
|
|
65
171
|
*
|
|
66
172
|
* @param {Object} params - The redeem parameters.
|
|
67
|
-
* @param {bigint} params.shares -
|
|
68
|
-
* @param {Address} params.userAddress -
|
|
69
|
-
* @
|
|
70
|
-
* @
|
|
173
|
+
* @param {bigint} params.shares - Exact vault shares to burn.
|
|
174
|
+
* @param {Address} params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
|
|
175
|
+
* @param {bigint} [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
|
|
176
|
+
* @param {Address} [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
|
|
177
|
+
* @param {bigint} [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
|
|
178
|
+
* @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
|
|
179
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
180
|
+
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
181
|
+
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
182
|
+
* requirement resolution.
|
|
183
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
184
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
185
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
186
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
187
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
188
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance or nonce read fails.
|
|
189
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
190
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
191
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit does not match the
|
|
192
|
+
* resolved share cap, spender, owner, nonce, or deadline.
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
196
|
+
*
|
|
197
|
+
* const vault = client.morpho.vaultV2(vaultAddress, 1);
|
|
198
|
+
* const redemption = vault.redeem({ shares: 1_000_000n, userAddress });
|
|
199
|
+
* const signatures = [];
|
|
200
|
+
* for (const requirement of await redemption.getRequirements()) {
|
|
201
|
+
* if (isRequirementSignature(requirement)) {
|
|
202
|
+
* signatures.push(await requirement.sign(walletClient, userAddress));
|
|
203
|
+
* } else {
|
|
204
|
+
* const hash = await walletClient.sendTransaction(requirement);
|
|
205
|
+
* await client.waitForTransactionReceipt({ hash });
|
|
206
|
+
* }
|
|
207
|
+
* }
|
|
208
|
+
* const tx = redemption.buildTx(signatures);
|
|
209
|
+
* // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
|
|
210
|
+
* ```
|
|
71
211
|
*/
|
|
72
212
|
redeem: (params: {
|
|
73
|
-
shares: bigint;
|
|
74
|
-
userAddress: Address;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
213
|
+
readonly shares: bigint;
|
|
214
|
+
readonly userAddress: Address;
|
|
215
|
+
readonly referralFeePct?: bigint;
|
|
216
|
+
readonly referralFeeRecipient?: Address;
|
|
217
|
+
readonly deadline?: bigint;
|
|
218
|
+
}) => ActionOutput<VaultV2RedeemAction, readonly RequirementSignature[], undefined>;
|
|
78
219
|
/**
|
|
79
220
|
* Prepares an illiquid Vault V2 exit into idle assets and Morpho Blue supply positions.
|
|
80
221
|
*
|
|
@@ -214,28 +355,40 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
214
355
|
private readonly chainId;
|
|
215
356
|
constructor(client: MorphoClientType, vault: Address, chainId: number);
|
|
216
357
|
getData(parameters?: FetchParameters): Promise<AccrualVaultV2>;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
358
|
+
/** {@inheritDoc VaultV2Actions.deposit} */
|
|
359
|
+
deposit(params: {
|
|
360
|
+
readonly userAddress: Address;
|
|
361
|
+
readonly vaultData: AccrualVaultV2;
|
|
362
|
+
readonly slippageTolerance?: bigint;
|
|
363
|
+
readonly referralFeePct?: bigint;
|
|
364
|
+
readonly referralFeeRecipient?: Address;
|
|
365
|
+
readonly deadline?: bigint;
|
|
366
|
+
} & BundlesFundingArgs): Readonly<{
|
|
367
|
+
getRequirements: (requirementOptions?: BundlesTokenRequirementsOptions) => Promise<readonly ActionRequirement[]>;
|
|
225
368
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
226
|
-
}
|
|
227
|
-
withdraw(
|
|
228
|
-
amount: bigint;
|
|
229
|
-
userAddress: Address;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
369
|
+
}>;
|
|
370
|
+
withdraw(params: {
|
|
371
|
+
readonly amount: bigint;
|
|
372
|
+
readonly userAddress: Address;
|
|
373
|
+
readonly slippageTolerance?: bigint;
|
|
374
|
+
readonly referralFeePct?: bigint;
|
|
375
|
+
readonly referralFeeRecipient?: Address;
|
|
376
|
+
readonly deadline?: bigint;
|
|
377
|
+
}): Readonly<{
|
|
378
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
379
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2WithdrawAction>>;
|
|
380
|
+
}>;
|
|
381
|
+
/** {@inheritDoc VaultV2Actions.redeem} */
|
|
382
|
+
redeem(params: {
|
|
383
|
+
readonly shares: bigint;
|
|
384
|
+
readonly userAddress: Address;
|
|
385
|
+
readonly referralFeePct?: bigint;
|
|
386
|
+
readonly referralFeeRecipient?: Address;
|
|
387
|
+
readonly deadline?: bigint;
|
|
388
|
+
}): Readonly<{
|
|
389
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
390
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2RedeemAction>>;
|
|
391
|
+
}>;
|
|
239
392
|
/** {@inheritDoc VaultV2Actions.inKindRedeem} */
|
|
240
393
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }: {
|
|
241
394
|
readonly amount: bigint;
|