@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
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type { MarketV1Actions } from "../entities/marketV1/index.js";
|
|
2
|
+
export type { VaultV1Actions } from "../entities/vaultV1/index.js";
|
|
3
|
+
export type { VaultV2Actions } from "../entities/vaultV2/index.js";
|
|
1
4
|
export * from "./marketV1/index.js";
|
|
2
5
|
export * from "./requirements/index.js";
|
|
3
6
|
export * from "./vaultV1/index.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BundlerAction } from "@morpho-org/bundler-sdk-viem";
|
|
2
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
3
3
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
4
|
import { NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, } from "../../types/index.js";
|
|
5
5
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
@@ -70,10 +70,7 @@ export const marketV1Borrow = ({ market: { chainId, marketParams }, args: { amou
|
|
|
70
70
|
type: "morphoBorrow",
|
|
71
71
|
args: [marketParams, amount, 0n, minSharePrice, receiver, false],
|
|
72
72
|
});
|
|
73
|
-
let tx =
|
|
74
|
-
...BundlerAction.encodeBundle(chainId, actions),
|
|
75
|
-
value: reallocationFee,
|
|
76
|
-
};
|
|
73
|
+
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
77
74
|
if (metadata) {
|
|
78
75
|
tx = addTransactionMetadata(tx, metadata);
|
|
79
76
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type { Action } from "
|
|
2
|
+
import type { Action } from "../../bundler/index.js";
|
|
3
3
|
import type { VaultReallocation } from "../../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Builds reallocation bundler actions and computes the total fee.
|
|
@@ -12,8 +12,7 @@ import type { VaultReallocation } from "../../types/index.js";
|
|
|
12
12
|
*
|
|
13
13
|
* @param reallocations - The vault reallocations to encode.
|
|
14
14
|
* @param targetMarketParams - The target market params the freed liquidity is destined for.
|
|
15
|
-
* @returns The encoded `reallocateTo` actions and the summed reallocation fee
|
|
16
|
-
* as `tx.value` in the parent bundle).
|
|
15
|
+
* @returns The encoded `reallocateTo` actions and the summed reallocation fee in native tokens.
|
|
17
16
|
* @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
|
|
18
17
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
19
18
|
* @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
|
|
@@ -10,8 +10,7 @@ import { validateReallocations } from "../../helpers/index.js";
|
|
|
10
10
|
*
|
|
11
11
|
* @param reallocations - The vault reallocations to encode.
|
|
12
12
|
* @param targetMarketParams - The target market params the freed liquidity is destined for.
|
|
13
|
-
* @returns The encoded `reallocateTo` actions and the summed reallocation fee
|
|
14
|
-
* as `tx.value` in the parent bundle).
|
|
13
|
+
* @returns The encoded `reallocateTo` actions and the summed reallocation fee in native tokens.
|
|
15
14
|
* @throws {NegativeReallocationFeeError} when any reallocation fee is negative.
|
|
16
15
|
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
17
16
|
* @throws {NonPositiveReallocationAmountError} when any withdrawal amount is non-positive.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./borrow.js";
|
|
2
2
|
export * from "./repay.js";
|
|
3
3
|
export * from "./repayWithdrawCollateral.js";
|
|
4
|
+
export * from "./supply.js";
|
|
4
5
|
export * from "./supplyCollateral.js";
|
|
5
6
|
export * from "./supplyCollateralBorrow.js";
|
|
7
|
+
export * from "./withdraw.js";
|
|
6
8
|
export * from "./withdrawCollateral.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./borrow.js";
|
|
2
2
|
export * from "./repay.js";
|
|
3
3
|
export * from "./repayWithdrawCollateral.js";
|
|
4
|
+
export * from "./supply.js";
|
|
4
5
|
export * from "./supplyCollateral.js";
|
|
5
6
|
export * from "./supplyCollateralBorrow.js";
|
|
7
|
+
export * from "./withdraw.js";
|
|
6
8
|
export * from "./withdrawCollateral.js";
|
|
@@ -68,6 +68,8 @@ export interface MarketV1RepayParams {
|
|
|
68
68
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
69
69
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
70
70
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
71
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
72
|
+
* signature is missing its expiration.
|
|
71
73
|
* @example
|
|
72
74
|
* ```ts
|
|
73
75
|
* import { marketV1Repay } 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 { maxUint256 } from "viem";
|
|
4
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata, validateRepayParams, } from "../../helpers/index.js";
|
|
6
6
|
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
7
7
|
/**
|
|
@@ -44,6 +44,8 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
44
44
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
45
45
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
46
46
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
47
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
48
|
+
* signature is missing its expiration.
|
|
47
49
|
* @example
|
|
48
50
|
* ```ts
|
|
49
51
|
* import { marketV1Repay } from "@morpho-org/morpho-sdk";
|
|
@@ -105,10 +107,7 @@ export const marketV1Repay = ({ market: { chainId, marketParams }, args: { asset
|
|
|
105
107
|
],
|
|
106
108
|
});
|
|
107
109
|
}
|
|
108
|
-
let tx =
|
|
109
|
-
...BundlerAction.encodeBundle(chainId, actions),
|
|
110
|
-
value: 0n,
|
|
111
|
-
};
|
|
110
|
+
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
112
111
|
if (metadata) {
|
|
113
112
|
tx = addTransactionMetadata(tx, metadata);
|
|
114
113
|
}
|
|
@@ -81,6 +81,8 @@ export interface MarketV1RepayWithdrawCollateralParams {
|
|
|
81
81
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
82
82
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
83
83
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
84
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
85
|
+
* signature is missing its expiration.
|
|
84
86
|
* @example
|
|
85
87
|
* ```ts
|
|
86
88
|
* import { marketV1RepayWithdrawCollateral } 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 { maxUint256 } from "viem";
|
|
4
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
5
5
|
import { addTransactionMetadata, validateRepayParams, } from "../../helpers/index.js";
|
|
6
6
|
import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js";
|
|
7
7
|
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
@@ -55,6 +55,8 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
55
55
|
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
56
56
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
57
57
|
* is provided and the signed amount differs from `args.transferAmount`.
|
|
58
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
59
|
+
* signature is missing its expiration.
|
|
58
60
|
* @example
|
|
59
61
|
* ```ts
|
|
60
62
|
* import { marketV1RepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
@@ -125,10 +127,7 @@ export const marketV1RepayWithdrawCollateral = ({ market: { chainId, marketParam
|
|
|
125
127
|
type: "morphoWithdrawCollateral",
|
|
126
128
|
args: [marketParams, withdrawAmount, receiver, false],
|
|
127
129
|
});
|
|
128
|
-
let tx =
|
|
129
|
-
...BundlerAction.encodeBundle(chainId, actions),
|
|
130
|
-
value: 0n,
|
|
131
|
-
};
|
|
130
|
+
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
132
131
|
if (metadata) {
|
|
133
132
|
tx = addTransactionMetadata(tx, metadata);
|
|
134
133
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import { type DepositAmountArgs, type MarketV1SupplyAction, type Metadata, type RequirementSignature, type Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link marketV1Supply}. */
|
|
5
|
+
export interface MarketV1SupplyParams {
|
|
6
|
+
market: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly marketParams: MarketParams;
|
|
9
|
+
};
|
|
10
|
+
args: DepositAmountArgs & {
|
|
11
|
+
onBehalf: Address;
|
|
12
|
+
/** Maximum supply share price (in ray). Slippage protection against inflation attacks. */
|
|
13
|
+
maxSharePrice: bigint;
|
|
14
|
+
requirementSignature?: RequirementSignature;
|
|
15
|
+
};
|
|
16
|
+
metadata?: Metadata;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Prepares a loan-asset supply transaction for a Morpho Blue market.
|
|
20
|
+
*
|
|
21
|
+
* Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
|
|
22
|
+
* via `GeneralAdapter1.wrapNative()` before the supply; the loan token must be the chain's
|
|
23
|
+
* wNative for that path. Uses `maxSharePrice` to protect against share-price inflation between
|
|
24
|
+
* transaction construction and execution.
|
|
25
|
+
*
|
|
26
|
+
* Zero loss: all supplied assets reach Morpho. No dust left in bundler or adapter.
|
|
27
|
+
*
|
|
28
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
29
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
30
|
+
* @param params.args.amount - Amount of ERC-20 loan asset to supply. At least one of `amount` or
|
|
31
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
32
|
+
* @param params.args.onBehalf - Address whose Morpho supply position is credited.
|
|
33
|
+
* @param params.args.maxSharePrice - Maximum acceptable supply share price (in ray). Slippage
|
|
34
|
+
* protection.
|
|
35
|
+
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
36
|
+
* supply. Requires the loan token to be the chain's wNative.
|
|
37
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
|
|
38
|
+
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
39
|
+
* approved `GeneralAdapter1`.
|
|
40
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
|
+
* @returns A deep-frozen `Transaction<MarketV1SupplyAction>` with `to`, `value`, `data`, and the
|
|
42
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
43
|
+
* @throws {NegativeSupplyAmountError} when `amount < 0n`.
|
|
44
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
45
|
+
* @throws {ZeroSupplyAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
46
|
+
* @throws {NegativeSupplyMaxSharePriceError} when `maxSharePrice < 0n`.
|
|
47
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
48
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
49
|
+
* the chain's wNative.
|
|
50
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
51
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
52
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
53
|
+
* is provided and the signed amount differs from `args.amount`.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { marketV1Supply } from "@morpho-org/morpho-sdk";
|
|
57
|
+
*
|
|
58
|
+
* const tx = marketV1Supply({
|
|
59
|
+
* market: { chainId: 1, marketParams },
|
|
60
|
+
* args: {
|
|
61
|
+
* amount: 1_000_000_000n,
|
|
62
|
+
* onBehalf: supplier,
|
|
63
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
* // tx satisfies Readonly<Transaction<MarketV1SupplyAction>>
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare const marketV1Supply: ({ market: { chainId, marketParams }, args: { amount, onBehalf, maxSharePrice, requirementSignature, nativeAmount, }, metadata, }: MarketV1SupplyParams) => Readonly<Transaction<MarketV1SupplyAction>>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
4
|
+
import { addTransactionMetadata, validateNativeAsset, } from "../../helpers/index.js";
|
|
5
|
+
import { NegativeNativeAmountError, NegativeSupplyAmountError, NegativeSupplyMaxSharePriceError, ZeroSupplyAmountError, } from "../../types/index.js";
|
|
6
|
+
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
7
|
+
/**
|
|
8
|
+
* Prepares a loan-asset supply transaction for a Morpho Blue market.
|
|
9
|
+
*
|
|
10
|
+
* Routed through bundler3 via `GeneralAdapter1`. When `nativeAmount > 0`, native ETH is wrapped
|
|
11
|
+
* via `GeneralAdapter1.wrapNative()` before the supply; the loan token must be the chain's
|
|
12
|
+
* wNative for that path. Uses `maxSharePrice` to protect against share-price inflation between
|
|
13
|
+
* transaction construction and execution.
|
|
14
|
+
*
|
|
15
|
+
* Zero loss: all supplied assets reach Morpho. No dust left in bundler or adapter.
|
|
16
|
+
*
|
|
17
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
18
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
19
|
+
* @param params.args.amount - Amount of ERC-20 loan asset to supply. At least one of `amount` or
|
|
20
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
21
|
+
* @param params.args.onBehalf - Address whose Morpho supply position is credited.
|
|
22
|
+
* @param params.args.maxSharePrice - Maximum acceptable supply share price (in ray). Slippage
|
|
23
|
+
* protection.
|
|
24
|
+
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
25
|
+
* supply. Requires the loan token to be the chain's wNative.
|
|
26
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
|
|
27
|
+
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
28
|
+
* approved `GeneralAdapter1`.
|
|
29
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
30
|
+
* @returns A deep-frozen `Transaction<MarketV1SupplyAction>` with `to`, `value`, `data`, and the
|
|
31
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
32
|
+
* @throws {NegativeSupplyAmountError} when `amount < 0n`.
|
|
33
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
34
|
+
* @throws {ZeroSupplyAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
35
|
+
* @throws {NegativeSupplyMaxSharePriceError} when `maxSharePrice < 0n`.
|
|
36
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
37
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not
|
|
38
|
+
* the chain's wNative.
|
|
39
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
40
|
+
* is provided and the signed asset differs from `marketParams.loanToken`.
|
|
41
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
42
|
+
* is provided and the signed amount differs from `args.amount`.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { marketV1Supply } from "@morpho-org/morpho-sdk";
|
|
46
|
+
*
|
|
47
|
+
* const tx = marketV1Supply({
|
|
48
|
+
* market: { chainId: 1, marketParams },
|
|
49
|
+
* args: {
|
|
50
|
+
* amount: 1_000_000_000n,
|
|
51
|
+
* onBehalf: supplier,
|
|
52
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* // tx satisfies Readonly<Transaction<MarketV1SupplyAction>>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export const marketV1Supply = ({ market: { chainId, marketParams }, args: { amount = 0n, onBehalf, maxSharePrice, requirementSignature, nativeAmount, }, metadata, }) => {
|
|
59
|
+
if (amount < 0n) {
|
|
60
|
+
throw new NegativeSupplyAmountError(marketParams.id);
|
|
61
|
+
}
|
|
62
|
+
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
63
|
+
throw new NegativeNativeAmountError(nativeAmount);
|
|
64
|
+
}
|
|
65
|
+
if (maxSharePrice < 0n) {
|
|
66
|
+
throw new NegativeSupplyMaxSharePriceError(marketParams.id);
|
|
67
|
+
}
|
|
68
|
+
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
69
|
+
if (totalAssets === 0n) {
|
|
70
|
+
throw new ZeroSupplyAmountError(marketParams.id);
|
|
71
|
+
}
|
|
72
|
+
const { bundler3: { generalAdapter1, bundler3 }, } = getChainAddresses(chainId);
|
|
73
|
+
const actions = [];
|
|
74
|
+
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
75
|
+
validateNativeAsset(chainId, marketParams.loanToken);
|
|
76
|
+
actions.push({
|
|
77
|
+
type: "nativeTransfer",
|
|
78
|
+
args: [bundler3, generalAdapter1, nativeAmount, false],
|
|
79
|
+
}, {
|
|
80
|
+
type: "wrapNative",
|
|
81
|
+
args: [nativeAmount, generalAdapter1, false],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (amount > 0n) {
|
|
85
|
+
if (requirementSignature) {
|
|
86
|
+
actions.push(...getRequirementsAction({
|
|
87
|
+
asset: marketParams.loanToken,
|
|
88
|
+
amount,
|
|
89
|
+
recipient: generalAdapter1,
|
|
90
|
+
requirementSignature,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
actions.push({
|
|
95
|
+
type: "erc20TransferFrom",
|
|
96
|
+
args: [marketParams.loanToken, amount, generalAdapter1, false],
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
actions.push({
|
|
101
|
+
type: "morphoSupply",
|
|
102
|
+
args: [marketParams, totalAssets, 0n, maxSharePrice, onBehalf, [], false],
|
|
103
|
+
});
|
|
104
|
+
let tx = {
|
|
105
|
+
...BundlerAction.encodeBundle(chainId, actions),
|
|
106
|
+
value: nativeAmount ?? 0n,
|
|
107
|
+
};
|
|
108
|
+
if (metadata) {
|
|
109
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
110
|
+
}
|
|
111
|
+
return deepFreeze({
|
|
112
|
+
...tx,
|
|
113
|
+
action: {
|
|
114
|
+
type: "marketV1Supply",
|
|
115
|
+
args: {
|
|
116
|
+
market: marketParams.id,
|
|
117
|
+
amount: totalAssets,
|
|
118
|
+
onBehalf,
|
|
119
|
+
maxSharePrice,
|
|
120
|
+
nativeAmount,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
};
|
|
@@ -39,12 +39,14 @@ export interface MarketV1SupplyCollateralParams {
|
|
|
39
39
|
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
40
40
|
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
41
41
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
42
|
-
* @throws {
|
|
42
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
43
43
|
* token is not the chain's wNative.
|
|
44
44
|
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
45
45
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
46
46
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
47
47
|
* is provided and the signed amount differs from `args.amount`.
|
|
48
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
49
|
+
* signature is missing its expiration.
|
|
48
50
|
* @example
|
|
49
51
|
* ```ts
|
|
50
52
|
* import { marketV1SupplyCollateral } 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
|
-
import {
|
|
3
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
4
|
+
import { addTransactionMetadata, validateNativeAsset, } from "../../helpers/index.js";
|
|
5
5
|
import { NegativeNativeAmountError, NonPositiveAssetAmountError, ZeroCollateralAmountError, } from "../../types/index.js";
|
|
6
6
|
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
7
7
|
/**
|
|
@@ -30,12 +30,14 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
30
30
|
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
31
31
|
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
32
32
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
33
|
-
* @throws {
|
|
33
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
34
34
|
* token is not the chain's wNative.
|
|
35
35
|
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
36
36
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
37
37
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
38
38
|
* is provided and the signed amount differs from `args.amount`.
|
|
39
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
40
|
+
* signature is missing its expiration.
|
|
39
41
|
* @example
|
|
40
42
|
* ```ts
|
|
41
43
|
* import { marketV1SupplyCollateral } from "@morpho-org/morpho-sdk";
|
|
@@ -61,7 +63,7 @@ export const marketV1SupplyCollateral = ({ market: { chainId, marketParams }, ar
|
|
|
61
63
|
const { bundler3: { generalAdapter1, bundler3 }, } = getChainAddresses(chainId);
|
|
62
64
|
const actions = [];
|
|
63
65
|
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
64
|
-
|
|
66
|
+
validateNativeAsset(chainId, marketParams.collateralToken);
|
|
65
67
|
actions.push({
|
|
66
68
|
type: "nativeTransfer",
|
|
67
69
|
args: [bundler3, generalAdapter1, nativeAmount, false],
|
|
@@ -90,10 +92,7 @@ export const marketV1SupplyCollateral = ({ market: { chainId, marketParams }, ar
|
|
|
90
92
|
type: "morphoSupplyCollateral",
|
|
91
93
|
args: [marketParams, totalCollateral, onBehalf, [], false],
|
|
92
94
|
});
|
|
93
|
-
let tx =
|
|
94
|
-
...BundlerAction.encodeBundle(chainId, actions),
|
|
95
|
-
value: nativeAmount ?? 0n,
|
|
96
|
-
};
|
|
95
|
+
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
97
96
|
if (metadata) {
|
|
98
97
|
tx = addTransactionMetadata(tx, metadata);
|
|
99
98
|
}
|
|
@@ -55,12 +55,14 @@ export interface MarketV1SupplyCollateralBorrowParams {
|
|
|
55
55
|
* @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n`.
|
|
56
56
|
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
57
57
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
58
|
-
* @throws {
|
|
58
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
59
59
|
* token is not the chain's wNative.
|
|
60
60
|
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
61
61
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
62
62
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
63
63
|
* is provided and the signed amount differs from `args.amount`.
|
|
64
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
65
|
+
* signature is missing its expiration.
|
|
64
66
|
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
65
67
|
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
66
68
|
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
@@ -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
|
-
import {
|
|
3
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
4
|
+
import { addTransactionMetadata, validateNativeAsset, } from "../../helpers/index.js";
|
|
5
5
|
import { NegativeNativeAmountError, NonPositiveAssetAmountError, NonPositiveBorrowAmountError, NonPositiveMinBorrowSharePriceError, ZeroCollateralAmountError, } from "../../types/index.js";
|
|
6
6
|
import { getRequirementsAction } from "../requirements/getRequirementsAction.js";
|
|
7
7
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
@@ -41,12 +41,14 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
41
41
|
* @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n`.
|
|
42
42
|
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
43
43
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
44
|
-
* @throws {
|
|
44
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
45
45
|
* token is not the chain's wNative.
|
|
46
46
|
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
47
47
|
* is provided and the signed asset differs from `marketParams.collateralToken`.
|
|
48
48
|
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `requirementSignature`
|
|
49
49
|
* is provided and the signed amount differs from `args.amount`.
|
|
50
|
+
* @throws {Permit2ExpirationMissingError} from `getRequirementsAction` when a Permit2 requirement
|
|
51
|
+
* signature is missing its expiration.
|
|
50
52
|
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
51
53
|
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
52
54
|
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
@@ -94,7 +96,7 @@ export const marketV1SupplyCollateralBorrow = ({ market: { chainId, marketParams
|
|
|
94
96
|
const { bundler3: { generalAdapter1, bundler3 }, } = getChainAddresses(chainId);
|
|
95
97
|
const actions = [];
|
|
96
98
|
if (nativeAmount !== undefined && nativeAmount > 0n) {
|
|
97
|
-
|
|
99
|
+
validateNativeAsset(chainId, marketParams.collateralToken);
|
|
98
100
|
actions.push({
|
|
99
101
|
type: "nativeTransfer",
|
|
100
102
|
args: [bundler3, generalAdapter1, nativeAmount, false],
|
|
@@ -133,10 +135,7 @@ export const marketV1SupplyCollateralBorrow = ({ market: { chainId, marketParams
|
|
|
133
135
|
type: "morphoBorrow",
|
|
134
136
|
args: [marketParams, borrowAmount, 0n, minSharePrice, receiver, false],
|
|
135
137
|
});
|
|
136
|
-
let tx =
|
|
137
|
-
...BundlerAction.encodeBundle(chainId, actions),
|
|
138
|
-
value: (nativeAmount ?? 0n) + reallocationFee,
|
|
139
|
-
};
|
|
138
|
+
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
140
139
|
if (metadata) {
|
|
141
140
|
tx = addTransactionMetadata(tx, metadata);
|
|
142
141
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import { type MarketV1WithdrawAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link marketV1Withdraw}. */
|
|
5
|
+
export interface MarketV1WithdrawParams {
|
|
6
|
+
market: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly marketParams: MarketParams;
|
|
9
|
+
};
|
|
10
|
+
args: {
|
|
11
|
+
/** Withdraw assets amount (`0n` when withdrawing by shares). */
|
|
12
|
+
assets: bigint;
|
|
13
|
+
/** Withdraw shares amount (`0n` when withdrawing by assets). */
|
|
14
|
+
shares: bigint;
|
|
15
|
+
/** Address that receives the withdrawn assets. */
|
|
16
|
+
receiver: Address;
|
|
17
|
+
/** Minimum withdraw share price (in ray). Slippage protection. */
|
|
18
|
+
minSharePrice: bigint;
|
|
19
|
+
/**
|
|
20
|
+
* Vault reallocations to execute before withdrawing. Compute via
|
|
21
|
+
* `MorphoMarketV1.getReallocations({ operation: "withdraw", amount })` or directly via
|
|
22
|
+
* `computeReallocations({ operation: "withdraw", amount, ... })`.
|
|
23
|
+
*/
|
|
24
|
+
reallocations?: readonly VaultReallocation[];
|
|
25
|
+
};
|
|
26
|
+
metadata?: Metadata;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Prepares a loan-asset withdraw transaction for a Morpho Blue market.
|
|
30
|
+
*
|
|
31
|
+
* Routed through bundler3 via `morphoWithdraw`. Supports two modes (exactly one):
|
|
32
|
+
*
|
|
33
|
+
* - **By assets** (`assets > 0, shares = 0`): withdraws an exact asset amount.
|
|
34
|
+
* - **By shares** (`assets = 0, shares > 0`): burns an exact share count (typical for a full
|
|
35
|
+
* supplier position close; immune to interest accrual between tx construction and execution).
|
|
36
|
+
*
|
|
37
|
+
* When `reallocations` are provided, `reallocateTo` actions are prepended to the bundle, moving
|
|
38
|
+
* liquidity from other markets into this one via the PublicAllocator before withdrawing.
|
|
39
|
+
* Reallocation fees accumulate in `tx.value`. The on-chain `morphoWithdraw` sends the assets
|
|
40
|
+
* computed on-chain directly to `receiver`; no skim is required.
|
|
41
|
+
*
|
|
42
|
+
* The withdraw is performed on behalf of the transaction initiator (signer) — there is no
|
|
43
|
+
* separate `onBehalf` field; mirror `marketV1Borrow`. The entity layer keeps `receiver` aligned
|
|
44
|
+
* with the user when none is provided. Requires the user to have authorized `GeneralAdapter1`
|
|
45
|
+
* on Morpho.
|
|
46
|
+
*
|
|
47
|
+
* @param params.market.chainId - The chain the market lives on.
|
|
48
|
+
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
49
|
+
* @param params.args.assets - Withdraw amount in loan-token assets. Set to `0n` in shares mode.
|
|
50
|
+
* @param params.args.shares - Withdraw amount in supply shares. Set to `0n` in assets mode.
|
|
51
|
+
* @param params.args.receiver - Address that receives the withdrawn assets.
|
|
52
|
+
* @param params.args.minSharePrice - Minimum acceptable withdraw share price (in ray). Slippage
|
|
53
|
+
* protection.
|
|
54
|
+
* @param params.args.reallocations - Optional vault reallocations to execute before withdrawing,
|
|
55
|
+
* computed by the entity layer.
|
|
56
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
57
|
+
* @returns A deep-frozen `Transaction<MarketV1WithdrawAction>` with `to`, `value`, `data`, and
|
|
58
|
+
* the typed `action` discriminator the simulation layer consumes.
|
|
59
|
+
* @throws {NonPositiveWithdrawAmountError} when both `assets` and `shares` are zero, or either is negative.
|
|
60
|
+
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
61
|
+
* @throws {NegativeWithdrawMinSharePriceError} when `minSharePrice < 0n` (zero is allowed despite
|
|
62
|
+
* the class name — pattern preserved for symmetry with `marketV1Borrow`).
|
|
63
|
+
* @throws Reallocation errors from `buildReallocationActions` when `reallocations` is malformed
|
|
64
|
+
* (see its JSDoc: `NegativeReallocationFeeError`, `EmptyReallocationWithdrawalsError`,
|
|
65
|
+
* `NonPositiveReallocationAmountError`, `ReallocationWithdrawalOnTargetMarketError`,
|
|
66
|
+
* `UnsortedReallocationWithdrawalsError`).
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { marketV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
70
|
+
*
|
|
71
|
+
* const tx = marketV1Withdraw({
|
|
72
|
+
* market: { chainId: 1, marketParams },
|
|
73
|
+
* args: {
|
|
74
|
+
* assets: 1_000_000_000n,
|
|
75
|
+
* shares: 0n,
|
|
76
|
+
* receiver: supplier,
|
|
77
|
+
* minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinWithdrawSharePrice` from market state + slippage tolerance
|
|
78
|
+
* },
|
|
79
|
+
* });
|
|
80
|
+
* // tx satisfies Readonly<Transaction<MarketV1WithdrawAction>>
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare const marketV1Withdraw: ({ market: { chainId, marketParams }, args: { assets, shares, receiver, minSharePrice, reallocations }, metadata, }: MarketV1WithdrawParams) => Readonly<Transaction<MarketV1WithdrawAction>>;
|