@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,85 +1,62 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link vaultV1MigrateToV2}. */
|
|
4
4
|
export interface VaultV1MigrateToV2Params {
|
|
5
|
-
vault: {
|
|
6
|
-
chainId: number;
|
|
7
|
-
address: Address;
|
|
8
|
-
|
|
9
|
-
asset: Address;
|
|
5
|
+
readonly vault: {
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly address: Address;
|
|
8
|
+
readonly asset: Address;
|
|
10
9
|
};
|
|
11
|
-
args: {
|
|
12
|
-
targetVault: Address;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
recipient: Address;
|
|
23
|
-
/** Pre-signed permit/permit2 approval for V1 share transfer. */
|
|
24
|
-
requirementSignature?: PermitRequirementSignature;
|
|
10
|
+
readonly args: VaultV1MigrateToV2AmountArgs & {
|
|
11
|
+
readonly targetVault: Address;
|
|
12
|
+
readonly targetAsset: Address;
|
|
13
|
+
readonly maxSharePriceVaultV2: bigint;
|
|
14
|
+
readonly userAddress: Address;
|
|
15
|
+
readonly recipient?: never;
|
|
16
|
+
readonly minSharePriceVaultV1?: never;
|
|
17
|
+
readonly requirementSignature?: Erc2612RequirementSignature;
|
|
18
|
+
readonly referralFeePct?: bigint;
|
|
19
|
+
readonly referralFeeRecipient?: Address;
|
|
20
|
+
readonly deadline: bigint;
|
|
25
21
|
};
|
|
26
|
-
metadata?: Metadata;
|
|
22
|
+
readonly metadata?: Metadata;
|
|
27
23
|
}
|
|
28
24
|
/**
|
|
29
|
-
*
|
|
25
|
+
* Encodes an assets-or-shares Vault V1 to Vault V2 migration through VaultBundlesV1.
|
|
30
26
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
42
|
-
* @
|
|
43
|
-
* @
|
|
44
|
-
* @param params.args.targetVault - The target VaultV2 address.
|
|
45
|
-
* @param params.args.targetAsset - The underlying asset of the target V2 vault. Must equal
|
|
46
|
-
* `vault.asset`.
|
|
47
|
-
* @param params.args.shares - Number of V1 shares to migrate.
|
|
48
|
-
* @param params.args.minSharePriceVaultV1 - Minimum V1 share price in RAY (slippage protection
|
|
49
|
-
* for the redeem leg).
|
|
50
|
-
* @param params.args.maxSharePriceVaultV2 - Maximum V2 share price in RAY (inflation protection
|
|
51
|
-
* for the deposit leg).
|
|
52
|
-
* @param params.args.recipient - Address that receives the V2 vault shares.
|
|
53
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
|
|
54
|
-
* transfer.
|
|
55
|
-
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
56
|
-
* @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
|
|
57
|
-
* the typed `action` discriminator the simulation layer consumes.
|
|
58
|
-
* @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
|
|
59
|
-
* @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
|
|
60
|
-
* @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
|
|
61
|
-
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
62
|
-
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
63
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
64
|
-
* is provided and the signed amount differs from `args.shares`.
|
|
65
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
66
|
-
* signature is missing its expiration.
|
|
27
|
+
* @param params - Source/destination vaults, exclusive migration amount, fee, permit, and deadline.
|
|
28
|
+
* @returns A deep-frozen VaultBundlesV1 migration transaction.
|
|
29
|
+
* @throws {VaultAssetMismatchError} when source and destination assets differ.
|
|
30
|
+
* @throws {SameVaultMigrationError} when source and destination vaults are identical.
|
|
31
|
+
* @throws {AmountAndSharesExclusiveError} when both amount modes or neither are supplied.
|
|
32
|
+
* @throws {NonPositiveInputError} when the selected amount, destination share-price bound, or deadline is not positive.
|
|
33
|
+
* @throws {InputExceedsMaxError} when the selected amount, `maxSharePriceVaultV2`, or `deadline` exceeds uint256.
|
|
34
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
35
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
36
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
37
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
38
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
39
|
+
* @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
|
|
67
40
|
* @example
|
|
68
41
|
* ```ts
|
|
69
42
|
* import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
|
|
70
43
|
*
|
|
71
44
|
* const tx = vaultV1MigrateToV2({
|
|
72
|
-
* vault: {
|
|
45
|
+
* vault: {
|
|
46
|
+
* chainId: 1,
|
|
47
|
+
* address: "0x0000000000000000000000000000000000000001",
|
|
48
|
+
* asset: "0x0000000000000000000000000000000000000003",
|
|
49
|
+
* },
|
|
73
50
|
* args: {
|
|
74
|
-
* targetVault,
|
|
75
|
-
* targetAsset: USDC,
|
|
76
51
|
* shares: 1_000_000n,
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
52
|
+
* targetVault: "0x0000000000000000000000000000000000000002",
|
|
53
|
+
* targetAsset: "0x0000000000000000000000000000000000000003",
|
|
54
|
+
* maxSharePriceVaultV2: 1_000_000_000_000_000_000_000_000_000n,
|
|
55
|
+
* userAddress: "0x0000000000000000000000000000000000000004",
|
|
56
|
+
* deadline: 1_900_000_000n,
|
|
80
57
|
* },
|
|
81
58
|
* });
|
|
82
|
-
* // tx
|
|
59
|
+
* // tx.action.type === "vaultV1MigrateToV2"
|
|
83
60
|
* ```
|
|
84
61
|
*/
|
|
85
|
-
export declare const vaultV1MigrateToV2: (
|
|
62
|
+
export declare const vaultV1MigrateToV2: (params: VaultV1MigrateToV2Params) => Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
@@ -1,132 +1,119 @@
|
|
|
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, isAddressEqual } from "viem";
|
|
3
|
+
import { vaultBundlesV1Abi } from "../../abis.js";
|
|
4
|
+
import { validateUint256Field } from "../../helpers/validate.js";
|
|
5
|
+
import { AmountAndSharesExclusiveError, NonPositiveInputError, SameVaultMigrationError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
6
|
+
import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBundlesSharesPermit, normalizeBundlesCommonParams, } from "../bundles/common.js";
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
8
|
+
* Encodes an assets-or-shares Vault V1 to Vault V2 migration through VaultBundlesV1.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
24
|
-
* @param params.args.targetVault - The target VaultV2 address.
|
|
25
|
-
* @param params.args.targetAsset - The underlying asset of the target V2 vault. Must equal
|
|
26
|
-
* `vault.asset`.
|
|
27
|
-
* @param params.args.shares - Number of V1 shares to migrate.
|
|
28
|
-
* @param params.args.minSharePriceVaultV1 - Minimum V1 share price in RAY (slippage protection
|
|
29
|
-
* for the redeem leg).
|
|
30
|
-
* @param params.args.maxSharePriceVaultV2 - Maximum V2 share price in RAY (inflation protection
|
|
31
|
-
* for the deposit leg).
|
|
32
|
-
* @param params.args.recipient - Address that receives the V2 vault shares.
|
|
33
|
-
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 for the V1 share
|
|
34
|
-
* transfer.
|
|
35
|
-
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
36
|
-
* @returns A deep-frozen `Transaction<VaultV1MigrateToV2Action>` with `to`, `value`, `data`, and
|
|
37
|
-
* the typed `action` discriminator the simulation layer consumes.
|
|
38
|
-
* @throws {VaultAssetMismatchError} when `targetAsset` differs from `vault.asset`.
|
|
39
|
-
* @throws {NonPositiveInputError} when `shares <= 0n` or `maxSharePriceVaultV2 <= 0n`.
|
|
40
|
-
* @throws {NegativeInputError} when `minSharePriceVaultV1 < 0n`.
|
|
41
|
-
* @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
42
|
-
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
43
|
-
* @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature`
|
|
44
|
-
* is provided and the signed amount differs from `args.shares`.
|
|
45
|
-
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
46
|
-
* signature is missing its expiration.
|
|
10
|
+
* @param params - Source/destination vaults, exclusive migration amount, fee, permit, and deadline.
|
|
11
|
+
* @returns A deep-frozen VaultBundlesV1 migration transaction.
|
|
12
|
+
* @throws {VaultAssetMismatchError} when source and destination assets differ.
|
|
13
|
+
* @throws {SameVaultMigrationError} when source and destination vaults are identical.
|
|
14
|
+
* @throws {AmountAndSharesExclusiveError} when both amount modes or neither are supplied.
|
|
15
|
+
* @throws {NonPositiveInputError} when the selected amount, destination share-price bound, or deadline is not positive.
|
|
16
|
+
* @throws {InputExceedsMaxError} when the selected amount, `maxSharePriceVaultV2`, or `deadline` exceeds uint256.
|
|
17
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
18
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
19
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
20
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
21
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
22
|
+
* @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
|
|
47
23
|
* @example
|
|
48
24
|
* ```ts
|
|
49
25
|
* import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
|
|
50
26
|
*
|
|
51
27
|
* const tx = vaultV1MigrateToV2({
|
|
52
|
-
* vault: {
|
|
28
|
+
* vault: {
|
|
29
|
+
* chainId: 1,
|
|
30
|
+
* address: "0x0000000000000000000000000000000000000001",
|
|
31
|
+
* asset: "0x0000000000000000000000000000000000000003",
|
|
32
|
+
* },
|
|
53
33
|
* args: {
|
|
54
|
-
* targetVault,
|
|
55
|
-
* targetAsset: USDC,
|
|
56
34
|
* shares: 1_000_000n,
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
35
|
+
* targetVault: "0x0000000000000000000000000000000000000002",
|
|
36
|
+
* targetAsset: "0x0000000000000000000000000000000000000003",
|
|
37
|
+
* maxSharePriceVaultV2: 1_000_000_000_000_000_000_000_000_000n,
|
|
38
|
+
* userAddress: "0x0000000000000000000000000000000000000004",
|
|
39
|
+
* deadline: 1_900_000_000n,
|
|
60
40
|
* },
|
|
61
41
|
* });
|
|
62
|
-
* // tx
|
|
42
|
+
* // tx.action.type === "vaultV1MigrateToV2"
|
|
63
43
|
* ```
|
|
64
44
|
*/
|
|
65
|
-
export const vaultV1MigrateToV2 = (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!isAddressEqual(sourceAsset, targetAsset)) {
|
|
69
|
-
throw new VaultAssetMismatchError(sourceAsset, targetAsset);
|
|
45
|
+
export const vaultV1MigrateToV2 = (params) => {
|
|
46
|
+
if (!isAddressEqual(params.vault.asset, params.args.targetAsset)) {
|
|
47
|
+
throw new VaultAssetMismatchError(params.vault.asset, params.args.targetAsset);
|
|
70
48
|
}
|
|
71
|
-
if (
|
|
72
|
-
throw new
|
|
49
|
+
if (isAddressEqual(params.vault.address, params.args.targetVault)) {
|
|
50
|
+
throw new SameVaultMigrationError(params.vault.address);
|
|
73
51
|
}
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
const assets = "assets" in params.args ? params.args.assets : undefined;
|
|
53
|
+
const shares = "shares" in params.args ? params.args.shares : undefined;
|
|
54
|
+
if ((assets == null) === (shares == null)) {
|
|
55
|
+
throw new AmountAndSharesExclusiveError();
|
|
76
56
|
}
|
|
77
|
-
|
|
78
|
-
|
|
57
|
+
const selectedAmount = assets ?? shares ?? 0n;
|
|
58
|
+
if (selectedAmount <= 0n) {
|
|
59
|
+
throw new NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
|
|
79
60
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
61
|
+
if (params.args.maxSharePriceVaultV2 <= 0n) {
|
|
62
|
+
throw new NonPositiveInputError("maxSharePriceVaultV2", params.args.maxSharePriceVaultV2);
|
|
63
|
+
}
|
|
64
|
+
// Reject ABI overflow with SDK errors before calldata encoding.
|
|
65
|
+
validateUint256Field(assets != null ? "assets" : "shares", selectedAmount);
|
|
66
|
+
validateUint256Field("maxSharePriceVaultV2", params.args.maxSharePriceVaultV2);
|
|
67
|
+
const common = normalizeBundlesCommonParams(params.args);
|
|
68
|
+
const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
|
|
69
|
+
const sharesPermit = getBundlesSharesPermit({
|
|
70
|
+
vault: params.vault.address,
|
|
71
|
+
deadline: common.deadline,
|
|
72
|
+
owner: params.args.userAddress,
|
|
73
|
+
spender,
|
|
87
74
|
amount: shares,
|
|
88
|
-
|
|
89
|
-
requirementSignature,
|
|
90
|
-
}));
|
|
91
|
-
// GA1 redeems its own shares (owner = GA1, no allowance check).
|
|
92
|
-
actions.push({
|
|
93
|
-
type: "erc4626Redeem",
|
|
94
|
-
args: [
|
|
95
|
-
sourceVault,
|
|
96
|
-
maxUint256,
|
|
97
|
-
minSharePriceVaultV1,
|
|
98
|
-
generalAdapter1,
|
|
99
|
-
generalAdapter1,
|
|
100
|
-
false /* skipRevert */,
|
|
101
|
-
],
|
|
102
|
-
});
|
|
103
|
-
// Deposit all resulting assets into V2.
|
|
104
|
-
actions.push({
|
|
105
|
-
type: "erc4626Deposit",
|
|
106
|
-
args: [
|
|
107
|
-
targetVault,
|
|
108
|
-
maxUint256,
|
|
109
|
-
maxSharePriceVaultV2,
|
|
110
|
-
recipient,
|
|
111
|
-
false /* skipRevert */,
|
|
112
|
-
],
|
|
75
|
+
requirementSignature: params.args.requirementSignature,
|
|
113
76
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
77
|
+
const referralFeeAssets = assets == null
|
|
78
|
+
? undefined
|
|
79
|
+
: getBundlesReferralFeeAssets(assets, common.referralFeePct);
|
|
80
|
+
return finalizeVaultBundlesV1Transaction({
|
|
81
|
+
chainId: params.vault.chainId,
|
|
82
|
+
value: 0n,
|
|
83
|
+
data: encodeFunctionData({
|
|
84
|
+
abi: vaultBundlesV1Abi,
|
|
85
|
+
functionName: "vaultBundlesV1Migrate",
|
|
86
|
+
args: [
|
|
87
|
+
params.vault.address,
|
|
88
|
+
params.args.targetVault,
|
|
89
|
+
assets ?? 0n,
|
|
90
|
+
shares ?? 0n,
|
|
91
|
+
params.args.maxSharePriceVaultV2,
|
|
92
|
+
sharesPermit,
|
|
93
|
+
common.referralFeePct,
|
|
94
|
+
common.referralFeeRecipient,
|
|
95
|
+
common.deadline,
|
|
96
|
+
],
|
|
97
|
+
}),
|
|
120
98
|
action: {
|
|
121
99
|
type: "vaultV1MigrateToV2",
|
|
122
100
|
args: {
|
|
123
|
-
sourceVault,
|
|
124
|
-
targetVault,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
maxSharePriceVaultV2,
|
|
128
|
-
|
|
101
|
+
sourceVault: params.vault.address,
|
|
102
|
+
targetVault: params.args.targetVault,
|
|
103
|
+
assets: assets ?? 0n,
|
|
104
|
+
shares: shares ?? 0n,
|
|
105
|
+
maxSharePriceVaultV2: params.args.maxSharePriceVaultV2,
|
|
106
|
+
referralFeePct: common.referralFeePct,
|
|
107
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
108
|
+
...(assets != null && referralFeeAssets != null
|
|
109
|
+
? {
|
|
110
|
+
referralFeeAssets,
|
|
111
|
+
netAssets: assets - referralFeeAssets,
|
|
112
|
+
}
|
|
113
|
+
: {}),
|
|
114
|
+
deadline: common.deadline,
|
|
129
115
|
},
|
|
130
116
|
},
|
|
117
|
+
metadata: params.metadata,
|
|
131
118
|
});
|
|
132
119
|
};
|
|
@@ -1,39 +1,46 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import { type Metadata, type Transaction, type VaultV1RedeemAction } from "../../types/index.js";
|
|
2
|
+
import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV1RedeemAction } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link vaultV1Redeem}. */
|
|
4
4
|
export interface VaultV1RedeemParams {
|
|
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 V1 redemption through VaultBundlesV1.
|
|
17
23
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
24
|
-
* @
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
27
|
-
* @throws {
|
|
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.
|
|
28
34
|
* @example
|
|
29
35
|
* ```ts
|
|
30
36
|
* import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
37
|
+
* import { zeroAddress } from "viem";
|
|
31
38
|
*
|
|
32
39
|
* const tx = vaultV1Redeem({
|
|
33
|
-
* vault: { address:
|
|
34
|
-
* args: { shares: 1_000_000n,
|
|
40
|
+
* vault: { chainId: 1, address: zeroAddress },
|
|
41
|
+
* args: { shares: 1_000_000n, userAddress: zeroAddress, deadline: 1_900_000_000n },
|
|
35
42
|
* });
|
|
36
|
-
* // tx
|
|
43
|
+
* // tx.action.type === "vaultV1Redeem"
|
|
37
44
|
* ```
|
|
38
45
|
*/
|
|
39
|
-
export declare const vaultV1Redeem: (
|
|
46
|
+
export declare const vaultV1Redeem: (params: VaultV1RedeemParams) => Readonly<Transaction<VaultV1RedeemAction>>;
|
|
@@ -1,53 +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 V1 redemption through VaultBundlesV1.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
16
|
-
* @
|
|
17
|
-
*
|
|
18
|
-
* @throws {
|
|
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.
|
|
19
20
|
* @example
|
|
20
21
|
* ```ts
|
|
21
22
|
* import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
23
|
+
* import { zeroAddress } from "viem";
|
|
22
24
|
*
|
|
23
25
|
* const tx = vaultV1Redeem({
|
|
24
|
-
* vault: { address:
|
|
25
|
-
* args: { shares: 1_000_000n,
|
|
26
|
+
* vault: { chainId: 1, address: zeroAddress },
|
|
27
|
+
* args: { shares: 1_000_000n, userAddress: zeroAddress, deadline: 1_900_000_000n },
|
|
26
28
|
* });
|
|
27
|
-
* // tx
|
|
29
|
+
* // tx.action.type === "vaultV1Redeem"
|
|
28
30
|
* ```
|
|
29
31
|
*/
|
|
30
|
-
export const vaultV1Redeem = (
|
|
31
|
-
if (shares <= 0n) {
|
|
32
|
-
throw new NonPositiveInputError("shares", shares);
|
|
32
|
+
export const vaultV1Redeem = (params) => {
|
|
33
|
+
if (params.args.shares <= 0n) {
|
|
34
|
+
throw new NonPositiveInputError("shares", params.args.shares);
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
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,
|
|
36
51
|
data: encodeFunctionData({
|
|
37
|
-
abi:
|
|
38
|
-
functionName: "
|
|
39
|
-
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
|
+
],
|
|
40
63
|
}),
|
|
41
|
-
value: 0n,
|
|
42
|
-
};
|
|
43
|
-
if (metadata) {
|
|
44
|
-
tx = addTransactionMetadata(tx, metadata);
|
|
45
|
-
}
|
|
46
|
-
return deepFreeze({
|
|
47
|
-
...tx,
|
|
48
64
|
action: {
|
|
49
65
|
type: "vaultV1Redeem",
|
|
50
|
-
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
|
+
},
|
|
51
73
|
},
|
|
74
|
+
metadata: params.metadata,
|
|
52
75
|
});
|
|
53
76
|
};
|