@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
|
@@ -1,130 +1,132 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { getTokenRequirementActions } from "../signatures/getTokenRequirementActions.js";
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { encodeFunctionData } from "viem";
|
|
3
|
+
import { vaultBundlesV1Abi } from "../../abis.js";
|
|
4
|
+
import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
5
|
+
import { NonPositiveInputError, UnexpectedRequirementSignatureError, } from "../../types/index.js";
|
|
6
|
+
import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBundlesTokenPermit, normalizeBundlesCommonParams, resolveBundlesFunding, } from "../bundles/common.js";
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
8
|
+
* Encodes a Vault V2 deposit through the registered VaultBundlesV1 contract.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* asset
|
|
18
|
-
*
|
|
19
|
-
* @param params.
|
|
20
|
-
* @param params.
|
|
21
|
-
* @param params.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param params.args.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @param params.metadata -
|
|
31
|
-
* @
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @throws {
|
|
35
|
-
*
|
|
36
|
-
* @throws {
|
|
37
|
-
*
|
|
38
|
-
* @throws {NativeAmountOnNonWNativeVaultError} when
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @throws {
|
|
46
|
-
*
|
|
10
|
+
* @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
|
|
11
|
+
* @param params.vault.address - Vault V2 contract receiving the net deposit.
|
|
12
|
+
* @param params.vault.asset - Underlying ERC-20 asset; must be the chain's wNative for native funding.
|
|
13
|
+
* @param params.args.amount - Positive gross ERC-20 amount in asset base units, exclusive with `nativeAmount`.
|
|
14
|
+
* @param params.args.nativeAmount - Positive gross native amount in wei, exclusive with `amount` and
|
|
15
|
+
* `requirementSignature`; sent as `tx.value` and wrapped by VaultBundlesV1.
|
|
16
|
+
* @param params.args.maxSharePrice - Positive maximum asset base units per share base unit, scaled
|
|
17
|
+
* by RAY (1e27). Compute it for the net deposit after referral fees to bound slippage.
|
|
18
|
+
* @param params.args.userAddress - Permit owner and transaction sender; VaultBundlesV1 mints shares to this account.
|
|
19
|
+
* @param params.args.recipient - Unsupported; shares are always minted to the transaction sender.
|
|
20
|
+
* @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer signature
|
|
21
|
+
* for the gross amount, vault asset, `userAddress`, and VaultBundlesV1 spender.
|
|
22
|
+
* @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
|
|
23
|
+
* The fee is rounded down and deducted from gross assets before depositing.
|
|
24
|
+
* @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
|
|
25
|
+
* when `referralFeePct > 0n`.
|
|
26
|
+
* @param params.args.deadline - Positive uint256 Unix timestamp in seconds after which execution
|
|
27
|
+
* reverts. The caller must supply it; the builder chooses no default.
|
|
28
|
+
* @param params.metadata - Optional analytics metadata appended to the transaction calldata.
|
|
29
|
+
* @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
|
|
30
|
+
* @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
|
|
31
|
+
* @returns A deep-frozen `Transaction<VaultV2DepositAction>` targeting VaultBundlesV1, with
|
|
32
|
+
* `to`, `value`, `data`, and gross/fee/net deposit action metadata.
|
|
33
|
+
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
34
|
+
* @throws {NegativeInputError} when the selected funding amount or `referralFeePct` is negative.
|
|
35
|
+
* @throws {NonPositiveInputError} when funding, `maxSharePrice`, or `deadline` is not positive.
|
|
36
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
37
|
+
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
38
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD; it extends
|
|
39
|
+
* {@link InputExceedsMaxError}, so either class catches it.
|
|
40
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
41
|
+
* @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit or a
|
|
42
|
+
* Permit2 AllowanceTransfer signature is supplied.
|
|
43
|
+
* @throws {InputExceedsMaxError} when funding, `maxSharePrice`, or `deadline` exceeds uint256.
|
|
44
|
+
* @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
|
|
45
|
+
* @throws {DepositAssetMismatchError} when the signed asset differs from the vault asset.
|
|
46
|
+
* @throws {DepositAmountMismatchError} when the signed amount differs from the gross funding amount.
|
|
47
|
+
* @throws {DepositSpenderMismatchError} when the signed spender is not VaultBundlesV1.
|
|
48
|
+
* @throws {BundlesRequirementSignatureMismatchError} when the signature deadline, nonce, or encoding is invalid.
|
|
49
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
50
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
47
51
|
* @example
|
|
48
52
|
* ```ts
|
|
49
53
|
* import { vaultV2Deposit } from "@morpho-org/morpho-sdk";
|
|
54
|
+
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
55
|
+
* import type { Address } from "viem";
|
|
56
|
+
* import { mainnet } from "viem/chains";
|
|
50
57
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
*
|
|
58
|
+
* export function buildKeyrockUsdcDeposit(
|
|
59
|
+
* userAddress: Address,
|
|
60
|
+
* maxSharePrice: bigint,
|
|
61
|
+
* deadline: bigint,
|
|
62
|
+
* ) {
|
|
63
|
+
* const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
64
|
+
* const { usdc } = getChainAddresses(mainnet.id);
|
|
65
|
+
* const tx = vaultV2Deposit({
|
|
66
|
+
* vault: { chainId: mainnet.id, address: keyrockUsdcVaultV2, asset: usdc! },
|
|
67
|
+
* args: { amount: 1_000_000n, maxSharePrice, userAddress, deadline },
|
|
68
|
+
* });
|
|
69
|
+
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
70
|
+
* return tx;
|
|
71
|
+
* }
|
|
60
72
|
* ```
|
|
61
73
|
*/
|
|
62
|
-
export const vaultV2Deposit = (
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
export const vaultV2Deposit = (params) => {
|
|
75
|
+
const funding = resolveBundlesFunding(params.args);
|
|
76
|
+
if (params.args.maxSharePrice <= 0n) {
|
|
77
|
+
throw new NonPositiveInputError("maxSharePrice", params.args.maxSharePrice);
|
|
65
78
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
throw new
|
|
74
|
-
}
|
|
75
|
-
if (!isDefined(wNative)) {
|
|
76
|
-
throw new ChainWNativeMissingError(chainId);
|
|
79
|
+
// Reject ABI overflow with SDK errors before calldata encoding.
|
|
80
|
+
validateUint256Field(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
|
|
81
|
+
validateUint256Field("maxSharePrice", params.args.maxSharePrice);
|
|
82
|
+
if (funding.value > 0n) {
|
|
83
|
+
// Reject native funding unless the vault accepts the chain's wrapped-native asset.
|
|
84
|
+
validateNativeVaultAsset(params.vault.chainId, params.vault.asset);
|
|
85
|
+
if (params.args.requirementSignature != null) {
|
|
86
|
+
throw new UnexpectedRequirementSignatureError(params.args.requirementSignature.action.type);
|
|
77
87
|
}
|
|
78
|
-
if (!isAddressEqual(asset, wNative)) {
|
|
79
|
-
throw new NativeAmountOnNonWNativeVaultError(asset, wNative);
|
|
80
|
-
}
|
|
81
|
-
actions.push(
|
|
82
|
-
// Transfers native token from Bundler3 to GeneralAdapter1 for wrapping.
|
|
83
|
-
{
|
|
84
|
-
type: "nativeTransfer",
|
|
85
|
-
args: [bundler3, generalAdapter1, nativeAmount, false /* skipRevert */],
|
|
86
|
-
}, {
|
|
87
|
-
type: "wrapNative",
|
|
88
|
-
args: [nativeAmount, generalAdapter1, false /* skipRevert */],
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (amount > 0n) {
|
|
92
|
-
actions.push(...getTokenRequirementActions({
|
|
93
|
-
asset,
|
|
94
|
-
amount,
|
|
95
|
-
recipient: generalAdapter1,
|
|
96
|
-
requirementSignature,
|
|
97
|
-
}));
|
|
98
88
|
}
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
recipient,
|
|
110
|
-
false /* skipRevert */,
|
|
111
|
-
],
|
|
89
|
+
const common = normalizeBundlesCommonParams(params.args);
|
|
90
|
+
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
91
|
+
const netAssets = funding.assets - referralFeeAssets;
|
|
92
|
+
const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
|
|
93
|
+
const tokenPermit = getBundlesTokenPermit({
|
|
94
|
+
userAddress: params.args.userAddress,
|
|
95
|
+
token: params.vault.asset,
|
|
96
|
+
spender,
|
|
97
|
+
amount: funding.assets,
|
|
98
|
+
requirementSignature: params.args.requirementSignature,
|
|
112
99
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
100
|
+
return finalizeVaultBundlesV1Transaction({
|
|
101
|
+
chainId: params.vault.chainId,
|
|
102
|
+
value: funding.value,
|
|
103
|
+
data: encodeFunctionData({
|
|
104
|
+
abi: vaultBundlesV1Abi,
|
|
105
|
+
functionName: "vaultBundlesV1Deposit",
|
|
106
|
+
args: [
|
|
107
|
+
params.vault.address,
|
|
108
|
+
funding.assets,
|
|
109
|
+
params.args.maxSharePrice,
|
|
110
|
+
tokenPermit,
|
|
111
|
+
common.referralFeePct,
|
|
112
|
+
common.referralFeeRecipient,
|
|
113
|
+
common.deadline,
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
119
116
|
action: {
|
|
120
117
|
type: "vaultV2Deposit",
|
|
121
118
|
args: {
|
|
122
|
-
vault:
|
|
123
|
-
amount,
|
|
124
|
-
maxSharePrice,
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
vault: params.vault.address,
|
|
120
|
+
amount: funding.assets,
|
|
121
|
+
maxSharePrice: params.args.maxSharePrice,
|
|
122
|
+
nativeAmount: funding.value || undefined,
|
|
123
|
+
referralFeePct: common.referralFeePct,
|
|
124
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
125
|
+
referralFeeAssets,
|
|
126
|
+
netAssets,
|
|
127
|
+
deadline: common.deadline,
|
|
127
128
|
},
|
|
128
129
|
},
|
|
130
|
+
metadata: params.metadata,
|
|
129
131
|
});
|
|
130
132
|
};
|
|
@@ -1,40 +1,46 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import { type Metadata, type Transaction, type VaultV2RedeemAction } from "../../types/index.js";
|
|
2
|
+
import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV2RedeemAction } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link vaultV2Redeem}. */
|
|
4
4
|
export interface VaultV2RedeemParams {
|
|
5
|
-
vault: {
|
|
6
|
-
|
|
5
|
+
readonly vault: {
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly address: Address;
|
|
7
8
|
};
|
|
8
|
-
args: {
|
|
9
|
-
shares: bigint;
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
readonly args: {
|
|
10
|
+
readonly shares: bigint;
|
|
11
|
+
readonly userAddress: Address;
|
|
12
|
+
readonly recipient?: never;
|
|
13
|
+
readonly onBehalf?: never;
|
|
14
|
+
readonly requirementSignature?: Erc2612RequirementSignature;
|
|
15
|
+
readonly referralFeePct?: bigint;
|
|
16
|
+
readonly referralFeeRecipient?: Address;
|
|
17
|
+
readonly deadline: bigint;
|
|
12
18
|
};
|
|
13
|
-
metadata?: Metadata;
|
|
19
|
+
readonly metadata?: Metadata;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
|
-
*
|
|
22
|
+
* Encodes an exact-shares Vault V2 redemption through VaultBundlesV1.
|
|
17
23
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
24
|
-
* @
|
|
25
|
-
* @
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* @throws {NonPositiveInputError} when `shares <= 0n`.
|
|
24
|
+
* @param params - Vault, shares, share permit, fee, and deadline values.
|
|
25
|
+
* @returns A deep-frozen VaultBundlesV1 redemption transaction.
|
|
26
|
+
* @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
|
|
27
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
28
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
29
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
30
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
31
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
32
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
33
|
+
* @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
|
|
29
34
|
* @example
|
|
30
35
|
* ```ts
|
|
31
36
|
* import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
|
|
37
|
+
* import { zeroAddress } from "viem";
|
|
32
38
|
*
|
|
33
39
|
* const tx = vaultV2Redeem({
|
|
34
|
-
* vault: { address:
|
|
35
|
-
* args: { shares: 1_000_000n,
|
|
40
|
+
* vault: { chainId: 1, address: zeroAddress },
|
|
41
|
+
* args: { shares: 1_000_000n, userAddress: zeroAddress, deadline: 1_900_000_000n },
|
|
36
42
|
* });
|
|
37
|
-
* // tx
|
|
43
|
+
* // tx.action.type === "vaultV2Redeem"
|
|
38
44
|
* ```
|
|
39
45
|
*/
|
|
40
|
-
export declare const vaultV2Redeem: (
|
|
46
|
+
export declare const vaultV2Redeem: (params: VaultV2RedeemParams) => Readonly<Transaction<VaultV2RedeemAction>>;
|
|
@@ -1,54 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
2
|
import { encodeFunctionData } from "viem";
|
|
4
|
-
import {
|
|
3
|
+
import { vaultBundlesV1Abi } from "../../abis.js";
|
|
4
|
+
import { validateUint256Field } from "../../helpers/validate.js";
|
|
5
5
|
import { NonPositiveInputError, } from "../../types/index.js";
|
|
6
|
+
import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBundlesCommonParams, } from "../bundles/common.js";
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Encodes an exact-shares Vault V2 redemption through VaultBundlesV1.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
* @throws {NonPositiveInputError} when `shares <= 0n`.
|
|
10
|
+
* @param params - Vault, shares, share permit, fee, and deadline values.
|
|
11
|
+
* @returns A deep-frozen VaultBundlesV1 redemption transaction.
|
|
12
|
+
* @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
|
|
13
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
14
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
15
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
16
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
17
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
18
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
19
|
+
* @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
22
22
|
* import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
|
|
23
|
+
* import { zeroAddress } from "viem";
|
|
23
24
|
*
|
|
24
25
|
* const tx = vaultV2Redeem({
|
|
25
|
-
* vault: { address:
|
|
26
|
-
* args: { shares: 1_000_000n,
|
|
26
|
+
* vault: { chainId: 1, address: zeroAddress },
|
|
27
|
+
* args: { shares: 1_000_000n, userAddress: zeroAddress, deadline: 1_900_000_000n },
|
|
27
28
|
* });
|
|
28
|
-
* // tx
|
|
29
|
+
* // tx.action.type === "vaultV2Redeem"
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
|
-
export const vaultV2Redeem = (
|
|
32
|
-
if (shares <= 0n) {
|
|
33
|
-
throw new NonPositiveInputError("shares", shares);
|
|
32
|
+
export const vaultV2Redeem = (params) => {
|
|
33
|
+
if (params.args.shares <= 0n) {
|
|
34
|
+
throw new NonPositiveInputError("shares", params.args.shares);
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
// Reject ABI overflow with SDK errors before calldata encoding.
|
|
37
|
+
validateUint256Field("shares", params.args.shares);
|
|
38
|
+
const common = normalizeBundlesCommonParams(params.args);
|
|
39
|
+
const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
|
|
40
|
+
const sharesPermit = getBundlesSharesPermit({
|
|
41
|
+
vault: params.vault.address,
|
|
42
|
+
deadline: common.deadline,
|
|
43
|
+
owner: params.args.userAddress,
|
|
44
|
+
spender,
|
|
45
|
+
amount: params.args.shares,
|
|
46
|
+
requirementSignature: params.args.requirementSignature,
|
|
47
|
+
});
|
|
48
|
+
return finalizeVaultBundlesV1Transaction({
|
|
49
|
+
chainId: params.vault.chainId,
|
|
50
|
+
value: 0n,
|
|
37
51
|
data: encodeFunctionData({
|
|
38
|
-
abi:
|
|
39
|
-
functionName: "
|
|
40
|
-
args: [
|
|
52
|
+
abi: vaultBundlesV1Abi,
|
|
53
|
+
functionName: "vaultBundlesV1Withdraw",
|
|
54
|
+
args: [
|
|
55
|
+
params.vault.address,
|
|
56
|
+
0n,
|
|
57
|
+
params.args.shares,
|
|
58
|
+
sharesPermit,
|
|
59
|
+
common.referralFeePct,
|
|
60
|
+
common.referralFeeRecipient,
|
|
61
|
+
common.deadline,
|
|
62
|
+
],
|
|
41
63
|
}),
|
|
42
|
-
value: 0n,
|
|
43
|
-
};
|
|
44
|
-
if (metadata) {
|
|
45
|
-
tx = addTransactionMetadata(tx, metadata);
|
|
46
|
-
}
|
|
47
|
-
return deepFreeze({
|
|
48
|
-
...tx,
|
|
49
64
|
action: {
|
|
50
65
|
type: "vaultV2Redeem",
|
|
51
|
-
args: {
|
|
66
|
+
args: {
|
|
67
|
+
vault: params.vault.address,
|
|
68
|
+
shares: params.args.shares,
|
|
69
|
+
referralFeePct: common.referralFeePct,
|
|
70
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
71
|
+
deadline: common.deadline,
|
|
72
|
+
},
|
|
52
73
|
},
|
|
74
|
+
metadata: params.metadata,
|
|
53
75
|
});
|
|
54
76
|
};
|
|
@@ -1,40 +1,73 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import { type Metadata, type Transaction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
2
|
+
import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link vaultV2Withdraw}. */
|
|
4
4
|
export interface VaultV2WithdrawParams {
|
|
5
|
-
vault: {
|
|
6
|
-
|
|
5
|
+
readonly vault: {
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly address: Address;
|
|
7
8
|
};
|
|
8
|
-
args: {
|
|
9
|
-
amount: bigint;
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
readonly args: {
|
|
10
|
+
readonly amount: bigint;
|
|
11
|
+
readonly userAddress: Address;
|
|
12
|
+
readonly recipient?: never;
|
|
13
|
+
readonly onBehalf?: never;
|
|
14
|
+
readonly requirementSignature?: Erc2612RequirementSignature;
|
|
15
|
+
readonly referralFeePct?: bigint;
|
|
16
|
+
readonly referralFeeRecipient?: Address;
|
|
17
|
+
readonly deadline: bigint;
|
|
12
18
|
};
|
|
13
|
-
metadata?: Metadata;
|
|
19
|
+
readonly metadata?: Metadata;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
|
-
*
|
|
22
|
+
* Encodes an exact-assets Vault V2 withdrawal through VaultBundlesV1.
|
|
17
23
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
24
|
+
* This low-level builder does not bind `permit.value` to a share cap; use
|
|
25
|
+
* `MorphoVaultV2.withdraw().buildTx()` to validate it against the cap from `getRequirements()`.
|
|
20
26
|
*
|
|
21
|
-
* @param params.vault.
|
|
22
|
-
* @param params.
|
|
23
|
-
* @param params.args.
|
|
24
|
-
* @param params.args.
|
|
25
|
-
* @param params.
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
|
|
28
|
+
* @param params.vault.address - Vault V2 whose shares are burned for the withdrawal.
|
|
29
|
+
* @param params.args.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
30
|
+
* @param params.args.userAddress - Share owner and transaction sender; receives the net withdrawn assets.
|
|
31
|
+
* @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
|
|
32
|
+
* @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
|
|
33
|
+
* @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
|
|
34
|
+
* and the registered VaultBundlesV1 spender. Omit when the exact share allowance is already set.
|
|
35
|
+
* @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
|
|
36
|
+
* The fee is rounded down and deducted from the gross withdrawn assets.
|
|
37
|
+
* @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
|
|
38
|
+
* when `referralFeePct > 0n`.
|
|
39
|
+
* @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
|
|
40
|
+
* execution reverts. This pure builder does not check the current time.
|
|
41
|
+
* @param params.metadata - Optional analytics metadata appended to the transaction calldata.
|
|
42
|
+
* @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
|
|
43
|
+
* @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
|
|
44
|
+
* @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` targeting VaultBundlesV1, with
|
|
45
|
+
* `to`, `value: 0n`, `data`, and gross/fee/net withdrawal action metadata.
|
|
46
|
+
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
47
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
|
|
48
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
49
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
50
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
51
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
52
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
53
|
+
* @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
|
|
54
|
+
* @throws {viem.BaseError} when transaction encoding fails.
|
|
29
55
|
* @example
|
|
30
56
|
* ```ts
|
|
31
57
|
* import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
|
|
58
|
+
* import type { Address } from "viem";
|
|
59
|
+
* import { mainnet } from "viem/chains";
|
|
32
60
|
*
|
|
33
|
-
*
|
|
34
|
-
* vault
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
61
|
+
* export function buildUsdcWithdrawal(userAddress: Address, deadline: bigint) {
|
|
62
|
+
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
63
|
+
* // Set the exact vault-share allowance before submitting; the entity API derives that cap.
|
|
64
|
+
* const tx = vaultV2Withdraw({
|
|
65
|
+
* vault: { chainId: mainnet.id, address: vault },
|
|
66
|
+
* args: { amount: 1_000_000n, userAddress, deadline },
|
|
67
|
+
* });
|
|
68
|
+
* // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
|
|
69
|
+
* return tx;
|
|
70
|
+
* }
|
|
38
71
|
* ```
|
|
39
72
|
*/
|
|
40
|
-
export declare const vaultV2Withdraw: (
|
|
73
|
+
export declare const vaultV2Withdraw: (params: VaultV2WithdrawParams) => Readonly<Transaction<VaultV2WithdrawAction>>;
|