@morpho-org/morpho-sdk 2.1.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/abis.d.ts +2816 -0
- package/lib/cjs/abis.js +1951 -0
- package/lib/cjs/actions/index.d.ts +3 -0
- package/lib/cjs/actions/marketV1/borrow.js +7 -10
- package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +2 -3
- package/lib/cjs/actions/marketV1/buildReallocationActions.js +1 -2
- package/lib/cjs/actions/marketV1/index.d.ts +2 -0
- package/lib/cjs/actions/marketV1/index.js +2 -0
- package/lib/cjs/actions/marketV1/repay.d.ts +2 -0
- package/lib/cjs/actions/marketV1/repay.js +7 -8
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +9 -10
- package/lib/cjs/actions/marketV1/supply.d.ts +69 -0
- package/lib/cjs/actions/marketV1/supply.js +128 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +3 -1
- package/lib/cjs/actions/marketV1/supplyCollateral.js +12 -13
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +14 -15
- package/lib/cjs/actions/marketV1/withdraw.d.ts +83 -0
- package/lib/cjs/actions/marketV1/withdraw.js +110 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -2
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
- package/lib/cjs/actions/vaultV1/deposit.js +13 -14
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
- package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
- package/lib/cjs/actions/vaultV2/deposit.js +13 -14
- package/lib/cjs/addresses.d.ts +2 -0
- package/lib/cjs/addresses.js +18 -0
- package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
- package/lib/cjs/augment/AccrualPosition.js +8 -0
- package/lib/cjs/augment/AccrualVault.d.ts +8 -0
- package/lib/cjs/augment/AccrualVault.js +7 -0
- package/lib/cjs/augment/Holding.d.ts +8 -0
- package/lib/cjs/augment/Holding.js +7 -0
- package/lib/cjs/augment/Market.d.ts +8 -0
- package/lib/cjs/augment/Market.js +7 -0
- package/lib/cjs/augment/MarketParams.d.ts +8 -0
- package/lib/cjs/augment/MarketParams.js +7 -0
- package/lib/cjs/augment/Position.d.ts +8 -0
- package/lib/cjs/augment/Position.js +7 -0
- package/lib/cjs/augment/Token.d.ts +8 -0
- package/lib/cjs/augment/Token.js +7 -0
- package/lib/cjs/augment/User.d.ts +8 -0
- package/lib/cjs/augment/User.js +7 -0
- package/lib/cjs/augment/Vault.d.ts +8 -0
- package/lib/cjs/augment/Vault.js +7 -0
- package/lib/cjs/augment/VaultConfig.d.ts +8 -0
- package/lib/cjs/augment/VaultConfig.js +7 -0
- package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
- package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
- package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
- package/lib/cjs/augment/VaultMarketConfig.js +7 -0
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
- package/lib/cjs/augment/VaultUser.d.ts +8 -0
- package/lib/cjs/augment/VaultUser.js +7 -0
- package/lib/cjs/augment.d.ts +14 -0
- package/lib/cjs/augment.js +16 -0
- package/lib/cjs/bundler/actions.d.ts +637 -0
- package/lib/cjs/bundler/actions.js +1088 -0
- package/lib/cjs/bundler/index.d.ts +2 -0
- package/lib/cjs/bundler/index.js +18 -0
- package/lib/cjs/bundler/types.d.ts +200 -0
- package/lib/cjs/bundler/types.js +2 -0
- package/lib/cjs/constants.d.ts +3 -0
- package/lib/cjs/constants.js +32 -0
- package/lib/cjs/entities/index.d.ts +6 -3
- package/lib/cjs/entities/index.js +41 -17
- package/lib/cjs/entities/marketV1/marketV1.d.ts +161 -24
- package/lib/cjs/entities/marketV1/marketV1.js +166 -19
- package/lib/cjs/entities/reallocationData.d.ts +193 -0
- package/lib/cjs/entities/reallocationData.js +406 -0
- package/lib/cjs/errors.d.ts +2 -0
- package/lib/cjs/errors.js +18 -0
- package/lib/cjs/fetch.d.ts +1 -0
- package/lib/cjs/fetch.js +30 -0
- package/lib/cjs/format.d.ts +2 -0
- package/lib/cjs/format.js +22 -0
- package/lib/cjs/helpers/computeReallocations.d.ts +63 -12
- package/lib/cjs/helpers/computeReallocations.js +160 -41
- package/lib/cjs/helpers/constant.d.ts +17 -0
- package/lib/cjs/helpers/constant.js +30 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +14 -2
- package/lib/cjs/helpers/slippage.d.ts +57 -0
- package/lib/cjs/helpers/slippage.js +82 -0
- package/lib/cjs/helpers/validate.d.ts +40 -7
- package/lib/cjs/helpers/validate.js +67 -12
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/types/action.d.ts +27 -6
- package/lib/cjs/types/client.d.ts +1 -1
- package/lib/cjs/types/error.d.ts +155 -7
- package/lib/cjs/types/error.js +202 -11
- package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
- package/lib/cjs/types.d.ts +3 -0
- package/lib/cjs/types.js +17 -0
- package/lib/cjs/utils.d.ts +9 -0
- package/lib/cjs/utils.js +65 -0
- package/lib/esm/abis.d.ts +2816 -0
- package/lib/esm/abis.js +1922 -0
- package/lib/esm/actions/index.d.ts +3 -0
- package/lib/esm/actions/marketV1/borrow.js +2 -5
- package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
- package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
- package/lib/esm/actions/marketV1/index.d.ts +2 -0
- package/lib/esm/actions/marketV1/index.js +2 -0
- package/lib/esm/actions/marketV1/repay.d.ts +2 -0
- package/lib/esm/actions/marketV1/repay.js +4 -5
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
- package/lib/esm/actions/marketV1/supply.d.ts +69 -0
- package/lib/esm/actions/marketV1/supply.js +124 -0
- package/lib/esm/actions/marketV1/supplyCollateral.d.ts +3 -1
- package/lib/esm/actions/marketV1/supplyCollateral.js +7 -8
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +7 -8
- package/lib/esm/actions/marketV1/withdraw.d.ts +83 -0
- package/lib/esm/actions/marketV1/withdraw.js +106 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
- package/lib/esm/actions/vaultV1/deposit.js +3 -4
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
- package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
- package/lib/esm/actions/vaultV2/deposit.js +3 -4
- package/lib/esm/addresses.d.ts +2 -0
- package/lib/esm/addresses.js +1 -0
- package/lib/esm/augment/AccrualPosition.d.ts +9 -0
- package/lib/esm/augment/AccrualPosition.js +5 -0
- package/lib/esm/augment/AccrualVault.d.ts +8 -0
- package/lib/esm/augment/AccrualVault.js +4 -0
- package/lib/esm/augment/Holding.d.ts +8 -0
- package/lib/esm/augment/Holding.js +4 -0
- package/lib/esm/augment/Market.d.ts +8 -0
- package/lib/esm/augment/Market.js +4 -0
- package/lib/esm/augment/MarketParams.d.ts +8 -0
- package/lib/esm/augment/MarketParams.js +4 -0
- package/lib/esm/augment/Position.d.ts +8 -0
- package/lib/esm/augment/Position.js +4 -0
- package/lib/esm/augment/Token.d.ts +8 -0
- package/lib/esm/augment/Token.js +4 -0
- package/lib/esm/augment/User.d.ts +8 -0
- package/lib/esm/augment/User.js +4 -0
- package/lib/esm/augment/Vault.d.ts +8 -0
- package/lib/esm/augment/Vault.js +4 -0
- package/lib/esm/augment/VaultConfig.d.ts +8 -0
- package/lib/esm/augment/VaultConfig.js +4 -0
- package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
- package/lib/esm/augment/VaultMarketAllocation.js +4 -0
- package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
- package/lib/esm/augment/VaultMarketConfig.js +4 -0
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
- package/lib/esm/augment/VaultUser.d.ts +8 -0
- package/lib/esm/augment/VaultUser.js +4 -0
- package/lib/esm/augment.d.ts +14 -0
- package/lib/esm/augment.js +14 -0
- package/lib/esm/bundler/actions.d.ts +637 -0
- package/lib/esm/bundler/actions.js +1085 -0
- package/lib/esm/bundler/index.d.ts +2 -0
- package/lib/esm/bundler/index.js +2 -0
- package/lib/esm/bundler/types.d.ts +200 -0
- package/lib/esm/bundler/types.js +1 -0
- package/lib/esm/constants.d.ts +3 -0
- package/lib/esm/constants.js +3 -0
- package/lib/esm/entities/index.d.ts +6 -3
- package/lib/esm/entities/index.js +5 -3
- package/lib/esm/entities/marketV1/marketV1.d.ts +161 -24
- package/lib/esm/entities/marketV1/marketV1.js +170 -23
- package/lib/esm/entities/reallocationData.d.ts +193 -0
- package/lib/esm/entities/reallocationData.js +402 -0
- package/lib/esm/errors.d.ts +2 -0
- package/lib/esm/errors.js +1 -0
- package/lib/esm/fetch.d.ts +1 -0
- package/lib/esm/fetch.js +1 -0
- package/lib/esm/format.d.ts +2 -0
- package/lib/esm/format.js +1 -0
- package/lib/esm/helpers/computeReallocations.d.ts +63 -12
- package/lib/esm/helpers/computeReallocations.js +160 -41
- package/lib/esm/helpers/constant.d.ts +17 -0
- package/lib/esm/helpers/constant.js +30 -1
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/slippage.d.ts +57 -0
- package/lib/esm/helpers/slippage.js +80 -0
- package/lib/esm/helpers/validate.d.ts +40 -7
- package/lib/esm/helpers/validate.js +63 -11
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/types/action.d.ts +27 -6
- package/lib/esm/types/client.d.ts +1 -1
- package/lib/esm/types/error.d.ts +155 -7
- package/lib/esm/types/error.js +185 -9
- package/lib/esm/types/sharedLiquidity.d.ts +43 -3
- package/lib/esm/types.d.ts +3 -0
- package/lib/esm/types.js +1 -0
- package/lib/esm/utils.d.ts +9 -0
- package/lib/esm/utils.js +7 -0
- package/package.json +128 -17
- package/src/index.ts +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
3
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
+
import { MutuallyExclusiveWithdrawAmountsError, NegativeWithdrawMinSharePriceError, NonPositiveWithdrawAmountError, } from "../../types/index.js";
|
|
5
|
+
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
6
|
+
/**
|
|
7
|
+
* Prepares a loan-asset withdraw transaction for a Morpho Blue market.
|
|
8
|
+
*
|
|
9
|
+
* Routed through bundler3 via `morphoWithdraw`. Supports two modes (exactly one):
|
|
10
|
+
*
|
|
11
|
+
* - **By assets** (`assets > 0, shares = 0`): withdraws an exact asset amount.
|
|
12
|
+
* - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
|
|
13
|
+
* supplier position close; immune to interest accrual between tx construction and execution).
|
|
14
|
+
*
|
|
15
|
+
* When `reallocations` are provided, `reallocateTo` actions are prepended to the bundle, moving
|
|
16
|
+
* liquidity from other markets into this one via the PublicAllocator before withdrawing.
|
|
17
|
+
* Reallocation fees accumulate in `tx.value`. The on-chain `morphoWithdraw` sends the assets
|
|
18
|
+
* computed on-chain directly to `receiver`; no skim is required.
|
|
19
|
+
*
|
|
20
|
+
* The withdraw is performed on behalf of the transaction initiator (signer) — there is no
|
|
21
|
+
* separate `onBehalf` field; mirror `marketV1Borrow`. The entity layer keeps `receiver` aligned
|
|
22
|
+
* with the user when none is provided. Requires the user to have authorized `GeneralAdapter1`
|
|
23
|
+
* on Morpho.
|
|
24
|
+
*
|
|
25
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
26
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
27
|
+
* @param params.args.assets - Withdraw amount in loan-token assets. Set to `0n` in shares mode.
|
|
28
|
+
* @param params.args.shares - Withdraw amount in supply shares. Set to `0n` in assets mode.
|
|
29
|
+
* @param params.args.receiver - Address that receives the withdrawn assets.
|
|
30
|
+
* @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
|
|
31
|
+
* protection.
|
|
32
|
+
* @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
|
|
33
|
+
* computed by the entity layer.
|
|
34
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
35
|
+
* @returns A deep-frozen `Transaction<MarketV1WithdrawAction>` with `to`, `value`, `data`, and
|
|
36
|
+
* the typed `action` discriminator the simulation layer consumes.
|
|
37
|
+
* @throws {NonPositiveWithdrawAmountError} when both `assets` and `shares` are zero, or either is negative.
|
|
38
|
+
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
39
|
+
* @throws {NegativeWithdrawMinSharePriceError} when `minSharePrice < 0n` (zero is allowed despite
|
|
40
|
+
* the class name — pattern preserved for symmetry with `marketV1Borrow`).
|
|
41
|
+
* @throws Reallocation errors from `buildReallocationActions` when `reallocations` is malformed
|
|
42
|
+
* (see its JSDoc: `NegativeReallocationFeeError`, `EmptyReallocationWithdrawalsError`,
|
|
43
|
+
* `NonPositiveReallocationAmountError`, `ReallocationWithdrawalOnTargetMarketError`,
|
|
44
|
+
* `UnsortedReallocationWithdrawalsError`).
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { marketV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
48
|
+
*
|
|
49
|
+
* const tx = marketV1Withdraw({
|
|
50
|
+
* market: { chainId: 1, marketParams },
|
|
51
|
+
* args: {
|
|
52
|
+
* assets: 1_000_000_000n,
|
|
53
|
+
* shares: 0n,
|
|
54
|
+
* receiver: supplier,
|
|
55
|
+
* minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinWithdrawSharePrice` from market state + slippage tolerance
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
* // tx satisfies Readonly<Transaction<MarketV1WithdrawAction>>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export const marketV1Withdraw = ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }) => {
|
|
62
|
+
// Mutual exclusion is detected on "both values present" (either non-zero),
|
|
63
|
+
// before sign checks — otherwise `{ assets: -1n, shares: 5n }` would be
|
|
64
|
+
// misreported as a positivity error rather than the actual mode conflict.
|
|
65
|
+
if (assets !== 0n && shares !== 0n) {
|
|
66
|
+
throw new MutuallyExclusiveWithdrawAmountsError(marketParams.id);
|
|
67
|
+
}
|
|
68
|
+
if (assets < 0n || shares < 0n || (assets === 0n && shares === 0n)) {
|
|
69
|
+
throw new NonPositiveWithdrawAmountError(marketParams.id);
|
|
70
|
+
}
|
|
71
|
+
if (minSharePrice < 0n) {
|
|
72
|
+
throw new NegativeWithdrawMinSharePriceError(marketParams.id);
|
|
73
|
+
}
|
|
74
|
+
const actions = [];
|
|
75
|
+
let reallocationFee = 0n;
|
|
76
|
+
if (reallocations && reallocations.length > 0) {
|
|
77
|
+
const result = buildReallocationActions(reallocations, marketParams);
|
|
78
|
+
actions.push(...result.actions);
|
|
79
|
+
reallocationFee = result.fee;
|
|
80
|
+
}
|
|
81
|
+
actions.push({
|
|
82
|
+
type: "morphoWithdraw",
|
|
83
|
+
args: [marketParams, assets, shares, minSharePrice, receiver, false],
|
|
84
|
+
});
|
|
85
|
+
let tx = {
|
|
86
|
+
...BundlerAction.encodeBundle(chainId, actions),
|
|
87
|
+
value: reallocationFee,
|
|
88
|
+
};
|
|
89
|
+
if (metadata) {
|
|
90
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
91
|
+
}
|
|
92
|
+
return deepFreeze({
|
|
93
|
+
...tx,
|
|
94
|
+
action: {
|
|
95
|
+
type: "marketV1Withdraw",
|
|
96
|
+
args: {
|
|
97
|
+
market: marketParams.id,
|
|
98
|
+
assets,
|
|
99
|
+
shares,
|
|
100
|
+
receiver,
|
|
101
|
+
minSharePrice,
|
|
102
|
+
reallocationFee,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MathLib } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { MAX_TOKEN_APPROVALS } from "@morpho-org/simulation-sdk";
|
|
4
3
|
import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
|
|
4
|
+
import { MAX_TOKEN_APPROVALS } from "../../../helpers/constant.js";
|
|
5
5
|
/**
|
|
6
6
|
* Encodes a deep-frozen ERC-20 `approve(spender, amount)` transaction.
|
|
7
7
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Action } from "@morpho-org/bundler-sdk-viem";
|
|
2
1
|
import { type Address } from "viem";
|
|
2
|
+
import type { Action } from "../../bundler/index.js";
|
|
3
3
|
import { type Permit2Action, type PermitAction, type PermitArgs } from "../../types/index.js";
|
|
4
4
|
interface GetRequirementsActionParams {
|
|
5
5
|
asset: Address;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APPROVE_ONLY_ONCE_TOKENS } from "
|
|
1
|
+
import { APPROVE_ONLY_ONCE_TOKENS } from "../../helpers/constant.js";
|
|
2
2
|
import { ApprovalAmountLessThanSpendAmountError, } from "../../types/index.js";
|
|
3
3
|
import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
|
|
4
4
|
/**
|
|
@@ -53,6 +53,8 @@ export interface VaultV1DepositParams {
|
|
|
53
53
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
54
54
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
55
55
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
56
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when `amount > 0n` and a
|
|
57
|
+
* Permit2 requirement signature is missing its expiration.
|
|
56
58
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
57
59
|
* @example
|
|
58
60
|
* ```ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
3
2
|
import { deepFreeze, isDefined } from "@morpho-org/morpho-ts";
|
|
4
3
|
import { isAddressEqual } from "viem";
|
|
4
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
6
|
import { ChainWNativeMissingError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveMaxSharePriceError, ZeroDepositAmountError, } from "../../types/index.js";
|
|
7
7
|
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
@@ -44,6 +44,8 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
44
44
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
45
45
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
46
46
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
47
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when `amount > 0n` and a
|
|
48
|
+
* Permit2 requirement signature is missing its expiration.
|
|
47
49
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
48
50
|
* @example
|
|
49
51
|
* ```ts
|
|
@@ -120,9 +122,6 @@ export const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset
|
|
|
120
122
|
],
|
|
121
123
|
});
|
|
122
124
|
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
123
|
-
if (nativeAmount) {
|
|
124
|
-
tx = { ...tx, value: nativeAmount };
|
|
125
|
-
}
|
|
126
125
|
if (metadata) {
|
|
127
126
|
tx = addTransactionMetadata(tx, metadata);
|
|
128
127
|
}
|
|
@@ -63,6 +63,8 @@ export interface VaultV1MigrateToV2Params {
|
|
|
63
63
|
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
64
64
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
65
65
|
* is provided and the signed amount differs from `args.shares`.
|
|
66
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
67
|
+
* signature is missing its expiration.
|
|
66
68
|
* @example
|
|
67
69
|
* ```ts
|
|
68
70
|
* import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
3
2
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
4
3
|
import { isAddressEqual, maxUint256 } from "viem";
|
|
4
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
6
|
import { NegativeMinSharePriceError, NonPositiveMaxSharePriceError, NonPositiveSharesAmountError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
7
7
|
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
@@ -43,6 +43,8 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
43
43
|
* is provided and the signed asset differs from `vault.address` (the V1 share token).
|
|
44
44
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
45
45
|
* is provided and the signed amount differs from `args.shares`.
|
|
46
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
47
|
+
* signature is missing its expiration.
|
|
46
48
|
* @example
|
|
47
49
|
* ```ts
|
|
48
50
|
* import { vaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
|
|
@@ -53,6 +53,8 @@ export interface VaultV2DepositParams {
|
|
|
53
53
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
54
54
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
55
55
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
56
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when `amount > 0n` and a
|
|
57
|
+
* Permit2 requirement signature is missing its expiration.
|
|
56
58
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
57
59
|
* @example
|
|
58
60
|
* ```ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
3
2
|
import { deepFreeze, isDefined } from "@morpho-org/morpho-ts";
|
|
4
3
|
import { isAddressEqual } from "viem";
|
|
4
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
6
|
import { ChainWNativeMissingError, NativeAmountOnNonWNativeVaultError, NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveMaxSharePriceError, ZeroDepositAmountError, } from "../../types/index.js";
|
|
7
7
|
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
@@ -44,6 +44,8 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
44
44
|
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
45
45
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
46
46
|
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
47
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when `amount > 0n` and a
|
|
48
|
+
* Permit2 requirement signature is missing its expiration.
|
|
47
49
|
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
48
50
|
* @example
|
|
49
51
|
* ```ts
|
|
@@ -120,9 +122,6 @@ export const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset
|
|
|
120
122
|
],
|
|
121
123
|
});
|
|
122
124
|
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
123
|
-
if (nativeAmount) {
|
|
124
|
-
tx = { ...tx, value: nativeAmount };
|
|
125
|
-
}
|
|
126
125
|
if (metadata) {
|
|
127
126
|
tx = addTransactionMetadata(tx, metadata);
|
|
128
127
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { AddressLabel, ChainAddresses, ChainDeployments, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { addresses, addressesRegistry, convexWrapperTokens, deployments, erc20WrapperTokens, getChainAddresses, getPermissionedCoinbaseTokens, getUnwrappedToken, NATIVE_ADDRESS, permissionedBackedTokens, permissionedCoinbaseTokens, permissionedWrapperTokens, registerCustomAddresses, unwrappedTokensMapping, } from "@morpho-org/blue-sdk";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { addresses, addressesRegistry, convexWrapperTokens, deployments, erc20WrapperTokens, getChainAddresses, getPermissionedCoinbaseTokens, getUnwrappedToken, NATIVE_ADDRESS, permissionedBackedTokens, permissionedCoinbaseTokens, permissionedWrapperTokens, registerCustomAddresses, unwrappedTokensMapping, } from "@morpho-org/blue-sdk";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccrualPosition as BlueAccrualPosition } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchAccrualPosition, fetchPreLiquidationPosition } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace AccrualPosition {
|
|
5
|
+
let fetch: typeof fetchAccrualPosition;
|
|
6
|
+
let fetchPreLiquidation: typeof fetchPreLiquidationPosition;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export { BlueAccrualPosition as AccrualPosition };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AccrualPosition as BlueAccrualPosition } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchAccrualPosition, fetchPreLiquidationPosition, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
BlueAccrualPosition.fetch = fetchAccrualPosition;
|
|
4
|
+
BlueAccrualPosition.fetchPreLiquidation = fetchPreLiquidationPosition;
|
|
5
|
+
export { BlueAccrualPosition as AccrualPosition };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AccrualVault as BlueAccrualVault } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace AccrualVault {
|
|
5
|
+
let fetch: typeof fetchAccrualVault;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BlueAccrualVault as AccrualVault };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MarketParams as BlueMarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchMarketParams } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace MarketParams {
|
|
5
|
+
let fetch: typeof fetchMarketParams;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BlueMarketParams as MarketParams };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Position as BluePosition } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchPosition } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace Position {
|
|
5
|
+
let fetch: typeof fetchPosition;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BluePosition as Position };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VaultConfig as BlueVaultConfig } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchVaultConfig } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace VaultConfig {
|
|
5
|
+
let fetch: typeof fetchVaultConfig;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BlueVaultConfig as VaultConfig };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VaultMarketAllocation as BlueVaultMarketAllocation } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchVaultMarketAllocation } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace VaultMarketAllocation {
|
|
5
|
+
let fetch: typeof fetchVaultMarketAllocation;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BlueVaultMarketAllocation as VaultMarketAllocation };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { VaultMarketAllocation as BlueVaultMarketAllocation } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchVaultMarketAllocation } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
BlueVaultMarketAllocation.fetch = fetchVaultMarketAllocation;
|
|
4
|
+
export { BlueVaultMarketAllocation as VaultMarketAllocation };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VaultMarketConfig as BlueVaultMarketConfig } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchVaultMarketConfig } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace VaultMarketConfig {
|
|
5
|
+
let fetch: typeof fetchVaultMarketConfig;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BlueVaultMarketConfig as VaultMarketConfig };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VaultMarketPublicAllocatorConfig as BlueVaultMarketPublicAllocatorConfig } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchVaultMarketPublicAllocatorConfig } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace VaultMarketPublicAllocatorConfig {
|
|
5
|
+
let fetch: typeof fetchVaultMarketPublicAllocatorConfig;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BlueVaultMarketPublicAllocatorConfig as VaultMarketPublicAllocatorConfig, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VaultMarketPublicAllocatorConfig as BlueVaultMarketPublicAllocatorConfig } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchVaultMarketPublicAllocatorConfig } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
BlueVaultMarketPublicAllocatorConfig.fetch =
|
|
4
|
+
fetchVaultMarketPublicAllocatorConfig;
|
|
5
|
+
export { BlueVaultMarketPublicAllocatorConfig as VaultMarketPublicAllocatorConfig, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VaultUser as BlueVaultUser } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchVaultUser } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
declare module "@morpho-org/blue-sdk" {
|
|
4
|
+
namespace VaultUser {
|
|
5
|
+
let fetch: typeof fetchVaultUser;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { BlueVaultUser as VaultUser };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./augment/AccrualPosition.js";
|
|
2
|
+
import "./augment/AccrualVault.js";
|
|
3
|
+
import "./augment/Holding.js";
|
|
4
|
+
import "./augment/Market.js";
|
|
5
|
+
import "./augment/MarketParams.js";
|
|
6
|
+
import "./augment/Position.js";
|
|
7
|
+
import "./augment/Token.js";
|
|
8
|
+
import "./augment/User.js";
|
|
9
|
+
import "./augment/Vault.js";
|
|
10
|
+
import "./augment/VaultConfig.js";
|
|
11
|
+
import "./augment/VaultMarketAllocation.js";
|
|
12
|
+
import "./augment/VaultMarketConfig.js";
|
|
13
|
+
import "./augment/VaultMarketPublicAllocatorConfig.js";
|
|
14
|
+
import "./augment/VaultUser.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./augment/AccrualPosition.js";
|
|
2
|
+
import "./augment/AccrualVault.js";
|
|
3
|
+
import "./augment/Holding.js";
|
|
4
|
+
import "./augment/Market.js";
|
|
5
|
+
import "./augment/MarketParams.js";
|
|
6
|
+
import "./augment/Position.js";
|
|
7
|
+
import "./augment/Token.js";
|
|
8
|
+
import "./augment/User.js";
|
|
9
|
+
import "./augment/Vault.js";
|
|
10
|
+
import "./augment/VaultConfig.js";
|
|
11
|
+
import "./augment/VaultMarketAllocation.js";
|
|
12
|
+
import "./augment/VaultMarketConfig.js";
|
|
13
|
+
import "./augment/VaultMarketPublicAllocatorConfig.js";
|
|
14
|
+
import "./augment/VaultUser.js";
|